@stytch/react 19.14.0 → 19.15.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 (42) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/StytchB2BContext-dad97135.js +1 -0
  3. package/dist/StytchB2BContext-dad97135.js.map +1 -0
  4. package/dist/StytchB2BContext-dc5957f6.js +1 -0
  5. package/dist/StytchB2BContext-dc5957f6.js.map +1 -0
  6. package/dist/StytchSSRProxy-34c789b5.js +1 -0
  7. package/dist/StytchSSRProxy-34c789b5.js.map +1 -0
  8. package/dist/StytchSSRProxy-86bc42b3.js +1 -0
  9. package/dist/StytchSSRProxy-86bc42b3.js.map +1 -0
  10. package/dist/adminPortal/index.esm.js +1 -0
  11. package/dist/adminPortal/index.esm.js.map +1 -0
  12. package/dist/adminPortal/index.js +1 -0
  13. package/dist/adminPortal/index.js.map +1 -0
  14. package/dist/b2b/index.esm.js +1 -0
  15. package/dist/b2b/index.esm.js.map +1 -0
  16. package/dist/b2b/index.headless.esm.js +1 -0
  17. package/dist/b2b/index.headless.esm.js.map +1 -0
  18. package/dist/b2b/index.headless.js +1 -0
  19. package/dist/b2b/index.headless.js.map +1 -0
  20. package/dist/b2b/index.js +1 -0
  21. package/dist/b2b/index.js.map +1 -0
  22. package/dist/b2b/index.ui.esm.js +1 -0
  23. package/dist/b2b/index.ui.esm.js.map +1 -0
  24. package/dist/b2b/index.ui.js +1 -0
  25. package/dist/b2b/index.ui.js.map +1 -0
  26. package/dist/index.esm.js +1 -0
  27. package/dist/index.esm.js.map +1 -0
  28. package/dist/index.headless.esm.js +1 -0
  29. package/dist/index.headless.esm.js.map +1 -0
  30. package/dist/index.headless.js +1 -0
  31. package/dist/index.headless.js.map +1 -0
  32. package/dist/index.js +1 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/index.ui.esm.js +1 -0
  35. package/dist/index.ui.esm.js.map +1 -0
  36. package/dist/index.ui.js +1 -0
  37. package/dist/index.ui.js.map +1 -0
  38. package/dist/useIsomorphicLayoutEffect-35a9b44b.js +1 -0
  39. package/dist/useIsomorphicLayoutEffect-35a9b44b.js.map +1 -0
  40. package/dist/useIsomorphicLayoutEffect-3bc90e37.js +1 -0
  41. package/dist/useIsomorphicLayoutEffect-3bc90e37.js.map +1 -0
  42. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @stytch/react
2
2
 
3
+ ## 19.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c64d639: When initializing StytchClient, the endpointOptions object is now deprecated
8
+ apiDomain and testApiDomain are now configured using customBaseUrl directly on the root object
9
+ fppaDomain and dfpCdnDomain are now configured as dfppaUrl and dfpCdnUrl directly on the root object
10
+ - b099ae8: Sourcemaps are now included
11
+
3
12
  ## 19.14.0
4
13
 
5
14
  ### Minor Changes
@@ -278,3 +278,4 @@ exports.withStytchMember = withStytchMember;
278
278
  exports.withStytchMemberSession = withStytchMemberSession;
279
279
  exports.withStytchOrganization = withStytchOrganization;
280
280
  exports.withStytchPermissions = withStytchPermissions;
281
+ //# sourceMappingURL=StytchB2BContext-dad97135.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StytchB2BContext-dad97135.js","sources":["../../../internal/react-shared/src/b2b/StytchB2BContext.tsx"],"sourcesContent":["import React, {\n ComponentType,\n createContext,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport { PermissionsMap } from '@stytch/core/public';\nimport { mergeWithStableProps } from '@stytch/js-utils';\nimport type { Member, MemberSession, Organization, StytchB2BUIClient } from '@stytch/vanilla-js/b2b';\nimport type { StytchB2BHeadlessClient, StytchProjectConfigurationInput } from '@stytch/vanilla-js/b2b/headless';\nimport { isStytchSSRProxy } from '../StytchSSRProxy';\nimport { useAsyncState } from '../utils/async';\nimport { noProviderError } from '../utils/errors';\nimport { invariant } from '../utils/invariant';\n\n/**\n * The Stytch Client object passed in to <StytchB2BProvider /> in your application root.\n * Either a StytchB2BUIClient or StytchB2BHeadlessClient.\n */\ntype StytchB2BClient<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | StytchB2BHeadlessClient<TProjectConfiguration>\n | StytchB2BUIClient<TProjectConfiguration>;\n\ntype StytchB2BContext<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | {\n isMounted: false;\n }\n | {\n isMounted: true;\n client: StytchB2BClient<TProjectConfiguration>;\n };\n\ntype SWRMemberUninitialized = {\n /**\n * Either the active {@link Member} object, or null if the member is not logged in.\n */\n member: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRMemberInitialized = {\n /**\n * Either the active {@link Member} object, or null if the member is not logged in.\n */\n member: Member | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRMember<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRMemberInitialized\n : SWRMemberInitialized | SWRMemberUninitialized;\n\nconst initialMember: SWRMember = {\n member: null,\n fromCache: false,\n isInitialized: false,\n};\n\ntype SWRMemberSessionUninitialized = {\n /**\n * Either the active {@link MemberSession} object, or null if the member is not logged in.\n */\n session: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRMemberSessionInitialized = {\n /**\n * Either the active {@link MemberSession} object, or null if the member is not logged in.\n */\n session: MemberSession | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRMemberSession<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRMemberSessionInitialized\n : SWRMemberSessionInitialized | SWRMemberSessionUninitialized;\n\nconst initialMemberSession: SWRMemberSession = {\n session: null,\n fromCache: false,\n isInitialized: false,\n};\n\ntype SWROrganizationUninitialized = {\n /**\n * Either the active {@link Organization} object, or null if the member is not logged in.\n */\n organization: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWROrganizationInitialized = {\n /**\n * Either the active {@link Organization} object, or null if the member is not logged in.\n */\n organization: Organization | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWROrganization<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWROrganizationInitialized\n : SWROrganizationInitialized | SWROrganizationUninitialized;\n\nconst initialOrganization: SWROrganization = {\n organization: null,\n fromCache: false,\n isInitialized: false,\n};\n\nconst StytchB2BContext = createContext<StytchB2BContext<StytchProjectConfigurationInput>>({ isMounted: false });\nconst StytchMemberContext = createContext<SWRMember>(initialMember);\nconst StytchMemberSessionContext = createContext<SWRMemberSession>(initialMemberSession);\nconst StytchOrganizationContext = createContext<SWROrganization>(initialOrganization);\n\nexport const useIsMounted__INTERNAL = (): boolean => useContext(StytchB2BContext).isMounted;\n\nexport const isUIClient = <TProjectConfiguration extends StytchProjectConfigurationInput>(\n client: StytchB2BClient<TProjectConfiguration>,\n): client is StytchB2BUIClient<TProjectConfiguration> => {\n return (client as StytchB2BUIClient<TProjectConfiguration>).mount !== undefined;\n};\n\n/**\n * Returns the active Member.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the member data is from persistent storage.\n * @example\n * const {member, isInitialized, fromCache} = useStytchMember();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<h1>Welcome, {member.name}</h1>);\n */\nexport const useStytchMember = <TAssumeHydrated extends boolean = false>(): SWRMember<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchMember', 'StytchB2BProvider'));\n return useContext(StytchMemberContext) as SWRMember<TAssumeHydrated>;\n};\n\n/**\n * Returns the active member's Stytch member session.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the session data is from persistent storage.\n * @example\n * const {session, isInitialized, fromCache} = useStytchMemberSession();\n * useEffect(() => {\n * if (!isInitialized) {\n * return;\n * }\n * if (!session) {\n * router.replace('/login')\n * }\n * }, [session, isInitialized]);\n */\nexport const useStytchMemberSession = <\n TAssumeHydrated extends boolean = false,\n>(): SWRMemberSession<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchMemberSession', 'StytchB2BProvider'));\n return useContext(StytchMemberSessionContext) as SWRMemberSession<TAssumeHydrated>;\n};\n\n/**\n * Returns the active Stytch organization.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the organization data is from persistent storage.\n * @example\n * const {organization, isInitialized, fromCache} = useStytchOrganization();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<p>Welcome to {organization.organization_name}</p>);\n */\nexport const useStytchOrganization = <TAssumeHydrated extends boolean = false>(): SWROrganization<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchOrganization', 'StytchB2BProvider'));\n return useContext(StytchOrganizationContext) as SWROrganization<TAssumeHydrated>;\n};\n\ntype SWRIsAuthorizedUninitialized = {\n /**\n * Whether the logged-in member is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: false;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRIsAuthorizedInitialized = {\n /**\n * Whether the logged-in member is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: boolean;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: boolean;\n};\n\ntype SWRIsAuthorized<TAlwaysInitialized extends boolean> = TAlwaysInitialized extends true\n ? SWRIsAuthorizedInitialized\n : SWRIsAuthorizedInitialized | SWRIsAuthorizedUninitialized;\n\n/**\n * Determines whether the logged-in member is allowed to perform the specified action on the specified resource.\n * Returns `true` if the member can perform the action, `false` otherwise.\n *\n * If the member is not logged in, this method will always return false.\n * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * const { isAuthorized } = useStytchIsAuthorized<Permissions>('documents', 'edit');\n * return <button disabled={!isAuthorized}>Edit</button>\n */\nexport const useStytchIsAuthorized = <TAssumeHydrated extends boolean = false>(\n resourceId: string,\n action: string,\n): SWRIsAuthorized<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchIsAuthorized', 'StytchB2BProvider'));\n const client = useStytchB2BClient();\n const { session } = useStytchMemberSession();\n const [isAuthorized, setIsAuthorized] = useAsyncState<SWRIsAuthorized<boolean>>({\n isInitialized: false,\n fromCache: false,\n isAuthorized: false,\n });\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n\n setIsAuthorized({\n isInitialized: true,\n fromCache: true,\n isAuthorized: client.rbac.isAuthorizedSync(resourceId, action),\n });\n }, [action, client, resourceId, setIsAuthorized]);\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n\n client.rbac.isAuthorized(resourceId, action).then((isAuthorized) => {\n setIsAuthorized({ isAuthorized, fromCache: false, isInitialized: true });\n });\n }, [client, session?.roles, resourceId, action, setIsAuthorized]);\n\n return isAuthorized;\n};\n\n/**\n * Returns the Stytch B2B client stored in the Stytch context.\n *\n * @example\n * const stytch = useStytchB2BClient();\n * useEffect(() => {\n * stytch.magicLinks.authenticate('...')\n * }, [stytch]);\n */\nexport const useStytchB2BClient = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(): StytchB2BHeadlessClient<TProjectConfiguration> => {\n const ctx = useContext(StytchB2BContext);\n invariant(ctx.isMounted, noProviderError('useStytchB2BClient', 'StytchB2BProvider'));\n return ctx.client as StytchB2BHeadlessClient<TProjectConfiguration>;\n};\n\nexport const withStytchB2BClient = <T extends object, TProjectConfiguration extends StytchProjectConfigurationInput>(\n Component: ComponentType<T & { stytch: StytchB2BHeadlessClient<TProjectConfiguration> }>,\n): ComponentType<T> => {\n const WithStytch: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchB2BClient', 'StytchB2BProvider'));\n return <Component {...props} stytch={useStytchB2BClient()} />;\n };\n WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;\n return WithStytch;\n};\n\nexport const withStytchMember = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & { stytchMember: Member | null; stytchMemberIsInitialized: boolean; stytchMemberIsFromCache: boolean }\n >,\n): ComponentType<T> => {\n const WithStytchUser: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchMember', 'StytchB2BProvider'));\n const { member, isInitialized, fromCache } = useStytchMember<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchMember={member}\n stytchMemberIsInitialized={isInitialized}\n stytchMemberIsFromCache={fromCache}\n />\n );\n };\n WithStytchUser.displayName = `withStytchMember(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchUser;\n};\n\nexport const withStytchMemberSession = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & {\n stytchMemberSession: MemberSession | null;\n stytchMemberSessionIsInitialized: boolean;\n stytchMemberSessionIsFromCache: boolean;\n }\n >,\n): ComponentType<T> => {\n const WithStytchSession: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchMemberSession', 'StytchB2BProvider'));\n const { session, isInitialized, fromCache } = useStytchMemberSession<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchMemberSession={session}\n stytchMemberSessionIsInitialized={isInitialized}\n stytchMemberSessionIsFromCache={fromCache}\n />\n );\n };\n WithStytchSession.displayName = `withStytchMemberSession(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchSession;\n};\n\nexport const withStytchOrganization = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & {\n stytchOrganization: Organization | null;\n stytchOrganizationIsInitialized: boolean;\n stytchOrganizationIsFromCache: boolean;\n }\n >,\n): ComponentType<T> => {\n const WithStytchOrganization: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchOrganization', 'StytchB2BProvider'));\n const { organization, isInitialized, fromCache } = useStytchOrganization<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchOrganization={organization}\n stytchOrganizationIsInitialized={isInitialized}\n stytchOrganizationIsFromCache={fromCache}\n />\n );\n };\n WithStytchOrganization.displayName = `withStytchOrganization(${\n Component.displayName || Component.name || 'Component'\n })`;\n return WithStytchOrganization;\n};\n\ntype permissionsLoaded<Permissions extends Record<string, string>> =\n | {\n loaded: false;\n value: null;\n }\n | {\n loaded: true;\n value: PermissionsMap<Permissions>;\n };\n\n/**\n * Wrap your component with this HOC in order to receive the permissions for the logged-in member.\n * Evaluates all permissions granted to the logged-in member.\n * Returns a Record<RoleId, Record<Action, boolean>> response indicating the member's permissions.\n * Each boolean will be `true` if the member can perform the action, `false` otherwise.\n *\n * If the member is not logged in, all values will be false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * type Permissions = {\n * document: 'create' | 'read' | 'write\n * image: 'create' | 'read'\n * }\n *\n * const MyComponent = (props) => {\n * const canEditDocuments = props.stytchPermissions.document.edit;\n * const canReadImages = props.stytchPermissions.image.read;\n * }\n * return withStytchPermissions<Permissions>(MyComponent)\n */\nexport const withStytchPermissions = <Permissions extends Record<string, string>, T extends object>(\n Component: ComponentType<T & { stytchPermissions: PermissionsMap<Permissions> }>,\n): ComponentType<T> => {\n const WithStytchPermissions: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useRBACPermissions', 'StytchB2BProvider'));\n const client = useStytchB2BClient();\n const { session } = useStytchMemberSession();\n const [permissions, setPermissions] = useAsyncState<permissionsLoaded<Permissions>>({ loaded: false, value: null });\n useEffect(() => {\n client.rbac\n .allPermissions<Permissions>()\n .then((permissions) => setPermissions({ loaded: true, value: permissions }));\n }, [client, session?.roles, setPermissions]);\n\n if (!permissions.loaded) {\n return null;\n }\n return <Component {...props} stytchPermissions={permissions.value} />;\n };\n WithStytchPermissions.displayName = `withStytchPermissions(${\n Component.displayName || Component.name || 'Component'\n })`;\n return WithStytchPermissions;\n};\n\nexport interface StytchB2BProviderProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> {\n /**\n * A Stytch client instance, created using either {@link createStytchHeadlessClient} or {@link createStytchUIClient}\n */\n stytch: StytchB2BClient<TProjectConfiguration>;\n /**\n * When true, the provider will assume that the component will only be\n * rendered in a browser environment, either in a single-page application or\n * after completing hydration of a server-rendered application. This allows\n * cached values to be retrieved from the browser on the first render, meaning\n * that the `isInitialized` value returned from Stytch hooks will be `true`\n * starting from the first render.\n *\n * When `false`, the provider will defer initialization until after the first\n * render, and `isInitialized` will initially be `false`.\n *\n * This value defaults to `false` in `@stytch/nextjs`.\n */\n assumeHydrated?: boolean;\n children?: ReactNode;\n}\n\n/**\n * The Stytch Context Provider.\n * Wrap your application with this component in order to use Stytch everywhere in your app.\n * @example\n * const stytch = createStytchB2BHeadlessClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchB2BProvider stytch={stytch}>\n * <App />\n * </StytchB2BProvider>\n * )\n */\nexport const StytchB2BProvider = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n stytch,\n children,\n assumeHydrated = false,\n}: StytchB2BProviderProps<TProjectConfiguration>): JSX.Element => {\n invariant(!useIsMounted__INTERNAL(), 'You cannot render a <StytchB2BProvider> inside another <StytchB2BProvider>.');\n invariant(\n !assumeHydrated || typeof window !== 'undefined',\n 'The `assumeHydrated` prop must be set to `false` when using StytchB2BProvider in a server environment.',\n );\n\n const ctx = useMemo(() => ({ client: stytch, isMounted: true }), [stytch]);\n\n type ClientState<TAlwaysInitialized extends boolean> = {\n member: SWRMember<TAlwaysInitialized>;\n session: SWRMemberSession<TAlwaysInitialized>;\n organization: SWROrganization<TAlwaysInitialized>;\n };\n\n const getHydratedState = useCallback(() => {\n return {\n member: { ...stytch.self.getInfo(), isInitialized: true },\n session: { ...stytch.session.getInfo(), isInitialized: true },\n organization: { ...stytch.organization.getInfo(), isInitialized: true },\n } satisfies ClientState<true>;\n }, [stytch]);\n\n const getInitialState = () => {\n return {\n member: initialMember,\n session: initialMemberSession,\n organization: initialOrganization,\n } satisfies ClientState<false>;\n };\n\n const [{ member, session, organization }, setClientState] = useAsyncState<ClientState<boolean>>(() =>\n assumeHydrated ? getHydratedState() : (getInitialState() as ClientState<boolean>),\n );\n\n // Store the initial value of `assumeHydrated` in a ref, because it is\n // logically only relevant for the first render\n const assumeHydratedRef = useRef(assumeHydrated);\n useEffect(() => {\n if (isStytchSSRProxy(stytch)) {\n return;\n }\n\n const updateState = () => {\n setClientState((oldState) => mergeWithStableProps(oldState, getHydratedState()));\n };\n\n if (!assumeHydratedRef.current) {\n updateState();\n }\n\n return stytch.onStateChange(updateState);\n }, [getHydratedState, setClientState, stytch]);\n\n return (\n <StytchB2BContext.Provider value={ctx}>\n <StytchOrganizationContext.Provider value={organization}>\n <StytchMemberContext.Provider value={member}>\n <StytchMemberSessionContext.Provider value={session}>{children}</StytchMemberSessionContext.Provider>\n </StytchMemberContext.Provider>\n </StytchOrganizationContext.Provider>\n </StytchB2BContext.Provider>\n );\n};\n"],"names":["createContext","useContext","invariant","noProviderError","useAsyncState","useEffect","isStytchSSRProxy","React","useMemo","useCallback","useRef","mergeWithStableProps"],"mappings":";;;;;;;;;;AAuEA,MAAM,aAAa,GAAc;AAC/B,IAAA,MAAM,EAAE,IAAI;AACZ,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,aAAa,EAAE,KAAK;CACrB,CAAC;AAoCF,MAAM,oBAAoB,GAAqB;AAC7C,IAAA,OAAO,EAAE,IAAI;AACb,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,aAAa,EAAE,KAAK;CACrB,CAAC;AAoCF,MAAM,mBAAmB,GAAoB;AAC3C,IAAA,YAAY,EAAE,IAAI;AAClB,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,aAAa,EAAE,KAAK;CACrB,CAAC;AAEF,MAAM,gBAAgB,GAAGA,mBAAa,CAAoD,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;AAChH,MAAM,mBAAmB,GAAGA,mBAAa,CAAY,aAAa,CAAC,CAAC;AACpE,MAAM,0BAA0B,GAAGA,mBAAa,CAAmB,oBAAoB,CAAC,CAAC;AACzF,MAAM,yBAAyB,GAAGA,mBAAa,CAAkB,mBAAmB,CAAC,CAAC;AAE/E,MAAM,sBAAsB,GAAG,MAAeC,gBAAU,CAAC,gBAAgB,CAAC,CAAC,UAAU;AAE/E,MAAA,UAAU,GAAG,CACxB,MAA8C,KACQ;AACtD,IAAA,OAAQ,MAAmD,CAAC,KAAK,KAAK,SAAS,CAAC;AAClF,EAAE;AAEF;;;;;;;;;;;AAWG;AACI,MAAM,eAAe,GAAG,MAA0E;IACvGC,mCAAS,CAAC,sBAAsB,EAAE,EAAEC,8BAAe,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAC7F,IAAA,OAAOF,gBAAU,CAAC,mBAAmB,CAA+B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AAC,QAAQ,KAAKK,8CAAoB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC;AACnF,SAAC,CAAC;AAEF,QAAA,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE;AAC9B,YAAA,WAAW,EAAE,CAAC;SACf;AAED,QAAA,OAAO,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;KAC1C,EAAE,CAAC,gBAAgB,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC;IAE/C,QACEJ,wCAAC,gBAAgB,CAAC,QAAQ,EAAC,EAAA,KAAK,EAAE,GAAG,EAAA;AACnC,QAAAA,yBAAA,CAAA,aAAA,CAAC,yBAAyB,CAAC,QAAQ,EAAC,EAAA,KAAK,EAAE,YAAY,EAAA;AACrD,YAAAA,yBAAA,CAAA,aAAA,CAAC,mBAAmB,CAAC,QAAQ,EAAC,EAAA,KAAK,EAAE,MAAM,EAAA;AACzC,gBAAAA,yBAAA,CAAA,aAAA,CAAC,0BAA0B,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,OAAO,EAAG,EAAA,QAAQ,CAAuC,CACxE,CACI,CACX,EAC5B;AACJ;;;;;;;;;;;;;;;;"}
@@ -260,3 +260,4 @@ const StytchB2BProvider = ({ stytch, children, assumeHydrated = false, }) => {
260
260
  };
261
261
 
262
262
  export { StytchB2BProvider as S, useStytchB2BClient as a, useStytchMember as b, useStytchMemberSession as c, useStytchOrganization as d, useStytchIsAuthorized as e, withStytchMemberSession as f, withStytchOrganization as g, withStytchB2BClient as h, isUIClient as i, withStytchPermissions as j, useIsMounted__INTERNAL as u, withStytchMember as w };
