@stytch/nextjs 12.0.0 → 13.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 +11 -0
  2. package/dist/Stytch.d.ts +172 -0
  3. package/dist/Stytch.js +214 -0
  4. package/dist/Stytch.js.map +1 -0
  5. package/dist/Stytch.spec.d.ts +1 -0
  6. package/dist/Stytch.spec.js +130 -0
  7. package/dist/Stytch.spec.js.map +1 -0
  8. package/dist/StytchContext.d.ts +104 -0
  9. package/dist/StytchContext.js +180 -0
  10. package/dist/StytchContext.js.map +1 -0
  11. package/dist/StytchContext.serverside.spec.d.ts +4 -0
  12. package/dist/StytchContext.serverside.spec.js +51 -0
  13. package/dist/StytchContext.serverside.spec.js.map +1 -0
  14. package/dist/StytchContext.spec.d.ts +1 -0
  15. package/dist/StytchContext.spec.js +212 -0
  16. package/dist/StytchContext.spec.js.map +1 -0
  17. package/dist/StytchSSRProxy.d.ts +2 -0
  18. package/dist/StytchSSRProxy.js +29 -0
  19. package/dist/StytchSSRProxy.js.map +1 -0
  20. package/dist/StytchSSRProxy.spec.d.ts +1 -0
  21. package/dist/StytchSSRProxy.spec.js +16 -0
  22. package/dist/StytchSSRProxy.spec.js.map +1 -0
  23. package/dist/b2b/Stytch.d.ts +104 -0
  24. package/dist/b2b/Stytch.js +90 -0
  25. package/dist/b2b/Stytch.js.map +1 -0
  26. package/dist/b2b/StytchB2BContext.d.ts +104 -0
  27. package/dist/b2b/StytchB2BContext.js +179 -0
  28. package/dist/b2b/StytchB2BContext.js.map +1 -0
  29. package/dist/b2b/StytchB2BContext.spec.d.ts +1 -0
  30. package/dist/b2b/StytchB2BContext.spec.js +217 -0
  31. package/dist/b2b/StytchB2BContext.spec.js.map +1 -0
  32. package/dist/b2b/createStytchB2BHeadlessClient.d.ts +15 -0
  33. package/dist/b2b/createStytchB2BHeadlessClient.js +26 -0
  34. package/dist/b2b/createStytchB2BHeadlessClient.js.map +1 -0
  35. package/dist/b2b/createStytchB2BUIClient.d.ts +16 -0
  36. package/dist/b2b/createStytchB2BUIClient.js +27 -0
  37. package/dist/b2b/createStytchB2BUIClient.js.map +1 -0
  38. package/dist/b2b/index.d.ts +3 -208
  39. package/dist/b2b/index.headless.d.ts +1 -16
  40. package/dist/b2b/index.headless.esm.js +569 -612
  41. package/dist/b2b/index.headless.js +17 -4164
  42. package/dist/b2b/index.headless.js.map +1 -0
  43. package/dist/b2b/index.js +14 -250
  44. package/dist/b2b/index.js.map +1 -0
  45. package/dist/b2b/index.ui.d.ts +1 -17
  46. package/dist/b2b/index.ui.js +16 -64
  47. package/dist/b2b/index.ui.js.map +1 -0
  48. package/dist/createStytchHeadlessClient.d.ts +15 -0
  49. package/dist/createStytchHeadlessClient.js +26 -0
  50. package/dist/createStytchHeadlessClient.js.map +1 -0
  51. package/dist/createStytchUIClient.d.ts +16 -0
  52. package/dist/createStytchUIClient.js +27 -0
  53. package/dist/createStytchUIClient.js.map +1 -0
  54. package/dist/index.d.ts +3 -244
  55. package/dist/index.esm.d.ts +32 -1
  56. package/dist/index.esm.js +56 -1
  57. package/dist/index.headless.d.ts +1 -16
  58. package/dist/index.headless.js +16 -63
  59. package/dist/index.headless.js.map +1 -0
  60. package/dist/index.js +16 -318
  61. package/dist/index.js.map +1 -0
  62. package/dist/index.ui.d.ts +1 -17
  63. package/dist/index.ui.js +16 -64
  64. package/dist/index.ui.js.map +1 -0
  65. package/dist/utils/async.d.ts +2 -0
  66. package/dist/utils/async.js +22 -0
  67. package/dist/utils/async.js.map +1 -0
  68. package/dist/utils/errors.d.ts +3 -0
  69. package/dist/utils/errors.js +28 -0
  70. package/dist/utils/errors.js.map +1 -0
  71. package/dist/utils/invariant.d.ts +1 -0
  72. package/dist/utils/invariant.js +10 -0
  73. package/dist/utils/invariant.js.map +1 -0
  74. package/dist/utils/useIsomorphicLayoutEffect.d.ts +3 -0
  75. package/dist/utils/useIsomorphicLayoutEffect.js +7 -0
  76. package/dist/utils/useIsomorphicLayoutEffect.js.map +1 -0
  77. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @stytch/nextjs
