{"version":3,"file":"us-states.D805wCqP.js","sources":["../../../src/lib/graphql.ts","../../../src/lib/us-states.ts"],"sourcesContent":["export const runQuery = async (query: string): Promise => {\n return runGraphQL({\n url: import.meta.env.PUBLIC_GRAPHQL_URL,\n query\n })\n}\n\nexport const runDataStoreQuery = async (query: string): Promise => {\n return runGraphQL({\n url: import.meta.env.PUBLIC_DATASTORE_API_GRAPHQL_URL,\n query,\n retry: true\n })\n}\n\nconst runGraphQL = async ({\n url,\n query,\n retry = false\n}: {\n url: string\n query: string\n retry?: boolean\n}): Promise => {\n const delays = retry ? [500, 1000, 3000] : []\n\n while (true) {\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ query })\n })\n\n const { data } = await response.json()\n return data\n } catch (error) {\n const delay = delays.shift()\n if (delay) {\n await new Promise((resolve) => setTimeout(resolve, delay))\n } else {\n throw error\n }\n }\n }\n}\n","import Cookies from 'js-cookie'\nimport { runQuery } from './graphql'\nimport type { CookieAttributes } from 'node_modules/@types/js-cookie'\nimport type { SearchOption } from '@components/ui/responsive-combobox'\n\nexport const US_STATES: readonly USState[] = [\n {\n sfcId: 1,\n name: \"Alabama\",\n abbr: \"AL\",\n slug: \"alabama\"\n },\n {\n sfcId: 2,\n name: \"Alaska\",\n abbr: \"AK\",\n slug: \"alaska\"\n },\n {\n sfcId: 3,\n name: \"Arizona\",\n abbr: \"AZ\",\n slug: \"arizona\"\n },\n {\n sfcId: 4,\n name: \"Arkansas\",\n abbr: \"AR\",\n slug: \"arkansas\"\n },\n {\n sfcId: 5,\n name: \"California\",\n abbr: \"CA\",\n slug: \"california\"\n },\n {\n sfcId: 6,\n name: \"Colorado\",\n abbr: \"CO\",\n slug: \"colorado\"\n },\n {\n sfcId: 7,\n name: \"Connecticut\",\n abbr: \"CT\",\n slug: \"connecticut\"\n },\n {\n sfcId: 8,\n name: \"Delaware\",\n abbr: \"DE\",\n slug: \"delaware\"\n },\n {\n sfcId: 9,\n name: \"District of Columbia\",\n abbr: \"DC\",\n slug: \"district-of-columbia\"\n },\n {\n sfcId: 10,\n name: \"Florida\",\n abbr: \"FL\",\n slug: \"florida\"\n },\n {\n sfcId: 11,\n name: \"Georgia\",\n abbr: \"GA\",\n slug: \"georgia\"\n },\n {\n sfcId: 12,\n name: \"Hawaii\",\n abbr: \"HI\",\n slug: \"hawaii\"\n },\n {\n sfcId: 13,\n name: \"Idaho\",\n abbr: \"ID\",\n slug: \"idaho\"\n },\n {\n sfcId: 14,\n name: \"Illinois\",\n abbr: \"IL\",\n slug: \"illinois\"\n },\n {\n sfcId: 15,\n name: \"Indiana\",\n abbr: \"IN\",\n slug: \"indiana\"\n },\n {\n sfcId: 16,\n name: \"Iowa\",\n abbr: \"IA\",\n slug: \"iowa\"\n },\n {\n sfcId: 17,\n name: \"Kansas\",\n abbr: \"KS\",\n slug: \"kansas\"\n },\n {\n sfcId: 18,\n name: \"Kentucky\",\n abbr: \"KY\",\n slug: \"kentucky\"\n },\n {\n sfcId: 19,\n name: \"Louisiana\",\n abbr: \"LA\",\n slug: \"louisiana\"\n },\n {\n sfcId: 20,\n name: \"Maine\",\n abbr: \"ME\",\n slug: \"maine\"\n },\n {\n sfcId: 21,\n name: \"Maryland\",\n abbr: \"MD\",\n slug: \"maryland\"\n },\n {\n sfcId: 22,\n name: \"Massachusetts\",\n abbr: \"MA\",\n slug: \"massachusetts\"\n },\n {\n sfcId: 23,\n name: \"Michigan\",\n abbr: \"MI\",\n slug: \"michigan\"\n },\n {\n sfcId: 24,\n name: \"Minnesota\",\n abbr: \"MN\",\n slug: \"minnesota\"\n },\n {\n sfcId: 25,\n name: \"Mississippi\",\n abbr: \"MS\",\n slug: \"mississippi\"\n },\n {\n sfcId: 26,\n name: \"Missouri\",\n abbr: \"MO\",\n slug: \"missouri\"\n },\n {\n sfcId: 27,\n name: \"Montana\",\n abbr: \"MT\",\n slug: \"montana\"\n },\n {\n sfcId: 28,\n name: \"Nebraska\",\n abbr: \"NE\",\n slug: \"nebraska\"\n },\n {\n sfcId: 29,\n name: \"Nevada\",\n abbr: \"NV\",\n slug: \"nevada\"\n },\n {\n sfcId: 30,\n name: \"New Hampshire\",\n abbr: \"NH\",\n slug: \"new-hampshire\"\n },\n {\n sfcId: 31,\n name: \"New Jersey\",\n abbr: \"NJ\",\n slug: \"new-jersey\"\n },\n {\n sfcId: 32,\n name: \"New Mexico\",\n abbr: \"NM\",\n slug: \"new-mexico\"\n },\n {\n sfcId: 33,\n name: \"New York\",\n abbr: \"NY\",\n slug: \"new-york\"\n },\n {\n sfcId: 34,\n name: \"North Carolina\",\n abbr: \"NC\",\n slug: \"north-carolina\"\n },\n {\n sfcId: 35,\n name: \"North Dakota\",\n abbr: \"ND\",\n slug: \"north-dakota\"\n },\n {\n sfcId: 36,\n name: \"Ohio\",\n abbr: \"OH\",\n slug: \"ohio\"\n },\n {\n sfcId: 37,\n name: \"Oklahoma\",\n abbr: \"OK\",\n slug: \"oklahoma\"\n },\n {\n sfcId: 38,\n name: \"Oregon\",\n abbr: \"OR\",\n slug: \"oregon\"\n },\n {\n sfcId: 39,\n name: \"Pennsylvania\",\n abbr: \"PA\",\n slug: \"pennsylvania\"\n },\n {\n sfcId: 40,\n name: \"Rhode Island\",\n abbr: \"RI\",\n slug: \"rhode-island\"\n },\n {\n sfcId: 41,\n name: \"South Carolina\",\n abbr: \"SC\",\n slug: \"south-carolina\"\n },\n {\n sfcId: 42,\n name: \"South Dakota\",\n abbr: \"SD\",\n slug: \"south-dakota\"\n },\n {\n sfcId: 43,\n name: \"Tennessee\",\n abbr: \"TN\",\n slug: \"tennessee\"\n },\n {\n sfcId: 44,\n name: \"Texas\",\n abbr: \"TX\",\n slug: \"texas\"\n },\n {\n sfcId: 45,\n name: \"Utah\",\n abbr: \"UT\",\n slug: \"utah\"\n },\n {\n sfcId: 46,\n name: \"Vermont\",\n abbr: \"VT\",\n slug: \"vermont\"\n },\n {\n sfcId: 47,\n name: \"Virginia\",\n abbr: \"VA\",\n slug: \"virginia\"\n },\n {\n sfcId: 48,\n name: \"Washington\",\n abbr: \"WA\",\n slug: \"washington\"\n },\n {\n sfcId: 49,\n name: \"West Virginia\",\n abbr: \"WV\",\n slug: \"west-virginia\"\n },\n {\n sfcId: 50,\n name: \"Wisconsin\",\n abbr: \"WI\",\n slug: \"wisconsin\"\n },\n {\n sfcId: 51,\n name: \"Wyoming\",\n abbr: \"WY\",\n slug: \"wyoming\"\n }\n] as const\n\nexport interface USState {\n sfcId: number\n name: string\n abbr: string\n slug: string\n}\nexport type USStateName = (typeof US_STATES)[number]['name']\n\nexport type USStateAbbreviation = (typeof US_STATES)[number]['abbr']\n\n/**\n * US states formatted for use in a Command Search component.\n */\nexport const US_STATES_SEARCH: SearchOption[] = US_STATES.map(({ name, abbr }) => ({\n label: name,\n id: abbr,\n value: name.toLowerCase()\n}))\n\n/**\n * Map of US states keyed by their abbreviations.\n */\nexport const US_STATES_MAP: Record = US_STATES.reduce(\n (acc, state) => {\n acc[state.abbr] = state\n return acc\n },\n {} as Record\n)\n\nconst COOKIE_NAME = 'state_from_ip'\n\nexport interface StateFromIp {\n id: string\n name: USStateName\n slug: string\n}\n\nconst getStateFromIpFromCookie = (): StateFromIp | undefined => {\n const cookieValue = Cookies.get(COOKIE_NAME)\n if (cookieValue) {\n return JSON.parse(cookieValue) as StateFromIp\n }\n\n return undefined\n}\n\nconst storeStateInCookie = (state: StateFromIp) => {\n const cookieOptions: CookieAttributes = {\n expires: 1,\n path: '/'\n }\n\n if (window.location.hostname.includes('savingforcollege.com')) {\n cookieOptions.domain = 'savingforcollege.com'\n }\n\n Cookies.set(COOKIE_NAME, JSON.stringify(state), cookieOptions)\n}\n\nconst fetchStateFromIp = async (): Promise => {\n const query = `\n query {\n\t\t\t\tno_graphql_cache()\n\t\t\t\tstate_from_ip(click_source:\"unknown_source\"){\n\t\t\t\t\tid\n\t\t\t\t\tname\n\t\t\t\t\tslug\n\t\t\t\t}\n }`\n\n try {\n const data: { state_from_ip: StateFromIp } = await runQuery(query)\n return data.state_from_ip\n } catch (e) {\n console.error('Failed to get state from IP', e)\n return undefined\n }\n}\n\nlet getStateFromIpPromise!: Promise\nexport const getStateFromIp = (): Promise => {\n if (getStateFromIpPromise === undefined) {\n getStateFromIpPromise = new Promise(async (resolve) => {\n const stateFromIpFromCookie = getStateFromIpFromCookie()\n if (stateFromIpFromCookie) {\n resolve(stateFromIpFromCookie)\n } else {\n try {\n const stateFromIp = await fetchStateFromIp()\n\n if (stateFromIp) {\n storeStateInCookie(stateFromIp)\n resolve(stateFromIp)\n } else {\n resolve(undefined)\n }\n } catch (error) {\n console.error('Failed to get state from IP', error)\n resolve(undefined)\n }\n }\n })\n }\n\n return getStateFromIpPromise\n}\n"],"names":["runQuery","query","runGraphQL","runDataStoreQuery","url","retry","delays","response","data","error","delay","resolve","US_STATES","US_STATES_SEARCH","name","abbr","US_STATES_MAP","acc","state","COOKIE_NAME","getStateFromIpFromCookie","cookieValue","Cookies","storeStateInCookie","cookieOptions","fetchStateFromIp","e","getStateFromIpPromise","getStateFromIp","stateFromIpFromCookie","stateFromIp"],"mappings":"gZAAa,MAAAA,EAAW,MAAOC,GACtBC,EAAW,CAChB,IAAK,2CACL,MAAAD,CAAA,CACD,EAGUE,EAAoB,MAAOF,GAC/BC,EAAW,CAChB,IAAK,oDACL,MAAAD,EACA,MAAO,EAAA,CACR,EAGGC,EAAa,MAAO,CACxB,IAAAE,EACA,MAAAH,EACA,MAAAI,EAAQ,EACV,IAIoB,CAClB,MAAMC,EAASD,EAAQ,CAAC,IAAK,IAAM,GAAI,EAAI,GAE3C,OACM,GAAA,CACI,MAAAE,EAAW,MAAM,MAAMH,EAAK,CAChC,OAAQ,OACR,QAAS,CAAE,eAAgB,kBAAmB,EAC9C,KAAM,KAAK,UAAU,CAAE,MAAAH,EAAO,CAAA,CAC/B,EAEK,CAAE,KAAAO,CAAS,EAAA,MAAMD,EAAS,KAAK,EAC9B,OAAAC,QACAC,EAAO,CACR,MAAAC,EAAQJ,EAAO,QACrB,GAAII,EACF,MAAM,IAAI,QAASC,GAAY,WAAWA,EAASD,CAAK,CAAC,MAEnD,OAAAD,CAEV,CAEJ,ECxCaG,EAAgC,CAC3C,CACE,MAAO,EACP,KAAM,UACN,KAAM,KACN,KAAM,SACR,EACA,CACE,MAAO,EACP,KAAM,SACN,KAAM,KACN,KAAM,QACR,EACA,CACE,MAAO,EACP,KAAM,UACN,KAAM,KACN,KAAM,SACR,EACA,CACE,MAAO,EACP,KAAM,WACN,KAAM,KACN,KAAM,UACR,EACA,CACE,MAAO,EACP,KAAM,aACN,KAAM,KACN,KAAM,YACR,EACA,CACE,MAAO,EACP,KAAM,WACN,KAAM,KACN,KAAM,UACR,EACA,CACE,MAAO,EACP,KAAM,cACN,KAAM,KACN,KAAM,aACR,EACA,CACE,MAAO,EACP,KAAM,WACN,KAAM,KACN,KAAM,UACR,EACA,CACE,MAAO,EACP,KAAM,uBACN,KAAM,KACN,KAAM,sBACR,EACA,CACE,MAAO,GACP,KAAM,UACN,KAAM,KACN,KAAM,SACR,EACA,CACE,MAAO,GACP,KAAM,UACN,KAAM,KACN,KAAM,SACR,EACA,CACE,MAAO,GACP,KAAM,SACN,KAAM,KACN,KAAM,QACR,EACA,CACE,MAAO,GACP,KAAM,QACN,KAAM,KACN,KAAM,OACR,EACA,CACE,MAAO,GACP,KAAM,WACN,KAAM,KACN,KAAM,UACR,EACA,CACE,MAAO,GACP,KAAM,UACN,KAAM,KACN,KAAM,SACR,EACA,CACE,MAAO,GACP,KAAM,OACN,KAAM,KACN,KAAM,MACR,EACA,CACE,MAAO,GACP,KAAM,SACN,KAAM,KACN,KAAM,QACR,EACA,CACE,MAAO,GACP,KAAM,WACN,KAAM,KACN,KAAM,UACR,EACA,CACE,MAAO,GACP,KAAM,YACN,KAAM,KACN,KAAM,WACR,EACA,CACE,MAAO,GACP,KAAM,QACN,KAAM,KACN,KAAM,OACR,EACA,CACE,MAAO,GACP,KAAM,WACN,KAAM,KACN,KAAM,UACR,EACA,CACE,MAAO,GACP,KAAM,gBACN,KAAM,KACN,KAAM,eACR,EACA,CACE,MAAO,GACP,KAAM,WACN,KAAM,KACN,KAAM,UACR,EACA,CACE,MAAO,GACP,KAAM,YACN,KAAM,KACN,KAAM,WACR,EACA,CACE,MAAO,GACP,KAAM,cACN,KAAM,KACN,KAAM,aACR,EACA,CACE,MAAO,GACP,KAAM,WACN,KAAM,KACN,KAAM,UACR,EACA,CACE,MAAO,GACP,KAAM,UACN,KAAM,KACN,KAAM,SACR,EACA,CACE,MAAO,GACP,KAAM,WACN,KAAM,KACN,KAAM,UACR,EACA,CACE,MAAO,GACP,KAAM,SACN,KAAM,KACN,KAAM,QACR,EACA,CACE,MAAO,GACP,KAAM,gBACN,KAAM,KACN,KAAM,eACR,EACA,CACE,MAAO,GACP,KAAM,aACN,KAAM,KACN,KAAM,YACR,EACA,CACE,MAAO,GACP,KAAM,aACN,KAAM,KACN,KAAM,YACR,EACA,CACE,MAAO,GACP,KAAM,WACN,KAAM,KACN,KAAM,UACR,EACA,CACE,MAAO,GACP,KAAM,iBACN,KAAM,KACN,KAAM,gBACR,EACA,CACE,MAAO,GACP,KAAM,eACN,KAAM,KACN,KAAM,cACR,EACA,CACE,MAAO,GACP,KAAM,OACN,KAAM,KACN,KAAM,MACR,EACA,CACE,MAAO,GACP,KAAM,WACN,KAAM,KACN,KAAM,UACR,EACA,CACE,MAAO,GACP,KAAM,SACN,KAAM,KACN,KAAM,QACR,EACA,CACE,MAAO,GACP,KAAM,eACN,KAAM,KACN,KAAM,cACR,EACA,CACE,MAAO,GACP,KAAM,eACN,KAAM,KACN,KAAM,cACR,EACA,CACE,MAAO,GACP,KAAM,iBACN,KAAM,KACN,KAAM,gBACR,EACA,CACE,MAAO,GACP,KAAM,eACN,KAAM,KACN,KAAM,cACR,EACA,CACE,MAAO,GACP,KAAM,YACN,KAAM,KACN,KAAM,WACR,EACA,CACE,MAAO,GACP,KAAM,QACN,KAAM,KACN,KAAM,OACR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