263
+ //# sourceMappingURL=StytchB2BContext-dc5957f6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StytchB2BContext-dc5957f6.js","sources":["../../../internal/react-shared/src/b2b/StytchB2BContext.tsx"],"sourcesContent":["import React, {\n ComponentType,\n createContext,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport { PermissionsMap } from '@stytch/core/public';\nimport { mergeWithStableProps } from '@stytch/js-utils';\nimport type { Member, MemberSession, Organization, StytchB2BUIClient } from '@stytch/vanilla-js/b2b';\nimport type { StytchB2BHeadlessClient, StytchProjectConfigurationInput } from '@stytch/vanilla-js/b2b/headless';\nimport { isStytchSSRProxy } from '../StytchSSRProxy';\nimport { useAsyncState } from '../utils/async';\nimport { noProviderError } from '../utils/errors';\nimport { invariant } from '../utils/invariant';\n\n/**\n * The Stytch Client object passed in to <StytchB2BProvider /> in your application root.\n * Either a StytchB2BUIClient or StytchB2BHeadlessClient.\n */\ntype StytchB2BClient<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | StytchB2BHeadlessClient<TProjectConfiguration>\n | StytchB2BUIClient<TProjectConfiguration>;\n\ntype StytchB2BContext<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | {\n isMounted: false;\n }\n | {\n isMounted: true;\n client: StytchB2BClient<TProjectConfiguration>;\n };\n\ntype SWRMemberUninitialized = {\n /**\n * Either the active {@link Member} object, or null if the member is not logged in.\n */\n member: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRMemberInitialized = {\n /**\n * Either the active {@link Member} object, or null if the member is not logged in.\n */\n member: Member | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRMember<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRMemberInitialized\n : SWRMemberInitialized | SWRMemberUninitialized;\n\nconst initialMember: SWRMember = {\n member: null,\n fromCache: false,\n isInitialized: false,\n};\n\ntype SWRMemberSessionUninitialized = {\n /**\n * Either the active {@link MemberSession} object, or null if the member is not logged in.\n */\n session: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRMemberSessionInitialized = {\n /**\n * Either the active {@link MemberSession} object, or null if the member is not logged in.\n */\n session: MemberSession | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRMemberSession<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRMemberSessionInitialized\n : SWRMemberSessionInitialized | SWRMemberSessionUninitialized;\n\nconst initialMemberSession: SWRMemberSession = {\n session: null,\n fromCache: false,\n isInitialized: false,\n};\n\ntype SWROrganizationUninitialized = {\n /**\n * Either the active {@link Organization} object, or null if the member is not logged in.\n */\n organization: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWROrganizationInitialized = {\n /**\n * Either the active {@link Organization} object, or null if the member is not logged in.\n */\n organization: Organization | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWROrganization<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWROrganizationInitialized\n : SWROrganizationInitialized | SWROrganizationUninitialized;\n\nconst initialOrganization: SWROrganization = {\n organization: null,\n fromCache: false,\n isInitialized: false,\n};\n\nconst StytchB2BContext = createContext<StytchB2BContext<StytchProjectConfigurationInput>>({ isMounted: false });\nconst StytchMemberContext = createContext<SWRMember>(initialMember);\nconst StytchMemberSessionContext = createContext<SWRMemberSession>(initialMemberSession);\nconst StytchOrganizationContext = createContext<SWROrganization>(initialOrganization);\n\nexport const useIsMounted__INTERNAL = (): boolean => useContext(StytchB2BContext).isMounted;\n\nexport const isUIClient = <TProjectConfiguration extends StytchProjectConfigurationInput>(\n client: StytchB2BClient<TProjectConfiguration>,\n): client is StytchB2BUIClient<TProjectConfiguration> => {\n return (client as StytchB2BUIClient<TProjectConfiguration>).mount !== undefined;\n};\n\n/**\n * Returns the active Member.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the member data is from persistent storage.\n * @example\n * const {member, isInitialized, fromCache} = useStytchMember();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<h1>Welcome, {member.name}</h1>);\n */\nexport const useStytchMember = <TAssumeHydrated extends boolean = false>(): SWRMember<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchMember', 'StytchB2BProvider'));\n return useContext(StytchMemberContext) as SWRMember<TAssumeHydrated>;\n};\n\n/**\n * Returns the active member's Stytch member session.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the session data is from persistent storage.\n * @example\n * const {session, isInitialized, fromCache} = useStytchMemberSession();\n * useEffect(() => {\n * if (!isInitialized) {\n * return;\n * }\n * if (!session) {\n * router.replace('/login')\n * }\n * }, [session, isInitialized]);\n */\nexport const useStytchMemberSession = <\n TAssumeHydrated extends boolean = false,\n>(): SWRMemberSession<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchMemberSession', 'StytchB2BProvider'));\n return useContext(StytchMemberSessionContext) as SWRMemberSession<TAssumeHydrated>;\n};\n\n/**\n * Returns the active Stytch organization.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the organization data is from persistent storage.\n * @example\n * const {organization, isInitialized, fromCache} = useStytchOrganization();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<p>Welcome to {organization.organization_name}</p>);\n */\nexport const useStytchOrganization = <TAssumeHydrated extends boolean = false>(): SWROrganization<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchOrganization', 'StytchB2BProvider'));\n return useContext(StytchOrganizationContext) as SWROrganization<TAssumeHydrated>;\n};\n\ntype SWRIsAuthorizedUninitialized = {\n /**\n * Whether the logged-in member is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: false;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRIsAuthorizedInitialized = {\n /**\n * Whether the logged-in member is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: boolean;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: boolean;\n};\n\ntype SWRIsAuthorized<TAlwaysInitialized extends boolean> = TAlwaysInitialized extends true\n ? SWRIsAuthorizedInitialized\n : SWRIsAuthorizedInitialized | SWRIsAuthorizedUninitialized;\n\n/**\n * Determines whether the logged-in member is allowed to perform the specified action on the specified resource.\n * Returns `true` if the member can perform the action, `false` otherwise.\n *\n * If the member is not logged in, this method will always return false.\n * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * const { isAuthorized } = useStytchIsAuthorized<Permissions>('documents', 'edit');\n * return <button disabled={!isAuthorized}>Edit</button>\n */\nexport const useStytchIsAuthorized = <TAssumeHydrated extends boolean = false>(\n resourceId: string,\n action: string,\n): SWRIsAuthorized<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchIsAuthorized', 'StytchB2BProvider'));\n const client = useStytchB2BClient();\n const { session } = useStytchMemberSession();\n const [isAuthorized, setIsAuthorized] = useAsyncState<SWRIsAuthorized<boolean>>({\n isInitialized: false,\n fromCache: false,\n isAuthorized: false,\n });\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n\n setIsAuthorized({\n isInitialized: true,\n fromCache: true,\n isAuthorized: client.rbac.isAuthorizedSync(resourceId, action),\n });\n }, [action, client, resourceId, setIsAuthorized]);\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n\n client.rbac.isAuthorized(resourceId, action).then((isAuthorized) => {\n setIsAuthorized({ isAuthorized, fromCache: false, isInitialized: true });\n });\n }, [client, session?.roles, resourceId, action, setIsAuthorized]);\n\n return isAuthorized;\n};\n\n/**\n * Returns the Stytch B2B client stored in the Stytch context.\n *\n * @example\n * const stytch = useStytchB2BClient();\n * useEffect(() => {\n * stytch.magicLinks.authenticate('...')\n * }, [stytch]);\n */\nexport const useStytchB2BClient = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(): StytchB2BHeadlessClient<TProjectConfiguration> => {\n const ctx = useContext(StytchB2BContext);\n invariant(ctx.isMounted, noProviderError('useStytchB2BClient', 'StytchB2BProvider'));\n return ctx.client as StytchB2BHeadlessClient<TProjectConfiguration>;\n};\n\nexport const withStytchB2BClient = <T extends object, TProjectConfiguration extends StytchProjectConfigurationInput>(\n Component: ComponentType<T & { stytch: StytchB2BHeadlessClient<TProjectConfiguration> }>,\n): ComponentType<T> => {\n const WithStytch: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchB2BClient', 'StytchB2BProvider'));\n return <Component {...props} stytch={useStytchB2BClient()} />;\n };\n WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;\n return WithStytch;\n};\n\nexport const withStytchMember = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & { stytchMember: Member | null; stytchMemberIsInitialized: boolean; stytchMemberIsFromCache: boolean }\n >,\n): ComponentType<T> => {\n const WithStytchUser: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchMember', 'StytchB2BProvider'));\n const { member, isInitialized, fromCache } = useStytchMember<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchMember={member}\n stytchMemberIsInitialized={isInitialized}\n stytchMemberIsFromCache={fromCache}\n />\n );\n };\n WithStytchUser.displayName = `withStytchMember(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchUser;\n};\n\nexport const withStytchMemberSession = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & {\n stytchMemberSession: MemberSession | null;\n stytchMemberSessionIsInitialized: boolean;\n stytchMemberSessionIsFromCache: boolean;\n }\n >,\n): ComponentType<T> => {\n const WithStytchSession: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchMemberSession', 'StytchB2BProvider'));\n const { session, isInitialized, fromCache } = useStytchMemberSession<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchMemberSession={session}\n stytchMemberSessionIsInitialized={isInitialized}\n stytchMemberSessionIsFromCache={fromCache}\n />\n );\n };\n WithStytchSession.displayName = `withStytchMemberSession(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchSession;\n};\n\nexport const withStytchOrganization = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & {\n stytchOrganization: Organization | null;\n stytchOrganizationIsInitialized: boolean;\n stytchOrganizationIsFromCache: boolean;\n }\n >,\n): ComponentType<T> => {\n const WithStytchOrganization: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchOrganization', 'StytchB2BProvider'));\n const { organization, isInitialized, fromCache } = useStytchOrganization<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchOrganization={organization}\n stytchOrganizationIsInitialized={isInitialized}\n stytchOrganizationIsFromCache={fromCache}\n />\n );\n };\n WithStytchOrganization.displayName = `withStytchOrganization(${\n Component.displayName || Component.name || 'Component'\n })`;\n return WithStytchOrganization;\n};\n\ntype permissionsLoaded<Permissions extends Record<string, string>> =\n | {\n loaded: false;\n value: null;\n }\n | {\n loaded: true;\n value: PermissionsMap<Permissions>;\n };\n\n/**\n * Wrap your component with this HOC in order to receive the permissions for the logged-in member.\n * Evaluates all permissions granted to the logged-in member.\n * Returns a Record<RoleId, Record<Action, boolean>> response indicating the member's permissions.\n * Each boolean will be `true` if the member can perform the action, `false` otherwise.\n *\n * If the member is not logged in, all values will be false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * type Permissions = {\n * document: 'create' | 'read' | 'write\n * image: 'create' | 'read'\n * }\n *\n * const MyComponent = (props) => {\n * const canEditDocuments = props.stytchPermissions.document.edit;\n * const canReadImages = props.stytchPermissions.image.read;\n * }\n * return withStytchPermissions<Permissions>(MyComponent)\n */\nexport const withStytchPermissions = <Permissions extends Record<string, string>, T extends object>(\n Component: ComponentType<T & { stytchPermissions: PermissionsMap<Permissions> }>,\n): ComponentType<T> => {\n const WithStytchPermissions: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useRBACPermissions', 'StytchB2BProvider'));\n const client = useStytchB2BClient();\n const { session } = useStytchMemberSession();\n const [permissions, setPermissions] = useAsyncState<permissionsLoaded<Permissions>>({ loaded: false, value: null });\n useEffect(() => {\n client.rbac\n .allPermissions<Permissions>()\n .then((permissions) => setPermissions({ loaded: true, value: permissions }));\n }, [client, session?.roles, setPermissions]);\n\n if (!permissions.loaded) {\n return null;\n }\n return <Component {...props} stytchPermissions={permissions.value} />;\n };\n WithStytchPermissions.displayName = `withStytchPermissions(${\n Component.displayName || Component.name || 'Component'\n })`;\n return WithStytchPermissions;\n};\n\nexport interface StytchB2BProviderProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> {\n /**\n * A Stytch client instance, created using either {@link createStytchHeadlessClient} or {@link createStytchUIClient}\n */\n stytch: StytchB2BClient<TProjectConfiguration>;\n /**\n * When true, the provider will assume that the component will only be\n * rendered in a browser environment, either in a single-page application or\n * after completing hydration of a server-rendered application. This allows\n * cached values to be retrieved from the browser on the first render, meaning\n * that the `isInitialized` value returned from Stytch hooks will be `true`\n * starting from the first render.\n *\n * When `false`, the provider will defer initialization until after the first\n * render, and `isInitialized` will initially be `false`.\n *\n * This value defaults to `false` in `@stytch/nextjs`.\n */\n assumeHydrated?: boolean;\n children?: ReactNode;\n}\n\n/**\n * The Stytch Context Provider.\n * Wrap your application with this component in order to use Stytch everywhere in your app.\n * @example\n * const stytch = createStytchB2BHeadlessClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchB2BProvider stytch={stytch}>\n * <App />\n * </StytchB2BProvider>\n * )\n */\nexport const StytchB2BProvider = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n stytch,\n children,\n assumeHydrated = false,\n}: StytchB2BProviderProps<TProjectConfiguration>): JSX.Element => {\n invariant(!useIsMounted__INTERNAL(), 'You cannot render a <StytchB2BProvider> inside another <StytchB2BProvider>.');\n invariant(\n !assumeHydrated || typeof window !== 'undefined',\n 'The `assumeHydrated` prop must be set to `false` when using StytchB2BProvider in a server environment.',\n );\n\n const ctx = useMemo(() => ({ client: stytch, isMounted: true }), [stytch]);\n\n type ClientState<TAlwaysInitialized extends boolean> = {\n member: SWRMember<TAlwaysInitialized>;\n session: SWRMemberSession<TAlwaysInitialized>;\n organization: SWROrganization<TAlwaysInitialized>;\n };\n\n const getHydratedState = useCallback(() => {\n return {\n member: { ...stytch.self.getInfo(), isInitialized: true },\n session: { ...stytch.session.getInfo(), isInitialized: true },\n organization: { ...stytch.organization.getInfo(), isInitialized: true },\n } satisfies ClientState<true>;\n }, [stytch]);\n\n const getInitialState = () => {\n return {\n member: initialMember,\n session: initialMemberSession,\n organization: initialOrganization,\n } satisfies ClientState<false>;\n };\n\n const [{ member, session, organization }, setClientState] = useAsyncState<ClientState<boolean>>(() =>\n assumeHydrated ? getHydratedState() : (getInitialState() as ClientState<boolean>),\n );\n\n // Store the initial value of `assumeHydrated` in a ref, because it is\n // logically only relevant for the first render\n const assumeHydratedRef = useRef(assumeHydrated);\n useEffect(() => {\n if (isStytchSSRProxy(stytch)) {\n return;\n }\n\n const updateState = () => {\n setClientState((oldState) => mergeWithStableProps(oldState, getHydratedState()));\n };\n\n if (!assumeHydratedRef.current) {\n updateState();\n }\n\n return stytch.onStateChange(updateState);\n }, [getHydratedState, setClientState, stytch]);\n\n return (\n <StytchB2BContext.Provider value={ctx}>\n <StytchOrganizationContext.Provider value={organization}>\n <StytchMemberContext.Provider value={member}>\n <StytchMemberSessionContext.Provider value={session}>{children}</StytchMemberSessionContext.Provider>\n </StytchMemberContext.Provider>\n </StytchOrganizationContext.Provider>\n </StytchB2BContext.Provider>\n );\n};\n"],"names":[],"mappings":";;;;AAuEA,MAAM,aAAa,GAAc;AAC/B,IAAA,MAAM,EAAE,IAAI;AACZ,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,aAAa,EAAE,KAAK;CACrB,CAAC;AAoCF,MAAM,oBAAoB,GAAqB;AAC7C,IAAA,OAAO,EAAE,IAAI;AACb,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,aAAa,EAAE,KAAK;CACrB,CAAC;AAoCF,MAAM,mBAAmB,GAAoB;AAC3C,IAAA,YAAY,EAAE,IAAI;AAClB,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,aAAa,EAAE,KAAK;CACrB,CAAC;AAEF,MAAM,gBAAgB,GAAG,aAAa,CAAoD,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;AAChH,MAAM,mBAAmB,GAAG,aAAa,CAAY,aAAa,CAAC,CAAC;AACpE,MAAM,0BAA0B,GAAG,aAAa,CAAmB,oBAAoB,CAAC,CAAC;AACzF,MAAM,yBAAyB,GAAG,aAAa,CAAkB,mBAAmB,CAAC,CAAC;AAE/E,MAAM,sBAAsB,GAAG,MAAe,UAAU,CAAC,gBAAgB,CAAC,CAAC,UAAU;AAE/E,MAAA,UAAU,GAAG,CACxB,MAA8C,KACQ;AACtD,IAAA,OAAQ,MAA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AC;IACjD,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,gBAAgB,CAAC,MAAM,CAAC,EAAE;YAC5B,OAAO;SACR;QAED,MAAM,WAAW,GAAG,MAAK;AACvB,YAAA,cAAc,CAAC,CAAC,QAAQ,KAAK,oBAAoB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC;AACnF,SAAC,CAAC;AAEF,QAAA,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE;AAC9B,YAAA,WAAW,EAAE,CAAC;SACf;AAED,QAAA,OAAO,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;KAC1C,EAAE,CAAC,gBAAgB,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC;IAE/C,QACE,oBAAC,gBAAgB,CAAC,QAAQ,EAAC,EAAA,KAAK,EAAE,GAAG,EAAA;AACnC,QAAA,KAAA,CAAA,aAAA,CAAC,yBAAyB,CAAC,QAAQ,EAAC,EAAA,KAAK,EAAE,YAAY,EAAA;AACrD,YAAA,KAAA,CAAA,aAAA,CAAC,mBAAmB,CAAC,QAAQ,EAAC,EAAA,KAAK,EAAE,MAAM,EAAA;AACzC,gBAAA,KAAA,CAAA,aAAA,CAAC,0BAA0B,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,OAAO,EAAG,EAAA,QAAQ,CAAuC,CACxE,CACI,CACX,EAC5B;AACJ;;;;"}
@@ -46,3 +46,4 @@ const createProxy = (path) => {
46
46
  const createStytchSSRProxy = () => createProxy('stytch');
47
47
 
48
48
  export { noHeadlessClientError as a, createStytchSSRProxy as c, isStytchSSRProxy as i, noProviderError as n, providerMustBeUniqueError as p };
49
+ //# sourceMappingURL=StytchSSRProxy-34c789b5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StytchSSRProxy-34c789b5.js","sources":["../../../internal/react-shared/src/utils/errors.ts","../../../internal/react-shared/src/StytchSSRProxy.ts"],"sourcesContent":["export const noProviderError = (item: string, provider = 'StytchProvider'): string =>\n `${item} can only be used inside <${provider}>.`;\n\nexport const providerMustBeUniqueError = 'You cannot render a <StytchProvider> inside another <StytchProvider>.';\n\nexport const noHeadlessClientError = `Tried to create a Stytch Login UI element using the Stytch Headless SDK.\nYou must use the UI SDK to use UI elements.\nPlease make sure you are using a Stytch UI client, not a Stytch Headless client.`;\n\nexport const cannotInvokeMethodOnServerError = (path: string) =>\n `[Stytch] Invalid serverside function call to ${path}.\nThe Stytch Javascript SDK is intended to ony be used on the client side.\nMake sure to wrap your API calls in a hook to ensure they are executed on the client.\n\\`\\`\\`\nconst myComponent = () => {\n const stytch = useStytch();\n // This will error out on the server.\n stytch.magicLinks.authenticate(...);\n useEffect(() => {\n // This will work well\n stytch.magicLinks.authenticate(...);\n }, []);\n}\n\\`\\`\\`\n\nIf you want to make API calls from server environments, please use the Stytch Node Library\nhttps://www.npmjs.com/package/stytch.\n`;\n","import { cannotInvokeMethodOnServerError } from './utils/errors';\n\nconst SSRStubKey = Symbol('__stytch_SSRStubKey');\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isStytchSSRProxy = (proxy: any): boolean => {\n return !!proxy[SSRStubKey];\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst createProxy = (path: string): any => {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const noop = () => {};\n return new Proxy(noop, {\n get(target: unknown, p: string | symbol) {\n if ((p as symbol) === SSRStubKey) {\n return true;\n }\n return createProxy(path + '.' + String(p));\n },\n apply() {\n throw new Error(cannotInvokeMethodOnServerError(path));\n },\n });\n};\n\nexport const createStytchSSRProxy = () => createProxy('stytch');\n"],"names":[],"mappings":"AAAa,MAAA,eAAe,GAAG,CAAC,IAAY,EAAE,QAAQ,GAAG,gBAAgB,KACvE,CAAA,EAAG,IAAI,CAA6B,0BAAA,EAAA,QAAQ,KAAK;AAE5C,MAAM,yBAAyB,GAAG,wEAAwE;AAEpG,MAAA,qBAAqB,GAAG,CAAA;;kFAE6C;AAE3E,MAAM,+BAA+B,GAAG,CAAC,IAAY,KAC1D,CAAA,6CAAA,EAAgD,IAAI,CAAA;;;;;;;;;;;;;;;;;CAiBrD;;ACzBD,MAAM,UAAU,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAEjD;AACa,MAAA,gBAAgB,GAAG,CAAC,KAAU,KAAa;AACtD,IAAA,OAAO,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AAC7B,EAAE;AAEF;AACA,MAAM,WAAW,GAAG,CAAC,IAAY,KAAS;;AAExC,IAAA,MAAM,IAAI,GAAG,MAAK,GAAG,CAAC;AACtB,IAAA,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE;QACrB,GAAG,CAAC,MAAe,EAAE,CAAkB,EAAA;AACrC,YAAA,IAAK,CAAY,KAAK,UAAU,EAAE;AAChC,gBAAA,OAAO,IAAI,CAAC;aACb;YACD,OAAO,WAAW,CAAC,IAAI,GAAG,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;SAC5C;QACD,KAAK,GAAA;YACH,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,IAAI,CAAC,CAAC,CAAC;SACxD;AACF,KAAA,CAAC,CAAC;AACL,CAAC,CAAC;AAEW,MAAA,oBAAoB,GAAG,MAAM,WAAW,CAAC,QAAQ;;;;"}
@@ -52,3 +52,4 @@ exports.isStytchSSRProxy = isStytchSSRProxy;
52
52
  exports.noHeadlessClientError = noHeadlessClientError;
53
53
  exports.noProviderError = noProviderError;
54
54
  exports.providerMustBeUniqueError = providerMustBeUniqueError;
55
+ //# sourceMappingURL=StytchSSRProxy-86bc42b3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StytchSSRProxy-86bc42b3.js","sources":["../../../internal/react-shared/src/utils/errors.ts","../../../internal/react-shared/src/StytchSSRProxy.ts"],"sourcesContent":["export const noProviderError = (item: string, provider = 'StytchProvider'): string =>\n `${item} can only be used inside <${provider}>.`;\n\nexport const providerMustBeUniqueError = 'You cannot render a <StytchProvider> inside another <StytchProvider>.';\n\nexport const noHeadlessClientError = `Tried to create a Stytch Login UI element using the Stytch Headless SDK.\nYou must use the UI SDK to use UI elements.\nPlease make sure you are using a Stytch UI client, not a Stytch Headless client.`;\n\nexport const cannotInvokeMethodOnServerError = (path: string) =>\n `[Stytch] Invalid serverside function call to ${path}.\nThe Stytch Javascript SDK is intended to ony be used on the client side.\nMake sure to wrap your API calls in a hook to ensure they are executed on the client.\n\\`\\`\\`\nconst myComponent = () => {\n const stytch = useStytch();\n // This will error out on the server.\n stytch.magicLinks.authenticate(...);\n useEffect(() => {\n // This will work well\n stytch.magicLinks.authenticate(...);\n }, []);\n}\n\\`\\`\\`\n\nIf you want to make API calls from server environments, please use the Stytch Node Library\nhttps://www.npmjs.com/package/stytch.\n`;\n","import { cannotInvokeMethodOnServerError } from './utils/errors';\n\nconst SSRStubKey = Symbol('__stytch_SSRStubKey');\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isStytchSSRProxy = (proxy: any): boolean => {\n return !!proxy[SSRStubKey];\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst createProxy = (path: string): any => {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const noop = () => {};\n return new Proxy(noop, {\n get(target: unknown, p: string | symbol) {\n if ((p as symbol) === SSRStubKey) {\n return true;\n }\n return createProxy(path + '.' + String(p));\n },\n apply() {\n throw new Error(cannotInvokeMethodOnServerError(path));\n },\n });\n};\n\nexport const createStytchSSRProxy = () => createProxy('stytch');\n"],"names":[],"mappings":";;AAAa,MAAA,eAAe,GAAG,CAAC,IAAY,EAAE,QAAQ,GAAG,gBAAgB,KACvE,CAAA,EAAG,IAAI,CAA6B,0BAAA,EAAA,QAAQ,KAAK;AAE5C,MAAM,yBAAyB,GAAG,wEAAwE;AAEpG,MAAA,qBAAqB,GAAG,CAAA;;kFAE6C;AAE3E,MAAM,+BAA+B,GAAG,CAAC,IAAY,KAC1D,CAAA,6CAAA,EAAgD,IAAI,CAAA;;;;;;;;;;;;;;;;;CAiBrD;;ACzBD,MAAM,UAAU,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAEjD;AACa,MAAA,gBAAgB,GAAG,CAAC,KAAU,KAAa;AACtD,IAAA,OAAO,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AAC7B,EAAE;AAEF;AACA,MAAM,WAAW,GAAG,CAAC,IAAY,KAAS;;AAExC,IAAA,MAAM,IAAI,GAAG,MAAK,GAAG,CAAC;AACtB,IAAA,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE;QACrB,GAAG,CAAC,MAAe,EAAE,CAAkB,EAAA;AACrC,YAAA,IAAK,CAAY,KAAK,UAAU,EAAE;AAChC,gBAAA,OAAO,IAAI,CAAC;aACb;YACD,OAAO,WAAW,CAAC,IAAI,GAAG,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;SAC5C;QACD,KAAK,GAAA;YACH,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,IAAI,CAAC,CAAC,CAAC;SACxD;AACF,KAAA,CAAC,CAAC;AACL,CAAC,CAAC;AAEW,MAAA,oBAAoB,GAAG,MAAM,WAAW,CAAC,QAAQ;;;;;;;;"}
@@ -54,3 +54,4 @@ const AdminPortalMemberManagement = makeAdminPortalComponent(mountAdminPortalMem
54
54
  const AdminPortalSCIM = makeAdminPortalComponent(mountAdminPortalSCIM, 'AdminPortalSCIM');
55
55
 
56
56
  export { AdminPortalMemberManagement, AdminPortalOrgSettings, AdminPortalSCIM, AdminPortalSSO };
57
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../../../../internal/react-shared/src/adminPortal/makeAdminPortalComponent.tsx","../../../../internal/react-shared/src/adminPortal/AdminPortalSSO.tsx","../../../../internal/react-shared/src/adminPortal/AdminPortalOrgSettings.tsx","../../../../internal/react-shared/src/adminPortal/AdminPortalMemberManagement.tsx","../../../../internal/react-shared/src/adminPortal/AdminPortalSCIM.tsx"],"sourcesContent":["import type { AdminPortalStyleConfig } from '@stytch/vanilla-js/b2b/adminPortal';\nimport type { StytchB2BHeadlessClient, StytchProjectConfigurationInput } from '@stytch/vanilla-js/b2b/headless';\nimport React, { useRef } from 'react';\nimport { PartialDeep } from 'type-fest';\nimport { useIsMounted__INTERNAL, useStytchB2BClient } from '../b2b/StytchB2BContext';\nimport { noProviderError } from '../utils/errors';\nimport { invariant } from '../utils/invariant';\nimport useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect';\n\nexport interface AdminPortalComponentProps<TProjectConfiguration extends StytchProjectConfigurationInput> {\n /**\n * The Stytch B2B client to use.\n */\n client: StytchB2BHeadlessClient<TProjectConfiguration>;\n /**\n * An HTML element or query selector string for the element that should contain the UI.\n * @example '#container'\n */\n element: string | HTMLElement;\n /**\n * An {@link AdminPortalStyleConfig} object containing custom styling info.\n */\n styles?: PartialDeep<AdminPortalStyleConfig>;\n}\n\ninterface InjectedOptions<TProjectConfiguration extends StytchProjectConfigurationInput> {\n client: StytchB2BHeadlessClient<TProjectConfiguration>;\n element: HTMLElement;\n}\n\nexport type ExcludeInjectedOptions<T> = Omit<T, keyof InjectedOptions<StytchProjectConfigurationInput>>;\n\nexport const makeAdminPortalComponent = <TProps extends AdminPortalComponentProps<StytchProjectConfigurationInput>>(\n mountFn: <TProjectConfiguration extends StytchProjectConfigurationInput>(\n props: ExcludeInjectedOptions<TProps> & InjectedOptions<TProjectConfiguration>,\n ) => void,\n componentName: string,\n) => {\n const Component = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n >(\n props: ExcludeInjectedOptions<TProps>,\n ): JSX.Element => {\n invariant(useIsMounted__INTERNAL(), noProviderError(`<${componentName} />`, 'StytchB2BProvider'));\n const stytchClient = useStytchB2BClient<TProjectConfiguration>();\n const containerEl = useRef<HTMLDivElement>(null);\n\n useIsomorphicLayoutEffect(() => {\n if (!containerEl.current) {\n return;\n }\n\n mountFn<TProjectConfiguration>({ ...props, client: stytchClient, element: containerEl.current });\n }, [stytchClient, props]);\n\n return <div ref={containerEl} />;\n };\n\n return Component;\n};\n","import { AdminPortalSSOMountOptions, mountAdminPortalSSO } from '@stytch/vanilla-js/b2b/adminPortal';\nimport { ExcludeInjectedOptions, makeAdminPortalComponent } from './makeAdminPortalComponent';\nimport type { StytchProjectConfigurationInput } from '@stytch/vanilla-js';\n\nexport type AdminPortalSSOProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> = ExcludeInjectedOptions<AdminPortalSSOMountOptions<TProjectConfiguration>>;\n\n/**\n * The Admin Portal SSO UI component.\n * This component must be rendered within a {@link StytchB2BProvider}.\n *\n * See the {@link https://stytch.com/docs/b2b/sdks/javascript-sdk online reference}\n */\nexport const AdminPortalSSO = makeAdminPortalComponent<AdminPortalSSOMountOptions<StytchProjectConfigurationInput>>(\n mountAdminPortalSSO,\n 'AdminPortalSSO',\n);\n","import { AdminPortalOrgSettingsMountOptions, mountAdminPortalOrgSettings } from '@stytch/vanilla-js/b2b/adminPortal';\nimport { ExcludeInjectedOptions, makeAdminPortalComponent } from './makeAdminPortalComponent';\nimport type { StytchProjectConfigurationInput } from '@stytch/vanilla-js';\n\nexport type AdminPortalOrgSettingsProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> = ExcludeInjectedOptions<AdminPortalOrgSettingsMountOptions<TProjectConfiguration>>;\n\n/**\n * The Admin Portal Organization Settings UI component.\n * This component must be rendered within a {@link StytchB2BProvider}.\n *\n * See the {@link https://stytch.com/docs/b2b/sdks/javascript-sdk online reference}\n */\nexport const AdminPortalOrgSettings = makeAdminPortalComponent<\n AdminPortalOrgSettingsMountOptions<StytchProjectConfigurationInput>\n>(mountAdminPortalOrgSettings, 'AdminPortalOrgSettings');\n","import {\n AdminPortalMemberManagementMountOptions,\n mountAdminPortalMemberManagement,\n} from '@stytch/vanilla-js/b2b/adminPortal';\nimport { ExcludeInjectedOptions, makeAdminPortalComponent } from './makeAdminPortalComponent';\nimport type { StytchProjectConfigurationInput } from '@stytch/vanilla-js';\n\nexport type AdminPortalMemberManagementProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> = ExcludeInjectedOptions<AdminPortalMemberManagementMountOptions<TProjectConfiguration>>;\n\n/**\n * The Admin Portal member management UI component.\n * This component must be rendered within a {@link StytchB2BProvider}.\n *\n * See the {@link https://stytch.com/docs/b2b/sdks/javascript-sdk online reference}\n */\nexport const AdminPortalMemberManagement = makeAdminPortalComponent<\n AdminPortalMemberManagementMountOptions<StytchProjectConfigurationInput>\n>(mountAdminPortalMemberManagement, 'AdminPortalMemberManagement');\n","import { AdminPortalSCIMMountOptions, mountAdminPortalSCIM } from '@stytch/vanilla-js/b2b/adminPortal';\nimport { ExcludeInjectedOptions, makeAdminPortalComponent } from './makeAdminPortalComponent';\nimport type { StytchProjectConfigurationInput } from '@stytch/vanilla-js';\n\nexport type AdminPortalSCIMProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> = ExcludeInjectedOptions<AdminPortalSCIMMountOptions<TProjectConfiguration>>;\n\n/**\n * The Admin Portal SCIM UI component.\n * This component must be rendered within a {@link StytchB2BProvider}.\n *\n * See the {@link https://stytch.com/docs/b2b/sdks/javascript-sdk online reference}\n */\nexport const AdminPortalSCIM = makeAdminPortalComponent<AdminPortalSCIMMountOptions<StytchProjectConfigurationInput>>(\n mountAdminPortalSCIM,\n 'AdminPortalSCIM',\n);\n"],"names":[],"mappings":";;;;;;;AAgCO,MAAM,wBAAwB,GAAG,CACtC,OAES,EACT,aAAqB,KACnB;AACF,IAAA,MAAM,SAAS,GAAG,CAGhB,KAAqC,KACtB;AACf,QAAA,SAAS,CAAC,sBAAsB,EAAE,EAAE,eAAe,CAAC,CAAI,CAAA,EAAA,aAAa,CAAK,GAAA,CAAA,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAClG,QAAA,MAAM,YAAY,GAAG,kBAAkB,EAAyB,CAAC;AACjE,QAAA,MAAM,WAAW,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;QAEjD,yBAAyB,CAAC,MAAK;AAC7B,YAAA,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;gBACxB,OAAO;aACR;AAED,YAAA,OAAO,CAA6B,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,KAAK,CAAE,EAAA,EAAA,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,IAAG,CAAC;AACnG,SAAC,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC;AAE1B,QAAA,OAAO,KAAK,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,GAAG,EAAE,WAAW,GAAI,CAAC;AACnC,KAAC,CAAC;AAEF,IAAA,OAAO,SAAS,CAAC;AACnB,CAAC;;ACnDD;;;;;AAKG;AACU,MAAA,cAAc,GAAG,wBAAwB,CACpD,mBAAmB,EACnB,gBAAgB;;ACRlB;;;;;AAKG;AACU,MAAA,sBAAsB,GAAG,wBAAwB,CAE5D,2BAA2B,EAAE,wBAAwB;;ACLvD;;;;;AAKG;AACU,MAAA,2BAA2B,GAAG,wBAAwB,CAEjE,gCAAgC,EAAE,6BAA6B;;ACXjE;;;;;AAKG;AACU,MAAA,eAAe,GAAG,wBAAwB,CACrD,oBAAoB,EACpB,iBAAiB;;;;"}
@@ -68,3 +68,4 @@ exports.AdminPortalMemberManagement = AdminPortalMemberManagement;
68
68
  exports.AdminPortalOrgSettings = AdminPortalOrgSettings;
69
69
  exports.AdminPortalSCIM = AdminPortalSCIM;
70
70
  exports.AdminPortalSSO = AdminPortalSSO;
71
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../internal/react-shared/src/adminPortal/makeAdminPortalComponent.tsx","../../../../internal/react-shared/src/adminPortal/AdminPortalSSO.tsx","../../../../internal/react-shared/src/adminPortal/AdminPortalOrgSettings.tsx","../../../../internal/react-shared/src/adminPortal/AdminPortalMemberManagement.tsx","../../../../internal/react-shared/src/adminPortal/AdminPortalSCIM.tsx"],"sourcesContent":["import type { AdminPortalStyleConfig } from '@stytch/vanilla-js/b2b/adminPortal';\nimport type { StytchB2BHeadlessClient, StytchProjectConfigurationInput } from '@stytch/vanilla-js/b2b/headless';\nimport React, { useRef } from 'react';\nimport { PartialDeep } from 'type-fest';\nimport { useIsMounted__INTERNAL, useStytchB2BClient } from '../b2b/StytchB2BContext';\nimport { noProviderError } from '../utils/errors';\nimport { invariant } from '../utils/invariant';\nimport useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect';\n\nexport interface AdminPortalComponentProps<TProjectConfiguration extends StytchProjectConfigurationInput> {\n /**\n * The Stytch B2B client to use.\n */\n client: StytchB2BHeadlessClient<TProjectConfiguration>;\n /**\n * An HTML element or query selector string for the element that should contain the UI.\n * @example '#container'\n */\n element: string | HTMLElement;\n /**\n * An {@link AdminPortalStyleConfig} object containing custom styling info.\n */\n styles?: PartialDeep<AdminPortalStyleConfig>;\n}\n\ninterface InjectedOptions<TProjectConfiguration extends StytchProjectConfigurationInput> {\n client: StytchB2BHeadlessClient<TProjectConfiguration>;\n element: HTMLElement;\n}\n\nexport type ExcludeInjectedOptions<T> = Omit<T, keyof InjectedOptions<StytchProjectConfigurationInput>>;\n\nexport const makeAdminPortalComponent = <TProps extends AdminPortalComponentProps<StytchProjectConfigurationInput>>(\n mountFn: <TProjectConfiguration extends StytchProjectConfigurationInput>(\n props: ExcludeInjectedOptions<TProps> & InjectedOptions<TProjectConfiguration>,\n ) => void,\n componentName: string,\n) => {\n const Component = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n >(\n props: ExcludeInjectedOptions<TProps>,\n ): JSX.Element => {\n invariant(useIsMounted__INTERNAL(), noProviderError(`<${componentName} />`, 'StytchB2BProvider'));\n const stytchClient = useStytchB2BClient<TProjectConfiguration>();\n const containerEl = useRef<HTMLDivElement>(null);\n\n useIsomorphicLayoutEffect(() => {\n if (!containerEl.current) {\n return;\n }\n\n mountFn<TProjectConfiguration>({ ...props, client: stytchClient, element: containerEl.current });\n }, [stytchClient, props]);\n\n return <div ref={containerEl} />;\n };\n\n return Component;\n};\n","import { AdminPortalSSOMountOptions, mountAdminPortalSSO } from '@stytch/vanilla-js/b2b/adminPortal';\nimport { ExcludeInjectedOptions, makeAdminPortalComponent } from './makeAdminPortalComponent';\nimport type { StytchProjectConfigurationInput } from '@stytch/vanilla-js';\n\nexport type AdminPortalSSOProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> = ExcludeInjectedOptions<AdminPortalSSOMountOptions<TProjectConfiguration>>;\n\n/**\n * The Admin Portal SSO UI component.\n * This component must be rendered within a {@link StytchB2BProvider}.\n *\n * See the {@link https://stytch.com/docs/b2b/sdks/javascript-sdk online reference}\n */\nexport const AdminPortalSSO = makeAdminPortalComponent<AdminPortalSSOMountOptions<StytchProjectConfigurationInput>>(\n mountAdminPortalSSO,\n 'AdminPortalSSO',\n);\n","import { AdminPortalOrgSettingsMountOptions, mountAdminPortalOrgSettings } from '@stytch/vanilla-js/b2b/adminPortal';\nimport { ExcludeInjectedOptions, makeAdminPortalComponent } from './makeAdminPortalComponent';\nimport type { StytchProjectConfigurationInput } from '@stytch/vanilla-js';\n\nexport type AdminPortalOrgSettingsProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> = ExcludeInjectedOptions<AdminPortalOrgSettingsMountOptions<TProjectConfiguration>>;\n\n/**\n * The Admin Portal Organization Settings UI component.\n * This component must be rendered within a {@link StytchB2BProvider}.\n *\n * See the {@link https://stytch.com/docs/b2b/sdks/javascript-sdk online reference}\n */\nexport const AdminPortalOrgSettings = makeAdminPortalComponent<\n AdminPortalOrgSettingsMountOptions<StytchProjectConfigurationInput>\n>(mountAdminPortalOrgSettings, 'AdminPortalOrgSettings');\n","import {\n AdminPortalMemberManagementMountOptions,\n mountAdminPortalMemberManagement,\n} from '@stytch/vanilla-js/b2b/adminPortal';\nimport { ExcludeInjectedOptions, makeAdminPortalComponent } from './makeAdminPortalComponent';\nimport type { StytchProjectConfigurationInput } from '@stytch/vanilla-js';\n\nexport type AdminPortalMemberManagementProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> = ExcludeInjectedOptions<AdminPortalMemberManagementMountOptions<TProjectConfiguration>>;\n\n/**\n * The Admin Portal member management UI component.\n * This component must be rendered within a {@link StytchB2BProvider}.\n *\n * See the {@link https://stytch.com/docs/b2b/sdks/javascript-sdk online reference}\n */\nexport const AdminPortalMemberManagement = makeAdminPortalComponent<\n AdminPortalMemberManagementMountOptions<StytchProjectConfigurationInput>\n>(mountAdminPortalMemberManagement, 'AdminPortalMemberManagement');\n","import { AdminPortalSCIMMountOptions, mountAdminPortalSCIM } from '@stytch/vanilla-js/b2b/adminPortal';\nimport { ExcludeInjectedOptions, makeAdminPortalComponent } from './makeAdminPortalComponent';\nimport type { StytchProjectConfigurationInput } from '@stytch/vanilla-js';\n\nexport type AdminPortalSCIMProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> = ExcludeInjectedOptions<AdminPortalSCIMMountOptions<TProjectConfiguration>>;\n\n/**\n * The Admin Portal SCIM UI component.\n * This component must be rendered within a {@link StytchB2BProvider}.\n *\n * See the {@link https://stytch.com/docs/b2b/sdks/javascript-sdk online reference}\n */\nexport const AdminPortalSCIM = makeAdminPortalComponent<AdminPortalSCIMMountOptions<StytchProjectConfigurationInput>>(\n mountAdminPortalSCIM,\n 'AdminPortalSCIM',\n);\n"],"names":["invariant","useIsMounted__INTERNAL","noProviderError","useStytchB2BClient","useRef","useIsomorphicLayoutE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AwB,CACrDC,gCAAoB,EACpB,iBAAiB;;;;;;;;;;;"}
@@ -194,3 +194,4 @@ const StytchB2BProvider = ({ stytch, children, assumeHydrated = true, }) => {
194
194
  };
195
195
 
196
196
  export { B2BIdentityProvider, StytchB2B, StytchB2BProvider, useStytchIsAuthorized, useStytchMember, useStytchMemberSession, useStytchOrganization, withStytchMember, withStytchMemberSession, withStytchOrganization };
197
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../../../../internal/react-shared/src/b2b/Stytch.tsx","../../src/b2b/StytchB2BContext.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport type {\n Callbacks,\n StringsOptions,\n StyleConfig,\n StytchB2BUIConfig,\n StytchProjectConfigurationInput,\n} from '@stytch/vanilla-js';\n\nimport type { IDPConsentScreenManifest } from '@stytch/vanilla-js/b2b';\n\nimport { useStytchB2BClient, isUIClient, useIsMounted__INTERNAL, useStytchMember } from './StytchB2BContext';\nimport { invariant } from '../utils/invariant';\nimport { noHeadlessClientError, noProviderError } from '../utils/errors';\nimport useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect';\n\nexport interface StytchB2BProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> extends StringsOptions {\n /**\n * An optional {@link StyleConfig} to customize the look and feel of the screen.\n *\n * @example\n * {\n * fontFamily: 'Arial, Helvetica, sans-serif',\n * width: '360px',\n * primaryColor: '#19303D',\n * }\n */\n styles?: StyleConfig;\n /**\n * An optional {@link Callbacks} object.\n *\n * @example\n * {\n * onError: ({message}) => {\n * console.error('Stytch error', message)\n * }\n * }\n *\n * @example\n * {\n * onEvent: ({type, data}) => {\n * if(type === StytchEventType.B2BMagicLinkAuthenticate) {\n * console.log('Logged in with', data);\n * }\n * }\n * }\n */\n callbacks?: Callbacks<TProjectConfiguration>;\n /**\n * A {@link StytchB2BUIConfig} object. Add products and product-specific config to this object to change the login methods shown.\n *\n *\n * @example\n * {\n * products: ['emailMagicLinks'],\n * authFlowType: \"Discovery\",\n * emailMagicLinksOptions: {\n * discoveryRedirectURL: 'https://example.com/authenticate',\n * },\n * sessionOptions: {\n * sessionDurationMinutes: 60,\n * },\n * }\n *\n * @example\n * {\n * products: ['emailMagicLinks', 'sso'],\n * authFlowType: \"Organization\",\n * emailMagicLinksOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * },\n * ssoOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * },\n * sessionOptions: {\n * sessionDurationMinutes: 60,\n * },\n * }\n */\n config: StytchB2BUIConfig;\n}\n\nexport type B2BIDPConsentManifestGenerator = (input: {\n scopes: string[];\n clientName: string;\n}) => IDPConsentScreenManifest;\n\ntype B2BAuthTokenParams = { trustedAuthToken: string; tokenProfileID: string };\n\nexport type B2BIdentityProviderProps = Omit<StytchB2BProps, 'config'> & {\n /**\n * Optional {@link B2BIDPConsentManifestGenerator} to customize the consent screen.\n */\n getIDPConsentManifest?: B2BIDPConsentManifestGenerator;\n /**\n * Optional trusted auth token parameters to attest before the OAuth flow.\n */\n trustedAuthTokenParams?: B2BAuthTokenParams;\n};\n\n/**\n * The Stytch B2B UI component.\n * This component can only be used with a Stytch B2B UI Client\n * passed into the StytchB2BProvider.\n *\n * See the {@link https://stytch.com/docs/b2b/sdks online reference}\n *\n * @example\n * <StytchB2B\n * config={{\n * authFlowType: \"Organization\",\n * emailMagicLinksOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * },\n * ssoOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * },\n * sessionOptions: {\n * sessionDurationMinutes: 60,\n * }\n * }}\n * styles={{\n * fontFamily: '\"Helvetica New\", Helvetica, sans-serif',\n * primaryColor: '#0577CA',\n * width: '321px',\n * }}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const StytchB2B = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n styles,\n callbacks,\n config,\n strings,\n}: StytchB2BProps<TProjectConfiguration>) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('<StytchB2B />', 'StytchB2BProvider'));\n const stytchClient = useStytchB2BClient<TProjectConfiguration>();\n const containerEl = useRef<HTMLDivElement>(null);\n\n useIsomorphicLayoutEffect(() => {\n if (!isUIClient(stytchClient)) {\n throw Error(noHeadlessClientError);\n }\n\n if (!containerEl.current) {\n return;\n }\n\n if (!containerEl.current.id) {\n const randId = Math.floor(Math.random() * 1e6);\n containerEl.current.id = `stytch-b2b-ui-${randId}`;\n }\n\n stytchClient.mount({\n callbacks,\n config,\n elementId: `#${containerEl.current.id}`,\n styles,\n strings,\n });\n }, [stytchClient, styles, callbacks, strings]);\n\n return <div ref={containerEl} />;\n};\n\n/**\n * The Stytch B2B IDP component.\n * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.\n * Requires the user to be logged in.\n * This component can only be used with a Stytch B2B UI Client\n * passed into the StytchB2BProvider.\n *\n * See the {@link https://stytch.com/docs/b2b/sdks online reference}\n *\n * @example\n * const styles = {\n * container: {\n * backgroundColor: '#e11e1e',\n * },\n * colors: {\n * primary: '#ff00f7',\n * secondary: '#5C727D',\n * },\n * }\n *\n * <B2BIdentityProvider\n * styles={styles}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const B2BIdentityProvider = ({\n styles,\n callbacks,\n getIDPConsentManifest,\n trustedAuthTokenParams,\n}: B2BIdentityProviderProps) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('<IdentityProvider />'));\n const stytchClient = useStytchB2BClient();\n const { member } = useStytchMember();\n const containerEl = useRef<HTMLDivElement>(null);\n\n useIsomorphicLayoutEffect(() => {\n if (!isUIClient(stytchClient)) {\n throw Error(noHeadlessClientError);\n }\n\n if (!containerEl.current) {\n return;\n }\n\n if (!containerEl.current.id) {\n const randId = Math.floor(Math.random() * 1e6);\n containerEl.current.id = `stytch-b2b-idp-${randId}`;\n }\n\n stytchClient.mountIdentityProvider({\n callbacks,\n elementId: `#${containerEl.current.id}`,\n styles,\n getIDPConsentManifest,\n trustedAuthTokenParams,\n });\n }, [stytchClient, styles, callbacks, member, getIDPConsentManifest, trustedAuthTokenParams]);\n\n return <div ref={containerEl} />;\n};\n","import React, { ComponentType, ReactNode } from 'react';\n\nimport type { Member, MemberSession, Organization, StytchB2BUIClient } from '@stytch/vanilla-js/b2b';\nimport type { StytchB2BHeadlessClient, StytchProjectConfigurationInput } from '@stytch/vanilla-js/b2b/headless';\n\n// We need a direct import to the original source file here (StytchB2BContext,\n// not just a barrel file) or the built type declarations will re-export these\n// values without ever importing them. This is evidently a bug that will\n// hopefully be resolved when we upgrade our build tooling.\n// eslint-disable-next-line @typescript-eslint/no-restricted-imports\nexport {\n useStytchB2BClient,\n withStytchB2BClient,\n withStytchPermissions,\n} from '@stytch/internal-react-shared/src/b2b/StytchB2BContext';\n// eslint-disable-next-line @typescript-eslint/no-restricted-imports\nimport {\n StytchB2BProvider as StytchB2BProviderShared,\n useStytchIsAuthorized as useStytchIsAuthorizedShared,\n useStytchMemberSession as useStytchMemberSessionShared,\n useStytchMember as useStytchMemberShared,\n useStytchOrganization as useStytchOrganizationShared,\n withStytchMemberSession as withStytchMemberSessionShared,\n withStytchMember as withStytchMemberShared,\n withStytchOrganization as withStytchOrganizationShared,\n} from '@stytch/internal-react-shared/src/b2b';\n\n/**\n * The Stytch Client object passed in to <StytchB2BProvider /> in your application root.\n * Either a StytchB2BUIClient or StytchB2BHeadlessClient.\n */\ntype StytchB2BClient<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | StytchB2BHeadlessClient<TProjectConfiguration>\n | StytchB2BUIClient<TProjectConfiguration>;\n\n/**\n * Returns the active Member.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the member data is from persistent storage.\n * @example\n * const {member, isInitialized, fromCache} = useStytchMember();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<h1>Welcome, {member.name}</h1>);\n */\nexport const useStytchMember = useStytchMemberShared as <TAssumeHydrated extends boolean = true>() => ReturnType<\n typeof useStytchMemberShared<TAssumeHydrated>\n>;\n\n/**\n * Returns the active member's Stytch member session.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the session data is from persistent storage.\n * @example\n * const {session, isInitialized, fromCache} = useStytchMemberSession();\n * useEffect(() => {\n * if (!isInitialized) {\n * return;\n * }\n * if (!session) {\n * router.replace('/login')\n * }\n * }, [session, isInitialized]);\n */\nexport const useStytchMemberSession = useStytchMemberSessionShared as <\n TAssumeHydrated extends boolean = true,\n>() => ReturnType<typeof useStytchMemberSessionShared<TAssumeHydrated>>;\n\n/**\n * Returns the active Stytch organization.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the organization data is from persistent storage.\n * @example\n * const {organization, isInitialized, fromCache} = useStytchOrganization();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<p>Welcome to {organization.organization_name}</p>);\n */\nexport const useStytchOrganization = useStytchOrganizationShared as <\n TAssumeHydrated extends boolean = true,\n>() => ReturnType<typeof useStytchOrganizationShared<TAssumeHydrated>>;\n\n/**\n * Determines whether the logged-in member is allowed to perform the specified action on the specified resource.\n * Returns `true` if the member can perform the action, `false` otherwise.\n *\n * If the member is not logged in, this method will always return false.\n * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * const { isAuthorized } = useStytchIsAuthorized<Permissions>('documents', 'edit');\n * return <button disabled={!isAuthorized}>Edit</button>\n */\nexport const useStytchIsAuthorized = useStytchIsAuthorizedShared as <TAssumeHydrated extends boolean = false>(\n resourceId: string,\n action: string,\n) => ReturnType<typeof useStytchIsAuthorizedShared<TAssumeHydrated>>;\n\nexport const withStytchMember = withStytchMemberShared as <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & { stytchMember: Member | null; stytchMemberIsInitialized: boolean; stytchMemberIsFromCache: boolean }\n >,\n) => ReturnType<typeof withStytchMemberShared<T, TAssumeHydrated>>;\n\nexport const withStytchMemberSession = withStytchMemberSessionShared as <\n T extends object,\n TAssumeHydrated extends boolean = false,\n>(\n Component: ComponentType<\n T & {\n stytchMemberSession: MemberSession | null;\n stytchMemberSessionIsInitialized: boolean;\n stytchMemberSessionIsFromCache: boolean;\n }\n >,\n) => ReturnType<typeof withStytchMemberSessionShared<T, TAssumeHydrated>>;\n\nexport const withStytchOrganization = withStytchOrganizationShared as <\n T extends object,\n TAssumeHydrated extends boolean = false,\n>(\n Component: ComponentType<\n T & {\n stytchOrganization: Organization | null;\n stytchOrganizationIsInitialized: boolean;\n stytchOrganizationIsFromCache: boolean;\n }\n >,\n) => ReturnType<typeof withStytchOrganizationShared<T, TAssumeHydrated>>;\n\nexport interface StytchB2BProviderProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> {\n /**\n * A Stytch client instance, either a {@link StytchB2BUIClient} or {@link StytchB2BHeadlessClient}\n */\n stytch: StytchB2BClient<TProjectConfiguration>;\n /**\n * When true, the provider will assume that the component will only be\n * rendered in a browser environment, either in a single-page application or\n * after completing hydration of a server-rendered application. This allows\n * cached values to be retrieved from the browser on the first render, meaning\n * that the `isInitialized` value returned from Stytch hooks will be `true`\n * starting from the first render.\n *\n * When `false`, the provider will defer initialization until after the first\n * render, and `isInitialized` will initially be `false`.\n *\n * If you encounter hydration errors relating to the use of this component,\n * set this to `false`.\n *\n * This value defaults to `true` in `@stytch/react`.\n */\n assumeHydrated?: boolean;\n children?: ReactNode;\n}\n\n/**\n * The Stytch Context Provider.\n * Wrap your application with this component in order to use Stytch everywhere in your app.\n * @example\n * const stytch = createStytchB2BHeadlessClient('public-token-<find yours in the stytch dashboard>')\n *\n * ReactDOM.render(\n * <StytchB2BProvider stytch={stytch}>\n * <App />\n * </StytchProvider>,\n * document.getElementById('root'),\n * )\n */\nexport const StytchB2BProvider = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n stytch,\n children,\n assumeHydrated = true,\n}: StytchB2BProviderProps<TProjectConfiguration>): JSX.Element => {\n return (\n <StytchB2BProviderShared stytch={stytch} assumeHydrated={assumeHydrated}>\n {children}\n </StytchB2BProviderShared>\n );\n};\n"],"names":["useStytchMember","useStytchMemberShared","useStytchMemberSessionShared","useStytchOrganizationShared","useStytchIsAuthorizedShared","withStytchMemberShared","withStytchMemberSessionShared","withStytchOrganizationShared","StytchB2BProviderShared"],"mappings":";;;;;;;AAwGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCG;AACI,MAAM,SAAS,GAAG,CAEvB,EACA,MAAM,EACN,SAAS,EACT,MAAM,EACN,OAAO,GAC+B,KAAI;IAC1C,SAAS,CAAC,sBAAsB,EAAE,EAAE,eAAe,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAC3F,IAAA,MAAM,YAAY,GAAG,kBAAkB,EAAyB,CAAC;AACjE,IAAA,MAAM,WAAW,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAEjD,yBAAyB,CAAC,MAAK;AAC7B,QAAA,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;AAC7B,YAAA,MAAM,KAAK,CAAC,qBAAqB,CAAC,CAAC;SACpC;AAED,QAAA,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;YACxB,OAAO;SACR;AAED,QAAA,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,EAAE;AAC3B,YAAA,MAAM,MAAM,G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ytchB2BHeadlessClient };
25
+ //# sourceMappingURL=index.headless.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.headless.esm.js","sources":["../../../../internal/react-shared/src/b2b/createStytchB2BHeadlessClient.ts"],"sourcesContent":["import { StytchB2BHeadlessClient, StytchProjectConfigurationInput } from '@stytch/vanilla-js/b2b/headless';\nimport { createStytchSSRProxy } from '../StytchSSRProxy';\n\n/**\n * Creates a Headless Stytch client object to call the stytch B2B APIs.\n * The Stytch client is not available serverside.\n * @example\n * const stytch = createStytchB2BHeadlessClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchB2BProvider stytch={stytch}>\n * <App />\n * </StytchB2BProvider>\n * )\n * @returns A {@link StytchB2BHeadlessClient}\n */\nexport const createStytchB2BHeadlessClient = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(\n ...args: ConstructorParameters<typeof StytchB2BHeadlessClient<TProjectConfiguration>>\n): StytchB2BHeadlessClient<TProjectConfiguration> => {\n if (typeof window === 'undefined') {\n return createStytchSSRProxy();\n }\n return new StytchB2BHeadlessClient<TProjectConfiguration>(...args);\n};\n"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;AAYG;MACU,6BAA6B,GAAG,CAG3C,GAAG,IAAkF,KACnC;AAClD,IAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,oBAAoB,EAAE,CAAC;KAC/B;AACD,IAAA,OAAO,IAAI,uBAAuB,CAAwB,GAAG,IAAI,CAAC,CAAC;AACrE;;;;"}
@@ -26,3 +26,4 @@ const createStytchB2BHeadlessClient = (...args) => {
26
26
  };
27
27
 
28
28
  exports.createStytchB2BHeadlessClient = createStytchB2BHeadlessClient;
29
+ //# sourceMappingURL=index.headless.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.headless.js","sources":["../../../../internal/react-shared/src/b2b/createStytchB2BHeadlessClient.ts"],"sourcesContent":["import { StytchB2BHeadlessClient, StytchProjectConfigurationInput } from '@stytch/vanilla-js/b2b/headless';\nimport { createStytchSSRProxy } from '../StytchSSRProxy';\n\n/**\n * Creates a Headless Stytch client object to call the stytch B2B APIs.\n * The Stytch client is not available serverside.\n * @example\n * const stytch = createStytchB2BHeadlessClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchB2BProvider stytch={stytch}>\n * <App />\n * </StytchB2BProvider>\n * )\n * @returns A {@link StytchB2BHeadlessClient}\n */\nexport const createStytchB2BHeadlessClient = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(\n ...args: ConstructorParameters<typeof StytchB2BHeadlessClient<TProjectConfiguration>>\n): StytchB2BHeadlessClient<TProjectConfiguration> => {\n if (typeof window === 'undefined') {\n return createStytchSSRProxy();\n }\n return new StytchB2BHeadlessClient<TProjectConfiguration>(...args);\n};\n"],"names":["createStytchSSRProxy","StytchB2BHeadlessClient"],"mappings":";;;;;;;AAGA;;;;;;;;;;;;AAYG;MACU,6BAA6B,GAAG,CAG3C,GAAG,IAAkF,KACnC;AAClD,IAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAOA,mCAAoB,EAAE,CAAC;KAC/B;AACD,IAAA,OAAO,IAAIC,gCAAuB,CAAwB,GAAG,IAAI,CAAC,CAAC;AACrE;;;;"}
package/dist/b2b/index.js CHANGED
@@ -221,3 +221,4 @@ exports.useStytchOrganization = useStytchOrganization;
221
221
  exports.withStytchMember = withStytchMember;
222
222
  exports.withStytchMemberSession = withStytchMemberSession;
223
223
  exports.withStytchOrganization = withStytchOrganization;
224
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../internal/react-shared/src/b2b/Stytch.tsx","../../src/b2b/StytchB2BContext.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport type {\n Callbacks,\n StringsOptions,\n StyleConfig,\n StytchB2BUIConfig,\n StytchProjectConfigurationInput,\n} from '@stytch/vanilla-js';\n\nimport type { IDPConsentScreenManifest } from '@stytch/vanilla-js/b2b';\n\nimport { useStytchB2BClient, isUIClient, useIsMounted__INTERNAL, useStytchMember } from './StytchB2BContext';\nimport { invariant } from '../utils/invariant';\nimport { noHeadlessClientError, noProviderError } from '../utils/errors';\nimport useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect';\n\nexport interface StytchB2BProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> extends StringsOptions {\n /**\n * An optional {@link StyleConfig} to customize the look and feel of the screen.\n *\n * @example\n * {\n * fontFamily: 'Arial, Helvetica, sans-serif',\n * width: '360px',\n * primaryColor: '#19303D',\n * }\n */\n styles?: StyleConfig;\n /**\n * An optional {@link Callbacks} object.\n *\n * @example\n * {\n * onError: ({message}) => {\n * console.error('Stytch error', message)\n * }\n * }\n *\n * @example\n * {\n * onEvent: ({type, data}) => {\n * if(type === StytchEventType.B2BMagicLinkAuthenticate) {\n * console.log('Logged in with', data);\n * }\n * }\n * }\n */\n callbacks?: Callbacks<TProjectConfiguration>;\n /**\n * A {@link StytchB2BUIConfig} object. Add products and product-specific config to this object to change the login methods shown.\n *\n *\n * @example\n * {\n * products: ['emailMagicLinks'],\n * authFlowType: \"Discovery\",\n * emailMagicLinksOptions: {\n * discoveryRedirectURL: 'https://example.com/authenticate',\n * },\n * sessionOptions: {\n * sessionDurationMinutes: 60,\n * },\n * }\n *\n * @example\n * {\n * products: ['emailMagicLinks', 'sso'],\n * authFlowType: \"Organization\",\n * emailMagicLinksOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * },\n * ssoOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * },\n * sessionOptions: {\n * sessionDurationMinutes: 60,\n * },\n * }\n */\n config: StytchB2BUIConfig;\n}\n\nexport type B2BIDPConsentManifestGenerator = (input: {\n scopes: string[];\n clientName: string;\n}) => IDPConsentScreenManifest;\n\ntype B2BAuthTokenParams = { trustedAuthToken: string; tokenProfileID: string };\n\nexport type B2BIdentityProviderProps = Omit<StytchB2BProps, 'config'> & {\n /**\n * Optional {@link B2BIDPConsentManifestGenerator} to customize the consent screen.\n */\n getIDPConsentManifest?: B2BIDPConsentManifestGenerator;\n /**\n * Optional trusted auth token parameters to attest before the OAuth flow.\n */\n trustedAuthTokenParams?: B2BAuthTokenParams;\n};\n\n/**\n * The Stytch B2B UI component.\n * This component can only be used with a Stytch B2B UI Client\n * passed into the StytchB2BProvider.\n *\n * See the {@link https://stytch.com/docs/b2b/sdks online reference}\n *\n * @example\n * <StytchB2B\n * config={{\n * authFlowType: \"Organization\",\n * emailMagicLinksOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * },\n * ssoOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * },\n * sessionOptions: {\n * sessionDurationMinutes: 60,\n * }\n * }}\n * styles={{\n * fontFamily: '\"Helvetica New\", Helvetica, sans-serif',\n * primaryColor: '#0577CA',\n * width: '321px',\n * }}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const StytchB2B = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n styles,\n callbacks,\n config,\n strings,\n}: StytchB2BProps<TProjectConfiguration>) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('<StytchB2B />', 'StytchB2BProvider'));\n const stytchClient = useStytchB2BClient<TProjectConfiguration>();\n const containerEl = useRef<HTMLDivElement>(null);\n\n useIsomorphicLayoutEffect(() => {\n if (!isUIClient(stytchClient)) {\n throw Error(noHeadlessClientError);\n }\n\n if (!containerEl.current) {\n return;\n }\n\n if (!containerEl.current.id) {\n const randId = Math.floor(Math.random() * 1e6);\n containerEl.current.id = `stytch-b2b-ui-${randId}`;\n }\n\n stytchClient.mount({\n callbacks,\n config,\n elementId: `#${containerEl.current.id}`,\n styles,\n strings,\n });\n }, [stytchClient, styles, callbacks, strings]);\n\n return <div ref={containerEl} />;\n};\n\n/**\n * The Stytch B2B IDP component.\n * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.\n * Requires the user to be logged in.\n * This component can only be used with a Stytch B2B UI Client\n * passed into the StytchB2BProvider.\n *\n * See the {@link https://stytch.com/docs/b2b/sdks online reference}\n *\n * @example\n * const styles = {\n * container: {\n * backgroundColor: '#e11e1e',\n * },\n * colors: {\n * primary: '#ff00f7',\n * secondary: '#5C727D',\n * },\n * }\n *\n * <B2BIdentityProvider\n * styles={styles}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const B2BIdentityProvider = ({\n styles,\n callbacks,\n getIDPConsentManifest,\n trustedAuthTokenParams,\n}: B2BIdentityProviderProps) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('<IdentityProvider />'));\n const stytchClient = useStytchB2BClient();\n const { member } = useStytchMember();\n const containerEl = useRef<HTMLDivElement>(null);\n\n useIsomorphicLayoutEffect(() => {\n if (!isUIClient(stytchClient)) {\n throw Error(noHeadlessClientError);\n }\n\n if (!containerEl.current) {\n return;\n }\n\n if (!containerEl.current.id) {\n const randId = Math.floor(Math.random() * 1e6);\n containerEl.current.id = `stytch-b2b-idp-${randId}`;\n }\n\n stytchClient.mountIdentityProvider({\n callbacks,\n elementId: `#${containerEl.current.id}`,\n styles,\n getIDPConsentManifest,\n trustedAuthTokenParams,\n });\n }, [stytchClient, styles, callbacks, member, getIDPConsentManifest, trustedAuthTokenParams]);\n\n return <div ref={containerEl} />;\n};\n","import React, { ComponentType, ReactNode } from 'react';\n\nimport type { Member, MemberSession, Organization, StytchB2BUIClient } from '@stytch/vanilla-js/b2b';\nimport type { StytchB2BHeadlessClient, StytchProjectConfigurationInput } from '@stytch/vanilla-js/b2b/headless';\n\n// We need a direct import to the original source file here (StytchB2BContext,\n// not just a barrel file) or the built type declarations will re-export these\n// values without ever importing them. This is evidently a bug that will\n// hopefully be resolved when we upgrade our build tooling.\n// eslint-disable-next-line @typescript-eslint/no-restricted-imports\nexport {\n useStytchB2BClient,\n withStytchB2BClient,\n withStytchPermissions,\n} from '@stytch/internal-react-shared/src/b2b/StytchB2BContext';\n// eslint-disable-next-line @typescript-eslint/no-restricted-imports\nimport {\n StytchB2BProvider as StytchB2BProviderShared,\n useStytchIsAuthorized as useStytchIsAuthorizedShared,\n useStytchMemberSession as useStytchMemberSessionShared,\n useStytchMember as useStytchMemberShared,\n useStytchOrganization as useStytchOrganizationShared,\n withStytchMemberSession as withStytchMemberSessionShared,\n withStytchMember as withStytchMemberShared,\n withStytchOrganization as withStytchOrganizationShared,\n} from '@stytch/internal-react-shared/src/b2b';\n\n/**\n * The Stytch Client object passed in to <StytchB2BProvider /> in your application root.\n * Either a StytchB2BUIClient or StytchB2BHeadlessClient.\n */\ntype StytchB2BClient<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | StytchB2BHeadlessClient<TProjectConfiguration>\n | StytchB2BUIClient<TProjectConfiguration>;\n\n/**\n * Returns the active Member.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the member data is from persistent storage.\n * @example\n * const {member, isInitialized, fromCache} = useStytchMember();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<h1>Welcome, {member.name}</h1>);\n */\nexport const useStytchMember = useStytchMemberShared as <TAssumeHydrated extends boolean = true>() => ReturnType<\n typeof useStytchMemberShared<TAssumeHydrated>\n>;\n\n/**\n * Returns the active member's Stytch member session.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the session data is from persistent storage.\n * @example\n * const {session, isInitialized, fromCache} = useStytchMemberSession();\n * useEffect(() => {\n * if (!isInitialized) {\n * return;\n * }\n * if (!session) {\n * router.replace('/login')\n * }\n * }, [session, isInitialized]);\n */\nexport const useStytchMemberSession = useStytchMemberSessionShared as <\n TAssumeHydrated extends boolean = true,\n>() => ReturnType<typeof useStytchMemberSessionShared<TAssumeHydrated>>;\n\n/**\n * Returns the active Stytch organization.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the organization data is from persistent storage.\n * @example\n * const {organization, isInitialized, fromCache} = useStytchOrganization();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<p>Welcome to {organization.organization_name}</p>);\n */\nexport const useStytchOrganization = useStytchOrganizationShared as <\n TAssumeHydrated extends boolean = true,\n>() => ReturnType<typeof useStytchOrganizationShared<TAssumeHydrated>>;\n\n/**\n * Determines whether the logged-in member is allowed to perform the specified action on the specified resource.\n * Returns `true` if the member can perform the action, `false` otherwise.\n *\n * If the member is not logged in, this method will always return false.\n * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * const { isAuthorized } = useStytchIsAuthorized<Permissions>('documents', 'edit');\n * return <button disabled={!isAuthorized}>Edit</button>\n */\nexport const useStytchIsAuthorized = useStytchIsAuthorizedShared as <TAssumeHydrated extends boolean = false>(\n resourceId: string,\n action: string,\n) => ReturnType<typeof useStytchIsAuthorizedShared<TAssumeHydrated>>;\n\nexport const withStytchMember = withStytchMemberShared as <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & { stytchMember: Member | null; stytchMemberIsInitialized: boolean; stytchMemberIsFromCache: boolean }\n >,\n) => ReturnType<typeof withStytchMemberShared<T, TAssumeHydrated>>;\n\nexport const withStytchMemberSession = withStytchMemberSessionShared as <\n T extends object,\n TAssumeHydrated extends boolean = false,\n>(\n Component: ComponentType<\n T & {\n stytchMemberSession: MemberSession | null;\n stytchMemberSessionIsInitialized: boolean;\n stytchMemberSessionIsFromCache: boolean;\n }\n >,\n) => ReturnType<typeof withStytchMemberSessionShared<T, TAssumeHydrated>>;\n\nexport const withStytchOrganization = withStytchOrganizationShared as <\n T extends object,\n TAssumeHydrated extends boolean = false,\n>(\n Component: ComponentType<\n T & {\n stytchOrganization: Organization | null;\n stytchOrganizationIsInitialized: boolean;\n stytchOrganizationIsFromCache: boolean;\n }\n >,\n) => ReturnType<typeof withStytchOrganizationShared<T, TAssumeHydrated>>;\n\nexport interface StytchB2BProviderProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> {\n /**\n * A Stytch client instance, either a {@link StytchB2BUIClient} or {@link StytchB2BHeadlessClient}\n */\n stytch: StytchB2BClient<TProjectConfiguration>;\n /**\n * When true, the provider will assume that the component will only be\n * rendered in a browser environment, either in a single-page application or\n * after completing hydration of a server-rendered application. This allows\n * cached values to be retrieved from the browser on the first render, meaning\n * that the `isInitialized` value returned from Stytch hooks will be `true`\n * starting from the first render.\n *\n * When `false`, the provider will defer initialization until after the first\n * render, and `isInitialized` will initially be `false`.\n *\n * If you encounter hydration errors relating to the use of this component,\n * set this to `false`.\n *\n * This value defaults to `true` in `@stytch/react`.\n */\n assumeHydrated?: boolean;\n children?: ReactNode;\n}\n\n/**\n * The Stytch Context Provider.\n * Wrap your application with this component in order to use Stytch everywhere in your app.\n * @example\n * const stytch = createStytchB2BHeadlessClient('public-token-<find yours in the stytch dashboard>')\n *\n * ReactDOM.render(\n * <StytchB2BProvider stytch={stytch}>\n * <App />\n * </StytchProvider>,\n * document.getElementById('root'),\n * )\n */\nexport const StytchB2BProvider = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n stytch,\n children,\n assumeHydrated = true,\n}: StytchB2BProviderProps<TProjectConfiguration>): JSX.Element => {\n return (\n <StytchB2BProviderShared stytch={stytch} assumeHydrated={assumeHydrated}>\n {children}\n </StytchB2BProviderShared>\n );\n};\n"],"names":["invariant","useIsMounted__INTERNAL","noProviderError","useStytchB2BClient","useRef","useIsomorphicLayoutEffect","isUIClient","noHeadlessClientError","React","useStytchMember","useStytchMemberShared","useStytchMemberSessionShared","useStytchOrganizationShared","useStytchIsAuthorizedShared","withStytchMemberShared","withStytchMemberSessionShared","withStytchOrganizationShared","StytchB2BProviderShared"],"mappings":";;;;;;;;;;;;;;AAwGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCG;AACI,MAAM,SAAS,GAAG,CAEvB,EACA,MAAM,EACN,SAAS,EACT,MAAM,EACN,OAAO,GAC+B,KAAI;IAC1CA,mCAAS,CAACC,uCAAsB,EAAE,EAAEC,8BAAe,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAC3F,IAAA,MAAM,YAAY,GAAGC,mCAAkB,EAAyB,CAAC;AACjE,IAAA,MAAM,WAAW,GAAGC,YAAM,CAAiB,IAAI,CAAC,CAAC;IAEjDC,mDAAyB,CAAC,MAAK;AAC7B,QAAA,IAAI,CAACC,2BAAU,CAAC,YAAY,CAAC,EAAE;AAC7B,YAAA,MAAM,KAAK,CAACC,oCAAqB,CAAC,CAAC;SACpC;AAED,QAAA,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;YACxB,OAAO;SACR;AAED,QAAA,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,EAAE;AAC3B,YAAA,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;YAC/C,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,CAAiB,cAAA,EAAA,MAAM,EAAE,CAAC;SACpD;QAED,YAAY,CAAC,KAAK,CAAC;YACjB,SAAS;YACT,MAAM;AACN,YAAA,SAAS,EAAE,CAAI,CAAA,EAAA,WAAW,CAAC,OAAO,CAAC,EAAE,CAAE,CAAA;YACvC,MAAM;YACN,OAAO;AACR,SAAA,CAAC,CAAC;KACJ,EAAE,CAAC,YAAY,EAAE,MAAM,E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EAAE,SAAS,EAAE,MAAM,EAAE,qBAAqB,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAE7F,IAAA,OAAOC,yBAAK,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,GAAG,EAAE,WAAW,GAAI,CAAC;AACnC;;AC1MA;;;;;;;;;;;AAWG;AACI,MAAM,eAAe,GAAGE,iCAE7B;AAEF;;;;;;;;;;;;;;;AAeG;AACI,MAAM,sBAAsB,GAAGC,wCAEkC;AAExE;;;;;;;;;;;AAWG;AACI,MAAM,qBAAqB,GAAGC,uCAEkC;AAEvE;;;;;;;;;;;AAWG;AACI,MAAM,qBAAqB,GAAGC,uCAGgC;AAE9D,MAAM,gBAAgB,GAAGC,kCAImC;AAE5D,MAAM,uBAAuB,GAAGC,yCAWmC;AAEnE,MAAM,sBAAsB,GAAGC,wCAWmC;AA6BzE;;;;;;;;;;;;AAYG;AACI,MAAM,iBAAiB,GAAG,CAE/B,EACA,MAAM,EACN,QAAQ,EACR,cAAc,GAAG,IAAI,GACyB,KAAiB;AAC/D,IAAA,QACER,yBAAA,CAAA,aAAA,CAACS,kCAAuB,EAAA,EAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,EAAA,EACpE,QAAQ,CACe,EAC1B;AACJ;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -23,3 +23,4 @@ const createStytchB2BUIClient = (...args) => {
23
23
  };
24
24
 
25
25
  export { createStytchB2BUIClient };
26
+ //# sourceMappingURL=index.ui.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.ui.esm.js","sources":["../../../../internal/react-shared/src/b2b/createStytchB2BUIClient.ts"],"sourcesContent":["import { StytchB2BUIClient, StytchProjectConfigurationInput } from '@stytch/vanilla-js/b2b';\nimport { createStytchSSRProxy } from '../StytchSSRProxy';\n\n/**\n * Creates a Stytch UI client object to call the Stytch APIs and render Stytch UI components.\n * The Stytch client is not available serverside.\n * If you do not use Stytch UI components, use {@link createStytchB2BHeadlessClient} to reduce your bundle size.\n * @example\n * const stytch = createStytchB2BUIClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchB2BProvider stytch={stytch}>\n * <App />\n * </StytchB2BProvider>\n * )\n * @returns A {@link StytchB2BUIClient}\n */\nexport const createStytchB2BUIClient = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(\n ...args: ConstructorParameters<typeof StytchB2BUIClient<TProjectConfiguration>>\n): StytchB2BUIClient<TProjectConfiguration> => {\n if (typeof window === 'undefined') {\n return createStytchSSRProxy();\n }\n return new StytchB2BUIClient<TProjectConfiguration>(...args);\n};\n"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;AAaG;MACU,uBAAuB,GAAG,CAGrC,GAAG,IAA4E,KACnC;AAC5C,IAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,oBAAoB,EAAE,CAAC;KAC/B;AACD,IAAA,OAAO,IAAI,iBAAiB,CAAwB,GAAG,IAAI,CAAC,CAAC;AAC/D;;;;"}
@@ -27,3 +27,4 @@ const createStytchB2BUIClient = (...args) => {
27
27
  };
28
28
 
29
29
  exports.createStytchB2BUIClient = createStytchB2BUIClient;
30
+ //# sourceMappingURL=index.ui.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.ui.js","sources":["../../../../internal/react-shared/src/b2b/createStytchB2BUIClient.ts"],"sourcesContent":["import { StytchB2BUIClient, StytchProjectConfigurationInput } from '@stytch/vanilla-js/b2b';\nimport { createStytchSSRProxy } from '../StytchSSRProxy';\n\n/**\n * Creates a Stytch UI client object to call the Stytch APIs and render Stytch UI components.\n * The Stytch client is not available serverside.\n * If you do not use Stytch UI components, use {@link createStytchB2BHeadlessClient} to reduce your bundle size.\n * @example\n * const stytch = createStytchB2BUIClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchB2BProvider stytch={stytch}>\n * <App />\n * </StytchB2BProvider>\n * )\n * @returns A {@link StytchB2BUIClient}\n */\nexport const createStytchB2BUIClient = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(\n ...args: ConstructorParameters<typeof StytchB2BUIClient<TProjectConfiguration>>\n): StytchB2BUIClient<TProjectConfiguration> => {\n if (typeof window === 'undefined') {\n return createStytchSSRProxy();\n }\n return new StytchB2BUIClient<TProjectConfiguration>(...args);\n};\n"],"names":["createStytchSSRProxy","StytchB2BUIClient"],"mappings":";;;;;;;AAGA;;;;;;;;;;;;;AAaG;MACU,uBAAuB,GAAG,CAGrC,GAAG,IAA4E,KACnC;AAC5C,IAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAOA,mCAAoB,EAAE,CAAC;KAC/B;AACD,IAAA,OAAO,IAAIC,qBAAiB,CAAwB,GAAG,IAAI,CAAC,CAAC;AAC/D;;;;"}
package/dist/index.esm.js CHANGED
@@ -496,3 +496,4 @@ const StytchProvider = ({ stytch, children, assumeHydrated = true, }) => {
496
496
  };
497
497
 
498
498
  export { IdentityProvider, StytchLogin, StytchPasskeyRegistration, StytchPasswordReset, StytchProvider, useStytch, useStytchIsAuthorized, useStytchSession, useStytchUser, withStytch, withStytchPermissions, withStytchSession, withStytchUser };
499
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../../../internal/react-shared/src/StytchContext.tsx","../../../internal/react-shared/src/Stytch.tsx","../src/StytchContext.tsx"],"sourcesContent":["import React, {\n ComponentType,\n createContext,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport { mergeWithStableProps } from '@stytch/js-utils';\nimport type { Session, StytchProjectConfigurationInput, StytchUIClient, User } from '@stytch/vanilla-js';\nimport type { PermissionsMap, StytchHeadlessClient } from '@stytch/vanilla-js/headless';\nimport { useAsyncState } from './utils/async';\nimport { noProviderError, providerMustBeUniqueError } from './utils/errors';\nimport { invariant } from './utils/invariant';\nimport { isStytchSSRProxy } from './StytchSSRProxy';\n\n/**\n * The Stytch Client object passed in to <StytchProvider /> in your application root.\n * Either a StytchUIClient or StytchHeadlessClient.\n */\ntype StytchClient<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | StytchUIClient<TProjectConfiguration>\n | StytchHeadlessClient<TProjectConfiguration>;\n\ntype StytchContext<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | {\n isMounted: false;\n }\n | {\n isMounted: true;\n client: StytchClient<TProjectConfiguration>;\n };\n\ntype SWRUserUninitialized = {\n /**\n * Either the active {@link User} object, or null if the user is not logged in.\n */\n user: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRUserInitialized = {\n /**\n * Either the active {@link User} object, or null if the user is not logged in.\n */\n user: User | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRUser<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRUserInitialized\n : SWRUserInitialized | SWRUserUninitialized;\n\nconst initialUser: SWRUserUninitialized = {\n user: null,\n fromCache: false,\n isInitialized: false,\n};\n\ntype SWRSessionUninitialized = {\n /**\n * Either the active {@link Session} object, or null if the user is not logged in.\n */\n session: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRSessionInitialized = {\n /**\n * Either the active {@link Session} object, or null if the user is not logged in.\n */\n session: Session | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRSession<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRSessionInitialized\n : SWRSessionInitialized | SWRSessionUninitialized;\n\nconst initialSession: SWRSessionUninitialized = {\n session: null,\n fromCache: false,\n isInitialized: false,\n};\n\nconst StytchContext = createContext<StytchContext<StytchProjectConfigurationInput>>({ isMounted: false });\nconst StytchUserContext = createContext<SWRUser>(initialUser);\nconst StytchSessionContext = createContext<SWRSession>(initialSession);\n\nexport const useIsMounted__INTERNAL = (): boolean => useContext(StytchContext).isMounted;\n\nexport const isUIClient = <TProjectConfiguration extends StytchProjectConfigurationInput>(\n client: StytchClient<TProjectConfiguration>,\n): client is StytchUIClient<TProjectConfiguration> => {\n return (client as StytchUIClient<TProjectConfiguration>).mountLogin !== undefined;\n};\n\n/**\n * Returns the active User.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the user data is from persistent storage.\n * @example\n * const {user, isInitialized, fromCache} = useStytchUser();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<h1>Welcome, {user.name.first_name}</h1>);\n */\nexport const useStytchUser = <TAssumeHydrated extends boolean = false>(): SWRUser<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchUser'));\n return useContext(StytchUserContext) as SWRUser<TAssumeHydrated>;\n};\n\n/**\n * Returns the active user's Stytch session.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the session data is from persistent storage.\n * @example\n * const {session, isInitialized, fromCache} = useStytchSession();\n * useEffect(() => {\n * if (!isInitialized) {\n * return;\n * }\n * if (!session) {\n * router.replace('/login')\n * }\n * }, [session, isInitialized]);\n */\nexport const useStytchSession = <TAssumeHydrated extends boolean = false>(): SWRSession<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchSession'));\n return useContext(StytchSessionContext) as SWRSession<TAssumeHydrated>;\n};\n\n/**\n * Returns the Stytch client stored in the Stytch context.\n *\n * @example\n * const stytch = useStytch();\n * useEffect(() => {\n * stytch.magicLinks.authenticate('...')\n * }, [stytch]);\n */\nexport const useStytch = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(): StytchClient<TProjectConfiguration> => {\n const ctx = useContext(StytchContext);\n invariant(ctx.isMounted, noProviderError('useStytch'));\n return ctx.client as StytchClient<TProjectConfiguration>;\n};\n\nexport const withStytch = <\n T extends object,\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(\n Component: ComponentType<T & { stytch: StytchClient<TProjectConfiguration> }>,\n): ComponentType<T> => {\n const WithStytch: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytch'));\n return <Component {...props} stytch={useStytch()} />;\n };\n WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;\n return WithStytch;\n};\n\nexport const withStytchUser = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & { stytchUser: User | null; stytchUserIsInitialized: boolean; stytchUserIsFromCache: boolean }\n >,\n): ComponentType<T> => {\n const WithStytchUser: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchUser'));\n const { user, isInitialized, fromCache } = useStytchUser<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchUser={user}\n stytchUserIsInitialized={isInitialized}\n stytchUserIsFromCache={fromCache}\n />\n );\n };\n WithStytchUser.displayName = `withStytchUser(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchUser;\n};\n\nexport const withStytchSession = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & { stytchSession: Session | null; stytchSessionIsInitialized: boolean; stytchSessionIsFromCache: boolean }\n >,\n): ComponentType<T> => {\n const WithStytchSession: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchSession'));\n const { session, isInitialized, fromCache } = useStytchSession<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchSession={session}\n stytchSessionIsInitialized={isInitialized}\n stytchSessionIsFromCache={fromCache}\n />\n );\n };\n WithStytchSession.displayName = `withStytchSession(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchSession;\n};\n\ntype SWRIsAuthorizedUninitialized = {\n /**\n * Whether the logged-in user is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: false;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRIsAuthorizedInitialized = {\n /**\n * Whether the logged-in user is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: boolean;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: boolean;\n};\n\ntype SWRIsAuthorized<TAlwaysInitialized extends boolean> = TAlwaysInitialized extends true\n ? SWRIsAuthorizedInitialized\n : SWRIsAuthorizedInitialized | SWRIsAuthorizedUninitialized;\n\n/**\n * Determines whether the logged-in user is allowed to perform the specified action on the specified resource.\n * Returns `true` if the user can perform the action, `false` otherwise.\n *\n * If the user is not logged in, this method will always return false.\n * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * const { isAuthorized } = useStytchIsAuthorized<Permissions>('documents', 'edit');\n * return <button disabled={!isAuthorized}>Edit</button>\n */\nexport const useStytchIsAuthorized = <TAssumeHydrated extends boolean = false>(\n resourceId: string,\n action: string,\n): SWRIsAuthorized<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchIsAuthorized', 'StytchProvider'));\n const client = useStytch();\n const { user } = useStytchUser();\n const [isAuthorized, setIsAuthorized] = useAsyncState<SWRIsAuthorized<boolean>>({\n isInitialized: false,\n fromCache: false,\n isAuthorized: false,\n });\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n\n setIsAuthorized({\n isInitialized: true,\n fromCache: true,\n isAuthorized: client.rbac.isAuthorizedSync(resourceId, action),\n });\n }, [action, client, resourceId, setIsAuthorized]);\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n client.rbac.isAuthorized(resourceId, action).then((isAuthorized) => {\n setIsAuthorized({ isAuthorized, fromCache: false, isInitialized: true });\n });\n }, [client, user?.roles, resourceId, action, setIsAuthorized]);\n\n return isAuthorized;\n};\n\ntype permissionsLoaded<Permissions extends Record<string, string>> =\n | {\n loaded: false;\n value: null;\n }\n | {\n loaded: true;\n value: PermissionsMap<Permissions>;\n };\n\n/**\n * Wrap your component with this HOC in order to receive the permissions for the logged-in user.\n * Evaluates all permissions granted to the logged-in user.\n * Returns a Record<RoleId, Record<Action, boolean>> response indicating the user's permissions.\n * Each boolean will be `true` if the user can perform the action, `false` otherwise.\n *\n * If the user is not logged in, all values will be false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * type Permissions = {\n * document: 'create' | 'read' | 'write\n * image: 'create' | 'read'\n * }\n *\n * const MyComponent = (props) => {\n * const canEditDocuments = props.stytchPermissions.document.edit;\n * const canReadImages = props.stytchPermissions.image.read;\n * }\n * return withStytchPermissions<Permissions>(MyComponent)\n */\nexport const withStytchPermissions = <Permissions extends Record<string, string>, T extends object>(\n Component: ComponentType<T & { stytchPermissions: PermissionsMap<Permissions> }>,\n): ComponentType<T> => {\n const WithStytchPermissions: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useRBACPermissions', 'StytchProvider'));\n const client = useStytch();\n const { user } = useStytchUser();\n const [permissions, setPermissions] = useAsyncState<permissionsLoaded<Permissions>>({ loaded: false, value: null });\n\n useEffect(() => {\n client.rbac.allPermissions<Permissions>().then((permissions) => {\n setPermissions({ loaded: true, value: permissions });\n });\n }, [client, user?.roles, setPermissions]);\n\n if (!permissions.loaded) {\n return null;\n }\n return <Component {...props} stytchPermissions={permissions.value} />;\n };\n WithStytchPermissions.displayName = `withStytchPermissions(${\n Component.displayName || Component.name || 'Component'\n })`;\n return WithStytchPermissions;\n};\n\nexport interface StytchProviderProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> {\n /**\n * A Stytch client instance, created using either {@link createStytchHeadlessClient} or {@link createStytchUIClient}\n */\n stytch: StytchClient<TProjectConfiguration>;\n /**\n * When true, the provider will assume that the component will only be\n * rendered in a browser environment, either in a single-page application or\n * after completing hydration of a server-rendered application. This allows\n * cached values to be retrieved from the browser on the first render, meaning\n * that the `isInitialized` value returned from Stytch hooks will be `true`\n * starting from the first render.\n *\n * When `false`, the provider will defer initialization until after the first\n * render, and `isInitialized` will initially be `false`.\n *\n * This value defaults to `false` in `@stytch/nextjs`.\n */\n assumeHydrated?: boolean;\n children?: ReactNode;\n}\n\n/**\n * The Stytch Context Provider.\n * Wrap your application with this component in order to use Stytch everywhere in your app.\n * @example\n * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchProvider stytch={stytch}>\n * <App />\n * </StytchProvider>\n * )\n */\nexport const StytchProvider = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n stytch,\n children,\n assumeHydrated = false,\n}: StytchProviderProps<TProjectConfiguration>): JSX.Element => {\n invariant(!useIsMounted__INTERNAL(), providerMustBeUniqueError);\n invariant(\n !assumeHydrated || typeof window !== 'undefined',\n 'The `assumeHydrated` prop must be set to `false` when using StytchProvider in a server environment.',\n );\n\n const ctx = useMemo(() => ({ client: stytch, isMounted: true }), [stytch]);\n\n type ClientState<TAlwaysInitialized extends boolean> = {\n session: SWRSession<TAlwaysInitialized>;\n user: SWRUser<TAlwaysInitialized>;\n };\n\n const getHydratedState = useCallback(() => {\n return {\n session: { ...stytch.session.getInfo(), isInitialized: true },\n user: { ...stytch.user.getInfo(), isInitialized: true },\n } satisfies ClientState<true>;\n }, [stytch]);\n\n const getInitialState = () => {\n return {\n session: initialSession,\n user: initialUser,\n } satisfies ClientState<false>;\n };\n\n const [{ user, session }, setClientState] = useAsyncState<ClientState<boolean>>(() =>\n assumeHydrated ? getHydratedState() : (getInitialState() as ClientState<boolean>),\n );\n\n // Store the initial value of `assumeHydrated` in a ref, because it is\n // logically only relevant for the first render\n const assumeHydratedRef = useRef(assumeHydrated);\n useEffect(() => {\n if (isStytchSSRProxy(stytch)) {\n return;\n }\n\n const updateState = () => {\n setClientState((oldState) => mergeWithStableProps(oldState, getHydratedState()));\n };\n\n if (!assumeHydratedRef.current) {\n updateState();\n }\n\n return stytch.onStateChange(updateState);\n }, [getHydratedState, setClientState, stytch]);\n\n return (\n <StytchContext.Provider value={ctx}>\n <StytchUserContext.Provider value={user}>\n <StytchSessionContext.Provider value={session}>{children}</StytchSessionContext.Provider>\n </StytchUserContext.Provider>\n </StytchContext.Provider>\n );\n};\n","import React, { useRef } from 'react';\nimport type {\n Callbacks,\n StringsOptions,\n StytchLoginConfig,\n StyleConfig,\n StytchProjectConfigurationInput,\n IDPConsentScreenManifest,\n} from '@stytch/vanilla-js';\n\nimport { useStytch, isUIClient, useIsMounted__INTERNAL, useStytchUser } from './StytchContext';\nimport { invariant } from './utils/invariant';\nimport { noHeadlessClientError, noProviderError } from './utils/errors';\nimport useIsomorphicLayoutEffect from './utils/useIsomorphicLayoutEffect';\n\nexport interface StytchProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> extends StringsOptions {\n /**\n * A {@link StytchLoginConfig} object. Add products and product-specific config to this object to change the login methods shown.\n *\n * @example\n * {\n * products: ['crypto', 'otps']\n * }\n *\n * @example\n * {\n * products: ['emailMagicLinks'>]\n * emailMagicLinksOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * }\n * }\n *\n * @example\n * {\n * products: ['oauth'>]\n * oauthOptions: {\n * providers: [\n * { type: 'google', one_tap: true, position: 'embedded' },\n * { type: 'microsoft' },\n * { type: 'apple' },\n * { type: 'facebook' },\n * ],\n * }\n * }\n */\n config: StytchLoginConfig;\n /**\n * An optional {@link StyleConfig} to customize the look and feel of the screen.\n *\n * @example\n * {\n * fontFamily: 'Arial, Helvetica, sans-serif',\n * width: '360px',\n * primaryColor: '#19303D',\n * }\n */\n styles?: StyleConfig;\n /**\n * An optional {@link Callbacks} object.\n *\n * @example\n * {\n * onError: ({message}) => {\n * console.error('Stytch login screen error', message)\n * }\n * }\n *\n * @example\n * {\n * onEvent: ({type, data}) => {\n * if(type === StytchEventType.CryptoWalletAuthenticate) {\n * console.log('Logged in with crypto wallet', data);\n * }\n * }\n * }\n */\n callbacks?: Callbacks<TProjectConfiguration>;\n}\n\n/**\n * The Stytch Login Screen component.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * <StytchLogin\n * config={{\n * products: ['emailMagicLinks', 'oauth'],\n * emailMagicLinksOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * },\n * oauthOptions: {\n * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],\n * },\n * }}\n * styles={{\n * fontFamily: '\"Helvetica New\", Helvetica, sans-serif',\n * primaryColor: '#0577CA',\n * width: '321px',\n * }}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const StytchLogin = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n config,\n styles,\n callbacks,\n strings,\n}: StytchProps<TProjectConfiguration>) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('<StytchLogin />'));\n const stytchClient = useStytch<TProjectConfiguration>();\n const containerEl = useRef<HTMLDivElement>(null);\n\n useIsomorphicLayoutEffect(() => {\n if (!isUIClient(stytchClient)) {\n throw Error(noHeadlessClientError);\n }\n\n if (!containerEl.current) {\n return;\n }\n\n if (!containerEl.current.id) {\n const randId = Math.floor(Math.random() * 1e6);\n containerEl.current.id = `stytch-magic-link-${randId}`;\n }\n\n stytchClient.mountLogin({\n config,\n callbacks,\n elementId: `#${containerEl.current.id}`,\n styles,\n strings,\n });\n }, [stytchClient, config, styles, callbacks, strings]);\n\n return <div ref={containerEl} />;\n};\n\nexport interface StytchResetPasswordProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> extends StytchProps<TProjectConfiguration> {\n /**\n * A Stytch password reset token.\n */\n passwordResetToken: string;\n}\n\nexport type IDPConsentScreenManifestGenerator = (input: {\n scopes: string[];\n clientName: string;\n}) => IDPConsentScreenManifest;\n\nexport type AuthTokenParams = {\n /**\n * The auth token to provide for attestation prior to running OAuth flow.\n */\n trustedAuthToken: string;\n /**\n * The profile ID of the token.\n */\n tokenProfileID: string;\n};\n\nexport type IdentityProviderProps = Omit<StytchProps, 'config'> & {\n /**\n * Optional {@link IDPConsentScreenManifestGenerator} to customize the consent screen.\n */\n getIDPConsentManifest?: IDPConsentScreenManifestGenerator;\n /**\n * Optional {@link AuthTokenParams} to provide a trusted auth token to provide for attestation prior to running OAuth flow.\n */\n authTokenParams?: AuthTokenParams;\n};\n\n/**\n * The Stytch Reset Password component.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * <StytchPasswordReset\n * config={{\n * products: ['emailMagicLinks', 'oauth'],\n * emailMagicLinksOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * },\n * oauthOptions: {\n * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],\n * },\n * }}\n * passwordResetToken=\"PvC5UudZ7TPZbELt95yXAQ-8MeEUCRob8bUQ-g52fIJs\"\n * styles={{\n * fontFamily: '\"Helvetica New\", Helvetica, sans-serif',\n * primaryColor: '#0577CA',\n * width: '321px',\n * }}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const StytchPasswordReset = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n config,\n styles,\n callbacks,\n strings,\n passwordResetToken,\n}: StytchResetPasswordProps<TProjectConfiguration>) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('<StytchResetPassword />'));\n const stytchClient = useStytch<TProjectConfiguration>();\n const containerEl = useRef<HTMLDivElement>(null);\n\n useIsomorphicLayoutEffect(() => {\n if (!isUIClient(stytchClient)) {\n throw Error(noHeadlessClientError);\n }\n\n if (!containerEl.current) {\n return;\n }\n\n if (!containerEl.current.id) {\n const randId = Math.floor(Math.random() * 1e6);\n containerEl.current.id = `stytch-reset-password-${randId}`;\n }\n\n if (passwordResetToken) {\n stytchClient.mountResetPassword({\n config,\n callbacks,\n elementId: `#${containerEl.current.id}`,\n styles,\n strings,\n passwordResetToken,\n });\n }\n }, [stytchClient, config, styles, callbacks, strings, passwordResetToken]);\n\n return <div ref={containerEl} />;\n};\n\n/**\n * The Stytch Passkey Registration component.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * const styles = {\n * container: {\n * backgroundColor: '#e11e1e',\n * },\n * colors: {\n * primary: '#ff00f7',\n * secondary: '#5C727D',\n * },\n * }\n *\n * <StytchPasskeyRegistration\n * styles={styles}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const StytchPasskeyRegistration = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n config,\n styles,\n callbacks,\n strings,\n}: StytchProps<TProjectConfiguration>) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('<StytchPasskeyRegistration />'));\n const stytchClient = useStytch<TProjectConfiguration>();\n const user = useStytchUser();\n const containerEl = useRef<HTMLDivElement>(null);\n\n useIsomorphicLayoutEffect(() => {\n if (!isUIClient(stytchClient)) {\n throw Error(noHeadlessClientError);\n }\n\n if (!containerEl.current) {\n return;\n }\n\n if (!containerEl.current.id) {\n const randId = Math.floor(Math.random() * 1e6);\n containerEl.current.id = `stytch-passkey-registration-${randId}`;\n }\n\n stytchClient.mountPasskeyRegistration({\n config,\n callbacks,\n elementId: `#${containerEl.current.id}`,\n styles,\n strings,\n });\n }, [stytchClient, config, styles, callbacks, strings, user]);\n\n return <div ref={containerEl} />;\n};\n\n/**\n * The Stytch IDP component.\n * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.\n * Requires the user to be logged in.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * const styles = {\n * container: {\n * backgroundColor: '#e11e1e',\n * },\n * colors: {\n * primary: '#ff00f7',\n * secondary: '#5C727D',\n * },\n * }\n *\n * <IdentityProvider\n * styles={styles}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const IdentityProvider = ({\n styles,\n callbacks,\n strings,\n getIDPConsentManifest,\n authTokenParams,\n}: IdentityProviderProps) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('<IdentityProvider />'));\n const stytchClient = useStytch();\n const user = useStytchUser();\n const containerEl = useRef<HTMLDivElement>(null);\n\n useIsomorphicLayoutEffect(() => {\n if (!isUIClient(stytchClient)) {\n throw Error(noHeadlessClientError);\n }\n\n if (!containerEl.current) {\n return;\n }\n\n if (!containerEl.current.id) {\n const randId = Math.floor(Math.random() * 1e6);\n containerEl.current.id = `stytch-idp-${randId}`;\n }\n\n stytchClient.mountIdentityProvider({\n callbacks,\n elementId: `#${containerEl.current.id}`,\n styles,\n strings,\n getIDPConsentManifest,\n authTokenParams,\n });\n }, [stytchClient, styles, callbacks, user, strings, getIDPConsentManifest, authTokenParams]);\n\n return <div ref={containerEl} />;\n};\n","import React, { ComponentType, ReactNode } from 'react';\n\nimport type { StytchProjectConfigurationInput, StytchUIClient } from '@stytch/vanilla-js';\nimport type { Session, StytchHeadlessClient, User } from '@stytch/vanilla-js/headless';\n\nexport { useStytch, withStytch } from '@stytch/internal-react-shared';\n\nimport {\n StytchProvider as StytchProviderShared,\n useStytchSession as useStytchSessionShared,\n useStytchUser as useStytchUserShared,\n withStytchSession as withStytchSessionShared,\n withStytchUser as withStytchUserShared,\n useStytchIsAuthorized as useStytchIsAuthorizedShared,\n withStytchPermissions as withStytchPermissionsShared,\n} from '@stytch/internal-react-shared';\n\n/**\n * Returns the active User.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the user data is from persistent storage.\n * @example\n * const {user, isInitialized, fromCache} = useStytchUser();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<h1>Welcome, {user.name.first_name}</h1>);\n */\nexport const useStytchUser = useStytchUserShared as <TAssumeHydrated extends boolean = true>() => ReturnType<\n typeof useStytchUserShared<TAssumeHydrated>\n>;\n\n/**\n * Returns the active user's Stytch session.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the session data is from persistent storage.\n * @example\n * const {session, isInitialized, fromCache} = useStytchSession();\n * useEffect(() => {\n * if (!isInitialized) {\n * return;\n * }\n * if (!session) {\n * router.replace('/login')\n * }\n * }, [session, isInitialized]);\n */\nexport const useStytchSession = useStytchSessionShared as <TAssumeHydrated extends boolean = true>() => ReturnType<\n typeof useStytchSessionShared<TAssumeHydrated>\n>;\n\nexport const withStytchUser = withStytchUserShared as <T extends object, TAssumeHydrated extends boolean = true>(\n Component: ComponentType<\n T & { stytchUser: User | null; stytchUserIsInitialized: boolean; stytchUserIsFromCache: boolean }\n >,\n) => ReturnType<typeof withStytchUserShared<T, TAssumeHydrated>>;\n\nexport const withStytchSession = withStytchSessionShared as <T extends object, TAssumeHydrated extends boolean = true>(\n Component: ComponentType<\n T & { stytchSession: Session | null; stytchSessionIsInitialized: boolean; stytchSessionIsFromCache: boolean }\n >,\n) => ReturnType<typeof withStytchSessionShared<T, TAssumeHydrated>>;\n\nexport const useStytchIsAuthorized = useStytchIsAuthorizedShared as <TAssumeHydrated extends boolean = true>(\n resourceId: string,\n action: string,\n) => ReturnType<typeof useStytchIsAuthorizedShared<TAssumeHydrated>>;\n\nexport const withStytchPermissions = withStytchPermissionsShared as <\n Permissions extends Record<string, string>,\n T extends object,\n>(\n Component: ComponentType<T & { stytchPermissions: Record<string, Record<string, boolean>> }>,\n) => ReturnType<typeof withStytchPermissionsShared<Permissions, T>>;\n\n/**\n * The Stytch Client object passed in to <StytchProvider /> in your application root.\n * Either a StytchUIClient or StytchHeadlessClient.\n */\ntype StytchClient<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | StytchUIClient<TProjectConfiguration>\n | StytchHeadlessClient<TProjectConfiguration>;\n\nexport interface StytchProviderProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> {\n /**\n * A Stytch client instance, either a {@link StytchUIClient} or {@link StytchHeadlessClient}\n */\n stytch: StytchClient<TProjectConfiguration>;\n /**\n * When true, the provider will assume that the component will only be\n * rendered in a browser environment, either in a single-page application or\n * after completing hydration of a server-rendered application. This allows\n * cached values to be retrieved from the browser on the first render, meaning\n * that the `isInitialized` value returned from Stytch hooks will be `true`\n * starting from the first render.\n *\n * When `false`, the provider will defer initialization until after the first\n * render, and `isInitialized` will initially be `false`.\n *\n * If you encounter hydration errors relating to the use of this component,\n * set this to `false`.\n *\n * This value defaults to `true` in `@stytch/react`.\n */\n assumeHydrated?: boolean;\n children?: ReactNode;\n}\n\n/**\n * The Stytch Context Provider.\n * Wrap your application with this component in order to use Stytch everywhere in your app.\n * @example\n * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')\n *\n * ReactDOM.render(\n * <StytchProvider stytch={stytch}>\n * <App />\n * </StytchProvider>,\n * document.getElementById('root'),\n * )\n */\nexport const StytchProvider = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n stytch,\n children,\n assumeHydrated = true,\n}: StytchProviderProps<TProjectConfiguration>): JSX.Element => {\n return (\n <StytchProviderShared stytch={stytch} assumeHydrated={assumeHydrated}>\n {children}\n </StytchProviderShared>\n );\n};\n"],"names":["useStytchUser","useStytchSession","withStytchUser","withStytchSession","useStytchIsAuthorized","withStytchPermissions","StytchProvider","useStytchUserShared","useStytchSessionShared","withStytchUserShared","withStytchSessionShared","useStytchIsAuthorizedShared","withStytchPermissionsShared","StytchProviderShared"],"mappings":";;;;;AAsEA,MAAM,WAAW,GAAyB;AACxC,IAAA,IAAI,EAAE,IAAI;AACV,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,aAAa,EAAE,KAAK;CACrB,CAAC;AAoCF,MAAM,cAAc,GAA4B;AAC9C,IAAA,OAAO,EAAE,IAAI;AACb,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,aAAa,EAAE,KAAK;CACrB,CAAC;AAEF,MAAM,aAAa,GAAG,aAAa,CAAiD,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1G,MAAM,iBAAiB,GAAG,aAAa,CAAU,WAAW,CAAC,CAAC;AAC9D,MAAM,oBAAoB,GAAG,aAAa,CAAa,cAAc,CAAC,CAAC;AAEhE,MAAM,sBAAsB,GAAG,MAAe,UAAU,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC;AAElF,MAAM,UAAU,GAAG,CACxB,MAA2C,KACQ;AACnD,IAAA,OAAQ,MAAgD,CAAC,UAAU,KAAK,SAAS,CAAC;AACpF,CAAC,CAAC;AAEF;;;;;;;;;;;AAWG;AACI,MAAMA,eAAa,GAAG,MAAwE;IACnG,SAAS,CAAC,sBAAsB,EAAE,EAAE,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC;AACtE,IAA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22
  };
