@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @stytch/vanilla-js
2
2
 
3
+ ## 4.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 807fcec: B2B Google One Tap is now available in the Javascript SDK and pre-built UI components!
8
+
9
+ You can enable One Tap in the UI components by editing the `B2BOAuthOptions` in your UI config - we've updated the `providers` type to accommodate One Tap. If you add `{ type: 'google', one_tap: true }` to your `providers` list, we'll show the Google One Tap prompt in the top right of the user's browser.
10
+
11
+ In the Javascript SDK, you can use the `stytch.oauth.googleOneTap.start()` and `stytch.oauth.googleOneTap.discovery.start()` methods to render the One Tap prompt, depending on if you are using an organization-specific or discovery flow.
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [807fcec]
16
+ - @stytch/core@2.14.0
17
+
18
+ ## 4.9.1
19
+
20
+ ### Patch Changes
21
+
22
+ - 6fb5732: Ensure we display friendly error messages where possible
23
+ - Updated dependencies [0055ad8]
24
+ - @stytch/core@2.13.1
25
+
3
26
  ## 4.9.0
4
27
 
5
28
  ### Minor Changes
@@ -1,5 +1,102 @@
1
1
  import { StateChangeRegisterFunction } from "@stytch/core";
2
- import { IHeadlessB2BDiscoveryClient, IHeadlessB2BMagicLinksClient, IHeadlessB2BMemberClient, IHeadlessB2BSelfClient, IHeadlessB2BOAuthClient, IHeadlessB2BOrganizationClient, IHeadlessB2BOTPsClient, IHeadlessB2BTOTPsClient, IHeadlessB2BSessionClient, IHeadlessB2BSSOClient, IHeadlessB2BRecoveryCodesClient, IHeadlessB2BRBACClient, StytchClientOptions, B2BState, IHeadlessB2BPasswordClient, Callbacks, StyleConfig, StytchB2BUIConfig } 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 { Callbacks as Callbacks$0 } from "@stytch/core/public";
4
+ import { StyleConfig as StyleConfig$0 } from "@stytch/core/public";
5
+ import { StytchB2BUIConfig as StytchB2BUIConfig$0 } from "@stytch/core/public";
6
+ import { PromptMomentNotification } from "google-one-tap";
7
+ type OneTapNotShownReason = ReturnType<PromptMomentNotification["getNotDisplayedReason"]> | ReturnType<PromptMomentNotification["getSkippedReason"]>;
8
+ type OneTapRenderResult = {
9
+ success: true;
10
+ } | {
11
+ success: false;
12
+ reason: OneTapNotShownReason;
13
+ };
14
+ declare global {
15
+ // The telemetry.js script will set a global function called GetTelemetryID on the window
16
+ // object. This interface is allows us to call that function while pleasing the TypeScript
17
+ // compiler.
18
+ interface Window {
19
+ GetTelemetryID: (publicToken: string, submitURL: string) => Promise<string>;
20
+ }
21
+ }
22
+ type B2BGoogleOneTapDiscoveryOAuthOptions = {
23
+ /**
24
+ * The URL that Stytch redirects to after the Google One Tap discovery flow is completed.
25
+ * This should be a URL that verifies the request by querying Stytch's /oauth/discovery/authenticate endpoint.
26
+ * If this value is not passed, the default discovery redirect URL that you set in your Dashboard is used.
27
+ * If you have not set a default discovery redirect URL, an error is returned.
28
+ */
29
+ discovery_redirect_url?: string;
30
+ };
31
+ type B2BGoogleOneTapOAuthOptions = {
32
+ /**
33
+ * The ID of the organization that the end user is logging in to.
34
+ */
35
+ organization_id: string;
36
+ /**
37
+ * The URL that Stytch redirects to after the Google One Tap flow is completed for a member who already exists.
38
+ * This should be a URL that verifies the request by querying Stytch's /oauth/authenticate endpoint.
39
+ * If this value is not passed, the default login redirect URL that you set in your Dashboard is used.
40
+ * If you have not set a default login redirect URL, an error is returned.
41
+ */
42
+ login_redirect_url?: string;
43
+ /**
44
+ * The URL that Stytch redirects to after the Google One Tap flow is completed for a member who does not yet exist.
45
+ * This should be a URL that verifies the request by querying Stytch's /oauth/authenticate endpoint.
46
+ * If this value is not passed, the default signup redirect URL that you set in your Dashboard is used.
47
+ * If you have not set a default signup redirect URL, an error is returned.
48
+ */
49
+ signup_redirect_url?: string;
50
+ };
51
+ interface IB2BGoogleOneTapOAuthProvider {
52
+ discovery: {
53
+ /**
54
+ * Start a discovery OAuth flow by showing the Google one tap prompt in the top right corner of the user's browser.
55
+ * You can configure this to be started by a user action (i.e Button click) or on load/render.
56
+ * @example
57
+ * const showGoogleOneTap = useCallback(()=> {
58
+ * stytch.oauth.googleOneTap.discovery.start({
59
+ * discovery_redirect_url: 'https://example.com/oauth/callback',
60
+ * })
61
+ * }, [stytch]);
62
+ * return (
63
+ * <Button onClick={showGoogleOneTap}> Show Google one tap </Button>
64
+ * );
65
+ *
66
+ * @param options - A {@link B2BGoogleOneTapDiscoveryOAuthOptions} object
67
+ *
68
+ * @returns A {@link OneTapRenderResult} object. The result object includes if the one-tap prompt
69
+ * was rendered, and a reason if it couldn't be rendered.
70
+ *
71
+ * @throws An Error if the one tap client cannot be created.
72
+ */
73
+ start(options?: B2BGoogleOneTapDiscoveryOAuthOptions): Promise<OneTapRenderResult>;
74
+ };
75
+ /**
76
+ * Start an OAuth flow by showing the Google one tap prompt in the top right corner of the user's browser.
77
+ * You can configure this to be started by a user action (i.e Button click) or on load/render.
78
+ * @example
79
+ * const showGoogleOneTap = useCallback(()=> {
80
+ * stytch.oauth.googleOneTap.start({
81
+ * organization_id: 'organization-test-123',
82
+ * })
83
+ * }, [stytch]);
84
+ * return (
85
+ * <Button onClick={showGoogleOneTap}> Show Google one tap </Button>
86
+ * );
87
+ *
88
+ * @param options - A {@link B2BGoogleOneTapOAuthOptions} object
89
+ *
90
+ * @returns A {@link OneTapRenderResult} object. The result object includes if the one-tap prompt
91
+ * was rendered, and a reason if it couldn't be rendered.
92
+ *
93
+ * @throws An Error if the one tap client cannot be created.
94
+ */
95
+ start(options?: B2BGoogleOneTapOAuthOptions): Promise<OneTapRenderResult>;
96
+ }
97
+ interface IWebB2BOAuthClient extends IHeadlessB2BOAuthClient {
98
+ googleOneTap: IB2BGoogleOneTapOAuthProvider;
99
+ }
3
100
  /**
4
101
  * A headless client used for invoking Stytch's B2B APIs.
5
102
  * The Stytch Headless Client can be used as a drop-in solution for authentication and session management.
@@ -16,6 +113,9 @@ declare class StytchB2BHeadlessClient {
16
113
  private readonly _subscriptionService;
17
114
  private readonly _sessionManager;
18
115
  private readonly _networkClient;
116
+ // The _apiNetworkClient uses the API instead of web-backend as the SDK backend URL. We choose between the test and
117
+ // live URL based on the public token.
118
+ private readonly _apiNetworkClient;
19
119
  private readonly _dataLayer;
20
120
  private readonly _stateChangeClient;
21
121
  // External API Clients
@@ -25,7 +125,7 @@ declare class StytchB2BHeadlessClient {
25
125
  member: IHeadlessB2BMemberClient;
26
126
  self: IHeadlessB2BSelfClient;
27
127
  organization: IHeadlessB2BOrganizationClient;
28
- oauth: IHeadlessB2BOAuthClient;
128
+ oauth: IWebB2BOAuthClient;
29
129
  sso: IHeadlessB2BSSOClient;
30
130
  discovery: IHeadlessB2BDiscoveryClient;
31
131
  passwords: IHeadlessB2BPasswordClient;
@@ -81,9 +181,9 @@ declare class StytchB2BUIClient extends StytchB2BHeadlessClient {
81
181
  */
