@stytch/vanilla-js 4.9.0 → 4.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,99 @@
1
1
  import { StateChangeRegisterFunction } from "@stytch/core";
2
- import { IHeadlessB2BDiscoveryClient, IHeadlessB2BMagicLinksClient, IHeadlessB2BMemberClient, IHeadlessB2BSelfClient, IHeadlessB2BOAuthClient, IHeadlessB2BOrganizationClient, IHeadlessB2BOTPsClient, IHeadlessB2BTOTPsClient, IHeadlessB2BSessionClient, IHeadlessB2BSSOClient, IHeadlessB2BRecoveryCodesClient, IHeadlessB2BRBACClient, StytchClientOptions, B2BState, IHeadlessB2BPasswordClient } from "@stytch/core/public";
2
+ import { IHeadlessB2BDiscoveryClient, IHeadlessB2BMagicLinksClient, IHeadlessB2BMemberClient, IHeadlessB2BSelfClient, IHeadlessB2BOrganizationClient, IHeadlessB2BOTPsClient, IHeadlessB2BTOTPsClient, IHeadlessB2BSessionClient, IHeadlessB2BSSOClient, IHeadlessB2BRecoveryCodesClient, IHeadlessB2BRBACClient, StytchClientOptions, B2BState, IHeadlessB2BPasswordClient, IHeadlessB2BOAuthClient } from "@stytch/core/public";
3
+ import { PromptMomentNotification } from "google-one-tap";
4
+ type OneTapNotShownReason = ReturnType<PromptMomentNotification["getNotDisplayedReason"]> | ReturnType<PromptMomentNotification["getSkippedReason"]>;
5
+ type OneTapRenderResult = {
6
+ success: true;
7
+ } | {
8
+ success: false;
9
+ reason: OneTapNotShownReason;
10
+ };
11
+ declare global {
12
+ // The telemetry.js script will set a global function called GetTelemetryID on the window
13
+ // object. This interface is allows us to call that function while pleasing the TypeScript
14
+ // compiler.
15
+ interface Window {
16
+ GetTelemetryID: (publicToken: string, submitURL: string) => Promise<string>;
17
+ }
18
+ }
19
+ type B2BGoogleOneTapDiscoveryOAuthOptions = {
20
+ /**
21
+ * The URL that Stytch redirects to after the Google One Tap discovery flow is completed.
22
+ * This should be a URL that verifies the request by querying Stytch's /oauth/discovery/authenticate endpoint.
23
+ * If this value is not passed, the default discovery redirect URL that you set in your Dashboard is used.
24
+ * If you have not set a default discovery redirect URL, an error is returned.
25
+ */
26
+ discovery_redirect_url?: string;
27
+ };
28
+ type B2BGoogleOneTapOAuthOptions = {
29
+ /**
30
+ * The ID of the organization that the end user is logging in to.
31
+ */
32
+ organization_id: string;
33
+ /**
34
+ * The URL that Stytch redirects to after the Google One Tap flow is completed for a member who already exists.
35
+ * This should be a URL that verifies the request by querying Stytch's /oauth/authenticate endpoint.
36
+ * If this value is not passed, the default login redirect URL that you set in your Dashboard is used.
37
+ * If you have not set a default login redirect URL, an error is returned.
38
+ */
39
+ login_redirect_url?: string;
40
+ /**
41
+ * The URL that Stytch redirects to after the Google One Tap flow is completed for a member who does not yet exist.
42
+ * This should be a URL that verifies the request by querying Stytch's /oauth/authenticate endpoint.
43
+ * If this value is not passed, the default signup redirect URL that you set in your Dashboard is used.
44
+ * If you have not set a default signup redirect URL, an error is returned.
45
+ */
46
+ signup_redirect_url?: string;
47
+ };
48
+ interface IB2BGoogleOneTapOAuthProvider {
49
+ discovery: {
50
+ /**
51
+ * Start a discovery OAuth flow by showing the Google one tap prompt in the top right corner of the user's browser.
52
+ * You can configure this to be started by a user action (i.e Button click) or on load/render.
53
+ * @example
54
+ * const showGoogleOneTap = useCallback(()=> {
55
+ * stytch.oauth.googleOneTap.discovery.start({
56
+ * discovery_redirect_url: 'https://example.com/oauth/callback',
57
+ * })
58
+ * }, [stytch]);
59
+ * return (
60
+ * <Button onClick={showGoogleOneTap}> Show Google one tap </Button>
61
+ * );
62
+ *
63
+ * @param options - A {@link B2BGoogleOneTapDiscoveryOAuthOptions} object
64
+ *
65
+ * @returns A {@link OneTapRenderResult} object. The result object includes if the one-tap prompt
66
+ * was rendered, and a reason if it couldn't be rendered.
67
+ *
68
+ * @throws An Error if the one tap client cannot be created.
69
+ */
70
+ start(options?: B2BGoogleOneTapDiscoveryOAuthOptions): Promise<OneTapRenderResult>;
71
+ };
72
+ /**
73
+ * Start an OAuth flow by showing the Google one tap prompt in the top right corner of the user's browser.
74
+ * You can configure this to be started by a user action (i.e Button click) or on load/render.
75
+ * @example
76
+ * const showGoogleOneTap = useCallback(()=> {
77
+ * stytch.oauth.googleOneTap.start({
78
+ * organization_id: 'organization-test-123',
79
+ * })
80
+ * }, [stytch]);
81
+ * return (
82
+ * <Button onClick={showGoogleOneTap}> Show Google one tap </Button>
83
+ * );
84
+ *
85
+ * @param options - A {@link B2BGoogleOneTapOAuthOptions} object
86
+ *
87
+ * @returns A {@link OneTapRenderResult} object. The result object includes if the one-tap prompt
88
+ * was rendered, and a reason if it couldn't be rendered.
89
+ *
90
+ * @throws An Error if the one tap client cannot be created.
91
+ */
92
+ start(options?: B2BGoogleOneTapOAuthOptions): Promise<OneTapRenderResult>;
93
+ }
94
+ interface IWebB2BOAuthClient extends IHeadlessB2BOAuthClient {
95
+ googleOneTap: IB2BGoogleOneTapOAuthProvider;
96
+ }
3
97
  /**
4
98
  * A headless client used for invoking Stytch's B2B APIs.
5
99
  * The Stytch Headless Client can be used as a drop-in solution for authentication and session management.
@@ -16,6 +110,9 @@ declare class StytchB2BHeadlessClient {
16
110
  private readonly _subscriptionService;
17
111
  private readonly _sessionManager;
18
112
  private readonly _networkClient;
113
+ // The _apiNetworkClient uses the API instead of web-backend as the SDK backend URL. We choose between the test and
114
+ // live URL based on the public token.
115
+ private readonly _apiNetworkClient;
19
116
  private readonly _dataLayer;
20
117
  private readonly _stateChangeClient;
21
118
  // External API Clients
@@ -25,7 +122,7 @@ declare class StytchB2BHeadlessClient {
25
122
  member: IHeadlessB2BMemberClient;
26
123
  self: IHeadlessB2BSelfClient;
27
124
  organization: IHeadlessB2BOrganizationClient;
28
- oauth: IHeadlessB2BOAuthClient;
125
+ oauth: IWebB2BOAuthClient;
29
126
  sso: IHeadlessB2BSSOClient;
30
127
  discovery: IHeadlessB2BDiscoveryClient;
31
128
  passwords: IHeadlessB2BPasswordClient;
@@ -1,5 +1,99 @@
1
1
  import { StateChangeRegisterFunction } from "@stytch/core";
2
- import { IHeadlessB2BDiscoveryClient, IHeadlessB2BMagicLinksClient, IHeadlessB2BMemberClient, IHeadlessB2BSelfClient, IHeadlessB2BOAuthClient, IHeadlessB2BOrganizationClient, IHeadlessB2BOTPsClient, IHeadlessB2BTOTPsClient, IHeadlessB2BSessionClient, IHeadlessB2BSSOClient, IHeadlessB2BRecoveryCodesClient, IHeadlessB2BRBACClient, StytchClientOptions, B2BState, IHeadlessB2BPasswordClient } from "@stytch/core/public";
2
+ import { IHeadlessB2BDiscoveryClient, IHeadlessB2BMagicLinksClient, IHeadlessB2BMemberClient, IHeadlessB2BSelfClient, IHeadlessB2BOrganizationClient, IHeadlessB2BOTPsClient, IHeadlessB2BTOTPsClient, IHeadlessB2BSessionClient, IHeadlessB2BSSOClient, IHeadlessB2BRecoveryCodesClient, IHeadlessB2BRBACClient, StytchClientOptions, B2BState, IHeadlessB2BPasswordClient, IHeadlessB2BOAuthClient } from "@stytch/core/public";
3
+ import { PromptMomentNotification } from "google-one-tap";
4
+ type OneTapNotShownReason = ReturnType<PromptMomentNotification["getNotDisplayedReason"]> | ReturnType<PromptMomentNotification["getSkippedReason"]>;
5
+ type OneTapRenderResult = {
6
+ success: true;
7
+ } | {
8
+ success: false;
9
+ reason: OneTapNotShownReason;
10
+ };
11
+ declare global {
12
+ // The telemetry.js script will set a global function called GetTelemetryID on the window
13
+ // object. This interface is allows us to call that function while pleasing the TypeScript
14
+ // compiler.
15
+ interface Window {
16
+ GetTelemetryID: (publicToken: string, submitURL: string) => Promise<string>;
17
+ }
18
+ }
19
+ type B2BGoogleOneTapDiscoveryOAuthOptions = {
20
+ /**
21
+ * The URL that Stytch redirects to after the Google One Tap discovery flow is completed.
22
+ * This should be a URL that verifies the request by querying Stytch's /oauth/discovery/authenticate endpoint.
23
+ * If this value is not passed, the default discovery redirect URL that you set in your Dashboard is used.
24
+ * If you have not set a default discovery redirect URL, an error is returned.
25
+ */
26
+ discovery_redirect_url?: string;
27
+ };
28
+ type B2BGoogleOneTapOAuthOptions = {
29
+ /**
30
+ * The ID of the organization that the end user is logging in to.
31
+ */
32
+ organization_id: string;
33
+ /**
34
+ * The URL that Stytch redirects to after the Google One Tap flow is completed for a member who already exists.
35
+ * This should be a URL that verifies the request by querying Stytch's /oauth/authenticate endpoint.
36
+ * If this value is not passed, the default login redirect URL that you set in your Dashboard is used.
37
+ * If you have not set a default login redirect URL, an error is returned.
38
+ */
39
+ login_redirect_url?: string;
40
+ /**
41
+ * The URL that Stytch redirects to after the Google One Tap flow is completed for a member who does not yet exist.
42
+ * This should be a URL that verifies the request by querying Stytch's /oauth/authenticate endpoint.
43
+ * If this value is not passed, the default signup redirect URL that you set in your Dashboard is used.
44
+ * If you have not set a default signup redirect URL, an error is returned.
45
+ */
46
+ signup_redirect_url?: string;
47
+ };
48
+ interface IB2BGoogleOneTapOAuthProvider {
49
+ discovery: {
50
+ /**
51
+ * Start a discovery OAuth flow by showing the Google one tap prompt in the top right corner of the user's browser.
52
+ * You can configure this to be started by a user action (i.e Button click) or on load/render.
53
+ * @example
54
+ * const showGoogleOneTap = useCallback(()=> {
55
+ * stytch.oauth.googleOneTap.discovery.start({
56
+ * discovery_redirect_url: 'https://example.com/oauth/callback',
57
+ * })
58
+ * }, [stytch]);
59
+ * return (
60
+ * <Button onClick={showGoogleOneTap}> Show Google one tap </Button>
61
+ * );
62
+ *
63
+ * @param options - A {@link B2BGoogleOneTapDiscoveryOAuthOptions} object
64
+ *
65
+ * @returns A {@link OneTapRenderResult} object. The result object includes if the one-tap prompt
66
+ * was rendered, and a reason if it couldn't be rendered.
67
+ *
68
+ * @throws An Error if the one tap client cannot be created.
69
+ */
70
+ start(options?: B2BGoogleOneTapDiscoveryOAuthOptions): Promise<OneTapRenderResult>;
71
+ };
72
+ /**
73
+ * Start an OAuth flow by showing the Google one tap prompt in the top right corner of the user's browser.
74
+ * You can configure this to be started by a user action (i.e Button click) or on load/render.
75
+ * @example
76
+ * const showGoogleOneTap = useCallback(()=> {
77
+ * stytch.oauth.googleOneTap.start({
78
+ * organization_id: 'organization-test-123',
79
+ * })
80
+ * }, [stytch]);
81
+ * return (
82
+ * <Button onClick={showGoogleOneTap}> Show Google one tap </Button>
83
+ * );
84
+ *
85
+ * @param options - A {@link B2BGoogleOneTapOAuthOptions} object
86
+ *
87
+ * @returns A {@link OneTapRenderResult} object. The result object includes if the one-tap prompt
88
+ * was rendered, and a reason if it couldn't be rendered.
89
+ *
90
+ * @throws An Error if the one tap client cannot be created.
91
+ */
92
+ start(options?: B2BGoogleOneTapOAuthOptions): Promise<OneTapRenderResult>;
93
+ }
94
+ interface IWebB2BOAuthClient extends IHeadlessB2BOAuthClient {
95
+ googleOneTap: IB2BGoogleOneTapOAuthProvider;
96
+ }
3
97
  /**
4
98
  * A headless client used for invoking Stytch's B2B APIs.
5
99
  * The Stytch Headless Client can be used as a drop-in solution for authentication and session management.
@@ -16,6 +110,9 @@ declare class StytchB2BHeadlessClient {
16
110
  private readonly _subscriptionService;
17
111
  private readonly _sessionManager;
18
112
  private readonly _networkClient;
113
+ // The _apiNetworkClient uses the API instead of web-backend as the SDK backend URL. We choose between the test and
114
+ // live URL based on the public token.
115
+ private readonly _apiNetworkClient;
19
116
  private readonly _dataLayer;
20
117
  private readonly _stateChangeClient;
21
118
  // External API Clients
@@ -25,7 +122,7 @@ declare class StytchB2BHeadlessClient {
25
122
  member: IHeadlessB2BMemberClient;
26
123
  self: IHeadlessB2BSelfClient;
27
124
  organization: IHeadlessB2BOrganizationClient;
28
- oauth: IHeadlessB2BOAuthClient;
125
+ oauth: IWebB2BOAuthClient;
29
126
  sso: IHeadlessB2BSSOClient;
30
127
  discovery: IHeadlessB2BDiscoveryClient;
31
128
  passwords: IHeadlessB2BPasswordClient;