23
23
 
24
24
  export { createStytchHeadlessClient };
25
+ //# sourceMappingURL=index.headless.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.headless.esm.js","sources":["../../../internal/react-shared/src/createStytchHeadlessClient.ts"],"sourcesContent":["import { StytchHeadlessClient, StytchProjectConfigurationInput } from '@stytch/vanilla-js/headless';\nimport { createStytchSSRProxy } from './StytchSSRProxy';\n\n/**\n * Creates a Headless Stytch client object to call the stytch APIs.\n * The Stytch client is not available serverside.\n * @example\n * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchProvider stytch={stytch}>\n * <App />\n * </StytchProvider>\n * )\n * @returns A {@link StytchHeadlessClient}\n */\nexport const createStytchHeadlessClient = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(\n ...args: ConstructorParameters<typeof StytchHeadlessClient<TProjectConfiguration>>\n): StytchHeadlessClient<TProjectConfiguration> => {\n if (typeof window === 'undefined') {\n return createStytchSSRProxy();\n }\n return new StytchHeadlessClient<TProjectConfiguration>(...args);\n};\n"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;AAYG;MACU,0BAA0B,GAAG,CAGxC,GAAG,IAA+E,KACnC;AAC/C,IAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,oBAAoB,EAAE,CAAC;KAC/B;AACD,IAAA,OAAO,IAAI,oBAAoB,CAAwB,GAAG,IAAI,CAAC,CAAC;AAClE;;;;"}
@@ -26,3 +26,4 @@ const createStytchHeadlessClient = (...args) => {
26
26
  };
