@phygitallabs/tapquest-core 6.7.9 → 6.7.11
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/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +35 -3
- package/dist/index.d.ts +35 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/modules/data-tracking/GtagConsentSync.tsx +62 -15
- package/src/modules/data-tracking/GtagGtmScriptToggle.tsx +73 -0
- package/src/modules/data-tracking/hooks/index.ts +133 -67
- package/src/modules/data-tracking/index.ts +2 -1
- package/src/modules/session-replay/providers/SessionReplayProvider.tsx +6 -6
- package/src/providers/ServicesProvider.tsx +132 -132
|
@@ -6,6 +6,7 @@ import { AchievementServiceProvider } from "@phygitallabs/achievement";
|
|
|
6
6
|
import { GenerateCertificateServiceProvider } from "@phygitallabs/generate-certificate";
|
|
7
7
|
import { PhygitalConsentProvider } from "@phygitallabs/phygital-consent";
|
|
8
8
|
import { GtagConsentSync } from "../modules/data-tracking";
|
|
9
|
+
// import { GtagGtmScriptToggleFromConsent } from "../modules/data-tracking";
|
|
9
10
|
|
|
10
11
|
import serviceApiUrl from "../constants/service";
|
|
11
12
|
import { APIConfig, ServiceConfig } from "../types/service";
|
|
@@ -21,143 +22,142 @@ import { tokenStorage } from "@phygitallabs/authentication";
|
|
|
21
22
|
import axios from "axios";
|
|
22
23
|
|
|
23
24
|
interface ServicesProviderProps {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
children: React.ReactNode;
|
|
26
|
+
queryClient: QueryClient;
|
|
27
|
+
apiConfig: APIConfig;
|
|
28
|
+
firebaseConfig?: any;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
export const ServicesProvider: React.FC<ServicesProviderProps> = ({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
children,
|
|
33
|
+
queryClient,
|
|
34
|
+
apiConfig = {
|
|
35
|
+
environment: "dev",
|
|
36
|
+
version: "v1",
|
|
37
|
+
},
|
|
37
38
|
}) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
const requestInterceptors = ({
|
|
93
|
-
onFulfilled: (config: any) => config,
|
|
94
|
-
onRejected: (error: any) => Promise.reject(error),
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
const axiosConfig = {
|
|
98
|
-
headers: {
|
|
99
|
-
"Content-Type": "application/json",
|
|
100
|
-
"Device-UID": deviceUid,
|
|
101
|
-
}
|
|
39
|
+
const { signOut, refreshToken } = useAuth();
|
|
40
|
+
const { environment, version } = apiConfig;
|
|
41
|
+
const [commonServiceConfig, setCommonServiceConfig] = useState<ServiceConfig | null>(null);
|
|
42
|
+
|
|
43
|
+
const [deviceUid, setDeviceUid] = useState<string>("");
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const initDeviceUid = async () => {
|
|
47
|
+
const deviceUid = await checkDeviceUid();
|
|
48
|
+
setDeviceUid(deviceUid);
|
|
49
|
+
};
|
|
50
|
+
initDeviceUid();
|
|
51
|
+
}, []);
|
|
52
|
+
|
|
53
|
+
// Init client
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const initClient = async () => {
|
|
56
|
+
try {
|
|
57
|
+
const deviceUid = await checkDeviceUid();
|
|
58
|
+
|
|
59
|
+
const responseInterceptors = {
|
|
60
|
+
onFulfilled: (response: any) => response,
|
|
61
|
+
onRejected: async (error: any) => {
|
|
62
|
+
const originalRequest = error.config;
|
|
63
|
+
const token = tokenStorage.getAuthToken();
|
|
64
|
+
|
|
65
|
+
if (error.response?.status === 401 && !originalRequest._retry) {
|
|
66
|
+
const retryAttempts = parseInt(getFromLS(retryAttemptsRefreshToken) || "0", 10);
|
|
67
|
+
if (retryAttempts >= httpMaxRetries) {
|
|
68
|
+
await signOut();
|
|
69
|
+
setToLS(retryAttemptsRefreshToken, 0);
|
|
70
|
+
return Promise.reject(error);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
setToLS(retryAttemptsRefreshToken, `${retryAttempts + 1}`);
|
|
74
|
+
originalRequest._retry = true;
|
|
75
|
+
|
|
76
|
+
if (token) {
|
|
77
|
+
try {
|
|
78
|
+
const result = await refreshToken();
|
|
79
|
+
if (result?.data?.idToken) {
|
|
80
|
+
originalRequest.headers.Authorization = `Bearer ${result?.data?.idToken}`;
|
|
81
|
+
return axios(originalRequest);
|
|
82
|
+
}
|
|
83
|
+
} catch (refreshError) {
|
|
84
|
+
console.error("Failed to refresh token:", refreshError);
|
|
85
|
+
await signOut();
|
|
86
|
+
return Promise.reject(refreshError);
|
|
102
87
|
}
|
|
103
|
-
|
|
104
|
-
const config: ServiceConfig = {
|
|
105
|
-
queryClient,
|
|
106
|
-
axiosConfig,
|
|
107
|
-
responseInterceptors,
|
|
108
|
-
requestInterceptors,
|
|
109
|
-
useDevTool: true,
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
setCommonServiceConfig(config);
|
|
113
|
-
|
|
114
|
-
} catch (error) {
|
|
115
|
-
console.error(error);
|
|
88
|
+
}
|
|
116
89
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const requestInterceptors = {
|
|
94
|
+
onFulfilled: (config: any) => config,
|
|
95
|
+
onRejected: (error: any) => Promise.reject(error),
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const axiosConfig = {
|
|
99
|
+
headers: {
|
|
100
|
+
"Content-Type": "application/json",
|
|
101
|
+
"Device-UID": deviceUid,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const config: ServiceConfig = {
|
|
106
|
+
queryClient,
|
|
107
|
+
axiosConfig,
|
|
108
|
+
responseInterceptors,
|
|
109
|
+
requestInterceptors,
|
|
110
|
+
useDevTool: true,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
setCommonServiceConfig(config);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error(error);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
initClient();
|
|
120
|
+
}, [queryClient]);
|
|
121
|
+
|
|
122
|
+
if (!commonServiceConfig) {
|
|
123
|
+
return <></>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<PGLCoreServiceProvider
|
|
128
|
+
{...commonServiceConfig}
|
|
129
|
+
baseURL={`${serviceApiUrl[environment].API_BASE_URL}/${version}`}
|
|
130
|
+
baseCoreURL={`${serviceApiUrl[environment].API_BASE_CORE_URL}/${version}`}
|
|
131
|
+
>
|
|
132
|
+
<RewardServiceProvider
|
|
133
|
+
{...commonServiceConfig}
|
|
134
|
+
// baseURL={`${serviceApiUrl[environment].API_REWARD_URL}/${version}`}
|
|
135
|
+
baseURL={`${serviceApiUrl[environment].API_REWARD_URL}/v1`} // todo: using v1 until backend fully migrate
|
|
136
|
+
>
|
|
137
|
+
<AchievementServiceProvider
|
|
138
|
+
{...commonServiceConfig}
|
|
139
|
+
baseURL={`${serviceApiUrl[environment].API_ACHIEVEMENT_URL}/${version}`}
|
|
131
140
|
>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
141
|
+
<GenerateCertificateServiceProvider
|
|
142
|
+
{...commonServiceConfig}
|
|
143
|
+
baseURL={`${serviceApiUrl[environment].API_GENERATE_CERTIFICATE_URL}/v1`}
|
|
144
|
+
>
|
|
145
|
+
<PhygitalConsentProvider
|
|
146
|
+
{...commonServiceConfig}
|
|
147
|
+
deviceId={deviceUid}
|
|
148
|
+
baseURL={`${serviceApiUrl[environment].API_CONSENT_URL}/v1`}
|
|
149
|
+
axiosConfig={{
|
|
150
|
+
headers: {
|
|
151
|
+
"Content-Type": "application/json",
|
|
152
|
+
},
|
|
153
|
+
}}
|
|
136
154
|
>
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
{...commonServiceConfig}
|
|
147
|
-
deviceId={deviceUid}
|
|
148
|
-
baseURL={`${serviceApiUrl[environment].API_CONSENT_URL}/v1`}
|
|
149
|
-
axiosConfig={{
|
|
150
|
-
headers: {
|
|
151
|
-
"Content-Type": "application/json",
|
|
152
|
-
}
|
|
153
|
-
}}
|
|
154
|
-
>
|
|
155
|
-
<GtagConsentSync />
|
|
156
|
-
{children}
|
|
157
|
-
</PhygitalConsentProvider>
|
|
158
|
-
</GenerateCertificateServiceProvider>
|
|
159
|
-
</AchievementServiceProvider>
|
|
160
|
-
</RewardServiceProvider>
|
|
161
|
-
</PGLCoreServiceProvider>
|
|
162
|
-
);
|
|
163
|
-
};
|
|
155
|
+
<GtagConsentSync />
|
|
156
|
+
{children}
|
|
157
|
+
</PhygitalConsentProvider>
|
|
158
|
+
</GenerateCertificateServiceProvider>
|
|
159
|
+
</AchievementServiceProvider>
|
|
160
|
+
</RewardServiceProvider>
|
|
161
|
+
</PGLCoreServiceProvider>
|
|
162
|
+
);
|
|
163
|
+
};
|