@phygitallabs/tapquest-core 2.7.0 → 2.9.0
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.cjs +1035 -750
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -35
- package/dist/index.d.ts +29 -35
- package/dist/index.js +1017 -717
- package/dist/index.js.map +1 -1
- package/package.json +10 -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 +31 -36
- package/src/modules/auth/helpers/refreshToken.ts +0 -63
- package/src/modules/auth/store/authSlice.ts +0 -137
package/dist/index.cjs
CHANGED
|
@@ -5,10 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __esm = (fn, res) => function __init() {
|
|
10
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
|
-
};
|
|
12
8
|
var __export = (target, all) => {
|
|
13
9
|
for (var name in all)
|
|
14
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -31,337 +27,28 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
31
27
|
mod
|
|
32
28
|
));
|
|
33
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
35
|
-
|
|
36
|
-
// src/modules/auth/constants/index.ts
|
|
37
|
-
var userInfoKey, accessTokenKey, refreshTokenKey, httpMaxRetries, retryAttemptsRefreshToken, deviceUIDKey, chipAuthTokenKey;
|
|
38
|
-
var init_constants = __esm({
|
|
39
|
-
"src/modules/auth/constants/index.ts"() {
|
|
40
|
-
"use strict";
|
|
41
|
-
userInfoKey = "phygital-user-info";
|
|
42
|
-
accessTokenKey = "accessToken";
|
|
43
|
-
refreshTokenKey = "refreshToken";
|
|
44
|
-
httpMaxRetries = 3;
|
|
45
|
-
retryAttemptsRefreshToken = "retryAttemptsRefreshToken";
|
|
46
|
-
deviceUIDKey = "Device-UID";
|
|
47
|
-
chipAuthTokenKey = "chip-auth-token";
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// src/modules/auth/services/FirebaseAuthService.ts
|
|
52
|
-
var firebaseApp, firebaseAuth, getFirebaseModules, FirebaseAuthService;
|
|
53
|
-
var init_FirebaseAuthService = __esm({
|
|
54
|
-
"src/modules/auth/services/FirebaseAuthService.ts"() {
|
|
55
|
-
"use strict";
|
|
56
|
-
init_constants();
|
|
57
|
-
getFirebaseModules = async () => {
|
|
58
|
-
if (typeof window === "undefined") {
|
|
59
|
-
throw new Error("Firebase can only be used in client environment");
|
|
60
|
-
}
|
|
61
|
-
if (!firebaseApp || !firebaseAuth) {
|
|
62
|
-
const [
|
|
63
|
-
{ initializeApp, getApps },
|
|
64
|
-
{
|
|
65
|
-
getAuth,
|
|
66
|
-
signInWithEmailAndPassword,
|
|
67
|
-
createUserWithEmailAndPassword,
|
|
68
|
-
signInWithPopup,
|
|
69
|
-
GoogleAuthProvider,
|
|
70
|
-
signOut: signOut2,
|
|
71
|
-
sendPasswordResetEmail,
|
|
72
|
-
sendEmailVerification,
|
|
73
|
-
updatePassword,
|
|
74
|
-
onAuthStateChanged
|
|
75
|
-
}
|
|
76
|
-
] = await Promise.all([
|
|
77
|
-
import("firebase/app"),
|
|
78
|
-
import("firebase/auth")
|
|
79
|
-
]);
|
|
80
|
-
firebaseApp = { initializeApp, getApps };
|
|
81
|
-
firebaseAuth = {
|
|
82
|
-
getAuth,
|
|
83
|
-
signInWithEmailAndPassword,
|
|
84
|
-
createUserWithEmailAndPassword,
|
|
85
|
-
signInWithPopup,
|
|
86
|
-
GoogleAuthProvider,
|
|
87
|
-
signOut: signOut2,
|
|
88
|
-
sendPasswordResetEmail,
|
|
89
|
-
sendEmailVerification,
|
|
90
|
-
updatePassword,
|
|
91
|
-
onAuthStateChanged
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
return { firebaseApp, firebaseAuth };
|
|
95
|
-
};
|
|
96
|
-
FirebaseAuthService = class {
|
|
97
|
-
constructor(config) {
|
|
98
|
-
__publicField(this, "app");
|
|
99
|
-
__publicField(this, "auth");
|
|
100
|
-
__publicField(this, "googleProvider");
|
|
101
|
-
__publicField(this, "config");
|
|
102
|
-
__publicField(this, "initialized", false);
|
|
103
|
-
this.config = config;
|
|
104
|
-
}
|
|
105
|
-
async ensureInitialized() {
|
|
106
|
-
if (this.initialized) return;
|
|
107
|
-
const { firebaseApp: firebaseApp2, firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
108
|
-
if (!firebaseApp2.getApps().length) {
|
|
109
|
-
this.app = firebaseApp2.initializeApp(this.config);
|
|
110
|
-
} else {
|
|
111
|
-
this.app = firebaseApp2.getApps()[0];
|
|
112
|
-
}
|
|
113
|
-
this.auth = firebaseAuth2.getAuth(this.app);
|
|
114
|
-
this.googleProvider = new firebaseAuth2.GoogleAuthProvider();
|
|
115
|
-
this.initialized = true;
|
|
116
|
-
}
|
|
117
|
-
transformUserData(user) {
|
|
118
|
-
return {
|
|
119
|
-
id: user.uid,
|
|
120
|
-
uid: user.uid,
|
|
121
|
-
userName: user.displayName || "",
|
|
122
|
-
displayName: user.displayName || "",
|
|
123
|
-
email: user.email || "",
|
|
124
|
-
refreshToken: user.refreshToken,
|
|
125
|
-
accessToken: user.accessToken || "",
|
|
126
|
-
exp: user.stsTokenManager?.expirationTime || 0,
|
|
127
|
-
emailVerified: user.emailVerified,
|
|
128
|
-
avatar: user.photoURL || "/images/default-avatar.jpg",
|
|
129
|
-
signInProvider: this.getSignInProvider(user),
|
|
130
|
-
role: void 0,
|
|
131
|
-
scanStatus: false
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
getSignInProvider(user) {
|
|
135
|
-
const providers = user.providerData.map((p) => p.providerId);
|
|
136
|
-
if (providers.includes("google.com")) return "google.com";
|
|
137
|
-
return "password";
|
|
138
|
-
}
|
|
139
|
-
translateErrorCode(errorCode) {
|
|
140
|
-
switch (errorCode) {
|
|
141
|
-
case "auth/invalid-email":
|
|
142
|
-
return "Email kh\xF4ng h\u1EE3p l\u1EC7";
|
|
143
|
-
case "auth/user-disabled":
|
|
144
|
-
return "T\xE0i kho\u1EA3n \u0111\xE3 b\u1ECB kh\xF3a";
|
|
145
|
-
case "auth/wrong-password":
|
|
146
|
-
return "T\xE0i kho\u1EA3n/m\u1EADt kh\u1EA9u kh\xF4ng \u0111\xFAng";
|
|
147
|
-
case "auth/user-not-found":
|
|
148
|
-
return "T\xE0i kho\u1EA3n/m\u1EADt kh\u1EA9u kh\xF4ng \u0111\xFAng";
|
|
149
|
-
case "auth/weak-password":
|
|
150
|
-
return "Weak password! Please use stronger password.";
|
|
151
|
-
case "auth/email-already-in-use":
|
|
152
|
-
return "Email \u0111\xE3 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng";
|
|
153
|
-
case "auth/account-exists-with-different-credential":
|
|
154
|
-
return "T\xE0i kho\u1EA3n email \u0111\xE3 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng b\u1EDFi m\u1ED9t ph\u01B0\u01A1ng th\u1EE9c \u0111\u0103ng nh\u1EADp kh\xE1c";
|
|
155
|
-
case "auth/email-not-verified":
|
|
156
|
-
return "Email ch\u01B0a \u0111\u01B0\u1EE3c x\xE1c th\u1EF1c";
|
|
157
|
-
default:
|
|
158
|
-
return "\u0110\xE3 c\xF3 l\u1ED7i x\u1EA3y ra";
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
async signInWithEmailAndPassword(email, password) {
|
|
162
|
-
try {
|
|
163
|
-
await this.ensureInitialized();
|
|
164
|
-
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
165
|
-
const signInResponse = await firebaseAuth2.signInWithEmailAndPassword(this.auth, email, password);
|
|
166
|
-
const { user } = signInResponse;
|
|
167
|
-
const data = this.transformUserData(user);
|
|
168
|
-
const { emailVerified } = data;
|
|
169
|
-
if (!emailVerified) {
|
|
170
|
-
await this.signOut();
|
|
171
|
-
localStorage.removeItem("phygital-user-info");
|
|
172
|
-
localStorage.removeItem(accessTokenKey);
|
|
173
|
-
localStorage.removeItem(refreshTokenKey);
|
|
174
|
-
throw new Error("Email is not verified");
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
errorCode: "",
|
|
178
|
-
data
|
|
179
|
-
};
|
|
180
|
-
} catch (err) {
|
|
181
|
-
const errorCode = this.translateErrorCode(err.code);
|
|
182
|
-
return {
|
|
183
|
-
errorCode,
|
|
184
|
-
data: null
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
async signInWithGoogle() {
|
|
189
|
-
try {
|
|
190
|
-
await this.ensureInitialized();
|
|
191
|
-
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
192
|
-
const signInResponse = await firebaseAuth2.signInWithPopup(this.auth, this.googleProvider);
|
|
193
|
-
const { user } = signInResponse;
|
|
194
|
-
const data = this.transformUserData(user);
|
|
195
|
-
const { emailVerified } = data;
|
|
196
|
-
if (!emailVerified) {
|
|
197
|
-
await this.signOut();
|
|
198
|
-
throw new Error("Email is not verified");
|
|
199
|
-
}
|
|
200
|
-
return {
|
|
201
|
-
errorCode: "",
|
|
202
|
-
data
|
|
203
|
-
};
|
|
204
|
-
} catch (err) {
|
|
205
|
-
const errorCode = this.translateErrorCode(err.code);
|
|
206
|
-
return {
|
|
207
|
-
errorCode,
|
|
208
|
-
data: null
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
async signUp(email, password) {
|
|
213
|
-
try {
|
|
214
|
-
await this.ensureInitialized();
|
|
215
|
-
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
216
|
-
const signUpResponse = await firebaseAuth2.createUserWithEmailAndPassword(this.auth, email, password);
|
|
217
|
-
const { user } = signUpResponse;
|
|
218
|
-
const data = this.transformUserData(user);
|
|
219
|
-
return {
|
|
220
|
-
errorCode: "",
|
|
221
|
-
data
|
|
222
|
-
};
|
|
223
|
-
} catch (err) {
|
|
224
|
-
const errorCode = this.translateErrorCode(err.code);
|
|
225
|
-
return {
|
|
226
|
-
errorCode,
|
|
227
|
-
data: null
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
async signOut() {
|
|
232
|
-
try {
|
|
233
|
-
await this.ensureInitialized();
|
|
234
|
-
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
235
|
-
await firebaseAuth2.signOut(this.auth);
|
|
236
|
-
} catch (err) {
|
|
237
|
-
console.log("Firebase signOut error:", err);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
async sendPasswordResetEmail(email) {
|
|
241
|
-
await this.ensureInitialized();
|
|
242
|
-
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
243
|
-
const actionCodeSettings = {
|
|
244
|
-
url: window.location.origin,
|
|
245
|
-
handleCodeInApp: true
|
|
246
|
-
};
|
|
247
|
-
await firebaseAuth2.sendPasswordResetEmail(this.auth, email, actionCodeSettings);
|
|
248
|
-
}
|
|
249
|
-
async sendEmailVerification() {
|
|
250
|
-
await this.ensureInitialized();
|
|
251
|
-
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
252
|
-
if (!this.auth.currentUser) {
|
|
253
|
-
throw new Error("No current user");
|
|
254
|
-
}
|
|
255
|
-
const actionCodeSettings = {
|
|
256
|
-
url: window.location.origin,
|
|
257
|
-
handleCodeInApp: true
|
|
258
|
-
};
|
|
259
|
-
await firebaseAuth2.sendEmailVerification(this.auth.currentUser, actionCodeSettings);
|
|
260
|
-
}
|
|
261
|
-
async changePassword(newPassword) {
|
|
262
|
-
await this.ensureInitialized();
|
|
263
|
-
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
264
|
-
const user = this.auth.currentUser;
|
|
265
|
-
if (!user) {
|
|
266
|
-
throw new Error("No current user");
|
|
267
|
-
}
|
|
268
|
-
return firebaseAuth2.updatePassword(user, newPassword);
|
|
269
|
-
}
|
|
270
|
-
onAuthStateChanged(callback) {
|
|
271
|
-
if (typeof window === "undefined") {
|
|
272
|
-
return () => {
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
let unsubscriber = null;
|
|
276
|
-
this.ensureInitialized().then(async () => {
|
|
277
|
-
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
278
|
-
unsubscriber = firebaseAuth2.onAuthStateChanged(this.auth, (user) => {
|
|
279
|
-
if (user && user.emailVerified) {
|
|
280
|
-
const userData = this.transformUserData(user);
|
|
281
|
-
callback(userData);
|
|
282
|
-
} else {
|
|
283
|
-
callback(null);
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
return () => {
|
|
288
|
-
if (unsubscriber) {
|
|
289
|
-
unsubscriber();
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
getCurrentUser() {
|
|
294
|
-
if (typeof window === "undefined" || !this.initialized) {
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
const user = this.auth.currentUser;
|
|
298
|
-
if (user && user.emailVerified) {
|
|
299
|
-
return this.transformUserData(user);
|
|
300
|
-
}
|
|
301
|
-
return null;
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
// src/modules/auth/services/authServiceFactory.ts
|
|
308
|
-
var authServiceInstance, createAuthService, getAuthService, resetAuthService;
|
|
309
|
-
var init_authServiceFactory = __esm({
|
|
310
|
-
"src/modules/auth/services/authServiceFactory.ts"() {
|
|
311
|
-
"use strict";
|
|
312
|
-
init_FirebaseAuthService();
|
|
313
|
-
authServiceInstance = null;
|
|
314
|
-
createAuthService = (config) => {
|
|
315
|
-
if (!authServiceInstance) {
|
|
316
|
-
authServiceInstance = new FirebaseAuthService(config.firebaseConfig);
|
|
317
|
-
}
|
|
318
|
-
return authServiceInstance;
|
|
319
|
-
};
|
|
320
|
-
getAuthService = () => {
|
|
321
|
-
return authServiceInstance;
|
|
322
|
-
};
|
|
323
|
-
resetAuthService = () => {
|
|
324
|
-
authServiceInstance = null;
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
// src/modules/auth/services/index.ts
|
|
330
|
-
var services_exports = {};
|
|
331
|
-
__export(services_exports, {
|
|
332
|
-
FirebaseAuthService: () => FirebaseAuthService,
|
|
333
|
-
createAuthService: () => createAuthService,
|
|
334
|
-
getAuthService: () => getAuthService,
|
|
335
|
-
resetAuthService: () => resetAuthService
|
|
336
|
-
});
|
|
337
|
-
var init_services = __esm({
|
|
338
|
-
"src/modules/auth/services/index.ts"() {
|
|
339
|
-
"use strict";
|
|
340
|
-
init_FirebaseAuthService();
|
|
341
|
-
init_authServiceFactory();
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
30
|
|
|
345
31
|
// src/index.ts
|
|
346
32
|
var index_exports = {};
|
|
347
33
|
__export(index_exports, {
|
|
34
|
+
ALLOWED_ORIGINS: () => ALLOWED_ORIGINS,
|
|
348
35
|
AchievementRuleActionType: () => import_achievement3.AchievementRuleActionType,
|
|
349
36
|
AchievementServiceProvider: () => import_achievement3.AchievementServiceProvider,
|
|
350
37
|
AchievementType: () => AchievementType,
|
|
351
38
|
AuthProvider: () => AuthProvider,
|
|
352
|
-
|
|
353
|
-
|
|
39
|
+
CALLBACK_URL: () => CALLBACK_URL,
|
|
40
|
+
CampaignState: () => import_api_core10.CampaignState,
|
|
41
|
+
CmentityRewardType: () => import_reward2.CmentityRewardType,
|
|
354
42
|
NotificationProvider: () => NotificationProvider,
|
|
355
43
|
RewardClaimStatus: () => RewardClaimStatus,
|
|
356
44
|
TapquestCoreProvider: () => TapquestCoreProvider,
|
|
357
45
|
TaskType: () => TaskType,
|
|
358
|
-
UserSourceType: () =>
|
|
46
|
+
UserSourceType: () => import_api_core6.UserSourceType,
|
|
359
47
|
accessTokenKey: () => accessTokenKey,
|
|
360
48
|
checkDeviceUid: () => checkDeviceUid,
|
|
361
49
|
chipAuthTokenKey: () => chipAuthTokenKey,
|
|
362
50
|
cn: () => import_helpers5.cn,
|
|
363
51
|
convertSnakeToCamel: () => convertSnakeToCamel,
|
|
364
|
-
createRefreshTokenFunction: () => createRefreshTokenFunction,
|
|
365
52
|
deviceUIDKey: () => deviceUIDKey,
|
|
366
53
|
fileToBase64: () => import_helpers5.fileToBase64,
|
|
367
54
|
filterLocationsByProperty: () => filterLocationsByProperty,
|
|
@@ -376,7 +63,7 @@ __export(index_exports, {
|
|
|
376
63
|
getUserInfo: () => getUserInfo,
|
|
377
64
|
httpMaxRetries: () => httpMaxRetries,
|
|
378
65
|
isAchievementCompleted: () => isAchievementCompleted,
|
|
379
|
-
locationQueryKeys: () =>
|
|
66
|
+
locationQueryKeys: () => import_api_core11.locationQueryKeys,
|
|
380
67
|
memoriesKey: () => import_api_core2.memoriesKey,
|
|
381
68
|
parse: () => import_helpers5.parse,
|
|
382
69
|
refreshTokenKey: () => refreshTokenKey,
|
|
@@ -397,48 +84,53 @@ __export(index_exports, {
|
|
|
397
84
|
useAchievementProgress: () => import_achievement2.useAchievementProgress,
|
|
398
85
|
useAchivementPlusRewardModel: () => achivementPlusRewardModel_default,
|
|
399
86
|
useAuth: () => useAuth,
|
|
400
|
-
useCampaignDetail: () =>
|
|
401
|
-
useCancelUserRewardsRequest: () =>
|
|
402
|
-
useChipScanStory: () =>
|
|
403
|
-
useClaimUserReward: () =>
|
|
404
|
-
useClearUserRewardCache: () =>
|
|
87
|
+
useCampaignDetail: () => import_api_core9.useOneCampaign,
|
|
88
|
+
useCancelUserRewardsRequest: () => import_api_core5.useCancelUserRewardsRequest,
|
|
89
|
+
useChipScanStory: () => import_api_core7.useChipScanStory,
|
|
90
|
+
useClaimUserReward: () => import_reward.useClaimUserReward,
|
|
91
|
+
useClearUserRewardCache: () => import_reward.useClearUserRewardCache,
|
|
92
|
+
useCreateCertificate: () => import_generate_certificate2.useCreateCertificate,
|
|
93
|
+
useCreateCertificateAnonymous: () => import_generate_certificate2.useCreateCertificateAnonymous,
|
|
94
|
+
useCreateCertificateWithMask: () => import_generate_certificate2.useCreateCertificateWithMask,
|
|
405
95
|
useCreateMemory: () => import_api_core2.useCreateMemory,
|
|
406
|
-
useCreateModelGroupReward: () =>
|
|
407
|
-
useCreateRewardModel: () =>
|
|
96
|
+
useCreateModelGroupReward: () => import_reward.useCreateModelGroupReward,
|
|
97
|
+
useCreateRewardModel: () => import_reward.useCreateRewardModel,
|
|
408
98
|
useDataTracking: () => useDataTracking,
|
|
409
|
-
useDeleteRewardModel: () =>
|
|
410
|
-
useGenerateFansipanCertificate: () =>
|
|
411
|
-
useGenerateTemplateCertificate: () =>
|
|
412
|
-
useGenerateThaocamvienCertificate: () =>
|
|
413
|
-
useGetRewardModel: () =>
|
|
414
|
-
useGetUserRewards: () =>
|
|
99
|
+
useDeleteRewardModel: () => import_reward.useDeleteRewardModel,
|
|
100
|
+
useGenerateFansipanCertificate: () => import_generate_certificate2.useGenerateFansipanCertificate,
|
|
101
|
+
useGenerateTemplateCertificate: () => import_generate_certificate2.useGenerateTemplateCertificate,
|
|
102
|
+
useGenerateThaocamvienCertificate: () => import_generate_certificate2.useGenerateThaocamvienCertificate,
|
|
103
|
+
useGetRewardModel: () => import_reward.useGetRewardModel,
|
|
104
|
+
useGetUserRewards: () => import_reward.useGetUserRewards,
|
|
105
|
+
useGoogleLogin: () => useGoogleLogin,
|
|
415
106
|
useInfiniteMemories: () => import_api_core2.useInfiniteMemories,
|
|
416
|
-
useListRewardModels: () =>
|
|
417
|
-
useLocationDetail: () =>
|
|
418
|
-
useLocationProgress: () =>
|
|
419
|
-
useLocationsList: () =>
|
|
107
|
+
useListRewardModels: () => import_reward.useListRewardModels,
|
|
108
|
+
useLocationDetail: () => import_api_core11.useOneLocation,
|
|
109
|
+
useLocationProgress: () => import_api_core11.useUserCampaignsCompletedLocation,
|
|
110
|
+
useLocationsList: () => import_api_core11.useManyLocations,
|
|
420
111
|
useManyAchievementProgress: () => useManyAchievementProgress,
|
|
421
112
|
useManyAchievements: () => import_achievement2.useManyAchievements,
|
|
422
113
|
useManyAchievementsRewardModels: () => import_achievement2.useManyAchievementsRewardModels,
|
|
423
114
|
useManyChildrenAchievements: () => import_achievement2.useManyChildrenAchievements,
|
|
424
115
|
useManyMemory: () => import_api_core2.useManyMemory,
|
|
425
|
-
useManyUserActionLocations: () =>
|
|
426
|
-
useManyUserRewards: () =>
|
|
427
|
-
useMyProfile: () =>
|
|
116
|
+
useManyUserActionLocations: () => import_api_core11.useManyUserActionLocations,
|
|
117
|
+
useManyUserRewards: () => import_reward.useManyUserRewards,
|
|
118
|
+
useMyProfile: () => import_api_core5.useMyProfile,
|
|
428
119
|
useOneAchievement: () => import_achievement2.useOneAchievement,
|
|
429
120
|
useOneMemory: () => import_api_core2.useOneMemory,
|
|
430
|
-
useOneUserCampaign: () =>
|
|
431
|
-
usePGLCoreService: () =>
|
|
121
|
+
useOneUserCampaign: () => import_api_core9.useOneUserCampaign,
|
|
122
|
+
usePGLCoreService: () => import_api_core8.usePGLCoreService,
|
|
432
123
|
useScanChip: () => useScanChip,
|
|
433
|
-
useSendEmail: () =>
|
|
434
|
-
useSyncCheckin: () =>
|
|
435
|
-
useUpdateMyProfile: () =>
|
|
436
|
-
useUpdateRewardModel: () =>
|
|
124
|
+
useSendEmail: () => import_api_core13.useSendEmail,
|
|
125
|
+
useSyncCheckin: () => import_api_core5.useSyncCheckin,
|
|
126
|
+
useUpdateMyProfile: () => import_api_core5.useUpdateMyProfile,
|
|
127
|
+
useUpdateRewardModel: () => import_reward.useUpdateRewardModel,
|
|
437
128
|
useUploadMedia: () => import_api_core2.useUploadMedia,
|
|
438
129
|
useUserAchievementAction: () => import_achievement2.useUserAchievementAction,
|
|
439
|
-
useUserCampaignAction: () =>
|
|
440
|
-
useV1ListRewards: () =>
|
|
441
|
-
userInfoKey: () => userInfoKey
|
|
130
|
+
useUserCampaignAction: () => import_api_core9.useUserCampaignAction,
|
|
131
|
+
useV1ListRewards: () => import_reward.useV1ListRewards,
|
|
132
|
+
userInfoKey: () => userInfoKey,
|
|
133
|
+
wrapTextWithFont: () => import_generate_certificate3.wrapTextWithFont
|
|
442
134
|
});
|
|
443
135
|
module.exports = __toCommonJS(index_exports);
|
|
444
136
|
|
|
@@ -564,10 +256,10 @@ var AchievementType = /* @__PURE__ */ ((AchievementType2) => {
|
|
|
564
256
|
})(AchievementType || {});
|
|
565
257
|
|
|
566
258
|
// src/modules/reward/hooks/useRewardService.ts
|
|
567
|
-
var
|
|
259
|
+
var import_reward = require("@phygitallabs/reward");
|
|
568
260
|
|
|
569
261
|
// src/modules/reward/types/enums.ts
|
|
570
|
-
var
|
|
262
|
+
var import_reward2 = require("@phygitallabs/reward");
|
|
571
263
|
var RewardClaimStatus = /* @__PURE__ */ ((RewardClaimStatus2) => {
|
|
572
264
|
RewardClaimStatus2["NOT_CLAIMED"] = "not_claimed";
|
|
573
265
|
RewardClaimStatus2["CLAIMED"] = "claimed";
|
|
@@ -630,8 +322,8 @@ var NotificationProvider = ({
|
|
|
630
322
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
631
323
|
import_notification_api.NotificationProvider,
|
|
632
324
|
{
|
|
633
|
-
userUid: user
|
|
634
|
-
accessToken: user
|
|
325
|
+
userUid: user?.id,
|
|
326
|
+
accessToken: user?.accessToken ?? null,
|
|
635
327
|
webSocketUrl,
|
|
636
328
|
autoConnect,
|
|
637
329
|
onWebSocketOpen,
|
|
@@ -649,69 +341,761 @@ __reExport(index_exports, notification_exports, module.exports);
|
|
|
649
341
|
var import_api_core2 = require("@phygitallabs/api-core");
|
|
650
342
|
|
|
651
343
|
// src/modules/auth/providers/AuthProvider.tsx
|
|
344
|
+
var import_authentication3 = require("@phygitallabs/authentication");
|
|
652
345
|
var import_react = require("react");
|
|
653
346
|
|
|
654
|
-
// src/store/
|
|
655
|
-
var
|
|
656
|
-
var
|
|
657
|
-
var
|
|
347
|
+
// src/modules/auth/store/authStore.ts
|
|
348
|
+
var import_zustand = require("zustand");
|
|
349
|
+
var import_immer = require("zustand/middleware/immer");
|
|
350
|
+
var import_middleware = require("zustand/middleware");
|
|
351
|
+
var import_authentication = require("@phygitallabs/authentication");
|
|
658
352
|
|
|
659
|
-
// src/modules/auth/
|
|
660
|
-
var
|
|
353
|
+
// src/modules/auth/constants/index.ts
|
|
354
|
+
var userInfoKey = "phygital-user-info";
|
|
355
|
+
var accessTokenKey = "accessToken";
|
|
356
|
+
var refreshTokenKey = "refreshToken";
|
|
357
|
+
var httpMaxRetries = 3;
|
|
358
|
+
var retryAttemptsRefreshToken = "retryAttemptsRefreshToken";
|
|
359
|
+
var deviceUIDKey = "Device-UID";
|
|
360
|
+
var chipAuthTokenKey = "chip-auth-token";
|
|
361
|
+
var CALLBACK_URL = "https://s3-sgn10.fptcloud.com/nomion-assets/platform/callback.html";
|
|
362
|
+
var ALLOWED_ORIGINS = [
|
|
363
|
+
"https://s3-sgn10.fptcloud.com",
|
|
364
|
+
"https://accounts.google.com/"
|
|
365
|
+
];
|
|
661
366
|
|
|
662
|
-
// src/modules/auth/
|
|
663
|
-
|
|
664
|
-
|
|
367
|
+
// src/modules/auth/store/authStore.ts
|
|
368
|
+
var initialState = {
|
|
369
|
+
user: null,
|
|
370
|
+
isSignedIn: false,
|
|
371
|
+
isInitialized: false,
|
|
372
|
+
isLoading: false,
|
|
373
|
+
error: null,
|
|
374
|
+
cleanupFunctions: {},
|
|
375
|
+
eventCallbacks: {}
|
|
376
|
+
};
|
|
377
|
+
var useAuthStore = (0, import_zustand.create)()(
|
|
378
|
+
(0, import_middleware.devtools)(
|
|
379
|
+
(0, import_middleware.persist)(
|
|
380
|
+
(0, import_middleware.subscribeWithSelector)(
|
|
381
|
+
(0, import_immer.immer)((set, get) => ({
|
|
382
|
+
...initialState,
|
|
383
|
+
actions: {
|
|
384
|
+
setIsLoading: (isLoading) => set((state) => {
|
|
385
|
+
state.isLoading = isLoading;
|
|
386
|
+
}),
|
|
387
|
+
setCleanupFunctions: (newCleanupFunctions) => set((state) => {
|
|
388
|
+
state.cleanupFunctions = {
|
|
389
|
+
...state.cleanupFunctions,
|
|
390
|
+
...newCleanupFunctions
|
|
391
|
+
};
|
|
392
|
+
}),
|
|
393
|
+
// Event management
|
|
394
|
+
addEventCallbacks: (callbacks) => {
|
|
395
|
+
set((state) => {
|
|
396
|
+
state.eventCallbacks = {
|
|
397
|
+
...state.eventCallbacks,
|
|
398
|
+
...callbacks
|
|
399
|
+
};
|
|
400
|
+
});
|
|
401
|
+
return () => {
|
|
402
|
+
set((state) => {
|
|
403
|
+
state.eventCallbacks = {
|
|
404
|
+
...state.eventCallbacks,
|
|
405
|
+
...callbacks
|
|
406
|
+
};
|
|
407
|
+
});
|
|
408
|
+
};
|
|
409
|
+
},
|
|
410
|
+
// Sign in with email and password
|
|
411
|
+
signInWithEmail: async (email, password) => {
|
|
412
|
+
const { eventCallbacks } = get();
|
|
413
|
+
set((state) => {
|
|
414
|
+
state.isLoading = true;
|
|
415
|
+
state.error = null;
|
|
416
|
+
});
|
|
417
|
+
try {
|
|
418
|
+
const response = await import_authentication.authService.signIn({
|
|
419
|
+
email,
|
|
420
|
+
password
|
|
421
|
+
});
|
|
422
|
+
if (response?.data?.idToken && response?.data?.refreshToken) {
|
|
423
|
+
import_authentication.tokenStorage.setTokens({
|
|
424
|
+
idToken: response.data.idToken,
|
|
425
|
+
refreshToken: response.data.refreshToken
|
|
426
|
+
});
|
|
427
|
+
set((state) => {
|
|
428
|
+
state.isSignedIn = true;
|
|
429
|
+
});
|
|
430
|
+
eventCallbacks.onLoginSuccess?.(response.data.idToken);
|
|
431
|
+
}
|
|
432
|
+
return response;
|
|
433
|
+
} catch (error) {
|
|
434
|
+
if (error?.response?.data?.code === 7) {
|
|
435
|
+
return {
|
|
436
|
+
data: void 0,
|
|
437
|
+
message: "Email verification required",
|
|
438
|
+
code: 7
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
const errorMessage = error instanceof Error ? error.message : "Login failed";
|
|
442
|
+
set((state) => {
|
|
443
|
+
state.error = errorMessage;
|
|
444
|
+
});
|
|
445
|
+
eventCallbacks.onLoginError?.(new Error(errorMessage));
|
|
446
|
+
throw error;
|
|
447
|
+
} finally {
|
|
448
|
+
set((state) => {
|
|
449
|
+
state.isLoading = false;
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
// Sign in with Google
|
|
454
|
+
signInWithGoogle: async () => {
|
|
455
|
+
const { eventCallbacks } = get();
|
|
456
|
+
try {
|
|
457
|
+
const currentDomain = CALLBACK_URL;
|
|
458
|
+
const userData = await import_authentication.authService.getOAuthSignInUrl(currentDomain);
|
|
459
|
+
return userData;
|
|
460
|
+
} catch (error) {
|
|
461
|
+
const errorMessage = error instanceof Error ? error.message : "Google sign in failed";
|
|
462
|
+
set((state) => {
|
|
463
|
+
state.error = errorMessage;
|
|
464
|
+
});
|
|
465
|
+
eventCallbacks.onLoginError?.(new Error(errorMessage));
|
|
466
|
+
throw error;
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
// Sign up with email and password
|
|
470
|
+
signUpWithEmail: async (email, password) => {
|
|
471
|
+
const { eventCallbacks } = get();
|
|
472
|
+
set((state) => {
|
|
473
|
+
state.isLoading = true;
|
|
474
|
+
state.error = null;
|
|
475
|
+
});
|
|
476
|
+
try {
|
|
477
|
+
const response = await import_authentication.authService.signUp({
|
|
478
|
+
email,
|
|
479
|
+
password
|
|
480
|
+
});
|
|
481
|
+
if (response.data) {
|
|
482
|
+
eventCallbacks.onSignupSuccess?.();
|
|
483
|
+
}
|
|
484
|
+
return response;
|
|
485
|
+
} catch (error) {
|
|
486
|
+
const errorMessage = error instanceof Error ? error.message : "Signup failed";
|
|
487
|
+
set((state) => {
|
|
488
|
+
state.error = errorMessage;
|
|
489
|
+
});
|
|
490
|
+
eventCallbacks.onSignupError?.(new Error(errorMessage));
|
|
491
|
+
throw error;
|
|
492
|
+
} finally {
|
|
493
|
+
set((state) => {
|
|
494
|
+
state.isLoading = false;
|
|
495
|
+
state.user = null;
|
|
496
|
+
state.isSignedIn = false;
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
},
|
|
500
|
+
// Sign out
|
|
501
|
+
signOut: async () => {
|
|
502
|
+
const { eventCallbacks, cleanupFunctions } = get();
|
|
503
|
+
set((state) => {
|
|
504
|
+
state.isLoading = true;
|
|
505
|
+
state.error = null;
|
|
506
|
+
});
|
|
507
|
+
try {
|
|
508
|
+
set((state) => {
|
|
509
|
+
state.user = null;
|
|
510
|
+
state.isSignedIn = false;
|
|
511
|
+
state.error = null;
|
|
512
|
+
});
|
|
513
|
+
const isTokenExpired = import_authentication.tokenStorage.isTokenExpired();
|
|
514
|
+
if (isTokenExpired) {
|
|
515
|
+
import_authentication.tokenStorage.clearTokens();
|
|
516
|
+
localStorage.clear();
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
await import_authentication.authService.logout();
|
|
520
|
+
localStorage.clear();
|
|
521
|
+
import_authentication.tokenStorage.clearTokens();
|
|
522
|
+
try {
|
|
523
|
+
cleanupFunctions.clearQueryCache?.();
|
|
524
|
+
cleanupFunctions.clearOrganization?.();
|
|
525
|
+
cleanupFunctions.clearCustomData?.();
|
|
526
|
+
cleanupFunctions.clearHeaders?.();
|
|
527
|
+
} catch (cleanupError) {
|
|
528
|
+
console.warn("Error during logout cleanup:", cleanupError);
|
|
529
|
+
}
|
|
530
|
+
eventCallbacks.onLogoutSuccess?.();
|
|
531
|
+
} catch (error) {
|
|
532
|
+
console.log(error);
|
|
533
|
+
const errorMessage = error instanceof Error ? error.message : "Logout failed";
|
|
534
|
+
set((state) => {
|
|
535
|
+
state.error = errorMessage;
|
|
536
|
+
});
|
|
537
|
+
eventCallbacks.onLogoutError?.(new Error(errorMessage));
|
|
538
|
+
throw error;
|
|
539
|
+
} finally {
|
|
540
|
+
set((state) => {
|
|
541
|
+
state.isLoading = false;
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
},
|
|
545
|
+
// Send password reset email
|
|
546
|
+
sendPasswordResetEmail: async (email) => {
|
|
547
|
+
set((state) => {
|
|
548
|
+
state.isLoading = true;
|
|
549
|
+
state.error = null;
|
|
550
|
+
});
|
|
551
|
+
try {
|
|
552
|
+
await import_authentication.verifyCodeService.forgotPassword({
|
|
553
|
+
email
|
|
554
|
+
});
|
|
555
|
+
} catch (error) {
|
|
556
|
+
const errorMessage = error instanceof Error ? error.message : "Failed to send reset email";
|
|
557
|
+
set((state) => {
|
|
558
|
+
state.error = errorMessage;
|
|
559
|
+
});
|
|
560
|
+
throw error;
|
|
561
|
+
} finally {
|
|
562
|
+
set((state) => {
|
|
563
|
+
state.isLoading = false;
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
},
|
|
567
|
+
resetPassword: async (data) => {
|
|
568
|
+
set((state) => {
|
|
569
|
+
state.isLoading = true;
|
|
570
|
+
state.error = null;
|
|
571
|
+
});
|
|
572
|
+
try {
|
|
573
|
+
const resetPasswordResponse = await import_authentication.verifyCodeService.resetPassword(data);
|
|
574
|
+
return resetPasswordResponse;
|
|
575
|
+
} catch (error) {
|
|
576
|
+
const errorMessage = error instanceof Error ? error.message : "Failed to reset password";
|
|
577
|
+
set((state) => {
|
|
578
|
+
state.error = errorMessage;
|
|
579
|
+
});
|
|
580
|
+
throw error;
|
|
581
|
+
} finally {
|
|
582
|
+
set((state) => {
|
|
583
|
+
state.isLoading = false;
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
},
|
|
587
|
+
changePassword: async (data) => {
|
|
588
|
+
set((state) => {
|
|
589
|
+
state.isLoading = true;
|
|
590
|
+
state.error = null;
|
|
591
|
+
});
|
|
592
|
+
try {
|
|
593
|
+
const changePasswordResponse = await import_authentication.verifyCodeService.changePassword(data);
|
|
594
|
+
return changePasswordResponse;
|
|
595
|
+
} catch (error) {
|
|
596
|
+
throw error;
|
|
597
|
+
} finally {
|
|
598
|
+
set((state) => {
|
|
599
|
+
state.isLoading = false;
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
},
|
|
603
|
+
verifyEmailCode: async (data) => {
|
|
604
|
+
set((state) => {
|
|
605
|
+
state.isLoading = true;
|
|
606
|
+
state.error = null;
|
|
607
|
+
});
|
|
608
|
+
try {
|
|
609
|
+
const verifyEmailResponse = await import_authentication.verifyCodeService.verifyEmail(data);
|
|
610
|
+
return verifyEmailResponse;
|
|
611
|
+
} catch (error) {
|
|
612
|
+
const errorMessage = error instanceof Error ? error.message : "Failed to send reset email";
|
|
613
|
+
set((state) => {
|
|
614
|
+
state.error = errorMessage;
|
|
615
|
+
});
|
|
616
|
+
throw error;
|
|
617
|
+
} finally {
|
|
618
|
+
set((state) => {
|
|
619
|
+
state.isLoading = false;
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
},
|
|
623
|
+
sendVerifyCode: async (data) => {
|
|
624
|
+
set((state) => {
|
|
625
|
+
state.isLoading = true;
|
|
626
|
+
state.error = null;
|
|
627
|
+
});
|
|
628
|
+
try {
|
|
629
|
+
const sendVerifyCodeResponse = await import_authentication.verifyCodeService.sendVerifyCode(data);
|
|
630
|
+
return sendVerifyCodeResponse;
|
|
631
|
+
} catch (error) {
|
|
632
|
+
const errorMessage = error instanceof Error ? error.message : "Failed to send verify code";
|
|
633
|
+
set((state) => {
|
|
634
|
+
state.error = errorMessage;
|
|
635
|
+
});
|
|
636
|
+
throw error;
|
|
637
|
+
} finally {
|
|
638
|
+
set((state) => {
|
|
639
|
+
state.isLoading = false;
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
},
|
|
643
|
+
refreshToken: async (refreshToken) => {
|
|
644
|
+
const refreshTokenResponse = await import_authentication.authService.refreshToken({
|
|
645
|
+
refreshToken: refreshToken ?? import_authentication.tokenStorage.getRefreshToken() ?? ""
|
|
646
|
+
});
|
|
647
|
+
return refreshTokenResponse;
|
|
648
|
+
},
|
|
649
|
+
// Clear error
|
|
650
|
+
clearError: () => set((state) => {
|
|
651
|
+
state.error = null;
|
|
652
|
+
}),
|
|
653
|
+
setUser: (user) => set((state) => {
|
|
654
|
+
state.user = user;
|
|
655
|
+
}),
|
|
656
|
+
setIsSignedIn: (isSignedIn) => set((state) => {
|
|
657
|
+
state.isSignedIn = isSignedIn;
|
|
658
|
+
}),
|
|
659
|
+
setIsInitialized: (isInitialized) => set((state) => {
|
|
660
|
+
state.isInitialized = isInitialized;
|
|
661
|
+
}),
|
|
662
|
+
patchUser: (user) => set((state) => {
|
|
663
|
+
if (state.user) {
|
|
664
|
+
state.user = { ...state.user, ...user };
|
|
665
|
+
} else {
|
|
666
|
+
state.user = user;
|
|
667
|
+
}
|
|
668
|
+
}),
|
|
669
|
+
// Initialize the store - check if user is already authenticated from tokenStorage
|
|
670
|
+
initialize: () => {
|
|
671
|
+
set((state) => {
|
|
672
|
+
const token = import_authentication.tokenStorage.getAuthToken();
|
|
673
|
+
state.isSignedIn = !!token;
|
|
674
|
+
state.isInitialized = true;
|
|
675
|
+
});
|
|
676
|
+
},
|
|
677
|
+
// Sync auth state from tokenStorage (called when axios interceptor updates tokens)
|
|
678
|
+
syncAuthState: () => {
|
|
679
|
+
set((state) => {
|
|
680
|
+
const token = import_authentication.tokenStorage.getAuthToken();
|
|
681
|
+
const wasSignedIn = state.isSignedIn;
|
|
682
|
+
state.isSignedIn = !!token;
|
|
683
|
+
if (wasSignedIn !== state.isSignedIn) {
|
|
684
|
+
if (state.isSignedIn) {
|
|
685
|
+
state.eventCallbacks?.onAuthStateChange?.(state.user, true);
|
|
686
|
+
} else {
|
|
687
|
+
state.eventCallbacks?.onAuthStateChange?.(null, false);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}))
|
|
694
|
+
),
|
|
695
|
+
{
|
|
696
|
+
version: 1,
|
|
697
|
+
name: "auth-store",
|
|
698
|
+
storage: (0, import_middleware.createJSONStorage)(() => localStorage),
|
|
699
|
+
partialize: (state) => ({
|
|
700
|
+
isSignedIn: state.isSignedIn,
|
|
701
|
+
user: state.user
|
|
702
|
+
})
|
|
703
|
+
}
|
|
704
|
+
)
|
|
705
|
+
)
|
|
706
|
+
);
|
|
707
|
+
var useAuth = () => {
|
|
708
|
+
const user = useAuthStore((state) => state.user);
|
|
709
|
+
const isSignedIn = useAuthStore((state) => state.isSignedIn);
|
|
710
|
+
const isInitialized = useAuthStore((state) => state.isInitialized);
|
|
711
|
+
const isLoading = useAuthStore((state) => state.isLoading);
|
|
712
|
+
const error = useAuthStore((state) => state.error);
|
|
713
|
+
const actions = useAuthStore((state) => state.actions);
|
|
714
|
+
return {
|
|
715
|
+
user,
|
|
716
|
+
isSignedIn,
|
|
717
|
+
isInitialized,
|
|
718
|
+
isLoading,
|
|
719
|
+
error,
|
|
720
|
+
...actions
|
|
721
|
+
};
|
|
722
|
+
};
|
|
665
723
|
|
|
666
|
-
// src/modules/auth/
|
|
667
|
-
var
|
|
668
|
-
var
|
|
669
|
-
|
|
670
|
-
|
|
724
|
+
// src/modules/auth/utils/user.ts
|
|
725
|
+
var import_jwt_decode = __toESM(require("jwt-decode"), 1);
|
|
726
|
+
var transformProtoUserData = (user, accessToken) => {
|
|
727
|
+
const userData = { ...user };
|
|
728
|
+
let tokenDecoded = {};
|
|
729
|
+
try {
|
|
730
|
+
tokenDecoded = (0, import_jwt_decode.default)(accessToken);
|
|
731
|
+
} catch (error) {
|
|
732
|
+
console.warn("Failed to decode token in transformUserData:", error);
|
|
733
|
+
}
|
|
734
|
+
userData.exp = tokenDecoded.exp || 0;
|
|
735
|
+
userData.accessToken = accessToken || "";
|
|
736
|
+
userData.roles = tokenDecoded?.roles || ["USER" /* USER */];
|
|
737
|
+
userData.account_type = tokenDecoded?.account_type || 0 /* C */;
|
|
738
|
+
userData.picture = user.picture || "";
|
|
739
|
+
return userData;
|
|
671
740
|
};
|
|
672
|
-
|
|
673
|
-
|
|
741
|
+
|
|
742
|
+
// src/modules/auth/providers/AuthProvider.tsx
|
|
743
|
+
var import_api_core3 = require("@phygitallabs/api-core");
|
|
744
|
+
var import_api_core4 = require("@phygitallabs/api-core");
|
|
745
|
+
var import_achievement4 = require("@phygitallabs/achievement");
|
|
746
|
+
var import_reward3 = require("@phygitallabs/reward");
|
|
747
|
+
var import_generate_certificate = require("@phygitallabs/generate-certificate");
|
|
748
|
+
|
|
749
|
+
// src/modules/auth/hooks/useTokenRefresher.ts
|
|
750
|
+
var import_react_query = require("@tanstack/react-query");
|
|
751
|
+
var import_authentication2 = require("@phygitallabs/authentication");
|
|
752
|
+
function useTokenRefresher() {
|
|
753
|
+
const { refreshToken, signOut } = useAuth();
|
|
754
|
+
const handleRefreshToken = async () => {
|
|
674
755
|
try {
|
|
675
|
-
const
|
|
676
|
-
|
|
677
|
-
if (!refreshToken) {
|
|
678
|
-
removeUserInfo();
|
|
756
|
+
const isTokenExpired = import_authentication2.tokenStorage.isTokenExpired();
|
|
757
|
+
if (!isTokenExpired) {
|
|
679
758
|
return;
|
|
680
759
|
}
|
|
681
|
-
const
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
760
|
+
const newToken = await refreshToken();
|
|
761
|
+
if (newToken.data?.idToken && newToken.data?.refreshToken) {
|
|
762
|
+
import_authentication2.tokenStorage.setTokens({
|
|
763
|
+
idToken: newToken.data?.idToken,
|
|
764
|
+
refreshToken: newToken.data?.refreshToken
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
} catch (error) {
|
|
768
|
+
console.error("Failed to refresh token:", error);
|
|
769
|
+
signOut();
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
(0, import_react_query.useQuery)({
|
|
773
|
+
queryKey: ["refresh-token"],
|
|
774
|
+
queryFn: () => handleRefreshToken(),
|
|
775
|
+
refetchInterval: 30 * 60 * 1e3,
|
|
776
|
+
// every 30 minutes
|
|
777
|
+
refetchIntervalInBackground: false,
|
|
778
|
+
// even when tab is hidden
|
|
779
|
+
refetchOnWindowFocus: true,
|
|
780
|
+
// also refresh when user returns to tab
|
|
781
|
+
retry: false,
|
|
782
|
+
// don't retry repeatedly if refresh fails
|
|
783
|
+
enabled: !!import_authentication2.tokenStorage.getAuthToken()
|
|
784
|
+
// only run if logged in
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// src/modules/auth/providers/AuthProvider.tsx
|
|
789
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
790
|
+
var AuthStateManager = () => {
|
|
791
|
+
const { updateHeaders } = (0, import_authentication3.useAuthenticationHeaders)();
|
|
792
|
+
const { updateHeaders: updateHeadersPGL, coreApi } = (0, import_api_core4.usePGLCoreService)();
|
|
793
|
+
const { updateHeaders: updateHeadersAchievement } = (0, import_achievement4.useAchievementService)();
|
|
794
|
+
const { updateHeaders: updateHeadersReward } = (0, import_reward3.useRewardService)();
|
|
795
|
+
const { updateHeaders: updateHeadersGenerateCertificate } = (0, import_generate_certificate.useGenerateCertificateService)();
|
|
796
|
+
(0, import_react.useEffect)(() => {
|
|
797
|
+
useAuthStore.getState().actions.initialize();
|
|
798
|
+
const token = import_authentication3.tokenStorage.getAuthToken();
|
|
799
|
+
if (token) {
|
|
800
|
+
updateHeaders({
|
|
801
|
+
Authorization: `Bearer ${token}`
|
|
802
|
+
});
|
|
803
|
+
updateHeadersPGL({
|
|
804
|
+
Authorization: `Bearer ${token}`
|
|
805
|
+
});
|
|
806
|
+
updateHeadersAchievement({
|
|
807
|
+
Authorization: `Bearer ${token}`
|
|
808
|
+
});
|
|
809
|
+
updateHeadersReward({
|
|
810
|
+
Authorization: `Bearer ${token}`
|
|
811
|
+
});
|
|
812
|
+
updateHeadersGenerateCertificate({
|
|
813
|
+
Authorization: `Bearer ${token}`
|
|
814
|
+
});
|
|
815
|
+
const { user } = useAuthStore.getState();
|
|
816
|
+
if (user && user.accessToken !== token) {
|
|
817
|
+
useAuthStore.getState().actions.setUser({
|
|
818
|
+
...user,
|
|
819
|
+
accessToken: token
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
let previousIsSignedIn = useAuthStore.getState().isSignedIn;
|
|
824
|
+
const unsub = useAuthStore.subscribe(
|
|
825
|
+
(state) => [state.isSignedIn, state.user],
|
|
826
|
+
async ([isSignedIn]) => {
|
|
827
|
+
if (isSignedIn === previousIsSignedIn) {
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
previousIsSignedIn = isSignedIn;
|
|
831
|
+
if (isSignedIn) {
|
|
832
|
+
const token2 = import_authentication3.tokenStorage.getAuthToken();
|
|
833
|
+
if (token2) {
|
|
834
|
+
updateHeaders({
|
|
835
|
+
Authorization: `Bearer ${token2}`
|
|
836
|
+
});
|
|
837
|
+
updateHeadersPGL({
|
|
838
|
+
Authorization: `Bearer ${token2}`
|
|
839
|
+
});
|
|
840
|
+
updateHeadersAchievement({
|
|
841
|
+
Authorization: `Bearer ${token2}`
|
|
842
|
+
});
|
|
843
|
+
updateHeadersReward({
|
|
844
|
+
Authorization: `Bearer ${token2}`
|
|
845
|
+
});
|
|
846
|
+
updateHeadersGenerateCertificate({
|
|
847
|
+
Authorization: `Bearer ${token2}`
|
|
848
|
+
});
|
|
849
|
+
try {
|
|
850
|
+
const userApi = (0, import_api_core3.userService)(coreApi);
|
|
851
|
+
const userProfile = await userApi.getMyProfile();
|
|
852
|
+
const transformedUserData = transformProtoUserData(
|
|
853
|
+
userProfile,
|
|
854
|
+
token2
|
|
855
|
+
);
|
|
856
|
+
useAuthStore.getState().actions.setUser(transformedUserData);
|
|
857
|
+
} catch (error) {
|
|
858
|
+
useAuthStore.getState().actions.signOut();
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
const { eventCallbacks, user } = useAuthStore.getState();
|
|
862
|
+
eventCallbacks?.onAuthStateChange?.(user, true);
|
|
863
|
+
} else {
|
|
864
|
+
updateHeaders({});
|
|
865
|
+
updateHeadersPGL({});
|
|
866
|
+
updateHeadersAchievement({
|
|
867
|
+
Authorization: ``
|
|
868
|
+
});
|
|
869
|
+
updateHeadersReward({
|
|
870
|
+
Authorization: ``
|
|
871
|
+
});
|
|
872
|
+
updateHeadersGenerateCertificate({
|
|
873
|
+
Authorization: ``
|
|
874
|
+
});
|
|
875
|
+
const { eventCallbacks } = useAuthStore.getState();
|
|
876
|
+
eventCallbacks?.onAuthStateChange?.(null, false);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
);
|
|
880
|
+
const unsubTokenChange = import_authentication3.tokenStorage.addTokenChangeListener(async () => {
|
|
881
|
+
const { isSignedIn, user } = useAuthStore.getState();
|
|
882
|
+
if (isSignedIn) {
|
|
883
|
+
const token2 = import_authentication3.tokenStorage.getAuthToken();
|
|
884
|
+
if (token2) {
|
|
885
|
+
updateHeaders({
|
|
886
|
+
Authorization: `Bearer ${token2}`
|
|
887
|
+
});
|
|
888
|
+
updateHeadersPGL({
|
|
889
|
+
Authorization: `Bearer ${token2}`
|
|
890
|
+
});
|
|
891
|
+
updateHeadersAchievement({
|
|
892
|
+
Authorization: `Bearer ${token2}`
|
|
893
|
+
});
|
|
894
|
+
updateHeadersReward({
|
|
895
|
+
Authorization: `Bearer ${token2}`
|
|
896
|
+
});
|
|
897
|
+
updateHeadersGenerateCertificate({
|
|
898
|
+
Authorization: `Bearer ${token2}`
|
|
899
|
+
});
|
|
900
|
+
if (user && user.accessToken !== token2) {
|
|
901
|
+
useAuthStore.getState().actions.setUser({
|
|
902
|
+
...user,
|
|
903
|
+
accessToken: token2
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
} else {
|
|
907
|
+
useAuthStore.getState().actions.signOut();
|
|
908
|
+
updateHeaders({});
|
|
909
|
+
updateHeadersPGL({});
|
|
910
|
+
updateHeadersAchievement({
|
|
911
|
+
Authorization: ``
|
|
912
|
+
});
|
|
913
|
+
updateHeadersReward({
|
|
914
|
+
Authorization: ``
|
|
915
|
+
});
|
|
916
|
+
updateHeadersGenerateCertificate({
|
|
917
|
+
Authorization: ``
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
return () => {
|
|
923
|
+
unsub();
|
|
924
|
+
unsubTokenChange();
|
|
925
|
+
};
|
|
926
|
+
}, [
|
|
927
|
+
updateHeaders,
|
|
928
|
+
updateHeadersPGL,
|
|
929
|
+
updateHeadersAchievement,
|
|
930
|
+
updateHeadersReward,
|
|
931
|
+
updateHeadersGenerateCertificate,
|
|
932
|
+
coreApi
|
|
933
|
+
]);
|
|
934
|
+
return null;
|
|
935
|
+
};
|
|
936
|
+
var TokenRefresher = () => {
|
|
937
|
+
useTokenRefresher();
|
|
938
|
+
return null;
|
|
939
|
+
};
|
|
940
|
+
var AuthProvider = ({
|
|
941
|
+
children,
|
|
942
|
+
baseURL,
|
|
943
|
+
queryClient
|
|
944
|
+
}) => {
|
|
945
|
+
const axiosConfig = {
|
|
946
|
+
headers: {
|
|
947
|
+
"Content-Type": "application/json"
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
951
|
+
import_authentication3.AuthenticationProvider,
|
|
952
|
+
{
|
|
953
|
+
axiosConfig,
|
|
954
|
+
baseURL,
|
|
955
|
+
queryClient,
|
|
956
|
+
children: [
|
|
957
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AuthStateManager, {}),
|
|
958
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TokenRefresher, {}),
|
|
959
|
+
children
|
|
960
|
+
]
|
|
961
|
+
}
|
|
962
|
+
);
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
// src/modules/auth/hooks/useGoogleLogin.ts
|
|
966
|
+
var import_react2 = require("react");
|
|
967
|
+
var import_authentication4 = require("@phygitallabs/authentication");
|
|
968
|
+
function useGoogleLogin(options = {}) {
|
|
969
|
+
const { onSuccess, onError, onPopupBlocked, onPopupClosed } = options;
|
|
970
|
+
const { signInWithGoogle, refreshToken, setIsSignedIn, setIsLoading, isLoading } = useAuth();
|
|
971
|
+
const popupRef = (0, import_react2.useRef)(null);
|
|
972
|
+
const gotDataRef = (0, import_react2.useRef)(false);
|
|
973
|
+
const timerRef = (0, import_react2.useRef)(null);
|
|
974
|
+
const errorRef = (0, import_react2.useRef)(null);
|
|
975
|
+
const handleTokenRefresh = (0, import_react2.useCallback)(
|
|
976
|
+
async (refresh) => {
|
|
977
|
+
if (refresh) {
|
|
978
|
+
try {
|
|
979
|
+
const newToken = await refreshToken(refresh);
|
|
980
|
+
if (newToken.data?.idToken && newToken.data?.refreshToken) {
|
|
981
|
+
import_authentication4.tokenStorage.setTokens({
|
|
982
|
+
idToken: newToken.data.idToken,
|
|
983
|
+
refreshToken: newToken.data.refreshToken
|
|
984
|
+
});
|
|
985
|
+
setIsSignedIn(true);
|
|
986
|
+
setIsLoading(false);
|
|
987
|
+
onSuccess?.();
|
|
988
|
+
}
|
|
989
|
+
} catch (error) {
|
|
990
|
+
const errorMessage = error instanceof Error ? error.message : "Token refresh failed";
|
|
991
|
+
errorRef.current = errorMessage;
|
|
992
|
+
onError?.(errorMessage);
|
|
993
|
+
setIsLoading(false);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
},
|
|
997
|
+
[refreshToken, setIsSignedIn, setIsLoading, onSuccess, onError]
|
|
998
|
+
);
|
|
999
|
+
const cleanup = (0, import_react2.useCallback)(() => {
|
|
1000
|
+
if (timerRef.current) {
|
|
1001
|
+
clearInterval(timerRef.current);
|
|
1002
|
+
timerRef.current = null;
|
|
1003
|
+
}
|
|
1004
|
+
gotDataRef.current = false;
|
|
1005
|
+
}, []);
|
|
1006
|
+
const handleMessage = (0, import_react2.useCallback)(
|
|
1007
|
+
(event) => {
|
|
1008
|
+
const allowedOrigins = ALLOWED_ORIGINS.concat(window?.location?.origin);
|
|
1009
|
+
if (event.origin !== "*" && !allowedOrigins.includes(event.origin)) {
|
|
1010
|
+
console.warn("Rejected message from untrusted origin:", event.origin);
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
if (!event.data || typeof event.data !== "object") {
|
|
1014
|
+
console.warn("Invalid message data received");
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
if (event.data.type === "LOGIN_SUCCESS") {
|
|
1018
|
+
const { refreshToken: refresh } = event.data;
|
|
1019
|
+
if (refresh) {
|
|
1020
|
+
handleTokenRefresh(refresh);
|
|
1021
|
+
}
|
|
1022
|
+
gotDataRef.current = true;
|
|
1023
|
+
cleanup();
|
|
1024
|
+
} else if (event.data.type === "LOGIN_ERROR") {
|
|
1025
|
+
const errorMessage = event.data.error || "Login failed";
|
|
1026
|
+
errorRef.current = errorMessage;
|
|
1027
|
+
onError?.(errorMessage);
|
|
1028
|
+
setIsLoading(false);
|
|
1029
|
+
gotDataRef.current = true;
|
|
1030
|
+
cleanup();
|
|
1031
|
+
}
|
|
1032
|
+
},
|
|
1033
|
+
[handleTokenRefresh, setIsLoading, cleanup, onError]
|
|
1034
|
+
);
|
|
1035
|
+
const signIn = (0, import_react2.useCallback)(async () => {
|
|
1036
|
+
const width = 500;
|
|
1037
|
+
const height = 600;
|
|
1038
|
+
const left = window.screenX + (window.outerWidth - width) / 2;
|
|
1039
|
+
const top = window.screenY + (window.outerHeight - height) / 2;
|
|
1040
|
+
try {
|
|
1041
|
+
errorRef.current = null;
|
|
1042
|
+
setIsLoading(true);
|
|
1043
|
+
const response = await signInWithGoogle();
|
|
1044
|
+
popupRef.current = window.open(
|
|
1045
|
+
`${response.statusMessage}`,
|
|
1046
|
+
"oauthPopup",
|
|
1047
|
+
`width=${width},height=${height},left=${left},top=${top},resizable,scrollbars`
|
|
694
1048
|
);
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
1049
|
+
if (!popupRef.current) {
|
|
1050
|
+
setIsLoading(false);
|
|
1051
|
+
const error = "Popup blocked. Please allow popups for this site.";
|
|
1052
|
+
errorRef.current = error;
|
|
1053
|
+
onPopupBlocked?.();
|
|
1054
|
+
onError?.(error);
|
|
698
1055
|
return;
|
|
699
1056
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
1057
|
+
timerRef.current = setInterval(() => {
|
|
1058
|
+
if (popupRef.current && popupRef.current.closed) {
|
|
1059
|
+
if (timerRef.current) {
|
|
1060
|
+
clearInterval(timerRef.current);
|
|
1061
|
+
timerRef.current = null;
|
|
1062
|
+
}
|
|
1063
|
+
if (!gotDataRef.current) {
|
|
1064
|
+
const error = "Authentication popup was closed";
|
|
1065
|
+
errorRef.current = error;
|
|
1066
|
+
onPopupClosed?.();
|
|
1067
|
+
onError?.(error);
|
|
1068
|
+
setIsLoading(false);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}, 500);
|
|
1072
|
+
} catch (error) {
|
|
1073
|
+
const errorMessage = error instanceof Error ? error.message : "Google sign in failed";
|
|
1074
|
+
errorRef.current = errorMessage;
|
|
1075
|
+
onError?.(errorMessage);
|
|
1076
|
+
setIsLoading(false);
|
|
709
1077
|
}
|
|
1078
|
+
}, [signInWithGoogle, setIsLoading, handleMessage, onError, onPopupBlocked, onPopupClosed]);
|
|
1079
|
+
(0, import_react2.useEffect)(() => {
|
|
1080
|
+
window.addEventListener("message", handleMessage);
|
|
1081
|
+
return () => {
|
|
1082
|
+
window.removeEventListener("message", handleMessage);
|
|
1083
|
+
};
|
|
1084
|
+
}, [handleMessage]);
|
|
1085
|
+
(0, import_react2.useEffect)(() => {
|
|
1086
|
+
return () => {
|
|
1087
|
+
cleanup();
|
|
1088
|
+
};
|
|
1089
|
+
}, [cleanup, handleMessage]);
|
|
1090
|
+
return {
|
|
1091
|
+
signIn,
|
|
1092
|
+
isLoading,
|
|
1093
|
+
error: errorRef.current
|
|
710
1094
|
};
|
|
711
|
-
|
|
712
|
-
};
|
|
1095
|
+
}
|
|
713
1096
|
|
|
714
1097
|
// src/modules/auth/helpers/index.ts
|
|
1098
|
+
var import_uuid = require("uuid");
|
|
715
1099
|
var generateDeviceId = async () => {
|
|
716
1100
|
try {
|
|
717
1101
|
const deviceFingerprint = await generateDeviceFingerprint();
|
|
@@ -826,221 +1210,19 @@ var removeUserInfo = () => {
|
|
|
826
1210
|
localStorage.removeItem(userInfoKey);
|
|
827
1211
|
};
|
|
828
1212
|
|
|
829
|
-
// src/modules/auth/store/authSlice.ts
|
|
830
|
-
var defaultUser = {
|
|
831
|
-
uid: "",
|
|
832
|
-
id: "",
|
|
833
|
-
userName: "",
|
|
834
|
-
displayName: "",
|
|
835
|
-
avatar: "/images/default-avatar.jpg",
|
|
836
|
-
email: "",
|
|
837
|
-
exp: 0,
|
|
838
|
-
emailVerified: false,
|
|
839
|
-
refreshToken: "",
|
|
840
|
-
accessToken: "",
|
|
841
|
-
role: "NULL" /* NULL */,
|
|
842
|
-
scanStatus: false
|
|
843
|
-
};
|
|
844
|
-
var initialState = {
|
|
845
|
-
user: defaultUser,
|
|
846
|
-
isSignedIn: false,
|
|
847
|
-
pending: true
|
|
848
|
-
};
|
|
849
|
-
var authSlice = (0, import_toolkit.createSlice)({
|
|
850
|
-
name: "auth",
|
|
851
|
-
initialState,
|
|
852
|
-
reducers: {
|
|
853
|
-
signIn: (state, action) => {
|
|
854
|
-
const userData = action.payload;
|
|
855
|
-
state.user = userData;
|
|
856
|
-
state.isSignedIn = true;
|
|
857
|
-
state.pending = false;
|
|
858
|
-
setUserInfo(userData);
|
|
859
|
-
setAccessToken(userData.accessToken);
|
|
860
|
-
setRefreshToken(userData.refreshToken);
|
|
861
|
-
},
|
|
862
|
-
signOut: (state) => {
|
|
863
|
-
state.user = defaultUser;
|
|
864
|
-
state.isSignedIn = false;
|
|
865
|
-
state.pending = false;
|
|
866
|
-
removeUserInfo();
|
|
867
|
-
removeAccessToken();
|
|
868
|
-
removeRefreshToken();
|
|
869
|
-
},
|
|
870
|
-
updateScanStatus: (state, action) => {
|
|
871
|
-
state.user.scanStatus = action.payload;
|
|
872
|
-
setUserInfo(state.user);
|
|
873
|
-
},
|
|
874
|
-
refreshUser: (state, action) => {
|
|
875
|
-
const userData = action.payload;
|
|
876
|
-
if (userData) {
|
|
877
|
-
state.user = userData;
|
|
878
|
-
state.isSignedIn = true;
|
|
879
|
-
state.pending = false;
|
|
880
|
-
setUserInfo(userData);
|
|
881
|
-
setAccessToken(userData.accessToken);
|
|
882
|
-
setRefreshToken(userData.refreshToken);
|
|
883
|
-
}
|
|
884
|
-
},
|
|
885
|
-
setPending: (state, action) => {
|
|
886
|
-
state.pending = action.payload;
|
|
887
|
-
},
|
|
888
|
-
initializeFromStorage: (state) => {
|
|
889
|
-
const storedUser = getUserInfo();
|
|
890
|
-
const accessToken = getAccessToken();
|
|
891
|
-
if (storedUser && accessToken) {
|
|
892
|
-
state.user = storedUser;
|
|
893
|
-
state.isSignedIn = true;
|
|
894
|
-
}
|
|
895
|
-
state.pending = false;
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
});
|
|
899
|
-
var {
|
|
900
|
-
signIn,
|
|
901
|
-
signOut,
|
|
902
|
-
updateScanStatus,
|
|
903
|
-
refreshUser,
|
|
904
|
-
setPending,
|
|
905
|
-
initializeFromStorage
|
|
906
|
-
} = authSlice.actions;
|
|
907
|
-
var selectUser = (state) => state.auth.user;
|
|
908
|
-
var selectIsSignedIn = (state) => state.auth.isSignedIn;
|
|
909
|
-
var selectIsLoading = (state) => state.auth.pending;
|
|
910
|
-
var authSlice_default = authSlice.reducer;
|
|
911
|
-
|
|
912
|
-
// src/modules/auth/providers/AuthProvider.tsx
|
|
913
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
914
|
-
var AuthContext = (0, import_react.createContext)(null);
|
|
915
|
-
function AuthProvider({ children, authService, authCallbacks }) {
|
|
916
|
-
const dispatch = useAppDispatch();
|
|
917
|
-
(0, import_react.useEffect)(() => {
|
|
918
|
-
dispatch(initializeFromStorage());
|
|
919
|
-
const unsubscribe = authService.onAuthStateChanged((user2) => {
|
|
920
|
-
if (user2) {
|
|
921
|
-
dispatch(signIn(user2));
|
|
922
|
-
if (authCallbacks?.onUserIdentify && user2.email) {
|
|
923
|
-
authCallbacks.onUserIdentify({
|
|
924
|
-
email: user2.email,
|
|
925
|
-
name: user2.displayName,
|
|
926
|
-
avatar: user2.avatar,
|
|
927
|
-
uid: user2.uid
|
|
928
|
-
});
|
|
929
|
-
}
|
|
930
|
-
if (authCallbacks?.onSignInSuccess) {
|
|
931
|
-
authCallbacks.onSignInSuccess(user2);
|
|
932
|
-
}
|
|
933
|
-
} else {
|
|
934
|
-
dispatch(signOut());
|
|
935
|
-
if (authCallbacks?.onTrackingReset) {
|
|
936
|
-
authCallbacks.onTrackingReset();
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
dispatch(setPending(false));
|
|
940
|
-
});
|
|
941
|
-
return () => {
|
|
942
|
-
unsubscribe();
|
|
943
|
-
};
|
|
944
|
-
}, [authService, dispatch, authCallbacks]);
|
|
945
|
-
const user = useAppSelector(selectUser);
|
|
946
|
-
const isSignedIn = useAppSelector(selectIsSignedIn);
|
|
947
|
-
const isLoading = useAppSelector(selectIsLoading);
|
|
948
|
-
const signInWithCredential = async (email, password) => {
|
|
949
|
-
const result = await authService.signInWithEmailAndPassword(email, password);
|
|
950
|
-
if (result.data && authCallbacks?.onSignInSuccess) {
|
|
951
|
-
authCallbacks.onSignInSuccess(result.data);
|
|
952
|
-
} else if (result.errorCode && authCallbacks?.onSignInError) {
|
|
953
|
-
authCallbacks.onSignInError(result.errorCode);
|
|
954
|
-
}
|
|
955
|
-
return result;
|
|
956
|
-
};
|
|
957
|
-
const signInWithGoogle = async () => {
|
|
958
|
-
const result = await authService.signInWithGoogle();
|
|
959
|
-
if (result.data && authCallbacks?.onSignInSuccess) {
|
|
960
|
-
authCallbacks.onSignInSuccess(result.data);
|
|
961
|
-
return result;
|
|
962
|
-
} else if (result.errorCode && authCallbacks?.onSignInError) {
|
|
963
|
-
authCallbacks.onSignInError(result.errorCode);
|
|
964
|
-
}
|
|
965
|
-
return null;
|
|
966
|
-
};
|
|
967
|
-
const signUp = async (email, password) => {
|
|
968
|
-
const result = await authService.signUp(email, password);
|
|
969
|
-
if (result.data && authCallbacks?.onSignUpSuccess) {
|
|
970
|
-
authCallbacks.onSignUpSuccess(result.data);
|
|
971
|
-
} else if (result.errorCode && authCallbacks?.onSignUpError) {
|
|
972
|
-
authCallbacks.onSignUpError(result.errorCode);
|
|
973
|
-
}
|
|
974
|
-
return result;
|
|
975
|
-
};
|
|
976
|
-
const signOut2 = async () => {
|
|
977
|
-
await authService.signOut();
|
|
978
|
-
dispatch(signOut());
|
|
979
|
-
if (authCallbacks?.onSignOutSuccess) {
|
|
980
|
-
authCallbacks.onSignOutSuccess();
|
|
981
|
-
}
|
|
982
|
-
};
|
|
983
|
-
const forgotPassword = async (email) => {
|
|
984
|
-
return await authService.sendPasswordResetEmail(email);
|
|
985
|
-
};
|
|
986
|
-
const sendEmailVerification = async () => {
|
|
987
|
-
return await authService.sendEmailVerification();
|
|
988
|
-
};
|
|
989
|
-
const changePassword = async (newPassword) => {
|
|
990
|
-
return await authService.changePassword(newPassword);
|
|
991
|
-
};
|
|
992
|
-
const updateScanStatus2 = (status) => {
|
|
993
|
-
dispatch(updateScanStatus(status));
|
|
994
|
-
};
|
|
995
|
-
const refreshUser2 = (userData) => {
|
|
996
|
-
dispatch(refreshUser(userData));
|
|
997
|
-
};
|
|
998
|
-
const contextValue = {
|
|
999
|
-
authService,
|
|
1000
|
-
authCallbacks,
|
|
1001
|
-
// User state
|
|
1002
|
-
user,
|
|
1003
|
-
isSignedIn,
|
|
1004
|
-
isLoading,
|
|
1005
|
-
// Auth actions
|
|
1006
|
-
signInWithCredential,
|
|
1007
|
-
signInWithGoogle,
|
|
1008
|
-
signUp,
|
|
1009
|
-
signOut: signOut2,
|
|
1010
|
-
// Password actions
|
|
1011
|
-
forgotPassword,
|
|
1012
|
-
sendEmailVerification,
|
|
1013
|
-
changePassword,
|
|
1014
|
-
// User management
|
|
1015
|
-
updateScanStatus: updateScanStatus2,
|
|
1016
|
-
refreshUser: refreshUser2
|
|
1017
|
-
};
|
|
1018
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AuthContext.Provider, { value: contextValue, children });
|
|
1019
|
-
}
|
|
1020
|
-
var useAuth = () => {
|
|
1021
|
-
const authContext = (0, import_react.useContext)(AuthContext);
|
|
1022
|
-
if (!authContext) {
|
|
1023
|
-
throw new Error("useAuth must be used within an AuthProvider");
|
|
1024
|
-
}
|
|
1025
|
-
return authContext;
|
|
1026
|
-
};
|
|
1027
|
-
|
|
1028
|
-
// src/modules/auth/index.ts
|
|
1029
|
-
init_constants();
|
|
1030
|
-
|
|
1031
1213
|
// src/modules/user-profile/hooks/index.ts
|
|
1032
|
-
var
|
|
1214
|
+
var import_api_core5 = require("@phygitallabs/api-core");
|
|
1033
1215
|
|
|
1034
1216
|
// src/modules/user-profile/types/index.ts
|
|
1035
|
-
var
|
|
1217
|
+
var import_api_core6 = require("@phygitallabs/api-core");
|
|
1036
1218
|
|
|
1037
1219
|
// src/modules/scan-chip/hooks/index.tsx
|
|
1038
|
-
var
|
|
1039
|
-
var
|
|
1040
|
-
var
|
|
1220
|
+
var import_react3 = require("react");
|
|
1221
|
+
var import_api_core7 = require("@phygitallabs/api-core");
|
|
1222
|
+
var import_api_core8 = require("@phygitallabs/api-core");
|
|
1041
1223
|
function useScanChip({ token, id, onScanChipError }) {
|
|
1042
|
-
const { updateHeaders } = (0,
|
|
1043
|
-
(0,
|
|
1224
|
+
const { updateHeaders } = (0, import_api_core8.usePGLCoreService)();
|
|
1225
|
+
(0, import_react3.useEffect)(() => {
|
|
1044
1226
|
if (!!token) {
|
|
1045
1227
|
const header = {
|
|
1046
1228
|
"Chip-Authorization": token
|
|
@@ -1049,11 +1231,11 @@ function useScanChip({ token, id, onScanChipError }) {
|
|
|
1049
1231
|
updateHeaders(header);
|
|
1050
1232
|
}
|
|
1051
1233
|
}, [token, updateHeaders]);
|
|
1052
|
-
const { data, isLoading, isError, isSuccess } = (0,
|
|
1234
|
+
const { data, isLoading, isError, isSuccess } = (0, import_api_core7.useChipScanStory)({
|
|
1053
1235
|
token,
|
|
1054
1236
|
id
|
|
1055
1237
|
});
|
|
1056
|
-
(0,
|
|
1238
|
+
(0, import_react3.useEffect)(() => {
|
|
1057
1239
|
if (isError) {
|
|
1058
1240
|
onScanChipError?.();
|
|
1059
1241
|
}
|
|
@@ -1085,10 +1267,10 @@ function useScanChip({ token, id, onScanChipError }) {
|
|
|
1085
1267
|
}
|
|
1086
1268
|
|
|
1087
1269
|
// src/modules/campaign/hooks/useCampaignService.ts
|
|
1088
|
-
var
|
|
1270
|
+
var import_api_core9 = require("@phygitallabs/api-core");
|
|
1089
1271
|
|
|
1090
1272
|
// src/modules/campaign/types/enums.ts
|
|
1091
|
-
var
|
|
1273
|
+
var import_api_core10 = require("@phygitallabs/api-core");
|
|
1092
1274
|
|
|
1093
1275
|
// src/modules/campaign/types/campaign.ts
|
|
1094
1276
|
var TaskType = /* @__PURE__ */ ((TaskType2) => {
|
|
@@ -1100,7 +1282,7 @@ var TaskType = /* @__PURE__ */ ((TaskType2) => {
|
|
|
1100
1282
|
})(TaskType || {});
|
|
1101
1283
|
|
|
1102
1284
|
// src/modules/location/hooks/useLocationService.ts
|
|
1103
|
-
var
|
|
1285
|
+
var import_api_core11 = require("@phygitallabs/api-core");
|
|
1104
1286
|
|
|
1105
1287
|
// src/modules/location/utils/locationHelpers.ts
|
|
1106
1288
|
var sortLocationsByIndex = (locations) => {
|
|
@@ -1111,10 +1293,168 @@ var filterLocationsByProperty = (locations, propertyName, value) => {
|
|
|
1111
1293
|
};
|
|
1112
1294
|
|
|
1113
1295
|
// src/modules/generate-certificate/hooks/index.ts
|
|
1114
|
-
var
|
|
1296
|
+
var import_generate_certificate2 = require("@phygitallabs/generate-certificate");
|
|
1297
|
+
|
|
1298
|
+
// src/modules/generate-certificate/helpers/index.ts
|
|
1299
|
+
var import_generate_certificate3 = require("@phygitallabs/generate-certificate");
|
|
1115
1300
|
|
|
1116
1301
|
// src/modules/data-tracking/hooks/index.ts
|
|
1117
1302
|
var import_posthog_js = __toESM(require("posthog-js"), 1);
|
|
1303
|
+
|
|
1304
|
+
// src/modules/session-replay/providers/SessionReplayProvider.tsx
|
|
1305
|
+
var import_react4 = require("react");
|
|
1306
|
+
var import_uuid2 = require("uuid");
|
|
1307
|
+
|
|
1308
|
+
// src/modules/session-replay/utils/index.ts
|
|
1309
|
+
var isBrowser = () => {
|
|
1310
|
+
return typeof window !== "undefined";
|
|
1311
|
+
};
|
|
1312
|
+
|
|
1313
|
+
// src/modules/session-replay/providers/SessionReplayProvider.tsx
|
|
1314
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1315
|
+
var TrackerContext = (0, import_react4.createContext)(null);
|
|
1316
|
+
function defaultGetUserId() {
|
|
1317
|
+
return (0, import_uuid2.v4)();
|
|
1318
|
+
}
|
|
1319
|
+
async function newTracker(config) {
|
|
1320
|
+
try {
|
|
1321
|
+
const OpenReplay = (await import("@openreplay/tracker")).default;
|
|
1322
|
+
const getUserId = config?.userIdEnabled && config?.getUserId ? config.getUserId : defaultGetUserId;
|
|
1323
|
+
const trackerConfig = {
|
|
1324
|
+
projectKey: config?.projectKey || process.env.NEXT_PUBLIC_OPENREPLAY_PROJECT_KEY,
|
|
1325
|
+
ingestPoint: config?.ingestPoint,
|
|
1326
|
+
// Capture options
|
|
1327
|
+
captureExceptions: config.captureExceptions ?? true,
|
|
1328
|
+
capturePerformance: config.capturePerformance ?? true,
|
|
1329
|
+
// Network tracking
|
|
1330
|
+
network: config.network || {
|
|
1331
|
+
capturePayload: true,
|
|
1332
|
+
sanitizer: (data) => data
|
|
1333
|
+
},
|
|
1334
|
+
// Console tracking
|
|
1335
|
+
console: config.console || {
|
|
1336
|
+
levels: ["error", "warn", "log"]
|
|
1337
|
+
},
|
|
1338
|
+
// Privacy settings
|
|
1339
|
+
obscureTextEmails: config.obscureTextEmails ?? true,
|
|
1340
|
+
obscureTextNumbers: config.obscureTextNumbers ?? false,
|
|
1341
|
+
obscureInputEmails: config.obscureInputEmails ?? true,
|
|
1342
|
+
// Development mode
|
|
1343
|
+
__DISABLE_SECURE_MODE: config.__DISABLE_SECURE_MODE ?? (typeof process !== "undefined" && process.env?.NODE_ENV === "development")
|
|
1344
|
+
};
|
|
1345
|
+
const tracker = new OpenReplay(trackerConfig);
|
|
1346
|
+
if (config?.userIdEnabled) {
|
|
1347
|
+
const userId = getUserId();
|
|
1348
|
+
tracker.setUserID(userId);
|
|
1349
|
+
console.log("User ID set:", userId);
|
|
1350
|
+
}
|
|
1351
|
+
console.log("OpenReplay tracker initialized");
|
|
1352
|
+
console.log("Project Key:", trackerConfig.projectKey);
|
|
1353
|
+
console.log("Ingest Point:", trackerConfig.ingestPoint);
|
|
1354
|
+
return tracker;
|
|
1355
|
+
} catch (error) {
|
|
1356
|
+
console.error("Failed to create tracker:", error);
|
|
1357
|
+
throw error;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
function reducer(state, action) {
|
|
1361
|
+
const { debug = false } = state.config;
|
|
1362
|
+
switch (action.type) {
|
|
1363
|
+
case "init":
|
|
1364
|
+
if (!state.tracker && isBrowser()) {
|
|
1365
|
+
if (!state.config.projectKey && !process.env.NEXT_PUBLIC_OPENREPLAY_PROJECT_KEY) {
|
|
1366
|
+
console.warn(
|
|
1367
|
+
debug,
|
|
1368
|
+
"Project key not found. Skipping session replay initialization."
|
|
1369
|
+
);
|
|
1370
|
+
return state;
|
|
1371
|
+
}
|
|
1372
|
+
return {
|
|
1373
|
+
...state,
|
|
1374
|
+
tracker: newTracker(state.config)
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
return state;
|
|
1378
|
+
case "start":
|
|
1379
|
+
if (state.tracker) {
|
|
1380
|
+
Promise.resolve(state.tracker).then((tracker) => {
|
|
1381
|
+
tracker.start();
|
|
1382
|
+
console.log(debug, "Session replay tracker started");
|
|
1383
|
+
}).catch((error) => {
|
|
1384
|
+
console.error("Failed to start tracker:", error);
|
|
1385
|
+
});
|
|
1386
|
+
} else {
|
|
1387
|
+
console.warn(debug, "Tracker not initialized. Call initTracker() first.");
|
|
1388
|
+
}
|
|
1389
|
+
return state;
|
|
1390
|
+
case "setUserId":
|
|
1391
|
+
if (state.tracker) {
|
|
1392
|
+
Promise.resolve(state.tracker).then((tracker) => {
|
|
1393
|
+
tracker.setUserID(action.payload);
|
|
1394
|
+
console.log(debug, "User ID updated:", action.payload);
|
|
1395
|
+
}).catch((error) => {
|
|
1396
|
+
console.error("Failed to set user ID:", error);
|
|
1397
|
+
});
|
|
1398
|
+
} else {
|
|
1399
|
+
console.warn(debug, "Tracker not initialized. Call initTracker() first.");
|
|
1400
|
+
}
|
|
1401
|
+
return state;
|
|
1402
|
+
// Set metadata
|
|
1403
|
+
case "setMetadata":
|
|
1404
|
+
if (state.tracker) {
|
|
1405
|
+
Promise.resolve(state.tracker).then((tracker) => {
|
|
1406
|
+
Object.entries(action.payload || {})?.forEach(([key, value]) => {
|
|
1407
|
+
tracker.setMetadata(key, value);
|
|
1408
|
+
});
|
|
1409
|
+
console.log(debug, "Metadata updated:", action.payload.metadata);
|
|
1410
|
+
}).catch((error) => {
|
|
1411
|
+
console.error("Failed to set metadata:", error);
|
|
1412
|
+
});
|
|
1413
|
+
} else {
|
|
1414
|
+
console.warn(debug, "Tracker not initialized. Call initTracker() first.");
|
|
1415
|
+
}
|
|
1416
|
+
return state;
|
|
1417
|
+
default:
|
|
1418
|
+
return state;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
var SessionReplayProvider = ({
|
|
1422
|
+
children,
|
|
1423
|
+
config = {}
|
|
1424
|
+
}) => {
|
|
1425
|
+
const [, dispatch] = (0, import_react4.useReducer)(reducer, {
|
|
1426
|
+
tracker: null,
|
|
1427
|
+
config
|
|
1428
|
+
});
|
|
1429
|
+
const initTracker = () => dispatch({ type: "init" });
|
|
1430
|
+
const startTracking = () => dispatch({ type: "start" });
|
|
1431
|
+
const setUserId = (userId) => dispatch({ type: "setUserId", payload: userId });
|
|
1432
|
+
const setMetadata = (metadata) => dispatch({ type: "setMetadata", payload: metadata });
|
|
1433
|
+
(0, import_react4.useEffect)(() => {
|
|
1434
|
+
initTracker();
|
|
1435
|
+
startTracking();
|
|
1436
|
+
}, []);
|
|
1437
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TrackerContext.Provider, { value: {
|
|
1438
|
+
initTracker,
|
|
1439
|
+
startTracking,
|
|
1440
|
+
setUserId,
|
|
1441
|
+
setMetadata
|
|
1442
|
+
}, children });
|
|
1443
|
+
};
|
|
1444
|
+
|
|
1445
|
+
// src/modules/session-replay/hooks/useSessionReplay.ts
|
|
1446
|
+
var import_react5 = require("react");
|
|
1447
|
+
function useSessionReplay() {
|
|
1448
|
+
const context = (0, import_react5.useContext)(TrackerContext);
|
|
1449
|
+
if (!context) {
|
|
1450
|
+
throw new Error(
|
|
1451
|
+
"useSessionReplay must be used within a SessionReplayProvider. Make sure your component is wrapped with <SessionReplayProvider>."
|
|
1452
|
+
);
|
|
1453
|
+
}
|
|
1454
|
+
return context;
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
// src/modules/data-tracking/hooks/index.ts
|
|
1118
1458
|
var pushEventToDataLayer = (event, data) => {
|
|
1119
1459
|
try {
|
|
1120
1460
|
window.dataLayer = window.dataLayer || [];
|
|
@@ -1137,6 +1477,7 @@ var pushEventToPosthog = (eventName, eventData) => {
|
|
|
1137
1477
|
import_posthog_js.default.capture(eventName, eventData);
|
|
1138
1478
|
};
|
|
1139
1479
|
function useDataTracking() {
|
|
1480
|
+
const { setUserId, setMetadata } = useSessionReplay();
|
|
1140
1481
|
const trackEvent = (eventName, eventData, useTools) => {
|
|
1141
1482
|
useTools = useTools || ["gtm"];
|
|
1142
1483
|
if (useTools.includes("gtm") && typeof window !== "undefined") {
|
|
@@ -1149,91 +1490,58 @@ function useDataTracking() {
|
|
|
1149
1490
|
pushEventToPosthog(eventName, eventData);
|
|
1150
1491
|
}
|
|
1151
1492
|
};
|
|
1493
|
+
const trackUserIdentify = (userInfo) => {
|
|
1494
|
+
import_posthog_js.default.identify(userInfo.email, {
|
|
1495
|
+
email: userInfo.email,
|
|
1496
|
+
name: userInfo.name,
|
|
1497
|
+
avatar: userInfo.avatar,
|
|
1498
|
+
uid: userInfo.uid
|
|
1499
|
+
});
|
|
1500
|
+
setUserId(userInfo.id);
|
|
1501
|
+
setMetadata({
|
|
1502
|
+
user_email: userInfo.email
|
|
1503
|
+
});
|
|
1504
|
+
};
|
|
1505
|
+
const trackLogoutEvent = () => {
|
|
1506
|
+
import_posthog_js.default.capture("user_signed_out");
|
|
1507
|
+
};
|
|
1152
1508
|
return {
|
|
1153
|
-
trackEvent
|
|
1509
|
+
trackEvent,
|
|
1510
|
+
trackUserIdentify,
|
|
1511
|
+
trackLogoutEvent
|
|
1154
1512
|
};
|
|
1155
1513
|
}
|
|
1156
1514
|
|
|
1157
1515
|
// src/providers/TapquestCoreProvider.tsx
|
|
1158
|
-
var
|
|
1159
|
-
var import_react_redux2 = require("react-redux");
|
|
1160
|
-
var import_react5 = require("redux-persist/integration/react");
|
|
1516
|
+
var import_react7 = require("react");
|
|
1161
1517
|
|
|
1162
1518
|
// src/providers/ServicesProvider.tsx
|
|
1163
|
-
var
|
|
1164
|
-
var
|
|
1165
|
-
var
|
|
1166
|
-
var
|
|
1167
|
-
var
|
|
1168
|
-
var
|
|
1169
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1519
|
+
var import_react6 = require("react");
|
|
1520
|
+
var import_api_core12 = require("@phygitallabs/api-core");
|
|
1521
|
+
var import_reward4 = require("@phygitallabs/reward");
|
|
1522
|
+
var import_achievement5 = require("@phygitallabs/achievement");
|
|
1523
|
+
var import_generate_certificate4 = require("@phygitallabs/generate-certificate");
|
|
1524
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1170
1525
|
var ServicesProvider = ({
|
|
1171
1526
|
children,
|
|
1172
1527
|
queryClient,
|
|
1173
1528
|
apiConfig = {
|
|
1174
1529
|
environment: "dev",
|
|
1175
1530
|
version: "v1"
|
|
1176
|
-
}
|
|
1177
|
-
firebaseConfig
|
|
1531
|
+
}
|
|
1178
1532
|
}) => {
|
|
1179
|
-
const { refreshUser: refreshUser2, signOut: signOut2 } = useAuth();
|
|
1180
1533
|
const { environment, version } = apiConfig;
|
|
1181
|
-
const [commonServiceConfig, setCommonServiceConfig] = (0,
|
|
1182
|
-
|
|
1183
|
-
if (!firebaseConfig?.apiKey) {
|
|
1184
|
-
console.warn("Firebase API key not provided, refresh token functionality will not work");
|
|
1185
|
-
return null;
|
|
1186
|
-
}
|
|
1187
|
-
return createRefreshTokenFunction({
|
|
1188
|
-
firebaseApiKey: firebaseConfig.apiKey
|
|
1189
|
-
});
|
|
1190
|
-
}, [firebaseConfig?.apiKey]);
|
|
1191
|
-
(0, import_react3.useEffect)(() => {
|
|
1534
|
+
const [commonServiceConfig, setCommonServiceConfig] = (0, import_react6.useState)(null);
|
|
1535
|
+
(0, import_react6.useEffect)(() => {
|
|
1192
1536
|
const initClient = async () => {
|
|
1193
1537
|
try {
|
|
1194
1538
|
const deviceUid = await checkDeviceUid();
|
|
1195
1539
|
const responseInterceptors = {
|
|
1196
1540
|
onFulfilled: (response) => response,
|
|
1197
|
-
onRejected: async (error) =>
|
|
1198
|
-
const originalRequest = error.config;
|
|
1199
|
-
if (error.response?.status === 401 && !originalRequest._retry) {
|
|
1200
|
-
const retryAttempts = parseInt(
|
|
1201
|
-
getRetryAttemptsRefreshToken() || "0",
|
|
1202
|
-
10
|
|
1203
|
-
);
|
|
1204
|
-
if (retryAttempts >= httpMaxRetries) {
|
|
1205
|
-
await signOut2();
|
|
1206
|
-
return Promise.reject(error);
|
|
1207
|
-
}
|
|
1208
|
-
setRetryAttemptsRefreshToken(`${retryAttempts + 1}`);
|
|
1209
|
-
originalRequest._retry = true;
|
|
1210
|
-
try {
|
|
1211
|
-
if (!memoizedRefreshToken) {
|
|
1212
|
-
await signOut2();
|
|
1213
|
-
return Promise.reject(error);
|
|
1214
|
-
}
|
|
1215
|
-
const result = await memoizedRefreshToken();
|
|
1216
|
-
if (result?.accessToken) {
|
|
1217
|
-
originalRequest.headers["Authorization"] = `Bearer ${result.accessToken}`;
|
|
1218
|
-
setRetryAttemptsRefreshToken("0");
|
|
1219
|
-
refreshUser2(result);
|
|
1220
|
-
return (0, import_axios.default)(originalRequest);
|
|
1221
|
-
}
|
|
1222
|
-
} catch (refreshError) {
|
|
1223
|
-
console.log("Failed to refresh token:", refreshError);
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
return Promise.reject(error);
|
|
1227
|
-
}
|
|
1541
|
+
onRejected: async (error) => Promise.reject(error)
|
|
1228
1542
|
};
|
|
1229
1543
|
const requestInterceptors = {
|
|
1230
|
-
onFulfilled: (config2) =>
|
|
1231
|
-
const currentToken = getAccessToken();
|
|
1232
|
-
if (currentToken && !config2.headers.Authorization) {
|
|
1233
|
-
config2.headers.Authorization = `Bearer ${currentToken}`;
|
|
1234
|
-
}
|
|
1235
|
-
return config2;
|
|
1236
|
-
},
|
|
1544
|
+
onFulfilled: (config2) => config2,
|
|
1237
1545
|
onRejected: (error) => Promise.reject(error)
|
|
1238
1546
|
};
|
|
1239
1547
|
const axiosConfig = {
|
|
@@ -1257,26 +1565,26 @@ var ServicesProvider = ({
|
|
|
1257
1565
|
initClient();
|
|
1258
1566
|
}, [queryClient]);
|
|
1259
1567
|
if (!commonServiceConfig) {
|
|
1260
|
-
return /* @__PURE__ */ (0,
|
|
1568
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, {});
|
|
1261
1569
|
}
|
|
1262
|
-
return /* @__PURE__ */ (0,
|
|
1263
|
-
|
|
1570
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1571
|
+
import_api_core12.PGLCoreServiceProvider,
|
|
1264
1572
|
{
|
|
1265
1573
|
...commonServiceConfig,
|
|
1266
1574
|
baseURL: `${service_default[environment].API_BASE_URL}/${version}`,
|
|
1267
1575
|
baseCoreURL: `${service_default[environment].API_BASE_CORE_URL}/${version}`,
|
|
1268
|
-
children: /* @__PURE__ */ (0,
|
|
1269
|
-
|
|
1576
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1577
|
+
import_reward4.RewardServiceProvider,
|
|
1270
1578
|
{
|
|
1271
1579
|
...commonServiceConfig,
|
|
1272
1580
|
baseURL: `${service_default[environment].API_REWARD_URL}/v1`,
|
|
1273
|
-
children: /* @__PURE__ */ (0,
|
|
1274
|
-
|
|
1581
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1582
|
+
import_achievement5.AchievementServiceProvider,
|
|
1275
1583
|
{
|
|
1276
1584
|
...commonServiceConfig,
|
|
1277
1585
|
baseURL: `${service_default[environment].API_ACHIEVEMENT_URL}/${version}`,
|
|
1278
|
-
children: /* @__PURE__ */ (0,
|
|
1279
|
-
|
|
1586
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1587
|
+
import_generate_certificate4.GenerateCertificateServiceProvider,
|
|
1280
1588
|
{
|
|
1281
1589
|
...commonServiceConfig,
|
|
1282
1590
|
baseURL: `${service_default[environment].API_GENERATE_CERTIFICATE_URL}/v1`,
|
|
@@ -1291,80 +1599,51 @@ var ServicesProvider = ({
|
|
|
1291
1599
|
);
|
|
1292
1600
|
};
|
|
1293
1601
|
|
|
1294
|
-
// src/store/index.ts
|
|
1295
|
-
var import_toolkit2 = require("@reduxjs/toolkit");
|
|
1296
|
-
var import_storage = __toESM(require("redux-persist/lib/storage"), 1);
|
|
1297
|
-
var import_redux_persist = require("redux-persist");
|
|
1298
|
-
var authPersistConfig = {
|
|
1299
|
-
key: "tapquest-auth",
|
|
1300
|
-
storage: import_storage.default,
|
|
1301
|
-
whitelist: ["user", "isSignedIn"]
|
|
1302
|
-
// Only persist user and sign-in status
|
|
1303
|
-
};
|
|
1304
|
-
var persistedAuthReducer = (0, import_redux_persist.persistReducer)(authPersistConfig, authSlice.reducer);
|
|
1305
|
-
var store = (0, import_toolkit2.configureStore)({
|
|
1306
|
-
reducer: {
|
|
1307
|
-
auth: persistedAuthReducer
|
|
1308
|
-
},
|
|
1309
|
-
middleware: (getDefaultMiddleware) => getDefaultMiddleware({
|
|
1310
|
-
serializableCheck: {
|
|
1311
|
-
// Ignore redux-persist actions
|
|
1312
|
-
ignoredActions: [
|
|
1313
|
-
"persist/FLUSH",
|
|
1314
|
-
"persist/REHYDRATE",
|
|
1315
|
-
"persist/PAUSE",
|
|
1316
|
-
"persist/PERSIST",
|
|
1317
|
-
"persist/PURGE",
|
|
1318
|
-
"persist/REGISTER"
|
|
1319
|
-
]
|
|
1320
|
-
}
|
|
1321
|
-
})
|
|
1322
|
-
});
|
|
1323
|
-
var persistor = (0, import_redux_persist.persistStore)(store);
|
|
1324
|
-
|
|
1325
1602
|
// src/providers/TapquestCoreProvider.tsx
|
|
1326
|
-
var
|
|
1603
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1327
1604
|
var TapquestCoreProvider = ({
|
|
1328
1605
|
children,
|
|
1329
1606
|
queryClient,
|
|
1330
|
-
apiConfig
|
|
1331
|
-
|
|
1332
|
-
authCallbacks
|
|
1607
|
+
apiConfig
|
|
1608
|
+
// authCallbacks
|
|
1333
1609
|
}) => {
|
|
1334
|
-
const
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
} catch (error) {
|
|
1340
|
-
console.warn("Failed to create auth service from firebase config:", error);
|
|
1341
|
-
return null;
|
|
1342
|
-
}
|
|
1610
|
+
const { environment } = apiConfig;
|
|
1611
|
+
const sessionReplayConfig = (0, import_react7.useMemo)(() => {
|
|
1612
|
+
const projectKey = process.env.NEXT_PUBLIC_OPENREPLAY_PROJECT_KEY;
|
|
1613
|
+
if (!projectKey) {
|
|
1614
|
+
return void 0;
|
|
1343
1615
|
}
|
|
1344
|
-
return
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1616
|
+
return {
|
|
1617
|
+
projectKey,
|
|
1618
|
+
ingestPoint: process.env.NEXT_PUBLIC_OPENREPLAY_INGEST_POINT,
|
|
1619
|
+
debug: process.env.NODE_ENV === "development",
|
|
1620
|
+
captureExceptions: true,
|
|
1621
|
+
capturePerformance: true,
|
|
1622
|
+
obscureTextEmails: true,
|
|
1623
|
+
obscureInputEmails: true
|
|
1624
|
+
};
|
|
1625
|
+
}, []);
|
|
1626
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SessionReplayProvider, { config: sessionReplayConfig, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1627
|
+
ServicesProvider,
|
|
1348
1628
|
{
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
children: /* @__PURE__ */ (0,
|
|
1352
|
-
|
|
1629
|
+
queryClient,
|
|
1630
|
+
apiConfig,
|
|
1631
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1632
|
+
AuthProvider,
|
|
1353
1633
|
{
|
|
1634
|
+
baseURL: `${service_default[environment].API_BASE_URL}`,
|
|
1354
1635
|
queryClient,
|
|
1355
|
-
apiConfig,
|
|
1356
|
-
firebaseConfig,
|
|
1357
1636
|
children
|
|
1358
1637
|
}
|
|
1359
1638
|
)
|
|
1360
1639
|
}
|
|
1361
|
-
) })
|
|
1640
|
+
) });
|
|
1362
1641
|
};
|
|
1363
1642
|
|
|
1364
1643
|
// src/modules/achivementWithReward/hooks/achivementPlusRewardModel.ts
|
|
1365
|
-
var
|
|
1644
|
+
var import_achievement6 = require("@phygitallabs/achievement");
|
|
1366
1645
|
var import_useGroupReward = require("@phygitallabs/reward/src/hooks/useGroupReward");
|
|
1367
|
-
var
|
|
1646
|
+
var import_react8 = require("react");
|
|
1368
1647
|
function buildMappedAchievements(achievements, groupRewardData) {
|
|
1369
1648
|
if (!groupRewardData?.reward_models) return [];
|
|
1370
1649
|
const rewardModels = groupRewardData.reward_models;
|
|
@@ -1386,7 +1665,7 @@ function buildMappedAchievements(achievements, groupRewardData) {
|
|
|
1386
1665
|
});
|
|
1387
1666
|
}
|
|
1388
1667
|
var useAchivementPlusRewardModel = ({ campaignId }) => {
|
|
1389
|
-
const { data: achievements, isLoading: isLoadingAchievements } = (0,
|
|
1668
|
+
const { data: achievements, isLoading: isLoadingAchievements } = (0, import_achievement6.useManyAchievements)(
|
|
1390
1669
|
{
|
|
1391
1670
|
"filter.labels": { campaign_id: campaignId },
|
|
1392
1671
|
"filter.type": "group_mission",
|
|
@@ -1394,7 +1673,7 @@ var useAchivementPlusRewardModel = ({ campaignId }) => {
|
|
|
1394
1673
|
},
|
|
1395
1674
|
{ enabled: !!campaignId }
|
|
1396
1675
|
);
|
|
1397
|
-
const groupRewardIds = (0,
|
|
1676
|
+
const groupRewardIds = (0, import_react8.useMemo)(() => {
|
|
1398
1677
|
if (!achievements?.data) return [];
|
|
1399
1678
|
return achievements.data.map((achievement) => achievement.groupRewardId).filter((id) => id !== void 0);
|
|
1400
1679
|
}, [achievements?.data]);
|
|
@@ -1403,12 +1682,12 @@ var useAchivementPlusRewardModel = ({ campaignId }) => {
|
|
|
1403
1682
|
data: groupRewardModelsData,
|
|
1404
1683
|
isPending: isPendingGroupRewardModels
|
|
1405
1684
|
} = (0, import_useGroupReward.useCreateModelGroupReward)();
|
|
1406
|
-
(0,
|
|
1685
|
+
(0, import_react8.useEffect)(() => {
|
|
1407
1686
|
if (groupRewardIds.length > 0) {
|
|
1408
1687
|
fetchGroupRewardModels({ group_reward_ids: groupRewardIds });
|
|
1409
1688
|
}
|
|
1410
1689
|
}, [groupRewardIds, fetchGroupRewardModels]);
|
|
1411
|
-
const mappedAchievements = (0,
|
|
1690
|
+
const mappedAchievements = (0, import_react8.useMemo)(() => {
|
|
1412
1691
|
if (!groupRewardModelsData?.data || !achievements?.data) return [];
|
|
1413
1692
|
return buildMappedAchievements(achievements.data, groupRewardModelsData.data);
|
|
1414
1693
|
}, [groupRewardModelsData, achievements?.data]);
|
|
@@ -1420,16 +1699,18 @@ var useAchivementPlusRewardModel = ({ campaignId }) => {
|
|
|
1420
1699
|
var achivementPlusRewardModel_default = useAchivementPlusRewardModel;
|
|
1421
1700
|
|
|
1422
1701
|
// src/modules/send-email/hooks/index.ts
|
|
1423
|
-
var
|
|
1702
|
+
var import_api_core13 = require("@phygitallabs/api-core");
|
|
1424
1703
|
|
|
1425
1704
|
// src/helper/helpers.ts
|
|
1426
1705
|
var import_helpers5 = require("@phygitallabs/helpers");
|
|
1427
1706
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1428
1707
|
0 && (module.exports = {
|
|
1708
|
+
ALLOWED_ORIGINS,
|
|
1429
1709
|
AchievementRuleActionType,
|
|
1430
1710
|
AchievementServiceProvider,
|
|
1431
1711
|
AchievementType,
|
|
1432
1712
|
AuthProvider,
|
|
1713
|
+
CALLBACK_URL,
|
|
1433
1714
|
CampaignState,
|
|
1434
1715
|
CmentityRewardType,
|
|
1435
1716
|
NotificationProvider,
|
|
@@ -1442,7 +1723,6 @@ var import_helpers5 = require("@phygitallabs/helpers");
|
|
|
1442
1723
|
chipAuthTokenKey,
|
|
1443
1724
|
cn,
|
|
1444
1725
|
convertSnakeToCamel,
|
|
1445
|
-
createRefreshTokenFunction,
|
|
1446
1726
|
deviceUIDKey,
|
|
1447
1727
|
fileToBase64,
|
|
1448
1728
|
filterLocationsByProperty,
|
|
@@ -1483,6 +1763,9 @@ var import_helpers5 = require("@phygitallabs/helpers");
|
|
|
1483
1763
|
useChipScanStory,
|
|
1484
1764
|
useClaimUserReward,
|
|
1485
1765
|
useClearUserRewardCache,
|
|
1766
|
+
useCreateCertificate,
|
|
1767
|
+
useCreateCertificateAnonymous,
|
|
1768
|
+
useCreateCertificateWithMask,
|
|
1486
1769
|
useCreateMemory,
|
|
1487
1770
|
useCreateModelGroupReward,
|
|
1488
1771
|
useCreateRewardModel,
|
|
@@ -1493,6 +1776,7 @@ var import_helpers5 = require("@phygitallabs/helpers");
|
|
|
1493
1776
|
useGenerateThaocamvienCertificate,
|
|
1494
1777
|
useGetRewardModel,
|
|
1495
1778
|
useGetUserRewards,
|
|
1779
|
+
useGoogleLogin,
|
|
1496
1780
|
useInfiniteMemories,
|
|
1497
1781
|
useListRewardModels,
|
|
1498
1782
|
useLocationDetail,
|
|
@@ -1519,6 +1803,7 @@ var import_helpers5 = require("@phygitallabs/helpers");
|
|
|
1519
1803
|
useUserAchievementAction,
|
|
1520
1804
|
useUserCampaignAction,
|
|
1521
1805
|
useV1ListRewards,
|
|
1522
|
-
userInfoKey
|
|
1806
|
+
userInfoKey,
|
|
1807
|
+
wrapTextWithFont
|
|
1523
1808
|
});
|
|
1524
1809
|
//# sourceMappingURL=index.cjs.map
|