{"version":3,"file":"pathname.cjs","names":["RZL_NEXT_KIT_EXTRA","getStaticGenerationStore","getExpectedRequestStore","ReadonlyURLSearchParams"],"sources":["../../src/extra/pathname.ts"],"sourcesContent":["import { headers } from \"next/headers\";\n\nimport {\n  getExpectedRequestStore,\n  getStaticGenerationStore\n} from \"@/extra/utils/async-storages\";\nimport { ReadonlyURLSearchParams } from \"@/extra/utils/search-params\";\n\nimport { RZL_NEXT_KIT_EXTRA } from \"./utils/constants\";\n\nconst { FLAG_MESSAGE } = RZL_NEXT_KIT_EXTRA.ERROR;\n\n// -- Internal ------------------------\n\nasync function getRequestOrigin() {\n  const requestHeaders = await headers();\n  const protocol = requestHeaders.get(\"x-forwarded-proto\") || \"http\";\n  const host =\n    requestHeaders.get(\"x-forwarded-host\") ||\n    requestHeaders.get(\"host\") ||\n    \"localhost:3000\";\n  return `${protocol}://${host}`;\n}\n\nasync function getRequestURL(callingExpression: string): Promise<URL> {\n  const origin = await getRequestOrigin();\n  const staticStore = getStaticGenerationStore(callingExpression);\n\n  if (\n    staticStore &&\n    \"urlPathname\" in staticStore &&\n    !!staticStore.urlPathname\n  ) {\n    return new URL(staticStore.urlPathname, origin);\n  }\n\n  const requestStore = getExpectedRequestStore(callingExpression);\n  if (requestStore && \"url\" in requestStore && !!requestStore.url) {\n    return new URL(\n      `${requestStore.url.pathname}${requestStore.url.search}`,\n      origin\n    );\n  }\n\n  // We should never get here.\n  throw new Error(\n    FLAG_MESSAGE(\n      `Function \\`${callingExpression}\\` could not access the request URL. Probably you should report this as a bug. GitHub: https://github.com/rzl-zone/next-kit/issues`\n    )\n  );\n}\n\n// -- Exported ------------------------\n\n/** -------------------------------------------------------------------\n * * ***This function lets you read the current URL's pathname.***\n * -------------------------------------------------------------------\n * * ***`⚠️ Warning: Currently is not support with turbopack flag mode !!!`***\n * -------------------------------------------------------------------\n * @example\n * ```ts\n * import { getPathname } from \"@rzl-zone/next-kit/extra/pathname\";\n *\n * type LayoutProps = Readonly<{ children: React.ReactNode }>;\n * export default async function Layout({ children }: LayoutProps) {\n *   const pathname = await getPathname();\n *   // ➔ returns \"/dashboard\" on /dashboard?foo=bar\n *\n *   return (\n *     //...\n *   );\n * };\n * ```\n */\nexport async function getPathname(): Promise<string> {\n  const expression = \"getPathname\";\n  const url = await getRequestURL(expression);\n\n  return url.pathname;\n}\n\n/** -------------------------------------------------------------------\n * * ***This function lets you *read* the current URL's search parameters.***\n * -------------------------------------------------------------------\n * * ***`⚠️ Warning: Currently is not support with turbopack flag mode !!!`***\n * -------------------------------------------------------------------\n * **Learn more about [`URLSearchParams` on MDN](https://developer.mozilla.org/docs/Web/API/URLSearchParams).**\n *\n * @example\n * ```ts\n * import { getSearchParams } from \"@rzl-zone/next-kit/extra/pathname\";\n *\n * type LayoutProps = Readonly<{ children: React.ReactNode }>;\n * export default async function Layout({ children }: LayoutProps) {\n *   const params = await getSearchParams();\n *   params.get(\"foo\");\n *   // ➔ returns \"bar\" when ?foo=bar\n *\n *   return (\n *     //...\n *   );\n * };\n * ```\n */\nexport async function getSearchParams(): Promise<ReadonlyURLSearchParams> {\n  const expression = \"getSearchParams\";\n  const url = await getRequestURL(expression);\n\n  return new ReadonlyURLSearchParams(url.searchParams);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAUA,MAAM,EAAE,iBAAiBA,qCAAmB;AAI5C,eAAe,mBAAmB;CAChC,MAAM,iBAAiB,mCAAc;CAMrC,OAAO,GALU,eAAe,IAAI,mBAAmB,KAAK,OAKzC,KAHjB,eAAe,IAAI,kBAAkB,KACrC,eAAe,IAAI,MAAM,KACzB;AAEJ;AAEA,eAAe,cAAc,mBAAyC;CACpE,MAAM,SAAS,MAAM,iBAAiB;CACtC,MAAM,cAAcC,gDAAyB,iBAAiB;CAE9D,IACE,eACA,iBAAiB,eACjB,CAAC,CAAC,YAAY,aAEd,OAAO,IAAI,IAAI,YAAY,aAAa,MAAM;CAGhD,MAAM,eAAeC,+CAAwB,iBAAiB;CAC9D,IAAI,gBAAgB,SAAS,gBAAgB,CAAC,CAAC,aAAa,KAC1D,OAAO,IAAI,IACT,GAAG,aAAa,IAAI,WAAW,aAAa,IAAI,UAChD,MACF;CAIF,MAAM,IAAI,MACR,aACE,cAAc,kBAAkB,mIAClC,CACF;AACF;;;;;;;;;;;;;;;;;;;;;AAwBA,eAAsB,cAA+B;CAInD,QAAO,MAFW,cAAc,aAAU,EAEhC,CAAC;AACb;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,eAAsB,kBAAoD;CAIxE,OAAO,IAAIC,+CAAwB,MAFjB,cAAc,iBAAU,EAEJ,CAAC,YAAY;AACrD"}
