@phygitallabs/tapquest-core 2.8.0 → 2.9.1
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 +1 -1
- package/dist/index.d.ts +29 -35
- package/dist/index.js +1015 -721
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
- package/src/modules/auth/constants/index.ts +6 -0
- package/src/modules/auth/helpers/index.ts +1 -4
- package/src/modules/auth/hooks/index.ts +2 -0
- package/src/modules/auth/hooks/useGoogleLogin.ts +169 -0
- package/src/modules/auth/hooks/useTokenRefresher.ts +39 -0
- package/src/modules/auth/index.ts +8 -2
- package/src/modules/auth/providers/AuthProvider.tsx +214 -186
- package/src/modules/auth/store/authStore.ts +577 -0
- package/src/modules/auth/types/auth.ts +29 -0
- package/src/modules/auth/types/user-data.ts +38 -0
- package/src/modules/auth/utils/user.ts +21 -0
- package/src/modules/data-tracking/hooks/index.ts +25 -1
- package/src/modules/generate-certificate/helpers/index.ts +3 -0
- package/src/modules/generate-certificate/hooks/index.ts +15 -6
- package/src/modules/generate-certificate/index.ts +3 -1
- package/src/modules/notification/providers/index.tsx +3 -3
- package/src/modules/reward/hooks/useRewardService.ts +6 -6
- package/src/modules/session-replay/README.md +334 -0
- package/src/modules/session-replay/hooks/useSessionReplay.ts +16 -0
- package/src/modules/session-replay/index.ts +10 -0
- package/src/modules/session-replay/providers/SessionReplayProvider.tsx +189 -0
- package/src/modules/session-replay/types/index.ts +147 -0
- package/src/modules/session-replay/utils/index.ts +12 -0
- package/src/providers/ServicesProvider.tsx +4 -76
- package/src/providers/TapquestCoreProvider.tsx +33 -46
- package/tsup.config.ts +1 -1
- package/dist/index.cjs +0 -1531
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -690
- package/src/modules/auth/helpers/refreshToken.ts +0 -63
- package/src/modules/auth/store/authSlice.ts +0 -137
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import mem from "mem";
|
|
2
|
-
import { setUserInfo, removeUserInfo, getUserInfo, getRefreshToken } from "./index";
|
|
3
|
-
|
|
4
|
-
// Internal configuration - managed by tapquest-core
|
|
5
|
-
const REFRESH_TOKEN_CONFIG = {
|
|
6
|
-
maxAge: 10000, // 10 seconds cache
|
|
7
|
-
} as const;
|
|
8
|
-
|
|
9
|
-
export interface RefreshTokenConfig {
|
|
10
|
-
firebaseApiKey: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const createRefreshTokenFunction = (config: RefreshTokenConfig) => {
|
|
14
|
-
const refreshTokenFn = async () => {
|
|
15
|
-
try {
|
|
16
|
-
const session = getUserInfo();
|
|
17
|
-
const refreshToken = getRefreshToken();
|
|
18
|
-
|
|
19
|
-
if (!refreshToken) {
|
|
20
|
-
removeUserInfo();
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const params = new URLSearchParams();
|
|
25
|
-
params.append("grant_type", "refresh_token");
|
|
26
|
-
params.append("refresh_token", refreshToken);
|
|
27
|
-
|
|
28
|
-
const fetchData = {
|
|
29
|
-
method: "POST",
|
|
30
|
-
headers: new Headers({
|
|
31
|
-
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
|
32
|
-
}),
|
|
33
|
-
body: params,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const response = await fetch(
|
|
37
|
-
`https://securetoken.googleapis.com/v1/token?key=${config.firebaseApiKey}`,
|
|
38
|
-
fetchData
|
|
39
|
-
);
|
|
40
|
-
const data = await response.json();
|
|
41
|
-
|
|
42
|
-
if (data.error) {
|
|
43
|
-
removeUserInfo();
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const newSession = {
|
|
48
|
-
...session,
|
|
49
|
-
accessToken: data.access_token,
|
|
50
|
-
refreshToken: data.refresh_token,
|
|
51
|
-
};
|
|
52
|
-
setUserInfo(newSession);
|
|
53
|
-
|
|
54
|
-
return newSession;
|
|
55
|
-
} catch {
|
|
56
|
-
removeUserInfo();
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
return mem(refreshTokenFn, { maxAge: REFRESH_TOKEN_CONFIG.maxAge });
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export { createRefreshTokenFunction };
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
|
2
|
-
import { UserData, UserRole } from "../types";
|
|
3
|
-
import {
|
|
4
|
-
setUserInfo,
|
|
5
|
-
removeUserInfo,
|
|
6
|
-
getUserInfo,
|
|
7
|
-
setAccessToken,
|
|
8
|
-
setRefreshToken,
|
|
9
|
-
removeAccessToken,
|
|
10
|
-
removeRefreshToken,
|
|
11
|
-
getAccessToken,
|
|
12
|
-
} from "../helpers";
|
|
13
|
-
|
|
14
|
-
const defaultUser: UserData = {
|
|
15
|
-
uid: "",
|
|
16
|
-
id: "",
|
|
17
|
-
userName: "",
|
|
18
|
-
displayName: "",
|
|
19
|
-
avatar: "/images/default-avatar.jpg",
|
|
20
|
-
email: "",
|
|
21
|
-
exp: 0,
|
|
22
|
-
emailVerified: false,
|
|
23
|
-
refreshToken: "",
|
|
24
|
-
accessToken: "",
|
|
25
|
-
role: UserRole.NULL,
|
|
26
|
-
scanStatus: false,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export interface AuthState {
|
|
30
|
-
user: UserData;
|
|
31
|
-
isSignedIn: boolean;
|
|
32
|
-
pending: boolean;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const initialState: AuthState = {
|
|
36
|
-
user: defaultUser,
|
|
37
|
-
isSignedIn: false,
|
|
38
|
-
pending: true,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const authSlice = createSlice<
|
|
42
|
-
AuthState,
|
|
43
|
-
{
|
|
44
|
-
signIn: (state: AuthState, action: PayloadAction<UserData>) => void;
|
|
45
|
-
signOut: (state: AuthState) => void;
|
|
46
|
-
updateScanStatus: (state: AuthState, action: PayloadAction<boolean>) => void;
|
|
47
|
-
refreshUser: (state: AuthState, action: PayloadAction<UserData>) => void;
|
|
48
|
-
setPending: (state: AuthState, action: PayloadAction<boolean>) => void;
|
|
49
|
-
initializeFromStorage: (state: AuthState) => void;
|
|
50
|
-
},
|
|
51
|
-
'auth'
|
|
52
|
-
>({
|
|
53
|
-
name: "auth",
|
|
54
|
-
initialState,
|
|
55
|
-
reducers: {
|
|
56
|
-
signIn: (state, action: PayloadAction<UserData>) => {
|
|
57
|
-
const userData = action.payload;
|
|
58
|
-
state.user = userData;
|
|
59
|
-
state.isSignedIn = true;
|
|
60
|
-
state.pending = false;
|
|
61
|
-
|
|
62
|
-
// Store in localStorage for persistence
|
|
63
|
-
setUserInfo(userData);
|
|
64
|
-
setAccessToken(userData.accessToken);
|
|
65
|
-
setRefreshToken(userData.refreshToken);
|
|
66
|
-
},
|
|
67
|
-
signOut: (state) => {
|
|
68
|
-
state.user = defaultUser;
|
|
69
|
-
state.isSignedIn = false;
|
|
70
|
-
state.pending = false;
|
|
71
|
-
|
|
72
|
-
// Clear localStorage
|
|
73
|
-
removeUserInfo();
|
|
74
|
-
removeAccessToken();
|
|
75
|
-
removeRefreshToken();
|
|
76
|
-
},
|
|
77
|
-
updateScanStatus: (state, action: PayloadAction<boolean>) => {
|
|
78
|
-
state.user.scanStatus = action.payload;
|
|
79
|
-
|
|
80
|
-
// Update localStorage
|
|
81
|
-
setUserInfo(state.user);
|
|
82
|
-
},
|
|
83
|
-
refreshUser: (state, action: PayloadAction<UserData>) => {
|
|
84
|
-
const userData = action.payload;
|
|
85
|
-
if (userData) {
|
|
86
|
-
state.user = userData;
|
|
87
|
-
state.isSignedIn = true;
|
|
88
|
-
state.pending = false;
|
|
89
|
-
|
|
90
|
-
// Update localStorage
|
|
91
|
-
setUserInfo(userData);
|
|
92
|
-
setAccessToken(userData.accessToken);
|
|
93
|
-
setRefreshToken(userData.refreshToken);
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
setPending: (state, action: PayloadAction<boolean>) => {
|
|
97
|
-
state.pending = action.payload;
|
|
98
|
-
},
|
|
99
|
-
initializeFromStorage: (state) => {
|
|
100
|
-
const storedUser = getUserInfo();
|
|
101
|
-
const accessToken = getAccessToken();
|
|
102
|
-
|
|
103
|
-
if (storedUser && accessToken) {
|
|
104
|
-
state.user = storedUser;
|
|
105
|
-
state.isSignedIn = true;
|
|
106
|
-
}
|
|
107
|
-
state.pending = false;
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
export const {
|
|
113
|
-
signIn,
|
|
114
|
-
signOut,
|
|
115
|
-
updateScanStatus,
|
|
116
|
-
refreshUser,
|
|
117
|
-
setPending,
|
|
118
|
-
initializeFromStorage,
|
|
119
|
-
} = authSlice.actions;
|
|
120
|
-
|
|
121
|
-
// Selectors
|
|
122
|
-
export const selectAuth = (state: any) => state.auth;
|
|
123
|
-
export const selectUser = (state: any) => state.auth.user;
|
|
124
|
-
export const selectUserUId = (state: any) =>
|
|
125
|
-
state.auth.user.uid || state.auth.user.id;
|
|
126
|
-
export const selectUserAccesstoken = (state: any) =>
|
|
127
|
-
state.auth.user.accessToken;
|
|
128
|
-
export const selectUserEmail = (state: any) => state.auth.user.email;
|
|
129
|
-
export const selectUsername = (state: any) => state.auth.user.userName;
|
|
130
|
-
export const selectSignInProvider = (state: any) =>
|
|
131
|
-
state.auth.user.signInProvider;
|
|
132
|
-
export const selectUserScanStatus = (state: any) =>
|
|
133
|
-
state.auth.user.scanStatus;
|
|
134
|
-
export const selectIsSignedIn = (state: any) => state.auth.isSignedIn;
|
|
135
|
-
export const selectIsLoading = (state: any) => state.auth.pending;
|
|
136
|
-
|
|
137
|
-
export default authSlice.reducer;
|