{"version":3,"file":"HeadlessOAuthClient.mjs","sources":["../../../../../../web/src/HeadlessOAuthClient.ts"],"sourcesContent":["import {\n  HeadlessOAuthClient as BaseHeadlessOAuthClient,\n  IConsumerSubscriptionService,\n  INetworkClient,\n  IPKCEManager,\n} from '@stytch/core';\nimport { IHeadlessOAuthClient, OneTapPositions, StytchProjectConfigurationInput } from '@stytch/core/public';\n\nimport { OneTapRenderResult } from './oneTap/GoogleOneTapClient';\nimport { OneTapProvider } from './oneTap/OneTapProvider';\n\nexport type GoogleOneTapOAuthOptions = {\n  /**\n   * The URL that Stytch redirects to after the OAuth flow is completed for a user that already exists.\n   * This URL should be an endpoint in the backend server that verifies the request by querying Stytch's /oauth/authenticate endpoint and finishes the login.\n   * The URL should be configured as a Login URL in the Stytch Dashboard's Redirect URL page.\n   * If the field is not specified, the default in the Dashboard is used.\n   */\n  login_redirect_url?: string;\n  /**\n   * The URL that Stytch redirects to after the OAuth flow is completed for a user that does not yet exist.\n   * This URL should be an endpoint in the backend server that verifies the request by querying Stytch's /oauth/authenticate endpoint and finishes the login.\n   * The URL should be configured as a Sign Up URL in the Stytch Dashboard's Redirect URL page.\n   * If the field is not specified, the default in the Dashboard is used.\n   */\n  signup_redirect_url?: string;\n  /**\n   * An optional callback function that runs when a user explicitly cancels out of the one tap flow.\n   * This callback may not be invoked immediately or at all depending on the behavior of the browser and Google's SDK.\n   */\n  onOneTapCancelled?: () => void;\n  /**\n   * Controls whether clicking outside the One Tap prompt dismisses the prompt.\n   * Defaults to true.\n   */\n  cancel_on_tap_outside?: boolean;\n};\n\ninterface IGoogleOneTapOAuthProvider {\n  /**\n   * Start an OAuth flow by showing the Google one tap prompt in the top right corner of the user's browser.\n   * You can configure this to be started by a user action (i.e Button click) or on load/render.\n   * @example\n   * const showGoogleOneTap = useCallback(()=> {\n   *   stytch.oauth.googleOneTap.start({\n   *     login_redirect_url: 'https://example.com/oauth/callback',\n   *     signup_redirect_url: 'https://example.com/oauth/callback',\n   *   })\n   * }, [stytch]);\n   * return (\n   *   <Button onClick={showGoogleOneTap}> Show Google one tap </Button>\n   * );\n   *\n   * @param options - An {@link GoogleOneTapOAuthOptions} object\n   *\n   * @returns A {@link OneTapRenderResult} object. The result object includes if the one-tap prompt\n   * was rendered, and a reason if it couldn't be rendered.\n   *\n   * @throws An Error if the one tap client cannot be created.\n   */\n  start(options?: GoogleOneTapOAuthOptions): Promise<OneTapRenderResult>;\n}\n\ntype DynamicConfig = Promise<{\n  cnameDomain: null | string;\n  pkceRequiredForOAuth: boolean;\n}>;\ntype Config = {\n  publicToken: string;\n  testAPIURL: string;\n  liveAPIURL: string;\n};\n\nexport interface IWebOAuthClient<TProjectConfiguration extends StytchProjectConfigurationInput>\n  extends IHeadlessOAuthClient<TProjectConfiguration> {\n  googleOneTap: IGoogleOneTapOAuthProvider;\n}\n\nexport class HeadlessOAuthClient<TProjectConfiguration extends StytchProjectConfigurationInput>\n  extends BaseHeadlessOAuthClient<TProjectConfiguration>\n  implements IWebOAuthClient<TProjectConfiguration>\n{\n  constructor(\n    _networkClient: INetworkClient,\n    _subscriptionService: IConsumerSubscriptionService<TProjectConfiguration>,\n    _pkceManager: IPKCEManager,\n    _dynamicConfig: DynamicConfig,\n    _config: Config,\n    private _oneTap: OneTapProvider,\n  ) {\n    super(_networkClient, _subscriptionService, _pkceManager, _dynamicConfig, _config);\n  }\n\n  private startOneTap = async (options: GoogleOneTapOAuthOptions): Promise<OneTapRenderResult> => {\n    const clientResult = await this._oneTap.createOneTapClient();\n    if (!clientResult.success) {\n      throw new Error(`One Tap could not load: ${clientResult.reason}`);\n    }\n\n    const { client } = clientResult;\n\n    const onSuccessCallback = this._oneTap.createOnSuccessHandler({\n      signupRedirectUrl: options.signup_redirect_url,\n      loginRedirectUrl: options.login_redirect_url,\n      onSuccess: this._oneTap.redirectOnSuccess,\n    });\n\n    return client.render({\n      style: {\n        position: OneTapPositions.floating,\n      },\n      onOneTapCancelled: options.onOneTapCancelled,\n      callback: onSuccessCallback,\n      cancelOnTapOutside: options.cancel_on_tap_outside,\n    });\n  };\n\n  googleOneTap: IGoogleOneTapOAuthProvider = {\n    start: this.startOneTap,\n  };\n}\n"],"names":["HeadlessOAuthClient","BaseHeadlessOAuthClient","_networkClient","_subscriptionService","_pkceManager","_dynamicConfig","_config","_oneTap","startOneTap","options","clientResult","createOneTapClient","success","Error","reason","client","onSuccessCallback","createOnSuccessHandler","signupRedirectUrl","signup_redirect_url","loginRedirectUrl","login_redirect_url","onSuccess","redirectOnSuccess","render","style","position","OneTapPositions","floating","onOneTapCancelled","callback","cancelOnTapOutside","cancel_on_tap_outside","googleOneTap","start"],"mappings":";;;;;;;;AA8EO,MAAMA,mBAAAA,SACHC,qBAAAA,CAAAA;;AAGR,IAAA,WAAA,CACEC,cAA8B,EAC9BC,oBAAyE,EACzEC,YAA0B,EAC1BC,cAA6B,EAC7BC,OAAe,EACf,OAA+B,CAC/B;AACA,QAAA,KAAK,CAACJ,cAAAA,EAAgBC,oBAAAA,EAAsBC,YAAAA,EAAcC,cAAAA,EAAgBC,eAFlEC,OAAAA,GAAAA,OAAAA;AAGV,IAAA;AAEQC,IAAAA,WAAAA,GAAc,OAAOC,OAAAA,GAAAA;AAC3B,QAAA,MAAMC,eAAe,MAAM,IAAI,CAACH,OAAO,CAACI,kBAAkB,EAAA;QAC1D,IAAI,CAACD,YAAAA,CAAaE,OAAO,EAAE;AACzB,YAAA,MAAM,IAAIC,KAAAA,CAAM,CAAC,wBAAwB,EAAEH,YAAAA,CAAaI,MAAM,CAAA,CAAE,CAAA;AAClE,QAAA;QAEA,MAAM,EAAEC,MAAM,EAAE,GAAGL,YAAAA;AAEnB,QAAA,MAAMM,oBAAoB,IAAI,CAACT,OAAO,CAACU,sBAAsB,CAAC;AAC5DC,YAAAA,iBAAAA,EAAmBT,QAAQU,mBAAmB;AAC9CC,YAAAA,gBAAAA,EAAkBX,QAAQY,kBAAkB;AAC5CC,YAAAA,SAAAA,EAAW,IAAI,CAACf,OAAO,CAACgB;AAC1B,SAAA,CAAA;QAEA,OAAOR,MAAAA,CAAOS,MAAM,CAAC;YACnBC,KAAAA,EAAO;AACLC,gBAAAA,QAAAA,EAAUC,gBAAgBC;AAC5B,aAAA;AACAC,YAAAA,iBAAAA,EAAmBpB,QAAQoB,iBAAiB;YAC5CC,QAAAA,EAAUd,iBAAAA;AACVe,YAAAA,kBAAAA,EAAoBtB,QAAQuB;AAC9B,SAAA,CAAA;IACF,CAAA;IAEAC,YAAAA,GAA2C;QACzCC,KAAAA,EAAO,IAAI,CAAC1B;KACd;AACF;;;;"}