27
27
 
28
28
  exports.createStytchHeadlessClient = createStytchHeadlessClient;
29
+ //# sourceMappingURL=index.headless.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.headless.js","sources":["../../../internal/react-shared/src/createStytchHeadlessClient.ts"],"sourcesContent":["import { StytchHeadlessClient, StytchProjectConfigurationInput } from '@stytch/vanilla-js/headless';\nimport { createStytchSSRProxy } from './StytchSSRProxy';\n\n/**\n * Creates a Headless Stytch client object to call the stytch APIs.\n * The Stytch client is not available serverside.\n * @example\n * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchProvider stytch={stytch}>\n * <App />\n * </StytchProvider>\n * )\n * @returns A {@link StytchHeadlessClient}\n */\nexport const createStytchHeadlessClient = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(\n ...args: ConstructorParameters<typeof StytchHeadlessClient<TProjectConfiguration>>\n): StytchHeadlessClient<TProjectConfiguration> => {\n if (typeof window === 'undefined') {\n return createStytchSSRProxy();\n }\n return new StytchHeadlessClient<TProjectConfiguration>(...args);\n};\n"],"names":["createStytchSSRProxy","StytchHeadlessClient"],"mappings":";;;;;;;AAGA;;;;;;;;;;;;AAYG;MACU,0BAA0B,GAAG,CAGxC,GAAG,IAA+E,KACnC;AAC/C,IAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAOA,mCAAoB,EAAE,CAAC;KAC/B;AACD,IAAA,OAAO,IAAIC,6BAAoB,CAAwB,GAAG,IAAI,CAAC,CAAC;AAClE;;;;"}
package/dist/index.js CHANGED
@@ -524,3 +524,4 @@ exports.withStytch = withStytch;
524
524
  exports.withStytchPermissions = withStytchPermissions;
