@stytch/react 19.4.4 → 19.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +7 -7
  3. package/b2b/headless/package.json +6 -0
  4. package/b2b/ui/package.json +6 -0
  5. package/dist/{StytchB2BContext-09d376ba.d.ts → StytchB2BContext-9c062712.d.ts} +127 -23
  6. package/dist/{StytchB2BContext-09d376ba.js → StytchB2BContext-9c062712.js} +85 -42
  7. package/dist/{StytchB2BContext-a8d57249.d.ts → StytchB2BContext-c5062f9b.d.ts} +127 -23
  8. package/dist/{StytchB2BContext-a8d57249.js → StytchB2BContext-c5062f9b.js} +95 -52
  9. package/dist/StytchSSRProxy-34c789b5.d.ts +3 -0
  10. package/dist/StytchSSRProxy-34c789b5.js +48 -0
  11. package/dist/StytchSSRProxy-86bc42b3.d.ts +3 -0
  12. package/dist/StytchSSRProxy-86bc42b3.js +54 -0
  13. package/dist/adminPortal/index.d.ts +1 -1
  14. package/dist/adminPortal/index.esm.d.ts +1 -1
  15. package/dist/adminPortal/index.esm.js +5 -4
  16. package/dist/adminPortal/index.js +5 -4
  17. package/dist/b2b/index.d.ts +170 -6
  18. package/dist/b2b/index.esm.d.ts +170 -6
  19. package/dist/b2b/index.esm.js +85 -8
  20. package/dist/b2b/index.headless.d.ts +16 -0
  21. package/dist/b2b/index.headless.esm.d.ts +16 -0
  22. package/dist/b2b/index.headless.esm.js +24 -0
  23. package/dist/b2b/index.headless.js +28 -0
  24. package/dist/b2b/index.js +93 -16
  25. package/dist/b2b/index.ui.d.ts +17 -0
  26. package/dist/b2b/index.ui.esm.d.ts +17 -0
  27. package/dist/b2b/index.ui.esm.js +25 -0
  28. package/dist/b2b/index.ui.js +29 -0
  29. package/dist/errors-d9d5fbc8.d.ts +5 -0
  30. package/dist/index-b14d4efe.d.ts +1 -1
  31. package/dist/index.d.ts +92 -54
  32. package/dist/index.esm.d.ts +92 -54
  33. package/dist/index.esm.js +112 -38
  34. package/dist/index.headless.d.ts +16 -0
  35. package/dist/index.headless.esm.d.ts +16 -0
  36. package/dist/index.headless.esm.js +24 -0
  37. package/dist/index.headless.js +28 -0
  38. package/dist/index.js +126 -52
  39. package/dist/index.ui.d.ts +17 -0
  40. package/dist/index.ui.esm.d.ts +17 -0
  41. package/dist/index.ui.esm.js +25 -0
  42. package/dist/index.ui.js +29 -0
  43. package/dist/useIsomorphicLayoutEffect-1babb81e.d.ts +24 -0
  44. package/dist/{invariant-568a7633.js → useIsomorphicLayoutEffect-1babb81e.js} +5 -13
  45. package/dist/useIsomorphicLayoutEffect-65746ef3.d.ts +24 -0
  46. package/dist/{invariant-ae5a5bce.js → useIsomorphicLayoutEffect-65746ef3.js} +4 -16
  47. package/package.json +4 -3
  48. package/dist/invariant-568a7633.d.ts +0 -27
  49. package/dist/invariant-ae5a5bce.d.ts +0 -27
