@stytch/react 19.4.4 → 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.
- package/CHANGELOG.md +25 -0
- package/README.md +7 -7
- package/b2b/headless/package.json +6 -0
- package/b2b/ui/package.json +6 -0
- package/dist/{StytchB2BContext-09d376ba.d.ts → StytchB2BContext-9c062712.d.ts} +127 -23
- package/dist/{StytchB2BContext-09d376ba.js → StytchB2BContext-9c062712.js} +85 -42
- package/dist/{StytchB2BContext-a8d57249.d.ts → StytchB2BContext-c5062f9b.d.ts} +127 -23
- package/dist/{StytchB2BContext-a8d57249.js → StytchB2BContext-c5062f9b.js} +95 -52
- package/dist/StytchSSRProxy-34c789b5.d.ts +3 -0
- package/dist/StytchSSRProxy-34c789b5.js +48 -0
- package/dist/StytchSSRProxy-86bc42b3.d.ts +3 -0
- package/dist/StytchSSRProxy-86bc42b3.js +54 -0
- package/dist/adminPortal/index.d.ts +1 -1
- package/dist/adminPortal/index.esm.d.ts +1 -1
- package/dist/adminPortal/index.esm.js +5 -4
- package/dist/adminPortal/index.js +5 -4
- package/dist/b2b/index.d.ts +170 -6
- package/dist/b2b/index.esm.d.ts +170 -6
- package/dist/b2b/index.esm.js +85 -8
- package/dist/b2b/index.headless.d.ts +16 -0
- package/dist/b2b/index.headless.esm.d.ts +16 -0
- package/dist/b2b/index.headless.esm.js +24 -0
- package/dist/b2b/index.headless.js +28 -0
- package/dist/b2b/index.js +93 -16
- package/dist/b2b/index.ui.d.ts +17 -0
- package/dist/b2b/index.ui.esm.d.ts +17 -0
- package/dist/b2b/index.ui.esm.js +25 -0
- package/dist/b2b/index.ui.js +29 -0
- package/dist/errors-d9d5fbc8.d.ts +5 -0
- package/dist/index-b14d4efe.d.ts +1 -1
- package/dist/index.d.ts +92 -54
- package/dist/index.esm.d.ts +92 -54
- package/dist/index.esm.js +112 -38
- package/dist/index.headless.d.ts +16 -0
- package/dist/index.headless.esm.d.ts +16 -0
- package/dist/index.headless.esm.js +24 -0
- package/dist/index.headless.js +28 -0
- package/dist/index.js +126 -52
- package/dist/index.ui.d.ts +17 -0
- package/dist/index.ui.esm.d.ts +17 -0
- package/dist/index.ui.esm.js +25 -0
- package/dist/index.ui.js +29 -0
- package/dist/useIsomorphicLayoutEffect-1babb81e.d.ts +24 -0
- package/dist/{invariant-568a7633.js → useIsomorphicLayoutEffect-1babb81e.js} +5 -13
- package/dist/useIsomorphicLayoutEffect-65746ef3.d.ts +24 -0
- package/dist/{invariant-ae5a5bce.js → useIsomorphicLayoutEffect-65746ef3.js} +4 -16
- package/package.json +4 -3
- package/dist/invariant-568a7633.d.ts +0 -27
- 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
|
|
4
|
-
import { u as useIsMounted__INTERNAL, a as useStytchB2BClient } from '../StytchB2BContext-
|
|
5
|
-
import {
|
|
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
|
-
|
|
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-
|
|
8
|
-
var
|
|
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
|
-
|
|
17
|
+
useIsomorphicLayoutEffect.invariant(StytchB2BContext.useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError(`<${componentName} />`, 'StytchB2BProvider'));
|
|
17
18
|
const stytchClient = StytchB2BContext.useStytchB2BClient();
|
|
18
19
|
const containerEl = React.useRef(null);
|
|
19
|
-
|
|
20
|
+
useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
|
|
20
21
|
if (!containerEl.current) {
|
|
21
22
|
return;
|
|
22
23
|
}
|
package/dist/b2b/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React from "react";
|
|
3
|
-
import {
|
|
4
|
-
import { IDPConsentScreenManifest } from "@stytch/vanilla-js/b2b";
|
|
5
|
-
|
|
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> {
|
|
6
9
|
/**
|
|
7
10
|
* An optional {@link StyleConfig} to customize the look and feel of the screen.
|
|
8
11
|
*
|
|
@@ -141,6 +144,167 @@ declare const StytchB2B: <TProjectConfiguration extends Partial<import("@stytch/
|
|
|
141
144
|
* />
|
|
142
145
|
*/
|
|
143
146
|
declare const B2BIdentityProvider: ({ styles, callbacks, getIDPConsentManifest }: B2BIdentityProviderProps) => React.JSX.Element;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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 };
|
package/dist/b2b/index.esm.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React from "react";
|
|
3
|
-
import {
|
|
4
|
-
import { IDPConsentScreenManifest } from "@stytch/vanilla-js/b2b";
|
|
5
|
-
|
|
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> {
|
|
6
9
|
/**
|
|
7
10
|
* An optional {@link StyleConfig} to customize the look and feel of the screen.
|
|
8
11
|
*
|
|
@@ -141,6 +144,167 @@ declare const StytchB2B: <TProjectConfiguration extends Partial<import("@stytch/
|
|
|
141
144
|
* />
|
|
142
145
|
*/
|
|
143
146
|
declare const B2BIdentityProvider: ({ styles, callbacks, getIDPConsentManifest }: B2BIdentityProviderProps) => React.JSX.Element;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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 };
|
package/dist/b2b/index.esm.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { i as invariant,
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
|
+
import { u as useIsMounted__INTERNAL, a as useStytchB2BClient, i as isUIClient, b as useStytchMember$1, c as useStytchMemberSession$1, d as useStytchOrganization$1, e as useStytchIsAuthorized$1, w as withStytchMember$1, f as withStytchMemberSession$1, g as withStytchOrganization$1, S as StytchB2BProvider$1 } from '../StytchB2BContext-9c062712.js';
|
|
3
|
+
export { a as useStytchB2BClient, h as withStytchB2BClient, j as withStytchPermissions } from '../StytchB2BContext-9c062712.js';
|
|
4
|
+
import { i as invariant, a as useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect-1babb81e.js';
|
|
5
|
+
import { a as noHeadlessClientError, n as noProviderError } from '../StytchSSRProxy-34c789b5.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* The Stytch B2B UI component.
|
|
@@ -40,7 +41,7 @@ const StytchB2B = ({ styles, callbacks, config, }) => {
|
|
|
40
41
|
invariant(useIsMounted__INTERNAL(), noProviderError('<StytchB2B />', 'StytchB2BProvider'));
|
|
41
42
|
const stytchClient = useStytchB2BClient();
|
|
42
43
|
const containerEl = useRef(null);
|
|
43
|
-
|
|
44
|
+
useIsomorphicLayoutEffect(() => {
|
|
44
45
|
if (!isUIClient(stytchClient)) {
|
|
45
46
|
throw Error(noHeadlessClientError);
|
|
46
47
|
}
|
|
@@ -91,9 +92,9 @@ const StytchB2B = ({ styles, callbacks, config, }) => {
|
|
|
91
92
|
const B2BIdentityProvider = ({ styles, callbacks, getIDPConsentManifest }) => {
|
|
92
93
|
invariant(useIsMounted__INTERNAL(), noProviderError('<IdentityProvider />'));
|
|
93
94
|
const stytchClient = useStytchB2BClient();
|
|
94
|
-
const { member } = useStytchMember();
|
|
95
|
+
const { member } = useStytchMember$1();
|
|
95
96
|
const containerEl = useRef(null);
|
|
96
|
-
|
|
97
|
+
useIsomorphicLayoutEffect(() => {
|
|
97
98
|
if (!isUIClient(stytchClient)) {
|
|
98
99
|
throw Error(noHeadlessClientError);
|
|
99
100
|
}
|
|
@@ -114,4 +115,80 @@ const B2BIdentityProvider = ({ styles, callbacks, getIDPConsentManifest }) => {
|
|
|
114
115
|
return React.createElement("div", { ref: containerEl });
|
|
115
116
|
};
|
|
116
117
|
|
|
117
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Returns the active Member.
|
|
120
|
+
* The Stytch SDKs are used for client-side authentication and session management.
|
|
121
|
+
* Check the isInitialized property to determine if the SDK has completed initialization.
|
|
122
|
+
* Check the fromCache property to determine if the member data is from persistent storage.
|
|
123
|
+
* @example
|
|
124
|
+
* const {member, isInitialized, fromCache} = useStytchMember();
|
|
125
|
+
* if (!isInitialized) {
|
|
126
|
+
* return <p>Loading...</p>;
|
|
127
|
+
* }
|
|
128
|
+
* return (<h1>Welcome, {member.name}</h1>);
|
|
129
|
+
*/
|
|
130
|
+
const useStytchMember = useStytchMember$1;
|
|
131
|
+
/**
|
|
132
|
+
* Returns the active member's Stytch member session.
|
|
133
|
+
* The Stytch SDKs are used for client-side authentication and session management.
|
|
134
|
+
* Check the isInitialized property to determine if the SDK has completed initialization.
|
|
135
|
+
* Check the fromCache property to determine if the session data is from persistent storage.
|
|
136
|
+
* @example
|
|
137
|
+
* const {session, isInitialized, fromCache} = useStytchMemberSession();
|
|
138
|
+
* useEffect(() => {
|
|
139
|
+
* if (!isInitialized) {
|
|
140
|
+
* return;
|
|
141
|
+
* }
|
|
142
|
+
* if (!session) {
|
|
143
|
+
* router.replace('/login')
|
|
144
|
+
* }
|
|
145
|
+
* }, [session, isInitialized]);
|
|
146
|
+
*/
|
|
147
|
+
const useStytchMemberSession = useStytchMemberSession$1;
|
|
148
|
+
/**
|
|
149
|
+
* Returns the active Stytch organization.
|
|
150
|
+
* The Stytch SDKs are used for client-side authentication and session management.
|
|
151
|
+
* Check the isInitialized property to determine if the SDK has completed initialization.
|
|
152
|
+
* Check the fromCache property to determine if the organization data is from persistent storage.
|
|
153
|
+
* @example
|
|
154
|
+
* const {organization, isInitialized, fromCache} = useStytchOrganization();
|
|
155
|
+
* if (!isInitialized) {
|
|
156
|
+
* return <p>Loading...</p>;
|
|
157
|
+
* }
|
|
158
|
+
* return (<p>Welcome to {organization.organization_name}</p>);
|
|
159
|
+
*/
|
|
160
|
+
const useStytchOrganization = useStytchOrganization$1;
|
|
161
|
+
/**
|
|
162
|
+
* Determines whether the logged-in member is allowed to perform the specified action on the specified resource.
|
|
163
|
+
* Returns `true` if the member can perform the action, `false` otherwise.
|
|
164
|
+
*
|
|
165
|
+
* If the member is not logged in, this method will always return false.
|
|
166
|
+
* If the resource or action provided are not valid for the configured RBAC policy, this method will return false.
|
|
167
|
+
*
|
|
168
|
+
* Remember - authorization checks for sensitive actions should always occur on the backend as well.
|
|
169
|
+
* @example
|
|
170
|
+
* const { isAuthorized } = useStytchIsAuthorized<Permissions>('documents', 'edit');
|
|
171
|
+
* return <button disabled={!isAuthorized}>Edit</button>
|
|
172
|
+
*/
|
|
173
|
+
const useStytchIsAuthorized = useStytchIsAuthorized$1;
|
|
174
|
+
const withStytchMember = withStytchMember$1;
|
|
175
|
+
const withStytchMemberSession = withStytchMemberSession$1;
|
|
176
|
+
const withStytchOrganization = withStytchOrganization$1;
|
|
177
|
+
/**
|
|
178
|
+
* The Stytch Context Provider.
|
|
179
|
+
* Wrap your application with this component in order to use Stytch everywhere in your app.
|
|
180
|
+
* @example
|
|
181
|
+
* const stytch = createStytchB2BHeadlessClient('public-token-<find yours in the stytch dashboard>')
|
|
182
|
+
*
|
|
183
|
+
* ReactDOM.render(
|
|
184
|
+
* <StytchB2BProvider stytch={stytch}>
|
|
185
|
+
* <App />
|
|
186
|
+
* </StytchProvider>,
|
|
187
|
+
* document.getElementById('root'),
|
|
188
|
+
* )
|
|
189
|
+
*/
|
|
190
|
+
const StytchB2BProvider = ({ stytch, children, assumeHydrated = true, }) => {
|
|
191
|
+
return (React.createElement(StytchB2BProvider$1, { stytch: stytch, assumeHydrated: assumeHydrated }, children));
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export { B2BIdentityProvider, StytchB2B, StytchB2BProvider, useStytchIsAuthorized, useStytchMember, useStytchMemberSession, useStytchOrganization, withStytchMember, withStytchMemberSession, withStytchOrganization };
|
|
@@ -0,0 +1,16 @@
|
|
|
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: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>(_PUBLIC_TOKEN: string, options?: import("@stytch/core/public").StytchClientOptions | undefined) => StytchB2BHeadlessClient<TProjectConfiguration>;
|
|
16
|
+
export { createStytchB2BHeadlessClient };
|
|
@@ -0,0 +1,16 @@
|
|
|
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: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>(_PUBLIC_TOKEN: string, options?: import("@stytch/core/public").StytchClientOptions | undefined) => StytchB2BHeadlessClient<TProjectConfiguration>;
|
|
16
|
+
export { createStytchB2BHeadlessClient };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { StytchB2BHeadlessClient } from '@stytch/vanilla-js/b2b/headless';
|
|
2
|
+
import { c as createStytchSSRProxy } from '../StytchSSRProxy-34c789b5.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a Headless Stytch client object to call the stytch B2B APIs.
|
|
6
|
+
* The Stytch client is not available serverside.
|
|
7
|
+
* @example
|
|
8
|
+
* const stytch = createStytchB2BHeadlessClient('public-token-<find yours in the stytch dashboard>')
|
|
9
|
+
*
|
|
10
|
+
* return (
|
|
11
|
+
* <StytchB2BProvider stytch={stytch}>
|
|
12
|
+
* <App />
|
|
13
|
+
* </StytchB2BProvider>
|
|
14
|
+
* )
|
|
15
|
+
* @returns A {@link StytchB2BHeadlessClient}
|
|
16
|
+
*/
|
|
17
|
+
const createStytchB2BHeadlessClient = (...args) => {
|
|
18
|
+
if (typeof window === 'undefined') {
|
|
19
|
+
return createStytchSSRProxy();
|
|
20
|
+
}
|
|
21
|
+
return new StytchB2BHeadlessClient(...args);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { createStytchB2BHeadlessClient };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var headless = require('@stytch/vanilla-js/b2b/headless');
|
|
6
|
+
var StytchSSRProxy = require('../StytchSSRProxy-86bc42b3.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates a Headless Stytch client object to call the stytch B2B APIs.
|
|
10
|
+
* The Stytch client is not available serverside.
|
|
11
|
+
* @example
|
|
12
|
+
* const stytch = createStytchB2BHeadlessClient('public-token-<find yours in the stytch dashboard>')
|
|
13
|
+
*
|
|
14
|
+
* return (
|
|
15
|
+
* <StytchB2BProvider stytch={stytch}>
|
|
16
|
+
* <App />
|
|
17
|
+
* </StytchB2BProvider>
|
|
18
|
+
* )
|
|
19
|
+
* @returns A {@link StytchB2BHeadlessClient}
|
|
20
|
+
*/
|
|
21
|
+
const createStytchB2BHeadlessClient = (...args) => {
|
|
22
|
+
if (typeof window === 'undefined') {
|
|
23
|
+
return StytchSSRProxy.createStytchSSRProxy();
|
|
24
|
+
}
|
|
25
|
+
return new headless.StytchB2BHeadlessClient(...args);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.createStytchB2BHeadlessClient = createStytchB2BHeadlessClient;
|