{"version":3,"file":"index.mjs","sources":["../../../../../../../web/src/utils/index.ts"],"sourcesContent":["import {\n  EmailMagicLinksOptions,\n  MagicLinksLoginOrCreateOptions,\n  PasswordOptions,\n  PasswordResetByEmailStartOptions,\n} from '@stytch/core/public';\n\n// You can't actually validate email just from regex. RFC 5322 is pretty complex and there are some *wild*\n// rules that we would never really expect to handle, but are technically valid like:\n//   1. Emails can contain comments -> cursed(comment)@example.com\n//   2. Emails can contain symbols -> cursed{email}@example.com != cursedemail@example.com\n//   3. Dots are allowed, but not consecutively -> ab.cd@example.com is okay, but not ab..cd@example.com\n//   4. ... unless quoted -> \"ab..cd\"@example.com is okay\n//      because yes, emails can also contain quotes\n//      but then they *can't* contain comments\n//   5. Emails can also consist of spaces and tabs if you use quoting\n//\n// TL;DR: it's really complicated. I once heard a joke that the only real way to validate an email is to check\n// for the presence of an @ symbol and then see if you can send an email without it bouncing. Anyway, the below\n// regex *attempts* to make some limitations on the regex to help end-users while not being overly constrained.\n// We relaxed it as part of https://linear.app/stytch/issue/OBACK-583/email-pattern-bug-in-fe-sdk if you want some\n// historical context here.\nexport const EMAIL_REGEX = /^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~.-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/;\n\nexport const convertMagicLinkOptions = (options: EmailMagicLinksOptions = {}): MagicLinksLoginOrCreateOptions => ({\n  signup_magic_link_url: options.signupRedirectURL,\n  signup_expiration_minutes: options.signupExpirationMinutes,\n  login_magic_link_url: options.loginRedirectURL,\n  login_expiration_minutes: options.loginExpirationMinutes,\n  login_template_id: options.loginTemplateId,\n  signup_template_id: options.signupTemplateId,\n  locale: options.locale,\n});\n\nexport const convertPasswordResetOptions = (\n  email: string,\n  options: PasswordOptions = {},\n): PasswordResetByEmailStartOptions => ({\n  email: email,\n  login_redirect_url: options.loginRedirectURL,\n  login_expiration_minutes: options.loginExpirationMinutes,\n  reset_password_redirect_url: options.resetPasswordRedirectURL,\n  reset_password_expiration_minutes: options.resetPasswordExpirationMinutes,\n  reset_password_template_id: options.resetPasswordTemplateId,\n  locale: options.locale,\n});\n\nexport const debounce = <F extends (...args: Parameters<F>) => ReturnType<F>>(func: F, waitFor = 500) => {\n  let timeout: number | undefined;\n  return (...args: Parameters<F>) => {\n    clearTimeout(timeout);\n    timeout = window.setTimeout(() => func(...args), waitFor);\n  };\n};\n\n// Borrowed from Create React App's service worker registration logic\nexport const isLocalhost = () =>\n  Boolean(\n    window.location.hostname === 'localhost' ||\n      // [::1] is the IPv6 localhost address.\n      window.location.hostname === '[::1]' ||\n      // 127.0.0.1/8 is considered localhost for IPv4.\n      window.location.hostname.match(/^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/),\n  );\n\nexport type DeepRequired<T> = { [K in keyof T]: DeepRequired<T[K]> } & Required<T>;\n\nexport const hasMultipleCookies = (cookieName: string) => {\n  const cookiePairs = document.cookie ? document.cookie.split('; ') : [];\n  const matchedCookies = cookiePairs.filter((pair) => {\n    const [name] = pair.split('=');\n    return cookieName === name;\n  });\n\n  return matchedCookies.length > 1;\n};\n\nexport const noop = () => {\n  // Noop\n};\n"],"names":["EMAIL_REGEX","convertMagicLinkOptions","options","signup_magic_link_url","signupRedirectURL","signup_expiration_minutes","signupExpirationMinutes","login_magic_link_url","loginRedirectURL","login_expiration_minutes","loginExpirationMinutes","login_template_id","loginTemplateId","signup_template_id","signupTemplateId","locale","convertPasswordResetOptions","email","login_redirect_url","reset_password_redirect_url","resetPasswordRedirectURL","reset_password_expiration_minutes","resetPasswordExpirationMinutes","reset_password_template_id","resetPasswordTemplateId","debounce","func","waitFor","timeout","args","clearTimeout","window","setTimeout","isLocalhost","Boolean","location","hostname","match","hasMultipleCookies","cookieName","cookiePairs","document","cookie","split","matchedCookies","filter","pair","name","length","noop"],"mappings":"AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,cAAc;MA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