525
525
  exports.withStytchSession = withStytchSession;
526
526
  exports.withStytchUser = withStytchUser;
527
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../internal/react-shared/src/StytchContext.tsx","../../../internal/react-shared/src/Stytch.tsx","../src/StytchContext.tsx"],"sourcesContent":["import React, {\n ComponentType,\n createContext,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport { mergeWithStableProps } from '@stytch/js-utils';\nimport type { Session, StytchProjectConfigurationInput, StytchUIClient, User } from '@stytch/vanilla-js';\nimport type { PermissionsMap, StytchHeadlessClient } from '@stytch/vanilla-js/headless';\nimport { useAsyncState } from './utils/async';\nimport { noProviderError, providerMustBeUniqueError } from './utils/errors';\nimport { invariant } from './utils/invariant';\nimport { isStytchSSRProxy } from './StytchSSRProxy';\n\n/**\n * The Stytch Client object passed in to <StytchProvider /> in your application root.\n * Either a StytchUIClient or StytchHeadlessClient.\n */\ntype StytchClient<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | StytchUIClient<TProjectConfiguration>\n | StytchHeadlessClient<TProjectConfiguration>;\n\ntype StytchContext<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | {\n isMounted: false;\n }\n | {\n isMounted: true;\n client: StytchClient<TProjectConfiguration>;\n };\n\ntype SWRUserUninitialized = {\n /**\n * Either the active {@link User} object, or null if the user is not logged in.\n */\n user: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRUserInitialized = {\n /**\n * Either the active {@link User} object, or null if the user is not logged in.\n */\n user: User | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRUser<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRUserInitialized\n : SWRUserInitialized | SWRUserUninitialized;\n\nconst initialUser: SWRUserUninitialized = {\n user: null,\n fromCache: false,\n isInitialized: false,\n};\n\ntype SWRSessionUninitialized = {\n /**\n * Either the active {@link Session} object, or null if the user is not logged in.\n */\n session: null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRSessionInitialized = {\n /**\n * Either the active {@link Session} object, or null if the user is not logged in.\n */\n session: Session | null;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: true;\n};\n\ntype SWRSession<TAlwaysInitialized extends boolean = boolean> = TAlwaysInitialized extends true\n ? SWRSessionInitialized\n : SWRSessionInitialized | SWRSessionUninitialized;\n\nconst initialSession: SWRSessionUninitialized = {\n session: null,\n fromCache: false,\n isInitialized: false,\n};\n\nconst StytchContext = createContext<StytchContext<StytchProjectConfigurationInput>>({ isMounted: false });\nconst StytchUserContext = createContext<SWRUser>(initialUser);\nconst StytchSessionContext = createContext<SWRSession>(initialSession);\n\nexport const useIsMounted__INTERNAL = (): boolean => useContext(StytchContext).isMounted;\n\nexport const isUIClient = <TProjectConfiguration extends StytchProjectConfigurationInput>(\n client: StytchClient<TProjectConfiguration>,\n): client is StytchUIClient<TProjectConfiguration> => {\n return (client as StytchUIClient<TProjectConfiguration>).mountLogin !== undefined;\n};\n\n/**\n * Returns the active User.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the user data is from persistent storage.\n * @example\n * const {user, isInitialized, fromCache} = useStytchUser();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<h1>Welcome, {user.name.first_name}</h1>);\n */\nexport const useStytchUser = <TAssumeHydrated extends boolean = false>(): SWRUser<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchUser'));\n return useContext(StytchUserContext) as SWRUser<TAssumeHydrated>;\n};\n\n/**\n * Returns the active user's Stytch session.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the session data is from persistent storage.\n * @example\n * const {session, isInitialized, fromCache} = useStytchSession();\n * useEffect(() => {\n * if (!isInitialized) {\n * return;\n * }\n * if (!session) {\n * router.replace('/login')\n * }\n * }, [session, isInitialized]);\n */\nexport const useStytchSession = <TAssumeHydrated extends boolean = false>(): SWRSession<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchSession'));\n return useContext(StytchSessionContext) as SWRSession<TAssumeHydrated>;\n};\n\n/**\n * Returns the Stytch client stored in the Stytch context.\n *\n * @example\n * const stytch = useStytch();\n * useEffect(() => {\n * stytch.magicLinks.authenticate('...')\n * }, [stytch]);\n */\nexport const useStytch = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(): StytchClient<TProjectConfiguration> => {\n const ctx = useContext(StytchContext);\n invariant(ctx.isMounted, noProviderError('useStytch'));\n return ctx.client as StytchClient<TProjectConfiguration>;\n};\n\nexport const withStytch = <\n T extends object,\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(\n Component: ComponentType<T & { stytch: StytchClient<TProjectConfiguration> }>,\n): ComponentType<T> => {\n const WithStytch: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytch'));\n return <Component {...props} stytch={useStytch()} />;\n };\n WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;\n return WithStytch;\n};\n\nexport const withStytchUser = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & { stytchUser: User | null; stytchUserIsInitialized: boolean; stytchUserIsFromCache: boolean }\n >,\n): ComponentType<T> => {\n const WithStytchUser: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchUser'));\n const { user, isInitialized, fromCache } = useStytchUser<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchUser={user}\n stytchUserIsInitialized={isInitialized}\n stytchUserIsFromCache={fromCache}\n />\n );\n };\n WithStytchUser.displayName = `withStytchUser(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchUser;\n};\n\nexport const withStytchSession = <T extends object, TAssumeHydrated extends boolean = false>(\n Component: ComponentType<\n T & { stytchSession: Session | null; stytchSessionIsInitialized: boolean; stytchSessionIsFromCache: boolean }\n >,\n): ComponentType<T> => {\n const WithStytchSession: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchSession'));\n const { session, isInitialized, fromCache } = useStytchSession<TAssumeHydrated>();\n return (\n <Component\n {...props}\n stytchSession={session}\n stytchSessionIsInitialized={isInitialized}\n stytchSessionIsFromCache={fromCache}\n />\n );\n };\n WithStytchSession.displayName = `withStytchSession(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchSession;\n};\n\ntype SWRIsAuthorizedUninitialized = {\n /**\n * Whether the logged-in user is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: false;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: false;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: false;\n};\n\ntype SWRIsAuthorizedInitialized = {\n /**\n * Whether the logged-in user is allowed to perform the specified action on the specified resource.\n */\n isAuthorized: boolean;\n /**\n * If true, indicates that the value returned is from the application cache and a state refresh is in progress.\n */\n fromCache: boolean;\n /**\n * If true, indicates that the SDK has completed initialization.\n */\n isInitialized: boolean;\n};\n\ntype SWRIsAuthorized<TAlwaysInitialized extends boolean> = TAlwaysInitialized extends true\n ? SWRIsAuthorizedInitialized\n : SWRIsAuthorizedInitialized | SWRIsAuthorizedUninitialized;\n\n/**\n * Determines whether the logged-in user is allowed to perform the specified action on the specified resource.\n * Returns `true` if the user can perform the action, `false` otherwise.\n *\n * If the user is not logged in, this method will always return false.\n * If the resource or action provided are not valid for the configured RBAC policy, this method will return false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * const { isAuthorized } = useStytchIsAuthorized<Permissions>('documents', 'edit');\n * return <button disabled={!isAuthorized}>Edit</button>\n */\nexport const useStytchIsAuthorized = <TAssumeHydrated extends boolean = false>(\n resourceId: string,\n action: string,\n): SWRIsAuthorized<TAssumeHydrated> => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchIsAuthorized', 'StytchProvider'));\n const client = useStytch();\n const { user } = useStytchUser();\n const [isAuthorized, setIsAuthorized] = useAsyncState<SWRIsAuthorized<boolean>>({\n isInitialized: false,\n fromCache: false,\n isAuthorized: false,\n });\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n\n setIsAuthorized({\n isInitialized: true,\n fromCache: true,\n isAuthorized: client.rbac.isAuthorizedSync(resourceId, action),\n });\n }, [action, client, resourceId, setIsAuthorized]);\n\n useEffect(() => {\n if (isStytchSSRProxy(client)) {\n return;\n }\n client.rbac.isAuthorized(resourceId, action).then((isAuthorized) => {\n setIsAuthorized({ isAuthorized, fromCache: false, isInitialized: true });\n });\n }, [client, user?.roles, resourceId, action, setIsAuthorized]);\n\n return isAuthorized;\n};\n\ntype permissionsLoaded<Permissions extends Record<string, string>> =\n | {\n loaded: false;\n value: null;\n }\n | {\n loaded: true;\n value: PermissionsMap<Permissions>;\n };\n\n/**\n * Wrap your component with this HOC in order to receive the permissions for the logged-in user.\n * Evaluates all permissions granted to the logged-in user.\n * Returns a Record<RoleId, Record<Action, boolean>> response indicating the user's permissions.\n * Each boolean will be `true` if the user can perform the action, `false` otherwise.\n *\n * If the user is not logged in, all values will be false.\n *\n * Remember - authorization checks for sensitive actions should always occur on the backend as well.\n * @example\n * type Permissions = {\n * document: 'create' | 'read' | 'write\n * image: 'create' | 'read'\n * }\n *\n * const MyComponent = (props) => {\n * const canEditDocuments = props.stytchPermissions.document.edit;\n * const canReadImages = props.stytchPermissions.image.read;\n * }\n * return withStytchPermissions<Permissions>(MyComponent)\n */\nexport const withStytchPermissions = <Permissions extends Record<string, string>, T extends object>(\n Component: ComponentType<T & { stytchPermissions: PermissionsMap<Permissions> }>,\n): ComponentType<T> => {\n const WithStytchPermissions: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useRBACPermissions', 'StytchProvider'));\n const client = useStytch();\n const { user } = useStytchUser();\n const [permissions, setPermissions] = useAsyncState<permissionsLoaded<Permissions>>({ loaded: false, value: null });\n\n useEffect(() => {\n client.rbac.allPermissions<Permissions>().then((permissions) => {\n setPermissions({ loaded: true, value: permissions });\n });\n }, [client, user?.roles, setPermissions]);\n\n if (!permissions.loaded) {\n return null;\n }\n return <Component {...props} stytchPermissions={permissions.value} />;\n };\n WithStytchPermissions.displayName = `withStytchPermissions(${\n Component.displayName || Component.name || 'Component'\n })`;\n return WithStytchPermissions;\n};\n\nexport interface StytchProviderProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> {\n /**\n * A Stytch client instance, created using either {@link createStytchHeadlessClient} or {@link createStytchUIClient}\n */\n stytch: StytchClient<TProjectConfiguration>;\n /**\n * When true, the provider will assume that the component will only be\n * rendered in a browser environment, either in a single-page application or\n * after completing hydration of a server-rendered application. This allows\n * cached values to be retrieved from the browser on the first render, meaning\n * that the `isInitialized` value returned from Stytch hooks will be `true`\n * starting from the first render.\n *\n * When `false`, the provider will defer initialization until after the first\n * render, and `isInitialized` will initially be `false`.\n *\n * This value defaults to `false` in `@stytch/nextjs`.\n */\n assumeHydrated?: boolean;\n children?: ReactNode;\n}\n\n/**\n * The Stytch Context Provider.\n * Wrap your application with this component in order to use Stytch everywhere in your app.\n * @example\n * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchProvider stytch={stytch}>\n * <App />\n * </StytchProvider>\n * )\n */\nexport const StytchProvider = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n stytch,\n children,\n assumeHydrated = false,\n}: StytchProviderProps<TProjectConfiguration>): JSX.Element => {\n invariant(!useIsMounted__INTERNAL(), providerMustBeUniqueError);\n invariant(\n !assumeHydrated || typeof window !== 'undefined',\n 'The `assumeHydrated` prop must be set to `false` when using StytchProvider in a server environment.',\n );\n\n const ctx = useMemo(() => ({ client: stytch, isMounted: true }), [stytch]);\n\n type ClientState<TAlwaysInitialized extends boolean> = {\n session: SWRSession<TAlwaysInitialized>;\n user: SWRUser<TAlwaysInitialized>;\n };\n\n const getHydratedState = useCallback(() => {\n return {\n session: { ...stytch.session.getInfo(), isInitialized: true },\n user: { ...stytch.user.getInfo(), isInitialized: true },\n } satisfies ClientState<true>;\n }, [stytch]);\n\n const getInitialState = () => {\n return {\n session: initialSession,\n user: initialUser,\n } satisfies ClientState<false>;\n };\n\n const [{ user, session }, setClientState] = useAsyncState<ClientState<boolean>>(() =>\n assumeHydrated ? getHydratedState() : (getInitialState() as ClientState<boolean>),\n );\n\n // Store the initial value of `assumeHydrated` in a ref, because it is\n // logically only relevant for the first render\n const assumeHydratedRef = useRef(assumeHydrated);\n useEffect(() => {\n if (isStytchSSRProxy(stytch)) {\n return;\n }\n\n const updateState = () => {\n setClientState((oldState) => mergeWithStableProps(oldState, getHydratedState()));\n };\n\n if (!assumeHydratedRef.current) {\n updateState();\n }\n\n return stytch.onStateChange(updateState);\n }, [getHydratedState, setClientState, stytch]);\n\n return (\n <StytchContext.Provider value={ctx}>\n <StytchUserContext.Provider value={user}>\n <StytchSessionContext.Provider value={session}>{children}</StytchSessionContext.Provider>\n </StytchUserContext.Provider>\n </StytchContext.Provider>\n );\n};\n","import React, { useRef } from 'react';\nimport type {\n Callbacks,\n StringsOptions,\n StytchLoginConfig,\n StyleConfig,\n StytchProjectConfigurationInput,\n IDPConsentScreenManifest,\n} from '@stytch/vanilla-js';\n\nimport { useStytch, isUIClient, useIsMounted__INTERNAL, useStytchUser } from './StytchContext';\nimport { invariant } from './utils/invariant';\nimport { noHeadlessClientError, noProviderError } from './utils/errors';\nimport useIsomorphicLayoutEffect from './utils/useIsomorphicLayoutEffect';\n\nexport interface StytchProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> extends StringsOptions {\n /**\n * A {@link StytchLoginConfig} object. Add products and product-specific config to this object to change the login methods shown.\n *\n * @example\n * {\n * products: ['crypto', 'otps']\n * }\n *\n * @example\n * {\n * products: ['emailMagicLinks'>]\n * emailMagicLinksOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * }\n * }\n *\n * @example\n * {\n * products: ['oauth'>]\n * oauthOptions: {\n * providers: [\n * { type: 'google', one_tap: true, position: 'embedded' },\n * { type: 'microsoft' },\n * { type: 'apple' },\n * { type: 'facebook' },\n * ],\n * }\n * }\n */\n config: StytchLoginConfig;\n /**\n * An optional {@link StyleConfig} to customize the look and feel of the screen.\n *\n * @example\n * {\n * fontFamily: 'Arial, Helvetica, sans-serif',\n * width: '360px',\n * primaryColor: '#19303D',\n * }\n */\n styles?: StyleConfig;\n /**\n * An optional {@link Callbacks} object.\n *\n * @example\n * {\n * onError: ({message}) => {\n * console.error('Stytch login screen error', message)\n * }\n * }\n *\n * @example\n * {\n * onEvent: ({type, data}) => {\n * if(type === StytchEventType.CryptoWalletAuthenticate) {\n * console.log('Logged in with crypto wallet', data);\n * }\n * }\n * }\n */\n callbacks?: Callbacks<TProjectConfiguration>;\n}\n\n/**\n * The Stytch Login Screen component.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * <StytchLogin\n * config={{\n * products: ['emailMagicLinks', 'oauth'],\n * emailMagicLinksOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * },\n * oauthOptions: {\n * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],\n * },\n * }}\n * styles={{\n * fontFamily: '\"Helvetica New\", Helvetica, sans-serif',\n * primaryColor: '#0577CA',\n * width: '321px',\n * }}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const StytchLogin = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n config,\n styles,\n callbacks,\n strings,\n}: StytchProps<TProjectConfiguration>) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('<StytchLogin />'));\n const stytchClient = useStytch<TProjectConfiguration>();\n const containerEl = useRef<HTMLDivElement>(null);\n\n useIsomorphicLayoutEffect(() => {\n if (!isUIClient(stytchClient)) {\n throw Error(noHeadlessClientError);\n }\n\n if (!containerEl.current) {\n return;\n }\n\n if (!containerEl.current.id) {\n const randId = Math.floor(Math.random() * 1e6);\n containerEl.current.id = `stytch-magic-link-${randId}`;\n }\n\n stytchClient.mountLogin({\n config,\n callbacks,\n elementId: `#${containerEl.current.id}`,\n styles,\n strings,\n });\n }, [stytchClient, config, styles, callbacks, strings]);\n\n return <div ref={containerEl} />;\n};\n\nexport interface StytchResetPasswordProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> extends StytchProps<TProjectConfiguration> {\n /**\n * A Stytch password reset token.\n */\n passwordResetToken: string;\n}\n\nexport type IDPConsentScreenManifestGenerator = (input: {\n scopes: string[];\n clientName: string;\n}) => IDPConsentScreenManifest;\n\nexport type AuthTokenParams = {\n /**\n * The auth token to provide for attestation prior to running OAuth flow.\n */\n trustedAuthToken: string;\n /**\n * The profile ID of the token.\n */\n tokenProfileID: string;\n};\n\nexport type IdentityProviderProps = Omit<StytchProps, 'config'> & {\n /**\n * Optional {@link IDPConsentScreenManifestGenerator} to customize the consent screen.\n */\n getIDPConsentManifest?: IDPConsentScreenManifestGenerator;\n /**\n * Optional {@link AuthTokenParams} to provide a trusted auth token to provide for attestation prior to running OAuth flow.\n */\n authTokenParams?: AuthTokenParams;\n};\n\n/**\n * The Stytch Reset Password component.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * <StytchPasswordReset\n * config={{\n * products: ['emailMagicLinks', 'oauth'],\n * emailMagicLinksOptions: {\n * loginRedirectURL: 'https://example.com/authenticate',\n * signupRedirectURL: 'https://example.com/authenticate',\n * },\n * oauthOptions: {\n * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],\n * },\n * }}\n * passwordResetToken=\"PvC5UudZ7TPZbELt95yXAQ-8MeEUCRob8bUQ-g52fIJs\"\n * styles={{\n * fontFamily: '\"Helvetica New\", Helvetica, sans-serif',\n * primaryColor: '#0577CA',\n * width: '321px',\n * }}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const StytchPasswordReset = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n config,\n styles,\n callbacks,\n strings,\n passwordResetToken,\n}: StytchResetPasswordProps<TProjectConfiguration>) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('<StytchResetPassword />'));\n const stytchClient = useStytch<TProjectConfiguration>();\n const containerEl = useRef<HTMLDivElement>(null);\n\n useIsomorphicLayoutEffect(() => {\n if (!isUIClient(stytchClient)) {\n throw Error(noHeadlessClientError);\n }\n\n if (!containerEl.current) {\n return;\n }\n\n if (!containerEl.current.id) {\n const randId = Math.floor(Math.random() * 1e6);\n containerEl.current.id = `stytch-reset-password-${randId}`;\n }\n\n if (passwordResetToken) {\n stytchClient.mountResetPassword({\n config,\n callbacks,\n elementId: `#${containerEl.current.id}`,\n styles,\n strings,\n passwordResetToken,\n });\n }\n }, [stytchClient, config, styles, callbacks, strings, passwordResetToken]);\n\n return <div ref={containerEl} />;\n};\n\n/**\n * The Stytch Passkey Registration component.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * const styles = {\n * container: {\n * backgroundColor: '#e11e1e',\n * },\n * colors: {\n * primary: '#ff00f7',\n * secondary: '#5C727D',\n * },\n * }\n *\n * <StytchPasskeyRegistration\n * styles={styles}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const StytchPasskeyRegistration = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n config,\n styles,\n callbacks,\n strings,\n}: StytchProps<TProjectConfiguration>) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('<StytchPasskeyRegistration />'));\n const stytchClient = useStytch<TProjectConfiguration>();\n const user = useStytchUser();\n const containerEl = useRef<HTMLDivElement>(null);\n\n useIsomorphicLayoutEffect(() => {\n if (!isUIClient(stytchClient)) {\n throw Error(noHeadlessClientError);\n }\n\n if (!containerEl.current) {\n return;\n }\n\n if (!containerEl.current.id) {\n const randId = Math.floor(Math.random() * 1e6);\n containerEl.current.id = `stytch-passkey-registration-${randId}`;\n }\n\n stytchClient.mountPasskeyRegistration({\n config,\n callbacks,\n elementId: `#${containerEl.current.id}`,\n styles,\n strings,\n });\n }, [stytchClient, config, styles, callbacks, strings, user]);\n\n return <div ref={containerEl} />;\n};\n\n/**\n * The Stytch IDP component.\n * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.\n * Requires the user to be logged in.\n * This component can only be used with a Stytch UI Client\n * passed into the StytchProvider.\n *\n * See the {@link https://stytch.com/docs/sdks online reference}\n *\n * @example\n * const styles = {\n * container: {\n * backgroundColor: '#e11e1e',\n * },\n * colors: {\n * primary: '#ff00f7',\n * secondary: '#5C727D',\n * },\n * }\n *\n * <IdentityProvider\n * styles={styles}\n * callbacks={{\n * onEvent: (event) => console.log(event)\n * }}\n * />\n */\nexport const IdentityProvider = ({\n styles,\n callbacks,\n strings,\n getIDPConsentManifest,\n authTokenParams,\n}: IdentityProviderProps) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('<IdentityProvider />'));\n const stytchClient = useStytch();\n const user = useStytchUser();\n const containerEl = useRef<HTMLDivElement>(null);\n\n useIsomorphicLayoutEffect(() => {\n if (!isUIClient(stytchClient)) {\n throw Error(noHeadlessClientError);\n }\n\n if (!containerEl.current) {\n return;\n }\n\n if (!containerEl.current.id) {\n const randId = Math.floor(Math.random() * 1e6);\n containerEl.current.id = `stytch-idp-${randId}`;\n }\n\n stytchClient.mountIdentityProvider({\n callbacks,\n elementId: `#${containerEl.current.id}`,\n styles,\n strings,\n getIDPConsentManifest,\n authTokenParams,\n });\n }, [stytchClient, styles, callbacks, user, strings, getIDPConsentManifest, authTokenParams]);\n\n return <div ref={containerEl} />;\n};\n","import React, { ComponentType, ReactNode } from 'react';\n\nimport type { StytchProjectConfigurationInput, StytchUIClient } from '@stytch/vanilla-js';\nimport type { Session, StytchHeadlessClient, User } from '@stytch/vanilla-js/headless';\n\nexport { useStytch, withStytch } from '@stytch/internal-react-shared';\n\nimport {\n StytchProvider as StytchProviderShared,\n useStytchSession as useStytchSessionShared,\n useStytchUser as useStytchUserShared,\n withStytchSession as withStytchSessionShared,\n withStytchUser as withStytchUserShared,\n useStytchIsAuthorized as useStytchIsAuthorizedShared,\n withStytchPermissions as withStytchPermissionsShared,\n} from '@stytch/internal-react-shared';\n\n/**\n * Returns the active User.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the user data is from persistent storage.\n * @example\n * const {user, isInitialized, fromCache} = useStytchUser();\n * if (!isInitialized) {\n * return <p>Loading...</p>;\n * }\n * return (<h1>Welcome, {user.name.first_name}</h1>);\n */\nexport const useStytchUser = useStytchUserShared as <TAssumeHydrated extends boolean = true>() => ReturnType<\n typeof useStytchUserShared<TAssumeHydrated>\n>;\n\n/**\n * Returns the active user's Stytch session.\n * The Stytch SDKs are used for client-side authentication and session management.\n * Check the isInitialized property to determine if the SDK has completed initialization.\n * Check the fromCache property to determine if the session data is from persistent storage.\n * @example\n * const {session, isInitialized, fromCache} = useStytchSession();\n * useEffect(() => {\n * if (!isInitialized) {\n * return;\n * }\n * if (!session) {\n * router.replace('/login')\n * }\n * }, [session, isInitialized]);\n */\nexport const useStytchSession = useStytchSessionShared as <TAssumeHydrated extends boolean = true>() => ReturnType<\n typeof useStytchSessionShared<TAssumeHydrated>\n>;\n\nexport const withStytchUser = withStytchUserShared as <T extends object, TAssumeHydrated extends boolean = true>(\n Component: ComponentType<\n T & { stytchUser: User | null; stytchUserIsInitialized: boolean; stytchUserIsFromCache: boolean }\n >,\n) => ReturnType<typeof withStytchUserShared<T, TAssumeHydrated>>;\n\nexport const withStytchSession = withStytchSessionShared as <T extends object, TAssumeHydrated extends boolean = true>(\n Component: ComponentType<\n T & { stytchSession: Session | null; stytchSessionIsInitialized: boolean; stytchSessionIsFromCache: boolean }\n >,\n) => ReturnType<typeof withStytchSessionShared<T, TAssumeHydrated>>;\n\nexport const useStytchIsAuthorized = useStytchIsAuthorizedShared as <TAssumeHydrated extends boolean = true>(\n resourceId: string,\n action: string,\n) => ReturnType<typeof useStytchIsAuthorizedShared<TAssumeHydrated>>;\n\nexport const withStytchPermissions = withStytchPermissionsShared as <\n Permissions extends Record<string, string>,\n T extends object,\n>(\n Component: ComponentType<T & { stytchPermissions: Record<string, Record<string, boolean>> }>,\n) => ReturnType<typeof withStytchPermissionsShared<Permissions, T>>;\n\n/**\n * The Stytch Client object passed in to <StytchProvider /> in your application root.\n * Either a StytchUIClient or StytchHeadlessClient.\n */\ntype StytchClient<TProjectConfiguration extends StytchProjectConfigurationInput> =\n | StytchUIClient<TProjectConfiguration>\n | StytchHeadlessClient<TProjectConfiguration>;\n\nexport interface StytchProviderProps<\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n> {\n /**\n * A Stytch client instance, either a {@link StytchUIClient} or {@link StytchHeadlessClient}\n */\n stytch: StytchClient<TProjectConfiguration>;\n /**\n * When true, the provider will assume that the component will only be\n * rendered in a browser environment, either in a single-page application or\n * after completing hydration of a server-rendered application. This allows\n * cached values to be retrieved from the browser on the first render, meaning\n * that the `isInitialized` value returned from Stytch hooks will be `true`\n * starting from the first render.\n *\n * When `false`, the provider will defer initialization until after the first\n * render, and `isInitialized` will initially be `false`.\n *\n * If you encounter hydration errors relating to the use of this component,\n * set this to `false`.\n *\n * This value defaults to `true` in `@stytch/react`.\n */\n assumeHydrated?: boolean;\n children?: ReactNode;\n}\n\n/**\n * The Stytch Context Provider.\n * Wrap your application with this component in order to use Stytch everywhere in your app.\n * @example\n * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')\n *\n * ReactDOM.render(\n * <StytchProvider stytch={stytch}>\n * <App />\n * </StytchProvider>,\n * document.getElementById('root'),\n * )\n */\nexport const StytchProvider = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>({\n stytch,\n children,\n assumeHydrated = true,\n}: StytchProviderProps<TProjectConfiguration>): JSX.Element => {\n return (\n <StytchProviderShared stytch={stytch} assumeHydrated={assumeHydrated}>\n {children}\n </StytchProviderShared>\n );\n};\n"],"names":["createContext","useContext","useStytchUser","invariant","noProviderError","useStytchSession","React","withStytchUser","withStytchSession","useStytchIsAuthorized","useAsyncState","useEffect","isStytchSSRProxy","withStytchPermissions","StytchProvider","providerMustBeUniqueError","useMemo","useCallback","useRef","mergeWithStableProps","useIsomorphicLayoutEffect","noHeadlessClientError","useStytchUserShared","useStytchSessionShared","withStytchUserShared","withStytchSessionShared","useStytchIsAuthorizedShared","withStytchPermissionsShared","StytchProviderShared"],"mappings":";;;;;;;;;;;;;AAsEA,MAAM,WAAW,GAAyB;AACxC,IAAA,IAAI,EAAE,IAAI;AACV,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,aAAa,EAAE,KAAK;CACrB,CAAC;AAoCF,MAAM,cAAc,GAA4B;AAC9C,IAAA,OAAO,EAAE,IAAI;AACb,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,aAAa,EAAE,KAAK;CACrB,CAAC;AAEF,MAAM,aAAa,GAAGA,mBAAa,CAAiD,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1G,MAAM,iBAAiB,GAAGA,mBAAa,CAAU,WAAW,CAAC,CAAC;AAC9D,MAAM,oBAAoB,GAAGA,mBAAa,CAAa,cAAc,CAAC,CAAC;AAEhE,MAAM,sBAAsB,GAAG,MAAeC,gBAAU,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC;AAElF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ImC;AAE7D,MAAM,qBAAqB,GAAGC,wBAGgC;AAE9D,MAAM,qBAAqB,GAAGC,wBAK+B;AAqCpE;;;;;;;;;;;;AAYG;AACI,MAAM,cAAc,GAAG,CAE5B,EACA,MAAM,EACN,QAAQ,EACR,cAAc,GAAG,IAAI,GACsB,KAAiB;AAC5D,IAAA,QACErB,yBAAA,CAAA,aAAA,CAACsB,gBAAoB,EAAA,EAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,EAAA,EACjE,QAAQ,CACY,EACvB;AACJ;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -23,3 +23,4 @@ const createStytchUIClient = (...args) => {
23
23
  };
