@stytch/nextjs 13.0.0 → 15.0.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 (77) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/b2b/index.d.ts +251 -3
  3. package/dist/b2b/index.esm.d.ts +46 -3
  4. package/dist/b2b/index.esm.js +84 -3
  5. package/dist/b2b/index.headless.d.ts +16 -1
  6. package/dist/b2b/index.headless.esm.js +845 -375
  7. package/dist/b2b/index.headless.js +4591 -17
  8. package/dist/b2b/index.js +333 -14
  9. package/dist/b2b/index.ui.d.ts +17 -1
  10. package/dist/b2b/index.ui.js +64 -16
  11. package/dist/index.d.ts +275 -3
  12. package/dist/index.headless.d.ts +16 -1
  13. package/dist/index.headless.js +63 -16
  14. package/dist/index.js +374 -16
  15. package/dist/index.ui.d.ts +17 -1
  16. package/dist/index.ui.js +64 -16
  17. package/package.json +3 -3
  18. package/dist/Stytch.d.ts +0 -172
  19. package/dist/Stytch.js +0 -214
  20. package/dist/Stytch.js.map +0 -1
  21. package/dist/Stytch.spec.d.ts +0 -1
  22. package/dist/Stytch.spec.js +0 -130
  23. package/dist/Stytch.spec.js.map +0 -1
  24. package/dist/StytchContext.d.ts +0 -104
  25. package/dist/StytchContext.js +0 -180
  26. package/dist/StytchContext.js.map +0 -1
  27. package/dist/StytchContext.serverside.spec.d.ts +0 -4
  28. package/dist/StytchContext.serverside.spec.js +0 -51
  29. package/dist/StytchContext.serverside.spec.js.map +0 -1
  30. package/dist/StytchContext.spec.d.ts +0 -1
  31. package/dist/StytchContext.spec.js +0 -212
  32. package/dist/StytchContext.spec.js.map +0 -1
  33. package/dist/StytchSSRProxy.d.ts +0 -2
  34. package/dist/StytchSSRProxy.js +0 -29
  35. package/dist/StytchSSRProxy.js.map +0 -1
  36. package/dist/StytchSSRProxy.spec.d.ts +0 -1
  37. package/dist/StytchSSRProxy.spec.js +0 -16
  38. package/dist/StytchSSRProxy.spec.js.map +0 -1
  39. package/dist/b2b/Stytch.d.ts +0 -104
  40. package/dist/b2b/Stytch.js +0 -90
  41. package/dist/b2b/Stytch.js.map +0 -1
  42. package/dist/b2b/StytchB2BContext.d.ts +0 -104
  43. package/dist/b2b/StytchB2BContext.js +0 -179
  44. package/dist/b2b/StytchB2BContext.js.map +0 -1
  45. package/dist/b2b/StytchB2BContext.spec.d.ts +0 -1
  46. package/dist/b2b/StytchB2BContext.spec.js +0 -217
  47. package/dist/b2b/StytchB2BContext.spec.js.map +0 -1
  48. package/dist/b2b/createStytchB2BHeadlessClient.d.ts +0 -15
  49. package/dist/b2b/createStytchB2BHeadlessClient.js +0 -26
  50. package/dist/b2b/createStytchB2BHeadlessClient.js.map +0 -1
  51. package/dist/b2b/createStytchB2BUIClient.d.ts +0 -16
  52. package/dist/b2b/createStytchB2BUIClient.js +0 -27
  53. package/dist/b2b/createStytchB2BUIClient.js.map +0 -1
  54. package/dist/b2b/index.headless.js.map +0 -1
  55. package/dist/b2b/index.js.map +0 -1
  56. package/dist/b2b/index.ui.js.map +0 -1
  57. package/dist/createStytchHeadlessClient.d.ts +0 -15
  58. package/dist/createStytchHeadlessClient.js +0 -26
  59. package/dist/createStytchHeadlessClient.js.map +0 -1
  60. package/dist/createStytchUIClient.d.ts +0 -16
  61. package/dist/createStytchUIClient.js +0 -27
  62. package/dist/createStytchUIClient.js.map +0 -1
  63. package/dist/index.headless.js.map +0 -1
  64. package/dist/index.js.map +0 -1
  65. package/dist/index.ui.js.map +0 -1
  66. package/dist/utils/async.d.ts +0 -2
  67. package/dist/utils/async.js +0 -22
  68. package/dist/utils/async.js.map +0 -1
  69. package/dist/utils/errors.d.ts +0 -3
  70. package/dist/utils/errors.js +0 -28
  71. package/dist/utils/errors.js.map +0 -1
  72. package/dist/utils/invariant.d.ts +0 -1
  73. package/dist/utils/invariant.js +0 -10
  74. package/dist/utils/invariant.js.map +0 -1
  75. package/dist/utils/useIsomorphicLayoutEffect.d.ts +0 -3
  76. package/dist/utils/useIsomorphicLayoutEffect.js +0 -7
  77. package/dist/utils/useIsomorphicLayoutEffect.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @stytch/nextjs
