@stytch/stytch-react 3.0.5 → 3.0.8-headless.beta.1

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { LoginOrSignupView, StyleConfig, CallbackOptions } from "@stytch/stytch-js";
2
+ import { CallbackOptions, LoginOrSignupView, StyleConfig, Session, StytchClient, User } from "@stytch/stytch-js";
3
+ import React from "react";
4
+ import { ReactNode } from "react";
3
5
  interface StytchProps {
4
- publicToken: string;
6
+ publicToken?: string;
5
7
  loginOrSignupView?: LoginOrSignupView;
6
8
  style?: StyleConfig;
7
9
  callbacks?: CallbackOptions;
@@ -11,6 +13,27 @@ interface StytchProps {
11
13
  *
12
14
  * [Documentation](https://stytch.com/docs/javascript-sdk)
13
15
  */
14
- declare const Stytch: (props: StytchProps) => JSX.Element;
15
- export { SDKProductTypes, OAuthProvidersTypes } from "@stytch/stytch-js";
16
- export { Stytch, StytchProps };
16
+ declare const Stytch: ({ publicToken, style, callbacks, loginOrSignupView }: StytchProps) => JSX.Element;
17
+ declare const useStytchUser: () => User | null;
18
+ declare const useStytchSession: () => Session | null;
19
+ declare const useStytch: () => StytchClient;
20
+ declare const useStytchLazy: () => StytchClient;
21
+ declare const withStytch: <T extends object>(Component: React.ComponentType<T & {
22
+ stytch: StytchClient;
23
+ }>) => React.ComponentType<T>;
24
+ declare const withStytchLazy: <T extends object>(Component: React.ComponentType<T & {
25
+ stytch: StytchClient | null;
26
+ }>) => React.ComponentType<T>;
27
+ declare const withStytchUser: <T extends object>(Component: React.ComponentType<T & {
28
+ stytchUser: User | null;
29
+ }>) => React.ComponentType<T>;
30
+ declare const withStytchSession: <T extends object>(Component: React.ComponentType<T & {
31
+ stytchSession: Session | null;
32
+ }>) => React.ComponentType<T>;
33
+ type StytchProviderProps = {
34
+ stytch: StytchClient | null | Promise<StytchClient | null>;
35
+ children?: ReactNode;
36
+ };
37
+ declare const StytchProvider: ({ stytch, children }: StytchProviderProps) => JSX.Element;
38
+ export { initStytch, loadAndInitStytch, SDKProductTypes, OneTapPositions, OAuthProvidersTypes, StytchClient } from '@stytch/stytch-js';
39
+ export { Stytch, StytchProps, StytchProvider, StytchProviderProps, useStytch, useStytchLazy, useStytchSession, useStytchUser, withStytch, withStytchLazy, withStytchSession, withStytchUser };
@@ -1,7 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { LoginOrSignupView, StyleConfig, CallbackOptions } from "@stytch/stytch-js";
2
+ import { CallbackOptions, LoginOrSignupView, StyleConfig, Session, StytchClient, User } from "@stytch/stytch-js";
3
+ import React from "react";
4
+ import { ReactNode } from "react";
3
5
  interface StytchProps {
4
- publicToken: string;
6
+ publicToken?: string;
5
7
  loginOrSignupView?: LoginOrSignupView;
6
8
  style?: StyleConfig;
7
9
  callbacks?: CallbackOptions;
@@ -11,6 +13,27 @@ interface StytchProps {
11
13
  *
12
14
  * [Documentation](https://stytch.com/docs/javascript-sdk)
13
15
  */
14
- declare const Stytch: (props: StytchProps) => JSX.Element;
15
- export { SDKProductTypes, OAuthProvidersTypes } from "@stytch/stytch-js";
16
- export { Stytch, StytchProps };
16
+ declare const Stytch: ({ publicToken, style, callbacks, loginOrSignupView }: StytchProps) => JSX.Element;
17
+ declare const useStytchUser: () => User | null;
18
+ declare const useStytchSession: () => Session | null;
19
+ declare const useStytch: () => StytchClient;
20
+ declare const useStytchLazy: () => StytchClient;
21
+ declare const withStytch: <T extends object>(Component: React.ComponentType<T & {
22
+ stytch: StytchClient;
23
+ }>) => React.ComponentType<T>;
24
+ declare const withStytchLazy: <T extends object>(Component: React.ComponentType<T & {
25
+ stytch: StytchClient | null;
26
+ }>) => React.ComponentType<T>;
27
+ declare const withStytchUser: <T extends object>(Component: React.ComponentType<T & {
28
+ stytchUser: User | null;
29
+ }>) => React.ComponentType<T>;
30
+ declare const withStytchSession: <T extends object>(Component: React.ComponentType<T & {
31
+ stytchSession: Session | null;
32
+ }>) => React.ComponentType<T>;
33
+ type StytchProviderProps = {
34
+ stytch: StytchClient | null | Promise<StytchClient | null>;
35
+ children?: ReactNode;
36
+ };
37
+ declare const StytchProvider: ({ stytch, children }: StytchProviderProps) => JSX.Element;
38
+ export { initStytch, loadAndInitStytch, SDKProductTypes, OneTapPositions, OAuthProvidersTypes, StytchClient } from '@stytch/stytch-js';
39
+ export { Stytch, StytchProps, StytchProvider, StytchProviderProps, useStytch, useStytchLazy, useStytchSession, useStytchUser, withStytch, withStytchLazy, withStytchSession, withStytchUser };
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { createContext, useContext, useState, useEffect } from 'react';
2
2
 
3
3
  var PUBLIC_URL = 'https://js.stytch.com/stytch.js';
4
4
  function getJSUrl() {
@@ -93,6 +93,8 @@ var OAuthProvidersTypes;
93
93
  OAuthProvidersTypes["Google"] = "google";
94
94
  OAuthProvidersTypes["Microsoft"] = "microsoft";
95
95
  OAuthProvidersTypes["Apple"] = "apple";
96
+ OAuthProvidersTypes["Github"] = "github";
97
+ OAuthProvidersTypes["Facebook"] = "facebook";
96
98
  })(OAuthProvidersTypes || (OAuthProvidersTypes = {}));
97
99
  var OneTapPositions;
98
100
  (function (OneTapPositions) {
@@ -100,15 +102,159 @@ var OneTapPositions;
100
102
  OneTapPositions["floating"] = "floating";
101
103
  })(OneTapPositions || (OneTapPositions = {}));
102
104
 
103
- var useStytchFactory = function () {
104
- var _a = useState(), stytchFactory = _a[0], setStytchFactory = _a[1];
105
+ var initStytch = function () {
106
+ var args = [];
107
+ for (var _i = 0; _i < arguments.length; _i++) {
108
+ args[_i] = arguments[_i];
109
+ }
110
+ if (typeof window === 'undefined') {
111
+ return null;
112
+ }
113
+ if (!window.Stytch) {
114
+ throw new Error('Stytch has not been loaded.');
115
+ }
116
+ return window.Stytch.apply(window, args);
117
+ };
118
+ var loadAndInitStytch = function () {
119
+ var args = [];
120
+ for (var _i = 0; _i < arguments.length; _i++) {
121
+ args[_i] = arguments[_i];
122
+ }
123
+ return loadStytch().then(function (stytchFactory) { return stytchFactory && stytchFactory.apply(void 0, args); });
124
+ };
125
+
126
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
127
+ function invariant(cond, message) {
128
+ if (!cond)
129
+ throw new Error(message);
130
+ }
131
+
132
+ /*! *****************************************************************************
133
+ Copyright (c) Microsoft Corporation.
134
+
135
+ Permission to use, copy, modify, and/or distribute this software for any
136
+ purpose with or without fee is hereby granted.
137
+
138
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
139
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
140
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
141
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
142
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
143
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
144
+ PERFORMANCE OF THIS SOFTWARE.
145
+ ***************************************************************************** */
146
+
147
+ var __assign = function() {
148
+ __assign = Object.assign || function __assign(t) {
149
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
150
+ s = arguments[i];
151
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
152
+ }
153
+ return t;
154
+ };
155
+ return __assign.apply(this, arguments);
156
+ };
157
+
158
+ var noProviderError = function (hookOrHOC) { return "".concat(hookOrHOC, " can only be used inside <StytchProvider>."); };
159
+ var lazyError = function (hookOrHOC) {
160
+ return "".concat(hookOrHOC, " can only be used if Stytch is preloaded. Add <script src=\"https://js.stytch.com/stytch.js\" /> in your document header to load the script synchronously, or use ").concat(hookOrHOC, "Lazy if you want to lazy load Stytch. If you are using SSR, you will need to use ").concat(hookOrHOC, "Lazy.");
161
+ };
162
+
163
+ var StytchMountedContext = createContext({
164
+ isLazy: false,
165
+ isMounted: false,
166
+ });
167
+ var StytchUserContext = createContext(null);
168
+ var StytchSessionContext = createContext(null);
169
+ var StytchContext = createContext(null);
170
+ var useIsMounted__INTERNAL = function () { return useContext(StytchMountedContext).isMounted; };
171
+ var useIsLazy__INTERNAL = function () { return useContext(StytchMountedContext).isLazy; };
172
+ var useStytchRaw__INTERNAL = function () { return useContext(StytchContext); };
173
+ var useStytchUser = function () {
174
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchUser'));
175
+ return useContext(StytchUserContext);
176
+ };
177
+ var useStytchSession = function () {
178
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchSession'));
179
+ return useContext(StytchSessionContext);
180
+ };
181
+ var useStytch = function () {
182
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytch'));
183
+ invariant(!useIsLazy__INTERNAL(), lazyError('useStytch'));
184
+ return useContext(StytchContext);
185
+ };
186
+ var useStytchLazy = function () {
187
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchLazy'));
188
+ return useContext(StytchContext);
189
+ };
190
+ var withStytch = function (Component) {
191
+ var WithStytch = function (props) {
192
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytch'));
193
+ invariant(!useIsLazy__INTERNAL(), lazyError('withStytch'));
194
+ return React.createElement(Component, __assign({}, props, { stytch: useStytch() }));
195
+ };
196
+ WithStytch.displayName = "withStytch(".concat(Component.displayName || Component.name || 'Component', ")");
197
+ return WithStytch;
198
+ };
199
+ var withStytchLazy = function (Component) {
200
+ var WithStytchLazy = function (props) {
201
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytchLazy'));
202
+ return React.createElement(Component, __assign({}, props, { stytch: useStytchLazy() }));
203
+ };
204
+ WithStytchLazy.displayName = "withStytchLazy(".concat(Component.displayName || Component.name || 'Component', ")");
205
+ return WithStytchLazy;
206
+ };
207
+ var withStytchUser = function (Component) {
208
+ var WithStytchUser = function (props) {
209
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytchUser'));
210
+ return React.createElement(Component, __assign({}, props, { stytchUser: useStytchUser() }));
211
+ };
212
+ WithStytchUser.displayName = "withStytchUser(".concat(Component.displayName || Component.name || 'Component', ")");
213
+ return WithStytchUser;
214
+ };
215
+ var withStytchSession = function (Component) {
216
+ var WithStytchSession = function (props) {
217
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytchSession'));
218
+ return React.createElement(Component, __assign({}, props, { stytchSession: useStytchSession() }));
219
+ };
220
+ WithStytchSession.displayName = "withStytchSession(".concat(Component.displayName || Component.name || 'Component', ")");
221
+ return WithStytchSession;
222
+ };
223
+ var StytchProvider = function (_a) {
224
+ var stytch = _a.stytch, children = _a.children;
225
+ invariant(!useIsMounted__INTERNAL(), 'You cannot render a <StytchProvider> inside another <StytchProvider>.');
226
+ var _b = useState(stytch instanceof Promise || !stytch ? null : stytch), stytchClient = _b[0], setStytchClient = _b[1];
227
+ var mountedContext = useState({
228
+ isLazy: !stytchClient,
229
+ isMounted: true,
230
+ })[0];
231
+ var _c = useState(stytchClient && stytchClient.user.getSync()), user = _c[0], setUser = _c[1];
232
+ var _d = useState(stytchClient && stytchClient.session.getSync()), session = _d[0], setSession = _d[1];
105
233
  useEffect(function () {
106
- // If we pass the function in directly React will execute it as a SetStateAction
107
- // Need to wrap in an anon - see https://medium.com/swlh/how-to-store-a-function-with-the-usestate-hook-in-react-8a88dd4eede1
108
- loadStytch().then(function (globalStytch) { return setStytchFactory(function () { return globalStytch; }); });
109
- }, []);
110
- return stytchFactory;
234
+ if (stytch instanceof Promise) {
235
+ stytch.then(setStytchClient);
236
+ }
237
+ }, [stytch]);
238
+ useEffect(function () {
239
+ if (stytchClient) {
240
+ if (mountedContext.isLazy) {
241
+ setUser(stytchClient.user.getSync());
242
+ setSession(stytchClient.session.getSync());
243
+ }
244
+ var unsubscribeUser_1 = stytchClient.user.onChange(setUser);
245
+ var unsubscribeSession_1 = stytchClient.session.onChange(setSession);
246
+ return function () {
247
+ unsubscribeUser_1();
248
+ unsubscribeSession_1();
249
+ };
250
+ }
251
+ }, [mountedContext, stytchClient]);
252
+ return (React.createElement(StytchMountedContext.Provider, { value: mountedContext },
253
+ React.createElement(StytchContext.Provider, { value: stytchClient },
254
+ React.createElement(StytchUserContext.Provider, { value: session && user },
255
+ React.createElement(StytchSessionContext.Provider, { value: user && session }, children)))));
111
256
  };
257
+
112
258
  /**
113
259
  * Returns a unique element ID.
114
260
  * Client-side only - will return null for server-side
@@ -119,7 +265,7 @@ var useUniqueElementId = function () {
119
265
  var _a = useState(null), elementId = _a[0], setElementId = _a[1];
120
266
  useEffect(function () {
121
267
  var randId = Math.floor(Math.random() * 1e6);
122
- setElementId("stytch-magic-link-" + randId);
268
+ setElementId("stytch-magic-link-".concat(randId));
123
269
  }, []);
124
270
  return elementId;
125
271
  };
@@ -128,25 +274,49 @@ var useUniqueElementId = function () {
128
274
  *
129
275
  * [Documentation](https://stytch.com/docs/javascript-sdk)
130
276
  */
131
- var Stytch = function (props) {
132
- var StytchFactory = useStytchFactory();
277
+ var Stytch = function (_a) {
278
+ var publicToken = _a.publicToken, style = _a.style, callbacks = _a.callbacks, loginOrSignupView = _a.loginOrSignupView;
279
+ var stytchClientFromContext = useStytchRaw__INTERNAL();
280
+ var stytchMounted = useIsMounted__INTERNAL();
281
+ var _b = useState(function () {
282
+ // If StytchProvider has been mounted, use context value
283
+ if (stytchMounted) {
284
+ return stytchClientFromContext;
285
+ }
286
+ // If StytchProvider isn't used, publicToken must be provided
287
+ invariant(publicToken, 'The Stytch component must either be inside a <StytchProvider> or provided the publicToken prop.');
288
+ // If Stytch has already been loaded, use global value
289
+ if (typeof window !== undefined && window.Stytch) {
290
+ return window.Stytch(publicToken);
291
+ }
292
+ // Otherwise, we will load Stytch
293
+ return null;
294
+ }), stytchClient = _b[0], setStytchClient = _b[1];
133
295
  var elementId = useUniqueElementId();
134
- var publicToken = props.publicToken, style = props.style, callbacks = props.callbacks, loginOrSignupView = props.loginOrSignupView;
135
296
  useEffect(function () {
136
- if (!StytchFactory || !elementId) {
297
+ if (!stytchClient) {
298
+ if (!stytchMounted) {
299
+ loadStytch().then(function (globalStytch) { return globalStytch && setStytchClient(globalStytch(publicToken)); });
300
+ }
301
+ else if (stytchClientFromContext) {
302
+ setStytchClient(stytchClientFromContext);
303
+ }
304
+ }
305
+ }, [stytchClient, stytchClientFromContext, stytchMounted, publicToken]);
306
+ useEffect(function () {
307
+ if (!stytchClient || !elementId) {
137
308
  return;
138
309
  }
139
- var stytch = StytchFactory(publicToken, callbacks);
140
- stytch.mount({
141
- elementId: "#" + elementId,
142
- style: style,
310
+ stytchClient.mount({
311
+ callbacks: callbacks,
312
+ elementId: "#".concat(elementId),
143
313
  loginOrSignupView: loginOrSignupView,
314
+ style: style,
144
315
  });
145
- }, [StytchFactory, elementId]);
146
- return elementId ?
147
- React.createElement("div", { id: elementId }) :
148
- null;
316
+ // eslint-disable-next-line react-hooks/exhaustive-deps
317
+ }, [elementId, stytchClient]);
318
+ return elementId ? React.createElement("div", { id: elementId }) : null;
149
319
  };
150
320
 
151
- export { OAuthProvidersTypes, SDKProductTypes, Stytch };
321
+ export { OAuthProvidersTypes, OneTapPositions, SDKProductTypes, Stytch, StytchProvider, initStytch, loadAndInitStytch, useStytch, useStytchLazy, useStytchSession, useStytchUser, withStytch, withStytchLazy, withStytchSession, withStytchUser };
152
322
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../node_modules/@stytch/stytch-js/dist/index.esm.js","../src/Stytch.tsx"],"sourcesContent":["var PUBLIC_URL = 'https://js.stytch.com/stytch.js';\nfunction getJSUrl() {\n try {\n if (process.env.STYTCH_JS_SDK_URL) {\n return process.env.STYTCH_JS_SDK_URL;\n }\n if (process.env.REACT_APP_STYTCH_JS_SDK_URL) {\n return process.env.REACT_APP_STYTCH_JS_SDK_URL;\n }\n if (process.env.NEXT_PUBLIC_STYTCH_JS_SDK_URL) {\n return process.env.NEXT_PUBLIC_STYTCH_JS_SDK_URL;\n }\n if (process.env.STORYBOOK_STYTCH_JS_SDK_URL) {\n return process.env.STORYBOOK_STYTCH_JS_SDK_URL;\n }\n return PUBLIC_URL;\n }\n catch (err) {\n return PUBLIC_URL;\n }\n}\nvar STYTCH_JS_URL = getJSUrl();\n\nvar findOrCreateScript = function () {\n var scripts = document.querySelectorAll(\"script[src=\\\"\" + STYTCH_JS_URL + \"\\\"]\");\n if (scripts[0]) {\n return scripts[0];\n }\n var script = document.createElement('script');\n script.src = STYTCH_JS_URL;\n document.head.appendChild(script);\n return script;\n};\nvar loadScript = function () {\n var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';\n if (!isBrowser) {\n return Promise.resolve(null);\n }\n return new Promise(function (resolve, reject) {\n if (window.Stytch) {\n console.warn('Stytch.js has already been loaded');\n resolve(window.Stytch);\n }\n var script = findOrCreateScript();\n script.addEventListener('load', function () {\n if (window.Stytch) {\n resolve(window.Stytch);\n }\n else {\n reject(new Error('Stytch.js could not be loaded'));\n }\n });\n script.addEventListener('error', function () {\n reject(new Error('Stytch.js could not be loaded'));\n });\n });\n};\n// Execute our own script injection after a tick to give users time to do their\n// own script injection.\nvar stytchPromise = Promise.resolve().then(function () { return loadScript(); });\nvar loadCalled = false;\n// We will log a warning if it doesn't look like the host code has checked or invoked the promise\nstytchPromise.catch(function (err) {\n if (!loadCalled) {\n console.warn(err);\n }\n});\nvar loadStytch = function () {\n loadCalled = true;\n return stytchPromise;\n};\n\n// Callback types\nvar EventType;\n(function (EventType) {\n EventType[\"CallbackEvent\"] = \"CALLBACK_EVENT\";\n EventType[\"ErrorEvent\"] = \"ERROR_EVENT\";\n EventType[\"SuccessEvent\"] = \"SUCCESS_EVENT\";\n})(EventType || (EventType = {}));\nvar CallbackEventType;\n(function (CallbackEventType) {\n CallbackEventType[\"UserEventType\"] = \"USER_EVENT_TYPE\";\n})(CallbackEventType || (CallbackEventType = {}));\nvar SDKProductTypes;\n(function (SDKProductTypes) {\n SDKProductTypes[\"emailMagicLinks\"] = \"emailMagicLinks\";\n SDKProductTypes[\"oauth\"] = \"oauth\";\n})(SDKProductTypes || (SDKProductTypes = {}));\nvar OAuthProvidersTypes;\n(function (OAuthProvidersTypes) {\n OAuthProvidersTypes[\"Google\"] = \"google\";\n OAuthProvidersTypes[\"Microsoft\"] = \"microsoft\";\n OAuthProvidersTypes[\"Apple\"] = \"apple\";\n})(OAuthProvidersTypes || (OAuthProvidersTypes = {}));\nvar OneTapPositions;\n(function (OneTapPositions) {\n OneTapPositions[\"embedded\"] = \"embedded\";\n OneTapPositions[\"floating\"] = \"floating\";\n})(OneTapPositions || (OneTapPositions = {}));\n\nexport { CallbackEventType, EventType, OAuthProvidersTypes, OneTapPositions, SDKProductTypes, loadStytch };\n//# sourceMappingURL=index.esm.js.map\n","import React, {useEffect, useState} from \"react\";\nimport {loadStytch, LoginOrSignupView, StyleConfig, CallbackOptions, StytchFactory} from '@stytch/stytch-js'\n\nexport {SDKProductTypes, OAuthProvidersTypes} from '@stytch/stytch-js'\n\nexport interface StytchProps {\n publicToken: string;\n loginOrSignupView?: LoginOrSignupView;\n style?: StyleConfig;\n callbacks?: CallbackOptions;\n}\n\nconst useStytchFactory = (): StytchFactory => {\n const [stytchFactory, setStytchFactory] = useState<StytchFactory>();\n useEffect(() => {\n // If we pass the function in directly React will execute it as a SetStateAction\n // Need to wrap in an anon - see https://medium.com/swlh/how-to-store-a-function-with-the-usestate-hook-in-react-8a88dd4eede1\n loadStytch().then(globalStytch => setStytchFactory(() => globalStytch))\n }, []);\n\n return stytchFactory;\n}\n\n/**\n * Returns a unique element ID.\n * Client-side only - will return null for server-side\n * resolves: https://stytch.slack.com/archives/C015UDB4X33/p1641450131000800\n * based on: https://github.com/vercel/next.js/issues/7322#issuecomment-968858477\n */\nconst useUniqueElementId = (): string | null => {\n const [elementId, setElementId] = useState<string | null>(null);\n useEffect(() => {\n const randId = Math.floor(Math.random() * 1e6);\n setElementId(`stytch-magic-link-${randId}`);\n }, [])\n return elementId;\n}\n\n/**\n * Stytch JS React Component\n *\n * [Documentation](https://stytch.com/docs/javascript-sdk)\n */\nexport const Stytch = (props: StytchProps) => {\n const StytchFactory = useStytchFactory();\n const elementId = useUniqueElementId();\n\n const {publicToken, style, callbacks, loginOrSignupView} = props;\n\n useEffect(() => {\n if (!StytchFactory || !elementId) {\n return;\n }\n const stytch = StytchFactory(publicToken, callbacks);\n\n stytch.mount({\n elementId: `#${elementId}`,\n style,\n loginOrSignupView,\n });\n }, [StytchFactory, elementId]);\n\n return elementId ?\n <div id={elementId}></div> :\n null;\n};\n"],"names":[],"mappings":";;AAAA,IAAI,UAAU,GAAG,iCAAiC,CAAC;AACnD,SAAS,QAAQ,GAAG;AACpB,IAAI,IAAI;AACR,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE;AAC3C,YAAY,OAAO,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;AACjD,SAAS;AACT,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE;AACrD,YAAY,OAAO,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC;AAC3D,SAAS;AACT,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE;AACvD,YAAY,OAAO,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC;AAC7D,SAAS;AACT,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE;AACrD,YAAY,OAAO,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC;AAC3D,SAAS;AACT,QAAQ,OAAO,UAAU,CAAC;AAC1B,KAAK;AACL,IAAI,OAAO,GAAG,EAAE;AAChB,QAAQ,OAAO,UAAU,CAAC;AAC1B,KAAK;AACL,CAAC;AACD,IAAI,aAAa,GAAG,QAAQ,EAAE,CAAC;AAC/B;AACA,IAAI,kBAAkB,GAAG,YAAY;AACrC,IAAI,IAAI,OAAO,GAAG,QAAQ,CAA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AY,CAAC,uBAAqB,MAAQ,CAAC,CAAC;KAC7C,EAAE,EAAE,CAAC,CAAA;IACN,OAAO,SAAS,CAAC;AACnB,CAAC,CAAA;AAED;;;;;IAKa,MAAM,GAAG,UAAC,KAAkB;IACvC,IAAM,aAAa,GAAG,gBAAgB,EAAE,CAAC;IACzC,IAAM,SAAS,GAAG,kBAAkB,EAAE,CAAC;IAEhC,IAAA,WAAW,GAAyC,KAAK,YAA9C,EAAE,KAAK,GAAkC,KAAK,MAAvC,EAAE,SAAS,GAAuB,KAAK,UAA5B,EAAE,iBAAiB,GAAI,KAAK,kBAAT,CAAU;IAEjE,SAAS,CAAC;QACR,IAAI,CAAC,aAAa,IAAI,CAAC,SAAS,EAAE;YAChC,OAAO;SACR;QACD,IAAM,MAAM,GAAG,aAAa,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAErD,MAAM,CAAC,KAAK,CAAC;YACX,SAAS,EAAE,MAAI,SAAW;YAC1B,KAAK,OAAA;YACL,iBAAiB,mBAAA;SAClB,CAAC,CAAC;KACJ,EAAE,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC;IAE/B,OAAO,SAAS;QACd,6BAAK,EAAE,EAAE,SAAS,GAAQ;QAC1B,IAAI,CAAC;AACT;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../node_modules/@stytch/stytch-js/dist/index.esm.js","../src/utils/invariant.ts","../node_modules/tslib/tslib.es6.js","../src/utils/errors.ts","../src/StytchContext.tsx","../src/Stytch.tsx"],"sourcesContent":["var PUBLIC_URL = 'https://js.stytch.com/stytch.js';\nfunction getJSUrl() {\n try {\n if (process.env.STYTCH_JS_SDK_URL) {\n return process.env.STYTCH_JS_SDK_URL;\n }\n if (process.env.REACT_APP_STYTCH_JS_SDK_URL) {\n return process.env.REACT_APP_STYTCH_JS_SDK_URL;\n }\n if (process.env.NEXT_PUBLIC_STYTCH_JS_SDK_URL) {\n return process.env.NEXT_PUBLIC_STYTCH_JS_SDK_URL;\n }\n if (process.env.STORYBOOK_STYTCH_JS_SDK_URL) {\n return process.env.STORYBOOK_STYTCH_JS_SDK_URL;\n }\n return PUBLIC_URL;\n }\n catch (err) {\n return PUBLIC_URL;\n }\n}\nvar STYTCH_JS_URL = getJSUrl();\n\nvar findOrCreateScript = function () {\n var scripts = document.querySelectorAll(\"script[src=\\\"\" + STYTCH_JS_URL + \"\\\"]\");\n if (scripts[0]) {\n return scripts[0];\n }\n var script = document.createElement('script');\n script.src = STYTCH_JS_URL;\n document.head.appendChild(script);\n return script;\n};\nvar loadScript = function () {\n var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';\n if (!isBrowser) {\n return Promise.resolve(null);\n }\n return new Promise(function (resolve, reject) {\n if (window.Stytch) {\n console.warn('Stytch.js has already been loaded');\n resolve(window.Stytch);\n }\n var script = findOrCreateScript();\n script.addEventListener('load', function () {\n if (window.Stytch) {\n resolve(window.Stytch);\n }\n else {\n reject(new Error('Stytch.js could not be loaded'));\n }\n });\n script.addEventListener('error', function () {\n reject(new Error('Stytch.js could not be loaded'));\n });\n });\n};\n// Execute our own script injection after a tick to give users time to do their\n// own script injection.\nvar stytchPromise = Promise.resolve().then(function () { return loadScript(); });\nvar loadCalled = false;\n// We will log a warning if it doesn't look like the host code has checked or invoked the promise\nstytchPromise.catch(function (err) {\n if (!loadCalled) {\n console.warn(err);\n }\n});\nvar loadStytch = function () {\n loadCalled = true;\n return stytchPromise;\n};\n\n// Callback types\nvar EventType;\n(function (EventType) {\n EventType[\"CallbackEvent\"] = \"CALLBACK_EVENT\";\n EventType[\"ErrorEvent\"] = \"ERROR_EVENT\";\n EventType[\"SuccessEvent\"] = \"SUCCESS_EVENT\";\n})(EventType || (EventType = {}));\nvar CallbackEventType;\n(function (CallbackEventType) {\n CallbackEventType[\"UserEventType\"] = \"USER_EVENT_TYPE\";\n})(CallbackEventType || (CallbackEventType = {}));\nvar SDKProductTypes;\n(function (SDKProductTypes) {\n SDKProductTypes[\"emailMagicLinks\"] = \"emailMagicLinks\";\n SDKProductTypes[\"oauth\"] = \"oauth\";\n})(SDKProductTypes || (SDKProductTypes = {}));\nvar OAuthProvidersTypes;\n(function (OAuthProvidersTypes) {\n OAuthProvidersTypes[\"Google\"] = \"google\";\n OAuthProvidersTypes[\"Microsoft\"] = \"microsoft\";\n OAuthProvidersTypes[\"Apple\"] = \"apple\";\n OAuthProvidersTypes[\"Github\"] = \"github\";\n OAuthProvidersTypes[\"Facebook\"] = \"facebook\";\n})(OAuthProvidersTypes || (OAuthProvidersTypes = {}));\nvar OneTapPositions;\n(function (OneTapPositions) {\n OneTapPositions[\"embedded\"] = \"embedded\";\n OneTapPositions[\"floating\"] = \"floating\";\n})(OneTapPositions || (OneTapPositions = {}));\n\nvar initStytch = function () {\n var args = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n }\n if (typeof window === 'undefined') {\n return null;\n }\n if (!window.Stytch) {\n throw new Error('Stytch has not been loaded.');\n }\n return window.Stytch.apply(window, args);\n};\nvar loadAndInitStytch = function () {\n var args = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n }\n return loadStytch().then(function (stytchFactory) { return stytchFactory && stytchFactory.apply(void 0, args); });\n};\n\nexport { CallbackEventType, EventType, OAuthProvidersTypes, OneTapPositions, SDKProductTypes, initStytch, loadAndInitStytch, loadStytch };\n//# sourceMappingURL=index.esm.js.map\n","// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function invariant(cond: any, message: string): asserts cond {\n if (!cond) throw new Error(message);\n}\n","/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n","export const noProviderError = (hookOrHOC: string): string => `${hookOrHOC} can only be used inside <StytchProvider>.`;\n\nexport const lazyError = (hookOrHOC: string): string =>\n `${hookOrHOC} can only be used if Stytch is preloaded. Add <script src=\"https://js.stytch.com/stytch.js\" /> in your document header to load the script synchronously, or use ${hookOrHOC}Lazy if you want to lazy load Stytch. If you are using SSR, you will need to use ${hookOrHOC}Lazy.`;\n","import { Session, StytchClient, User } from '@stytch/stytch-js';\nimport React, { ComponentType, createContext, ReactNode, useContext, useEffect, useState } from 'react';\n\nimport { lazyError, noProviderError } from 'utils/errors';\nimport { invariant } from 'utils/invariant';\n\ntype StytchMountedContextType = {\n isMounted: boolean;\n isLazy: boolean;\n};\n\nconst StytchMountedContext = createContext<StytchMountedContextType>({\n isLazy: false,\n isMounted: false,\n});\nconst StytchUserContext = createContext<User | null>(null);\nconst StytchSessionContext = createContext<Session | null>(null);\nconst StytchContext = createContext<StytchClient | null>(null);\n\nexport const useIsMounted__INTERNAL = (): boolean => useContext(StytchMountedContext).isMounted;\nexport const useIsLazy__INTERNAL = (): boolean => useContext(StytchMountedContext).isLazy;\nexport const useStytchRaw__INTERNAL = (): StytchClient | null => useContext(StytchContext);\n\nexport const useStytchUser = (): User | null => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchUser'));\n return useContext(StytchUserContext);\n};\nexport const useStytchSession = (): Session | null => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchSession'));\n return useContext(StytchSessionContext);\n};\nexport const useStytch = (): StytchClient => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytch'));\n invariant(!useIsLazy__INTERNAL(), lazyError('useStytch'));\n return useContext(StytchContext);\n};\nexport const useStytchLazy = (): StytchClient => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchLazy'));\n return useContext(StytchContext);\n};\n\nexport const withStytch = <T extends object>(\n Component: ComponentType<T & { stytch: StytchClient }>,\n): ComponentType<T> => {\n const WithStytch: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytch'));\n invariant(!useIsLazy__INTERNAL(), lazyError('withStytch'));\n return <Component {...props} stytch={useStytch()} />;\n };\n WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;\n return WithStytch;\n};\nexport const withStytchLazy = <T extends object>(\n Component: ComponentType<T & { stytch: StytchClient | null }>,\n): ComponentType<T> => {\n const WithStytchLazy: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchLazy'));\n return <Component {...props} stytch={useStytchLazy()} />;\n };\n WithStytchLazy.displayName = `withStytchLazy(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchLazy;\n};\nexport const withStytchUser = <T extends object>(\n Component: ComponentType<T & { stytchUser: User | null }>,\n): ComponentType<T> => {\n const WithStytchUser: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchUser'));\n return <Component {...props} stytchUser={useStytchUser()} />;\n };\n WithStytchUser.displayName = `withStytchUser(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchUser;\n};\nexport const withStytchSession = <T extends object>(\n Component: ComponentType<T & { stytchSession: Session | null }>,\n): ComponentType<T> => {\n const WithStytchSession: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchSession'));\n return <Component {...props} stytchSession={useStytchSession()} />;\n };\n WithStytchSession.displayName = `withStytchSession(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchSession;\n};\n\nexport type StytchProviderProps = {\n stytch: StytchClient | null | Promise<StytchClient | null>;\n children?: ReactNode;\n};\n\nexport const StytchProvider = ({ stytch, children }: StytchProviderProps): JSX.Element => {\n invariant(!useIsMounted__INTERNAL(), 'You cannot render a <StytchProvider> inside another <StytchProvider>.');\n const [stytchClient, setStytchClient] = useState<StytchClient | null>(\n stytch instanceof Promise || !stytch ? null : stytch,\n );\n const [mountedContext] = useState<StytchMountedContextType>({\n isLazy: !stytchClient,\n isMounted: true,\n });\n const [user, setUser] = useState<User | null>(stytchClient && stytchClient.user.getSync());\n const [session, setSession] = useState<Session | null>(stytchClient && stytchClient.session.getSync());\n\n useEffect(() => {\n if (stytch instanceof Promise) {\n stytch.then(setStytchClient);\n }\n }, [stytch]);\n\n useEffect(() => {\n if (stytchClient) {\n if (mountedContext.isLazy) {\n setUser(stytchClient.user.getSync());\n setSession(stytchClient.session.getSync());\n }\n const unsubscribeUser = stytchClient.user.onChange(setUser);\n const unsubscribeSession = stytchClient.session.onChange(setSession);\n return () => {\n unsubscribeUser();\n unsubscribeSession();\n };\n }\n }, [mountedContext, stytchClient]);\n\n return (\n <StytchMountedContext.Provider value={mountedContext}>\n <StytchContext.Provider value={stytchClient}>\n <StytchUserContext.Provider value={session && user}>\n <StytchSessionContext.Provider value={user && session}>{children}</StytchSessionContext.Provider>\n </StytchUserContext.Provider>\n </StytchContext.Provider>\n </StytchMountedContext.Provider>\n );\n};\n","import { CallbackOptions, loadStytch, LoginOrSignupView, StyleConfig, StytchClient } from '@stytch/stytch-js';\nimport React, { useEffect, useState } from 'react';\n\nimport { invariant } from 'utils/invariant';\n\nimport { useIsMounted__INTERNAL, useStytchRaw__INTERNAL } from './StytchContext';\n\nexport interface StytchProps {\n publicToken?: string;\n loginOrSignupView?: LoginOrSignupView;\n style?: StyleConfig;\n callbacks?: CallbackOptions;\n}\n\n/**\n * Returns a unique element ID.\n * Client-side only - will return null for server-side\n * resolves: https://stytch.slack.com/archives/C015UDB4X33/p1641450131000800\n * based on: https://github.com/vercel/next.js/issues/7322#issuecomment-968858477\n */\nconst useUniqueElementId = (): string | null => {\n const [elementId, setElementId] = useState<string | null>(null);\n useEffect(() => {\n const randId = Math.floor(Math.random() * 1e6);\n setElementId(`stytch-magic-link-${randId}`);\n }, []);\n return elementId;\n};\n\n/**\n * Stytch JS React Component\n *\n * [Documentation](https://stytch.com/docs/javascript-sdk)\n */\nexport const Stytch = ({ publicToken, style, callbacks, loginOrSignupView }: StytchProps) => {\n const stytchClientFromContext = useStytchRaw__INTERNAL();\n const stytchMounted = useIsMounted__INTERNAL();\n const [stytchClient, setStytchClient] = useState<StytchClient | null>(() => {\n // If StytchProvider has been mounted, use context value\n if (stytchMounted) {\n return stytchClientFromContext;\n }\n // If StytchProvider isn't used, publicToken must be provided\n invariant(\n publicToken,\n 'The Stytch component must either be inside a <StytchProvider> or provided the publicToken prop.',\n );\n // If Stytch has already been loaded, use global value\n if (typeof window !== undefined && window.Stytch) {\n return window.Stytch(publicToken);\n }\n // Otherwise, we will load Stytch\n return null;\n });\n const elementId = useUniqueElementId();\n\n useEffect(() => {\n if (!stytchClient) {\n if (!stytchMounted) {\n loadStytch().then((globalStytch) => globalStytch && setStytchClient(globalStytch(publicToken)));\n } else if (stytchClientFromContext) {\n setStytchClient(stytchClientFromContext);\n }\n }\n }, [stytchClient, stytchClientFromContext, stytchMounted, publicToken]);\n\n useEffect(() => {\n if (!stytchClient || !elementId) {\n return;\n }\n\n stytchClient.mount({\n callbacks,\n elementId: `#${elementId}`,\n loginOrSignupView,\n style,\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [elementId, stytchClient]);\n\n return elementId ? <div id={elementId}></div> : null;\n};\n"],"names":[],"mappings":";;AAAA,IAAI,UAAU,GAAG,iCAAiC,CAAC;AACnD,SAAS,QA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] = "google";
102
102
  OAuthProvidersTypes["Microsoft"] = "microsoft";
103
103
  OAuthProvidersTypes["Apple"] = "apple";
104
+ OAuthProvidersTypes["Github"] = "github";
105
+ OAuthProvidersTypes["Facebook"] = "facebook";
104
106
  })(exports.OAuthProvidersTypes || (exports.OAuthProvidersTypes = {}));
105
- var OneTapPositions;
107
+ exports.OneTapPositions = void 0;
106
108
  (function (OneTapPositions) {
107
109
  OneTapPositions["embedded"] = "embedded";
108
110
  OneTapPositions["floating"] = "floating";
109
- })(OneTapPositions || (OneTapPositions = {}));
111
+ })(exports.OneTapPositions || (exports.OneTapPositions = {}));
110
112
 
111
- var useStytchFactory = function () {
112
- var _a = React.useState(), stytchFactory = _a[0], setStytchFactory = _a[1];
113
+ var initStytch = function () {
114
+ var args = [];
115
+ for (var _i = 0; _i < arguments.length; _i++) {
116
+ args[_i] = arguments[_i];
117
+ }
118
+ if (typeof window === 'undefined') {
119
+ return null;
120
+ }
121
+ if (!window.Stytch) {
122
+ throw new Error('Stytch has not been loaded.');
123
+ }
124
+ return window.Stytch.apply(window, args);
125
+ };
126
+ var loadAndInitStytch = function () {
127
+ var args = [];
128
+ for (var _i = 0; _i < arguments.length; _i++) {
129
+ args[_i] = arguments[_i];
130
+ }
131
+ return loadStytch().then(function (stytchFactory) { return stytchFactory && stytchFactory.apply(void 0, args); });
132
+ };
133
+
134
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
135
+ function invariant(cond, message) {
136
+ if (!cond)
137
+ throw new Error(message);
138
+ }
139
+
140
+ /*! *****************************************************************************
141
+ Copyright (c) Microsoft Corporation.
142
+
143
+ Permission to use, copy, modify, and/or distribute this software for any
144
+ purpose with or without fee is hereby granted.
145
+
146
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
147
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
148
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
149
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
150
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
151
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
152
+ PERFORMANCE OF THIS SOFTWARE.
153
+ ***************************************************************************** */
154
+
155
+ var __assign = function() {
156
+ __assign = Object.assign || function __assign(t) {
157
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
158
+ s = arguments[i];
159
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
160
+ }
161
+ return t;
162
+ };
163
+ return __assign.apply(this, arguments);
164
+ };
165
+
166
+ var noProviderError = function (hookOrHOC) { return "".concat(hookOrHOC, " can only be used inside <StytchProvider>."); };
167
+ var lazyError = function (hookOrHOC) {
168
+ return "".concat(hookOrHOC, " can only be used if Stytch is preloaded. Add <script src=\"https://js.stytch.com/stytch.js\" /> in your document header to load the script synchronously, or use ").concat(hookOrHOC, "Lazy if you want to lazy load Stytch. If you are using SSR, you will need to use ").concat(hookOrHOC, "Lazy.");
169
+ };
170
+
171
+ var StytchMountedContext = React.createContext({
172
+ isLazy: false,
173
+ isMounted: false,
174
+ });
175
+ var StytchUserContext = React.createContext(null);
176
+ var StytchSessionContext = React.createContext(null);
177
+ var StytchContext = React.createContext(null);
178
+ var useIsMounted__INTERNAL = function () { return React.useContext(StytchMountedContext).isMounted; };
179
+ var useIsLazy__INTERNAL = function () { return React.useContext(StytchMountedContext).isLazy; };
180
+ var useStytchRaw__INTERNAL = function () { return React.useContext(StytchContext); };
181
+ var useStytchUser = function () {
182
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchUser'));
183
+ return React.useContext(StytchUserContext);
184
+ };
185
+ var useStytchSession = function () {
186
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchSession'));
187
+ return React.useContext(StytchSessionContext);
188
+ };
189
+ var useStytch = function () {
190
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytch'));
191
+ invariant(!useIsLazy__INTERNAL(), lazyError('useStytch'));
192
+ return React.useContext(StytchContext);
193
+ };
194
+ var useStytchLazy = function () {
195
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchLazy'));
196
+ return React.useContext(StytchContext);
197
+ };
198
+ var withStytch = function (Component) {
199
+ var WithStytch = function (props) {
200
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytch'));
201
+ invariant(!useIsLazy__INTERNAL(), lazyError('withStytch'));
202
+ return React__default["default"].createElement(Component, __assign({}, props, { stytch: useStytch() }));
203
+ };
204
+ WithStytch.displayName = "withStytch(".concat(Component.displayName || Component.name || 'Component', ")");
205
+ return WithStytch;
206
+ };
207
+ var withStytchLazy = function (Component) {
208
+ var WithStytchLazy = function (props) {
209
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytchLazy'));
210
+ return React__default["default"].createElement(Component, __assign({}, props, { stytch: useStytchLazy() }));
211
+ };
212
+ WithStytchLazy.displayName = "withStytchLazy(".concat(Component.displayName || Component.name || 'Component', ")");
213
+ return WithStytchLazy;
214
+ };
215
+ var withStytchUser = function (Component) {
216
+ var WithStytchUser = function (props) {
217
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytchUser'));
218
+ return React__default["default"].createElement(Component, __assign({}, props, { stytchUser: useStytchUser() }));
219
+ };
220
+ WithStytchUser.displayName = "withStytchUser(".concat(Component.displayName || Component.name || 'Component', ")");
221
+ return WithStytchUser;
222
+ };
223
+ var withStytchSession = function (Component) {
224
+ var WithStytchSession = function (props) {
225
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytchSession'));
226
+ return React__default["default"].createElement(Component, __assign({}, props, { stytchSession: useStytchSession() }));
227
+ };
228
+ WithStytchSession.displayName = "withStytchSession(".concat(Component.displayName || Component.name || 'Component', ")");
229
+ return WithStytchSession;
230
+ };
231
+ var StytchProvider = function (_a) {
232
+ var stytch = _a.stytch, children = _a.children;
233
+ invariant(!useIsMounted__INTERNAL(), 'You cannot render a <StytchProvider> inside another <StytchProvider>.');
234
+ var _b = React.useState(stytch instanceof Promise || !stytch ? null : stytch), stytchClient = _b[0], setStytchClient = _b[1];
235
+ var mountedContext = React.useState({
236
+ isLazy: !stytchClient,
237
+ isMounted: true,
238
+ })[0];
239
+ var _c = React.useState(stytchClient && stytchClient.user.getSync()), user = _c[0], setUser = _c[1];
240
+ var _d = React.useState(stytchClient && stytchClient.session.getSync()), session = _d[0], setSession = _d[1];
113
241
  React.useEffect(function () {
114
- // If we pass the function in directly React will execute it as a SetStateAction
115
- // Need to wrap in an anon - see https://medium.com/swlh/how-to-store-a-function-with-the-usestate-hook-in-react-8a88dd4eede1
116
- loadStytch().then(function (globalStytch) { return setStytchFactory(function () { return globalStytch; }); });
117
- }, []);
118
- return stytchFactory;
242
+ if (stytch instanceof Promise) {
243
+ stytch.then(setStytchClient);
244
+ }
245
+ }, [stytch]);
246
+ React.useEffect(function () {
247
+ if (stytchClient) {
248
+ if (mountedContext.isLazy) {
249
+ setUser(stytchClient.user.getSync());
250
+ setSession(stytchClient.session.getSync());
251
+ }
252
+ var unsubscribeUser_1 = stytchClient.user.onChange(setUser);
253
+ var unsubscribeSession_1 = stytchClient.session.onChange(setSession);
254
+ return function () {
255
+ unsubscribeUser_1();
256
+ unsubscribeSession_1();
257
+ };
258
+ }
259
+ }, [mountedContext, stytchClient]);
260
+ return (React__default["default"].createElement(StytchMountedContext.Provider, { value: mountedContext },
261
+ React__default["default"].createElement(StytchContext.Provider, { value: stytchClient },
262
+ React__default["default"].createElement(StytchUserContext.Provider, { value: session && user },
263
+ React__default["default"].createElement(StytchSessionContext.Provider, { value: user && session }, children)))));
119
264
  };