24
24
 
25
25
  export { createStytchUIClient };
26
+ //# sourceMappingURL=index.ui.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.ui.esm.js","sources":["../../../internal/react-shared/src/createStytchUIClient.ts"],"sourcesContent":["import { StytchProjectConfigurationInput, StytchUIClient } from '@stytch/vanilla-js';\nimport { createStytchSSRProxy } from './StytchSSRProxy';\n\n/**\n * Creates a Stytch UI client object to call the Stytch APIs and render Stytch UI components.\n * The Stytch client is not available serverside.\n * If you do not use Stytch UI components, use {@link createStytchHeadlessClient} to reduce your bundle size.\n * @example\n * const stytch = createStytchUIClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchProvider stytch={stytch}>\n * <App />\n * </StytchProvider>\n * )\n * @returns A {@link StytchUIClient}\n */\nexport const createStytchUIClient = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(\n ...args: ConstructorParameters<typeof StytchUIClient<TProjectConfiguration>>\n): StytchUIClient<TProjectConfiguration> => {\n if (typeof window === 'undefined') {\n return createStytchSSRProxy();\n }\n return new StytchUIClient<TProjectConfiguration>(...args);\n};\n"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;AAaG;MACU,oBAAoB,GAAG,CAGlC,GAAG,IAAyE,KACnC;AACzC,IAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,oBAAoB,EAAE,CAAC;KAC/B;AACD,IAAA,OAAO,IAAI,cAAc,CAAwB,GAAG,IAAI,CAAC,CAAC;AAC5D;;;;"}
package/dist/index.ui.js CHANGED
@@ -27,3 +27,4 @@ const createStytchUIClient = (...args) => {
27
27
  };