2
2
 
3
+ ## 15.0.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6890694: Mark stytch.member as deprecated in favor of stytch.self
8
+ Adds RBAC functionality
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [9ee61b3]
13
+ - Updated dependencies [c3c108b]
14
+ - Updated dependencies [6890694]
15
+ - @stytch/vanilla-js@3.3.0
16
+
17
+ ## 14.0.0
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [ec1962c]
22
+ - @stytch/vanilla-js@3.2.0
23
+
3
24
  ## 13.0.0
4
25
 
5
26
  ### Minor Changes
@@ -1,3 +1,251 @@
1
- export { StytchB2BProvider, useStytchB2BClient, useStytchMemberSession, useStytchMember, withStytchB2BClient, withStytchMemberSession, withStytchMember, } from './StytchB2BContext';
2
- export { StytchB2B } from './Stytch';
3
- export type { StytchB2BProviderProps } from './StytchB2BContext';
1
+ /// <reference types="react" />
2
+ import React from "react";
3
+ import { ReactNode } from "react";
4
+ import { Member, MemberSession, StytchB2BUIClient } from "@stytch/vanilla-js/b2b";
5
+ import { StytchB2BHeadlessClient } from "@stytch/vanilla-js/b2b/headless";
6
+ import { PermissionsMap } from "@stytch/core/public";
7
+ import { Callbacks, StyleConfig, StytchB2BUIConfig } from "@stytch/vanilla-js";
8
+ /**
9
+ * The Stytch Client object passed in to <StytchProvider /> in your `_app.js`.
10
+ * Either a StytchUIClient or StytchHeadlessClient.
11
+ */
12
+ type StytchB2BClient = StytchB2BHeadlessClient | StytchB2BUIClient;
13
+ type SWRMember = {
14
+ member: null;
15
+ fromCache: false;
16
+ isInitialized: false;
17
+ } | {
18
+ member: Member | null;
19
+ fromCache: boolean;
20
+ isInitialized: true;
21
+ };
22
+ type SWRMemberSession = {
23
+ session: null;
24
+ fromCache: false;
25
+ isInitialized: false;
26
+ } | {
27
+ session: MemberSession | null;
28
+ fromCache: boolean;
29
+ isInitialized: true;
30
+ };
31
+ /**
32
+ * Returns the active member.
33
+ * The Stytch SDKs are used for client-side authentication and session management.
34
+ * Check the isInitialized property to determine if the SDK has completed initialization.
35
+ * Check the fromCache property to determine if the session data is from persistent storage.
36
+ * See Next's {@link https://nextjs.org/docs/authentication#authenticating-statically-generated-pages documentation} for more.
37
+ * @example
38
+ * const {member, isInitialized, fromCache} = useStytchMember();
39
+ * if (!isInitialized) {
40
+ * return <p>Loading...</p>;
41
+ * }
42
+ * return (<h1>Welcome, {member.name}</h1>);
43
+ */
44
+ declare const useStytchMember: () => SWRMember;
45
+ /**
46
+ * Returns the member's active Stytch member session.
47
+ * The Stytch SDKs are used for client-side authentication and session management.
48
+ * Check the isInitialized property to determine if the SDK has completed initialization.
49
+ * Check the fromCache property to determine if the session data is from persistent storage.
50
+ * See Next's {@link https://nextjs.org/docs/authentication#authenticating-statically-generated-pages documentation} for more.
51
+ * @example
52
+ * const {session, isInitialized, fromCache} = useStytchMemberSession();
53
+ * useEffect(() => {
54
+ * if (!isInitialized) {
55
+ * return;
56
+ * }
57
+ * if (!session) {
58
+ * router.replace('/login')
59
+ * }
60
+ * }, [session, isInitialized]);
61
+ */
62
+ declare const useStytchMemberSession: () => SWRMemberSession;
63
+ type SWRIsAuthorized = {
64
+ isAuthorized: boolean;
65
+ fromCache: boolean;
66
+ isInitialized: boolean;
67
+ };
68
+ /**
69
+ * Determines whether the logged-in member is allowed to perform the specified action on the specified resource.
70
+ * Returns `true` if the member can perform the action, `false` otherwise.
71
+ *
72
+ * If the member is not logged in, this method will always return false.
73
+ * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.
74
+ *
75
+ * Remember - authorization checks for sensitive actions should always occur on the backend as well.
76
+ * @example
77
+ * const isAuthorized = useStytchIsAuthorized<Permissions>('documents', 'edit');
78
+ * return <button disabled={!isAuthorized}>Edit</button>
79
+ */
80
+ declare const useStytchIsAuthorized: (resourceId: string, action: string) => SWRIsAuthorized;
81
+ /**
82
+ * Returns the Stytch client stored in the Stytch context.
83
+ *
84
+ * @example
85
+ * const stytch = useStytch();
86
+ * useEffect(() => {
87
+ * stytch.magicLinks.authenticate('...')
88
+ * }, [stytch]);
89
+ */
90
+ declare const useStytchB2BClient: () => StytchB2BHeadlessClient;
91
+ declare const withStytchB2BClient: <T extends object>(Component: React.ComponentType<T & {
92
+ stytch: StytchB2BHeadlessClient;
93
+ }>) => React.ComponentType<T>;
94
+ declare const withStytchMember: <T extends object>(Component: React.ComponentType<T & {
95
+ stytchMember: Member | null;
96
+ stytchMemberIsInitialized: boolean;
97
+ stytchMemberIsFromCache: boolean;
98
+ }>) => React.ComponentType<T>;
99
+ declare const withStytchMemberSession: <T extends object>(Component: React.ComponentType<T & {
100
+ stytchMemberSession: MemberSession | null;
101
+ stytchMemberSessionIsInitialized: boolean;
102
+ stytchMemberSessionIsFromCache: boolean;
103
+ }>) => React.ComponentType<T>;
104
+ /**
105
+ * Wrap your component with this HOC in order to receive the permissions for the logged-in member.
106
+ * Evaluates all permissions granted to the logged-in member.
107
+ * Returns a Record<RoleId, Record<Action, boolean>> response indicating the member's permissions.
108
+ * Each boolean will be `true` if the member can perform the action, `false` otherwise.
109
+ *
110
+ * If the member is not logged in, all values will be false.
111
+ *
112
+ * Remember - authorization checks for sensitive actions should always occur on the backend as well.
113
+ * @example
114
+ * type Permissions = {
115
+ * document: 'create' | 'read' | 'write
116
+ * image: 'create' | 'read'
117
+ * }
118
+ *
119
+ * const MyComponent = (props) => {
120
+ * const canEditDocuments = props.stytchPermissions.document.edit;
121
+ * const canReadImages = props.stytchPermissions.image.read;
122
+ * }
123
+ * return withStytchPermissions<Permissions>(MyComponent)
124
+ */
125
+ declare const withStytchPermissions: <Permissions_1 extends Record<string, string>, T extends object>(Component: React.ComponentType<T & {
126
+ stytchPermissions: PermissionsMap<Permissions_1>;
127
+ }>) => React.ComponentType<T>;
128
+ interface StytchB2BProviderProps {
129
+ /**
130
+ * A Stytch client instance, created using either {@link createStytchHeadlessClient} or {@link createStytchUIClient}
131
+ */
132
+ stytch: StytchB2BClient;
133
+ children?: ReactNode;
134
+ }
135
+ /**
136
+ * The Stytch Context Provider.
137
+ * Wrap your application with this component in `_app.js` in order to use Stytch everywhere in your app.
138
+ * @example
139
+ * const stytch = createStytchB2BHeadlessClient('public-token-<find yours in the stytch dashboard>')
140
+ *
141
+ * return (
142
+ * <StytchB2BProvider stytch={stytch}>
143
+ * <App />
144
+ * </StytchB2BProvider>
145
+ * )
146
+ */
147
+ declare const StytchB2BProvider: ({ stytch, children }: StytchB2BProviderProps) => JSX.Element;
148
+ interface StytchB2BProps {
149
+ /**
150
+ * An optional {@link StyleConfig} to customize the look and feel of the screen.
151
+ *
152
+ * @example
153
+ * {
154
+ * fontFamily: 'Arial, Helvetica, sans-serif',
155
+ * width: '360px',
156
+ * primaryColor: '#19303D',
157
+ * }
158
+ */
159
+ styles?: StyleConfig;
160
+ /**
161
+ * An optional {@link Callbacks} object.
162
+ *
163
+ * @example
164
+ * {
165
+ * onError: ({message}) => {
166
+ * console.error('Stytch error', message)
167
+ * }
168
+ * }
169
+ *
170
+ * @example
171
+ * {
172
+ * onEvent: ({type, data}) => {
173
+ * if(type === StytchEventType.B2BMagicLinkAuthenticate) {
174
+ * console.log('Logged in with', data);
175
+ * }
176
+ * }
177
+ * }
178
+ */
179
+ callbacks?: Callbacks;
180
+ /**
181
+ * A {@link StytchB2BUIConfig} object. Add products and product-specific config to this object to change the login methods shown.
182
+ *
183
+ *
184
+ * @example
185
+ * {
186
+ * products: ['emailMagicLinks'],
187
+ * authFlowType: "Discovery",
188
+ * emailMagicLinksOptions: {
189
+ * discoveryRedirectURL: 'https://example.com/authenticate',
190
+ * },
191
+ * sessionOptions: {
192
+ * sessionDurationMinutes: 60,
193
+ * },
194
+ * }
195
+ *
196
+ * @example
197
+ * {
198
+ * products: ['emailMagicLinks', 'sso'],
199
+ * authFlowType: "Organization",
200
+ * emailMagicLinksOptions: {
201
+ * loginRedirectURL: 'https://example.com/authenticate',
202
+ * signupRedirectURL: 'https://example.com/authenticate',
203
+ * },
204
+ * ssoOptions: {
205
+ * loginRedirectURL: 'https://example.com/authenticate',
206
+ * signupRedirectURL: 'https://example.com/authenticate',
207
+ * },
208
+ * sessionOptions: {
209
+ * sessionDurationMinutes: 60,
210
+ * },
211
+ * }
212
+ */
213
+ config: StytchB2BUIConfig;
214
+ }
215
+ /**
216
+ * The Stytch B2B UI component.
217
+ * This component can only be used with a {@link StytchB2BUIClient} client constructor
218
+ * passed into the {@link StytchB2BProvider}
219
+ *
220
+ * See the {@link https://stytch.com/docs/b2b/sdks/javascript-sdk online reference}
221
+ *
222
+ * @example
223
+ * <StytchB2B
224
+ * config={{
225
+ * authFlowType: "Organization",
226
+ * emailMagicLinksOptions: {
227
+ * loginRedirectURL: 'https://example.com/authenticate',
228
+ * signupRedirectURL: 'https://example.com/authenticate',
229
+ * },
230
+ * ssoOptions: {
231
+ * loginRedirectURL: 'https://example.com/authenticate',
232
+ * signupRedirectURL: 'https://example.com/authenticate',
233
+ * },
234
+ * sessionOptions: {
235
+ * sessionDurationMinutes: 60,
236
+ * }
237
+ * }}
238
+ * styles={{
239
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
240
+ * primaryColor: '#0577CA',
241
+ * width: '321px',
242
+ * }}
243
+ * callbacks={{
244
+ * onEvent: (event) => console.log(event)
245
+ * }}
246
+ * />
247
+ * @param props {@link StytchB2BProps}
248
+ */
249
+ declare const StytchB2B: ({ styles, callbacks, config }: StytchB2BProps) => React.JSX.Element;
250
+ export { StytchB2BProvider, useStytchB2BClient, useStytchMemberSession, useStytchMember, useStytchIsAuthorized, withStytchB2BClient, withStytchMemberSession, withStytchMember, withStytchPermissions, StytchB2B };
251
+ export type { StytchB2BProviderProps };
@@ -3,6 +3,7 @@ import React from "react";
3
3
  import { ReactNode } from "react";