@@ -0,0 +1,17 @@
1
+ import { StytchUIClient } from "@stytch/vanilla-js";
2
+ /**
3
+ * Creates a Stytch UI client object to call the Stytch APIs and render Stytch UI components.
4
+ * The Stytch client is not available serverside.
5
+ * If you do not use Stytch UI components, use {@link createStytchHeadlessClient} to reduce your bundle size.
6
+ * @example
7
+ * const stytch = createStytchUIClient('public-token-<find yours in the stytch dashboard>')
8
+ *
9
+ * return (
10
+ * <StytchProvider stytch={stytch}>
11
+ * <App />
12
+ * </StytchProvider>
13
+ * )
14
+ * @returns A {@link StytchUIClient}
15
+ */
16
+ declare const createStytchUIClient: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>(_PUBLIC_TOKEN: string, options?: import("@stytch/core/public").StytchClientOptions | undefined) => StytchUIClient<TProjectConfiguration>;
17
+ export { createStytchUIClient };
@@ -0,0 +1,25 @@
1
+ import { StytchUIClient } from '@stytch/vanilla-js';
2
+ import { c as createStytchSSRProxy } from './StytchSSRProxy-34c789b5.js';
3
+
4
+ /**
5
+ * Creates a Stytch UI client object to call the Stytch APIs and render Stytch UI components.
6
+ * The Stytch client is not available serverside.
7
+ * If you do not use Stytch UI components, use {@link createStytchHeadlessClient} to reduce your bundle size.
8
+ * @example
9
+ * const stytch = createStytchUIClient('public-token-<find yours in the stytch dashboard>')
10
+ *
11
+ * return (
12
+ * <StytchProvider stytch={stytch}>
13
+ * <App />
14
+ * </StytchProvider>
15
+ * )
16
+ * @returns A {@link StytchUIClient}
17
+ */
18
+ const createStytchUIClient = (...args) => {
19
+ if (typeof window === 'undefined') {
20
+ return createStytchSSRProxy();
21
+ }
22
+ return new StytchUIClient(...args);
23
+ };
24
+
25
+ export { createStytchUIClient };
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var vanillaJs = require('@stytch/vanilla-js');
6
+ var StytchSSRProxy = require('./StytchSSRProxy-86bc42b3.js');
7
+
8
+ /**
9
+ * Creates a Stytch UI client object to call the Stytch APIs and render Stytch UI components.
10
+ * The Stytch client is not available serverside.
11
+ * If you do not use Stytch UI components, use {@link createStytchHeadlessClient} to reduce your bundle size.
12
+ * @example
13
+ * const stytch = createStytchUIClient('public-token-<find yours in the stytch dashboard>')
14
+ *
15
+ * return (
16
+ * <StytchProvider stytch={stytch}>
17
+ * <App />
18
+ * </StytchProvider>
19
+ * )
20
+ * @returns A {@link StytchUIClient}
21
+ */
22
+ const createStytchUIClient = (...args) => {
23
+ if (typeof window === 'undefined') {
24
+ return StytchSSRProxy.createStytchSSRProxy();
25
+ }
26
+ return new vanillaJs.StytchUIClient(...args);
27
+ };
28
+
29
+ exports.createStytchUIClient = createStytchUIClient;
@@ -0,0 +1,24 @@
1
+ import { Dispatch, SetStateAction, useEffect } from "react";
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ declare function invariant(cond: any, message: string): asserts cond;
4
+ // useState can cause memory leaks if it is set after the component unmounted. For example, if it is
5
+ // set after `await`, or in a `then`, `catch`, or `finally`, or in a setTimout/setInterval.
6
+ declare const useAsyncState: <T>(initialState: T | (() => T)) => [
7
+ T,
8
+ Dispatch<SetStateAction<T>>
9
+ ];
10
+ /**
11
+ * Returns a version of `newValue` whose properties that are deeply equal to
12
+ * those in `oldValue` are replaced with those from `oldValue`. This provides a
13
+ * limited form of "structural sharing" that provides a stable reference for
14
+ * unchanged slices of the object.
15
+ *
16
+ * If `oldValue` and `newValue` are referentially equal, the same value is
17
+ * returned.
18
+ *
19
+ * @param oldValue The old value
20
+ * @param newValue The new value
21
+ */
22
+ declare const mergeWithStableProps: <T extends Record<string, unknown>, U extends Record<string, unknown> = T>(oldValue: U, newValue: T) => T;
23
+ declare const useIsomorphicLayoutEffect: typeof useEffect;
24
+ export { useIsomorphicLayoutEffect as default, invariant, useAsyncState, mergeWithStableProps };
@@ -1,4 +1,4 @@
1
- import { useRef, useState, useEffect, useCallback } from 'react';
1
+ import { useRef, useState, useEffect, useCallback, useLayoutEffect } from 'react';
2
2
 
