{
  "version": 3,
  "sources": ["../../src/index.ts"],
  "sourcesContent": ["import {\n  DeviceVerificationEventEmit,\n  Extension,\n  LoginWithEmailOTPConfiguration,\n  LoginWithEmailOTPEventEmit,\n  LoginWithEmailOTPEventHandlers,\n  LoginWithMagicLinkConfiguration,\n  LoginWithMagicLinkEventHandlers,\n  LoginWithSmsConfiguration,\n  MagicPayloadMethod,\n  UpdateEmailConfiguration,\n} from '@magic-sdk/commons';\nimport { ViewController, isMajorVersionAtLeast } from '@magic-sdk/provider';\nimport type localForage from 'localforage';\n\ntype ConstructorOf<C> = { new (...args: any[]): C };\n\ninterface SDKEnvironment {\n  sdkName: 'magic-sdk' | '@magic-sdk/react-native' | '@magic-sdk/react-native-bare' | '@magic-sdk/react-native-expo';\n  version: string;\n  platform: 'web' | 'react-native';\n  defaultEndpoint: string;\n  ViewController: ConstructorOf<ViewController>;\n  configureStorage: () => Promise<typeof localForage>;\n  bundleId?: string | null;\n}\n\nconst SDKEnvironment: SDKEnvironment = {} as any;\n\ntype UpdateEmailEventHandlers = {\n  [UpdateEmailEventsOnReceived.EmailSent]: () => void;\n  [UpdateEmailEventsOnReceived.EmailNotDeliverable]: () => void;\n  [UpdateEmailEventsOnReceived.OldEmailConfirmed]: () => void;\n  [UpdateEmailEventsOnReceived.NewEmailConfirmed]: () => void;\n  [UpdateEmailEventsEmit.Retry]: () => void;\n};\n\nexport enum UpdateEmailEventsEmit {\n  Retry = 'retry',\n}\n\nexport enum UpdateEmailEventsOnReceived {\n  EmailSent = 'email-sent',\n  EmailNotDeliverable = 'email-not-deliverable',\n  OldEmailConfirmed = 'old-email-confirmed',\n  NewEmailConfirmed = 'new-email-confirmed',\n}\n\nexport class AuthExtension extends Extension.Internal<'auth', any> {\n  name = 'auth' as const;\n  config: any = {};\n\n  /**\n   * Initiate the \"magic link\" login flow for a user. If the flow is successful,\n   * this method will return a Decentralized ID token (with a default lifespan\n   * of 15 minutes).\n   */\n  public loginWithMagicLink(configuration: LoginWithMagicLinkConfiguration) {\n    if (\n      (SDKEnvironment.sdkName === '@magic-sdk/react-native' ||\n        SDKEnvironment.sdkName === '@magic-sdk/react-native-bare' ||\n        SDKEnvironment.sdkName === '@magic-sdk/react-native-expo') &&\n      isMajorVersionAtLeast(SDKEnvironment.version, 19)\n    ) {\n      throw new Error(\n        'loginWithMagicLink() is deprecated for this package, please utlize a passcode method like loginWithSMS or loginWithEmailOTP instead.',\n      );\n    }\n    const { email, showUI = true, redirectURI } = configuration;\n\n    const requestPayload = this.utils.createJsonRpcRequestPayload(\n      this.sdk.testMode ? MagicPayloadMethod.LoginWithMagicLinkTestMode : MagicPayloadMethod.LoginWithMagicLink,\n      [{ email, showUI, redirectURI }],\n    );\n    return this.request<string | null, LoginWithMagicLinkEventHandlers>(requestPayload);\n  }\n\n  /**\n   * Initiate an SMS login flow for a user. If successful,\n   * this method will return a Decenteralized ID token (with a default lifespan\n   * of 15 minutes)\n   */\n  public loginWithSMS(configuration: LoginWithSmsConfiguration) {\n    const { phoneNumber } = configuration;\n    const requestPayload = this.utils.createJsonRpcRequestPayload(\n      this.sdk.testMode ? MagicPayloadMethod.LoginWithSmsTestMode : MagicPayloadMethod.LoginWithSms,\n      [{ phoneNumber, showUI: true }],\n    );\n    return this.request<string | null>(requestPayload);\n  }\n\n  /**\n   * Initiate an Email with OTP login flow for a user. If successful,\n   * this method will return a Decenteralized ID token (with a default lifespan\n   * of 15 minutes)\n   */\n  public loginWithEmailOTP(configuration: LoginWithEmailOTPConfiguration) {\n    const { email, showUI, deviceCheckUI } = configuration;\n    const requestPayload = this.utils.createJsonRpcRequestPayload(\n      this.sdk.testMode ? MagicPayloadMethod.LoginWithEmailOTPTestMode : MagicPayloadMethod.LoginWithEmailOTP,\n      [{ email, showUI, deviceCheckUI }],\n    );\n    const handle = this.request<string | null, LoginWithEmailOTPEventHandlers>(requestPayload);\n    if (!deviceCheckUI && handle) {\n      handle.on(DeviceVerificationEventEmit.Retry, () => {\n        this.createIntermediaryEvent(DeviceVerificationEventEmit.Retry, requestPayload.id as any)();\n      });\n    }\n    if (!showUI && handle) {\n      handle.on(LoginWithEmailOTPEventEmit.VerifyEmailOtp, (otp: string) => {\n        this.createIntermediaryEvent(LoginWithEmailOTPEventEmit.VerifyEmailOtp, requestPayload.id as any)(otp);\n      });\n      handle.on(LoginWithEmailOTPEventEmit.Cancel, () => {\n        this.createIntermediaryEvent(LoginWithEmailOTPEventEmit.Cancel, requestPayload.id as any)();\n      });\n    }\n    return handle;\n  }\n\n  /**\n   * Log a user in with a special one-time-use credential token. This is\n   * currently used during magic link flows with a configured redirect to\n   * hydrate the user session at the end of the flow. If the flow is successful,\n   * this method will return a Decentralized ID token (with a default lifespan\n   * of 15 minutes).\n   *\n   * If no argument is provided, a credential is automatically parsed from\n   * `window.location.search`.\n   */\n  public loginWithCredential(credentialOrQueryString?: string) {\n    let credentialResolved = credentialOrQueryString ?? '';\n\n    if (!credentialOrQueryString) {\n      credentialResolved = window.location.search;\n\n      // Remove the query from the redirect callback as a precaution.\n      const urlWithoutQuery = window.location.origin + window.location.pathname;\n      window.history.replaceState(null, '', urlWithoutQuery);\n    }\n\n    const requestPayload = this.utils.createJsonRpcRequestPayload(\n      this.sdk.testMode ? MagicPayloadMethod.LoginWithCredentialTestMode : MagicPayloadMethod.LoginWithCredential,\n      [credentialResolved],\n    );\n\n    return this.request<string | null>(requestPayload);\n  }\n\n  // Custom Auth\n  public setAuthorizationToken(jwt: string) {\n    const requestPayload = this.utils.createJsonRpcRequestPayload(MagicPayloadMethod.SetAuthorizationToken, [{ jwt }]);\n    return this.request<boolean>(requestPayload);\n  }\n\n  public updateEmailWithUI(configuration: UpdateEmailConfiguration) {\n    const { email, showUI = true } = configuration;\n    const requestPayload = this.utils.createJsonRpcRequestPayload(\n      this.sdk.testMode ? MagicPayloadMethod.UpdateEmailTestMode : MagicPayloadMethod.UpdateEmail,\n      [{ email, showUI }],\n    );\n    return this.request<string | null, UpdateEmailEventHandlers>(requestPayload);\n  }\n}\n\nex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"names": ["DeviceVerificationEventEmit", "Extension", "LoginWithEmailOTPEventEmit", "MagicPayloadMethod", "isMajorVersionAtLeast", "SDKEnvironment", "UpdateEmailEventsEmit", "UpdateEmailEventsOnReceived", "AuthExtension", "configuration", "email", "showUI", "redirectURI", "requestPayload", "phoneNumber", "deviceCheckUI", "handle", "otp", "credentialOrQueryString", "credentialResolved", "urlWithoutQuery", "jwt"]
}