4
4
  import { Member, MemberSession, StytchB2BUIClient } from "@stytch/vanilla-js/b2b";
5
5
  import { StytchB2BHeadlessClient } from "@stytch/vanilla-js/b2b/headless";
6
+ import { PermissionsMap } from "@stytch/core/public";
6
7
  import { Callbacks, StyleConfig, StytchB2BUIConfig } from "@stytch/vanilla-js";
7
8
  /**
8
9
  * The Stytch Client object passed in to <StytchProvider /> in your `_app.js`.
@@ -59,6 +60,24 @@ declare const useStytchMember: () => SWRMember;
59
60
  * }, [session, isInitialized]);
60
61
  */
61
62
  declare const useStytchMemberSession: () => SWRMemberSession;
63
+ type SWRIsAuthorized = {
64
+ isAuthorized: boolean;
65
+ fromCache: boolean;
66
+ isInitialized: boolean;
67
+ };
68
+ /**
69
+ * Determines whether the logged-in member is allowed to perform the specified action on the specified resource.
70
+ * Returns `true` if the member can perform the action, `false` otherwise.
71
+ *
72
+ * If the member is not logged in, this method will always return false.
73
+ * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.
74
+ *
75
+ * Remember - authorization checks for sensitive actions should always occur on the backend as well.
76
+ * @example
77
+ * const isAuthorized = useStytchIsAuthorized<Permissions>('documents', 'edit');
78
+ * return <button disabled={!isAuthorized}>Edit</button>
79
+ */
80
+ declare const useStytchIsAuthorized: (resourceId: string, action: string) => SWRIsAuthorized;
62
81
  /**
63
82
  * Returns the Stytch client stored in the Stytch context.
64
83
  *
@@ -68,9 +87,9 @@ declare const useStytchMemberSession: () => SWRMemberSession;
68
87
  * stytch.magicLinks.authenticate('...')
69
88
  * }, [stytch]);
70
89
  */
