{"version":3,"file":"getTranslatedError.mjs","sources":["../../../../../../../web/src/utils/getTranslatedError.ts"],"sourcesContent":["import { MessageDescriptor } from '@lingui/core';\nimport { msg } from '@lingui/core/macro';\nimport { StytchAPIError } from '@stytch/core/public';\n\nimport { extractErrorType } from './extractErrorType';\n\nconst errorMessages = {\n  invalid_email: msg({ id: 'error.invalidEmail', message: 'Email format is invalid.' }),\n  invalid_phone_number: msg({\n    id: 'error.invalidPhoneNumber',\n    message: 'Phone number format is invalid. Ensure the phone number is in the E.164 format.',\n  }),\n  unsubscribed_phone_number: msg({\n    id: 'error.unsubscribedPhoneNumber',\n    message:\n      \"Phone number is unsubscribed. User has unsubscribed. Resubscribe by texting 'START' before messages can be sent.\",\n  }),\n  inactive_email: msg({\n    id: 'error.inactiveEmail',\n    message:\n      'The email address is marked as inactive. Please try another email address, or contact your admin if you think this is a mistake.',\n  }),\n  unauthorized_credentials: msg({ id: 'error.unauthorizedCredentials', message: 'Unauthorized credentials.' }),\n  user_unauthenticated: msg({\n    id: 'error.userUnauthenticated',\n    message: 'Must have an active session to call this method. Have you logged in yet?',\n  }),\n  email_not_found: msg({ id: 'error.emailNotFound', message: 'Email not found.' }),\n  unable_to_auth_magic_link: msg({\n    id: 'error.unableToAuthMagicLink',\n    message:\n      'The magic link could not be authenticated because it was either already used or expired. Please try again.',\n  }),\n  no_user_password: msg({ id: 'error.noUserPassword', message: 'Password not found for this user. Please try again.' }),\n  breached_password: msg({\n    id: 'error.breachedPassword',\n    message: 'Password appears in the list of breached passwords and must be reset.',\n  }),\n  reset_password: msg({ id: 'error.resetPassword', message: 'Password must be reset.' }),\n  oauth_token_not_found: msg({ id: 'error.oauthTokenNotFound', message: 'OAuth Token could not be found.' }),\n  invalid_code: msg({ id: 'error.invalidCode', message: 'Code format is invalid, please try again.' }),\n  member_password_not_found: msg({ id: 'error.memberPasswordNotFound', message: 'Member password not found.' }),\n  oauth_flow_callback_error: msg({\n    id: 'error.oauthFlowCallbackError',\n    message: 'An error was encountered in the callback of the OAuth flow. Please try again.',\n  }),\n  unauthorized_action: msg({ id: 'error.unauthorizedAction', message: 'Unauthorized action.' }),\n  user_lock_limit_reached: msg({\n    id: 'error.userLockLimitReached',\n    message: 'Too many failed authentication attempts. Please try again later.',\n  }),\n  invalid_session_token: msg({ id: 'error.invalidSessionToken', message: 'Invalid session token.' }),\n  session_not_found: msg({ id: 'error.sessionNotFound', message: 'Session not found.' }),\n  invalid_phone_number_country_code: msg({\n    id: 'error.invalidPhoneNumberCountryCode',\n    message: \"The phone number's country code is invalid, unsupported, or disabled.\",\n  }),\n  otp_code_not_found: msg({ id: 'error.otpCodeNotFound', message: 'Invalid passcode, please try again.' }),\n  duplicate_member_phone_number: msg({\n    id: 'error.duplicatePhoneNumber',\n    message: 'A member with the specified phone number already exists for this organization.',\n  }),\n} as const;\n\n/**\n * This method is meant to be a catch all for errors that don't require special handling.\n * It will return a translated error message for the error type.\n * If the error type is not included here, it will return the error message as an untranslated string.\n */\nexport const getTranslatedError = (error: StytchAPIError, t: (descriptor: MessageDescriptor) => string) => {\n  const errorType = extractErrorType(error);\n  const messageDescriptor = errorMessages[errorType as keyof typeof errorMessages];\n  if (messageDescriptor) {\n    return t(messageDescriptor);\n  }\n  return error.error_message;\n};\n"],"names":["errorMessages","invalid_email","invalid_phone_number","unsubscribed_phone_number","inactive_email","unauthorized_credentials","user_unauthenticated","email_not_found","unable_to_auth_magic_link","no_user_password","breached_password","reset_password","oauth_token_not_found","invalid_code","member_password_not_found","oauth_flow_callback_error","unauthorized_action","user_lock_limit_reached","invalid_session_token","session_not_found","invalid_phone_number_country_code","otp_code_not_found","duplicate_member_phone_number","getTranslatedError","error","t","errorType","extractErrorType","messageDescriptor","error_message"],"mappings":";;AAMA,MAAMA,aAAAA,GAAgB;IACpBC,aAAa,EAAA;;;;IACbC,oBAAoB,EAAA;;;;IAIpBC,yBAAyB,EAAA;;;;IAKzBC,cAAc,EAAA;;;;IAKdC,wBAAwB,EAAA;;;;IACxBC,oBAAoB,EAAA;;;;IAIpBC,eAAe,EAAA;;;;IACfC,yBAAyB,EAAA;;;;IAKzBC,gBAAgB,EAAA;;;;IAChBC,iBAAiB,EAAA;;;;IAIjBC,cAAc,EAAA;;;;IACdC,qBAAqB,EAAA;;;;IACrBC,YAAY,EAAA;;;;IACZC,yBAAyB,EAAA;;;;IACzBC,yBAAyB,EAAA;;;;IAIzBC,mBAAmB,EAAA;;;;IACnBC,uBAAuB,EAAA;;;;IAIvBC,qBAAqB,EAAA;;;;IACrBC,iBAAiB,EAAA;;;;IACjBC,iCAAiC,EAAA;;;;IAIjCC,kBAAkB,EAAA;;;;IAClBC,6BAA6B,EAAA;;;;AAI/B,CAAA;AAEA;;;;AAIC,IACM,MAAMC,kBAAAA,GAAqB,CAACC,KAAAA,EAAuBC,CAAAA,GAAAA;AACxD,IAAA,MAAMC,YAAYC,gBAAAA,CAAiBH,KAAAA,CAAAA;IACnC,MAAMI,iBAAAA,GAAoB5B,aAAa,CAAC0B,SAAAA,CAAwC;AAChF,IAAA,IAAIE,iBAAAA,EAAmB;AACrB,QAAA,OAAOH,CAAAA,CAAEG,iBAAAA,CAAAA;AACX,IAAA;AACA,IAAA,OAAOJ,MAAMK,aAAa;AAC5B;;;;"}