quidproquo-web-react 0.0.208 → 0.0.210

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/lib/commonjs/api/hooks/index.d.ts +2 -0
  2. package/lib/commonjs/api/hooks/index.js +18 -0
  3. package/lib/commonjs/api/hooks/useAuthenticatedNetworkRequest.d.ts +2 -0
  4. package/lib/commonjs/api/hooks/useAuthenticatedNetworkRequest.js +14 -0
  5. package/lib/commonjs/api/hooks/useNetworkRequest.d.ts +2 -0
  6. package/lib/commonjs/api/hooks/useNetworkRequest.js +10 -0
  7. package/lib/commonjs/api/index.d.ts +1 -0
  8. package/lib/commonjs/api/index.js +17 -0
  9. package/lib/commonjs/auth/authContext.d.ts +3 -0
  10. package/lib/commonjs/auth/authContext.js +8 -0
  11. package/lib/commonjs/auth/hooks/index.d.ts +3 -0
  12. package/lib/commonjs/auth/hooks/index.js +19 -0
  13. package/lib/commonjs/auth/hooks/useAuthAccessToken.d.ts +1 -0
  14. package/lib/commonjs/auth/hooks/useAuthAccessToken.js +12 -0
  15. package/lib/commonjs/auth/hooks/useIsLoggedIn.d.ts +1 -0
  16. package/lib/commonjs/auth/hooks/useIsLoggedIn.js +11 -0
  17. package/lib/commonjs/auth/hooks/useRefreshTokens.d.ts +2 -0
  18. package/lib/commonjs/auth/hooks/useRefreshTokens.js +34 -0
  19. package/lib/commonjs/auth/index.d.ts +3 -0
  20. package/lib/commonjs/auth/index.js +19 -0
  21. package/lib/commonjs/auth/types/AuthState.d.ts +8 -0
  22. package/lib/commonjs/auth/types/AuthState.js +2 -0
  23. package/lib/commonjs/auth/types/index.d.ts +1 -0
  24. package/lib/commonjs/auth/types/index.js +17 -0
  25. package/lib/commonjs/index.d.ts +3 -0
  26. package/lib/commonjs/index.js +3 -0
  27. package/lib/commonjs/state/index.d.ts +1 -0
  28. package/lib/commonjs/state/index.js +17 -0
  29. package/lib/commonjs/state/useStateUpdater.d.ts +4 -0
  30. package/lib/commonjs/state/useStateUpdater.js +12 -0
  31. package/lib/esm/api/hooks/index.d.ts +2 -0
  32. package/lib/esm/api/hooks/index.js +2 -0
  33. package/lib/esm/api/hooks/useAuthenticatedNetworkRequest.d.ts +2 -0
  34. package/lib/esm/api/hooks/useAuthenticatedNetworkRequest.js +17 -0
  35. package/lib/esm/api/hooks/useNetworkRequest.d.ts +2 -0
  36. package/lib/esm/api/hooks/useNetworkRequest.js +6 -0
  37. package/lib/esm/api/index.d.ts +1 -0
  38. package/lib/esm/api/index.js +1 -0
  39. package/lib/esm/auth/authContext.d.ts +3 -0
  40. package/lib/esm/auth/authContext.js +5 -0
  41. package/lib/esm/auth/hooks/index.d.ts +3 -0
  42. package/lib/esm/auth/hooks/index.js +3 -0
  43. package/lib/esm/auth/hooks/useAuthAccessToken.d.ts +1 -0
  44. package/lib/esm/auth/hooks/useAuthAccessToken.js +7 -0
  45. package/lib/esm/auth/hooks/useIsLoggedIn.d.ts +1 -0
  46. package/lib/esm/auth/hooks/useIsLoggedIn.js +6 -0
  47. package/lib/esm/auth/hooks/useRefreshTokens.d.ts +2 -0
  48. package/lib/esm/auth/hooks/useRefreshTokens.js +30 -0
  49. package/lib/esm/auth/index.d.ts +3 -0
  50. package/lib/esm/auth/index.js +3 -0
  51. package/lib/esm/auth/types/AuthState.d.ts +8 -0
  52. package/lib/esm/auth/types/AuthState.js +1 -0
  53. package/lib/esm/auth/types/index.d.ts +1 -0
  54. package/lib/esm/auth/types/index.js +1 -0
  55. package/lib/esm/index.d.ts +3 -0
  56. package/lib/esm/index.js +3 -0
  57. package/lib/esm/state/index.d.ts +1 -0
  58. package/lib/esm/state/index.js +1 -0
  59. package/lib/esm/state/useStateUpdater.d.ts +4 -0
  60. package/lib/esm/state/useStateUpdater.js +11 -0
  61. package/package.json +6 -6