28
28
 
29
29
  exports.createStytchUIClient = createStytchUIClient;
30
+ //# sourceMappingURL=index.ui.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.ui.js","sources":["../../../internal/react-shared/src/createStytchUIClient.ts"],"sourcesContent":["import { StytchProjectConfigurationInput, StytchUIClient } from '@stytch/vanilla-js';\nimport { createStytchSSRProxy } from './StytchSSRProxy';\n\n/**\n * Creates a Stytch UI client object to call the Stytch APIs and render Stytch UI components.\n * The Stytch client is not available serverside.\n * If you do not use Stytch UI components, use {@link createStytchHeadlessClient} to reduce your bundle size.\n * @example\n * const stytch = createStytchUIClient('public-token-<find yours in the stytch dashboard>')\n *\n * return (\n * <StytchProvider stytch={stytch}>\n * <App />\n * </StytchProvider>\n * )\n * @returns A {@link StytchUIClient}\n */\nexport const createStytchUIClient = <\n TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration,\n>(\n ...args: ConstructorParameters<typeof StytchUIClient<TProjectConfiguration>>\n): StytchUIClient<TProjectConfiguration> => {\n if (typeof window === 'undefined') {\n return createStytchSSRProxy();\n }\n return new StytchUIClient<TProjectConfiguration>(...args);\n};\n"],"names":["createStytchSSRProxy","StytchUIClient"],"mappings":";;;;;;;AAGA;;;;;;;;;;;;;AAaG;MACU,oBAAoB,GAAG,CAGlC,GAAG,IAAyE,KACnC;AACzC,IAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAOA,mCAAoB,EAAE,CAAC;KAC/B;AACD,IAAA,OAAO,IAAIC,wBAAc,CAAwB,GAAG,IAAI,CAAC,CAAC;AAC5D;;;;"}
@@ -84,3 +84,4 @@ exports.invariant = invariant;
84
84
  exports.mergeWithStableProps = mergeWithStableProps;
