@stytch/react 19.4.3 → 19.5.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +7 -7
  3. package/b2b/headless/package.json +6 -0
  4. package/b2b/ui/package.json +6 -0
  5. package/dist/StytchB2BContext-9c062712.d.ts +272 -0
  6. package/dist/{StytchB2BContext-081081ee.js → StytchB2BContext-9c062712.js} +94 -49
  7. package/dist/StytchB2BContext-c5062f9b.d.ts +272 -0
  8. package/dist/StytchB2BContext-c5062f9b.js +280 -0
  9. package/dist/StytchSSRProxy-34c789b5.d.ts +3 -0
  10. package/dist/StytchSSRProxy-34c789b5.js +48 -0
  11. package/dist/StytchSSRProxy-86bc42b3.d.ts +3 -0
  12. package/dist/StytchSSRProxy-86bc42b3.js +54 -0
  13. package/dist/adminPortal/index.d.ts +1 -1
  14. package/dist/adminPortal/index.esm.d.ts +1 -1
  15. package/dist/adminPortal/index.esm.js +5 -4
  16. package/dist/adminPortal/index.js +5 -4
  17. package/dist/b2b/index.d.ts +180 -19
  18. package/dist/b2b/index.esm.d.ts +180 -19
  19. package/dist/b2b/index.esm.js +91 -18
  20. package/dist/b2b/index.headless.d.ts +16 -0
  21. package/dist/b2b/index.headless.esm.d.ts +16 -0
  22. package/dist/b2b/index.headless.esm.js +24 -0
  23. package/dist/b2b/index.headless.js +28 -0
  24. package/dist/b2b/index.js +99 -26
  25. package/dist/b2b/index.ui.d.ts +17 -0
  26. package/dist/b2b/index.ui.esm.d.ts +17 -0
  27. package/dist/b2b/index.ui.esm.js +25 -0
  28. package/dist/b2b/index.ui.js +29 -0
  29. package/dist/errors-d9d5fbc8.d.ts +5 -0
  30. package/dist/index-b14d4efe.d.ts +1 -1
  31. package/dist/index.d.ts +134 -77
  32. package/dist/index.esm.d.ts +134 -77
  33. package/dist/index.esm.js +153 -94
  34. package/dist/index.headless.d.ts +16 -0
  35. package/dist/index.headless.esm.d.ts +16 -0
  36. package/dist/index.headless.esm.js +24 -0
  37. package/dist/index.headless.js +28 -0
  38. package/dist/index.js +167 -108
  39. package/dist/index.ui.d.ts +17 -0
  40. package/dist/index.ui.esm.d.ts +17 -0
  41. package/dist/index.ui.esm.js +25 -0
  42. package/dist/index.ui.js +29 -0
  43. package/dist/useIsomorphicLayoutEffect-1babb81e.d.ts +24 -0
  44. package/dist/{invariant-568a7633.js → useIsomorphicLayoutEffect-1babb81e.js} +5 -13
  45. package/dist/useIsomorphicLayoutEffect-65746ef3.d.ts +24 -0
  46. package/dist/{invariant-ae5a5bce.js → useIsomorphicLayoutEffect-65746ef3.js} +4 -16
  47. package/package.json +5 -3
  48. package/dist/StytchB2BContext-081081ee.d.ts +0 -165
  49. package/dist/StytchB2BContext-865b6947.d.ts +0 -165
  50. package/dist/StytchB2BContext-865b6947.js +0 -235
  51. package/dist/invariant-568a7633.d.ts +0 -27
  52. package/dist/invariant-ae5a5bce.d.ts +0 -27
