@eventuras/fides-auth-react 0.1.0 → 0.1.4

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/dist/hooks.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","names":[],"sources":["../src/hooks.ts"],"sourcesContent":["import { useSelector as useStoreSelector } from '@xstate/store-react';\nimport type { SessionUser, createAuthStore } from '@eventuras/fides-auth-store';\n\n/**\n * Return type for store-based auth hooks\n */\nexport type AuthStoreSelector = {\n isAuthenticated: boolean;\n isAdmin: boolean;\n user: SessionUser | null;\n error: string | null;\n lastChecked: Date | null;\n isInitializing: boolean;\n};\n\n/**\n * Actions for store-based auth\n */\nexport type AuthStoreActions = {\n loginSuccess: (user: SessionUser) => void;\n logout: () => void;\n sessionExpired: () => void;\n authSuccess: (user: SessionUser) => void;\n authFailed: (error?: string) => void;\n setError: (error: string) => void;\n clearError: () => void;\n};\n\n/**\n * Creates React hooks for interacting with the auth store\n *\n * @param store - The XState store instance\n * @returns Object containing useAuthStore hook\n *\n * @example\n * ```typescript\n * const authStore = createAuthStore({\n * checkAuthStatus: getAuthStatus,\n * });\n *\n * export const { useAuthStore } = createAuthStoreHooks(authStore);\n *\n * // In component\n * function MyComponent() {\n * const auth = useAuthStore();\n *\n * if (auth.error) {\n * toast.error(auth.error);\n * }\n *\n * if (auth.isInitializing) {\n * return <Spinner />;\n * }\n *\n * return (\n * <div>\n * {auth.isAuthenticated ? `Hello ${auth.user?.name}` : 'Please login'}\n * </div>\n * );\n * }\n * ```\n */\nexport function createAuthStoreHooks(store: ReturnType<typeof createAuthStore>) {\n /**\n * Hook to access the auth store state\n */\n function useAuthStore(): AuthStoreSelector {\n const snapshot = useStoreSelector(store, (snapshot) => snapshot);\n return snapshot.context;\n }\n\n /**\n * Hook to get auth store actions\n */\n function useAuthActions(): AuthStoreActions {\n return {\n loginSuccess: (user: SessionUser) => store.send({ type: 'loginSuccess', user }),\n logout: () => store.send({ type: 'logout' }),\n sessionExpired: () => store.send({ type: 'sessionExpired' }),\n authSuccess: (user: SessionUser) => store.send({ type: 'authSuccess', user }),\n authFailed: (error?: string) => store.send({ type: 'authFailed', error }),\n setError: (error: string) => store.send({ type: 'setError', error }),\n clearError: () => store.send({ type: 'clearError' }),\n };\n }\n\n return {\n useAuthStore,\n useAuthActions,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,SAAgB,qBAAqB,OAA2C;;;;CAI9E,SAAS,eAAkC;EAEzC,OADiB,YAAiB,QAAQ,aAAa,QAChD,EAAS;CAClB;;;;CAKA,SAAS,iBAAmC;EAC1C,OAAO;GACL,eAAe,SAAsB,MAAM,KAAK;IAAE,MAAM;IAAgB;GAAK,CAAC;GAC9E,cAAc,MAAM,KAAK,EAAE,MAAM,SAAS,CAAC;GAC3C,sBAAsB,MAAM,KAAK,EAAE,MAAM,iBAAiB,CAAC;GAC3D,cAAc,SAAsB,MAAM,KAAK;IAAE,MAAM;IAAe;GAAK,CAAC;GAC5E,aAAa,UAAmB,MAAM,KAAK;IAAE,MAAM;IAAc;GAAM,CAAC;GACxE,WAAW,UAAkB,MAAM,KAAK;IAAE,MAAM;IAAY;GAAM,CAAC;GACnE,kBAAkB,MAAM,KAAK,EAAE,MAAM,aAAa,CAAC;EACrD;CACF;CAEA,OAAO;EACL;EACA;CACF;AACF"}
1
+ {"version":3,"file":"hooks.js","names":[],"sources":["../src/hooks.ts"],"sourcesContent":["import { useSelector as useStoreSelector } from '@xstate/store-react';\nimport type { SessionUser, createAuthStore } from '@eventuras/fides-auth-store';\n\n/**\n * Return type for store-based auth hooks\n */\nexport type AuthStoreSelector = {\n isAuthenticated: boolean;\n isAdmin: boolean;\n user: SessionUser | null;\n error: string | null;\n lastChecked: Date | null;\n isInitializing: boolean;\n};\n\n/**\n * Actions for store-based auth\n */\nexport type AuthStoreActions = {\n loginSuccess: (user: SessionUser) => void;\n logout: () => void;\n sessionExpired: () => void;\n authSuccess: (user: SessionUser) => void;\n authFailed: (error?: string) => void;\n setError: (error: string) => void;\n clearError: () => void;\n};\n\n/**\n * Creates React hooks for interacting with the auth store\n *\n * @param store - The XState store instance\n * @returns Object containing useAuthStore hook\n *\n * @example\n * ```typescript\n * const authStore = createAuthStore({\n * checkAuthStatus: getAuthStatus,\n * });\n *\n * export const { useAuthStore } = createAuthStoreHooks(authStore);\n *\n * // In component\n * function MyComponent() {\n * const auth = useAuthStore();\n *\n * if (auth.error) {\n * toast.error(auth.error);\n * }\n *\n * if (auth.isInitializing) {\n * return <Spinner />;\n * }\n *\n * return (\n * <div>\n * {auth.isAuthenticated ? `Hello ${auth.user?.name}` : 'Please login'}\n * </div>\n * );\n * }\n * ```\n */\nexport function createAuthStoreHooks(store: ReturnType<typeof createAuthStore>) {\n /**\n * Hook to access the auth store state\n */\n function useAuthStore(): AuthStoreSelector {\n const snapshot = useStoreSelector(store, (snapshot) => snapshot);\n return snapshot.context;\n }\n\n /**\n * Hook to get auth store actions\n */\n function useAuthActions(): AuthStoreActions {\n return {\n loginSuccess: (user: SessionUser) => store.send({ type: 'loginSuccess', user }),\n logout: () => store.send({ type: 'logout' }),\n sessionExpired: () => store.send({ type: 'sessionExpired' }),\n authSuccess: (user: SessionUser) => store.send({ type: 'authSuccess', user }),\n authFailed: (error?: string) => store.send({ type: 'authFailed', error }),\n setError: (error: string) => store.send({ type: 'setError', error }),\n clearError: () => store.send({ type: 'clearError' }),\n };\n }\n\n return {\n useAuthStore,\n useAuthActions,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,SAAgB,qBAAqB,OAA2C;;;;CAI9E,SAAS,eAAkC;EAEzC,OADiB,YAAiB,QAAQ,aAAa,QAChD,CAAA,CAAS;CAClB;;;;CAKA,SAAS,iBAAmC;EAC1C,OAAO;GACL,eAAe,SAAsB,MAAM,KAAK;IAAE,MAAM;IAAgB;GAAK,CAAC;GAC9E,cAAc,MAAM,KAAK,EAAE,MAAM,SAAS,CAAC;GAC3C,sBAAsB,MAAM,KAAK,EAAE,MAAM,iBAAiB,CAAC;GAC3D,cAAc,SAAsB,MAAM,KAAK;IAAE,MAAM;IAAe;GAAK,CAAC;GAC5E,aAAa,UAAmB,MAAM,KAAK;IAAE,MAAM;IAAc;GAAM,CAAC;GACxE,WAAW,UAAkB,MAAM,KAAK;IAAE,MAAM;IAAY;GAAM,CAAC;GACnE,kBAAkB,MAAM,KAAK,EAAE,MAAM,aAAa,CAAC;EACrD;CACF;CAEA,OAAO;EACL;EACA;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-heartbeat.d.ts","sourceRoot":"","sources":["../src/use-heartbeat.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAExF,YAAY,EAAE,eAAe,EAAE,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,MAAM,GAAE,eAAoB,GAAG,IAAI,CAsC/D"}
1
+ {"version":3,"file":"use-heartbeat.d.ts","sourceRoot":"","sources":["../src/use-heartbeat.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAExF,YAAY,EAAE,eAAe,EAAE,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,MAAM,GAAE,eAAoB,GAAG,IAAI,CAuC/D"}
@@ -40,7 +40,8 @@ function useHeartbeat(config = {}) {
40
40
  loggerNamespace,
41
41
  onSessionExpired: () => callbacksRef.current.onSessionExpired?.(),
42
42
  onRefreshed: () => callbacksRef.current.onRefreshed?.(),
43
- onError: (error) => callbacksRef.current.onError?.(error)
43
+ onError: (error) => callbacksRef.current.onError?.(error),
44
+ onEvent: (event) => callbacksRef.current.onEvent?.(event)
44
45
  }).stop;
45
46
  }, [
46
47
  endpoint,
@@ -1 +1 @@
1
- {"version":3,"file":"use-heartbeat.js","names":[],"sources":["../src/use-heartbeat.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { createHeartbeat, type HeartbeatConfig } from '@eventuras/fides-auth/heartbeat';\n\nexport type { HeartbeatConfig };\n\n/**\n * React wrapper around the framework-agnostic {@link createHeartbeat} engine.\n *\n * Starts the heartbeat on mount and stops it on unmount. Callbacks are read\n * through a ref so changing their identity between renders does not restart the\n * engine; the primitive options are the effect's dependencies.\n *\n * Intended to be paired with {@link useSessionMonitor}: the monitor *detects*\n * session loss; this hook *prevents* it for active users. See\n * {@link HeartbeatConfig} for the tuning knobs.\n *\n * @example\n * ```tsx\n * 'use client';\n * import { useHeartbeat, useSessionMonitor } from '@eventuras/fides-auth-react';\n *\n * function AuthProvider({ children }) {\n * useSessionMonitor(authStore, checkAuthStatus);\n * useHeartbeat({ onSessionExpired: () => authStore.send({ type: 'sessionExpired' }) });\n * return <>{children}</>;\n * }\n * ```\n */\nexport function useHeartbeat(config: HeartbeatConfig = {}): void {\n const {\n endpoint,\n fraction,\n minSkewMs,\n minRefreshIntervalMs,\n idleThresholdMs,\n initialExpiresAt,\n loggerNamespace,\n } = config;\n\n // Keep callbacks current without re-running the effect when their identities change.\n const callbacksRef = useRef(config);\n callbacksRef.current = config;\n\n useEffect(() => {\n const handle = createHeartbeat({\n endpoint,\n fraction,\n minSkewMs,\n minRefreshIntervalMs,\n idleThresholdMs,\n initialExpiresAt,\n loggerNamespace,\n onSessionExpired: () => callbacksRef.current.onSessionExpired?.(),\n onRefreshed: () => callbacksRef.current.onRefreshed?.(),\n onError: (error) => callbacksRef.current.onError?.(error),\n });\n return handle.stop;\n }, [\n endpoint,\n fraction,\n minSkewMs,\n minRefreshIntervalMs,\n idleThresholdMs,\n initialExpiresAt,\n loggerNamespace,\n ]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,aAAa,SAA0B,CAAC,GAAS;CAC/D,MAAM,EACJ,UACA,UACA,WACA,sBACA,iBACA,kBACA,oBACE;CAGJ,MAAM,eAAe,OAAO,MAAM;CAClC,aAAa,UAAU;CAEvB,gBAAgB;EAad,OAZe,gBAAgB;GAC7B;GACA;GACA;GACA;GACA;GACA;GACA;GACA,wBAAwB,aAAa,QAAQ,mBAAmB;GAChE,mBAAmB,aAAa,QAAQ,cAAc;GACtD,UAAU,UAAU,aAAa,QAAQ,UAAU,KAAK;EAC1D,CACO,EAAO;CAChB,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"use-heartbeat.js","names":[],"sources":["../src/use-heartbeat.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { createHeartbeat, type HeartbeatConfig } from '@eventuras/fides-auth/heartbeat';\n\nexport type { HeartbeatConfig };\n\n/**\n * React wrapper around the framework-agnostic {@link createHeartbeat} engine.\n *\n * Starts the heartbeat on mount and stops it on unmount. Callbacks are read\n * through a ref so changing their identity between renders does not restart the\n * engine; the primitive options are the effect's dependencies.\n *\n * Intended to be paired with {@link useSessionMonitor}: the monitor *detects*\n * session loss; this hook *prevents* it for active users. See\n * {@link HeartbeatConfig} for the tuning knobs.\n *\n * @example\n * ```tsx\n * 'use client';\n * import { useHeartbeat, useSessionMonitor } from '@eventuras/fides-auth-react';\n *\n * function AuthProvider({ children }) {\n * useSessionMonitor(authStore, checkAuthStatus);\n * useHeartbeat({ onSessionExpired: () => authStore.send({ type: 'sessionExpired' }) });\n * return <>{children}</>;\n * }\n * ```\n */\nexport function useHeartbeat(config: HeartbeatConfig = {}): void {\n const {\n endpoint,\n fraction,\n minSkewMs,\n minRefreshIntervalMs,\n idleThresholdMs,\n initialExpiresAt,\n loggerNamespace,\n } = config;\n\n // Keep callbacks current without re-running the effect when their identities change.\n const callbacksRef = useRef(config);\n callbacksRef.current = config;\n\n useEffect(() => {\n const handle = createHeartbeat({\n endpoint,\n fraction,\n minSkewMs,\n minRefreshIntervalMs,\n idleThresholdMs,\n initialExpiresAt,\n loggerNamespace,\n onSessionExpired: () => callbacksRef.current.onSessionExpired?.(),\n onRefreshed: () => callbacksRef.current.onRefreshed?.(),\n onError: (error) => callbacksRef.current.onError?.(error),\n onEvent: (event) => callbacksRef.current.onEvent?.(event),\n });\n return handle.stop;\n }, [\n endpoint,\n fraction,\n minSkewMs,\n minRefreshIntervalMs,\n idleThresholdMs,\n initialExpiresAt,\n loggerNamespace,\n ]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,aAAa,SAA0B,CAAC,GAAS;CAC/D,MAAM,EACJ,UACA,UACA,WACA,sBACA,iBACA,kBACA,oBACE;CAGJ,MAAM,eAAe,OAAO,MAAM;CAClC,aAAa,UAAU;CAEvB,gBAAgB;EAcd,OAbe,gBAAgB;GAC7B;GACA;GACA;GACA;GACA;GACA;GACA;GACA,wBAAwB,aAAa,QAAQ,mBAAmB;GAChE,mBAAmB,aAAa,QAAQ,cAAc;GACtD,UAAU,UAAU,aAAa,QAAQ,UAAU,KAAK;GACxD,UAAU,UAAU,aAAa,QAAQ,UAAU,KAAK;EAC1D,CACO,CAAA,CAAO;CAChB,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventuras/fides-auth-react",
3
- "version": "0.1.0",
3
+ "version": "0.1.4",
4
4
  "description": "React hooks for @eventuras/fides-auth — auth store bindings, session monitoring, and heartbeat",
5
5
  "keywords": [
6
6
  "authentication",
@@ -40,21 +40,22 @@
40
40
  "dependencies": {
41
41
  "@eventuras/logger": "^0.8.1",
42
42
  "@xstate/store-react": "^2.0.0",
43
- "@eventuras/fides-auth": "0.9.0",
44
- "@eventuras/fides-auth-store": "0.1.0"
43
+ "@eventuras/fides-auth": "0.13.0",
44
+ "@eventuras/fides-auth-store": "0.2.0"
45
45
  },
46
46
  "peerDependencies": {
47
- "@xstate/store": "^4.0.0",
47
+ "@xstate/store": "^4.2.2",
48
48
  "@xstate/store-react": "^2.0.0",
49
49
  "react": "^19.0.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@types/react": "^19.2.14",
53
- "@xstate/store": "^4.0.0",
52
+ "@types/react": "^19.2.18",
53
+ "@xstate/store": "^4.2.2",
54
54
  "@xstate/store-react": "^2.0.0",
55
- "react": "^19.2.0",
56
- "vite": "^8.0.8",
57
- "vitest": "^4.1.6",
55
+ "react": "^19.2.8",
56
+ "typescript": "^6.0.2",
57
+ "vite": "^8.2.0",
58
+ "vitest": "^4.1.10",
58
59
  "@eventuras/typescript-config": "1.0.0",
59
60
  "@eventuras/vite-config": "0.2.2"
60
61
  },
@@ -63,6 +64,7 @@
63
64
  },
64
65
  "scripts": {
65
66
  "build": "vite build",
67
+ "typecheck": "tsc --noEmit",
66
68
  "dev": "vite build --watch",
67
69
  "test": "vitest run",
68
70
  "test:watch": "vitest"