82
182
  mount({ elementId, styles, callbacks, config }: {
83
183
  elementId: string;
84
- styles?: StyleConfig;
85
- callbacks?: Callbacks;
86
- config: StytchB2BUIConfig;
184
+ styles?: StyleConfig$0;
185
+ callbacks?: Callbacks$0;
186
+ config: StytchB2BUIConfig$0;
87
187
  }): void;
88
188
  }
89
189
  export { StytchB2BUIClient };
@@ -1,5 +1,102 @@
1
1
  import { StateChangeRegisterFunction } from "@stytch/core";
2
- import { IHeadlessB2BDiscoveryClient, IHeadlessB2BMagicLinksClient, IHeadlessB2BMemberClient, IHeadlessB2BSelfClient, IHeadlessB2BOAuthClient, IHeadlessB2BOrganizationClient, IHeadlessB2BOTPsClient, IHeadlessB2BTOTPsClient, IHeadlessB2BSessionClient, IHeadlessB2BSSOClient, IHeadlessB2BRecoveryCodesClient, IHeadlessB2BRBACClient, StytchClientOptions, B2BState, IHeadlessB2BPasswordClient, Callbacks, StyleConfig, StytchB2BUIConfig } 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 { Callbacks as Callbacks$0 } from "@stytch/core/public";
4
+ import { StyleConfig as StyleConfig$0 } from "@stytch/core/public";
5
+ import { StytchB2BUIConfig as StytchB2BUIConfig$0 } from "@stytch/core/public";
6
+ import { PromptMomentNotification } from "google-one-tap";
7
+ type OneTapNotShownReason = ReturnType<PromptMomentNotification["getNotDisplayedReason"]> | ReturnType<PromptMomentNotification["getSkippedReason"]>;
8
+ type OneTapRenderResult = {
9
+ success: true;
10
+ } | {
11
+ success: false;
12
+ reason: OneTapNotShownReason;
13
+ };
14
+ declare global {
15
+ // The telemetry.js script will set a global function called GetTelemetryID on the window
16
+ // object. This interface is allows us to call that function while pleasing the TypeScript
17
+ // compiler.
18
+ interface Window {
19
+ GetTelemetryID: (publicToken: string, submitURL: string) => Promise<string>;
20
+ }
21
+ }
22
+ type B2BGoogleOneTapDiscoveryOAuthOptions = {
23
+ /**
24
+ * The URL that Stytch redirects to after the Google One Tap discovery flow is completed.
25
+ * This should be a URL that verifies the request by querying Stytch's /oauth/discovery/authenticate endpoint.
26
+ * If this value is not passed, the default discovery redirect URL that you set in your Dashboard is used.
27
+ * If you have not set a default discovery redirect URL, an error is returned.
28
+ */
29
+ discovery_redirect_url?: string;
30
+ };
31
+ type B2BGoogleOneTapOAuthOptions = {
32
+ /**
33
+ * The ID of the organization that the end user is logging in to.
34
+ */
35
+ organization_id: string;
36
+ /**
37
+ * The URL that Stytch redirects to after the Google One Tap flow is completed for a member who already exists.
38
+ * This should be a URL that verifies the request by querying Stytch's /oauth/authenticate endpoint.
39
+ * If this value is not passed, the default login redirect URL that you set in your Dashboard is used.
40
+ * If you have not set a default login redirect URL, an error is returned.
41
+ */
42
+ login_redirect_url?: string;
43
+ /**
44
+ * The URL that Stytch redirects to after the Google One Tap flow is completed for a member who does not yet exist.
45
+ * This should be a URL that verifies the request by querying Stytch's /oauth/authenticate endpoint.
46
+ * If this value is not passed, the default signup redirect URL that you set in your Dashboard is used.
47
+ * If you have not set a default signup redirect URL, an error is returned.
48
+ */
49
+ signup_redirect_url?: string;
50
+ };
51
+ interface IB2BGoogleOneTapOAuthProvider {
52
+ discovery: {
53
+ /**
54
+ * Start a discovery OAuth flow by showing the Google one tap prompt in the top right corner of the user's browser.
55
+ * You can configure this to be started by a user action (i.e Button click) or on load/render.
56
+ * @example
57
+ * const showGoogleOneTap = useCallback(()=> {
58
+ * stytch.oauth.googleOneTap.discovery.start({
59
+ * discovery_redirect_url: 'https://example.com/oauth/callback',
60
+ * })
61
+ * }, [stytch]);
62
+ * return (
63
+ * <Button onClick={showGoogleOneTap}> Show Google one tap </Button>
64
+ * );
65
+ *
66
+ * @param options - A {@link B2BGoogleOneTapDiscoveryOAuthOptions} object
67
+ *
68
+ * @returns A {@link OneTapRenderResult} object. The result object includes if the one-tap prompt
69
+ * was rendered, and a reason if it couldn't be rendered.
70
+ *
71
+ * @throws An Error if the one tap client cannot be created.
72
+ */
73
+ start(options?: B2BGoogleOneTapDiscoveryOAuthOptions): Promise<OneTapRenderResult>;
74
+ };
75
+ /**
76
+ * Start an OAuth flow by showing the Google one tap prompt in the top right corner of the user's browser.
77
+ * You can configure this to be started by a user action (i.e Button click) or on load/render.
78
+ * @example
79
+ * const showGoogleOneTap = useCallback(()=> {
80
+ * stytch.oauth.googleOneTap.start({
81
+ * organization_id: 'organization-test-123',
82
+ * })
83
+ * }, [stytch]);
84
+ * return (
85
+ * <Button onClick={showGoogleOneTap}> Show Google one tap </Button>
86
+ * );
87
+ *
88
+ * @param options - A {@link B2BGoogleOneTapOAuthOptions} object
89
+ *
90
+ * @returns A {@link OneTapRenderResult} object. The result object includes if the one-tap prompt
91
+ * was rendered, and a reason if it couldn't be rendered.
92
+ *
93
+ * @throws An Error if the one tap client cannot be created.
94
+ */
95
+ start(options?: B2BGoogleOneTapOAuthOptions): Promise<OneTapRenderResult>;
96
+ }
97
+ interface IWebB2BOAuthClient extends IHeadlessB2BOAuthClient {
98
+ googleOneTap: IB2BGoogleOneTapOAuthProvider;
99
+ }
3
100
  /**
4
101
  * A headless client used for invoking Stytch's B2B APIs.
5
102
  * The Stytch Headless Client can be used as a drop-in solution for authentication and session management.
@@ -16,6 +113,9 @@ declare class StytchB2BHeadlessClient {
16
113
  private readonly _subscriptionService;
17
114
  private readonly _sessionManager;
18
115
  private readonly _networkClient;
116
+ // The _apiNetworkClient uses the API instead of web-backend as the SDK backend URL. We choose between the test and
117
+ // live URL based on the public token.
118
+ private readonly _apiNetworkClient;
19
119
  private readonly _dataLayer;
20
120
  private readonly _stateChangeClient;
21
121
  // External API Clients
@@ -25,7 +125,7 @@ declare class StytchB2BHeadlessClient {
25
125
  member: IHeadlessB2BMemberClient;
26
126
  self: IHeadlessB2BSelfClient;
27
127
  organization: IHeadlessB2BOrganizationClient;
28
- oauth: IHeadlessB2BOAuthClient;
128
+ oauth: IWebB2BOAuthClient;
29
129
  sso: IHeadlessB2BSSOClient;
30
130
  discovery: IHeadlessB2BDiscoveryClient;
31
131
  passwords: IHeadlessB2BPasswordClient;
@@ -81,9 +181,9 @@ declare class StytchB2BUIClient extends StytchB2BHeadlessClient {
81
181
  */
82
182
  mount({ elementId, styles, callbacks, config }: {
83
183
  elementId: string;
84
- styles?: StyleConfig;
85
- callbacks?: Callbacks;
86
- config: StytchB2BUIConfig;
184
+ styles?: StyleConfig$0;
185
+ callbacks?: Callbacks$0;
186
+ config: StytchB2BUIConfig$0;
87
187
  }): void;
88
188
  }
89
189
  export { StytchB2BUIClient };