@@ -39,6 +39,6 @@ type AdminPortalSCIMProps<TProjectConfiguration extends StytchProjectConfigurati
39
39
  * See the {@link https://stytch.com/docs/b2b/sdks/javascript-sdk online reference}
40
40
  */
41
41
  declare const AdminPortalSCIM: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>(props: ExcludeInjectedOptions<AdminPortalSCIMMountOptions<Partial<import("@stytch/core/public").StytchProjectConfiguration>>>) => JSX.Element;
42
- export { AdminPortalSSO, AdminPortalOrgSettings, AdminPortalMemberManagement, AdminPortalSCIM };
43
42
  export { AdminPortalB2BProducts } from "@stytch/vanilla-js/b2b/adminPortal";
43
+ export { AdminPortalMemberManagement, AdminPortalOrgSettings, AdminPortalSCIM, AdminPortalSSO };
44
44
  export type { AdminPortalSSOProps, AdminPortalOrgSettingsProps, AdminPortalMemberManagementProps, AdminPortalSCIMProps };
@@ -1,15 +1,16 @@
1
1
  import { mountAdminPortalSSO, mountAdminPortalOrgSettings, mountAdminPortalMemberManagement, mountAdminPortalSCIM } from '@stytch/vanilla-js/b2b/adminPortal';
2
2
  export { AdminPortalB2BProducts } from '@stytch/vanilla-js/b2b/adminPortal';
3
- import React, { useRef, useLayoutEffect } from 'react';
4
- import { u as useIsMounted__INTERNAL, a as useStytchB2BClient } from '../StytchB2BContext-081081ee.js';
5
- import { i as invariant, n as noProviderError } from '../invariant-568a7633.js';
3
+ import React, { useRef } from 'react';
4
+ import { u as useIsMounted__INTERNAL, a as useStytchB2BClient } from '../StytchB2BContext-9c062712.js';
5
+ import { n as noProviderError } from '../StytchSSRProxy-34c789b5.js';
6
+ import { i as invariant, a as useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect-1babb81e.js';
6
7
 
7
8
  const makeAdminPortalComponent = (mountFn, componentName) => {
8
9
  const Component = (props) => {
9
10
  invariant(useIsMounted__INTERNAL(), noProviderError(`<${componentName} />`, 'StytchB2BProvider'));
10
11
  const stytchClient = useStytchB2BClient();
11
12
  const containerEl = useRef(null);
12
- useLayoutEffect(() => {
13
+ useIsomorphicLayoutEffect(() => {
13
14
  if (!containerEl.current) {
14
15
  return;
15
16
  }
@@ -4,8 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var adminPortal = require('@stytch/vanilla-js/b2b/adminPortal');
6
6
  var React = require('react');
7
- var StytchB2BContext = require('../StytchB2BContext-865b6947.js');
8
- var invariant = require('../invariant-ae5a5bce.js');
7
+ var StytchB2BContext = require('../StytchB2BContext-c5062f9b.js');
8
+ var StytchSSRProxy = require('../StytchSSRProxy-86bc42b3.js');
9
+ var useIsomorphicLayoutEffect = require('../useIsomorphicLayoutEffect-65746ef3.js');
9
10
 
10
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
12
 
@@ -13,10 +14,10 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
13
14
 
14
15
  const makeAdminPortalComponent = (mountFn, componentName) => {
15
16
  const Component = (props) => {
16
- invariant.invariant(StytchB2BContext.useIsMounted__INTERNAL(), invariant.noProviderError(`<${componentName} />`, 'StytchB2BProvider'));
17
+ useIsomorphicLayoutEffect.invariant(StytchB2BContext.useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError(`<${componentName} />`, 'StytchB2BProvider'));
17
18
  const stytchClient = StytchB2BContext.useStytchB2BClient();
18
19
  const containerEl = React.useRef(null);
19
- React.useLayoutEffect(() => {
20
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
20
21
  if (!containerEl.current) {
21
22
  return;
22
23
  }
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import React from "react";
3
- import { Callbacks, StyleConfig, StytchB2BUIConfig, StytchProjectConfigurationInput } from "@stytch/vanilla-js";
4
- // We need to import the StytchB2BUIClient type to give the TSDoc parser a hint as to where it is from
5
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
- import { IDPConsentScreenManifest } from "@stytch/vanilla-js/b2b";
7
- interface StytchB2BProps<TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration> {
3
+ import { ReactNode } from "react";
4
+ import { Member, MemberSession, Organization, StytchB2BUIClient, IDPConsentScreenManifest } from "@stytch/vanilla-js/b2b";
5
+ import { StytchB2BHeadlessClient, StytchProjectConfigurationInput } from "@stytch/vanilla-js/b2b/headless";
6
+ import { Callbacks, StyleConfig, StytchB2BUIConfig } from "@stytch/vanilla-js";
7
+ import { StytchProjectConfigurationInput as StytchProjectConfigurationInput$0 } from "@stytch/vanilla-js";
8
+ interface StytchB2BProps<TProjectConfiguration extends StytchProjectConfigurationInput$0 = Stytch.DefaultProjectConfiguration> {
8
9
  /**
9
10
  * An optional {@link StyleConfig} to customize the look and feel of the screen.
10
11
  *
@@ -76,14 +77,17 @@ type B2BIDPConsentManifestGenerator = (input: {
76
77
  clientName: string;
77
78
  }) => IDPConsentScreenManifest;
78
79
  type B2BIdentityProviderProps = Omit<StytchB2BProps, "config"> & {
80
+ /**
81
+ * Optional {@link B2BIDPConsentManifestGenerator} to customize the consent screen.
82
+ */
79
83
  getIDPConsentManifest?: B2BIDPConsentManifestGenerator;
80
84
  };
81
85
  /**
82
86
  * The Stytch B2B UI component.
83
- * This component can only be used with a {@link StytchB2BUIClient} client constructor
84
- * passed into the {@link StytchB2BProvider}
87
+ * This component can only be used with a Stytch B2B UI Client
88
+ * passed into the StytchB2BProvider.
85
89
  *
86
- * See the {@link https://stytch.com/docs/b2b/sdks/javascript-sdk online reference}
90
+ * See the {@link https://stytch.com/docs/b2b/sdks online reference}
87
91
  *
88
92
  * @example
89
93
  * <StytchB2B
@@ -110,17 +114,16 @@ type B2BIdentityProviderProps = Omit<StytchB2BProps, "config"> & {
110
114
  * onEvent: (event) => console.log(event)
111
115
  * }}
112
116
  * />
113
- * @param props {@link StytchB2BProps}
114
117
  */
115
- declare const StytchB2B: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration>>({ styles, callbacks, config }: StytchB2BProps<TProjectConfiguration>) => React.JSX.Element;
118
+ declare const StytchB2B: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>({ styles, callbacks, config }: StytchB2BProps<TProjectConfiguration>) => React.JSX.Element;
116
119
  /**
117
120
  * The Stytch B2B IDP component.
118
121
  * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.
119
122
  * Requires the user to be logged in.
120
- * This component can only be used with a {@link StytchB2BUIClient} client constructor
121
- * passed into the {@link StytchB2BProvider}
123
+ * This component can only be used with a Stytch B2B UI Client
124
+ * passed into the StytchB2BProvider.
122
125
  *
123
- * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
126
+ * See the {@link https://stytch.com/docs/b2b/sdks online reference}
124
127
  *
125
128
  * @example
126
129
  * const styles = {
@@ -139,11 +142,169 @@ declare const StytchB2B: <TProjectConfiguration extends Partial<import("@stytch/
139
142
  * onEvent: (event) => console.log(event)
140
143
  * }}
141
144
  * />
142
- * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
143
- * @param callbacks - An optional {@link Callbacks} object
144
- * @param getIDPConsentManifest - Optional {@link B2BIDPConsentManifestGenerator} to customize the consent screen.
145
145
  */
146
146
  declare const B2BIdentityProvider: ({ styles, callbacks, getIDPConsentManifest }: B2BIdentityProviderProps) => React.JSX.Element;
147
- export { StytchB2BProvider, useStytchB2BClient, useStytchMemberSession, useStytchMember, useStytchIsAuthorized, useStytchOrganization, withStytchB2BClient, withStytchMemberSession, withStytchMember, withStytchOrganization, withStytchPermissions } from "../StytchB2BContext-865b6947.js";
148
- export { StytchB2B, B2BIdentityProvider };
149
- export type { StytchB2BProviderProps } from "../StytchB2BContext-865b6947.js";
147
+ /**
148
+ * The Stytch Client object passed in to <StytchB2BProvider /> in your application root.
149
+ * Either a StytchB2BUIClient or StytchB2BHeadlessClient.
150
+ */
151
+ type StytchB2BClient<TProjectConfiguration extends StytchProjectConfigurationInput> = StytchB2BHeadlessClient<TProjectConfiguration> | StytchB2BUIClient<TProjectConfiguration>;
152
+ /**
153
+ * Returns the active Member.
154
+ * The Stytch SDKs are used for client-side authentication and session management.
155
+ * Check the isInitialized property to determine if the SDK has completed initialization.
156
+ * Check the fromCache property to determine if the member data is from persistent storage.
157
+ * @example
158
+ * const {member, isInitialized, fromCache} = useStytchMember();
159
+ * if (!isInitialized) {
160
+ * return <p>Loading...</p>;
161
+ * }
162
+ * return (<h1>Welcome, {member.name}</h1>);
163
+ */
164
+ declare const useStytchMember: <TAssumeHydrated extends boolean = true>() => TAssumeHydrated extends true ? {
165
+ member: Member | null;
166
+ fromCache: boolean;
167
+ isInitialized: true;
168
+ } : {
169
+ member: null;
170
+ fromCache: false;
171
+ isInitialized: false;
172
+ } | {
173
+ member: Member | null;
174
+ fromCache: boolean;
175
+ isInitialized: true;
176
+ };
177
+ /**
178
+ * Returns the active member's Stytch member session.
179
+ * The Stytch SDKs are used for client-side authentication and session management.
180
+ * Check the isInitialized property to determine if the SDK has completed initialization.
181
+ * Check the fromCache property to determine if the session data is from persistent storage.
182
+ * @example
183
+ * const {session, isInitialized, fromCache} = useStytchMemberSession();
184
+ * useEffect(() => {
185
+ * if (!isInitialized) {
186
+ * return;
187
+ * }
188
+ * if (!session) {
189
+ * router.replace('/login')
190
+ * }
191
+ * }, [session, isInitialized]);
192
+ */
193
+ declare const useStytchMemberSession: <TAssumeHydrated extends boolean = true>() => TAssumeHydrated extends true ? {
194
+ session: MemberSession | null;
195
+ fromCache: boolean;
196
+ isInitialized: true;
197
+ } : {
198
+ session: null;
199
+ fromCache: false;
200
+ isInitialized: false;
201
+ } | {
202
+ session: MemberSession | null;
203
+ fromCache: boolean;
204
+ isInitialized: true;
205
+ };
206
+ /**
207
+ * Returns the active Stytch organization.
208
+ * The Stytch SDKs are used for client-side authentication and session management.
209
+ * Check the isInitialized property to determine if the SDK has completed initialization.
210
+ * Check the fromCache property to determine if the organization data is from persistent storage.
211
+ * @example
212
+ * const {organization, isInitialized, fromCache} = useStytchOrganization();
213
+ * if (!isInitialized) {
214
+ * return <p>Loading...</p>;
215
+ * }
216
+ * return (<p>Welcome to {organization.organization_name}</p>);
217
+ */
218
+ declare const useStytchOrganization: <TAssumeHydrated extends boolean = true>() => TAssumeHydrated extends true ? {
219
+ organization: Organization | null;
220
+ fromCache: boolean;
221
+ isInitialized: true;
222
+ } : {
223
+ organization: null;
224
+ fromCache: false;
225
+ isInitialized: false;
226
+ } | {
227
+ organization: Organization | null;
228
+ fromCache: boolean;
229
+ isInitialized: true;
230
+ };
231
+ /**
232
+ * Determines whether the logged-in member is allowed to perform the specified action on the specified resource.
233
+ * Returns `true` if the member can perform the action, `false` otherwise.
234
+ *
235
+ * If the member is not logged in, this method will always return false.
236
+ * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.
237
+ *
238
+ * Remember - authorization checks for sensitive actions should always occur on the backend as well.
239
+ * @example
240
+ * const { isAuthorized } = useStytchIsAuthorized<Permissions>('documents', 'edit');
241
+ * return <button disabled={!isAuthorized}>Edit</button>
242
+ */
243
+ declare const useStytchIsAuthorized: <TAssumeHydrated extends boolean = false>(resourceId: string, action: string) => TAssumeHydrated extends true ? {
244
+ isAuthorized: boolean;
245
+ fromCache: boolean;
246
+ isInitialized: boolean;
247
+ } : {
248
+ isAuthorized: false;
249
+ fromCache: false;
250
+ isInitialized: false;
251
+ } | {
252
+ isAuthorized: boolean;
253
+ fromCache: boolean;
254
+ isInitialized: boolean;
255
+ };
256
+ declare const withStytchMember: <T extends object, TAssumeHydrated extends boolean = false>(Component: React.ComponentType<T & {
257
+ stytchMember: Member | null;
258
+ stytchMemberIsInitialized: boolean;
259
+ stytchMemberIsFromCache: boolean;
260
+ }>) => React.ComponentType<T>;
261
+ declare const withStytchMemberSession: <T extends object, TAssumeHydrated extends boolean = false>(Component: React.ComponentType<T & {
262
+ stytchMemberSession: MemberSession | null;
263
+ stytchMemberSessionIsInitialized: boolean;
264
+ stytchMemberSessionIsFromCache: boolean;
265
+ }>) => React.ComponentType<T>;
266
+ declare const withStytchOrganization: <T extends object, TAssumeHydrated extends boolean = false>(Component: React.ComponentType<T & {
267
+ stytchOrganization: Organization | null;
268
+ stytchOrganizationIsInitialized: boolean;
269
+ stytchOrganizationIsFromCache: boolean;
270
+ }>) => React.ComponentType<T>;
271
+ interface StytchB2BProviderProps<TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration> {
272
+ /**
273
+ * A Stytch client instance, either a {@link StytchB2BUIClient} or {@link StytchB2BHeadlessClient}
274
+ */
275
+ stytch: StytchB2BClient<TProjectConfiguration>;
276
+ /**
277
+ * When true, the provider will assume that the component will only be
278
+ * rendered in a browser environment, either in a single-page application or
279
+ * after completing hydration of a server-rendered application. This allows
280
+ * cached values to be retrieved from the browser on the first render, meaning
281
+ * that the `isInitialized` value returned from Stytch hooks will be `true`
282
+ * starting from the first render.
283
+ *
284
+ * When `false`, the provider will defer initialization until after the first
285
+ * render, and `isInitialized` will initially be `false`.
286
+ *
287
+ * If you encounter hydration errors relating to the use of this component,
288
+ * set this to `false`.
289
+ *
290
+ * This value defaults to `true` in `@stytch/react`.
291
+ */
292
+ assumeHydrated?: boolean;
293
+ children?: ReactNode;
294
+ }
295
+ /**
296
+ * The Stytch Context Provider.
297
+ * Wrap your application with this component in order to use Stytch everywhere in your app.
298
+ * @example
299
+ * const stytch = createStytchB2BHeadlessClient('public-token-<find yours in the stytch dashboard>')
300
+ *
301
+ * ReactDOM.render(
302
+ * <StytchB2BProvider stytch={stytch}>
303
+ * <App />
304
+ * </StytchProvider>,
305
+ * document.getElementById('root'),
306
+ * )
307
+ */
308
+ declare const StytchB2BProvider: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>({ stytch, children, assumeHydrated }: StytchB2BProviderProps<TProjectConfiguration>) => JSX.Element;
309
+ export { StytchB2BProvider, useStytchB2BClient, useStytchMemberSession, useStytchMember, useStytchIsAuthorized, useStytchOrganization, withStytchB2BClient, withStytchMemberSession, withStytchMember, withStytchOrganization, withStytchPermissions, StytchB2B, B2BIdentityProvider };
310
+ export type { StytchB2BProviderProps, StytchB2BProps, B2BIdentityProviderProps };
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import React from "react";
3
- import { Callbacks, StyleConfig, StytchB2BUIConfig, StytchProjectConfigurationInput } from "@stytch/vanilla-js";
4
- // We need to import the StytchB2BUIClient type to give the TSDoc parser a hint as to where it is from
5
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
- import { IDPConsentScreenManifest } from "@stytch/vanilla-js/b2b";
7
- interface StytchB2BProps<TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration> {
3
+ import { ReactNode } from "react";
4
+ import { Member, MemberSession, Organization, StytchB2BUIClient, IDPConsentScreenManifest } from "@stytch/vanilla-js/b2b";
5
+ import { StytchB2BHeadlessClient, StytchProjectConfigurationInput } from "@stytch/vanilla-js/b2b/headless";
6
+ import { Callbacks, StyleConfig, StytchB2BUIConfig } from "@stytch/vanilla-js";
7
+ import { StytchProjectConfigurationInput as StytchProjectConfigurationInput$0 } from "@stytch/vanilla-js";
8
+ interface StytchB2BProps<TProjectConfiguration extends StytchProjectConfigurationInput$0 = Stytch.DefaultProjectConfiguration> {
8
9
  /**
9
10
  * An optional {@link StyleConfig} to customize the look and feel of the screen.
10
11
  *
@@ -76,14 +77,17 @@ type B2BIDPConsentManifestGenerator = (input: {
76
77
  clientName: string;
77
78
  }) => IDPConsentScreenManifest;
78
79
  type B2BIdentityProviderProps = Omit<StytchB2BProps, "config"> & {
80
+ /**
81
+ * Optional {@link B2BIDPConsentManifestGenerator} to customize the consent screen.
82
+ */
79
83
  getIDPConsentManifest?: B2BIDPConsentManifestGenerator;
80
84
  };
81
85
  /**
82
86
  * The Stytch B2B UI component.
83
- * This component can only be used with a {@link StytchB2BUIClient} client constructor
84
- * passed into the {@link StytchB2BProvider}
87
+ * This component can only be used with a Stytch B2B UI Client
88
+ * passed into the StytchB2BProvider.
85
89
  *
86
- * See the {@link https://stytch.com/docs/b2b/sdks/javascript-sdk online reference}
90
+ * See the {@link https://stytch.com/docs/b2b/sdks online reference}
87
91
  *
88
92
  * @example
89
93
  * <StytchB2B
@@ -110,17 +114,16 @@ type B2BIdentityProviderProps = Omit<StytchB2BProps, "config"> & {
110
114
  * onEvent: (event) => console.log(event)
111
115
  * }}
112
116
  * />
113
- * @param props {@link StytchB2BProps}
114
117
  */
115
- declare const StytchB2B: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration>>({ styles, callbacks, config }: StytchB2BProps<TProjectConfiguration>) => React.JSX.Element;
118
+ declare const StytchB2B: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>({ styles, callbacks, config }: StytchB2BProps<TProjectConfiguration>) => React.JSX.Element;
116
119
  /**
117
120
  * The Stytch B2B IDP component.
118
121
  * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.
119
122
  * Requires the user to be logged in.
120
- * This component can only be used with a {@link StytchB2BUIClient} client constructor
121
- * passed into the {@link StytchB2BProvider}
123
+ * This component can only be used with a Stytch B2B UI Client
124
+ * passed into the StytchB2BProvider.
122
125
  *
123
- * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
126
+ * See the {@link https://stytch.com/docs/b2b/sdks online reference}
124
127
  *
125
128
  * @example
126
129
  * const styles = {
@@ -139,11 +142,169 @@ declare const StytchB2B: <TProjectConfiguration extends Partial<import("@stytch/
139
142
  * onEvent: (event) => console.log(event)
140
143
  * }}
141
144
  * />
142
- * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
143
- * @param callbacks - An optional {@link Callbacks} object
144
- * @param getIDPConsentManifest - Optional {@link B2BIDPConsentManifestGenerator} to customize the consent screen.
145
145
  */
146
146
  declare const B2BIdentityProvider: ({ styles, callbacks, getIDPConsentManifest }: B2BIdentityProviderProps) => React.JSX.Element;
147
- export { StytchB2BProvider, useStytchB2BClient, useStytchMemberSession, useStytchMember, useStytchIsAuthorized, useStytchOrganization, withStytchB2BClient, withStytchMemberSession, withStytchMember, withStytchOrganization, withStytchPermissions } from "../StytchB2BContext-081081ee.js";
148
- export { StytchB2B, B2BIdentityProvider };
149
- export type { StytchB2BProviderProps } from "../StytchB2BContext-081081ee.js";
147
+ /**
148
+ * The Stytch Client object passed in to <StytchB2BProvider /> in your application root.
149
+ * Either a StytchB2BUIClient or StytchB2BHeadlessClient.
150
+ */
151
+ type StytchB2BClient<TProjectConfiguration extends StytchProjectConfigurationInput> = StytchB2BHeadlessClient<TProjectConfiguration> | StytchB2BUIClient<TProjectConfiguration>;
152
+ /**
153
+ * Returns the active Member.
154
+ * The Stytch SDKs are used for client-side authentication and session management.
155
+ * Check the isInitialized property to determine if the SDK has completed initialization.
156
+ * Check the fromCache property to determine if the member data is from persistent storage.
157
+ * @example
158
+ * const {member, isInitialized, fromCache} = useStytchMember();
159
+ * if (!isInitialized) {
160
+ * return <p>Loading...</p>;
161
+ * }
162
+ * return (<h1>Welcome, {member.name}</h1>);
163
+ */
164
+ declare const useStytchMember: <TAssumeHydrated extends boolean = true>() => TAssumeHydrated extends true ? {
165
+ member: Member | null;
166
+ fromCache: boolean;
167
+ isInitialized: true;
168
+ } : {
169
+ member: null;
170
+ fromCache: false;
171
+ isInitialized: false;
172
+ } | {
173
+ member: Member | null;
174
+ fromCache: boolean;
175
+ isInitialized: true;
176
+ };
177
+ /**
178
+ * Returns the active member's Stytch member session.
179
+ * The Stytch SDKs are used for client-side authentication and session management.
180
+ * Check the isInitialized property to determine if the SDK has completed initialization.
181
+ * Check the fromCache property to determine if the session data is from persistent storage.
182
+ * @example
183
+ * const {session, isInitialized, fromCache} = useStytchMemberSession();
184
+ * useEffect(() => {
185
+ * if (!isInitialized) {
186
+ * return;
187
+ * }
188
+ * if (!session) {
189
+ * router.replace('/login')
190
+ * }
191
+ * }, [session, isInitialized]);
192
+ */
193
+ declare const useStytchMemberSession: <TAssumeHydrated extends boolean = true>() => TAssumeHydrated extends true ? {
194
+ session: MemberSession | null;
195
+ fromCache: boolean;
196
+ isInitialized: true;
197
+ } : {
198
+ session: null;
199
+ fromCache: false;
200
+ isInitialized: false;
201
+ } | {
202
+ session: MemberSession | null;
203
+ fromCache: boolean;
204
+ isInitialized: true;
205
+ };
206
+ /**
207
+ * Returns the active Stytch organization.
208
+ * The Stytch SDKs are used for client-side authentication and session management.
209
+ * Check the isInitialized property to determine if the SDK has completed initialization.
210
+ * Check the fromCache property to determine if the organization data is from persistent storage.
211
+ * @example
212
+ * const {organization, isInitialized, fromCache} = useStytchOrganization();
213
+ * if (!isInitialized) {
214
+ * return <p>Loading...</p>;
215
+ * }
216
+ * return (<p>Welcome to {organization.organization_name}</p>);
217
+ */
218
+ declare const useStytchOrganization: <TAssumeHydrated extends boolean = true>() => TAssumeHydrated extends true ? {
219
+ organization: Organization | null;
220
+ fromCache: boolean;
221
+ isInitialized: true;
222
+ } : {
223
+ organization: null;
224
+ fromCache: false;
225
+ isInitialized: false;
226
+ } | {
227
+ organization: Organization | null;
228
+ fromCache: boolean;
229
+ isInitialized: true;
230
+ };
231
+ /**
232
+ * Determines whether the logged-in member is allowed to perform the specified action on the specified resource.
233
+ * Returns `true` if the member can perform the action, `false` otherwise.
234
+ *
235
+ * If the member is not logged in, this method will always return false.
236
+ * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.
237
+ *
238
+ * Remember - authorization checks for sensitive actions should always occur on the backend as well.
239
+ * @example
240
+ * const { isAuthorized } = useStytchIsAuthorized<Permissions>('documents', 'edit');
241
+ * return <button disabled={!isAuthorized}>Edit</button>
242
+ */
243
+ declare const useStytchIsAuthorized: <TAssumeHydrated extends boolean = false>(resourceId: string, action: string) => TAssumeHydrated extends true ? {
244
+ isAuthorized: boolean;
245
+ fromCache: boolean;
246
+ isInitialized: boolean;
247
+ } : {
248
+ isAuthorized: false;
249
+ fromCache: false;
250
+ isInitialized: false;
251
+ } | {
252
+ isAuthorized: boolean;
253
+ fromCache: boolean;
254
+ isInitialized: boolean;
255
+ };
256
+ declare const withStytchMember: <T extends object, TAssumeHydrated extends boolean = false>(Component: React.ComponentType<T & {
257
+ stytchMember: Member | null;
258
+ stytchMemberIsInitialized: boolean;
259
+ stytchMemberIsFromCache: boolean;
260
+ }>) => React.ComponentType<T>;
261
+ declare const withStytchMemberSession: <T extends object, TAssumeHydrated extends boolean = false>(Component: React.ComponentType<T & {
262
+ stytchMemberSession: MemberSession | null;
263
+ stytchMemberSessionIsInitialized: boolean;
264
+ stytchMemberSessionIsFromCache: boolean;
265
+ }>) => React.ComponentType<T>;
266
+ declare const withStytchOrganization: <T extends object, TAssumeHydrated extends boolean = false>(Component: React.ComponentType<T & {
267
+ stytchOrganization: Organization | null;
268
+ stytchOrganizationIsInitialized: boolean;
269
+ stytchOrganizationIsFromCache: boolean;
270
+ }>) => React.ComponentType<T>;
271
+ interface StytchB2BProviderProps<TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration> {
272
+ /**
273
+ * A Stytch client instance, either a {@link StytchB2BUIClient} or {@link StytchB2BHeadlessClient}
274
+ */
275
+ stytch: StytchB2BClient<TProjectConfiguration>;
276
+ /**
277
+ * When true, the provider will assume that the component will only be
278
+ * rendered in a browser environment, either in a single-page application or
279
+ * after completing hydration of a server-rendered application. This allows
280
+ * cached values to be retrieved from the browser on the first render, meaning
281
+ * that the `isInitialized` value returned from Stytch hooks will be `true`
282
+ * starting from the first render.
283
+ *
284
+ * When `false`, the provider will defer initialization until after the first
285
+ * render, and `isInitialized` will initially be `false`.
286
+ *
287
+ * If you encounter hydration errors relating to the use of this component,
288
+ * set this to `false`.
289
+ *
290
+ * This value defaults to `true` in `@stytch/react`.
291
+ */
292
+ assumeHydrated?: boolean;
293
+ children?: ReactNode;
294
+ }
295
+ /**
296
+ * The Stytch Context Provider.
297
+ * Wrap your application with this component in order to use Stytch everywhere in your app.
298
+ * @example
299
+ * const stytch = createStytchB2BHeadlessClient('public-token-<find yours in the stytch dashboard>')
300
+ *
301
+ * ReactDOM.render(
302
+ * <StytchB2BProvider stytch={stytch}>
303
+ * <App />
304
+ * </StytchProvider>,
305
+ * document.getElementById('root'),
306
+ * )
307
+ */
308
+ declare const StytchB2BProvider: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>({ stytch, children, assumeHydrated }: StytchB2BProviderProps<TProjectConfiguration>) => JSX.Element;
309
+ export { StytchB2BProvider, useStytchB2BClient, useStytchMemberSession, useStytchMember, useStytchIsAuthorized, useStytchOrganization, withStytchB2BClient, withStytchMemberSession, withStytchMember, withStytchOrganization, withStytchPermissions, StytchB2B, B2BIdentityProvider };
310
+ export type { StytchB2BProviderProps, StytchB2BProps, B2BIdentityProviderProps };