@strivacity/sdk-react 4.0.0-beta.1 → 4.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -23
- package/dist/components.cjs +1 -1
- package/dist/components.cjs.map +1 -1
- package/dist/components.mjs +1 -1
- package/dist/components.mjs.map +1 -1
- package/dist/errors.cjs +1 -2
- package/dist/errors.mjs +1 -2
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.mjs +1 -1
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.cjs +1 -2
- package/dist/index.mjs +1 -2
- package/dist/storages.cjs +1 -1
- package/dist/storages.mjs +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.d.ts +5 -28
- package/dist/types.mjs +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.mjs +1 -1
- package/package.json +2 -2
- package/dist/assets/rolldown-runtime.cjs +0 -1
- package/dist/assets/rolldown-runtime.mjs +0 -1
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.mjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/testing/tests/components.spec.tsx +0 -146
- package/testing/tests/errors.spec.ts +0 -10
- package/testing/tests/guard.spec.tsx +0 -119
- package/testing/tests/hooks.spec.tsx +0 -418
- package/testing/tests/index.spec.ts +0 -105
- package/testing/tests/storages.spec.ts +0 -10
- package/testing/tests/utils.spec.ts +0 -10
package/README.md
CHANGED
|
@@ -407,7 +407,33 @@ export default function Login() {
|
|
|
407
407
|
|
|
408
408
|
#### Handle the callback
|
|
409
409
|
|
|
410
|
-
The
|
|
410
|
+
The pop-up still navigates to your `redirectUri`, so you still need a callback page there - without it nothing posts the result back to the opener. Call `handleCallback()` on that page; in popup mode it never resolves (the opener closes the pop-up once it receives the result), so don't rely on code after it running:
|
|
411
|
+
|
|
412
|
+
```tsx
|
|
413
|
+
// pages/Callback.tsx
|
|
414
|
+
import { useStrivacity } from '@strivacity/sdk-react';
|
|
415
|
+
import { useEffect } from 'react';
|
|
416
|
+
|
|
417
|
+
export default function Callback() {
|
|
418
|
+
const { loading, handleCallback } = useStrivacity();
|
|
419
|
+
|
|
420
|
+
useEffect(() => {
|
|
421
|
+
if (loading) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
void handleCallback();
|
|
426
|
+
}, [loading]);
|
|
427
|
+
|
|
428
|
+
return (
|
|
429
|
+
<section>
|
|
430
|
+
<h1>Logging in...</h1>
|
|
431
|
+
</section>
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
`login()` resolves in the opener once the result has been received and, for client-managed sessions, the tokens have been exchanged.
|
|
411
437
|
|
|
412
438
|
#### Registration
|
|
413
439
|
|
|
@@ -1072,7 +1098,6 @@ export default function Login() {
|
|
|
1072
1098
|
params: {
|
|
1073
1099
|
prompt: 'login', // use 'create' to open the registration flow instead
|
|
1074
1100
|
language: 'en-US', // set the UI language (BCP 47 language tag)
|
|
1075
|
-
sdk: 'web-minimal', // rendering mode: 'web-minimal' for simplified rendering (see below), 'web' (default) for full rendering hints and branding
|
|
1076
1101
|
sessionId: searchParams.get('session_id'), // pass a session ID to resume an existing flow
|
|
1077
1102
|
},
|
|
1078
1103
|
onLogin: async () => {
|
|
@@ -1359,23 +1384,31 @@ const ctx = useStrivacity<RedirectFlow>();
|
|
|
1359
1384
|
```ts
|
|
1360
1385
|
{
|
|
1361
1386
|
// SDK instance (access any SDK method)
|
|
1362
|
-
sdk: RedirectFlow | PopupFlow | EmbeddedFlow | NativeFlow;
|
|
1387
|
+
readonly sdk: RedirectFlow | PopupFlow | EmbeddedFlow | NativeFlow;
|
|
1363
1388
|
|
|
1364
1389
|
// Reactive state (plain values - the component re-renders when they change)
|
|
1365
|
-
loading: boolean; // True during initialization
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
//
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1390
|
+
readonly loading: boolean; // True during initialization
|
|
1391
|
+
readonly language: string; // Current BCP 47 language code
|
|
1392
|
+
readonly isAuthenticated: boolean; // True if user has valid session
|
|
1393
|
+
readonly idTokenClaims: IdTokenClaims | null; // Decoded ID token claims
|
|
1394
|
+
readonly accessToken: string | null; // Current access token
|
|
1395
|
+
readonly refreshToken: string | null; // Current refresh token
|
|
1396
|
+
readonly accessTokenExpired: boolean; // True once the access token has expired
|
|
1397
|
+
readonly accessTokenExpirationDate: number | null; // Access token expiration timestamp
|
|
1398
|
+
|
|
1399
|
+
// Methods (same signatures as the underlying flow's methods)
|
|
1400
|
+
init(): Promise<void>; // Initialize the SDK (load metadata, restore a persisted session)
|
|
1401
|
+
checkAuthentication(params?: { autoRefresh: boolean }): Promise<boolean>; // Check the session, optionally refreshing the token (never when serverSessionUri is set)
|
|
1402
|
+
login(params?: RedirectParams | PopupParams): Promise<void>; // Start login flow (redirect: `returnTo` sets where handleCallback() sends the user) (embedded/native: returns an EmbeddedLoginFlow/NativeLoginFlow instead)
|
|
1403
|
+
register(params?: RedirectParams | PopupParams): Promise<void>; // Start registration flow (embedded/native: returns an EmbeddedLoginFlow/NativeLoginFlow instead)
|
|
1404
|
+
handleCallback(url?: string | URL): Promise<{ returnTo?: string }>; // Handle OAuth callback; resolves to the `returnTo` given to login()
|
|
1375
1405
|
logout(params?: LogoutParams): Promise<void>; // End session
|
|
1376
|
-
refresh(): Promise<void>; // Refresh access token
|
|
1406
|
+
refresh(params?: { returnTo?: string }): Promise<void>; // Refresh access token (server-managed: navigates to the server's refresh route, `${authUrlPrefix}/refresh`, instead; `returnTo` sets where it returns, default: the current URL)
|
|
1377
1407
|
revoke(): Promise<void>; // Revoke tokens
|
|
1378
|
-
|
|
1408
|
+
tokenExchange(params?: Record<string, string>): Promise<void>; // Perform a token exchange
|
|
1409
|
+
entry(url?: string | URL, params?: RedirectOptions): Promise<void | EntryResponse>; // Handle external entry (resolves to EntryResponse in embedded/native mode)
|
|
1410
|
+
subscribeToEvent<T extends keyof EventFunctions>(eventName: T, callbackFn: (...params: Parameters<EventFunctions[T]>) => Promise<void> | void): { dispose: () => void }; // Subscribe to a single SDK event
|
|
1411
|
+
subscribeToAllEvents(callbackFn: (...params: Array<unknown>) => Promise<void> | void): { dispose: () => void }; // Subscribe to all SDK events
|
|
1379
1412
|
}
|
|
1380
1413
|
```
|
|
1381
1414
|
|
|
@@ -1401,10 +1434,10 @@ const ctx = useNativeLogin({
|
|
|
1401
1434
|
{
|
|
1402
1435
|
params?: NativeParams; // Initial flow parameters
|
|
1403
1436
|
onLogin?: (session: SessionData) => void | Promise<void>; // Called on successful login
|
|
1404
|
-
onClose?: () => void
|
|
1405
|
-
onError?: (error:
|
|
1406
|
-
onFallback?: (error: FallbackError) => void
|
|
1407
|
-
onGlobalMessage?: (message: NativeFlowMessage) => void
|
|
1437
|
+
onClose?: () => void | Promise<void>; // Called when user closes the flow
|
|
1438
|
+
onError?: (error: Error) => void | Promise<void>; // Called on error
|
|
1439
|
+
onFallback?: (error: FallbackError) => void | Promise<void>; // Called when fallback needed
|
|
1440
|
+
onGlobalMessage?: (message: NativeFlowMessage) => void | Promise<void>; // Called for global messages
|
|
1408
1441
|
}
|
|
1409
1442
|
```
|
|
1410
1443
|
|
|
@@ -1427,9 +1460,19 @@ const ctx = useNativeLogin({
|
|
|
1427
1460
|
}
|
|
1428
1461
|
```
|
|
1429
1462
|
|
|
1463
|
+
### useNativeLoginContext
|
|
1464
|
+
|
|
1465
|
+
Returns the context of the currently mounted `useNativeLogin()` from any component (e.g. your own widget components), without passing it down as props. Before `useNativeLogin()` has mounted it returns an empty default context (`loading: true`, no-op methods).
|
|
1466
|
+
|
|
1467
|
+
```ts
|
|
1468
|
+
import { useNativeLoginContext } from '@strivacity/sdk-react';
|
|
1469
|
+
|
|
1470
|
+
const { forms, messages, setFormValue, submitForm } = useNativeLoginContext();
|
|
1471
|
+
```
|
|
1472
|
+
|
|
1430
1473
|
### withAuthGuard
|
|
1431
1474
|
|
|
1432
|
-
Higher-order component that guards a component with authentication. Waits for the SDK to finish loading, checks the session, and redirects to the login page if the user is not authenticated.
|
|
1475
|
+
Higher-order component that guards a component with authentication. Waits for the SDK to finish loading, checks the session, and redirects to the login page if the user is not authenticated (with the current path as `returnTo`, e.g. `/login?returnTo=%2Forders` - pass it on with `login({ returnTo })`). With server-managed sessions (`serverSessionUri`), an expired session is sent through the server's refresh route instead (`sdk.refresh()`, returning to the current URL) - see [Server-side session (BFF) mode](#server-side-session-bff-mode).
|
|
1433
1476
|
|
|
1434
1477
|
```tsx
|
|
1435
1478
|
import { withAuthGuard } from '@strivacity/sdk-react';
|
|
@@ -1455,7 +1498,7 @@ export default withAuthGuard(
|
|
|
1455
1498
|
|
|
1456
1499
|
## Route guards
|
|
1457
1500
|
|
|
1458
|
-
Protect routes that require authentication with the `withAuthGuard` higher-order component. It waits for the SDK to finish loading, verifies the session, and redirects to the login page if the user is not authenticated:
|
|
1501
|
+
Protect routes that require authentication with the `withAuthGuard` higher-order component. It waits for the SDK to finish loading, verifies the session, and redirects to the login page if the user is not authenticated (with the current path as `returnTo`, e.g. `/login?returnTo=%2Forders` - pass it on with `login({ returnTo })`). With server-managed sessions, an expired session is refreshed through the server (`${authUrlPrefix}/refresh`) instead of starting a new login (see [Server-side session (BFF) mode](#server-side-session-bff-mode)):
|
|
1459
1502
|
|
|
1460
1503
|
```tsx
|
|
1461
1504
|
// pages/Profile.tsx
|
|
@@ -1678,6 +1721,7 @@ createRoot(document.getElementById('app')!).render(
|
|
|
1678
1721
|
redirectUri: 'https://your-app.example.com/callback',
|
|
1679
1722
|
scopes: ['openid', 'profile', 'email'],
|
|
1680
1723
|
serverSessionUri: '/api/auth/login', // Requests are routed through your server; tokens are NOT written to client storage
|
|
1724
|
+
authUrlPrefix: '/api/auth', // Where your server serves the auth routes: refresh() and the guards use `${authUrlPrefix}/refresh`
|
|
1681
1725
|
}}
|
|
1682
1726
|
>
|
|
1683
1727
|
<App />
|
|
@@ -1685,6 +1729,10 @@ createRoot(document.getElementById('app')!).render(
|
|
|
1685
1729
|
);
|
|
1686
1730
|
```
|
|
1687
1731
|
|
|
1732
|
+
In this mode `logout()` doesn't clear the server session cookie. Navigate the browser to your server's logout route instead (e.g. `/api/auth/logout`, optionally with a same-origin `?returnTo=`), which clears the server session and redirects to the IDP end-session endpoint. See [Logging out](../sdk-core/README.md#logging-out) in the core SDK README for the `returnTo` rules.
|
|
1733
|
+
|
|
1734
|
+
The browser never refreshes tokens in this mode (`autoRefresh` is ignored). `sdk.refresh()` navigates the browser to your server's refresh route, `${authUrlPrefix}/refresh` (default `/auth`; set `authUrlPrefix` when your server uses another prefix) (a full-page navigation, also in `popup` mode) with `returnTo` set to the current URL - or pass your own with `sdk.refresh({ returnTo: '/profile' })`; the server rotates the session cookie and redirects back. `withAuthGuard` does the same for an expired session instead of redirecting to `loginUri`. See [Refreshing the session](../sdk-core/README.md#refreshing-the-session) in the core SDK README.
|
|
1735
|
+
|
|
1688
1736
|
See [`apps/react`](../../apps/react) paired with [`apps/backend`](../../apps/backend) for a working example. See also [Using the backend app with SPA apps](../../README.md#using-the-backend-app-with-spa-apps) in the root README.
|
|
1689
1737
|
|
|
1690
1738
|
---
|
|
@@ -1693,7 +1741,7 @@ See [`apps/react`](../../apps/react) paired with [`apps/backend`](../../apps/bac
|
|
|
1693
1741
|
|
|
1694
1742
|
### Migrating to v4.0
|
|
1695
1743
|
|
|
1696
|
-
v4 replaces the SDK's class-based flow architecture with function-based architecture, and adds first-class support for server-managed (BFF) sessions. `StyAuthProvider`, `useStrivacity()`,
|
|
1744
|
+
v4 replaces the SDK's class-based flow architecture with function-based architecture, and adds first-class support for server-managed (BFF) sessions. `StyAuthProvider`, `useStrivacity()`, and the built-in `redirect`/`popup`/`embedded`/`native` modes are unchanged (`useStrivacity()` no longer exposes `options` - use `sdk.options`). `useNativeLogin()` is new in v4: it replaces v3's `<StyLoginRenderer>` component (and `NativeFlowContext`), so `native` mode now renders your own widget components driven by [`useNativeLogin()`](#usenativelogin) and [`useNativeLoginContext()`](#usenativelogincontext). Apps that rendered `<StyLoginRenderer>`, used `mode: 'custom'`, or drove `native` mode through the old `NativeFlowHandler` need to update their code.
|
|
1697
1745
|
|
|
1698
1746
|
#### Class-based flows replaced by functions
|
|
1699
1747
|
|
|
@@ -1720,7 +1768,7 @@ import type { SDKInitConfig, SDKOptions } from '@strivacity/sdk-core/types';
|
|
|
1720
1768
|
|
|
1721
1769
|
export function createCustomFlow(initConfig: SDKInitConfig) {
|
|
1722
1770
|
const state = getDefaultFlowState();
|
|
1723
|
-
const options = getSDKOptions<SDKOptions>(
|
|
1771
|
+
const options = getSDKOptions<SDKOptions>(initConfig);
|
|
1724
1772
|
const base = createBaseFlow(state, options);
|
|
1725
1773
|
|
|
1726
1774
|
async function refresh(): Promise<void> {
|
package/dist/components.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./hooks.cjs");let t=require("react"),n=require("@strivacity/sdk-core"),r=require("react/jsx-runtime");var i;function a({options:a,session:o,children:s}){let[c,l]=(0,t.useState)(!0),[u,d]=(0,t.useState)(globalThis.navigator?.language??`en-US`),[f,p]=(0,t.useState)(!1),[m,h]=(0,t.useState)(null),[g,_]=(0,t.useState)(null),[v,y]=(0,t.useState)(null),[b,x]=(0,t.useState)(!0),[S,C]=(0,t.useState)(null),w=async()=>{let e=await i.isAuthenticated;c&&l(!1),i.language!==u&&d(i.language),e!==f&&p(e),i.idTokenClaims!==m&&h(i.idTokenClaims||null),i.accessToken!==g&&_(i.accessToken||null),i.refreshToken!==v&&y(i.refreshToken||null),i.accessTokenExpired!==b&&x(i.accessTokenExpired),i.accessTokenExpirationDate!==S&&C(i.accessTokenExpirationDate||null)};(0,t.useEffect)(()=>{i=(0,n.initFlow)(a);let e=i.subscribeToAllEvents(w);return o&&(i.session=o),w(),()=>{e.dispose()}},[]);let T=(0,t.useMemo)(()=>({sdk:i,loading:c,language:u,isAuthenticated:f,idTokenClaims:m,accessToken:g,refreshToken:v,accessTokenExpired:b,accessTokenExpirationDate:S,init:()=>i.init(),subscribeToEvent:((...e)=>i.subscribeToEvent(...e)),subscribeToAllEvents:(...e)=>i.subscribeToAllEvents(...e),checkAuthentication:(...e)=>i.checkAuthentication(...e),tokenExchange:(...e)=>i.tokenExchange(...e),handleCallback:(...e)=>i.handleCallback(...e),refresh:()=>i.refresh(),revoke:()=>i.revoke(),logout:(...e)=>i.logout(...e),login:(...e)=>i.login(...e),register:(...e)=>i.register(...e),entry:(...e)=>i.entry(...e)}),[i,c,f,m,g,v,b,S]);return(0,r.jsx)(e.STRIVACITY_SDK.Provider,{value:T,children:s})}exports.StyAuthProvider=a;
|
|
1
|
+
"use client";"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./hooks.cjs");let t=require("react"),n=require("@strivacity/sdk-core"),r=require("react/jsx-runtime");var i;function a({options:a,session:o,children:s}){let[c,l]=(0,t.useState)(!0),[u,d]=(0,t.useState)(globalThis.navigator?.language??`en-US`),[f,p]=(0,t.useState)(!1),[m,h]=(0,t.useState)(null),[g,_]=(0,t.useState)(null),[v,y]=(0,t.useState)(null),[b,x]=(0,t.useState)(!0),[S,C]=(0,t.useState)(null),w=async()=>{let e=await i.isAuthenticated;c&&l(!1),i.language!==u&&d(i.language),e!==f&&p(e),i.idTokenClaims!==m&&h(i.idTokenClaims||null),i.accessToken!==g&&_(i.accessToken||null),i.refreshToken!==v&&y(i.refreshToken||null),i.accessTokenExpired!==b&&x(i.accessTokenExpired),i.accessTokenExpirationDate!==S&&C(i.accessTokenExpirationDate||null)};(0,t.useEffect)(()=>{i=(0,n.initFlow)(a);let e=i.subscribeToAllEvents(w);return o&&(i.session=o),w(),()=>{e.dispose()}},[]);let T=(0,t.useMemo)(()=>({sdk:i,loading:c,language:u,isAuthenticated:f,idTokenClaims:m,accessToken:g,refreshToken:v,accessTokenExpired:b,accessTokenExpirationDate:S,init:()=>i.init(),subscribeToEvent:((...e)=>i.subscribeToEvent(...e)),subscribeToAllEvents:(...e)=>i.subscribeToAllEvents(...e),checkAuthentication:(...e)=>i.checkAuthentication(...e),tokenExchange:(...e)=>i.tokenExchange(...e),handleCallback:(...e)=>i.handleCallback(...e),refresh:(...e)=>i.refresh(...e),revoke:()=>i.revoke(),logout:(...e)=>i.logout(...e),login:(...e)=>i.login(...e),register:(...e)=>i.register(...e),entry:(...e)=>i.entry(...e)}),[i,c,f,m,g,v,b,S]);return(0,r.jsx)(e.STRIVACITY_SDK.Provider,{value:T,children:s})}exports.StyAuthProvider=a;
|
|
2
2
|
//# sourceMappingURL=components.cjs.map
|
package/dist/components.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.cjs","names":[],"sources":["../src/components.tsx"],"sourcesContent":["'use client';\n\nimport type { IdTokenClaims, RedirectFlow, PopupFlow, EmbeddedFlow, NativeFlow, SDKContext, SDKInstance, StyAuthProviderProps } from './types';\nimport { type JSX, useEffect, useMemo, useState } from 'react';\nimport { initFlow } from '@strivacity/sdk-core';\nimport { STRIVACITY_SDK } from './hooks';\n\nlet sdk: SDKInstance;\n\n/**\n * The `StyAuthProvider` component is a React context provider that initializes the Strivacity SDK and provides its state and methods to the rest of the application.\n *\n * @param {StyAuthProviderProps} props - The properties for the `StyAuthProvider` component.\n * @param {SDKInitConfig} props.options - The configuration options for initializing the Strivacity SDK.\n * @param {ReactNode} props.children - The child components that will have access to the SDK context.\n * @param {SessionData | null} [props.session] - Optional session data to initialize the SDK with.\n */\nexport function StyAuthProvider({ options, session, children }: StyAuthProviderProps): JSX.Element {\n\tconst [loading, setLoading] = useState<boolean>(true);\n\tconst [language, setLanguage] = useState<string>(globalThis.navigator?.language ?? 'en-US');\n\tconst [isAuthenticated, setIsAuthenticated] = useState<boolean>(false);\n\tconst [idTokenClaims, setIdTokenClaims] = useState<IdTokenClaims | null>(null);\n\tconst [accessToken, setAccessToken] = useState<string | null>(null);\n\tconst [refreshToken, setRefreshToken] = useState<string | null>(null);\n\tconst [accessTokenExpired, setAccessTokenExpired] = useState<boolean>(true);\n\tconst [accessTokenExpirationDate, setAccessTokenExpirationDate] = useState<number | null>(null);\n\n\tconst updateSession = async () => {\n\t\tconst authenticated = await sdk.isAuthenticated;\n\n\t\tif (loading) {\n\t\t\tsetLoading(false);\n\t\t}\n\t\tif (sdk.language !== language) {\n\t\t\tsetLanguage(sdk.language);\n\t\t}\n\t\tif (authenticated !== isAuthenticated) {\n\t\t\tsetIsAuthenticated(authenticated);\n\t\t}\n\t\tif (sdk.idTokenClaims !== idTokenClaims) {\n\t\t\tsetIdTokenClaims(sdk.idTokenClaims || null);\n\t\t}\n\t\tif (sdk.accessToken !== accessToken) {\n\t\t\tsetAccessToken(sdk.accessToken || null);\n\t\t}\n\t\tif (sdk.refreshToken !== refreshToken) {\n\t\t\tsetRefreshToken(sdk.refreshToken || null);\n\t\t}\n\t\tif (sdk.accessTokenExpired !== accessTokenExpired) {\n\t\t\tsetAccessTokenExpired(sdk.accessTokenExpired);\n\t\t}\n\t\tif (sdk.accessTokenExpirationDate !== accessTokenExpirationDate) {\n\t\t\tsetAccessTokenExpirationDate(sdk.accessTokenExpirationDate || null);\n\t\t}\n\t};\n\n\tuseEffect(() => {\n\t\tsdk = initFlow(options as never);\n\t\tconst sdkEvents = sdk.subscribeToAllEvents(updateSession);\n\n\t\tif (session) {\n\t\t\tsdk.session = session;\n\t\t}\n\n\t\tvoid updateSession();\n\n\t\treturn () => {\n\t\t\tsdkEvents.dispose();\n\t\t};\n\t}, []);\n\n\tconst value = useMemo<SDKContext<RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow>>(() => {\n\t\treturn {\n\t\t\tsdk,\n\t\t\tloading,\n\t\t\tlanguage,\n\t\t\tisAuthenticated,\n\t\t\tidTokenClaims,\n\t\t\taccessToken,\n\t\t\trefreshToken,\n\t\t\taccessTokenExpired,\n\t\t\taccessTokenExpirationDate,\n\t\t\tinit: () => sdk.init(),\n\t\t\tsubscribeToEvent: ((...args: Parameters<typeof sdk.subscribeToEvent>) => sdk.subscribeToEvent(...args)) as typeof sdk.subscribeToEvent,\n\t\t\tsubscribeToAllEvents: (...args: Parameters<typeof sdk.subscribeToAllEvents>) => sdk.subscribeToAllEvents(...args),\n\t\t\tcheckAuthentication: (...args: Parameters<typeof sdk.checkAuthentication>) => sdk.checkAuthentication(...args),\n\t\t\ttokenExchange: (...args: Parameters<typeof sdk.tokenExchange>) => sdk.tokenExchange(...args),\n\t\t\thandleCallback: (...args: Parameters<typeof sdk.handleCallback>) => sdk.handleCallback(...args),\n\t\t\trefresh: () => sdk.refresh(),\n\t\t\trevoke: () => sdk.revoke(),\n\t\t\tlogout: (...args: Parameters<typeof sdk.logout>) => sdk.logout(...args),\n\t\t\tlogin: (...args: Parameters<typeof sdk.login>) => sdk.login(...args),\n\t\t\tregister: (...args: Parameters<typeof sdk.register>) => sdk.register(...args),\n\t\t\tentry: (...args: Parameters<typeof sdk.entry>) => sdk.entry(...args),\n\t\t};\n\t}, [sdk, loading, isAuthenticated, idTokenClaims, accessToken, refreshToken, accessTokenExpired, accessTokenExpirationDate]);\n\n\treturn <STRIVACITY_SDK.Provider value={value}>{children}</STRIVACITY_SDK.Provider>;\n}\n"],"mappings":"oNAiBA,IAAA,EACC,SAAO,EAAS,CAAA,UAAc,UAAA,YAAsB,CACpD,GAAM,CAAC,EAAA,IAAU,EAAA,EAAe,SAAA,CAAA,EAAiB,EAC3C,CAAC,EAAA,IAAiB,EAAA,EAAA,SAAsB,CAAA,WAAA,WAAuB,UAAA,OAAA,EAC/D,CAAC,EAAe,IAAoB,EAAA,EAAA,SAA+B,CAAI,EAAA,EACvE,CAAC,EAAa,IAAkB,EAAA,EAAA,SAAwB,CAAI,IAAA,EAC5D,CAAC,EAAA,IAAc,EAAA,EAAmB,SAAA,CAAA,IAAwB,EAC1D,CAAC,EAAA,IAAoB,EAAA,EAAA,SAAyB,CAAA,IAAA,EAC9C,CAAC,EAAA,IAA2B,EAAA,EAAA,SAAgC,CAAA,EAAA,EAE5D,CAAA,EAA4B,IAAA,EAAA,EAAA,SAAA,CAAA,IAAA,EACjC,EAAM,SAA0B,CAEhC,IAAI,EACH,MAAW,EAAK,gBAEb,GAAI,EAAa,EAAA,EAGjB,EAAA,WAAA,GAAkB,EACrB,EAAA,QAAA,EAEG,IAAI,GAAkB,EACR,CAAI,EAElB,EAAI,gBAAgB,GACvB,EAAmB,EAAA,eAAmB,IAAA,EAEnC,EAAI,cAAA,GAAiB,EACxB,EAAgB,aAAI,IAAgB,EAEjC,EAAI,eAAA,GAAuB,EAC9B,EAAA,cAAsB,IAAI,EAEvB,EAAI,qBAAA,GAA8B,EACrC,EAAA,kBAA6B,EAE/B,EAAA,4BAAA,GAAA,EAAA,EAAA,2BAAA,IAAA,CAEA,GACC,EAAA,EAAA,UAAM,KAAA,CACN,GAAM,EAAA,EAAgB,SAAA,CAAA,CAAqB,EAE3C,IAAI,EACC,EAAA,qBAAU,CAAA,EAMd,OAHI,IAAA,EAAc,QAAA,GAEnB,EAAa,MACF,CACX,EAAA,QAAA,CACD,CAEA,EAAA,CAAA,CAAA,EACC,IAAA,GAAO,EAAA,EAAA,QAAA,MACN,CACA,MACA,UACA,WACA,kBACA,gBACA,cACA,eACA,qBACA,4BACA,SAAA,EAAA,KAAoB,EACpB,mBAAA,GAAuB,IAAG,EAAsD,iBAAI,GAAA,CAAqB,GACzG,sBAAsB,GAAG,IAAqD,EAAI,qBAAoB,GAAG,CAAI,EAC7G,qBAAmB,GAAA,IAAmD,EAAA,oBAAqB,GAAA,CAAA,EAC3F,eAAA,GAAiB,IAAG,EAAgD,cAAI,GAAe,CAAG,EAC1F,
|
|
1
|
+
{"version":3,"file":"components.cjs","names":[],"sources":["../src/components.tsx"],"sourcesContent":["'use client';\n\nimport type { IdTokenClaims, RedirectFlow, PopupFlow, EmbeddedFlow, NativeFlow, SDKContext, SDKInstance, StyAuthProviderProps } from './types';\nimport { type JSX, useEffect, useMemo, useState } from 'react';\nimport { initFlow } from '@strivacity/sdk-core';\nimport { STRIVACITY_SDK } from './hooks';\n\nlet sdk: SDKInstance;\n\n/**\n * The `StyAuthProvider` component is a React context provider that initializes the Strivacity SDK and provides its state and methods to the rest of the application.\n *\n * @param {StyAuthProviderProps} props - The properties for the `StyAuthProvider` component.\n * @param {SDKInitConfig} props.options - The configuration options for initializing the Strivacity SDK.\n * @param {ReactNode} props.children - The child components that will have access to the SDK context.\n * @param {SessionData | null} [props.session] - Optional session data to initialize the SDK with.\n */\nexport function StyAuthProvider({ options, session, children }: StyAuthProviderProps): JSX.Element {\n\tconst [loading, setLoading] = useState<boolean>(true);\n\tconst [language, setLanguage] = useState<string>(globalThis.navigator?.language ?? 'en-US');\n\tconst [isAuthenticated, setIsAuthenticated] = useState<boolean>(false);\n\tconst [idTokenClaims, setIdTokenClaims] = useState<IdTokenClaims | null>(null);\n\tconst [accessToken, setAccessToken] = useState<string | null>(null);\n\tconst [refreshToken, setRefreshToken] = useState<string | null>(null);\n\tconst [accessTokenExpired, setAccessTokenExpired] = useState<boolean>(true);\n\tconst [accessTokenExpirationDate, setAccessTokenExpirationDate] = useState<number | null>(null);\n\n\tconst updateSession = async () => {\n\t\tconst authenticated = await sdk.isAuthenticated;\n\n\t\tif (loading) {\n\t\t\tsetLoading(false);\n\t\t}\n\t\tif (sdk.language !== language) {\n\t\t\tsetLanguage(sdk.language);\n\t\t}\n\t\tif (authenticated !== isAuthenticated) {\n\t\t\tsetIsAuthenticated(authenticated);\n\t\t}\n\t\tif (sdk.idTokenClaims !== idTokenClaims) {\n\t\t\tsetIdTokenClaims(sdk.idTokenClaims || null);\n\t\t}\n\t\tif (sdk.accessToken !== accessToken) {\n\t\t\tsetAccessToken(sdk.accessToken || null);\n\t\t}\n\t\tif (sdk.refreshToken !== refreshToken) {\n\t\t\tsetRefreshToken(sdk.refreshToken || null);\n\t\t}\n\t\tif (sdk.accessTokenExpired !== accessTokenExpired) {\n\t\t\tsetAccessTokenExpired(sdk.accessTokenExpired);\n\t\t}\n\t\tif (sdk.accessTokenExpirationDate !== accessTokenExpirationDate) {\n\t\t\tsetAccessTokenExpirationDate(sdk.accessTokenExpirationDate || null);\n\t\t}\n\t};\n\n\tuseEffect(() => {\n\t\tsdk = initFlow(options as never);\n\t\tconst sdkEvents = sdk.subscribeToAllEvents(updateSession);\n\n\t\tif (session) {\n\t\t\tsdk.session = session;\n\t\t}\n\n\t\tvoid updateSession();\n\n\t\treturn () => {\n\t\t\tsdkEvents.dispose();\n\t\t};\n\t}, []);\n\n\tconst value = useMemo<SDKContext<RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow>>(() => {\n\t\treturn {\n\t\t\tsdk,\n\t\t\tloading,\n\t\t\tlanguage,\n\t\t\tisAuthenticated,\n\t\t\tidTokenClaims,\n\t\t\taccessToken,\n\t\t\trefreshToken,\n\t\t\taccessTokenExpired,\n\t\t\taccessTokenExpirationDate,\n\t\t\tinit: () => sdk.init(),\n\t\t\tsubscribeToEvent: ((...args: Parameters<typeof sdk.subscribeToEvent>) => sdk.subscribeToEvent(...args)) as typeof sdk.subscribeToEvent,\n\t\t\tsubscribeToAllEvents: (...args: Parameters<typeof sdk.subscribeToAllEvents>) => sdk.subscribeToAllEvents(...args),\n\t\t\tcheckAuthentication: (...args: Parameters<typeof sdk.checkAuthentication>) => sdk.checkAuthentication(...args),\n\t\t\ttokenExchange: (...args: Parameters<typeof sdk.tokenExchange>) => sdk.tokenExchange(...args),\n\t\t\thandleCallback: (...args: Parameters<typeof sdk.handleCallback>) => sdk.handleCallback(...args),\n\t\t\trefresh: (...args: Parameters<typeof sdk.refresh>) => sdk.refresh(...args),\n\t\t\trevoke: () => sdk.revoke(),\n\t\t\tlogout: (...args: Parameters<typeof sdk.logout>) => sdk.logout(...args),\n\t\t\tlogin: (...args: Parameters<typeof sdk.login>) => sdk.login(...args),\n\t\t\tregister: (...args: Parameters<typeof sdk.register>) => sdk.register(...args),\n\t\t\tentry: (...args: Parameters<typeof sdk.entry>) => sdk.entry(...args),\n\t\t};\n\t}, [sdk, loading, isAuthenticated, idTokenClaims, accessToken, refreshToken, accessTokenExpired, accessTokenExpirationDate]);\n\n\treturn <STRIVACITY_SDK.Provider value={value}>{children}</STRIVACITY_SDK.Provider>;\n}\n"],"mappings":"oNAiBA,IAAA,EACC,SAAO,EAAS,CAAA,UAAc,UAAA,YAAsB,CACpD,GAAM,CAAC,EAAA,IAAU,EAAA,EAAe,SAAA,CAAA,EAAiB,EAC3C,CAAC,EAAA,IAAiB,EAAA,EAAA,SAAsB,CAAA,WAAA,WAAuB,UAAA,OAAA,EAC/D,CAAC,EAAe,IAAoB,EAAA,EAAA,SAA+B,CAAI,EAAA,EACvE,CAAC,EAAa,IAAkB,EAAA,EAAA,SAAwB,CAAI,IAAA,EAC5D,CAAC,EAAA,IAAc,EAAA,EAAmB,SAAA,CAAA,IAAwB,EAC1D,CAAC,EAAA,IAAoB,EAAA,EAAA,SAAyB,CAAA,IAAA,EAC9C,CAAC,EAAA,IAA2B,EAAA,EAAA,SAAgC,CAAA,EAAA,EAE5D,CAAA,EAA4B,IAAA,EAAA,EAAA,SAAA,CAAA,IAAA,EACjC,EAAM,SAA0B,CAEhC,IAAI,EACH,MAAW,EAAK,gBAEb,GAAI,EAAa,EAAA,EAGjB,EAAA,WAAA,GAAkB,EACrB,EAAA,QAAA,EAEG,IAAI,GAAkB,EACR,CAAI,EAElB,EAAI,gBAAgB,GACvB,EAAmB,EAAA,eAAmB,IAAA,EAEnC,EAAI,cAAA,GAAiB,EACxB,EAAgB,aAAI,IAAgB,EAEjC,EAAI,eAAA,GAAuB,EAC9B,EAAA,cAAsB,IAAI,EAEvB,EAAI,qBAAA,GAA8B,EACrC,EAAA,kBAA6B,EAE/B,EAAA,4BAAA,GAAA,EAAA,EAAA,2BAAA,IAAA,CAEA,GACC,EAAA,EAAA,UAAM,KAAA,CACN,GAAM,EAAA,EAAgB,SAAA,CAAA,CAAqB,EAE3C,IAAI,EACC,EAAA,qBAAU,CAAA,EAMd,OAHI,IAAA,EAAc,QAAA,GAEnB,EAAa,MACF,CACX,EAAA,QAAA,CACD,CAEA,EAAA,CAAA,CAAA,EACC,IAAA,GAAO,EAAA,EAAA,QAAA,MACN,CACA,MACA,UACA,WACA,kBACA,gBACA,cACA,eACA,qBACA,4BACA,SAAA,EAAA,KAAoB,EACpB,mBAAA,GAAuB,IAAG,EAAsD,iBAAI,GAAA,CAAqB,GACzG,sBAAsB,GAAG,IAAqD,EAAI,qBAAoB,GAAG,CAAI,EAC7G,qBAAmB,GAAA,IAAmD,EAAA,oBAAqB,GAAA,CAAA,EAC3F,eAAA,GAAiB,IAAG,EAAgD,cAAI,GAAe,CAAG,EAC1F,gBAAa,GAAA,IAA6C,EAAA,eAAe,GAAA,CAAA,EACzE,SAAA,GAAA,IAAkB,EAAO,QAAA,GAAA,CAAA,EACzB,WAAY,EAAA,OAA4C,EACxD,QAAQ,GAAG,IAAuC,EAAI,OAAM,GAAG,CAAI,EACnE,OAAA,GAAW,IAAG,EAA0C,MAAI,GAAA,CAAS,EACrE,UAAW,GAAA,IAAuC,EAAI,SAAS,GAAI,CAAA,EACpE,OAAA,GAAA,IAAA,EAAA,MAAA,GAAA,CAAA,CACD,GAAI,CAAK,EAAS,EAAiB,EAAe,EAAa,EAAc,EAAoB,EAA0B,CAE3H,CAAA,EAAuC,OAAA,EAAA,EAAA,IAAA,CAAA,EAAA,eAAA,SAAA,CAAQ,QAAkC,UAClF,CAAA"}
|
package/dist/components.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";"use client";import{STRIVACITY_SDK as e}from"./hooks.mjs";import{useEffect as t,useMemo as n,useState as r}from"react";import{initFlow as i}from"@strivacity/sdk-core";import{jsx as a}from"react/jsx-runtime";var o;function s({options:s,session:c,children:l}){let[u,d]=r(!0),[f,p]=r(globalThis.navigator?.language??`en-US`),[m,h]=r(!1),[g,_]=r(null),[v,y]=r(null),[b,x]=r(null),[S,C]=r(!0),[w,T]=r(null),E=async()=>{let e=await o.isAuthenticated;u&&d(!1),o.language!==f&&p(o.language),e!==m&&h(e),o.idTokenClaims!==g&&_(o.idTokenClaims||null),o.accessToken!==v&&y(o.accessToken||null),o.refreshToken!==b&&x(o.refreshToken||null),o.accessTokenExpired!==S&&C(o.accessTokenExpired),o.accessTokenExpirationDate!==w&&T(o.accessTokenExpirationDate||null)};t(()=>{o=i(s);let e=o.subscribeToAllEvents(E);return c&&(o.session=c),E(),()=>{e.dispose()}},[]);let D=n(()=>({sdk:o,loading:u,language:f,isAuthenticated:m,idTokenClaims:g,accessToken:v,refreshToken:b,accessTokenExpired:S,accessTokenExpirationDate:w,init:()=>o.init(),subscribeToEvent:((...e)=>o.subscribeToEvent(...e)),subscribeToAllEvents:(...e)=>o.subscribeToAllEvents(...e),checkAuthentication:(...e)=>o.checkAuthentication(...e),tokenExchange:(...e)=>o.tokenExchange(...e),handleCallback:(...e)=>o.handleCallback(...e),refresh:()=>o.refresh(),revoke:()=>o.revoke(),logout:(...e)=>o.logout(...e),login:(...e)=>o.login(...e),register:(...e)=>o.register(...e),entry:(...e)=>o.entry(...e)}),[o,u,m,g,v,b,S,w]);return a(e.Provider,{value:D,children:l})}export{s as StyAuthProvider};
|
|
1
|
+
"use client";"use client";import{STRIVACITY_SDK as e}from"./hooks.mjs";import{useEffect as t,useMemo as n,useState as r}from"react";import{initFlow as i}from"@strivacity/sdk-core";import{jsx as a}from"react/jsx-runtime";var o;function s({options:s,session:c,children:l}){let[u,d]=r(!0),[f,p]=r(globalThis.navigator?.language??`en-US`),[m,h]=r(!1),[g,_]=r(null),[v,y]=r(null),[b,x]=r(null),[S,C]=r(!0),[w,T]=r(null),E=async()=>{let e=await o.isAuthenticated;u&&d(!1),o.language!==f&&p(o.language),e!==m&&h(e),o.idTokenClaims!==g&&_(o.idTokenClaims||null),o.accessToken!==v&&y(o.accessToken||null),o.refreshToken!==b&&x(o.refreshToken||null),o.accessTokenExpired!==S&&C(o.accessTokenExpired),o.accessTokenExpirationDate!==w&&T(o.accessTokenExpirationDate||null)};t(()=>{o=i(s);let e=o.subscribeToAllEvents(E);return c&&(o.session=c),E(),()=>{e.dispose()}},[]);let D=n(()=>({sdk:o,loading:u,language:f,isAuthenticated:m,idTokenClaims:g,accessToken:v,refreshToken:b,accessTokenExpired:S,accessTokenExpirationDate:w,init:()=>o.init(),subscribeToEvent:((...e)=>o.subscribeToEvent(...e)),subscribeToAllEvents:(...e)=>o.subscribeToAllEvents(...e),checkAuthentication:(...e)=>o.checkAuthentication(...e),tokenExchange:(...e)=>o.tokenExchange(...e),handleCallback:(...e)=>o.handleCallback(...e),refresh:(...e)=>o.refresh(...e),revoke:()=>o.revoke(),logout:(...e)=>o.logout(...e),login:(...e)=>o.login(...e),register:(...e)=>o.register(...e),entry:(...e)=>o.entry(...e)}),[o,u,m,g,v,b,S,w]);return a(e.Provider,{value:D,children:l})}export{s as StyAuthProvider};
|
|
2
2
|
//# sourceMappingURL=components.mjs.map
|
package/dist/components.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.mjs","names":[],"sources":["../src/components.tsx"],"sourcesContent":["'use client';\n\nimport type { IdTokenClaims, RedirectFlow, PopupFlow, EmbeddedFlow, NativeFlow, SDKContext, SDKInstance, StyAuthProviderProps } from './types';\nimport { type JSX, useEffect, useMemo, useState } from 'react';\nimport { initFlow } from '@strivacity/sdk-core';\nimport { STRIVACITY_SDK } from './hooks';\n\nlet sdk: SDKInstance;\n\n/**\n * The `StyAuthProvider` component is a React context provider that initializes the Strivacity SDK and provides its state and methods to the rest of the application.\n *\n * @param {StyAuthProviderProps} props - The properties for the `StyAuthProvider` component.\n * @param {SDKInitConfig} props.options - The configuration options for initializing the Strivacity SDK.\n * @param {ReactNode} props.children - The child components that will have access to the SDK context.\n * @param {SessionData | null} [props.session] - Optional session data to initialize the SDK with.\n */\nexport function StyAuthProvider({ options, session, children }: StyAuthProviderProps): JSX.Element {\n\tconst [loading, setLoading] = useState<boolean>(true);\n\tconst [language, setLanguage] = useState<string>(globalThis.navigator?.language ?? 'en-US');\n\tconst [isAuthenticated, setIsAuthenticated] = useState<boolean>(false);\n\tconst [idTokenClaims, setIdTokenClaims] = useState<IdTokenClaims | null>(null);\n\tconst [accessToken, setAccessToken] = useState<string | null>(null);\n\tconst [refreshToken, setRefreshToken] = useState<string | null>(null);\n\tconst [accessTokenExpired, setAccessTokenExpired] = useState<boolean>(true);\n\tconst [accessTokenExpirationDate, setAccessTokenExpirationDate] = useState<number | null>(null);\n\n\tconst updateSession = async () => {\n\t\tconst authenticated = await sdk.isAuthenticated;\n\n\t\tif (loading) {\n\t\t\tsetLoading(false);\n\t\t}\n\t\tif (sdk.language !== language) {\n\t\t\tsetLanguage(sdk.language);\n\t\t}\n\t\tif (authenticated !== isAuthenticated) {\n\t\t\tsetIsAuthenticated(authenticated);\n\t\t}\n\t\tif (sdk.idTokenClaims !== idTokenClaims) {\n\t\t\tsetIdTokenClaims(sdk.idTokenClaims || null);\n\t\t}\n\t\tif (sdk.accessToken !== accessToken) {\n\t\t\tsetAccessToken(sdk.accessToken || null);\n\t\t}\n\t\tif (sdk.refreshToken !== refreshToken) {\n\t\t\tsetRefreshToken(sdk.refreshToken || null);\n\t\t}\n\t\tif (sdk.accessTokenExpired !== accessTokenExpired) {\n\t\t\tsetAccessTokenExpired(sdk.accessTokenExpired);\n\t\t}\n\t\tif (sdk.accessTokenExpirationDate !== accessTokenExpirationDate) {\n\t\t\tsetAccessTokenExpirationDate(sdk.accessTokenExpirationDate || null);\n\t\t}\n\t};\n\n\tuseEffect(() => {\n\t\tsdk = initFlow(options as never);\n\t\tconst sdkEvents = sdk.subscribeToAllEvents(updateSession);\n\n\t\tif (session) {\n\t\t\tsdk.session = session;\n\t\t}\n\n\t\tvoid updateSession();\n\n\t\treturn () => {\n\t\t\tsdkEvents.dispose();\n\t\t};\n\t}, []);\n\n\tconst value = useMemo<SDKContext<RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow>>(() => {\n\t\treturn {\n\t\t\tsdk,\n\t\t\tloading,\n\t\t\tlanguage,\n\t\t\tisAuthenticated,\n\t\t\tidTokenClaims,\n\t\t\taccessToken,\n\t\t\trefreshToken,\n\t\t\taccessTokenExpired,\n\t\t\taccessTokenExpirationDate,\n\t\t\tinit: () => sdk.init(),\n\t\t\tsubscribeToEvent: ((...args: Parameters<typeof sdk.subscribeToEvent>) => sdk.subscribeToEvent(...args)) as typeof sdk.subscribeToEvent,\n\t\t\tsubscribeToAllEvents: (...args: Parameters<typeof sdk.subscribeToAllEvents>) => sdk.subscribeToAllEvents(...args),\n\t\t\tcheckAuthentication: (...args: Parameters<typeof sdk.checkAuthentication>) => sdk.checkAuthentication(...args),\n\t\t\ttokenExchange: (...args: Parameters<typeof sdk.tokenExchange>) => sdk.tokenExchange(...args),\n\t\t\thandleCallback: (...args: Parameters<typeof sdk.handleCallback>) => sdk.handleCallback(...args),\n\t\t\trefresh: () => sdk.refresh(),\n\t\t\trevoke: () => sdk.revoke(),\n\t\t\tlogout: (...args: Parameters<typeof sdk.logout>) => sdk.logout(...args),\n\t\t\tlogin: (...args: Parameters<typeof sdk.login>) => sdk.login(...args),\n\t\t\tregister: (...args: Parameters<typeof sdk.register>) => sdk.register(...args),\n\t\t\tentry: (...args: Parameters<typeof sdk.entry>) => sdk.entry(...args),\n\t\t};\n\t}, [sdk, loading, isAuthenticated, idTokenClaims, accessToken, refreshToken, accessTokenExpired, accessTokenExpirationDate]);\n\n\treturn <STRIVACITY_SDK.Provider value={value}>{children}</STRIVACITY_SDK.Provider>;\n}\n"],"mappings":"4NAiBA,IAAA,EACC,SAAO,EAAS,CAAA,UAAc,UAAsB,YAAA,CACpD,GAAM,CAAC,EAAA,GAAU,EAAe,EAAiB,EAC3C,CAAC,EAAA,GAAiB,EAAA,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nimport type { IdTokenClaims, RedirectFlow, PopupFlow, EmbeddedFlow, NativeFlow, SDKContext, SDKInstance, StyAuthProviderProps } from './types';\nimport { type JSX, useEffect, useMemo, useState } from 'react';\nimport { initFlow } from '@strivacity/sdk-core';\nimport { STRIVACITY_SDK } from './hooks';\n\nlet sdk: SDKInstance;\n\n/**\n * The `StyAuthProvider` component is a React context provider that initializes the Strivacity SDK and provides its state and methods to the rest of the application.\n *\n * @param {StyAuthProviderProps} props - The properties for the `StyAuthProvider` component.\n * @param {SDKInitConfig} props.options - The configuration options for initializing the Strivacity SDK.\n * @param {ReactNode} props.children - The child components that will have access to the SDK context.\n * @param {SessionData | null} [props.session] - Optional session data to initialize the SDK with.\n */\nexport function StyAuthProvider({ options, session, children }: StyAuthProviderProps): JSX.Element {\n\tconst [loading, setLoading] = useState<boolean>(true);\n\tconst [language, setLanguage] = useState<string>(globalThis.navigator?.language ?? 'en-US');\n\tconst [isAuthenticated, setIsAuthenticated] = useState<boolean>(false);\n\tconst [idTokenClaims, setIdTokenClaims] = useState<IdTokenClaims | null>(null);\n\tconst [accessToken, setAccessToken] = useState<string | null>(null);\n\tconst [refreshToken, setRefreshToken] = useState<string | null>(null);\n\tconst [accessTokenExpired, setAccessTokenExpired] = useState<boolean>(true);\n\tconst [accessTokenExpirationDate, setAccessTokenExpirationDate] = useState<number | null>(null);\n\n\tconst updateSession = async () => {\n\t\tconst authenticated = await sdk.isAuthenticated;\n\n\t\tif (loading) {\n\t\t\tsetLoading(false);\n\t\t}\n\t\tif (sdk.language !== language) {\n\t\t\tsetLanguage(sdk.language);\n\t\t}\n\t\tif (authenticated !== isAuthenticated) {\n\t\t\tsetIsAuthenticated(authenticated);\n\t\t}\n\t\tif (sdk.idTokenClaims !== idTokenClaims) {\n\t\t\tsetIdTokenClaims(sdk.idTokenClaims || null);\n\t\t}\n\t\tif (sdk.accessToken !== accessToken) {\n\t\t\tsetAccessToken(sdk.accessToken || null);\n\t\t}\n\t\tif (sdk.refreshToken !== refreshToken) {\n\t\t\tsetRefreshToken(sdk.refreshToken || null);\n\t\t}\n\t\tif (sdk.accessTokenExpired !== accessTokenExpired) {\n\t\t\tsetAccessTokenExpired(sdk.accessTokenExpired);\n\t\t}\n\t\tif (sdk.accessTokenExpirationDate !== accessTokenExpirationDate) {\n\t\t\tsetAccessTokenExpirationDate(sdk.accessTokenExpirationDate || null);\n\t\t}\n\t};\n\n\tuseEffect(() => {\n\t\tsdk = initFlow(options as never);\n\t\tconst sdkEvents = sdk.subscribeToAllEvents(updateSession);\n\n\t\tif (session) {\n\t\t\tsdk.session = session;\n\t\t}\n\n\t\tvoid updateSession();\n\n\t\treturn () => {\n\t\t\tsdkEvents.dispose();\n\t\t};\n\t}, []);\n\n\tconst value = useMemo<SDKContext<RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow>>(() => {\n\t\treturn {\n\t\t\tsdk,\n\t\t\tloading,\n\t\t\tlanguage,\n\t\t\tisAuthenticated,\n\t\t\tidTokenClaims,\n\t\t\taccessToken,\n\t\t\trefreshToken,\n\t\t\taccessTokenExpired,\n\t\t\taccessTokenExpirationDate,\n\t\t\tinit: () => sdk.init(),\n\t\t\tsubscribeToEvent: ((...args: Parameters<typeof sdk.subscribeToEvent>) => sdk.subscribeToEvent(...args)) as typeof sdk.subscribeToEvent,\n\t\t\tsubscribeToAllEvents: (...args: Parameters<typeof sdk.subscribeToAllEvents>) => sdk.subscribeToAllEvents(...args),\n\t\t\tcheckAuthentication: (...args: Parameters<typeof sdk.checkAuthentication>) => sdk.checkAuthentication(...args),\n\t\t\ttokenExchange: (...args: Parameters<typeof sdk.tokenExchange>) => sdk.tokenExchange(...args),\n\t\t\thandleCallback: (...args: Parameters<typeof sdk.handleCallback>) => sdk.handleCallback(...args),\n\t\t\trefresh: (...args: Parameters<typeof sdk.refresh>) => sdk.refresh(...args),\n\t\t\trevoke: () => sdk.revoke(),\n\t\t\tlogout: (...args: Parameters<typeof sdk.logout>) => sdk.logout(...args),\n\t\t\tlogin: (...args: Parameters<typeof sdk.login>) => sdk.login(...args),\n\t\t\tregister: (...args: Parameters<typeof sdk.register>) => sdk.register(...args),\n\t\t\tentry: (...args: Parameters<typeof sdk.entry>) => sdk.entry(...args),\n\t\t};\n\t}, [sdk, loading, isAuthenticated, idTokenClaims, accessToken, refreshToken, accessTokenExpired, accessTokenExpirationDate]);\n\n\treturn <STRIVACITY_SDK.Provider value={value}>{children}</STRIVACITY_SDK.Provider>;\n}\n"],"mappings":"4NAiBA,IAAA,EACC,SAAO,EAAS,CAAA,UAAc,UAAsB,YAAA,CACpD,GAAM,CAAC,EAAA,GAAU,EAAe,EAAiB,EAC3C,CAAC,EAAA,GAAiB,EAAA,WAAsB,WAAuB,UAAA,OAAA,EAC/D,CAAC,EAAe,GAAoB,EAAmC,EAAA,EACvE,CAAC,EAAa,GAAkB,EAA4B,IAAA,EAC5D,CAAC,EAAA,GAAc,EAAmB,IAAwB,EAC1D,CAAC,EAAA,GAAoB,EAAA,IAAyB,EAC9C,CAAC,EAAA,GAA2B,EAAA,EAAA,EAE5B,CAAA,EAA4B,GAAA,EAAA,IAAA,EACjC,EAAM,SAA0B,CAEhC,IAAI,EACH,MAAW,EAAK,gBAEb,GAAI,EAAa,EAAA,EAGjB,EAAA,WAAA,GAAkB,EACrB,EAAA,QAAA,EAEG,IAAI,GAAkB,EACR,CAAI,EAElB,EAAI,gBAAgB,GACvB,EAAmB,EAAA,eAAmB,IAAA,EAEnC,EAAI,cAAA,GAAiB,EACxB,EAAgB,aAAI,IAAgB,EAEjC,EAAI,eAAA,GAAuB,EAC9B,EAAA,cAAsB,IAAI,EAEvB,EAAI,qBAAA,GAA8B,EACrC,EAAA,kBAA6B,EAE/B,EAAA,4BAAA,GAAA,EAAA,EAAA,2BAAA,IAAA,CAEA,EACC,MAAe,CACf,EAAM,EAAA,CAAgB,EAEtB,IAAI,EACC,EAAA,qBAAU,CAAA,EAMd,OAHI,IAAA,EAAc,QAAA,GAEnB,EAAa,MACF,CACX,EAAA,QAAA,CACD,CAEA,EAAA,CAAA,CAAA,EACC,IAAA,EAAO,OACN,CACA,MACA,UACA,WACA,kBACA,gBACA,cACA,eACA,qBACA,4BACA,SAAA,EAAA,KAAoB,EACpB,mBAAA,GAAuB,IAAG,EAAsD,iBAAI,GAAA,CAAqB,GACzG,sBAAsB,GAAG,IAAqD,EAAI,qBAAoB,GAAG,CAAI,EAC7G,qBAAmB,GAAA,IAAmD,EAAA,oBAAqB,GAAA,CAAA,EAC3F,eAAA,GAAiB,IAAG,EAAgD,cAAI,GAAe,CAAG,EAC1F,gBAAa,GAAA,IAA6C,EAAA,eAAe,GAAA,CAAA,EACzE,SAAA,GAAA,IAAkB,EAAO,QAAA,GAAA,CAAA,EACzB,WAAY,EAAA,OAA4C,EACxD,QAAQ,GAAG,IAAuC,EAAI,OAAM,GAAG,CAAI,EACnE,OAAA,GAAW,IAAG,EAA0C,MAAI,GAAA,CAAS,EACrE,UAAW,GAAA,IAAuC,EAAI,SAAS,GAAI,CAAA,EACpE,OAAA,GAAA,IAAA,EAAA,MAAA,GAAA,CAAA,CACD,GAAI,CAAK,EAAS,EAAiB,EAAe,EAAa,EAAc,EAAoB,EAA0B,CAE3H,CAAA,EAAuC,OAAA,EAAA,EAAA,SAAA,CAAQ,QAAkC,UAClF,CAAA"}
|
package/dist/errors.cjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=errors.cjs.map
|
|
1
|
+
var e=require("@strivacity/sdk-core/utils/errors");Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
|
package/dist/errors.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=errors.mjs.map
|
|
1
|
+
export*from"@strivacity/sdk-core/utils/errors";
|
package/dist/hooks.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});
|
|
1
|
+
"use client";"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@strivacity/sdk-core/utils"),t=require("react"),n=require("@strivacity/sdk-core/utils/path"),r=require("react/jsx-runtime");var i=(0,t.createContext)(null),a=new Set,o={loading:!0,forms:{},messages:{},state:{},triggerFallback:()=>void 0,triggerClose:()=>void 0,submitForm:async()=>Promise.resolve(void 0),setFormValue:()=>void 0,setMessage:()=>void 0},s=o,c={subscribe:e=>(a.add(e),()=>{a.delete(e)}),notify:()=>{a.forEach(e=>e())},get:()=>s,set:e=>{s=e}},l=()=>(0,t.useSyncExternalStore)(c.subscribe,c.get),u=()=>{let e=(0,t.useContext)(i);if(!e)throw Error(`Missing SDK context`);return e};function d(n={}){let{sdk:r}=u(),i=(0,t.useMemo)(()=>(0,e.createNativeLoginController)(()=>r,n),[r]);i.setOptions(n);let a=(0,t.useSyncExternalStore)(i.subscribe,i.getSnapshot,i.getSnapshot);(0,t.useEffect)(()=>{r&&i.start()},[r,i]);let s=(0,t.useMemo)(()=>({...a,triggerFallback:i.triggerFallback,triggerClose:i.triggerClose,submitForm:i.submitForm,setFormValue:i.setFormValue,setMessage:i.setMessage}),[a,i]);return c.set(s),(0,t.useEffect)(()=>(c.set(s),c.notify(),()=>{c.set(o),c.notify()}),[s]),s}function f(e,i){return function(a){let{loading:o,sdk:s}=u(),[c,l]=(0,t.useState)(null);return(0,t.useEffect)(()=>{if(o)return;let e=!1;return s.checkAuthentication().then(t=>{if(!e&&(l(t),!t)){if(s.options.serverSessionUri&&s.session)return s.refresh();globalThis.location.href=(0,n.appendReturnTo)(i?.loginUri??`/login`)}}),()=>{e=!0}},[o,s]),o||!c?i?.onLoading?.()??null:(0,r.jsx)(e,{...a})}}exports.STRIVACITY_SDK=i,exports.useNativeLogin=d,exports.useNativeLoginContext=l,exports.useStrivacity=u,exports.withAuthGuard=f;
|
|
2
2
|
//# sourceMappingURL=hooks.cjs.map
|
package/dist/hooks.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.cjs","names":[],"sources":["../src/hooks.tsx"],"sourcesContent":["'use client';\n\nimport type { ComponentType } from 'react';\nimport type {\n\tNativeFlowState,\n\tNativeFlowMessage,\n\tRedirectFlow,\n\tPopupFlow,\n\tEmbeddedFlow,\n\tNativeFlow,\n\tNativeParams,\n\tLoginContext,\n\tSDKContext,\n\tUseNativeLoginOptions,\n\tWithAuthGuardOptions,\n} from './types';\nimport { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';\nimport { isSessionExpired, unflattenObject } from '@strivacity/sdk-core/utils';\nimport { FallbackError } from './errors';\n\nexport const STRIVACITY_SDK = createContext<SDKContext<RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow>>(null!);\n\nconst loginContextListeners = new Set<() => void>();\nconst defaultLoginContext: LoginContext = {\n\tloading: true,\n\tforms: {},\n\tmessages: {},\n\tstate: {},\n\ttriggerFallback: () => undefined,\n\ttriggerClose: () => undefined,\n\tsubmitForm: async () => Promise.resolve(undefined),\n\tsetFormValue: () => undefined,\n\tsetMessage: () => undefined,\n};\nlet currentLoginContext: LoginContext = defaultLoginContext;\n\nconst loginContextStore = {\n\tsubscribe: (listener: () => void) => {\n\t\tloginContextListeners.add(listener);\n\n\t\treturn () => {\n\t\t\tloginContextListeners.delete(listener);\n\t\t};\n\t},\n\tnotify: () => {\n\t\tloginContextListeners.forEach((listener) => listener());\n\t},\n\tget: () => currentLoginContext,\n\tset: (context: LoginContext) => {\n\t\tcurrentLoginContext = context;\n\t},\n};\n\n/**\n * A custom hook to access the native login context.\n *\n * @returns {LoginContext} The native login context.\n */\nexport const useNativeLoginContext = (): LoginContext => {\n\treturn useSyncExternalStore(loginContextStore.subscribe, loginContextStore.get);\n};\n\n/**\n * A custom hook to access the Strivacity SDK context.\n *\n * @template T - The type of the Strivacity SDK flow (RedirectFlow, PopupFlow, NativeFlow, or EmbeddedFlow).\n * @returns {SDKContext<T>} The Strivacity SDK context.\n */\nexport const useStrivacity = <\n\tT extends RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow = RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow,\n>(): SDKContext<T> => {\n\tconst context = useContext(STRIVACITY_SDK);\n\n\tif (!context) {\n\t\tthrow new Error('Missing SDK context');\n\t}\n\n\treturn context as SDKContext<T>;\n};\n\n/**\n * A custom hook that manages a native login flow session.\n *\n * @param {UseNativeLoginOptions} [options] - Optional options for the login session.\n * @returns {LoginContext} The native login context.\n */\nexport function useNativeLogin(options: UseNativeLoginOptions = {}): ReturnType<typeof useNativeLoginContext> {\n\tconst { sdk } = useStrivacity<NativeFlow>();\n\tconst optionsRef = useRef(options);\n\tconst stateRef = useRef<Partial<NativeFlowState>>({});\n\n\tconst [loading, setLoading] = useState<boolean>(true);\n\tconst [forms, setForms] = useState<Record<string, Record<string, unknown>>>({});\n\tconst [messages, setMessages] = useState<Record<string, Record<string, NativeFlowMessage>>>({});\n\tconst [state, setState] = useState<Partial<NativeFlowState>>({});\n\n\tuseEffect(() => {\n\t\toptionsRef.current = options;\n\t}, [options]);\n\n\tuseEffect(() => {\n\t\tstateRef.current = state;\n\t}, [state]);\n\n\tconst handleResponse = useCallback(\n\t\tasync (nextState: Partial<NativeFlowState>) => {\n\t\t\tif (sdk.session && !isSessionExpired(sdk.session)) {\n\t\t\t\treturn await optionsRef.current.onLogin?.(sdk.session);\n\t\t\t}\n\n\t\t\tconst newState: NativeFlowState = {\n\t\t\t\thostedUrl: nextState?.hostedUrl ?? stateRef.current.hostedUrl,\n\t\t\t\tfinalizeUrl: nextState?.finalizeUrl ?? stateRef.current.finalizeUrl,\n\t\t\t\tscreen: nextState?.screen ?? stateRef.current.screen,\n\t\t\t\tforms: nextState?.forms ?? stateRef.current.forms,\n\t\t\t\tlayout: nextState?.layout ?? stateRef.current.layout,\n\t\t\t\tmessages: nextState?.messages ?? {},\n\t\t\t\tbranding: nextState?.branding ?? stateRef.current.branding,\n\t\t\t};\n\n\t\t\tconst hasScreenChanged = newState.screen !== stateRef.current.screen;\n\n\t\t\tif (hasScreenChanged) {\n\t\t\t\tconst nextForms: Record<string, Record<string, unknown>> = {};\n\t\t\t\tconst nextMessages: Record<string, Record<string, NativeFlowMessage>> = {};\n\n\t\t\t\tfor (const form of newState.forms ?? []) {\n\t\t\t\t\tnextForms[form.id] = {};\n\t\t\t\t\tnextMessages[form.id] = {};\n\t\t\t\t}\n\n\t\t\t\tsetForms(nextForms);\n\t\t\t\tsetMessages(nextMessages);\n\t\t\t} else {\n\t\t\t\tsdk.logging?.info(`Updating screen: ${newState.screen}`);\n\t\t\t}\n\n\t\t\tsetMessages((previousMessages) => {\n\t\t\t\tconst nextMessageMap = { ...previousMessages };\n\n\t\t\t\tObject.keys(newState.messages ?? {}).forEach((formId) => {\n\t\t\t\t\tif (formId === 'global') {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n\t\t\t\t\t\tvoid optionsRef.current.onGlobalMessage?.(newState.messages?.global!);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnextMessageMap[formId] = newState.messages![formId] ?? {};\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\treturn nextMessageMap;\n\t\t\t});\n\t\t\tsetState(newState);\n\n\t\t\tif (!newState.finalizeUrl) {\n\t\t\t\tsetLoading(false);\n\t\t\t}\n\t\t},\n\t\t[sdk],\n\t);\n\n\tconst startSession = useCallback(\n\t\tasync (loginParams: NativeParams = {}) => {\n\t\t\ttry {\n\t\t\t\tsetLoading(true);\n\n\t\t\t\tconst nextState = await sdk.startSession(loginParams);\n\n\t\t\t\tif (nextState) {\n\t\t\t\t\tawait handleResponse(nextState);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof FallbackError) {\n\t\t\t\t\tsdk.logging?.error('Fallback error occurred', error);\n\t\t\t\t\tvoid optionsRef.current.onFallback?.(error);\n\t\t\t\t} else {\n\t\t\t\t\tsdk.logging?.error('Error starting session', error);\n\t\t\t\t\tvoid optionsRef.current.onError?.(error as Error);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[handleResponse, sdk],\n\t);\n\n\tconst triggerFallback = useCallback(\n\t\t(message?: string) => {\n\t\t\tsdk.logging?.warn(message ? `Triggering fallback due to: ${message}` : 'Triggering fallback');\n\n\t\t\tif (!stateRef.current.hostedUrl) {\n\t\t\t\tconst error = new Error('No hosted URL provided');\n\t\t\t\tsdk.logging?.error('Fallback error', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tvoid optionsRef.current.onFallback?.(new FallbackError(new URL(stateRef.current.hostedUrl)));\n\t\t},\n\t\t[sdk],\n\t);\n\n\tconst triggerClose = useCallback(() => {\n\t\tsdk.logging?.debug('Triggering close');\n\t\tvoid optionsRef.current.onClose?.();\n\t}, [sdk]);\n\n\tconst submitForm = useCallback(\n\t\tasync (formId: string, customBody?: Record<string, unknown>) => {\n\t\t\ttry {\n\t\t\t\tsetLoading(true);\n\n\t\t\t\tconst nextState = await sdk.submitForm(formId, customBody ?? unflattenObject(forms[formId] ?? {}));\n\n\t\t\t\tif (nextState) {\n\t\t\t\t\tawait handleResponse(nextState);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof FallbackError) {\n\t\t\t\t\tsdk.logging?.error('Fallback error occurred', error);\n\t\t\t\t\tvoid optionsRef.current.onFallback?.(error);\n\t\t\t\t} else {\n\t\t\t\t\tsdk.logging?.error('Error submitting form', error);\n\t\t\t\t\tvoid optionsRef.current.onError?.(error as Error);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[forms, handleResponse, sdk],\n\t);\n\n\tconst setFormValue = useCallback((formId: string, widgetId: string, value: unknown) => {\n\t\tsetForms((previousForms) => ({\n\t\t\t...previousForms,\n\t\t\t[formId]: {\n\t\t\t\t...(previousForms[formId] ?? {}),\n\t\t\t\t[widgetId]: value === '' ? null : value,\n\t\t\t},\n\t\t}));\n\t}, []);\n\n\tconst setMessage = useCallback((formId: string, widgetId: string, value: NativeFlowMessage) => {\n\t\tsetMessages((previousMessages) => ({\n\t\t\t...previousMessages,\n\t\t\t[formId]: {\n\t\t\t\t...(previousMessages[formId] ?? {}),\n\t\t\t\t[widgetId]: value,\n\t\t\t},\n\t\t}));\n\t}, []);\n\n\tuseEffect(() => {\n\t\tif (!sdk) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst abortController = new AbortController();\n\n\t\tsdk\n\t\t\t.init()\n\t\t\t.then(() => {\n\t\t\t\tstartSession(optionsRef.current.params).catch((error) => {\n\t\t\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tsdk.logging?.error('Error fetching authorization URI', error);\n\t\t\t\t\tvoid optionsRef.current.onError?.(error as Error);\n\t\t\t\t\tsetLoading(false);\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tsdk.logging?.error('Error initializing SDK', error);\n\t\t\t\tvoid optionsRef.current.onError?.(error as Error);\n\t\t\t\tsetLoading(false);\n\t\t\t});\n\n\t\treturn () => {\n\t\t\tabortController.abort();\n\t\t};\n\t}, [sdk, startSession]);\n\n\tconst ctx = useMemo(\n\t\t() => ({\n\t\t\tloading,\n\t\t\tforms,\n\t\t\tmessages,\n\t\t\tstate,\n\t\t\ttriggerFallback,\n\t\t\ttriggerClose,\n\t\t\tsubmitForm,\n\t\t\tsetFormValue,\n\t\t\tsetMessage,\n\t\t}),\n\t\t[loading, forms, messages, state, triggerFallback, triggerClose, submitForm, setFormValue, setMessage],\n\t);\n\n\t// Publish synchronously during render (not only in an effect): WidgetRenderer/widgets are descendants rendered in this same synchronous pass and read this store via useNativeLoginContext();\n\t// If we only wrote in an effect, they'd read the previous render's (stale) value, since effects run after the whole tree has rendered.\n\tloginContextStore.set(ctx);\n\n\tuseEffect(() => {\n\t\t// In React StrictMode (dev) effects run mount -> cleanup -> mount again without a new render in between. The cleanup below resets the store to defaultLoginContext.\n\t\t// Without this line the second \"mount\" would leave the store stuck on that empty default instead of the real ctx.\n\t\tloginContextStore.set(ctx);\n\t\tloginContextStore.notify();\n\n\t\treturn () => {\n\t\t\tloginContextStore.set(defaultLoginContext);\n\t\t\tloginContextStore.notify();\n\t\t};\n\t}, [ctx]);\n\n\treturn ctx;\n}\n\n/**\n * A higher-order component that guards a component with authentication.\n * Waits for the SDK to finish loading, then redirects to the login page if the user is not authenticated.\n *\n * @param {ComponentType<P>} WrappedComponent - The component to guard.\n * @param {WithAuthGuardOptions} [options] - Optional options for the auth guard.\n * @param {string} [opts.loginUri='/login'] - The URI to redirect to if the user is not authenticated.\n * @returns {ComponentType<P>} The guarded component.\n */\nexport function withAuthGuard<P extends object>(WrappedComponent: ComponentType<P>, options?: WithAuthGuardOptions): ComponentType<P> {\n\treturn function AuthGuard(props: P) {\n\t\tconst { loading, sdk } = useStrivacity();\n\t\tconst [authenticated, setAuthenticated] = useState<boolean | null>(null);\n\n\t\tuseEffect(() => {\n\t\t\tif (loading) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet disposed = false;\n\n\t\t\tvoid sdk.checkAuthentication().then((result) => {\n\t\t\t\tif (disposed) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetAuthenticated(result);\n\n\t\t\t\tif (!result) {\n\t\t\t\t\toptions ??= {};\n\t\t\t\t\toptions.loginUri ??= '/login';\n\t\t\t\t\tglobalThis.location.href = options.loginUri;\n\t\t\t\t}\n\t\t\t});\n\n\t\t\treturn () => {\n\t\t\t\tdisposed = true;\n\t\t\t};\n\t\t}, [loading, sdk]);\n\n\t\tif (loading || !authenticated) {\n\t\t\treturn options?.onLoading?.() ?? null;\n\t\t}\n\n\t\treturn <WrappedComponent {...props} />;\n\t};\n}\n"],"mappings":"2NAsBA,IAAM,GAAA,E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AAA,EAAI,UACH,KAAA,CAGD,GAAI,EAAA,OAEJ,IAAS,EAAA,GAeR,OAdA,EAAA,oBACC,CAAA,CAAA,KAAA,GAAA,CAGD,IAEA,EAAa,CAAA,EACZ,IACA,IAAQ,CAAA,EACR,EAAA,WAAoB,SACrB,WAAA,SAAA,KAAA,EAAA,UAGD,CAAA,MACY,CACZ,EAAA,EACD,CAEA,EAAA,CAAI,EAAA,CAAY,CAAA,EAIhB,GAAO,CAAA,EAAA,GAAA,YAAC,GAAA,MACT,EAAA,EAAA,IAAA,CAAA,EAAA,CAAA,GAAA,CAAA,CAAA,CACD"}
|
|
1
|
+
{"version":3,"file":"hooks.cjs","names":[],"sources":["../src/hooks.tsx"],"sourcesContent":["'use client';\n\nimport type { ComponentType } from 'react';\nimport type { RedirectFlow, PopupFlow, EmbeddedFlow, NativeFlow, LoginContext, SDKContext, UseNativeLoginOptions, WithAuthGuardOptions } from './types';\nimport { createContext, useContext, useEffect, useMemo, useState, useSyncExternalStore } from 'react';\nimport { createNativeLoginController } from '@strivacity/sdk-core/utils';\nimport { appendReturnTo } from '@strivacity/sdk-core/utils/path';\n\nexport const STRIVACITY_SDK = createContext<SDKContext<RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow>>(null!);\n\nconst loginContextListeners = new Set<() => void>();\nconst defaultLoginContext: LoginContext = {\n\tloading: true,\n\tforms: {},\n\tmessages: {},\n\tstate: {},\n\ttriggerFallback: () => undefined,\n\ttriggerClose: () => undefined,\n\tsubmitForm: async () => Promise.resolve(undefined),\n\tsetFormValue: () => undefined,\n\tsetMessage: () => undefined,\n};\nlet currentLoginContext: LoginContext = defaultLoginContext;\n\nconst loginContextStore = {\n\tsubscribe: (listener: () => void) => {\n\t\tloginContextListeners.add(listener);\n\n\t\treturn () => {\n\t\t\tloginContextListeners.delete(listener);\n\t\t};\n\t},\n\tnotify: () => {\n\t\tloginContextListeners.forEach((listener) => listener());\n\t},\n\tget: () => currentLoginContext,\n\tset: (context: LoginContext) => {\n\t\tcurrentLoginContext = context;\n\t},\n};\n\n/**\n * A custom hook to access the native login context.\n *\n * @returns {LoginContext} The native login context.\n */\nexport const useNativeLoginContext = (): LoginContext => {\n\treturn useSyncExternalStore(loginContextStore.subscribe, loginContextStore.get);\n};\n\n/**\n * A custom hook to access the Strivacity SDK context.\n *\n * @template T - The type of the Strivacity SDK flow (RedirectFlow, PopupFlow, NativeFlow, or EmbeddedFlow).\n * @returns {SDKContext<T>} The Strivacity SDK context.\n */\nexport const useStrivacity = <\n\tT extends RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow = RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow,\n>(): SDKContext<T> => {\n\tconst context = useContext(STRIVACITY_SDK);\n\n\tif (!context) {\n\t\tthrow new Error('Missing SDK context');\n\t}\n\n\treturn context as SDKContext<T>;\n};\n\n/**\n * A custom hook that manages a native login flow session.\n *\n * @param {UseNativeLoginOptions} [options] - Optional options for the login session.\n * @returns {LoginContext} The native login context.\n */\nexport function useNativeLogin(options: UseNativeLoginOptions = {}): ReturnType<typeof useNativeLoginContext> {\n\tconst { sdk } = useStrivacity<NativeFlow>();\n\tconst controller = useMemo(() => createNativeLoginController(() => sdk, options), [sdk]);\n\n\t// NOTE: We need to set the options on every render, because the options object may change between renders.\n\tcontroller.setOptions(options);\n\n\tconst snapshot = useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot);\n\n\tuseEffect(() => {\n\t\tif (sdk) {\n\t\t\tvoid controller.start();\n\t\t}\n\t}, [sdk, controller]);\n\n\tconst ctx = useMemo(\n\t\t() => ({\n\t\t\t...snapshot,\n\t\t\ttriggerFallback: controller.triggerFallback,\n\t\t\ttriggerClose: controller.triggerClose,\n\t\t\tsubmitForm: controller.submitForm,\n\t\t\tsetFormValue: controller.setFormValue,\n\t\t\tsetMessage: controller.setMessage,\n\t\t}),\n\t\t[snapshot, controller],\n\t);\n\n\t// Publish synchronously during render (not only in an effect): WidgetRenderer/widgets are descendants rendered in this same synchronous pass and read this store via useNativeLoginContext();\n\t// If we only wrote in an effect, they'd read the previous render's (stale) value, since effects run after the whole tree has rendered.\n\tloginContextStore.set(ctx);\n\n\tuseEffect(() => {\n\t\t// In React StrictMode (dev) effects run mount -> cleanup -> mount again without a new render in between. The cleanup below resets the store to defaultLoginContext.\n\t\t// Without this line the second \"mount\" would leave the store stuck on that empty default instead of the real ctx.\n\t\tloginContextStore.set(ctx);\n\t\tloginContextStore.notify();\n\n\t\treturn () => {\n\t\t\tloginContextStore.set(defaultLoginContext);\n\t\t\tloginContextStore.notify();\n\t\t};\n\t}, [ctx]);\n\n\treturn ctx;\n}\n\n/**\n * A higher-order component that guards a component with authentication.\n * Waits for the SDK to finish loading, then redirects to the login page if the user is not authenticated.\n *\n * @param {ComponentType<P>} WrappedComponent - The component to guard.\n * @param {WithAuthGuardOptions} [options] - Optional options for the auth guard.\n * @param {string} [opts.loginUri='/login'] - The URI to redirect to if the user is not authenticated.\n * @returns {ComponentType<P>} The guarded component.\n */\nexport function withAuthGuard<P extends object>(WrappedComponent: ComponentType<P>, options?: WithAuthGuardOptions): ComponentType<P> {\n\treturn function AuthGuard(props: P) {\n\t\tconst { loading, sdk } = useStrivacity();\n\t\tconst [authenticated, setAuthenticated] = useState<boolean | null>(null);\n\n\t\tuseEffect(() => {\n\t\t\tif (loading) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet disposed = false;\n\n\t\t\tvoid sdk.checkAuthentication().then((result) => {\n\t\t\t\tif (disposed) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetAuthenticated(result);\n\n\t\t\t\tif (!result) {\n\t\t\t\t\tif (sdk.options.serverSessionUri && sdk.session) {\n\t\t\t\t\t\treturn sdk.refresh();\n\t\t\t\t\t}\n\n\t\t\t\t\tglobalThis.location.href = appendReturnTo(options?.loginUri ?? '/login');\n\t\t\t\t}\n\t\t\t});\n\n\t\t\treturn () => {\n\t\t\t\tdisposed = true;\n\t\t\t};\n\t\t}, [loading, sdk]);\n\n\t\tif (loading || !authenticated) {\n\t\t\treturn options?.onLoading?.() ?? null;\n\t\t}\n\n\t\treturn <WrappedComponent {...props} />;\n\t};\n}\n"],"mappings":"wOAUA,IAAM,GAAA,EAAA,EAAA,cAAwB,CAAA,IAAI,EAC5B,EAAoC,IAAA,IACzC,EAAS,CACT,QAAQ,GACR,MAAA,CAAA,EACA,SAAQ,CAAA,EACR,MAAA,CAAA,EACA,oBAAoB,IAAA,GACpB,iBAAY,IAAY,GACxB,WAAA,SAAoB,QAAA,QAAA,IAAA,EAAA,EACpB,iBAAkB,IAAA,GACnB,eAAA,IAAA,EACA,EAEM,EAAoB,EACzB,EAAY,CACX,UAAA,IAEA,EAAa,IAAA,CAAA,MACZ,CACD,EAAA,OAAA,CAAA,CACD,GAEC,WAAA,CACD,EAAA,QAAA,GAAA,EAAA,CAAA,CACA,EACA,QAAM,EACL,IAAA,GAAA,CACD,EAAA,CACD,CAOA,EACC,OACD,EAAA,EAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,GAAA,EAWC,MAAgB,CAEhB,IAAK,GACJ,EAAM,EAAI,WAAM,CAAA,CAAqB,EAGtC,GAAA,CAAA,EAAO,MAAA,MAAA,qBAAA,EACR,OAAA,CAQA,EACC,SAAQ,EAAQ,EAA0B,CAAA,EAAA,CAC1C,GAAM,CAAA,OAAA,EAAa,EAGnB,GAAW,EAAW,EAAO,QAAA,MAAA,EAAA,EAAA,4BAAA,KAAA,EAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAE7B,EAAM,WAAW,CAAA,EAEjB,IAAA,GAAA,EAAA,EAAgB,qBAAA,CAAA,EAAA,UAAA,EAAA,YAAA,EAAA,WAAA,GACf,EAAA,EACC,UAAK,KAAiB,CAEpB,GAAK,EAAW,MAAA,CAEpB,EAAA,CAAA,EAAM,CAAM,CAAA,EAEV,IAAG,GAAA,EAAA,EAAA,QAAA,MAAA,CACH,GAAA,EACA,gBAAc,EAAW,gBACzB,aAAY,EAAW,aACvB,WAAA,EAAc,WACd,aAAY,EAAW,aACxB,WACC,EAAU,UAKZ,GAAA,CAAA,EAAA,CAAyB,CAAA,EAe1B,OAbC,EAAA,IAAA,CAAA,GAGC,EAAA,EAAA,UAAkB,MAClB,EAAkB,IAAA,CAAO,EAEzB,EAAa,OAAA,MACZ,CACA,EAAkB,IAAA,CAAO,EAC1B,EAAA,OAAA,CACD,GAEA,CAAA,CAAO,CAAA,EACR,CAWA,CACC,SAAO,EAAS,EAAoB,EAAA,CACnC,OAAM,SAAmB,EAAA,CACzB,GAAM,CAAC,UAAA,OAAe,EAAA,EAEtB,CAAA,EAAA,IAAgB,EAAA,EAAA,SAAA,CAAA,IAAA,EAiCjB,OAhCE,EAAA,EAAI,UACH,KAAA,CAGD,GAAI,EAAA,OAEJ,IAAS,EAAA,GAiBR,OAhBA,EAAA,oBACC,CAAA,CAAA,KAAA,GAAA,CAGD,QAEA,EAAa,CAAA,EACZ,CAAI,GAAI,CAIR,GAAA,EAAA,QAAW,kBAAgB,EAAA,QAAA,OAAA,EAAA,QAAA,EAC5B,WAAA,SAAA,MAAA,EAAA,EAAA,eAAA,CAAA,GAAA,UAAA,QAAA,CACA,CAED,CAAA,MACY,CACZ,EAAA,EACD,CAEA,EAAA,CAAI,EAAA,CAAY,CAAA,EAIhB,GAAO,CAAA,EAAA,GAAA,YAAC,GAAA,MACT,EAAA,EAAA,IAAA,CAAA,EAAA,CAAA,GAAA,CAAA,CAAA,CACD"}
|
package/dist/hooks.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";"use client";import{
|
|
1
|
+
"use client";"use client";import{createNativeLoginController as e}from"@strivacity/sdk-core/utils";import{createContext as t,useContext as n,useEffect as r,useMemo as i,useState as a,useSyncExternalStore as o}from"react";import{appendReturnTo as s}from"@strivacity/sdk-core/utils/path";import{jsx as c}from"react/jsx-runtime";var l=t(null),u=new Set,d={loading:!0,forms:{},messages:{},state:{},triggerFallback:()=>void 0,triggerClose:()=>void 0,submitForm:async()=>Promise.resolve(void 0),setFormValue:()=>void 0,setMessage:()=>void 0},f=d,p={subscribe:e=>(u.add(e),()=>{u.delete(e)}),notify:()=>{u.forEach(e=>e())},get:()=>f,set:e=>{f=e}},m=()=>o(p.subscribe,p.get),h=()=>{let e=n(l);if(!e)throw Error(`Missing SDK context`);return e};function g(t={}){let{sdk:n}=h(),a=i(()=>e(()=>n,t),[n]);a.setOptions(t);let s=o(a.subscribe,a.getSnapshot,a.getSnapshot);r(()=>{n&&a.start()},[n,a]);let c=i(()=>({...s,triggerFallback:a.triggerFallback,triggerClose:a.triggerClose,submitForm:a.submitForm,setFormValue:a.setFormValue,setMessage:a.setMessage}),[s,a]);return p.set(c),r(()=>(p.set(c),p.notify(),()=>{p.set(d),p.notify()}),[c]),c}function _(e,t){return function(n){let{loading:i,sdk:o}=h(),[l,u]=a(null);return r(()=>{if(i)return;let e=!1;return o.checkAuthentication().then(n=>{if(!e&&(u(n),!n)){if(o.options.serverSessionUri&&o.session)return o.refresh();globalThis.location.href=s(t?.loginUri??`/login`)}}),()=>{e=!0}},[i,o]),i||!l?t?.onLoading?.()??null:c(e,{...n})}}export{l as STRIVACITY_SDK,g as useNativeLogin,m as useNativeLoginContext,h as useStrivacity,_ as withAuthGuard};
|
|
2
2
|
//# sourceMappingURL=hooks.mjs.map
|
package/dist/hooks.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.mjs","names":[],"sources":["../src/hooks.tsx"],"sourcesContent":["'use client';\n\nimport type { ComponentType } from 'react';\nimport type {\n\tNativeFlowState,\n\tNativeFlowMessage,\n\tRedirectFlow,\n\tPopupFlow,\n\tEmbeddedFlow,\n\tNativeFlow,\n\tNativeParams,\n\tLoginContext,\n\tSDKContext,\n\tUseNativeLoginOptions,\n\tWithAuthGuardOptions,\n} from './types';\nimport { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';\nimport { isSessionExpired, unflattenObject } from '@strivacity/sdk-core/utils';\nimport { FallbackError } from './errors';\n\nexport const STRIVACITY_SDK = createContext<SDKContext<RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow>>(null!);\n\nconst loginContextListeners = new Set<() => void>();\nconst defaultLoginContext: LoginContext = {\n\tloading: true,\n\tforms: {},\n\tmessages: {},\n\tstate: {},\n\ttriggerFallback: () => undefined,\n\ttriggerClose: () => undefined,\n\tsubmitForm: async () => Promise.resolve(undefined),\n\tsetFormValue: () => undefined,\n\tsetMessage: () => undefined,\n};\nlet currentLoginContext: LoginContext = defaultLoginContext;\n\nconst loginContextStore = {\n\tsubscribe: (listener: () => void) => {\n\t\tloginContextListeners.add(listener);\n\n\t\treturn () => {\n\t\t\tloginContextListeners.delete(listener);\n\t\t};\n\t},\n\tnotify: () => {\n\t\tloginContextListeners.forEach((listener) => listener());\n\t},\n\tget: () => currentLoginContext,\n\tset: (context: LoginContext) => {\n\t\tcurrentLoginContext = context;\n\t},\n};\n\n/**\n * A custom hook to access the native login context.\n *\n * @returns {LoginContext} The native login context.\n */\nexport const useNativeLoginContext = (): LoginContext => {\n\treturn useSyncExternalStore(loginContextStore.subscribe, loginContextStore.get);\n};\n\n/**\n * A custom hook to access the Strivacity SDK context.\n *\n * @template T - The type of the Strivacity SDK flow (RedirectFlow, PopupFlow, NativeFlow, or EmbeddedFlow).\n * @returns {SDKContext<T>} The Strivacity SDK context.\n */\nexport const useStrivacity = <\n\tT extends RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow = RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow,\n>(): SDKContext<T> => {\n\tconst context = useContext(STRIVACITY_SDK);\n\n\tif (!context) {\n\t\tthrow new Error('Missing SDK context');\n\t}\n\n\treturn context as SDKContext<T>;\n};\n\n/**\n * A custom hook that manages a native login flow session.\n *\n * @param {UseNativeLoginOptions} [options] - Optional options for the login session.\n * @returns {LoginContext} The native login context.\n */\nexport function useNativeLogin(options: UseNativeLoginOptions = {}): ReturnType<typeof useNativeLoginContext> {\n\tconst { sdk } = useStrivacity<NativeFlow>();\n\tconst optionsRef = useRef(options);\n\tconst stateRef = useRef<Partial<NativeFlowState>>({});\n\n\tconst [loading, setLoading] = useState<boolean>(true);\n\tconst [forms, setForms] = useState<Record<string, Record<string, unknown>>>({});\n\tconst [messages, setMessages] = useState<Record<string, Record<string, NativeFlowMessage>>>({});\n\tconst [state, setState] = useState<Partial<NativeFlowState>>({});\n\n\tuseEffect(() => {\n\t\toptionsRef.current = options;\n\t}, [options]);\n\n\tuseEffect(() => {\n\t\tstateRef.current = state;\n\t}, [state]);\n\n\tconst handleResponse = useCallback(\n\t\tasync (nextState: Partial<NativeFlowState>) => {\n\t\t\tif (sdk.session && !isSessionExpired(sdk.session)) {\n\t\t\t\treturn await optionsRef.current.onLogin?.(sdk.session);\n\t\t\t}\n\n\t\t\tconst newState: NativeFlowState = {\n\t\t\t\thostedUrl: nextState?.hostedUrl ?? stateRef.current.hostedUrl,\n\t\t\t\tfinalizeUrl: nextState?.finalizeUrl ?? stateRef.current.finalizeUrl,\n\t\t\t\tscreen: nextState?.screen ?? stateRef.current.screen,\n\t\t\t\tforms: nextState?.forms ?? stateRef.current.forms,\n\t\t\t\tlayout: nextState?.layout ?? stateRef.current.layout,\n\t\t\t\tmessages: nextState?.messages ?? {},\n\t\t\t\tbranding: nextState?.branding ?? stateRef.current.branding,\n\t\t\t};\n\n\t\t\tconst hasScreenChanged = newState.screen !== stateRef.current.screen;\n\n\t\t\tif (hasScreenChanged) {\n\t\t\t\tconst nextForms: Record<string, Record<string, unknown>> = {};\n\t\t\t\tconst nextMessages: Record<string, Record<string, NativeFlowMessage>> = {};\n\n\t\t\t\tfor (const form of newState.forms ?? []) {\n\t\t\t\t\tnextForms[form.id] = {};\n\t\t\t\t\tnextMessages[form.id] = {};\n\t\t\t\t}\n\n\t\t\t\tsetForms(nextForms);\n\t\t\t\tsetMessages(nextMessages);\n\t\t\t} else {\n\t\t\t\tsdk.logging?.info(`Updating screen: ${newState.screen}`);\n\t\t\t}\n\n\t\t\tsetMessages((previousMessages) => {\n\t\t\t\tconst nextMessageMap = { ...previousMessages };\n\n\t\t\t\tObject.keys(newState.messages ?? {}).forEach((formId) => {\n\t\t\t\t\tif (formId === 'global') {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n\t\t\t\t\t\tvoid optionsRef.current.onGlobalMessage?.(newState.messages?.global!);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnextMessageMap[formId] = newState.messages![formId] ?? {};\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\treturn nextMessageMap;\n\t\t\t});\n\t\t\tsetState(newState);\n\n\t\t\tif (!newState.finalizeUrl) {\n\t\t\t\tsetLoading(false);\n\t\t\t}\n\t\t},\n\t\t[sdk],\n\t);\n\n\tconst startSession = useCallback(\n\t\tasync (loginParams: NativeParams = {}) => {\n\t\t\ttry {\n\t\t\t\tsetLoading(true);\n\n\t\t\t\tconst nextState = await sdk.startSession(loginParams);\n\n\t\t\t\tif (nextState) {\n\t\t\t\t\tawait handleResponse(nextState);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof FallbackError) {\n\t\t\t\t\tsdk.logging?.error('Fallback error occurred', error);\n\t\t\t\t\tvoid optionsRef.current.onFallback?.(error);\n\t\t\t\t} else {\n\t\t\t\t\tsdk.logging?.error('Error starting session', error);\n\t\t\t\t\tvoid optionsRef.current.onError?.(error as Error);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[handleResponse, sdk],\n\t);\n\n\tconst triggerFallback = useCallback(\n\t\t(message?: string) => {\n\t\t\tsdk.logging?.warn(message ? `Triggering fallback due to: ${message}` : 'Triggering fallback');\n\n\t\t\tif (!stateRef.current.hostedUrl) {\n\t\t\t\tconst error = new Error('No hosted URL provided');\n\t\t\t\tsdk.logging?.error('Fallback error', error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tvoid optionsRef.current.onFallback?.(new FallbackError(new URL(stateRef.current.hostedUrl)));\n\t\t},\n\t\t[sdk],\n\t);\n\n\tconst triggerClose = useCallback(() => {\n\t\tsdk.logging?.debug('Triggering close');\n\t\tvoid optionsRef.current.onClose?.();\n\t}, [sdk]);\n\n\tconst submitForm = useCallback(\n\t\tasync (formId: string, customBody?: Record<string, unknown>) => {\n\t\t\ttry {\n\t\t\t\tsetLoading(true);\n\n\t\t\t\tconst nextState = await sdk.submitForm(formId, customBody ?? unflattenObject(forms[formId] ?? {}));\n\n\t\t\t\tif (nextState) {\n\t\t\t\t\tawait handleResponse(nextState);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof FallbackError) {\n\t\t\t\t\tsdk.logging?.error('Fallback error occurred', error);\n\t\t\t\t\tvoid optionsRef.current.onFallback?.(error);\n\t\t\t\t} else {\n\t\t\t\t\tsdk.logging?.error('Error submitting form', error);\n\t\t\t\t\tvoid optionsRef.current.onError?.(error as Error);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[forms, handleResponse, sdk],\n\t);\n\n\tconst setFormValue = useCallback((formId: string, widgetId: string, value: unknown) => {\n\t\tsetForms((previousForms) => ({\n\t\t\t...previousForms,\n\t\t\t[formId]: {\n\t\t\t\t...(previousForms[formId] ?? {}),\n\t\t\t\t[widgetId]: value === '' ? null : value,\n\t\t\t},\n\t\t}));\n\t}, []);\n\n\tconst setMessage = useCallback((formId: string, widgetId: string, value: NativeFlowMessage) => {\n\t\tsetMessages((previousMessages) => ({\n\t\t\t...previousMessages,\n\t\t\t[formId]: {\n\t\t\t\t...(previousMessages[formId] ?? {}),\n\t\t\t\t[widgetId]: value,\n\t\t\t},\n\t\t}));\n\t}, []);\n\n\tuseEffect(() => {\n\t\tif (!sdk) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst abortController = new AbortController();\n\n\t\tsdk\n\t\t\t.init()\n\t\t\t.then(() => {\n\t\t\t\tstartSession(optionsRef.current.params).catch((error) => {\n\t\t\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tsdk.logging?.error('Error fetching authorization URI', error);\n\t\t\t\t\tvoid optionsRef.current.onError?.(error as Error);\n\t\t\t\t\tsetLoading(false);\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tsdk.logging?.error('Error initializing SDK', error);\n\t\t\t\tvoid optionsRef.current.onError?.(error as Error);\n\t\t\t\tsetLoading(false);\n\t\t\t});\n\n\t\treturn () => {\n\t\t\tabortController.abort();\n\t\t};\n\t}, [sdk, startSession]);\n\n\tconst ctx = useMemo(\n\t\t() => ({\n\t\t\tloading,\n\t\t\tforms,\n\t\t\tmessages,\n\t\t\tstate,\n\t\t\ttriggerFallback,\n\t\t\ttriggerClose,\n\t\t\tsubmitForm,\n\t\t\tsetFormValue,\n\t\t\tsetMessage,\n\t\t}),\n\t\t[loading, forms, messages, state, triggerFallback, triggerClose, submitForm, setFormValue, setMessage],\n\t);\n\n\t// Publish synchronously during render (not only in an effect): WidgetRenderer/widgets are descendants rendered in this same synchronous pass and read this store via useNativeLoginContext();\n\t// If we only wrote in an effect, they'd read the previous render's (stale) value, since effects run after the whole tree has rendered.\n\tloginContextStore.set(ctx);\n\n\tuseEffect(() => {\n\t\t// In React StrictMode (dev) effects run mount -> cleanup -> mount again without a new render in between. The cleanup below resets the store to defaultLoginContext.\n\t\t// Without this line the second \"mount\" would leave the store stuck on that empty default instead of the real ctx.\n\t\tloginContextStore.set(ctx);\n\t\tloginContextStore.notify();\n\n\t\treturn () => {\n\t\t\tloginContextStore.set(defaultLoginContext);\n\t\t\tloginContextStore.notify();\n\t\t};\n\t}, [ctx]);\n\n\treturn ctx;\n}\n\n/**\n * A higher-order component that guards a component with authentication.\n * Waits for the SDK to finish loading, then redirects to the login page if the user is not authenticated.\n *\n * @param {ComponentType<P>} WrappedComponent - The component to guard.\n * @param {WithAuthGuardOptions} [options] - Optional options for the auth guard.\n * @param {string} [opts.loginUri='/login'] - The URI to redirect to if the user is not authenticated.\n * @returns {ComponentType<P>} The guarded component.\n */\nexport function withAuthGuard<P extends object>(WrappedComponent: ComponentType<P>, options?: WithAuthGuardOptions): ComponentType<P> {\n\treturn function AuthGuard(props: P) {\n\t\tconst { loading, sdk } = useStrivacity();\n\t\tconst [authenticated, setAuthenticated] = useState<boolean | null>(null);\n\n\t\tuseEffect(() => {\n\t\t\tif (loading) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet disposed = false;\n\n\t\t\tvoid sdk.checkAuthentication().then((result) => {\n\t\t\t\tif (disposed) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetAuthenticated(result);\n\n\t\t\t\tif (!result) {\n\t\t\t\t\toptions ??= {};\n\t\t\t\t\toptions.loginUri ??= '/login';\n\t\t\t\t\tglobalThis.location.href = options.loginUri;\n\t\t\t\t}\n\t\t\t});\n\n\t\t\treturn () => {\n\t\t\t\tdisposed = true;\n\t\t\t};\n\t\t}, [loading, sdk]);\n\n\t\tif (loading || !authenticated) {\n\t\t\treturn options?.onLoading?.() ?? null;\n\t\t}\n\n\t\treturn <WrappedComponent {...props} />;\n\t};\n}\n"],"mappings":"6UAsBA,IAAM,EAAA,EAAA,IAAA,EACA,EAAoC,IAAA,IACzC,EAAS,CACT,QAAQ,GACR,MAAA,CAAA,EACA,SAAQ,CAAA,EACR,MAAA,CAAA,EACA,oBAAoB,IAAA,GACpB,iBAAY,IAAY,GACxB,WAAA,SAAoB,QAAA,QAAA,IAAA,EAAA,EACpB,iBAAkB,IAAA,GACnB,eAAA,IAAA,EACA,EAEM,EAAoB,EACzB,EAAY,CACX,UAAA,IAEA,EAAa,IAAA,CAAA,MACZ,CACD,EAAA,OAAA,CAAA,CACD,GAEC,WAAA,CACD,EAAA,QAAA,GAAA,EAAA,CAAA,CACA,EACA,QAAM,EACL,IAAA,GAAA,CACD,EAAA,CACD,CA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c,EAAY,EAAc,EAC5F,CAIA,CAAA,EAeD,OAbC,EAAgB,IAAA,CAAA,EAGf,OACA,EAAkB,IAAA,CAAO,EAEzB,EAAa,OAAA,MACZ,CACA,EAAkB,IAAA,CAAO,EAC1B,EAAA,OAAA,CACD,GAEA,CAAA,CAAO,CAAA,EACR,CAWA,CACC,SAAO,EAAS,EAAoB,EAAA,CACnC,OAAM,SAAmB,EAAA,CACzB,GAAM,CAAC,UAAA,OAAe,EAAA,EAEtB,CAAA,EAAgB,GAAA,EAAA,IAAA,EA+BjB,OA9BE,MACC,CAGD,GAAI,EAAA,OAEJ,IAAS,EAAA,GAeR,OAdA,EAAA,oBACC,CAAA,CAAA,KAAA,GAAA,CAGD,IAEA,EAAa,CAAA,EACZ,IACA,IAAQ,CAAA,EACR,EAAA,WAAoB,SACrB,WAAA,SAAA,KAAA,EAAA,UAGD,CAAA,MACY,CACZ,EAAA,EACD,CAEA,EAAA,CAAI,EAAA,CAAY,CAAA,EAIhB,GAAO,CAAA,EAAC,GAAiB,YAAY,GAAA,KACtC,EAAA,EAAA,CAAA,GAAA,CAAA,CAAA,CACD"}
|
|
1
|
+
{"version":3,"file":"hooks.mjs","names":[],"sources":["../src/hooks.tsx"],"sourcesContent":["'use client';\n\nimport type { ComponentType } from 'react';\nimport type { RedirectFlow, PopupFlow, EmbeddedFlow, NativeFlow, LoginContext, SDKContext, UseNativeLoginOptions, WithAuthGuardOptions } from './types';\nimport { createContext, useContext, useEffect, useMemo, useState, useSyncExternalStore } from 'react';\nimport { createNativeLoginController } from '@strivacity/sdk-core/utils';\nimport { appendReturnTo } from '@strivacity/sdk-core/utils/path';\n\nexport const STRIVACITY_SDK = createContext<SDKContext<RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow>>(null!);\n\nconst loginContextListeners = new Set<() => void>();\nconst defaultLoginContext: LoginContext = {\n\tloading: true,\n\tforms: {},\n\tmessages: {},\n\tstate: {},\n\ttriggerFallback: () => undefined,\n\ttriggerClose: () => undefined,\n\tsubmitForm: async () => Promise.resolve(undefined),\n\tsetFormValue: () => undefined,\n\tsetMessage: () => undefined,\n};\nlet currentLoginContext: LoginContext = defaultLoginContext;\n\nconst loginContextStore = {\n\tsubscribe: (listener: () => void) => {\n\t\tloginContextListeners.add(listener);\n\n\t\treturn () => {\n\t\t\tloginContextListeners.delete(listener);\n\t\t};\n\t},\n\tnotify: () => {\n\t\tloginContextListeners.forEach((listener) => listener());\n\t},\n\tget: () => currentLoginContext,\n\tset: (context: LoginContext) => {\n\t\tcurrentLoginContext = context;\n\t},\n};\n\n/**\n * A custom hook to access the native login context.\n *\n * @returns {LoginContext} The native login context.\n */\nexport const useNativeLoginContext = (): LoginContext => {\n\treturn useSyncExternalStore(loginContextStore.subscribe, loginContextStore.get);\n};\n\n/**\n * A custom hook to access the Strivacity SDK context.\n *\n * @template T - The type of the Strivacity SDK flow (RedirectFlow, PopupFlow, NativeFlow, or EmbeddedFlow).\n * @returns {SDKContext<T>} The Strivacity SDK context.\n */\nexport const useStrivacity = <\n\tT extends RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow = RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow,\n>(): SDKContext<T> => {\n\tconst context = useContext(STRIVACITY_SDK);\n\n\tif (!context) {\n\t\tthrow new Error('Missing SDK context');\n\t}\n\n\treturn context as SDKContext<T>;\n};\n\n/**\n * A custom hook that manages a native login flow session.\n *\n * @param {UseNativeLoginOptions} [options] - Optional options for the login session.\n * @returns {LoginContext} The native login context.\n */\nexport function useNativeLogin(options: UseNativeLoginOptions = {}): ReturnType<typeof useNativeLoginContext> {\n\tconst { sdk } = useStrivacity<NativeFlow>();\n\tconst controller = useMemo(() => createNativeLoginController(() => sdk, options), [sdk]);\n\n\t// NOTE: We need to set the options on every render, because the options object may change between renders.\n\tcontroller.setOptions(options);\n\n\tconst snapshot = useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot);\n\n\tuseEffect(() => {\n\t\tif (sdk) {\n\t\t\tvoid controller.start();\n\t\t}\n\t}, [sdk, controller]);\n\n\tconst ctx = useMemo(\n\t\t() => ({\n\t\t\t...snapshot,\n\t\t\ttriggerFallback: controller.triggerFallback,\n\t\t\ttriggerClose: controller.triggerClose,\n\t\t\tsubmitForm: controller.submitForm,\n\t\t\tsetFormValue: controller.setFormValue,\n\t\t\tsetMessage: controller.setMessage,\n\t\t}),\n\t\t[snapshot, controller],\n\t);\n\n\t// Publish synchronously during render (not only in an effect): WidgetRenderer/widgets are descendants rendered in this same synchronous pass and read this store via useNativeLoginContext();\n\t// If we only wrote in an effect, they'd read the previous render's (stale) value, since effects run after the whole tree has rendered.\n\tloginContextStore.set(ctx);\n\n\tuseEffect(() => {\n\t\t// In React StrictMode (dev) effects run mount -> cleanup -> mount again without a new render in between. The cleanup below resets the store to defaultLoginContext.\n\t\t// Without this line the second \"mount\" would leave the store stuck on that empty default instead of the real ctx.\n\t\tloginContextStore.set(ctx);\n\t\tloginContextStore.notify();\n\n\t\treturn () => {\n\t\t\tloginContextStore.set(defaultLoginContext);\n\t\t\tloginContextStore.notify();\n\t\t};\n\t}, [ctx]);\n\n\treturn ctx;\n}\n\n/**\n * A higher-order component that guards a component with authentication.\n * Waits for the SDK to finish loading, then redirects to the login page if the user is not authenticated.\n *\n * @param {ComponentType<P>} WrappedComponent - The component to guard.\n * @param {WithAuthGuardOptions} [options] - Optional options for the auth guard.\n * @param {string} [opts.loginUri='/login'] - The URI to redirect to if the user is not authenticated.\n * @returns {ComponentType<P>} The guarded component.\n */\nexport function withAuthGuard<P extends object>(WrappedComponent: ComponentType<P>, options?: WithAuthGuardOptions): ComponentType<P> {\n\treturn function AuthGuard(props: P) {\n\t\tconst { loading, sdk } = useStrivacity();\n\t\tconst [authenticated, setAuthenticated] = useState<boolean | null>(null);\n\n\t\tuseEffect(() => {\n\t\t\tif (loading) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet disposed = false;\n\n\t\t\tvoid sdk.checkAuthentication().then((result) => {\n\t\t\t\tif (disposed) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetAuthenticated(result);\n\n\t\t\t\tif (!result) {\n\t\t\t\t\tif (sdk.options.serverSessionUri && sdk.session) {\n\t\t\t\t\t\treturn sdk.refresh();\n\t\t\t\t\t}\n\n\t\t\t\t\tglobalThis.location.href = appendReturnTo(options?.loginUri ?? '/login');\n\t\t\t\t}\n\t\t\t});\n\n\t\t\treturn () => {\n\t\t\t\tdisposed = true;\n\t\t\t};\n\t\t}, [loading, sdk]);\n\n\t\tif (loading || !authenticated) {\n\t\t\treturn options?.onLoading?.() ?? null;\n\t\t}\n\n\t\treturn <WrappedComponent {...props} />;\n\t};\n}\n"],"mappings":"sUAUA,IAAM,EAAA,EAAA,IAAA,EACA,EAAoC,IAAA,IACzC,EAAS,CACT,QAAQ,GACR,MAAA,CAAA,EACA,SAAQ,CAAA,EACR,MAAA,CAAA,EACA,oBAAoB,IAAA,GACpB,iBAAY,IAAY,GACxB,WAAA,SAAoB,QAAA,QAAA,IAAA,EAAA,EACpB,iBAAkB,IAAA,GACnB,eAAA,IAAA,EACA,EAEM,EAAoB,EACzB,EAAY,CACX,UAAA,IAEA,EAAa,IAAA,CAAA,MACZ,CACD,EAAA,OAAA,CAAA,CACD,GAEC,WAAA,CACD,EAAA,QAAA,GAAA,EAAA,CAAA,CACA,EACA,QAAM,EACL,IAAA,GAAA,CACD,EAAA,CACD,CAOA,EACC,MACD,EAAA,EAAA,UAAA,EAAA,GAAA,EAWC,MAAgB,CAEhB,IAAK,EACJ,EAAU,CAAM,EAGjB,GAAA,CAAA,EAAO,MAAA,MAAA,qBAAA,EACR,OAAA,CAQA,EACC,SAAQ,EAAQ,EAA0B,CAAA,EAAA,CAC1C,GAAM,CAAA,OAAA,EAAa,EAGnB,EAAW,MAAkB,MAAA,EAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAE7B,EAAM,WAAW,CAAA,EAEjB,IAAA,EAAgB,EAAA,EAAA,UAAA,EAAA,YAAA,EAAA,WAAA,EACf,MACM,CAEH,GAAK,EAAW,MAAA,CAEpB,EAAA,CAAA,EAAM,CAAM,CAAA,EAEV,IAAG,EAAA,OAAA,CACH,GAAA,EACA,gBAAc,EAAW,gBACzB,aAAY,EAAW,aACvB,WAAA,EAAc,WACd,aAAY,EAAW,aACxB,WACC,EAAU,UAKZ,GAAA,CAAA,EAAA,CAAyB,CAAA,EAe1B,OAbC,EAAgB,IAAA,CAAA,EAGf,OACA,EAAkB,IAAA,CAAO,EAEzB,EAAa,OAAA,MACZ,CACA,EAAkB,IAAA,CAAO,EAC1B,EAAA,OAAA,CACD,GAEA,CAAA,CAAO,CAAA,EACR,CAWA,CACC,SAAO,EAAS,EAAoB,EAAA,CACnC,OAAM,SAAmB,EAAA,CACzB,GAAM,CAAC,UAAA,OAAe,EAAA,EAEtB,CAAA,EAAgB,GAAA,EAAA,IAAA,EAiCjB,OAhCE,MACC,CAGD,GAAI,EAAA,OAEJ,IAAS,EAAA,GAiBR,OAhBA,EAAA,oBACC,CAAA,CAAA,KAAA,GAAA,CAGD,QAEA,EAAa,CAAA,EACZ,CAAI,GAAI,CAIR,GAAA,EAAA,QAAW,kBAAgB,EAAA,QAAe,OAAS,EAAA,QAAY,EAChE,WAAA,SAAA,KAAA,EAAA,GAAA,UAAA,QAAA,CACA,CAED,CAAA,MACY,CACZ,EAAA,EACD,CAEA,EAAA,CAAI,EAAA,CAAY,CAAA,EAIhB,GAAO,CAAA,EAAC,GAAiB,YAAY,GAAA,KACtC,EAAA,EAAA,CAAA,GAAA,CAAA,CAAA,CACD"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`})
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("./errors.cjs");const e=require("./hooks.cjs"),t=require("./components.cjs");require("./storages.cjs"),require("./types.cjs"),require("./utils.cjs"),exports.STRIVACITY_SDK=e.STRIVACITY_SDK,exports.StyAuthProvider=t.StyAuthProvider,exports.useNativeLogin=e.useNativeLogin,exports.useNativeLoginContext=e.useNativeLoginContext,exports.useStrivacity=e.useStrivacity,exports.withAuthGuard=e.withAuthGuard;var n=require("@strivacity/sdk-core/flows");Object.keys(n).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return n[e]}})});var r=require("@strivacity/sdk-core/handlers");Object.keys(r).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return r[e]}})});var i=require("@strivacity/sdk-core/utils");Object.keys(i).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return i[e]}})});var a=require("@strivacity/sdk-core/utils/errors");Object.keys(a).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return a[e]}})});var o=require("@strivacity/sdk-core/storages");Object.keys(o).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return o[e]}})});var s=require("@strivacity/sdk-core/types");Object.keys(s).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return s[e]}})});
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import"./errors.mjs";import{STRIVACITY_SDK as e,useNativeLogin as t,useNativeLoginContext as n,useStrivacity as r,withAuthGuard as i}from"./hooks.mjs";import{StyAuthProvider as a}from"./components.mjs";import"./storages.mjs";import"./types.mjs";import"./utils.mjs";export*from"@strivacity/sdk-core/utils/errors";export*from"@strivacity/sdk-core/flows";export*from"@strivacity/sdk-core/handlers";export*from"@strivacity/sdk-core/utils";export*from"@strivacity/sdk-core/storages";export*from"@strivacity/sdk-core/types";export{e as STRIVACITY_SDK,a as StyAuthProvider,t as useNativeLogin,n as useNativeLoginContext,r as useStrivacity,i as withAuthGuard};
|
package/dist/storages.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var e=require("@strivacity/sdk-core/storages");Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
|
package/dist/storages.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export*from"@strivacity/sdk-core/storages";
|
package/dist/types.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var e=require("@strivacity/sdk-core/types");Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ReactNode, DetailedHTMLProps, HTMLAttributes } from 'react';
|
|
2
|
-
import { LoginComponent, NotificationComponent, LandingComponent, LanguageSelectorComponent, SDKInitConfig, SessionData, IdTokenClaims, RedirectFlow, PopupFlow, NativeFlow, EmbeddedFlow, initFlow, NativeFlowState, NativeFlowMessage,
|
|
3
|
-
import { FallbackError } from '@strivacity/sdk-core/utils';
|
|
2
|
+
import { LoginComponent, NotificationComponent, LandingComponent, LanguageSelectorComponent, SDKInitConfig, SessionData, IdTokenClaims, RedirectFlow, PopupFlow, NativeFlow, EmbeddedFlow, initFlow, NativeFlowState, NativeFlowMessage, NativeLoginControllerOptions } from '@strivacity/sdk-core';
|
|
4
3
|
export * from '@strivacity/sdk-core/types';
|
|
5
4
|
declare module 'react' {
|
|
6
5
|
namespace JSX {
|
|
@@ -173,32 +172,10 @@ export type LoginContext = {
|
|
|
173
172
|
*/
|
|
174
173
|
setMessage: (formId: string, widgetId: string, value: NativeFlowMessage) => void;
|
|
175
174
|
};
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
params?: NativeParams;
|
|
181
|
-
/**
|
|
182
|
-
* Called when the user successfully completes the login flow.
|
|
183
|
-
*/
|
|
184
|
-
onLogin?: (session: SessionData) => void | Promise<void>;
|
|
185
|
-
/**
|
|
186
|
-
* Called when the fallback flow is triggered.
|
|
187
|
-
*/
|
|
188
|
-
onFallback?: (error: FallbackError) => void | Promise<void>;
|
|
189
|
-
/**
|
|
190
|
-
* Called when the login flow is closed by the user.
|
|
191
|
-
*/
|
|
192
|
-
onClose?: () => void | Promise<void>;
|
|
193
|
-
/**
|
|
194
|
-
* Called when an error occurs during login flow initialization or submission.
|
|
195
|
-
*/
|
|
196
|
-
onError?: (error: Error) => void | Promise<void>;
|
|
197
|
-
/**
|
|
198
|
-
* Called when a global message is received during the login flow.
|
|
199
|
-
*/
|
|
200
|
-
onGlobalMessage?: (message: NativeFlowMessage) => void | Promise<void>;
|
|
201
|
-
};
|
|
175
|
+
/**
|
|
176
|
+
* Callbacks and parameters of the native login flow. See `NativeLoginControllerOptions` in `@strivacity/sdk-core`.
|
|
177
|
+
*/
|
|
178
|
+
export type UseNativeLoginOptions = NativeLoginControllerOptions;
|
|
202
179
|
export type WithAuthGuardOptions = {
|
|
203
180
|
/**
|
|
204
181
|
* The URL to redirect the user to if they are not authenticated.
|
package/dist/types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export*from"@strivacity/sdk-core/types";
|
package/dist/utils.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var e=require("@strivacity/sdk-core/utils");Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
|
package/dist/utils.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export*from"@strivacity/sdk-core/utils";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strivacity/sdk-react",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.2",
|
|
4
4
|
"description": "Strivacity React SDK client",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "strivacity <opensource@strivacity.com>",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
}
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@strivacity/sdk-core": "4.0.0-beta.
|
|
59
|
+
"@strivacity/sdk-core": "4.0.0-beta.2"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"react": ">=18"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=Object.defineProperty,t=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,i=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r},a=(i,a,o,s)=>{if(a&&typeof a==`object`||typeof a==`function`)for(var c=n(a),l=0,u=c.length,d;l<u;l++)d=c[l],!r.call(i,d)&&d!==o&&e(i,d,{get:(e=>a[e]).bind(null,d),enumerable:!(s=t(a,d))||s.enumerable});return i},o=(e,t,n)=>(a(e,t,`default`),n&&a(n,t,`default`));Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=Object.defineProperty,t=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,i=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r},a=(i,a,o,s)=>{if(a&&typeof a==`object`||typeof a==`function`)for(var c=n(a),l=0,u=c.length,d;l<u;l++)d=c[l],!r.call(i,d)&&d!==o&&e(i,d,{get:(e=>a[e]).bind(null,d),enumerable:!(s=t(a,d))||s.enumerable});return i},o=(e,t,n)=>(a(e,t,`default`),n&&a(n,t,`default`));export{o as n,i as t};
|
package/dist/errors.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export * from '@strivacity/sdk-core/utils/errors';\n"],"mappings":""}
|
package/dist/errors.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export * from '@strivacity/sdk-core/utils/errors';\n"],"mappings":""}
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from '@strivacity/sdk-core/flows';\nexport * from '@strivacity/sdk-core/handlers';\nexport * from '@strivacity/sdk-core/utils';\nexport * from './components';\nexport * from './errors';\nexport * from './hooks';\nexport * from './storages';\nexport * from './types';\nexport * from './utils';\n"],"mappings":""}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from '@strivacity/sdk-core/flows';\nexport * from '@strivacity/sdk-core/handlers';\nexport * from '@strivacity/sdk-core/utils';\nexport * from './components';\nexport * from './errors';\nexport * from './hooks';\nexport * from './storages';\nexport * from './types';\nexport * from './utils';\n"],"mappings":""}
|