265
+
120
266
  /**
121
267
  * Returns a unique element ID.
122
268
  * Client-side only - will return null for server-side
@@ -127,7 +273,7 @@ var useUniqueElementId = function () {
127
273
  var _a = React.useState(null), elementId = _a[0], setElementId = _a[1];
128
274
  React.useEffect(function () {
129
275
  var randId = Math.floor(Math.random() * 1e6);
130
- setElementId("stytch-magic-link-" + randId);
276
+ setElementId("stytch-magic-link-".concat(randId));
131
277
  }, []);
132
278
  return elementId;
133
279
  };
@@ -136,25 +282,60 @@ var useUniqueElementId = function () {
136
282
  *
137
283
  * [Documentation](https://stytch.com/docs/javascript-sdk)
138
284
  */
139
- var Stytch = function (props) {
140
- var StytchFactory = useStytchFactory();
285
+ var Stytch = function (_a) {
286
+ var publicToken = _a.publicToken, style = _a.style, callbacks = _a.callbacks, loginOrSignupView = _a.loginOrSignupView;
287
+ var stytchClientFromContext = useStytchRaw__INTERNAL();
288
+ var stytchMounted = useIsMounted__INTERNAL();
289
+ var _b = React.useState(function () {
290
+ // If StytchProvider has been mounted, use context value
291
+ if (stytchMounted) {
292
+ return stytchClientFromContext;
293
+ }
294
+ // If StytchProvider isn't used, publicToken must be provided
295
+ invariant(publicToken, 'The Stytch component must either be inside a <StytchProvider> or provided the publicToken prop.');
296
+ // If Stytch has already been loaded, use global value
297
+ if (typeof window !== undefined && window.Stytch) {
298
+ return window.Stytch(publicToken);
299
+ }
300
+ // Otherwise, we will load Stytch
301
+ return null;
302
+ }), stytchClient = _b[0], setStytchClient = _b[1];
141
303
  var elementId = useUniqueElementId();
142
- var publicToken = props.publicToken, style = props.style, callbacks = props.callbacks, loginOrSignupView = props.loginOrSignupView;
143
304
  React.useEffect(function () {
144
- if (!StytchFactory || !elementId) {
305
+ if (!stytchClient) {
306
+ if (!stytchMounted) {
307
+ loadStytch().then(function (globalStytch) { return globalStytch && setStytchClient(globalStytch(publicToken)); });
308
+ }
309
+ else if (stytchClientFromContext) {
310
+ setStytchClient(stytchClientFromContext);
311
+ }
312
+ }
313
+ }, [stytchClient, stytchClientFromContext, stytchMounted, publicToken]);
314
+ React.useEffect(function () {
315
+ if (!stytchClient || !elementId) {
145
316
  return;
146
317
  }
147
- var stytch = StytchFactory(publicToken, callbacks);
148
- stytch.mount({
149
- elementId: "#" + elementId,
150
- style: style,
318
+ stytchClient.mount({
319
+ callbacks: callbacks,
320
+ elementId: "#".concat(elementId),
151
321
  loginOrSignupView: loginOrSignupView,
322
+ style: style,
152
323
  });
153
- }, [StytchFactory, elementId]);
154
- return elementId ?
155
- React__default['default'].createElement("div", { id: elementId }) :
156
- null;
324
+ // eslint-disable-next-line react-hooks/exhaustive-deps
325
+ }, [elementId, stytchClient]);
326
+ return elementId ? React__default["default"].createElement("div", { id: elementId }) : null;
157
327
  };
158
328
 
159
329
  exports.Stytch = Stytch;
330
+ exports.StytchProvider = StytchProvider;
331
+ exports.initStytch = initStytch;
332
+ exports.loadAndInitStytch = loadAndInitStytch;
333
+ exports.useStytch = useStytch;
334
+ exports.useStytchLazy = useStytchLazy;
335
+ exports.useStytchSession = useStytchSession;
336
+ exports.useStytchUser = useStytchUser;
337
+ exports.withStytch = withStytch;
338
+ exports.withStytchLazy = withStytchLazy;
339
+ exports.withStytchSession = withStytchSession;
340
+ exports.withStytchUser = withStytchUser;
160
341
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../node_modules/@stytch/stytch-js/dist/index.esm.js","../src/Stytch.tsx"],"sourcesContent":["var PUBLIC_URL = 'https://js.stytch.com/stytch.js';\nfunction getJSUrl() {\n try {\n if (process.env.STYTCH_JS_SDK_URL) {\n return process.env.STYTCH_JS_SDK_URL;\n }\n if (process.env.REACT_APP_STYTCH_JS_SDK_URL) {\n return process.env.REACT_APP_STYTCH_JS_SDK_URL;\n }\n if (process.env.NEXT_PUBLIC_STYTCH_JS_SDK_URL) {\n return process.env.NEXT_PUBLIC_STYTCH_JS_SDK_URL;\n }\n if (process.env.STORYBOOK_STYTCH_JS_SDK_URL) {\n return process.env.STORYBOOK_STYTCH_JS_SDK_URL;\n }\n return PUBLIC_URL;\n }\n catch (err) {\n return PUBLIC_URL;\n }\n}\nvar STYTCH_JS_URL = getJSUrl();\n\nvar findOrCreateScript = function () {\n var scripts = document.querySelectorAll(\"script[src=\\\"\" + STYTCH_JS_URL + \"\\\"]\");\n if (scripts[0]) {\n return scripts[0];\n }\n var script = document.createElement('script');\n script.src = STYTCH_JS_URL;\n document.head.appendChild(script);\n return script;\n};\nvar loadScript = function () {\n var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';\n if (!isBrowser) {\n return Promise.resolve(null);\n }\n return new Promise(function (resolve, reject) {\n if (window.Stytch) {\n console.warn('Stytch.js has already been loaded');\n resolve(window.Stytch);\n }\n var script = findOrCreateScript();\n script.addEventListener('load', function () {\n if (window.Stytch) {\n resolve(window.Stytch);\n }\n else {\n reject(new Error('Stytch.js could not be loaded'));\n }\n });\n script.addEventListener('error', function () {\n reject(new Error('Stytch.js could not be loaded'));\n });\n });\n};\n// Execute our own script injection after a tick to give users time to do their\n// own script injection.\nvar stytchPromise = Promise.resolve().then(function () { return loadScript(); });\nvar loadCalled = false;\n// We will log a warning if it doesn't look like the host code has checked or invoked the promise\nstytchPromise.catch(function (err) {\n if (!loadCalled) {\n console.warn(err);\n }\n});\nvar loadStytch = function () {\n loadCalled = true;\n return stytchPromise;\n};\n\n// Callback types\nvar EventType;\n(function (EventType) {\n EventType[\"CallbackEvent\"] = \"CALLBACK_EVENT\";\n EventType[\"ErrorEvent\"] = \"ERROR_EVENT\";\n EventType[\"SuccessEvent\"] = \"SUCCESS_EVENT\";\n})(EventType || (EventType = {}));\nvar CallbackEventType;\n(function (CallbackEventType) {\n CallbackEventType[\"UserEventType\"] = \"USER_EVENT_TYPE\";\n})(CallbackEventType || (CallbackEventType = {}));\nvar SDKProductTypes;\n(function (SDKProductTypes) {\n SDKProductTypes[\"emailMagicLinks\"] = \"emailMagicLinks\";\n SDKProductTypes[\"oauth\"] = \"oauth\";\n})(SDKProductTypes || (SDKProductTypes = {}));\nvar OAuthProvidersTypes;\n(function (OAuthProvidersTypes) {\n OAuthProvidersTypes[\"Google\"] = \"google\";\n OAuthProvidersTypes[\"Microsoft\"] = \"microsoft\";\n OAuthProvidersTypes[\"Apple\"] = \"apple\";\n})(OAuthProvidersTypes || (OAuthProvidersTypes = {}));\nvar OneTapPositions;\n(function (OneTapPositions) {\n OneTapPositions[\"embedded\"] = \"embedded\";\n OneTapPositions[\"floating\"] = \"floating\";\n})(OneTapPositions || (OneTapPositions = {}));\n\nexport { CallbackEventType, EventType, OAuthProvidersTypes, OneTapPositions, SDKProductTypes, loadStytch };\n//# sourceMappingURL=index.esm.js.map\n","import React, {useEffect, useState} from \"react\";\nimport {loadStytch, LoginOrSignupView, StyleConfig, CallbackOptions, StytchFactory} from '@stytch/stytch-js'\n\nexport {SDKProductTypes, OAuthProvidersTypes} from '@stytch/stytch-js'\n\nexport interface StytchProps {\n publicToken: string;\n loginOrSignupView?: LoginOrSignupView;\n style?: StyleConfig;\n callbacks?: CallbackOptions;\n}\n\nconst useStytchFactory = (): StytchFactory => {\n const [stytchFactory, setStytchFactory] = useState<StytchFactory>();\n useEffect(() => {\n // If we pass the function in directly React will execute it as a SetStateAction\n // Need to wrap in an anon - see https://medium.com/swlh/how-to-store-a-function-with-the-usestate-hook-in-react-8a88dd4eede1\n loadStytch().then(globalStytch => setStytchFactory(() => globalStytch))\n }, []);\n\n return stytchFactory;\n}\n\n/**\n * Returns a unique element ID.\n * Client-side only - will return null for server-side\n * resolves: https://stytch.slack.com/archives/C015UDB4X33/p1641450131000800\n * based on: https://github.com/vercel/next.js/issues/7322#issuecomment-968858477\n */\nconst useUniqueElementId = (): string | null => {\n const [elementId, setElementId] = useState<string | null>(null);\n useEffect(() => {\n const randId = Math.floor(Math.random() * 1e6);\n setElementId(`stytch-magic-link-${randId}`);\n }, [])\n return elementId;\n}\n\n/**\n * Stytch JS React Component\n *\n * [Documentation](https://stytch.com/docs/javascript-sdk)\n */\nexport const Stytch = (props: StytchProps) => {\n const StytchFactory = useStytchFactory();\n const elementId = useUniqueElementId();\n\n const {publicToken, style, callbacks, loginOrSignupView} = props;\n\n useEffect(() => {\n if (!StytchFactory || !elementId) {\n return;\n }\n const stytch = StytchFactory(publicToken, callbacks);\n\n stytch.mount({\n elementId: `#${elementId}`,\n style,\n loginOrSignupView,\n });\n }, [StytchFactory, elementId]);\n\n return elementId ?\n <div id={elementId}></div> :\n null;\n};\n"],"names":["SDKProductTypes","OAuthProvidersTypes","useState","useEffect","React"],"mappings":";;;;;;;;;;AAAA,IAAI,UAAU,GAAG,iCAAiC,CAAC;AACnD,SAAS,QAAQ,GAAG;AACpB,IAAI,IAAI;AACR,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE;AAC3C,YAAY,OAAO,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;AACjD,SAAS;AACT,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE;AACrD,YAAY,OAAO,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC;AAC3D,SAAS;AACT,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE;AACvD,YAAY,OAAO,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC;AAC7D,SAAS;AACT,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE;AACrD,YAAY,OAAO,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC;AAC3D,SAAS;AACT,QAAQ,OAAO,UAAU,CAAC;AAC1B,KAAK;AACL,IAAI,OAAO,GAAG,EAAE;AAChB,QAAQ,OAAO,UAAU,CAAC;AAC1B,KAAK;AACL,CAAC;AACD,IAAI,aAAa,GAAG,QAAQ,EAAE,CAAC;AAC/B;AACA,IAAI,kBAAkB,GAAG,YAAY;AACrC,IAAI,IAAI,OAAO,GAAG,QAAQ,CAAC,gBAAgB,CAAC,eAAe,GAAG,aAAa,GAAG,KAAK,CAAC,CAAC;AACrF,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE;AACpB,QAAQ,OAAO,OAAO,CAAC,CAAC,CAAC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kB;IACvC,IAAM,aAAa,GAAG,gBAAgB,EAAE,CAAC;IACzC,IAAM,SAAS,GAAG,kBAAkB,EAAE,CAAC;IAEhC,IAAA,WAAW,GAAyC,KAAK,YAA9C,EAAE,KAAK,GAAkC,KAAK,MAAvC,EAAE,SAAS,GAAuB,KAAK,UAA5B,EAAE,iBAAiB,GAAI,KAAK,kBAAT,CAAU;IAEjEA,eAAS,CAAC;QACR,IAAI,CAAC,aAAa,IAAI,CAAC,SAAS,EAAE;YAChC,OAAO;SACR;QACD,IAAM,MAAM,GAAG,aAAa,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAErD,MAAM,CAAC,KAAK,CAAC;YACX,SAAS,EAAE,MAAI,SAAW;YAC1B,KAAK,OAAA;YACL,iBAAiB,mBAAA;SAClB,CAAC,CAAC;KACJ,EAAE,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC;IAE/B,OAAO,SAAS;QACdC,iDAAK,EAAE,EAAE,SAAS,GAAQ;QAC1B,IAAI,CAAC;AACT;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../node_modules/@stytch/stytch-js/dist/index.esm.js","../src/utils/invariant.ts","../node_modules/tslib/tslib.es6.js","../src/utils/errors.ts","../src/StytchContext.tsx","../src/Stytch.tsx"],"sourcesContent":["var PUBLIC_URL = 'https://js.stytch.com/stytch.js';\nfunction getJSUrl() {\n try {\n if (process.env.STYTCH_JS_SDK_URL) {\n return process.env.STYTCH_JS_SDK_URL;\n }\n if (process.env.REACT_APP_STYTCH_JS_SDK_URL) {\n return process.env.REACT_APP_STYTCH_JS_SDK_URL;\n }\n if (process.env.NEXT_PUBLIC_STYTCH_JS_SDK_URL) {\n return process.env.NEXT_PUBLIC_STYTCH_JS_SDK_URL;\n }\n if (process.env.STORYBOOK_STYTCH_JS_SDK_URL) {\n return process.env.STORYBOOK_STYTCH_JS_SDK_URL;\n }\n return PUBLIC_URL;\n }\n catch (err) {\n return PUBLIC_URL;\n }\n}\nvar STYTCH_JS_URL = getJSUrl();\n\nvar findOrCreateScript = function () {\n var scripts = document.querySelectorAll(\"script[src=\\\"\" + STYTCH_JS_URL + \"\\\"]\");\n if (scripts[0]) {\n return scripts[0];\n }\n var script = document.createElement('script');\n script.src = STYTCH_JS_URL;\n document.head.appendChild(script);\n return script;\n};\nvar loadScript = function () {\n var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';\n if (!isBrowser) {\n return Promise.resolve(null);\n }\n return new Promise(function (resolve, reject) {\n if (window.Stytch) {\n console.warn('Stytch.js has already been loaded');\n resolve(window.Stytch);\n }\n var script = findOrCreateScript();\n script.addEventListener('load', function () {\n if (window.Stytch) {\n resolve(window.Stytch);\n }\n else {\n reject(new Error('Stytch.js could not be loaded'));\n }\n });\n script.addEventListener('error', function () {\n reject(new Error('Stytch.js could not be loaded'));\n });\n });\n};\n// Execute our own script injection after a tick to give users time to do their\n// own script injection.\nvar stytchPromise = Promise.resolve().then(function () { return loadScript(); });\nvar loadCalled = false;\n// We will log a warning if it doesn't look like the host code has checked or invoked the promise\nstytchPromise.catch(function (err) {\n if (!loadCalled) {\n console.warn(err);\n }\n});\nvar loadStytch = function () {\n loadCalled = true;\n return stytchPromise;\n};\n\n// Callback types\nvar EventType;\n(function (EventType) {\n EventType[\"CallbackEvent\"] = \"CALLBACK_EVENT\";\n EventType[\"ErrorEvent\"] = \"ERROR_EVENT\";\n EventType[\"SuccessEvent\"] = \"SUCCESS_EVENT\";\n})(EventType || (EventType = {}));\nvar CallbackEventType;\n(function (CallbackEventType) {\n CallbackEventType[\"UserEventType\"] = \"USER_EVENT_TYPE\";\n})(CallbackEventType || (CallbackEventType = {}));\nvar SDKProductTypes;\n(function (SDKProductTypes) {\n SDKProductTypes[\"emailMagicLinks\"] = \"emailMagicLinks\";\n SDKProductTypes[\"oauth\"] = \"oauth\";\n})(SDKProductTypes || (SDKProductTypes = {}));\nvar OAuthProvidersTypes;\n(function (OAuthProvidersTypes) {\n OAuthProvidersTypes[\"Google\"] = \"google\";\n OAuthProvidersTypes[\"Microsoft\"] = \"microsoft\";\n OAuthProvidersTypes[\"Apple\"] = \"apple\";\n OAuthProvidersTypes[\"Github\"] = \"github\";\n OAuthProvidersTypes[\"Facebook\"] = \"facebook\";\n})(OAuthProvidersTypes || (OAuthProvidersTypes = {}));\nvar OneTapPositions;\n(function (OneTapPositions) {\n OneTapPositions[\"embedded\"] = \"embedded\";\n OneTapPositions[\"floating\"] = \"floating\";\n})(OneTapPositions || (OneTapPositions = {}));\n\nvar initStytch = function () {\n var args = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n }\n if (typeof window === 'undefined') {\n return null;\n }\n if (!window.Stytch) {\n throw new Error('Stytch has not been loaded.');\n }\n return window.Stytch.apply(window, args);\n};\nvar loadAndInitStytch = function () {\n var args = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n }\n return loadStytch().then(function (stytchFactory) { return stytchFactory && stytchFactory.apply(void 0, args); });\n};\n\nexport { CallbackEventType, EventType, OAuthProvidersTypes, OneTapPositions, SDKProductTypes, initStytch, loadAndInitStytch, loadStytch };\n//# sourceMappingURL=index.esm.js.map\n","// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function invariant(cond: any, message: string): asserts cond {\n if (!cond) throw new Error(message);\n}\n","/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n","export const noProviderError = (hookOrHOC: string): string => `${hookOrHOC} can only be used inside <StytchProvider>.`;\n\nexport const lazyError = (hookOrHOC: string): string =>\n `${hookOrHOC} can only be used if Stytch is preloaded. Add <script src=\"https://js.stytch.com/stytch.js\" /> in your document header to load the script synchronously, or use ${hookOrHOC}Lazy if you want to lazy load Stytch. If you are using SSR, you will need to use ${hookOrHOC}Lazy.`;\n","import { Session, StytchClient, User } from '@stytch/stytch-js';\nimport React, { ComponentType, createContext, ReactNode, useContext, useEffect, useState } from 'react';\n\nimport { lazyError, noProviderError } from 'utils/errors';\nimport { invariant } from 'utils/invariant';\n\ntype StytchMountedContextType = {\n isMounted: boolean;\n isLazy: boolean;\n};\n\nconst StytchMountedContext = createContext<StytchMountedContextType>({\n isLazy: false,\n isMounted: false,\n});\nconst StytchUserContext = createContext<User | null>(null);\nconst StytchSessionContext = createContext<Session | null>(null);\nconst StytchContext = createContext<StytchClient | null>(null);\n\nexport const useIsMounted__INTERNAL = (): boolean => useContext(StytchMountedContext).isMounted;\nexport const useIsLazy__INTERNAL = (): boolean => useContext(StytchMountedContext).isLazy;\nexport const useStytchRaw__INTERNAL = (): StytchClient | null => useContext(StytchContext);\n\nexport const useStytchUser = (): User | null => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchUser'));\n return useContext(StytchUserContext);\n};\nexport const useStytchSession = (): Session | null => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchSession'));\n return useContext(StytchSessionContext);\n};\nexport const useStytch = (): StytchClient => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytch'));\n invariant(!useIsLazy__INTERNAL(), lazyError('useStytch'));\n return useContext(StytchContext);\n};\nexport const useStytchLazy = (): StytchClient => {\n invariant(useIsMounted__INTERNAL(), noProviderError('useStytchLazy'));\n return useContext(StytchContext);\n};\n\nexport const withStytch = <T extends object>(\n Component: ComponentType<T & { stytch: StytchClient }>,\n): ComponentType<T> => {\n const WithStytch: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytch'));\n invariant(!useIsLazy__INTERNAL(), lazyError('withStytch'));\n return <Component {...props} stytch={useStytch()} />;\n };\n WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;\n return WithStytch;\n};\nexport const withStytchLazy = <T extends object>(\n Component: ComponentType<T & { stytch: StytchClient | null }>,\n): ComponentType<T> => {\n const WithStytchLazy: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchLazy'));\n return <Component {...props} stytch={useStytchLazy()} />;\n };\n WithStytchLazy.displayName = `withStytchLazy(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchLazy;\n};\nexport const withStytchUser = <T extends object>(\n Component: ComponentType<T & { stytchUser: User | null }>,\n): ComponentType<T> => {\n const WithStytchUser: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchUser'));\n return <Component {...props} stytchUser={useStytchUser()} />;\n };\n WithStytchUser.displayName = `withStytchUser(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchUser;\n};\nexport const withStytchSession = <T extends object>(\n Component: ComponentType<T & { stytchSession: Session | null }>,\n): ComponentType<T> => {\n const WithStytchSession: ComponentType<T> = (props) => {\n invariant(useIsMounted__INTERNAL(), noProviderError('withStytchSession'));\n return <Component {...props} stytchSession={useStytchSession()} />;\n };\n WithStytchSession.displayName = `withStytchSession(${Component.displayName || Component.name || 'Component'})`;\n return WithStytchSession;\n};\n\nexport type StytchProviderProps = {\n stytch: StytchClient | null | Promise<StytchClient | null>;\n children?: ReactNode;\n};\n\nexport const StytchProvider = ({ stytch, children }: StytchProviderProps): JSX.Element => {\n invariant(!useIsMounted__INTERNAL(), 'You cannot render a <StytchProvider> inside another <StytchProvider>.');\n const [stytchClient, setStytchClient] = useState<StytchClient | null>(\n stytch instanceof Promise || !stytch ? null : stytch,\n );\n const [mountedContext] = useState<StytchMountedContextType>({\n isLazy: !stytchClient,\n isMounted: true,\n });\n const [user, setUser] = useState<User | null>(stytchClient && stytchClient.user.getSync());\n const [session, setSession] = useState<Session | null>(stytchClient && stytchClient.session.getSync());\n\n useEffect(() => {\n if (stytch instanceof Promise) {\n stytch.then(setStytchClient);\n }\n }, [stytch]);\n\n useEffect(() => {\n if (stytchClient) {\n if (mountedContext.isLazy) {\n setUser(stytchClient.user.getSync());\n setSession(stytchClient.session.getSync());\n }\n const unsubscribeUser = stytchClient.user.onChange(setUser);\n const unsubscribeSession = stytchClient.session.onChange(setSession);\n return () => {\n unsubscribeUser();\n unsubscribeSession();\n };\n }\n }, [mountedContext, stytchClient]);\n\n return (\n <StytchMountedContext.Provider value={mountedContext}>\n <StytchContext.Provider value={stytchClient}>\n <StytchUserContext.Provider value={session && user}>\n <StytchSessionContext.Provider value={user && session}>{children}</StytchSessionContext.Provider>\n </StytchUserContext.Provider>\n </StytchContext.Provider>\n </StytchMountedContext.Provider>\n );\n};\n","import { CallbackOptions, loadStytch, LoginOrSignupView, StyleConfig, StytchClient } from '@stytch/stytch-js';\nimport React, { useEffect, useState } from 'react';\n\nimport { invariant } from 'utils/invariant';\n\nimport { useIsMounted__INTERNAL, useStytchRaw__INTERNAL } from './StytchContext';\n\nexport interface StytchProps {\n publicToken?: string;\n loginOrSignupView?: LoginOrSignupView;\n style?: StyleConfig;\n callbacks?: CallbackOptions;\n}\n\n/**\n * Returns a unique element ID.\n * Client-side only - will return null for server-side\n * resolves: https://stytch.slack.com/archives/C015UDB4X33/p1641450131000800\n * based on: https://github.com/vercel/next.js/issues/7322#issuecomment-968858477\n */\nconst useUniqueElementId = (): string | null => {\n const [elementId, setElementId] = useState<string | null>(null);\n useEffect(() => {\n const randId = Math.floor(Math.random() * 1e6);\n setElementId(`stytch-magic-link-${randId}`);\n }, []);\n return elementId;\n};\n\n/**\n * Stytch JS React Component\n *\n * [Documentation](https://stytch.com/docs/javascript-sdk)\n */\nexport const Stytch = ({ publicToken, style, callbacks, loginOrSignupView }: StytchProps) => {\n const stytchClientFromContext = useStytchRaw__INTERNAL();\n const stytchMounted = useIsMounted__INTERNAL();\n const [stytchClient, setStytchClient] = useState<StytchClient | null>(() => {\n // If StytchProvider has been mounted, use context value\n if (stytchMounted) {\n return stytchClientFromContext;\n }\n // If StytchProvider isn't used, publicToken must be provided\n invariant(\n publicToken,\n 'The Stytch component must either be inside a <StytchProvider> or provided the publicToken prop.',\n );\n // If Stytch has already been loaded, use global value\n if (typeof window !== undefined && window.Stytch) {\n return window.Stytch(publicToken);\n }\n // Otherwise, we will load Stytch\n return null;\n });\n const elementId = useUniqueElementId();\n\n useEffect(() => {\n if (!stytchClient) {\n if (!stytchMounted) {\n loadStytch().then((globalStytch) => globalStytch && setStytchClient(globalStytch(publicToken)));\n } else if (stytchClientFromContext) {\n setStytchClient(stytchClientFromContext);\n }\n }\n }, [stytchClient, stytchClientFromContext, stytchMounted, publicToken]);\n\n useEffect(() => {\n if (!stytchClient || !elementId) {\n return;\n }\n\n stytchClient.mount({\n callbacks,\n elementId: `#${elementId}`,\n loginOrSignupView,\n style,\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [elementId, stytchClient]);\n\n return elementId ? <div id={elementId}></div> : null;\n};\n"],"names":["SDKProductTypes","OAuthProvidersTypes","OneTapPositions","createContext","useContext","React","useState","useEffect"],"mappings":";;;;;;;;;;AAAA,IAAI,UAAU,GAAG,iCAAiC,CAAC;AACnD,SAAS,QAAQ,GAAG;AACpB,IAAI,IAAI;AACR,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,EA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ta.1",
4
4
  "description": "Stytch's official React Library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
7
7
  "scripts": {
8
8
  "test": "npx jest",
9
9
  "build": "rollup -c",
10
- "prepare": "rollup -c"
10
+ "prepare": "rollup -c",
11
+ "patch-stytch-js": "./patch-stytch-js.sh"
11
12
  },
12
13
  "author": "Stytch",
13
14
  "license": "MIT",
@@ -20,18 +21,30 @@
20
21
  "@types/enzyme": "^3.10.10",
21
22
  "@types/enzyme-adapter-react-16": "^1.0.6",
22
23
  "@types/jest": "^26.0.20",
24
+ "@types/react": "^17.0.39",
23
25
  "@types/react-dom": "^17.0.10",
24
- "@wessberg/rollup-plugin-ts": "^1.3.8",
26
+ "@typescript-eslint/eslint-plugin": "^5.10.2",
27
+ "@typescript-eslint/parser": "^5.10.2",
25
28
  "babel-loader": "^8.2.2",
26
29
  "enzyme": "^3.11.0",
27
30
  "enzyme-adapter-react-16": "^1.15.6",
31
+ "eslint": "^8.8.0",
32
+ "eslint-config-prettier": "^8.3.0",
33
+ "eslint-import-resolver-typescript": "^2.5.0",
34
+ "eslint-plugin-import": "^2.25.4",
35
+ "eslint-plugin-prettier": "^4.0.0",
36
+ "eslint-plugin-react": "^7.28.0",
37
+ "eslint-plugin-react-hooks": "^4.3.0",
38
+ "eslint-plugin-simple-import-sort": "^7.0.0",
28
39
  "jest": "^26.6.3",
40
+ "prettier": "^2.5.1",
29
41
  "react": "^16.14.0",
30
42
  "react-dom": "^16.14.0",
31
43
  "rollup": "^2.56.3",
32
44
  "rollup-plugin-babel": "^4.4.0",
33
45
  "rollup-plugin-commonjs": "^10.1.0",
34
46
  "rollup-plugin-node-resolve": "^5.2.0",
47
+ "rollup-plugin-ts": "^2.0.5",
35
48
  "typescript": "^4.4.4"
36
49
  },
37
50
  "repository": {
@@ -50,7 +63,7 @@
50
63
  "package.json"
51
64
  ],
52
65
  "dependencies": {
53
- "@stytch/stytch-js": "^2.0.6"
66
+ "@stytch/stytch-js": "^2.0.9-headless.beta.3"
54
67
  },
55
68
  "peerDependencies": {
56
69
  "react": ">= 16.x.x"
package/src/Stytch.tsx CHANGED
@@ -1,26 +1,17 @@
1
- import React, {useEffect, useState} from "react";
2
- import {loadStytch, LoginOrSignupView, StyleConfig, CallbackOptions, StytchFactory} from '@stytch/stytch-js'
1
+ import { CallbackOptions, loadStytch, LoginOrSignupView, StyleConfig, StytchClient } from '@stytch/stytch-js';
2
+ import React, { useEffect, useState } from 'react';
3
3
 
4
- export {SDKProductTypes, OAuthProvidersTypes} from '@stytch/stytch-js'
4
+ import { invariant } from 'utils/invariant';
5
+
6
+ import { useIsMounted__INTERNAL, useStytchRaw__INTERNAL } from './StytchContext';
5
7
 
6
8
  export interface StytchProps {
7
- publicToken: string;
9
+ publicToken?: string;
8
10
  loginOrSignupView?: LoginOrSignupView;
9
11
  style?: StyleConfig;
10
12
  callbacks?: CallbackOptions;
11
13
  }
12
14
 
13
- const useStytchFactory = (): StytchFactory => {
14
- const [stytchFactory, setStytchFactory] = useState<StytchFactory>();
15
- useEffect(() => {
16
- // If we pass the function in directly React will execute it as a SetStateAction
17
- // Need to wrap in an anon - see https://medium.com/swlh/how-to-store-a-function-with-the-usestate-hook-in-react-8a88dd4eede1
18
- loadStytch().then(globalStytch => setStytchFactory(() => globalStytch))
19
- }, []);
20
-
21
- return stytchFactory;
22
- }
23
-
24
15
  /**
25
16
  * Returns a unique element ID.
26
17
  * Client-side only - will return null for server-side
@@ -32,35 +23,60 @@ const useUniqueElementId = (): string | null => {
32
23
  useEffect(() => {
33
24
  const randId = Math.floor(Math.random() * 1e6);
34
25
  setElementId(`stytch-magic-link-${randId}`);
35
- }, [])
26
+ }, []);
36
27
  return elementId;
37
- }
28
+ };
38
29
 
39
30
  /**
40
31
  * Stytch JS React Component
41
32
  *
42
33
  * [Documentation](https://stytch.com/docs/javascript-sdk)
43
34
  */
44
- export const Stytch = (props: StytchProps) => {
45
- const StytchFactory = useStytchFactory();
35
+ export const Stytch = ({ publicToken, style, callbacks, loginOrSignupView }: StytchProps) => {
36
+ const stytchClientFromContext = useStytchRaw__INTERNAL();
37
+ const stytchMounted = useIsMounted__INTERNAL();
38
+ const [stytchClient, setStytchClient] = useState<StytchClient | null>(() => {
39
+ // If StytchProvider has been mounted, use context value
40
+ if (stytchMounted) {
41
+ return stytchClientFromContext;
42
+ }
43
+ // If StytchProvider isn't used, publicToken must be provided
44
+ invariant(
45
+ publicToken,
46
+ 'The Stytch component must either be inside a <StytchProvider> or provided the publicToken prop.',
47
+ );
48
+ // If Stytch has already been loaded, use global value
49
+ if (typeof window !== undefined && window.Stytch) {
50
+ return window.Stytch(publicToken);
51
+ }
52
+ // Otherwise, we will load Stytch
53
+ return null;
54
+ });
46
55
  const elementId = useUniqueElementId();
47
56
 
48
- const {publicToken, style, callbacks, loginOrSignupView} = props;
57
+ useEffect(() => {
58
+ if (!stytchClient) {
59
+ if (!stytchMounted) {
60
+ loadStytch().then((globalStytch) => globalStytch && setStytchClient(globalStytch(publicToken)));
61
+ } else if (stytchClientFromContext) {
62
+ setStytchClient(stytchClientFromContext);
63
+ }
64
+ }
65
+ }, [stytchClient, stytchClientFromContext, stytchMounted, publicToken]);
49
66
 
50
67
  useEffect(() => {
51
- if (!StytchFactory || !elementId) {
68
+ if (!stytchClient || !elementId) {
52
69
  return;
53
70
  }
54
- const stytch = StytchFactory(publicToken, callbacks);
55
71
 
56
- stytch.mount({
72
+ stytchClient.mount({
73
+ callbacks,
57
74
  elementId: `#${elementId}`,
58
- style,
59
75
  loginOrSignupView,
76
+ style,
60
77
  });
61
- }, [StytchFactory, elementId]);
78
+ // eslint-disable-next-line react-hooks/exhaustive-deps
79
+ }, [elementId, stytchClient]);
62
80
 
63
- return elementId ?
64
- <div id={elementId}></div> :
65
- null;
81
+ return elementId ? <div id={elementId}></div> : null;
66
82
  };
@@ -0,0 +1,131 @@
1
+ import { Session, StytchClient, User } from '@stytch/stytch-js';
2
+ import React, { ComponentType, createContext, ReactNode, useContext, useEffect, useState } from 'react';
3
+
4
+ import { lazyError, noProviderError } from 'utils/errors';
5
+ import { invariant } from 'utils/invariant';
6
+
7
+ type StytchMountedContextType = {
8
+ isMounted: boolean;
9
+ isLazy: boolean;
10
+ };
11
+
12
+ const StytchMountedContext = createContext<StytchMountedContextType>({
13
+ isLazy: false,
14
+ isMounted: false,
15
+ });
16
+ const StytchUserContext = createContext<User | null>(null);
17
+ const StytchSessionContext = createContext<Session | null>(null);
18
+ const StytchContext = createContext<StytchClient | null>(null);
19
+
20
+ export const useIsMounted__INTERNAL = (): boolean => useContext(StytchMountedContext).isMounted;
21
+ export const useIsLazy__INTERNAL = (): boolean => useContext(StytchMountedContext).isLazy;
22
+ export const useStytchRaw__INTERNAL = (): StytchClient | null => useContext(StytchContext);
23
+
24
+ export const useStytchUser = (): User | null => {
25
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchUser'));
26
+ return useContext(StytchUserContext);
27
+ };
28
+ export const useStytchSession = (): Session | null => {
29
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchSession'));
30
+ return useContext(StytchSessionContext);
31
+ };
32
+ export const useStytch = (): StytchClient => {
33
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytch'));
34
+ invariant(!useIsLazy__INTERNAL(), lazyError('useStytch'));
35
+ return useContext(StytchContext);
36
+ };
37
+ export const useStytchLazy = (): StytchClient => {
38
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchLazy'));
39
+ return useContext(StytchContext);
40
+ };
41
+
42
+ export const withStytch = <T extends object>(
43
+ Component: ComponentType<T & { stytch: StytchClient }>,
44
+ ): ComponentType<T> => {
45
+ const WithStytch: ComponentType<T> = (props) => {
46
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytch'));
47
+ invariant(!useIsLazy__INTERNAL(), lazyError('withStytch'));
48
+ return <Component {...props} stytch={useStytch()} />;
49
+ };
50
+ WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;
51
+ return WithStytch;
52
+ };
53
+ export const withStytchLazy = <T extends object>(
54
+ Component: ComponentType<T & { stytch: StytchClient | null }>,
55
+ ): ComponentType<T> => {
56
+ const WithStytchLazy: ComponentType<T> = (props) => {
57
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytchLazy'));
58
+ return <Component {...props} stytch={useStytchLazy()} />;
59
+ };
60
+ WithStytchLazy.displayName = `withStytchLazy(${Component.displayName || Component.name || 'Component'})`;
61
+ return WithStytchLazy;
62
+ };
63
+ export const withStytchUser = <T extends object>(
64
+ Component: ComponentType<T & { stytchUser: User | null }>,
65
+ ): ComponentType<T> => {
66
+ const WithStytchUser: ComponentType<T> = (props) => {
67
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytchUser'));
68
+ return <Component {...props} stytchUser={useStytchUser()} />;
69
+ };
70
+ WithStytchUser.displayName = `withStytchUser(${Component.displayName || Component.name || 'Component'})`;
71
+ return WithStytchUser;
72
+ };
73
+ export const withStytchSession = <T extends object>(
74
+ Component: ComponentType<T & { stytchSession: Session | null }>,
75
+ ): ComponentType<T> => {
76
+ const WithStytchSession: ComponentType<T> = (props) => {
77
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytchSession'));
78
+ return <Component {...props} stytchSession={useStytchSession()} />;
79
+ };
80
+ WithStytchSession.displayName = `withStytchSession(${Component.displayName || Component.name || 'Component'})`;
81
+ return WithStytchSession;
82
+ };
83
+
84
+ export type StytchProviderProps = {
85
+ stytch: StytchClient | null | Promise<StytchClient | null>;
86
+ children?: ReactNode;
87
+ };
88
+
89
+ export const StytchProvider = ({ stytch, children }: StytchProviderProps): JSX.Element => {
90
+ invariant(!useIsMounted__INTERNAL(), 'You cannot render a <StytchProvider> inside another <StytchProvider>.');
91
+ const [stytchClient, setStytchClient] = useState<StytchClient | null>(
92
+ stytch instanceof Promise || !stytch ? null : stytch,
93
+ );
94
+ const [mountedContext] = useState<StytchMountedContextType>({
95
+ isLazy: !stytchClient,
96
+ isMounted: true,
97
+ });
98
+ const [user, setUser] = useState<User | null>(stytchClient && stytchClient.user.getSync());
99
+ const [session, setSession] = useState<Session | null>(stytchClient && stytchClient.session.getSync());
100
+
101
+ useEffect(() => {
102
+ if (stytch instanceof Promise) {
103
+ stytch.then(setStytchClient);
104
+ }
105
+ }, [stytch]);
106
+
107
+ useEffect(() => {
108
+ if (stytchClient) {
109
+ if (mountedContext.isLazy) {
110
+ setUser(stytchClient.user.getSync());
111
+ setSession(stytchClient.session.getSync());
112
+ }
113
+ const unsubscribeUser = stytchClient.user.onChange(setUser);
114
+ const unsubscribeSession = stytchClient.session.onChange(setSession);
115
+ return () => {
116
+ unsubscribeUser();
117
+ unsubscribeSession();
118
+ };
119
+ }
120
+ }, [mountedContext, stytchClient]);
121
+
122
+ return (
123
+ <StytchMountedContext.Provider value={mountedContext}>
124
+ <StytchContext.Provider value={stytchClient}>
125
+ <StytchUserContext.Provider value={session && user}>
126
+ <StytchSessionContext.Provider value={user && session}>{children}</StytchSessionContext.Provider>
127
+ </StytchUserContext.Provider>
128
+ </StytchContext.Provider>
129
+ </StytchMountedContext.Provider>
130
+ );
131
+ };
package/src/index.ts CHANGED
@@ -1 +1,21 @@
1
- export { Stytch, StytchProps, SDKProductTypes, OAuthProvidersTypes } from "./Stytch";
1
+ export {
2
+ initStytch,
3
+ loadAndInitStytch,
4
+ SDKProductTypes,
5
+ OneTapPositions,
6
+ OAuthProvidersTypes,
7
+ StytchClient,
8
+ } from '@stytch/stytch-js';
9
+ export { Stytch, StytchProps } from './Stytch';
10
+ export {
11
+ StytchProvider,
12
+ StytchProviderProps,
13
+ useStytch,
14
+ useStytchLazy,
15
+ useStytchSession,
16
+ useStytchUser,
17
+ withStytch,
18
+ withStytchLazy,
19
+ withStytchSession,
20
+ withStytchUser,
21
+ } from './StytchContext';
@@ -0,0 +1,4 @@
1
+ export const noProviderError = (hookOrHOC: string): string => `${hookOrHOC} can only be used inside <StytchProvider>.`;
2
+
3
+ export const lazyError = (hookOrHOC: string): string =>
4
+ `${hookOrHOC} can only be used if Stytch is preloaded. Add <script src="https://js.stytch.com/stytch.js" /> in your document header to load the script synchronously, or use ${hookOrHOC}Lazy if you want to lazy load Stytch. If you are using SSR, you will need to use ${hookOrHOC}Lazy.`;
@@ -0,0 +1,4 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ export function invariant(cond: any, message: string): asserts cond {
3
+ if (!cond) throw new Error(message);
4
+ }