85
85
  exports.useAsyncState = useAsyncState;
86
86
  exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
87
+ //# sourceMappingURL=useIsomorphicLayoutEffect-35a9b44b.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsomorphicLayoutEffect-35a9b44b.js","sources":["../../js-utils/src/createDeepEqual.ts","../../js-utils/src/mergeWithStableProps.ts","../../../internal/react-shared/src/utils/async.ts","../../../internal/react-shared/src/utils/invariant.ts","../../../internal/react-shared/src/utils/useIsomorphicLayoutEffect.ts"],"sourcesContent":["type DeepEqualOpts = {\n KEYS_TO_EXCLUDE?: string[];\n};\n\nexport const createDeepEqual = ({ KEYS_TO_EXCLUDE = [] }: DeepEqualOpts = {}) => {\n // If comparing functions, this may need some work. Not sure the\n // best path for this: compare instance (what it currently does),\n // stringify and compare, etc.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const deepEqual = (a: any, b: any): boolean => {\n // Ensures type is the same\n if (typeof a !== typeof b) return false;\n // arrays, null, and objects all have type 'object'\n if (a === null || b === null) return a === b;\n if (typeof a === 'object') {\n if (Object.keys(a).length !== Object.keys(b).length || Object.keys(a).some((k) => !(k in b))) return false;\n return Object.entries(a)\n .filter(([k]) => !KEYS_TO_EXCLUDE.includes(k))\n .every(([k, v]) => deepEqual(v, b[k]));\n }\n // boolean, string, number, undefined\n return a === b;\n };\n\n return deepEqual;\n};\n","import { createDeepEqual } from './createDeepEqual';\n\nconst deepEqual = createDeepEqual();\n\n/**\n * Returns a version of `newValue` whose properties that are deeply equal to\n * those in `oldValue` are replaced with those from `oldValue`. This provides a\n * limited form of \"structural sharing\" that provides a stable reference for\n * unchanged slices of the object.\n *\n * If `oldValue` and `newValue` are referentially equal, the same value is\n * returned.\n *\n * @param oldValue The old value\n * @param newValue The new value\n */\nexport const mergeWithStableProps = <T extends Record<string, unknown>, U extends Record<string, unknown> = T>(\n oldValue: U,\n newValue: T,\n): T => {\n // If the values are already referentially the same, just return the new value\n if ((oldValue as unknown) === newValue) {\n return newValue;\n }\n\n return Object.keys(oldValue).reduce(\n (acc, key) => {\n if (key in newValue && deepEqual(oldValue[key], newValue[key])) {\n acc[key as keyof T] = oldValue[key] as unknown as T[keyof T];\n }\n return acc;\n },\n { ...newValue },\n );\n};\n","import { Dispatch, SetStateAction, useCallback, useEffect, useRef, useState } from 'react';\n\n// useState can cause memory leaks if it is set after the component unmounted. For example, if it is\n// set after `await`, or in a `then`, `catch`, or `finally`, or in a setTimout/setInterval.\nexport const useAsyncState = <T>(initialState: T | (() => T)): [T, Dispatch<SetStateAction<T>>] => {\n const isMounted = useRef<boolean>(true);\n const [state, setState] = useState<T>(initialState);\n\n useEffect(() => {\n isMounted.current = true;\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n const setStateAction = useCallback<Dispatch<SetStateAction<T>>>((newState) => {\n if (isMounted.current) {\n setState(newState);\n }\n }, []);\n\n return [state, setStateAction];\n};\n","export function invariant(cond: unknown, message: string): asserts cond {\n if (!cond) throw new Error(message);\n}\n","import { useLayoutEffect, useEffect } from 'react';\n// cc https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\nexport default useIsomorphicLayoutEffect;\n"],"names":["useRef","useState","useEffect","useCallback","useLayoutEffect"],"mappings":";;;;AAIO,MAAM,eAAe,GAAG,CAAC,EAAE,eAAe,GAAG,EAAE,EAAA,GAAoB,EAAE,KAAI;;;;;AAK9E,IAAA,MAAM,SAAS,GAAG,CAAC,CAAM,EAAE,CAAM,KAAa;;AAE5C,QAAA,IAAI,OAAO,CAAC,KAAK,OAAO,CAAC;AAAE,YAAA,OAAO,KAAK,CAAC;;AAExC,QAAA,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI;YAAE,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7C,QAAA,I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AAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACI,QAAQ,CAAA,CACd,CAAC;AACJ;;AChCA;AACA;AACa,MAAA,aAAa,GAAG,CAAI,YAA2B,KAAsC;AAChG,IAAA,MAAM,SAAS,GAAGA,YAAM,CAAU,IAAI,CAAC,CAAC;IACxC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGC,cAAQ,CAAI,YAAY,CAAC,CAAC;IAEpDC,eAAS,CAAC,MAAK;AACb,QAAA,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC;AACzB,QAAA,OAAO,MAAK;AACV,YAAA,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC;AAC5B,SAAC,CAAC;KACH,EAAE,EAAE,CAAC,CAAC;AAEP,IAAA,MAAM,cAAc,GAAGC,iBAAW,CAA8B,CAAC,QAAQ,KAAI;AAC3E,QAAA,IAAI,SAAS,CAAC,OAAO,EAAE;YACrB,QAAQ,CAAC,QAAQ,CAAC,CAAC;SACpB;KACF,EAAE,EAAE,CAAC,CAAC;AAEP,IAAA,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;AACjC;;ACtBgB,SAAA,SAAS,CAAC,IAAa,EAAE,OAAe,EAAA;AACtD,IAAA,IAAI,CAAC,IAAI;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AACtC;;ACDA;AACA,MAAM,yBAAyB,GAAG,OAAO,MAAM,KAAK,WAAW,GAAGC,qBAAe,GAAGF;;;;;;;"}
@@ -79,3 +79,4 @@ function invariant(cond, message) {
79
79
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
80
80
 
81
81
  export { useIsomorphicLayoutEffect as a, invariant as i, mergeWithStableProps as m, useAsyncState as u };
82
+ //# sourceMappingURL=useIsomorphicLayoutEffect-3bc90e37.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsomorphicLayoutEffect-3bc90e37.js","sources":["../../js-utils/src/createDeepEqual.ts","../../js-utils/src/mergeWithStableProps.ts","../../../internal/react-shared/src/utils/async.ts","../../../internal/react-shared/src/utils/invariant.ts","../../../internal/react-shared/src/utils/useIsomorphicLayoutEffect.ts"],"sourcesContent":["type DeepEqualOpts = {\n KEYS_TO_EXCLUDE?: string[];\n};\n\nexport const createDeepEqual = ({ KEYS_TO_EXCLUDE = [] }: DeepEqualOpts = {}) => {\n // If comparing functions, this may need some work. Not sure the\n // best path for this: compare instance (what it currently does),\n // stringify and compare, etc.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const deepEqual = (a: any, b: any): boolean => {\n // Ensures type is the same\n if (typeof a !== typeof b) return false;\n // arrays, null, and objects all have type 'object'\n if (a === null || b === null) return a === b;\n if (typeof a === 'object') {\n if (Object.keys(a).length !== Object.keys(b).length || Object.keys(a).some((k) => !(k in b))) return false;\n return Object.entries(a)\n .filter(([k]) => !KEYS_TO_EXCLUDE.includes(k))\n .every(([k, v]) => deepEqual(v, b[k]));\n }\n // boolean, string, number, undefined\n return a === b;\n };\n\n return deepEqual;\n};\n","import { createDeepEqual } from './createDeepEqual';\n\nconst deepEqual = createDeepEqual();\n\n/**\n * Returns a version of `newValue` whose properties that are deeply equal to\n * those in `oldValue` are replaced with those from `oldValue`. This provides a\n * limited form of \"structural sharing\" that provides a stable reference for\n * unchanged slices of the object.\n *\n * If `oldValue` and `newValue` are referentially equal, the same value is\n * returned.\n *\n * @param oldValue The old value\n * @param newValue The new value\n */\nexport const mergeWithStableProps = <T extends Record<string, unknown>, U extends Record<string, unknown> = T>(\n oldValue: U,\n newValue: T,\n): T => {\n // If the values are already referentially the same, just return the new value\n if ((oldValue as unknown) === newValue) {\n return newValue;\n }\n\n return Object.keys(oldValue).reduce(\n (acc, key) => {\n if (key in newValue && deepEqual(oldValue[key], newValue[key])) {\n acc[key as keyof T] = oldValue[key] as unknown as T[keyof T];\n }\n return acc;\n },\n { ...newValue },\n );\n};\n","import { Dispatch, SetStateAction, useCallback, useEffect, useRef, useState } from 'react';\n\n// useState can cause memory leaks if it is set after the component unmounted. For example, if it is\n// set after `await`, or in a `then`, `catch`, or `finally`, or in a setTimout/setInterval.\nexport const useAsyncState = <T>(initialState: T | (() => T)): [T, Dispatch<SetStateAction<T>>] => {\n const isMounted = useRef<boolean>(true);\n const [state, setState] = useState<T>(initialState);\n\n useEffect(() => {\n isMounted.current = true;\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n const setStateAction = useCallback<Dispatch<SetStateAction<T>>>((newState) => {\n if (isMounted.current) {\n setState(newState);\n }\n }, []);\n\n return [state, setStateAction];\n};\n","export function invariant(cond: unknown, message: string): asserts cond {\n if (!cond) throw new Error(message);\n}\n","import { useLayoutEffect, useEffect } from 'react';\n// cc https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\nexport default useIsomorphicLayoutEffect;\n"],"names":[],"mappings":";;AAIO,MAAM,eAAe,GAAG,CAAC,EAAE,eAAe,GAAG,EAAE,EAAA,GAAoB,EAAE,KAAI;;;;;AAK9E,IAAA,MAAM,SAAS,GAAG,CAAC,CAAM,EAAE,CAAM,KAAa;;AAE5C,QAAA,IAAI,OAAO,CAAC,KAAK,OAAO,CAAC;AAAE,YAAA,OAAO,KAAK,CAAC;;AAExC,QAAA,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI;YAAE,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7C,QAAA,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;AACzB,YAAA,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AAAE,gBAAA,OAAO,KAAK,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QAAA,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC;AACzB,QAAA,OAAO,MAAK;AACV,YAAA,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC;AAC5B,SAAC,CAAC;KACH,EAAE,EAAE,CAAC,CAAC;AAEP,IAAA,MAAM,cAAc,GAAG,WAAW,CAA8B,CAAC,QAAQ,KAAI;AAC3E,QAAA,IAAI,SAAS,CAAC,OAAO,EAAE;YACrB,QAAQ,CAAC,QAAQ,CAAC,CAAC;SACpB;KACF,EAAE,EAAE,CAAC,CAAC;AAEP,IAAA,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;AACjC;;ACtBgB,SAAA,SAAS,CAAC,IAAa,EAAE,OAAe,EAAA;AACtD,IAAA,IAAI,CAAC,IAAI;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AACtC;;ACDA;AACA,MAAM,yBAAyB,GAAG,OAAO,MAAM,KAAK,WAAW,GAAG,eAAe,GAAG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stytch/react",
3
- "version": "19.14.0",
3
+ "version": "19.15.0",
4
4
  "description": "Stytch's official React Library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -41,7 +41,7 @@
41
41
  "@stytch/internal-tsconfigs": "0.0.0",
42
42
  "@stytch/jest-environment": "0.0.0",
43
43
  "@stytch/js-utils": "0.0.1",
44
- "@stytch/vanilla-js": "5.39.0",
44
+ "@stytch/vanilla-js": "5.40.0",
45
45
  "@testing-library/react": "14.0.0",
46
46
  "@types/jest": "29.5.14",
47
47
  "@types/react": "18.3.26",