3
3
  const createDeepEqual = ({ KEYS_TO_EXCLUDE = [] } = {}) => {
4
4
  // If comparing functions, this may need some work. Not sure the
@@ -68,21 +68,13 @@ const useAsyncState = (initialState) => {
68
68
  return [state, setStateAction];
69
69
  };
70
70
 
71
- const noProviderError = (item, provider = 'StytchProvider') => `${item} can only be used inside <${provider}>.`;
72
- const providerMustBeUniqueError = 'You cannot render a <StytchProvider> inside another <StytchProvider>.';
73
- const B2BProviderMustBeUniqueError = 'You cannot render a <StytchB2BProvider> inside another <StytchB2BProvider>.';
74
- const noSSRError = `The @stytch/react library is not meant for use with serverside environments like NextJS.
75
- Use the @stytch/nextjs library instead -
76
- npm remove @stytch/react && npm install @stytch/nextjs
77
- `;
78
- const noHeadlessClientError = `Tried to create a Stytch Login UI element using the Stytch Headless SDK.
79
- You must use the UI SDK to use UI elements.
80
- Please make sure you are importing from @stytch/vanilla-js and not from the @stytch/vanilla-js/headless.`;
81
-
82
71
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
83
72
  function invariant(cond, message) {
84
73
  if (!cond)
85
74
  throw new Error(message);
86
75
  }
87
76
 
88
- export { B2BProviderMustBeUniqueError as B, noSSRError as a, noHeadlessClientError as b, invariant as i, mergeWithStableProps as m, noProviderError as n, providerMustBeUniqueError as p, useAsyncState as u };
77
+ // cc https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a
78
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
79
+
80
+ export { useIsomorphicLayoutEffect as a, invariant as i, mergeWithStableProps as m, useAsyncState as u };
@@ -0,0 +1,24 @@
1
+ import { Dispatch, SetStateAction, useEffect } from "react";
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ declare function invariant(cond: any, message: string): asserts cond;
4
+ // useState can cause memory leaks if it is set after the component unmounted. For example, if it is
5
+ // set after `await`, or in a `then`, `catch`, or `finally`, or in a setTimout/setInterval.
6
+ declare const useAsyncState: <T>(initialState: T | (() => T)) => [
7
+ T,
8
+ Dispatch<SetStateAction<T>>
9
+ ];
10
+ /**
11
+ * Returns a version of `newValue` whose properties that are deeply equal to
12
+ * those in `oldValue` are replaced with those from `oldValue`. This provides a
13
+ * limited form of "structural sharing" that provides a stable reference for
14
+ * unchanged slices of the object.
15
+ *
16
+ * If `oldValue` and `newValue` are referentially equal, the same value is
17
+ * returned.
18
+ *
19
+ * @param oldValue The old value
20
+ * @param newValue The new value
21
+ */
22
+ declare const mergeWithStableProps: <T extends Record<string, unknown>, U extends Record<string, unknown> = T>(oldValue: U, newValue: T) => T;
23
+ declare const useIsomorphicLayoutEffect: typeof useEffect;
24
+ export { useIsomorphicLayoutEffect as default, invariant, useAsyncState, mergeWithStableProps };
@@ -70,28 +70,16 @@ const useAsyncState = (initialState) => {
70
70
  return [state, setStateAction];
71
71
  };
72
72
 
73
- const noProviderError = (item, provider = 'StytchProvider') => `${item} can only be used inside <${provider}>.`;
74
- const providerMustBeUniqueError = 'You cannot render a <StytchProvider> inside another <StytchProvider>.';
75
- const B2BProviderMustBeUniqueError = 'You cannot render a <StytchB2BProvider> inside another <StytchB2BProvider>.';
76
- const noSSRError = `The @stytch/react library is not meant for use with serverside environments like NextJS.
77
- Use the @stytch/nextjs library instead -
78
- npm remove @stytch/react && npm install @stytch/nextjs
79
- `;
80
- const noHeadlessClientError = `Tried to create a Stytch Login UI element using the Stytch Headless SDK.
81
- You must use the UI SDK to use UI elements.
82
- Please make sure you are importing from @stytch/vanilla-js and not from the @stytch/vanilla-js/headless.`;
83
-
84
73
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
74
  function invariant(cond, message) {
86
75
  if (!cond)
87
76
  throw new Error(message);
88
77
  }
89
78
 
90
- exports.B2BProviderMustBeUniqueError = B2BProviderMustBeUniqueError;
79
+ // cc https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a
80
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
81
+
91
82
  exports.invariant = invariant;
92
83
  exports.mergeWithStableProps = mergeWithStableProps;
93
- exports.noHeadlessClientError = noHeadlessClientError;
94
- exports.noProviderError = noProviderError;
95
- exports.noSSRError = noSSRError;
96
- exports.providerMustBeUniqueError = providerMustBeUniqueError;
97
84
  exports.useAsyncState = useAsyncState;
85
+ exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stytch/react",
3
- "version": "19.4.4",
3
+ "version": "19.5.0",
4
4
  "description": "Stytch's official React Library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -32,11 +32,12 @@
32
32
  "user"
33
33
  ],