71
- declare const useStytchB2BClient: () => StytchB2BClient;
90
+ declare const useStytchB2BClient: () => StytchB2BHeadlessClient;
72
91
  declare const withStytchB2BClient: <T extends object>(Component: React.ComponentType<T & {
73
- stytch: StytchB2BClient;
92
+ stytch: StytchB2BHeadlessClient;
74
93
  }>) => React.ComponentType<T>;
75
94
  declare const withStytchMember: <T extends object>(Component: React.ComponentType<T & {
76
95
  stytchMember: Member | null;
@@ -82,6 +101,30 @@ declare const withStytchMemberSession: <T extends object>(Component: React.Compo
82
101
  stytchMemberSessionIsInitialized: boolean;
83
102
  stytchMemberSessionIsFromCache: boolean;
84
103
  }>) => React.ComponentType<T>;
104
+ /**
105
+ * Wrap your component with this HOC in order to receive the permissions for the logged-in member.
106
+ * Evaluates all permissions granted to the logged-in member.
107
+ * Returns a Record<RoleId, Record<Action, boolean>> response indicating the member's permissions.
108
+ * Each boolean will be `true` if the member can perform the action, `false` otherwise.
109
+ *
110
+ * If the member is not logged in, all values will be false.
111
+ *
112
+ * Remember - authorization checks for sensitive actions should always occur on the backend as well.
113
+ * @example
114
+ * type Permissions = {
115
+ * document: 'create' | 'read' | 'write
116
+ * image: 'create' | 'read'
117
+ * }
118
+ *
119
+ * const MyComponent = (props) => {
120
+ * const canEditDocuments = props.stytchPermissions.document.edit;
121
+ * const canReadImages = props.stytchPermissions.image.read;
122
+ * }
123
+ * return withStytchPermissions<Permissions>(MyComponent)
124
+ */
125
+ declare const withStytchPermissions: <Permissions_1 extends Record<string, string>, T extends object>(Component: React.ComponentType<T & {
126
+ stytchPermissions: PermissionsMap<Permissions_1>;
127
+ }>) => React.ComponentType<T>;
85
128
  interface StytchB2BProviderProps {
86
129
  /**
87
130
  * A Stytch client instance, created using either {@link createStytchHeadlessClient} or {@link createStytchUIClient}
@@ -204,5 +247,5 @@ interface StytchB2BProps {
204
247
  * @param props {@link StytchB2BProps}
205
248
  */
206
249
  declare const StytchB2B: ({ styles, callbacks, config }: StytchB2BProps) => React.JSX.Element;
207
- export { StytchB2BProvider, useStytchB2BClient, useStytchMemberSession, useStytchMember, withStytchB2BClient, withStytchMemberSession, withStytchMember, StytchB2B };
250
+ export { StytchB2BProvider, useStytchB2BClient, useStytchMemberSession, useStytchMember, useStytchIsAuthorized, withStytchB2BClient, withStytchMemberSession, withStytchMember, withStytchPermissions, StytchB2B };
208
251
  export type { StytchB2BProviderProps };
@@ -89,6 +89,47 @@ const useStytchMemberSession = () => {
89
89
  invariant(useIsMounted__INTERNAL(), noProviderError('useStytchMemberSession', 'StytchB2BProvider'));
90
90
  return useContext(StytchMemberSessionContext);
91
91
  };
92
+ /**
93
+ * Determines whether the logged-in member is allowed to perform the specified action on the specified resource.
94
+ * Returns `true` if the member can perform the action, `false` otherwise.
95
+ *
96
+ * If the member is not logged in, this method will always return false.
97
+ * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.
98
+ *
99
+ * Remember - authorization checks for sensitive actions should always occur on the backend as well.
100
+ * @example
101
+ * const isAuthorized = useStytchIsAuthorized<Permissions>('documents', 'edit');
102
+ * return <button disabled={!isAuthorized}>Edit</button>
103
+ */
104
+ const useStytchIsAuthorized = (resourceId, action) => {
105
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchIsAuthorized', 'StytchB2BProvider'));
106
+ const client = useStytchB2BClient();
107
+ const { session } = useStytchMemberSession();
108
+ const [isAuthorized, setIsAuthorized] = useAsyncState({
109
+ isInitialized: false,
110
+ fromCache: false,
111
+ isAuthorized: false,
112
+ });
113
+ useEffect(() => {
114
+ if (isStytchSSRProxy(client)) {
115
+ return;
116
+ }
117
+ setIsAuthorized({
118
+ isInitialized: true,
119
+ fromCache: true,
120
+ isAuthorized: client.rbac.isAuthorizedSync(resourceId, action),
121
+ });
122
+ }, []);
123
+ useEffect(() => {
124
+ if (isStytchSSRProxy(client)) {
125
+ return;
126
+ }
127
+ client.rbac.isAuthorized(resourceId, action).then((isAuthorized) => {
128
+ setIsAuthorized({ isAuthorized, fromCache: false, isInitialized: true });
129
+ });
130
+ }, [client, session === null || session === void 0 ? void 0 : session.roles, resourceId, action]);
131
+ return isAuthorized;
132
+ };
92
133
  /**
93
134
  * Returns the Stytch client stored in the Stytch context.
94
135
  *
@@ -129,6 +170,46 @@ const withStytchMemberSession = (Component) => {
129
170
  WithStytchSession.displayName = `withStytchMemberSession(${Component.displayName || Component.name || 'Component'})`;
130
171
  return WithStytchSession;
131
172
  };
173
+ /**
174
+ * Wrap your component with this HOC in order to receive the permissions for the logged-in member.
175
+ * Evaluates all permissions granted to the logged-in member.
176
+ * Returns a Record<RoleId, Record<Action, boolean>> response indicating the member's permissions.
177
+ * Each boolean will be `true` if the member can perform the action, `false` otherwise.
178
+ *
179
+ * If the member is not logged in, all values will be false.
180
+ *
181
+ * Remember - authorization checks for sensitive actions should always occur on the backend as well.
182
+ * @example
183
+ * type Permissions = {
184
+ * document: 'create' | 'read' | 'write
185
+ * image: 'create' | 'read'
186
+ * }
187
+ *
188
+ * const MyComponent = (props) => {
189
+ * const canEditDocuments = props.stytchPermissions.document.edit;
190
+ * const canReadImages = props.stytchPermissions.image.read;
191
+ * }
192
+ * return withStytchPermissions<Permissions>(MyComponent)
193
+ */
194
+ const withStytchPermissions = (Component) => {
195
+ const WithStytchPermissions = (props) => {
196
+ invariant(useIsMounted__INTERNAL(), noProviderError('useRBACPermissions', 'StytchB2BProvider'));
197
+ const client = useStytchB2BClient();
198
+ const { session } = useStytchMemberSession();
199
+ const [permissions, setPermissions] = useAsyncState({ loaded: false, value: null });
200
+ useEffect(() => {
201
+ client.rbac
202
+ .allPermissions()
203
+ .then((permissions) => setPermissions({ loaded: true, value: permissions }));
204
+ }, [client, session === null || session === void 0 ? void 0 : session.roles]);
205
+ if (!permissions.loaded) {
206
+ return null;
207
+ }
208
+ return React.createElement(Component, Object.assign({}, props, { stytchPermissions: permissions.value }));
209
+ };
210
+ WithStytchPermissions.displayName = `withStytchPermissions(${Component.displayName || Component.name || 'Component'})`;
211
+ return WithStytchPermissions;
212
+ };
132
213
  /**
133
214
  * The Stytch Context Provider.
134
215
  * Wrap your application with this component in `_app.js` in order to use Stytch everywhere in your app.
@@ -150,7 +231,7 @@ const StytchB2BProvider = ({ stytch, children }) => {
150
231
  return;
151
232
  }
152
233
  setMember({
153
- member: stytch.member.getSync(),
234
+ member: stytch.self.getSync(),
154
235
  fromCache: true,
155
236
  isInitialized: true,
156
237
  });
@@ -159,7 +240,7 @@ const StytchB2BProvider = ({ stytch, children }) => {
159
240
  fromCache: true,
160
241
  isInitialized: true,
161
242
  });
162
- const unsubscribeMember = stytch.member.onChange((member) => setMember({ member, fromCache: false, isInitialized: true }));
243
+ const unsubscribeMember = stytch.self.onChange((member) => setMember({ member, fromCache: false, isInitialized: true }));
163
244
  const unsubscribeMemberSession = stytch.session.onChange((session) => setMemberSession({ session, fromCache: false, isInitialized: true }));
164
245
  return () => {
165
246
  unsubscribeMember();
@@ -232,4 +313,4 @@ const StytchB2B = ({ styles, callbacks, config }) => {
232
313
  return React.createElement("div", { ref: containerEl });
233
314
  };
234
315
 
235
- export { StytchB2B, StytchB2BProvider, useStytchB2BClient, useStytchMember, useStytchMemberSession, withStytchB2BClient, withStytchMember, withStytchMemberSession };
316
+ export { StytchB2B, StytchB2BProvider, useStytchB2BClient, useStytchIsAuthorized, useStytchMember, useStytchMemberSession, withStytchB2BClient, withStytchMember, withStytchMemberSession, withStytchPermissions };
@@ -1 +1,16 @@
1
- export * from './createStytchB2BHeadlessClient';
1
+ import { StytchB2BHeadlessClient } from "@stytch/vanilla-js/b2b/headless";
2
+ /**
3
+ * Creates a Headless Stytch client object to call the stytch B2B APIs.
4
+ * The Stytch client is not available serverside.
5
+ * @example
6
+ * const stytch = createStytchB2BHeadlessClient('public-token-<find yours in the stytch dashboard>')
7
+ *
8
+ * return (
9
+ * <StytchB2BProvider stytch={stytch}>
10
+ * <App />
11
+ * </StytchB2BProvider>
12
+ * )
13
+ * @returns A {@link StytchB2BHeadlessClient}
14
+ */
15
+ declare const createStytchB2BHeadlessClient: (_PUBLIC_TOKEN: string, options?: import("core/dist/public").StytchClientOptions | undefined) => StytchB2BHeadlessClient;
16
+ export { createStytchB2BHeadlessClient };