@stytch/nextjs 13.0.0 → 15.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/b2b/index.d.ts +251 -3
  3. package/dist/b2b/index.esm.d.ts +46 -3
  4. package/dist/b2b/index.esm.js +84 -3
  5. package/dist/b2b/index.headless.d.ts +16 -1
  6. package/dist/b2b/index.headless.esm.js +845 -375
  7. package/dist/b2b/index.headless.js +4591 -17
  8. package/dist/b2b/index.js +333 -14
  9. package/dist/b2b/index.ui.d.ts +17 -1
  10. package/dist/b2b/index.ui.js +64 -16
  11. package/dist/index.d.ts +275 -3
  12. package/dist/index.headless.d.ts +16 -1
  13. package/dist/index.headless.js +63 -16
  14. package/dist/index.js +374 -16
  15. package/dist/index.ui.d.ts +17 -1
  16. package/dist/index.ui.js +64 -16
  17. package/package.json +3 -3
  18. package/dist/Stytch.d.ts +0 -172
  19. package/dist/Stytch.js +0 -214
  20. package/dist/Stytch.js.map +0 -1
  21. package/dist/Stytch.spec.d.ts +0 -1
  22. package/dist/Stytch.spec.js +0 -130
  23. package/dist/Stytch.spec.js.map +0 -1
  24. package/dist/StytchContext.d.ts +0 -104
  25. package/dist/StytchContext.js +0 -180
  26. package/dist/StytchContext.js.map +0 -1
  27. package/dist/StytchContext.serverside.spec.d.ts +0 -4
  28. package/dist/StytchContext.serverside.spec.js +0 -51
  29. package/dist/StytchContext.serverside.spec.js.map +0 -1
  30. package/dist/StytchContext.spec.d.ts +0 -1
  31. package/dist/StytchContext.spec.js +0 -212
  32. package/dist/StytchContext.spec.js.map +0 -1
  33. package/dist/StytchSSRProxy.d.ts +0 -2
  34. package/dist/StytchSSRProxy.js +0 -29
  35. package/dist/StytchSSRProxy.js.map +0 -1
  36. package/dist/StytchSSRProxy.spec.d.ts +0 -1
  37. package/dist/StytchSSRProxy.spec.js +0 -16
  38. package/dist/StytchSSRProxy.spec.js.map +0 -1
  39. package/dist/b2b/Stytch.d.ts +0 -104
  40. package/dist/b2b/Stytch.js +0 -90
  41. package/dist/b2b/Stytch.js.map +0 -1
  42. package/dist/b2b/StytchB2BContext.d.ts +0 -104
  43. package/dist/b2b/StytchB2BContext.js +0 -179
  44. package/dist/b2b/StytchB2BContext.js.map +0 -1
  45. package/dist/b2b/StytchB2BContext.spec.d.ts +0 -1
  46. package/dist/b2b/StytchB2BContext.spec.js +0 -217
  47. package/dist/b2b/StytchB2BContext.spec.js.map +0 -1
  48. package/dist/b2b/createStytchB2BHeadlessClient.d.ts +0 -15
  49. package/dist/b2b/createStytchB2BHeadlessClient.js +0 -26
  50. package/dist/b2b/createStytchB2BHeadlessClient.js.map +0 -1
  51. package/dist/b2b/createStytchB2BUIClient.d.ts +0 -16
  52. package/dist/b2b/createStytchB2BUIClient.js +0 -27
  53. package/dist/b2b/createStytchB2BUIClient.js.map +0 -1
  54. package/dist/b2b/index.headless.js.map +0 -1
  55. package/dist/b2b/index.js.map +0 -1
  56. package/dist/b2b/index.ui.js.map +0 -1
  57. package/dist/createStytchHeadlessClient.d.ts +0 -15
  58. package/dist/createStytchHeadlessClient.js +0 -26
  59. package/dist/createStytchHeadlessClient.js.map +0 -1
  60. package/dist/createStytchUIClient.d.ts +0 -16
  61. package/dist/createStytchUIClient.js +0 -27
  62. package/dist/createStytchUIClient.js.map +0 -1
  63. package/dist/index.headless.js.map +0 -1
  64. package/dist/index.js.map +0 -1
  65. package/dist/index.ui.js.map +0 -1
  66. package/dist/utils/async.d.ts +0 -2
  67. package/dist/utils/async.js +0 -22
  68. package/dist/utils/async.js.map +0 -1
  69. package/dist/utils/errors.d.ts +0 -3
  70. package/dist/utils/errors.js +0 -28
  71. package/dist/utils/errors.js.map +0 -1
  72. package/dist/utils/invariant.d.ts +0 -1
  73. package/dist/utils/invariant.js +0 -10
  74. package/dist/utils/invariant.js.map +0 -1
  75. package/dist/utils/useIsomorphicLayoutEffect.d.ts +0 -3
  76. package/dist/utils/useIsomorphicLayoutEffect.js +0 -7
  77. package/dist/utils/useIsomorphicLayoutEffect.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,3 +1,275 @@