34
34
  "devDependencies": {
35
- "@babel/runtime": "7.26.10",
35
+ "@babel/runtime": "7.27.0",
36
+ "@stytch/internal-react-shared": "0.0.0",
36
37
  "@stytch/internal-test-utils": "0.0.0",
37
38
  "@stytch/internal-tsconfigs": "0.0.0",
38
39
  "@stytch/js-utils": "0.0.1",
39
- "@stytch/vanilla-js": "5.22.3",
40
+ "@stytch/vanilla-js": "5.22.7",
40
41
  "@testing-library/react": "14.0.0",
41
42
  "@types/jest": "29.5.14",
42
43
  "eslint-config-custom": "0.0.1",
@@ -1,27 +0,0 @@
1
- import { Dispatch, SetStateAction } from "react";
2
- declare const noProviderError: (item: string, provider?: string) => string;
3
- declare const providerMustBeUniqueError = "You cannot render a <StytchProvider> inside another <StytchProvider>.";
4
- declare const B2BProviderMustBeUniqueError = "You cannot render a <StytchB2BProvider> inside another <StytchB2BProvider>.";
5
- declare const noSSRError = "The @stytch/react library is not meant for use with serverside environments like NextJS.\nUse the @stytch/nextjs library instead - \nnpm remove @stytch/react && npm install @stytch/nextjs\n";
6
- declare 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 importing from @stytch/vanilla-js and not from the @stytch/vanilla-js/headless.";
7
- // useState can cause memory leaks if it is set after the component unmounted. For example, if it is
8
- // set after `await`, or in a `then`, `catch`, or `finally`, or in a setTimout/setInterval.
9
- declare const useAsyncState: <T>(initialState: T | (() => T)) => [
10
- T,
11
- Dispatch<SetStateAction<T>>
12
- ];
13
- /**
14
- * Returns a version of `newValue` whose properties that are deeply equal to
15
- * those in `oldValue` are replaced with those from `oldValue`. This provides a
16
- * limited form of "structural sharing" that provides a stable reference for
17
- * unchanged slices of the object.
18
- *
19
- * If `oldValue` and `newValue` are referentially equal, the same value is
20
- * returned.
21
- *
22
- * @param oldValue The old value
23
- * @param newValue The new value
24
- */
25
- declare const mergeWithStableProps: <T extends Record<string, unknown>, U extends Record<string, unknown> = T>(oldValue: U, newValue: T) => T;
26
- declare function invariant(cond: any, message: string): asserts cond;
27
- export { noProviderError, providerMustBeUniqueError, B2BProviderMustBeUniqueError, noSSRError, noHeadlessClientError, useAsyncState, mergeWithStableProps, invariant };
@@ -1,27 +0,0 @@
1
- import { Dispatch, SetStateAction } from "react";
2
- declare const noProviderError: (item: string, provider?: string) => string;
3
- declare const providerMustBeUniqueError = "You cannot render a <StytchProvider> inside another <StytchProvider>.";
4
- declare const B2BProviderMustBeUniqueError = "You cannot render a <StytchB2BProvider> inside another <StytchB2BProvider>.";
5
- declare const noSSRError = "The @stytch/react library is not meant for use with serverside environments like NextJS.\nUse the @stytch/nextjs library instead - \nnpm remove @stytch/react && npm install @stytch/nextjs\n";
6
- declare 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 importing from @stytch/vanilla-js and not from the @stytch/vanilla-js/headless.";
7
- // useState can cause memory leaks if it is set after the component unmounted. For example, if it is
8
- // set after `await`, or in a `then`, `catch`, or `finally`, or in a setTimout/setInterval.
9
- declare const useAsyncState: <T>(initialState: T | (() => T)) => [
10
- T,
11
- Dispatch<SetStateAction<T>>
12
- ];
13
- /**
14
- * Returns a version of `newValue` whose properties that are deeply equal to
15
- * those in `oldValue` are replaced with those from `oldValue`. This provides a
16
- * limited form of "structural sharing" that provides a stable reference for
17
- * unchanged slices of the object.
18
- *
19
- * If `oldValue` and `newValue` are referentially equal, the same value is
20
- * returned.
21
- *
22
- * @param oldValue The old value
23
- * @param newValue The new value
24
- */
25
- declare const mergeWithStableProps: <T extends Record<string, unknown>, U extends Record<string, unknown> = T>(oldValue: U, newValue: T) => T;
26
- declare function invariant(cond: any, message: string): asserts cond;
27
- export { noProviderError, providerMustBeUniqueError, B2BProviderMustBeUniqueError, noSSRError, noHeadlessClientError, useAsyncState, mergeWithStableProps, invariant };