@@ -0,0 +1,2 @@
1
+ export * from './useNetworkRequest';
2
+ export * from './useAuthenticatedNetworkRequest';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./useNetworkRequest"), exports);
18
+ __exportStar(require("./useAuthenticatedNetworkRequest"), exports);
@@ -0,0 +1,2 @@
1
+ import { HTTPNetworkResponse, NetworkRequestActionPayload } from 'quidproquo-core';
2
+ export declare const useAuthenticatedNetworkRequest: <R>(payload: NetworkRequestActionPayload<any>) => () => Promise<HTTPNetworkResponse<R>>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAuthenticatedNetworkRequest = void 0;
4
+ const quidproquo_web_1 = require("quidproquo-web");
5
+ const hooks_1 = require("../../hooks");
6
+ const auth_1 = require("../../auth");
7
+ const useAuthenticatedNetworkRequest = (payload) => {
8
+ const authToken = (0, auth_1.useAuthAccessToken)();
9
+ const payloadWithAuthHeaders = authToken
10
+ ? Object.assign(Object.assign({}, payload), { headers: Object.assign(Object.assign({}, (payload.headers || {})), { Authorization: `Bearer ${authToken}` }) }) : payload;
11
+ const requeser = (0, hooks_1.useFastCallback)(() => (0, quidproquo_web_1.preformNetworkRequest)(payloadWithAuthHeaders));
12
+ return requeser;
13
+ };
14
+ exports.useAuthenticatedNetworkRequest = useAuthenticatedNetworkRequest;
@@ -0,0 +1,2 @@
1
+ import { HTTPNetworkResponse, NetworkRequestActionPayload } from 'quidproquo-core';
2
+ export declare const useNetworkRequest: <R>(payload: NetworkRequestActionPayload<any>) => () => Promise<HTTPNetworkResponse<R>>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useNetworkRequest = void 0;
4
+ const quidproquo_web_1 = require("quidproquo-web");
5
+ const hooks_1 = require("../../hooks");
6
+ const useNetworkRequest = (payload) => {
7
+ const requeser = (0, hooks_1.useFastCallback)(() => (0, quidproquo_web_1.preformNetworkRequest)(payload));
8
+ return requeser;
9
+ };
10
+ exports.useNetworkRequest = useNetworkRequest;
@@ -0,0 +1 @@
1
+ export * from './hooks';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./hooks"), exports);
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { AuthState } from './types';
3
+ export declare const authContext: import("react").Context<AuthState>;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authContext = void 0;
4
+ const react_1 = require("react");
5
+ exports.authContext = (0, react_1.createContext)({
6
+ username: '',
7
+ password: '',
8
+ });
@@ -0,0 +1,3 @@
1
+ export * from "./useIsLoggedIn";
2
+ export * from "./useAuthAccessToken";
3
+ export * from "./useRefreshTokens";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./useIsLoggedIn"), exports);
18
+ __exportStar(require("./useAuthAccessToken"), exports);
19
+ __exportStar(require("./useRefreshTokens"), exports);
@@ -0,0 +1 @@
1
+ export declare const useAuthAccessToken: () => string | undefined;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAuthAccessToken = void 0;
4
+ const react_1 = require("react");
5
+ const authContext_1 = require("../authContext");
6
+ const useAuthAccessToken = () => {
7
+ var _a;
8
+ const authState = (0, react_1.useContext)(authContext_1.authContext);
9
+ // TODO: dont return access token if it has expired.
10
+ return (_a = authState.authenticationInfo) === null || _a === void 0 ? void 0 : _a.accessToken;
11
+ };
12
+ exports.useAuthAccessToken = useAuthAccessToken;
@@ -0,0 +1 @@
1
+ export declare const useIsLoggedIn: () => boolean;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useIsLoggedIn = void 0;
4
+ const react_1 = require("react");
5
+ const authContext_1 = require("../authContext");
6
+ const useIsLoggedIn = () => {
7
+ var _a;
8
+ const authState = (0, react_1.useContext)(authContext_1.authContext);
9
+ return !!((_a = authState.authenticationInfo) === null || _a === void 0 ? void 0 : _a.accessToken);
10
+ };
11
+ exports.useIsLoggedIn = useIsLoggedIn;
@@ -0,0 +1,2 @@
1
+ import { AuthState } from '../types';
2
+ export declare const useRefreshTokens: (authState: AuthState, refreshTokens: (authState: AuthState) => void) => void;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useRefreshTokens = void 0;
4
+ const react_1 = require("react");
5
+ const useRefreshTokens = (authState, refreshTokens) => {
6
+ const refresh = () => {
7
+ const { refreshToken, expiresAt } = authState.authenticationInfo || {};
8
+ if (refreshToken && expiresAt) {
9
+ const now = new Date().toISOString();
10
+ const timeToExpire = new Date(expiresAt).getTime() - new Date(now).getTime();
11
+ // Refresh the token 10 minutes before it expires to ensure there's a buffer
12
+ const bufferTime = 10 * 60 * 1000;
13
+ const refreshTime = timeToExpire - bufferTime;
14
+ if (refreshTime > 0) {
15
+ return setTimeout(() => refreshTokens(authState), refreshTime);
16
+ }
17
+ else {
18
+ // If the token is already expired or very close to expiration, refresh immediately
19
+ refreshTokens(authState);
20
+ }
21
+ }
22
+ return null;
23
+ };
24
+ (0, react_1.useEffect)(() => {
25
+ const timerId = refresh();
26
+ return () => {
27
+ // Cleanup on unmount or when authState changes
28
+ if (timerId) {
29
+ clearTimeout(timerId);
30
+ }
31
+ };
32
+ }, [authState, refreshTokens]);
33
+ };
34
+ exports.useRefreshTokens = useRefreshTokens;
@@ -0,0 +1,3 @@
1
+ export * from './authContext';
2
+ export * from './hooks';
3
+ export * from './types';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./authContext"), exports);
18
+ __exportStar(require("./hooks"), exports);
19
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,8 @@
1
+ import { AuthenticationInfo } from "quidproquo-core";
2
+ export type AuthState = {
3
+ challenge?: string;
4
+ session?: string;
5
+ username: string;
6
+ password: string;
7
+ authenticationInfo?: AuthenticationInfo;
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export * from './AuthState';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./AuthState"), exports);
@@ -1,2 +1,5 @@
1
+ export * from './api';
1
2
  export * from './websocket';
2
3
  export * from './hooks';
4
+ export * from './auth';
5
+ export * from './state';
@@ -14,5 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api"), exports);
17
18
  __exportStar(require("./websocket"), exports);
18
19
  __exportStar(require("./hooks"), exports);
20
+ __exportStar(require("./auth"), exports);
21
+ __exportStar(require("./state"), exports);
@@ -0,0 +1 @@
1
+ export * from './useStateUpdater';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./useStateUpdater"), exports);
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ type UpdaterFunction<T> = (property: keyof T) => (value: T[keyof T]) => void;
3
+ export declare const useStateUpdater: <T>(setState: import("react").Dispatch<import("react").SetStateAction<T>>) => UpdaterFunction<T>;
4
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useStateUpdater = void 0;
4
+ const hooks_1 = require("../hooks");
5
+ const useStateUpdater = (setState) => {
6
+ return (0, hooks_1.useFastCallback)((property) => {
7
+ return (value) => {
8
+ setState((prevState) => (Object.assign(Object.assign({}, prevState), { [property]: value })));
9
+ };
10
+ }, [setState]);
11
+ };
12
+ exports.useStateUpdater = useStateUpdater;
@@ -0,0 +1,2 @@
1
+ export * from './useNetworkRequest';
2
+ export * from './useAuthenticatedNetworkRequest';
@@ -0,0 +1,2 @@
1
+ export * from './useNetworkRequest';
2
+ export * from './useAuthenticatedNetworkRequest';
@@ -0,0 +1,2 @@
1
+ import { HTTPNetworkResponse, NetworkRequestActionPayload } from 'quidproquo-core';
2
+ export declare const useAuthenticatedNetworkRequest: <R>(payload: NetworkRequestActionPayload<any>) => () => Promise<HTTPNetworkResponse<R>>;
@@ -0,0 +1,17 @@
1
+ import { preformNetworkRequest } from 'quidproquo-web';
2
+ import { useFastCallback } from '../../hooks';
3
+ import { useAuthAccessToken } from '../../auth';
4
+ export const useAuthenticatedNetworkRequest = (payload) => {
5
+ const authToken = useAuthAccessToken();
6
+ const payloadWithAuthHeaders = authToken
7
+ ? {
8
+ ...payload,
9
+ headers: {
10
+ ...(payload.headers || {}),
11
+ Authorization: `Bearer ${authToken}`,
12
+ },
13
+ }
14
+ : payload;
15
+ const requeser = useFastCallback(() => preformNetworkRequest(payloadWithAuthHeaders));
16
+ return requeser;
17
+ };
@@ -0,0 +1,2 @@
1
+ import { HTTPNetworkResponse, NetworkRequestActionPayload } from 'quidproquo-core';
2
+ export declare const useNetworkRequest: <R>(payload: NetworkRequestActionPayload<any>) => () => Promise<HTTPNetworkResponse<R>>;
@@ -0,0 +1,6 @@
1
+ import { preformNetworkRequest } from 'quidproquo-web';
2
+ import { useFastCallback } from '../../hooks';
3
+ export const useNetworkRequest = (payload) => {
4
+ const requeser = useFastCallback(() => preformNetworkRequest(payload));
5
+ return requeser;
6
+ };
@@ -0,0 +1 @@
1
+ export * from './hooks';
@@ -0,0 +1 @@
1
+ export * from './hooks';
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { AuthState } from './types';
3
+ export declare const authContext: import("react").Context<AuthState>;
@@ -0,0 +1,5 @@
1
+ import { createContext } from 'react';
2
+ export const authContext = createContext({
3
+ username: '',
4
+ password: '',
5
+ });
@@ -0,0 +1,3 @@
1
+ export * from "./useIsLoggedIn";
2
+ export * from "./useAuthAccessToken";
3
+ export * from "./useRefreshTokens";
@@ -0,0 +1,3 @@
1
+ export * from "./useIsLoggedIn";
2
+ export * from "./useAuthAccessToken";
3
+ export * from "./useRefreshTokens";
@@ -0,0 +1 @@
1
+ export declare const useAuthAccessToken: () => string | undefined;
@@ -0,0 +1,7 @@
1
+ import { useContext } from 'react';
2
+ import { authContext } from '../authContext';
3
+ export const useAuthAccessToken = () => {
4
+ const authState = useContext(authContext);
5
+ // TODO: dont return access token if it has expired.
6
+ return authState.authenticationInfo?.accessToken;
7
+ };
@@ -0,0 +1 @@
1
+ export declare const useIsLoggedIn: () => boolean;
@@ -0,0 +1,6 @@
1
+ import { useContext } from "react";
2
+ import { authContext } from "../authContext";
3
+ export const useIsLoggedIn = () => {
4
+ const authState = useContext(authContext);
5
+ return !!authState.authenticationInfo?.accessToken;
6
+ };
@@ -0,0 +1,2 @@
1
+ import { AuthState } from '../types';
2
+ export declare const useRefreshTokens: (authState: AuthState, refreshTokens: (authState: AuthState) => void) => void;
@@ -0,0 +1,30 @@
1
+ import { useEffect } from 'react';
2
+ export const useRefreshTokens = (authState, refreshTokens) => {
3
+ const refresh = () => {
4
+ const { refreshToken, expiresAt } = authState.authenticationInfo || {};
5
+ if (refreshToken && expiresAt) {
6
+ const now = new Date().toISOString();
7
+ const timeToExpire = new Date(expiresAt).getTime() - new Date(now).getTime();
8
+ // Refresh the token 10 minutes before it expires to ensure there's a buffer
9
+ const bufferTime = 10 * 60 * 1000;
10
+ const refreshTime = timeToExpire - bufferTime;
11
+ if (refreshTime > 0) {
12
+ return setTimeout(() => refreshTokens(authState), refreshTime);
13
+ }
14
+ else {
15
+ // If the token is already expired or very close to expiration, refresh immediately
16
+ refreshTokens(authState);
17
+ }
18
+ }
19
+ return null;
20
+ };
21
+ useEffect(() => {
22
+ const timerId = refresh();
23
+ return () => {
24
+ // Cleanup on unmount or when authState changes
25
+ if (timerId) {
26
+ clearTimeout(timerId);
27
+ }
28
+ };
29
+ }, [authState, refreshTokens]);
30
+ };
@@ -0,0 +1,3 @@
1
+ export * from './authContext';
2
+ export * from './hooks';
3
+ export * from './types';
@@ -0,0 +1,3 @@
1
+ export * from './authContext';
2
+ export * from './hooks';
3
+ export * from './types';
@@ -0,0 +1,8 @@
1
+ import { AuthenticationInfo } from "quidproquo-core";
2
+ export type AuthState = {
3
+ challenge?: string;
4
+ session?: string;
5
+ username: string;
6
+ password: string;
7
+ authenticationInfo?: AuthenticationInfo;
8
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './AuthState';
@@ -0,0 +1 @@
1
+ export * from './AuthState';
@@ -1,2 +1,5 @@
1
+ export * from './api';
1
2
  export * from './websocket';
2
3
  export * from './hooks';
4
+ export * from './auth';
5
+ export * from './state';
package/lib/esm/index.js CHANGED
@@ -1,2 +1,5 @@
1
+ export * from './api';
1
2
  export * from './websocket';
2
3
  export * from './hooks';
4
+ export * from './auth';
5
+ export * from './state';
@@ -0,0 +1 @@
1
+ export * from './useStateUpdater';
@@ -0,0 +1 @@
1
+ export * from './useStateUpdater';
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ type UpdaterFunction<T> = (property: keyof T) => (value: T[keyof T]) => void;
3
+ export declare const useStateUpdater: <T>(setState: import("react").Dispatch<import("react").SetStateAction<T>>) => UpdaterFunction<T>;
4
+ export {};
@@ -0,0 +1,11 @@
1
+ import { useFastCallback } from '../hooks';
2
+ export const useStateUpdater = (setState) => {
3
+ return useFastCallback((property) => {
4
+ return (value) => {
5
+ setState((prevState) => ({
6
+ ...prevState,
7
+ [property]: value,
8
+ }));
9
+ };
10
+ }, [setState]);
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-web-react",
3
- "version": "0.0.208",
3
+ "version": "0.0.210",
4
4
  "description": "",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/esm/index.js",
@@ -29,13 +29,13 @@
29
29
  },
30
30
  "homepage": "https://github.com/joe-coady/quidproquo#readme",
31
31
  "devDependencies": {
32
- "quidproquo-core": "0.0.208",
33
- "quidproquo-tsconfig": "0.0.208",
34
- "quidproquo-webserver": "0.0.208",
35
- "quidproquo-web": "0.0.208",
32
+ "quidproquo-core": "0.0.210",
33
+ "quidproquo-tsconfig": "0.0.210",
34
+ "quidproquo-webserver": "0.0.210",
35
+ "quidproquo-web": "0.0.210",
36
36
  "typescript": "^4.9.3"
37
37
  },
38
38
  "peerDependencies": {
39
- "react": ">=16.8.0"
39
+ "react": ">=18.3.1"
40
40
  }
41
41
  }