1
- export { StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser, } from './StytchContext';
2
- export { StytchLogin, StytchPasswordReset, StytchPasskeyRegistration } from './Stytch';
3
- export type { StytchProviderProps } from './StytchContext';
1
+ /// <reference types="react" />
2
+ import React from "react";
3
+ import { ReactNode } from "react";
4
+ import { User, Session, StytchUIClient, Callbacks, StytchLoginConfig, StyleConfig } from "@stytch/vanilla-js";
5
+ import { StytchHeadlessClient } from "@stytch/vanilla-js/headless";
6
+ /**
7
+ * The Stytch Client object passed in to <StytchProvider /> in your `_app.js`.
8
+ * Either a StytchUIClient or StytchHeadlessClient.
9
+ */
10
+ type StytchClient = StytchUIClient | StytchHeadlessClient;
11
+ type SWRUser = {
12
+ user: null;
13
+ fromCache: false;
14
+ isInitialized: false;
15
+ } | {
16
+ user: User | null;
17
+ fromCache: boolean;
18
+ isInitialized: true;
19
+ };
20
+ type SWRSession = {
21
+ session: null;
22
+ fromCache: false;
23
+ isInitialized: false;
24
+ } | {
25
+ session: Session | null;
26
+ fromCache: boolean;
27
+ isInitialized: true;
28
+ };
29
+ /**
30
+ * Returns the active User.
31
+ * The Stytch SDKs are used for client-side authentication and session management.
32
+ * Check the isInitialized property to determine if the SDK has completed initialization.
33
+ * Check the fromCache property to determine if the session data is from persistent storage.
34
+ * See Next's {@link https://nextjs.org/docs/authentication#authenticating-statically-generated-pages documentation} for more.
35
+ * @example
36
+ * const {user, isInitialized, fromCache} = useStytchUser();
37
+ * if (!isInitialized) {
38
+ * return <p>Loading...</p>;
39
+ * }
40
+ * return (<h1>Welcome, {user.name.first_name}</h1>);
41
+ */
42
+ declare const useStytchUser: () => SWRUser;
43
+ /**
44
+ * Returns the user's active Stytch session.
45
+ * The Stytch SDKs are used for client-side authentication and session management.
46
+ * Check the isInitialized property to determine if the SDK has completed initialization.
47
+ * Check the fromCache property to determine if the session data is from persistent storage.
48
+ * See Next's {@link https://nextjs.org/docs/authentication#authenticating-statically-generated-pages documentation} for more.
49
+ * @example
50
+ * const {session, isInitialized, fromCache} = useStytchSession();
51
+ * useEffect(() => {
52
+ * if (!isInitialized) {
53
+ * return;
54
+ * }
55
+ * if (!session) {
56
+ * router.replace('/login')
57
+ * }
58
+ * }, [session, isInitialized]);
59
+ */
60
+ declare const useStytchSession: () => SWRSession;
61
+ /**
62
+ * Returns the Stytch client stored in the Stytch context.
63
+ *
64
+ * @example
65
+ * const stytch = useStytch();
66
+ * useEffect(() => {
67
+ * stytch.magicLinks.authenticate('...')
68
+ * }, [stytch]);
69
+ */
70
+ declare const useStytch: () => StytchClient;
71
+ declare const withStytch: <T extends object>(Component: React.ComponentType<T & {
72
+ stytch: StytchClient;
73
+ }>) => React.ComponentType<T>;
74
+ declare const withStytchUser: <T extends object>(Component: React.ComponentType<T & {
75
+ stytchUser: User | null;
76
+ stytchUserIsInitialized: boolean;
77
+ stytchUserIsFromCache: boolean;
78
+ }>) => React.ComponentType<T>;
79
+ declare const withStytchSession: <T extends object>(Component: React.ComponentType<T & {
80
+ stytchSession: Session | null;
81
+ stytchSessionIsInitialized: boolean;
82
+ stytchSessionIsFromCache: boolean;
83
+ }>) => React.ComponentType<T>;
84
+ interface StytchProviderProps {
85
+ /**
86
+ * A Stytch client instance, created using either {@link createStytchHeadlessClient} or {@link createStytchUIClient}
87
+ */
88
+ stytch: StytchClient;
89
+ children?: ReactNode;
90
+ }
91
+ /**
92
+ * The Stytch Context Provider.
93
+ * Wrap your application with this component in `_app.js` in order to use Stytch everywhere in your app.
94
+ * @example
95
+ * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')
96
+ *
97
+ * return (
98
+ * <StytchProvider stytch={stytch}>
99
+ * <App />
100
+ * </StytchProvider>
101
+ * )
102
+ */
103
+ declare const StytchProvider: ({ stytch, children }: StytchProviderProps) => JSX.Element;
104
+ interface StytchProps {
105
+ /**
106
+ * A {@link StytchLoginConfig} object. Add products and product-specific config to this object to change the login methods shown.
107
+ *
108
+ * @example
109
+ * {
110
+ * products: ['crypto', 'otps']
111
+ * }
112
+ *
113
+ * @example
114
+ * {
115
+ * products: ['emailMagicLinks'>]
116
+ * emailMagicLinksOptions: {
117
+ * loginRedirectURL: 'https://example.com/authenticate',
118
+ * signupRedirectURL: 'https://example.com/authenticate',
119
+ * }
120
+ * }
121
+ *
122
+ * @example
123
+ * {
124
+ * products: ['oauth'>]
125
+ * oauthOptions: {
126
+ * providers: [
127
+ * { type: 'google', one_tap: true, position: 'embedded' },
128
+ * { type: 'microsoft' },
129
+ * { type: 'apple' },
130
+ * { type: 'facebook' },
131
+ * ],
132
+ * }
133
+ * }
134
+ */
135
+ config: StytchLoginConfig;
136
+ /**
137
+ * An optional {@link StyleConfig} to customize the look and feel of the screen.
138
+ *
139
+ * @example
140
+ * {
141
+ * fontFamily: 'Arial, Helvetica, sans-serif',
142
+ * width: '360px',
143
+ * primaryColor: '#19303D',
144
+ * }
145
+ */
146
+ styles?: StyleConfig;
147
+ /**
148
+ * An optional {@link Callbacks} object.
149
+ *
150
+ * @example
151
+ * {
152
+ * onError: ({message}) => {
153
+ * console.error('Stytch login screen error', message)
154
+ * }
155
+ * }
156
+ *
157
+ * @example
158
+ * {
159
+ * onEvent: ({type, data}) => {
160
+ * if(type === StytchEventType.CryptoWalletAuthenticate) {
161
+ * console.log('Logged in with crypto wallet', data);
162
+ * }
163
+ * }
164
+ * }
165
+ */
166
+ callbacks?: Callbacks;
167
+ }
168
+ /**
169
+ * The Stytch Login Screen component.
170
+ * This component can only be used with the Stytch UI Client - use {@link createStytchUIClient}
171
+ * in your `_app.jsx` file.
172
+ *
173
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
174
+ * and {@link https://storybook.stytch.com interactive examples} for more.
175
+ *
176
+ * @example
177
+ * <StytchLogin
178
+ * config={{
179
+ * products: ['emailMagicLinks', 'oauth'],
180
+ * emailMagicLinksOptions: {
181
+ * loginRedirectURL: 'https://example.com/authenticate',
182
+ * signupRedirectURL: 'https://example.com/authenticate',
183
+ * },
184
+ * oauthOptions: {
185
+ * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],
186
+ * },
187
+ * }}
188
+ * styles={{
189
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
190
+ * primaryColor: '#0577CA',
191
+ * width: '321px',
192
+ * }}
193
+ * callbacks={{
194
+ * onEvent: (event) => console.log(event)
195
+ * }}
196
+ * />
197
+ *
198
+ * @param config - A {@link StytchLoginConfig} object
199
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
200
+ * @param callbacks - An optional {@link Callbacks} object
201
+ */
202
+ declare const StytchLogin: ({ config, styles, callbacks }: StytchProps) => React.JSX.Element;
203
+ interface StytchResetPasswordProps extends StytchProps {
204
+ passwordResetToken: string;
205
+ }
206
+ /**
207
+ * The Stytch Reset Password component.
208
+ * This component can only be used with a {@link StytchUIClient} client constructor
209
+ * passed into the {@link StytchProvider}
210
+ *
211
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
212
+ * and {@link https://storybook.stytch.com interactive examples} for more.
213
+ *
214
+ * @example
215
+ * <StytchPasswordReset
216
+ * config={{
217
+ * products: ['emailMagicLinks', 'oauth'],
218
+ * emailMagicLinksOptions: {
219
+ * loginRedirectURL: 'https://example.com/authenticate',
220
+ * signupRedirectURL: 'https://example.com/authenticate',
221
+ * },
222
+ * oauthOptions: {
223
+ * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],
224
+ * },
225
+ * }}
226
+ * passwordResetToken="PvC5UudZ7TPZbELt95yXAQ-8MeEUCRob8bUQ-g52fIJs"
227
+ * styles={{
228
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
229
+ * primaryColor: '#0577CA',
230
+ * width: '321px',
231
+ * }}
232
+ * callbacks={{
233
+ * onEvent: (event) => console.log(event)
234
+ * }}
235
+ * />
236
+ *
237
+ * @param config - A {@link StytchLoginConfig} object
238
+ * @param passwordResetToken - A Stytch password reset token
239
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
240
+ * @param callbacks - An optional {@link Callbacks} object
241
+ */
242
+ declare const StytchPasswordReset: ({ config, styles, callbacks, passwordResetToken }: StytchResetPasswordProps) => React.JSX.Element;
243
+ /**
244
+ * The Stytch Passkey Registration component.
245
+ * This component can only be used with a {@link StytchUIClient} client constructor
246
+ * passed into the {@link StytchProvider}
247
+ *
248
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
249
+ * and {@link https://storybook.stytch.com interactive examples} for more.
250
+ *
251
+ * @example
252
+ * const styles = {
253
+ * container: {
254
+ * backgroundColor: '#e11e1e',
255
+ * },
256
+ * colors: {
257
+ * primary: '#ff00f7',
258
+ * secondary: '#5C727D',
259
+ * },
260
+ * }
261
+ *
262
+ * <StytchPasskeyRegistration
263
+ * styles={styles}
264
+ * callbacks={{
265
+ * onEvent: (event) => console.log(event)
266
+ * }}
267
+ * />
268
+ * />
269
+ *
270
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
271
+ * @param callbacks - An optional {@link Callbacks} object
272
+ */
273
+ declare const StytchPasskeyRegistration: ({ config, styles, callbacks }: StytchProps) => React.JSX.Element;
274
+ export { StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser, StytchLogin, StytchPasswordReset, StytchPasskeyRegistration };
275
+ export type { StytchProviderProps };
@@ -1 +1,16 @@
1
- export * from './createStytchHeadlessClient';
1
+ import { StytchHeadlessClient } from "@stytch/vanilla-js/headless";
2
+ /**
3
+ * Creates a Headless Stytch client object to call the stytch APIs.
4
+ * The Stytch client is not available serverside.
5
+ * @example
6
+ * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')
7
+ *
8
+ * return (
9
+ * <StytchProvider stytch={stytch}>
10
+ * <App />
11
+ * </StytchProvider>
12
+ * )
13
+ * @returns A {@link StytchHeadlessClient}
14
+ */
15
+ declare const createStytchHeadlessClient: (_PUBLIC_TOKEN: string, options?: import("@stytch/core/dist/public").StytchClientOptions | undefined) => StytchHeadlessClient;
16
+ export { createStytchHeadlessClient };
@@ -1,18 +1,65 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var headless = require('@stytch/vanilla-js/headless');
6
+
7
+ const cannotInvokeMethodOnServerError = (path) => `[Stytch] Invalid serverside function call to ${path}.
8
+ The Stytch Javascript SDK is intended to ony be used on the client side.
9
+ Make sure to wrap your API calls in a hook to ensure they are executed on the client.
10
+ \`\`\`
11
+ const myComponent = () => {
12
+ const stytch = useStytch();
13
+ // This will error out on the server.
14
+ stytch.magicLinks.authenticate(...);
15
+ useEffect(() => {
16
+ // This will work well
17
+ stytch.magicLinks.authenticate(...);
18
+ }, []);
19
+ }
20
+ \`\`\`
21
+
22
+ If you want to make API calls from server environments, please use the Stytch Node Library
23
+ https://www.npmjs.com/package/stytch.
24
+ `;
25
+
26
+ const SSRStubKey = Symbol('__stytch_SSRStubKey');
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ const createProxy = (path) => {
29
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
30
+ const noop = () => { };
31
+ return new Proxy(noop, {
32
+ get(target, p) {
33
+ if (p === SSRStubKey) {
34
+ return true;
35
+ }
36
+ return createProxy(path + '.' + String(p));
37
+ },
38
+ apply() {
39
+ throw new Error(cannotInvokeMethodOnServerError(path));
40
+ },
41
+ });
42
+ };
43
+ const createStytchSSRProxy = () => createProxy('stytch');
44
+
45
+ /**
46
+ * Creates a Headless Stytch client object to call the stytch APIs.
47
+ * The Stytch client is not available serverside.
48
+ * @example
49
+ * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')
50
+ *
51
+ * return (
52
+ * <StytchProvider stytch={stytch}>
53
+ * <App />
54
+ * </StytchProvider>
55
+ * )
56
+ * @returns A {@link StytchHeadlessClient}
57
+ */
58
+ const createStytchHeadlessClient = (...args) => {
59
+ if (typeof window === 'undefined') {
60
+ return createStytchSSRProxy();
7
61
  }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
62
+ return new headless.StytchHeadlessClient(...args);
15
63
  };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./createStytchHeadlessClient"), exports);
18
- //# sourceMappingURL=index.headless.js.map
64
+
65
+ exports.createStytchHeadlessClient = createStytchHeadlessClient;