{"version":3,"file":"util.mjs","sources":["../../../../src/grafana/api/util.ts"],"sourcesContent":["/**\n * @TODO move this to some shared package, currently copied from Grafana core (app/api/utils)\n */\n\nimport { config } from '@grafana/runtime';\n\nexport const getAPINamespace = () => config.namespace;\n\nexport const getAPIBaseURL = (group: string, version: string) => {\n  const subPath = config.appSubUrl || '';\n  return `${subPath}/apis/${group}/${version}/namespaces/${getAPINamespace()}` as const;\n};\n\n// By including the version in the reducer path we can prevent cache bugs when different versions of the API are used for the same entities\nexport const getAPIReducerPath = (group: string, version: string) => `${group}/${version}` as const;\n\n/**\n * Check if a string is well-formed UTF-16 (no lone surrogates).\n * encodeURIComponent() throws an error for lone surrogates\n */\nexport const isWellFormed = (str: string): boolean => {\n  try {\n    encodeURIComponent(str);\n    return true;\n  } catch (error) {\n    return false;\n  }\n};\n\n/**\n * Base64URL encode a string using native browser APIs.\n * Handles Unicode characters correctly by using TextEncoder.\n * Converts standard base64 to base64url by replacing + with -, / with _, and removing padding.\n * @throws Error if the input string contains lone surrogates (malformed UTF-16)\n */\nexport const base64UrlEncode = (value: string): string => {\n  // Check if the string is well-formed UTF-16\n  if (!isWellFormed(value)) {\n    throw new Error(`Cannot encode malformed UTF-16 string with lone surrogates: ${value}`);\n  }\n\n  // Encode UTF-8 string to bytes\n  const bytes = new TextEncoder().encode(value);\n\n  // Convert bytes to base64\n  const binString = String.fromCodePoint(...bytes);\n  const base64 = btoa(binString);\n\n  // Convert to base64url format\n  return base64.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '');\n};\n"],"names":[],"mappings":";;;AAMO,MAAM,eAAA,GAAkB,MAAM,MAAA,CAAO;AAErC,MAAM,aAAA,GAAgB,CAAC,KAAA,EAAe,OAAA,KAAoB;AAC/D,EAAA,MAAM,OAAA,GAAU,OAAO,SAAA,IAAa,EAAA;AACpC,EAAA,OAAO,CAAA,EAAG,OAAO,CAAA,MAAA,EAAS,KAAK,IAAI,OAAO,CAAA,YAAA,EAAe,iBAAiB,CAAA,CAAA;AAC5E;AAGO,MAAM,oBAAoB,CAAC,KAAA,EAAe,YAAoB,CAAA,EAAG,KAAK,IAAI,OAAO,CAAA;AAMjF,MAAM,YAAA,GAAe,CAAC,GAAA,KAAyB;AACpD,EAAA,IAAI;AACF,IAAA,kBAAA,CAAmB,GAAG,CAAA;AACtB,IAAA,OAAO,IAAA;AAAA,EACT,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,KAAA;AAAA,EACT;AACF;AAQO,MAAM,eAAA,GAAkB,CAAC,KAAA,KAA0B;AAExD,EAAA,IAAI,CAAC,YAAA,CAAa,KAAK,CAAA,EAAG;AACxB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,4DAAA,EAA+D,KAAK,CAAA,CAAE,CAAA;AAAA,EACxF;AAGA,EAAA,MAAM,KAAA,GAAQ,IAAI,WAAA,EAAY,CAAE,OAAO,KAAK,CAAA;AAG5C,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,aAAA,CAAc,GAAG,KAAK,CAAA;AAC/C,EAAA,MAAM,MAAA,GAAS,KAAK,SAAS,CAAA;AAG7B,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,KAAA,EAAO,GAAG,CAAA,CAAE,OAAA,CAAQ,KAAA,EAAO,GAAG,CAAA,CAAE,OAAA,CAAQ,IAAA,EAAM,EAAE,CAAA;AACxE;;;;"}