{"version":3,"file":"next-redirect-errors.cjs","sources":["../../../src/lib/next-redirect-errors.ts"],"sourcesContent":["// from https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/redirect-error.ts\n\nexport const RedirectStatusCode = {\n  SeeOther: 303,\n  TemporaryRedirect: 307,\n  PermanentRedirect: 308,\n} as const;\n\nexport type RedirectStatusCode = (typeof RedirectStatusCode)[keyof typeof RedirectStatusCode];\n\nexport const REDIRECT_ERROR_CODE = 'NEXT_REDIRECT';\n\nexport enum RedirectType {\n  push = 'push',\n  replace = 'replace',\n}\n\nexport type RedirectError = Error & {\n  digest: `${typeof REDIRECT_ERROR_CODE};${RedirectType};${string};${RedirectStatusCode};`;\n};\n\n/**\n * Checks an error to determine if it's an error generated by the\n * `redirect(url)` helper.\n *\n * @param error the error that may reference a redirect error\n * @returns true if the error is a redirect error\n */\nexport function isRedirectError(error: unknown): error is RedirectError {\n  if (typeof error !== 'object' || error === null || !('digest' in error) || typeof error.digest !== 'string') {\n    return false;\n  }\n\n  const digest = error.digest.split(';');\n  const [errorCode, type] = digest;\n  const destination = digest.slice(2, -2).join(';');\n  const status = digest.at(-2);\n\n  const statusCode = Number(status);\n\n  return (\n    errorCode === REDIRECT_ERROR_CODE &&\n    (type === 'replace' || type === 'push') &&\n    typeof destination === 'string' &&\n    !isNaN(statusCode) &&\n    Object.values(RedirectStatusCode).includes(statusCode as RedirectStatusCode)\n  );\n}\n\nexport function getRedirectStatus(error: RedirectError): RedirectStatusCode {\n  const status = error.digest.split(';').at(-2);\n  return Number(status) as RedirectStatusCode;\n}\n"],"names":[],"mappings":";;AAEO,MAAM,qBAAqB;AAAA,EAChC,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,mBAAmB;AACrB;AAIO,MAAM,sBAAsB;AAkB5B,SAAS,gBAAgB,OAAwC;AACtE,MAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,YAAY,UAAU,OAAO,MAAM,WAAW,UAAU;AAC3G,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,MAAM,OAAO,MAAM,GAAG;AACrC,QAAM,CAAC,WAAW,IAAI,IAAI;AAC1B,QAAM,cAAc,OAAO,MAAM,GAAG,EAAE,EAAE,KAAK,GAAG;AAChD,QAAM,SAAS,OAAO,GAAG,EAAE;AAE3B,QAAM,aAAa,OAAO,MAAM;AAEhC,SACE,cAAc,wBACb,SAAS,aAAa,SAAS,WAChC,OAAO,gBAAgB,YACvB,CAAC,MAAM,UAAU,KACjB,OAAO,OAAO,kBAAkB,EAAE,SAAS,UAAgC;AAE/E;AAEO,SAAS,kBAAkB,OAA0C;AAC1E,QAAM,SAAS,MAAM,OAAO,MAAM,GAAG,EAAE,GAAG,EAAE;AAC5C,SAAO,OAAO,MAAM;AACtB;;;;;"}