{"version":3,"file":"localeValidation.mjs","names":[],"sources":["../../src/request/localeValidation.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport { createInvalidRequestLocaleWarning } from '../errors/request';\n\nfunction determineSupportedLocale(locale: unknown): string | undefined {\n  if (typeof locale !== 'string' || locale.length === 0) return undefined;\n  return getI18nConfig().determineSupportedLocale(locale);\n}\n\nfunction warnInvalidLocale(locale: string, defaultLocale: string) {\n  if (\n    process.env._GENERALTRANSLATION_DISABLE_INVALID_LOCALE_WARNING === 'true'\n  ) {\n    return;\n  }\n\n  console.warn(createInvalidRequestLocaleWarning(locale, defaultLocale));\n}\n\nexport function resolveLocaleOrDefault(locale: unknown): string {\n  const i18nConfig = getI18nConfig();\n  const defaultLocale = i18nConfig.getDefaultLocale();\n  const supportedLocale =\n    typeof locale === 'string' && locale.length > 0\n      ? i18nConfig.determineSupportedLocale(locale)\n      : undefined;\n\n  if (supportedLocale) return supportedLocale;\n\n  if (typeof locale === 'string' && locale.length > 0) {\n    warnInvalidLocale(locale, defaultLocale);\n  }\n\n  return defaultLocale;\n}\n\n/**\n * Checks whether a locale is valid and supported by the current gt-next config.\n *\n * Use this when route params or other request inputs should be rejected instead\n * of falling back to the default locale.\n *\n * @param locale - The locale candidate to validate.\n * @returns True when the locale resolves to one of the configured locales.\n */\nexport function isLocaleSupported(locale: unknown): locale is string {\n  return determineSupportedLocale(locale) !== undefined;\n}\n"],"mappings":";;;AAGA,SAAS,yBAAyB,QAAqC;AACrE,KAAI,OAAO,WAAW,YAAY,OAAO,WAAW,EAAG,QAAO,KAAA;AAC9D,QAAO,eAAe,CAAC,yBAAyB,OAAO;;AAGzD,SAAS,kBAAkB,QAAgB,eAAuB;AAChE,KACE,QAAQ,IAAI,uDAAuD,OAEnE;AAGF,SAAQ,KAAK,kCAAkC,QAAQ,cAAc,CAAC;;AAGxE,SAAgB,uBAAuB,QAAyB;CAC9D,MAAM,aAAa,eAAe;CAClC,MAAM,gBAAgB,WAAW,kBAAkB;CACnD,MAAM,kBACJ,OAAO,WAAW,YAAY,OAAO,SAAS,IAC1C,WAAW,yBAAyB,OAAO,GAC3C,KAAA;AAEN,KAAI,gBAAiB,QAAO;AAE5B,KAAI,OAAO,WAAW,YAAY,OAAO,SAAS,EAChD,mBAAkB,QAAQ,cAAc;AAG1C,QAAO;;;;;;;;;;;AAYT,SAAgB,kBAAkB,QAAmC;AACnE,QAAO,yBAAyB,OAAO,KAAK,KAAA"}