2
2
 
3
+ ## 13.0.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8cff174: B2C Passkeys Headless Support & UI components
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [8cff174]
12
+ - @stytch/vanilla-js@3.1.0
13
+
3
14
  ## 12.0.0
4
15
 
5
16
  ### Major Changes
@@ -0,0 +1,172 @@
1
+ import React from 'react';
2
+ import type { Callbacks, StytchLoginConfig, StyleConfig } from '@stytch/vanilla-js';
3
+ export interface StytchProps {
4
+ /**
5
+ * A {@link StytchLoginConfig} object. Add products and product-specific config to this object to change the login methods shown.
6
+ *
7
+ * @example
8
+ * {
9
+ * products: ['crypto', 'otps']
10
+ * }
11
+ *
12
+ * @example
13
+ * {
14
+ * products: ['emailMagicLinks'>]
15
+ * emailMagicLinksOptions: {
16
+ * loginRedirectURL: 'https://example.com/authenticate',
17
+ * signupRedirectURL: 'https://example.com/authenticate',
18
+ * }
19
+ * }
20
+ *
21
+ * @example
22
+ * {
23
+ * products: ['oauth'>]
24
+ * oauthOptions: {
25
+ * providers: [
26
+ * { type: 'google', one_tap: true, position: 'embedded' },
27
+ * { type: 'microsoft' },
28
+ * { type: 'apple' },
29
+ * { type: 'facebook' },
30
+ * ],
31
+ * }
32
+ * }
33
+ */
34
+ config: StytchLoginConfig;
35
+ /**
36
+ * An optional {@link StyleConfig} to customize the look and feel of the screen.
37
+ *
38
+ * @example
39
+ * {
40
+ * fontFamily: 'Arial, Helvetica, sans-serif',
41
+ * width: '360px',
42
+ * primaryColor: '#19303D',
43
+ * }
44
+ */
45
+ styles?: StyleConfig;
46
+ /**
47
+ * An optional {@link Callbacks} object.
48
+ *
49
+ * @example
50
+ * {
51
+ * onError: ({message}) => {
52
+ * console.error('Stytch login screen error', message)
53
+ * }
54
+ * }
55
+ *
56
+ * @example
57
+ * {
58
+ * onEvent: ({type, data}) => {
59
+ * if(type === StytchEventType.CryptoWalletAuthenticate) {
60
+ * console.log('Logged in with crypto wallet', data);
61
+ * }
62
+ * }
63
+ * }
64
+ */
65
+ callbacks?: Callbacks;
66
+ }
67
+ /**
68
+ * The Stytch Login Screen component.
69
+ * This component can only be used with the Stytch UI Client - use {@link createStytchUIClient}
70
+ * in your `_app.jsx` file.
71
+ *
72
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
73
+ * and {@link https://storybook.stytch.com interactive examples} for more.
74
+ *
75
+ * @example
76
+ * <StytchLogin
77
+ * config={{
78
+ * products: ['emailMagicLinks', 'oauth'],
79
+ * emailMagicLinksOptions: {
80
+ * loginRedirectURL: 'https://example.com/authenticate',
81
+ * signupRedirectURL: 'https://example.com/authenticate',
82
+ * },
83
+ * oauthOptions: {
84
+ * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],
85
+ * },
86
+ * }}
87
+ * styles={{
88
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
89
+ * primaryColor: '#0577CA',
90
+ * width: '321px',
91
+ * }}
92
+ * callbacks={{
93
+ * onEvent: (event) => console.log(event)
94
+ * }}
95
+ * />
96
+ *
97
+ * @param config - A {@link StytchLoginConfig} object
98
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
99
+ * @param callbacks - An optional {@link Callbacks} object
100
+ */
101
+ export declare const StytchLogin: ({ config, styles, callbacks }: StytchProps) => React.JSX.Element;
102
+ export interface StytchResetPasswordProps extends StytchProps {
103
+ passwordResetToken: string;
104
+ }
105
+ /**
106
+ * The Stytch Reset Password component.
107
+ * This component can only be used with a {@link StytchUIClient} client constructor
108
+ * passed into the {@link StytchProvider}
109
+ *
110
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
111
+ * and {@link https://storybook.stytch.com interactive examples} for more.
112
+ *
113
+ * @example
114
+ * <StytchPasswordReset
115
+ * config={{
116
+ * products: ['emailMagicLinks', 'oauth'],
117
+ * emailMagicLinksOptions: {
118
+ * loginRedirectURL: 'https://example.com/authenticate',
119
+ * signupRedirectURL: 'https://example.com/authenticate',
120
+ * },
121
+ * oauthOptions: {
122
+ * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],
123
+ * },
124
+ * }}
125
+ * passwordResetToken="PvC5UudZ7TPZbELt95yXAQ-8MeEUCRob8bUQ-g52fIJs"
126
+ * styles={{
127
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
128
+ * primaryColor: '#0577CA',
129
+ * width: '321px',
130
+ * }}
131
+ * callbacks={{
132
+ * onEvent: (event) => console.log(event)
133
+ * }}
134
+ * />
135
+ *
136
+ * @param config - A {@link StytchLoginConfig} object
137
+ * @param passwordResetToken - A Stytch password reset token
138
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
139
+ * @param callbacks - An optional {@link Callbacks} object
140
+ */
141
+ export declare const StytchPasswordReset: ({ config, styles, callbacks, passwordResetToken }: StytchResetPasswordProps) => React.JSX.Element;
142
+ /**
143
+ * The Stytch Passkey Registration component.
144
+ * This component can only be used with a {@link StytchUIClient} client constructor
145
+ * passed into the {@link StytchProvider}
146
+ *
147
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
148
+ * and {@link https://storybook.stytch.com interactive examples} for more.
149
+ *
150
+ * @example
151
+ * const styles = {
152
+ * container: {
153
+ * backgroundColor: '#e11e1e',
154
+ * },
155
+ * colors: {
156
+ * primary: '#ff00f7',
157
+ * secondary: '#5C727D',
158
+ * },
159
+ * }
160
+ *
161
+ * <StytchPasskeyRegistration
162
+ * styles={styles}
163
+ * callbacks={{
164
+ * onEvent: (event) => console.log(event)
165
+ * }}
166
+ * />
167
+ * />
168
+ *
169
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
170
+ * @param callbacks - An optional {@link Callbacks} object
171
+ */
172
+ export declare const StytchPasskeyRegistration: ({ config, styles, callbacks }: StytchProps) => React.JSX.Element;
package/dist/Stytch.js ADDED
@@ -0,0 +1,214 @@
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]; } };
7
+ }
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.StytchPasskeyRegistration = exports.StytchPasswordReset = exports.StytchLogin = void 0;
30
+ const react_1 = __importStar(require("react"));
31
+ const StytchContext_1 = require("./StytchContext");
32
+ const invariant_1 = require("./utils/invariant");
33
+ const errors_1 = require("./utils/errors");
34
+ const useIsomorphicLayoutEffect_1 = __importDefault(require("./utils/useIsomorphicLayoutEffect"));
35
+ /**
36
+ * The Stytch Login Screen component.
37
+ * This component can only be used with the Stytch UI Client - use {@link createStytchUIClient}
38
+ * in your `_app.jsx` file.
39
+ *
40
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
41
+ * and {@link https://storybook.stytch.com interactive examples} for more.
42
+ *
43
+ * @example
44
+ * <StytchLogin
45
+ * config={{
46
+ * products: ['emailMagicLinks', 'oauth'],
47
+ * emailMagicLinksOptions: {
48
+ * loginRedirectURL: 'https://example.com/authenticate',
49
+ * signupRedirectURL: 'https://example.com/authenticate',
50
+ * },
51
+ * oauthOptions: {
52
+ * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],
53
+ * },
54
+ * }}
55
+ * styles={{
56
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
57
+ * primaryColor: '#0577CA',
58
+ * width: '321px',
59
+ * }}
60
+ * callbacks={{
61
+ * onEvent: (event) => console.log(event)
62
+ * }}
63
+ * />
64
+ *
65
+ * @param config - A {@link StytchLoginConfig} object
66
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
67
+ * @param callbacks - An optional {@link Callbacks} object
68
+ */
69
+ const StytchLogin = ({ config, styles, callbacks }) => {
70
+ (0, invariant_1.invariant)((0, StytchContext_1.useIsMounted__INTERNAL)(), (0, errors_1.noProviderError)('<StytchLogin />'));
71
+ const stytchClient = (0, StytchContext_1.useStytch)();
72
+ const containerEl = (0, react_1.useRef)(null);
73
+ (0, useIsomorphicLayoutEffect_1.default)(() => {
74
+ if (!(0, StytchContext_1.isUIClient)(stytchClient)) {
75
+ throw Error(errors_1.noHeadlessClientError);
76
+ }
77
+ if (!containerEl.current) {
78
+ return;
79
+ }
80
+ if (!containerEl.current.id) {
81
+ const randId = Math.floor(Math.random() * 1e6);
82
+ containerEl.current.id = `stytch-magic-link-${randId}`;
83
+ }
84
+ stytchClient.mountLogin({
85
+ config,
86
+ callbacks,
87
+ elementId: `#${containerEl.current.id}`,
88
+ styles,
89
+ });
90
+ }, [stytchClient, config, styles, callbacks]);
91
+ return react_1.default.createElement("div", { ref: containerEl });
92
+ };
93
+ exports.StytchLogin = StytchLogin;
94
+ /**
95
+ * The Stytch Reset Password component.
96
+ * This component can only be used with a {@link StytchUIClient} client constructor
97
+ * passed into the {@link StytchProvider}
98
+ *
99
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
100
+ * and {@link https://storybook.stytch.com interactive examples} for more.
101
+ *
102
+ * @example
103
+ * <StytchPasswordReset
104
+ * config={{
105
+ * products: ['emailMagicLinks', 'oauth'],
106
+ * emailMagicLinksOptions: {
107
+ * loginRedirectURL: 'https://example.com/authenticate',
108
+ * signupRedirectURL: 'https://example.com/authenticate',
109
+ * },
110
+ * oauthOptions: {
111
+ * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],
112
+ * },
113
+ * }}
114
+ * passwordResetToken="PvC5UudZ7TPZbELt95yXAQ-8MeEUCRob8bUQ-g52fIJs"
115
+ * styles={{
116
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
117
+ * primaryColor: '#0577CA',
118
+ * width: '321px',
119
+ * }}
120
+ * callbacks={{
121
+ * onEvent: (event) => console.log(event)
122
+ * }}
123
+ * />
124
+ *
125
+ * @param config - A {@link StytchLoginConfig} object
126
+ * @param passwordResetToken - A Stytch password reset token
127
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
128
+ * @param callbacks - An optional {@link Callbacks} object
129
+ */
130
+ const StytchPasswordReset = ({ config, styles, callbacks, passwordResetToken }) => {
131
+ (0, invariant_1.invariant)((0, StytchContext_1.useIsMounted__INTERNAL)(), (0, errors_1.noProviderError)('<StytchResetPassword />'));
132
+ const stytchClient = (0, StytchContext_1.useStytch)();
133
+ const containerEl = (0, react_1.useRef)(null);
134
+ (0, useIsomorphicLayoutEffect_1.default)(() => {
135
+ if (!(0, StytchContext_1.isUIClient)(stytchClient)) {
136
+ throw Error(errors_1.noHeadlessClientError);
137
+ }
138
+ if (!containerEl.current) {
139
+ return;
140
+ }
141
+ if (!containerEl.current.id) {
142
+ const randId = Math.floor(Math.random() * 1e6);
143
+ containerEl.current.id = `stytch-reset-password-${randId}`;
144
+ }
145
+ if (passwordResetToken) {
146
+ stytchClient.mountResetPassword({
147
+ config,
148
+ callbacks,
149
+ elementId: `#${containerEl.current.id}`,
150
+ styles,
151
+ passwordResetToken,
152
+ });
153
+ }
154
+ }, [stytchClient, config, styles, callbacks, passwordResetToken]);
155
+ return react_1.default.createElement("div", { ref: containerEl });
156
+ };
157
+ exports.StytchPasswordReset = StytchPasswordReset;
158
+ /**
159
+ * The Stytch Passkey Registration component.
160
+ * This component can only be used with a {@link StytchUIClient} client constructor
161
+ * passed into the {@link StytchProvider}
162
+ *
163
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
164
+ * and {@link https://storybook.stytch.com interactive examples} for more.
165
+ *
166
+ * @example
167
+ * const styles = {
168
+ * container: {
169
+ * backgroundColor: '#e11e1e',
170
+ * },
171
+ * colors: {
172
+ * primary: '#ff00f7',
173
+ * secondary: '#5C727D',
174
+ * },
175
+ * }
176
+ *
177
+ * <StytchPasskeyRegistration
178
+ * styles={styles}
179
+ * callbacks={{
180
+ * onEvent: (event) => console.log(event)
181
+ * }}
182
+ * />
183
+ * />
184
+ *
185
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
186
+ * @param callbacks - An optional {@link Callbacks} object
187
+ */
188
+ const StytchPasskeyRegistration = ({ config, styles, callbacks }) => {
189
+ (0, invariant_1.invariant)((0, StytchContext_1.useIsMounted__INTERNAL)(), (0, errors_1.noProviderError)('<StytchPasskeyRegistration />'));
190
+ const stytchClient = (0, StytchContext_1.useStytch)();
191
+ const containerEl = (0, react_1.useRef)(null);
192
+ const user = (0, StytchContext_1.useStytchUser)();
193
+ (0, useIsomorphicLayoutEffect_1.default)(() => {
194
+ if (!(0, StytchContext_1.isUIClient)(stytchClient)) {
195
+ throw Error(errors_1.noHeadlessClientError);
196
+ }
197
+ if (!containerEl.current) {
198
+ return;
199
+ }
200
+ if (!containerEl.current.id) {
201
+ const randId = Math.floor(Math.random() * 1e6);
202
+ containerEl.current.id = `stytch-passkey-registration-${randId}`;
203
+ }
204
+ stytchClient.mountPasskeyRegistration({
205
+ config,
206
+ callbacks,
207
+ elementId: `#${containerEl.current.id}`,
208
+ styles,
209
+ });
210
+ }, [stytchClient, config, styles, callbacks, user]);
211
+ return react_1.default.createElement("div", { ref: containerEl });
212
+ };
213
+ exports.StytchPasskeyRegistration = StytchPasskeyRegistration;
214
+ //# sourceMappingURL=Stytch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Stytch.js","sourceRoot":"","sources":["../src/Stytch.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAsC;AAGtC,mDAA+F;AAC/F,iDAA8C;AAC9C,2CAAwE;AACxE,kGAA0E;AAmE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACI,MAAM,WAAW,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAe,EAAE,EAAE;IACxE,IAAA,qBAAS,EAAC,IAAA,sCAAsB,GAAE,EAAE,IAAA,wBAAe,EAAC,iBAAiB,CAAC,CAAC,CAAC;IACxE,MAAM,YAAY,GAAG,IAAA,yBAAS,GAAE,CAAC;IACjC,MAAM,WAAW,GAAG,IAAA,cAAM,EAAiB,IAAI,CAAC,CAAC;IAEjD,IAAA,mCAAyB,EAAC,GAAG,EAAE;QAC7B,IAAI,CAAC,IAAA,0BAAU,EAAC,YAAY,CAAC,EAAE;YAC7B,MAAM,KAAK,CAAC,8BAAqB,CAAC,CAAC;SACpC;QAED,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;YACxB,OAAO;SACR;QAED,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,EAAE;YAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;YAC/C,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,qBAAqB,MAAM,EAAE,CAAC;SACxD;QAED,YAAY,CAAC,UAAU,CAAC;YACtB,MAAM;YACN,SAAS;YACT,SAAS,EAA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SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;IAEpD,OAAO,uCAAK,GAAG,EAAE,WAAW,GAAI,CAAC;AACnC,CAAC,CAAC;AA7BW,QAAA,yBAAyB,6BA6BpC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const react_1 = __importDefault(require("react"));
27
+ const vanilla_js_1 = require("@stytch/vanilla-js");
28
+ const react_2 = require("@testing-library/react");
29
+ const Stytch_1 = require("./Stytch");
30
+ const StytchContext_1 = require("./StytchContext");
31
+ const errors_1 = require("./utils/errors");
32
+ const mockStytchClient = {
33
+ user: { getSync: () => null, onChange: () => () => null },
34
+ session: { getSync: () => null, onChange: () => () => null },
35
+ mountLogin: jest.fn(),
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ };
38
+ beforeEach(() => {
39
+ jest.resetAllMocks();
40
+ });
41
+ describe('StytchLogin', () => {
42
+ const stytchUIConfig = {
43
+ emailMagicLinksOptions: {
44
+ createUserAsPending: true,
45
+ loginExpirationMinutes: 30,
46
+ loginRedirectURL: 'https://example.com/authenticate',
47
+ signupExpirationMinutes: 30,
48
+ signupRedirectURL: 'https://example.com/authenticate',
49
+ },
50
+ oauthOptions: {
51
+ providers: [{ type: vanilla_js_1.OAuthProviders.Google }, { type: vanilla_js_1.OAuthProviders.Microsoft }, { type: vanilla_js_1.OAuthProviders.Apple }],
52
+ },
53
+ products: [vanilla_js_1.Products.emailMagicLinks, vanilla_js_1.Products.oauth],
54
+ };
55
+ const stytchStyleConfig = {
56
+ fontFamily: '"Helvetica New", Helvetica, sans-serif',
57
+ };
58
+ it('expect error when not inside a StytchProvider', () => __awaiter(void 0, void 0, void 0, function* () {
59
+ expect(() => (0, react_2.render)(react_1.default.createElement(Stytch_1.StytchLogin, { config: stytchUIConfig, styles: stytchStyleConfig }))).toThrow((0, errors_1.noProviderError)('<StytchLogin />'));
60
+ }));
61
+ it('expect error when given a headless client', () => __awaiter(void 0, void 0, void 0, function* () {
62
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
63
+ const { mountLogin } = mockStytchClient, mockStytchHeadlessClient = __rest(mockStytchClient, ["mountLogin"]);
64
+ expect(() => (0, react_2.render)(react_1.default.createElement(StytchContext_1.StytchProvider, { stytch: mockStytchHeadlessClient },
65
+ react_1.default.createElement(Stytch_1.StytchLogin, { config: stytchUIConfig, styles: stytchStyleConfig })))).toThrow(errors_1.noHeadlessClientError);
66
+ }));
67
+ it('Creates a div and invokes stytchClient#mountLogin', () => __awaiter(void 0, void 0, void 0, function* () {
68
+ jest.spyOn(Math, 'random').mockReturnValueOnce(0.123456);
69
+ const { asFragment } = (0, react_2.render)(react_1.default.createElement(StytchContext_1.StytchProvider, { stytch: mockStytchClient },
70
+ react_1.default.createElement(Stytch_1.StytchLogin, { config: stytchUIConfig, styles: stytchStyleConfig })));
71
+ expect(mockStytchClient.mountLogin).toHaveBeenCalledWith({
72
+ elementId: '#stytch-magic-link-123456',
73
+ config: stytchUIConfig,
74
+ styles: stytchStyleConfig,
75
+ });
76
+ expect(asFragment()).toMatchInlineSnapshot(`
77
+ <DocumentFragment>
78
+ <div
79
+ id="stytch-magic-link-123456"
80
+ />
81
+ </DocumentFragment>
82
+ `);
83
+ }));
84
+ it('Invokes stytchClient#mountLogin again when properties change', () => __awaiter(void 0, void 0, void 0, function* () {
85
+ jest.spyOn(Math, 'random').mockReturnValueOnce(0.123456);
86
+ const { rerender } = (0, react_2.render)(react_1.default.createElement(StytchContext_1.StytchProvider, { stytch: mockStytchClient },
87
+ react_1.default.createElement(Stytch_1.StytchLogin, { config: stytchUIConfig, styles: stytchStyleConfig })));
88
+ expect(mockStytchClient.mountLogin).toHaveBeenCalledWith({
89
+ elementId: '#stytch-magic-link-123456',
90
+ config: stytchUIConfig,
91
+ styles: stytchStyleConfig,
92
+ });
93
+ const newStyleConfig = Object.assign(Object.assign({}, stytchStyleConfig), { width: '5000px' });
94
+ rerender(react_1.default.createElement(StytchContext_1.StytchProvider, { stytch: mockStytchClient },
95
+ react_1.default.createElement(Stytch_1.StytchLogin, { config: stytchUIConfig, styles: newStyleConfig })));
96
+ expect(mockStytchClient.mountLogin).toHaveBeenCalledWith({
97
+ elementId: '#stytch-magic-link-123456',
98
+ config: stytchUIConfig,
99
+ styles: newStyleConfig,
100
+ });
101
+ rerender(react_1.default.createElement(StytchContext_1.StytchProvider, { stytch: mockStytchClient },
102
+ react_1.default.createElement(Stytch_1.StytchLogin, { config: stytchUIConfig, styles: newStyleConfig })));
103
+ // third rerender should not have done anything
104
+ expect(mockStytchClient.mountLogin).toHaveBeenCalledTimes(2);
105
+ }));
106
+ it('Creates two unique divs when invoked twice on the same page', () => __awaiter(void 0, void 0, void 0, function* () {
107
+ jest.spyOn(Math, 'random').mockReturnValueOnce(0.123456).mockReturnValueOnce(0.789012);
108
+ const { asFragment } = (0, react_2.render)(react_1.default.createElement(StytchContext_1.StytchProvider, { stytch: mockStytchClient },
109
+ react_1.default.createElement(Stytch_1.StytchLogin, { config: stytchUIConfig, styles: stytchStyleConfig }),
110
+ react_1.default.createElement(Stytch_1.StytchLogin, { config: stytchUIConfig, styles: stytchStyleConfig })));
111
+ expect(mockStytchClient.mountLogin).toHaveBeenCalledTimes(2);
112
+ expect(mockStytchClient.mountLogin).toHaveBeenCalledWith(expect.objectContaining({
113
+ elementId: '#stytch-magic-link-123456',
114
+ }));
115
+ expect(mockStytchClient.mountLogin).toHaveBeenCalledWith(expect.objectContaining({
116
+ elementId: '#stytch-magic-link-789012',
117
+ }));
118
+ expect(asFragment()).toMatchInlineSnapshot(`
119
+ <DocumentFragment>
120
+ <div
121
+ id="stytch-magic-link-123456"
122
+ />
123
+ <div
124
+ id="stytch-magic-link-789012"
125
+ />
126
+ </DocumentFragment>
127
+ `);
128
+ }));
129
+ });
130
+ //# sourceMappingURL=Stytch.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Stytch.spec.js","sourceRoot":"","sources":["../src/Stytch.spec.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAE1B,mDAAqH;AAErH,kDAAgD;AAChD,qCAAuC;AACvC,mDAAiD;AACjD,2CAAwE;AAExE,MAAM,gBAAgB,GAAG;IACvB,IAAI,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE;IACzD,OAAO,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE;IAC5D,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;IACrB,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gBAAgB,CAAC,UAAU,CAAC,CAAC,oBAAoB,CACtD,MAAM,CAAC,gBAAgB,CAAC;YACtB,SAAS,EAAE,2BAA2B;SACvC,CAAC,CACH,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,oBAAoB,CACtD,MAAM,CAAC,gBAAgB,CAAC;YACtB,SAAS,EAAE,2BAA2B;SACvC,CAAC,CACH,CAAC;QAEF,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;KAS1C,CAAC,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,104 @@
1
+ import React, { ComponentType, ReactNode } from 'react';
2
+ import type { User, Session, StytchUIClient } from '@stytch/vanilla-js';
3
+ import type { StytchHeadlessClient } from '@stytch/vanilla-js/headless';
4
+ /**
5
+ * The Stytch Client object passed in to <StytchProvider /> in your `_app.js`.
6
+ * Either a StytchUIClient or StytchHeadlessClient.
7
+ */
8
+ declare type StytchClient = StytchUIClient | StytchHeadlessClient;
9
+ declare type SWRUser = {
10
+ user: null;
11
+ fromCache: false;
12
+ isInitialized: false;
13
+ } | {
14
+ user: User | null;
15
+ fromCache: boolean;
16
+ isInitialized: true;
17
+ };
18
+ declare type SWRSession = {
19
+ session: null;
20
+ fromCache: false;
21
+ isInitialized: false;
22
+ } | {
23
+ session: Session | null;
24
+ fromCache: boolean;
25
+ isInitialized: true;
26
+ };
27
+ export declare const useIsMounted__INTERNAL: () => boolean;
28
+ export declare const isUIClient: (client: StytchClient) => client is StytchUIClient;
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
+ export 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
+ export 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
+ export declare const useStytch: () => StytchClient;
71
+ export declare const withStytch: <T extends object>(Component: React.ComponentType<T & {
72
+ stytch: StytchClient;
73
+ }>) => React.ComponentType<T>;
74
+ export 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
+ export 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
+ export 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
+ export declare const StytchProvider: ({ stytch, children }: StytchProviderProps) => JSX.Element;
104
+ export {};