{"version":3,"file":"tld.cjs","sources":["../../../src/utils/tld.ts"],"sourcesContent":["import { SOL_SRS_RESOLUTION_ENABLED } from \"../config\";\r\nimport { UnsupportedTldError } from \"../errors\";\r\n\r\n/** The Solana Name Service top-level domain. */\r\nexport const SOL_TLD = \".sol\";\r\n\r\n/** The Bonfida SNS top-level domain. */\r\nexport const SNS_TLD = \".sns\";\r\n\r\n/** A top-level domain supported by this SDK. */\r\nexport type SupportedTld = typeof SNS_TLD | typeof SOL_TLD;\r\n\r\n/** TLD suffixes accepted by the domain parsing and resolution helpers. */\r\nexport const SUPPORTED_TLDS: readonly SupportedTld[] =\r\n  SOL_SRS_RESOLUTION_ENABLED ? [SNS_TLD] : [SNS_TLD, SOL_TLD];\r\n\r\n/**\r\n * Returns the matching TLD from `supportedTlds` if `domain` ends with one,\r\n * or `undefined` otherwise.\r\n *\r\n * @param domain Domain name to inspect\r\n * @param supportedTlds Supported suffixes to match against\r\n * @returns The matching suffix, or `undefined` when none match.\r\n *\r\n * @example\r\n * ```ts\r\n * const tld = getTld(\"example.sns\");\r\n * ```\r\n */\r\nexport const getTld = (\r\n  domain: string,\r\n  supportedTlds: readonly string[] = SUPPORTED_TLDS\r\n): string | undefined => supportedTlds.find((tld) => domain.endsWith(tld));\r\n\r\n/**\r\n * Ensures `domain` ends with one of the `supportedTlds` and strips that suffix.\r\n *\r\n * @param domain Domain name to parse\r\n * @param supportedTlds Supported suffixes to match against\r\n * @returns Domain name without suffix and the matching suffix.\r\n * @throws UnsupportedTldError If no supported suffix matches.\r\n *\r\n * @example\r\n * ```ts\r\n * const [domain, tld] = parseSupportedTld(\"example.sns\");\r\n * ```\r\n */\r\nexport const parseSupportedTld = (\r\n  domain: string,\r\n  supportedTlds: readonly string[] = SUPPORTED_TLDS\r\n): [string, string] => {\r\n  const tld = getTld(domain, supportedTlds);\r\n  if (!tld) {\r\n    throw new UnsupportedTldError(\r\n      `Domain \"${domain}\" is missing a supported TLD suffix (${supportedTlds.join(\"/\")})`\r\n    );\r\n  }\r\n  return [domain.slice(0, -tld.length), tld];\r\n};\r\n\r\n/**\r\n * Ensures `domain` ends with `.sns` and strips that suffix.\r\n *\r\n * @param domain Domain name to parse\r\n * @returns Domain name without suffix and the `.sns` suffix.\r\n * @throws UnsupportedTldError If the domain does not end with `.sns`.\r\n *\r\n * @example\r\n * ```ts\r\n * const [domain] = parseSnsTld(\"example.sns\");\r\n * ```\r\n */\r\nexport const parseSnsTld = (domain: string): [string, string] =>\r\n  parseSupportedTld(domain, [SNS_TLD]);\r\n"],"names":["UnsupportedTldError"],"mappings":";;;;;;AAGA;AACO,MAAM,OAAO,GAAG;AAEvB;AACO,MAAM,OAAO,GAAG;AAKvB;AACa,MAAA,cAAc,GACgB,CAAC,OAAO,EAAE,OAAO;AAE5D;;;;;;;;;;;;AAYG;AACI,MAAM,MAAM,GAAG,CACpB,MAAc,EACd,aAAA,GAAmC,cAAc,KAC1B,aAAa,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;AAEzE;;;;;;;;;;;;AAYG;AACU,MAAA,iBAAiB,GAAG,CAC/B,MAAc,EACd,aAAA,GAAmC,cAAc,KAC7B;IACpB,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC;IACzC,IAAI,CAAC,GAAG,EAAE;AACR,QAAA,MAAM,IAAIA,0BAAmB,CAC3B,CAAA,QAAA,EAAW,MAAM,CAAwC,qCAAA,EAAA,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA,CAAA,CAAG,CACpF;;AAEH,IAAA,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC;AAC5C;AAEA;;;;;;;;;;;AAWG;AACU,MAAA,WAAW,GAAG,CAAC,MAAc,KACxC,iBAAiB,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC;;;;;;;;;"}