@phygitallabs/tapquest-core 2.0.0 → 2.7.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/dist/index.cjs +1524 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +690 -0
- package/dist/index.d.ts +690 -0
- package/dist/index.js +1552 -0
- package/dist/index.js.map +1 -0
- package/package.json +8 -8
package/dist/index.js
ADDED
|
@@ -0,0 +1,1552 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __esm = (fn, res) => function __init() {
|
|
7
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
+
|
|
25
|
+
// src/modules/auth/constants/index.ts
|
|
26
|
+
var userInfoKey, accessTokenKey, refreshTokenKey, httpMaxRetries, retryAttemptsRefreshToken, deviceUIDKey, chipAuthTokenKey;
|
|
27
|
+
var init_constants = __esm({
|
|
28
|
+
"src/modules/auth/constants/index.ts"() {
|
|
29
|
+
"use strict";
|
|
30
|
+
userInfoKey = "phygital-user-info";
|
|
31
|
+
accessTokenKey = "accessToken";
|
|
32
|
+
refreshTokenKey = "refreshToken";
|
|
33
|
+
httpMaxRetries = 3;
|
|
34
|
+
retryAttemptsRefreshToken = "retryAttemptsRefreshToken";
|
|
35
|
+
deviceUIDKey = "Device-UID";
|
|
36
|
+
chipAuthTokenKey = "chip-auth-token";
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// src/modules/auth/services/FirebaseAuthService.ts
|
|
41
|
+
var firebaseApp, firebaseAuth, getFirebaseModules, FirebaseAuthService;
|
|
42
|
+
var init_FirebaseAuthService = __esm({
|
|
43
|
+
"src/modules/auth/services/FirebaseAuthService.ts"() {
|
|
44
|
+
"use strict";
|
|
45
|
+
init_constants();
|
|
46
|
+
getFirebaseModules = async () => {
|
|
47
|
+
if (typeof window === "undefined") {
|
|
48
|
+
throw new Error("Firebase can only be used in client environment");
|
|
49
|
+
}
|
|
50
|
+
if (!firebaseApp || !firebaseAuth) {
|
|
51
|
+
const [
|
|
52
|
+
{ initializeApp, getApps },
|
|
53
|
+
{
|
|
54
|
+
getAuth,
|
|
55
|
+
signInWithEmailAndPassword,
|
|
56
|
+
createUserWithEmailAndPassword,
|
|
57
|
+
signInWithPopup,
|
|
58
|
+
GoogleAuthProvider,
|
|
59
|
+
signOut: signOut2,
|
|
60
|
+
sendPasswordResetEmail,
|
|
61
|
+
sendEmailVerification,
|
|
62
|
+
updatePassword,
|
|
63
|
+
onAuthStateChanged
|
|
64
|
+
}
|
|
65
|
+
] = await Promise.all([
|
|
66
|
+
import("firebase/app"),
|
|
67
|
+
import("firebase/auth")
|
|
68
|
+
]);
|
|
69
|
+
firebaseApp = { initializeApp, getApps };
|
|
70
|
+
firebaseAuth = {
|
|
71
|
+
getAuth,
|
|
72
|
+
signInWithEmailAndPassword,
|
|
73
|
+
createUserWithEmailAndPassword,
|
|
74
|
+
signInWithPopup,
|
|
75
|
+
GoogleAuthProvider,
|
|
76
|
+
signOut: signOut2,
|
|
77
|
+
sendPasswordResetEmail,
|
|
78
|
+
sendEmailVerification,
|
|
79
|
+
updatePassword,
|
|
80
|
+
onAuthStateChanged
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return { firebaseApp, firebaseAuth };
|
|
84
|
+
};
|
|
85
|
+
FirebaseAuthService = class {
|
|
86
|
+
constructor(config) {
|
|
87
|
+
__publicField(this, "app");
|
|
88
|
+
__publicField(this, "auth");
|
|
89
|
+
__publicField(this, "googleProvider");
|
|
90
|
+
__publicField(this, "config");
|
|
91
|
+
__publicField(this, "initialized", false);
|
|
92
|
+
this.config = config;
|
|
93
|
+
}
|
|
94
|
+
async ensureInitialized() {
|
|
95
|
+
if (this.initialized) return;
|
|
96
|
+
const { firebaseApp: firebaseApp2, firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
97
|
+
if (!firebaseApp2.getApps().length) {
|
|
98
|
+
this.app = firebaseApp2.initializeApp(this.config);
|
|
99
|
+
} else {
|
|
100
|
+
this.app = firebaseApp2.getApps()[0];
|
|
101
|
+
}
|
|
102
|
+
this.auth = firebaseAuth2.getAuth(this.app);
|
|
103
|
+
this.googleProvider = new firebaseAuth2.GoogleAuthProvider();
|
|
104
|
+
this.initialized = true;
|
|
105
|
+
}
|
|
106
|
+
transformUserData(user) {
|
|
107
|
+
return {
|
|
108
|
+
id: user.uid,
|
|
109
|
+
uid: user.uid,
|
|
110
|
+
userName: user.displayName || "",
|
|
111
|
+
displayName: user.displayName || "",
|
|
112
|
+
email: user.email || "",
|
|
113
|
+
refreshToken: user.refreshToken,
|
|
114
|
+
accessToken: user.accessToken || "",
|
|
115
|
+
exp: user.stsTokenManager?.expirationTime || 0,
|
|
116
|
+
emailVerified: user.emailVerified,
|
|
117
|
+
avatar: user.photoURL || "/images/default-avatar.jpg",
|
|
118
|
+
signInProvider: this.getSignInProvider(user),
|
|
119
|
+
role: void 0,
|
|
120
|
+
scanStatus: false
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
getSignInProvider(user) {
|
|
124
|
+
const providers = user.providerData.map((p) => p.providerId);
|
|
125
|
+
if (providers.includes("google.com")) return "google.com";
|
|
126
|
+
return "password";
|
|
127
|
+
}
|
|
128
|
+
translateErrorCode(errorCode) {
|
|
129
|
+
switch (errorCode) {
|
|
130
|
+
case "auth/invalid-email":
|
|
131
|
+
return "Email kh\xF4ng h\u1EE3p l\u1EC7";
|
|
132
|
+
case "auth/user-disabled":
|
|
133
|
+
return "T\xE0i kho\u1EA3n \u0111\xE3 b\u1ECB kh\xF3a";
|
|
134
|
+
case "auth/wrong-password":
|
|
135
|
+
return "T\xE0i kho\u1EA3n/m\u1EADt kh\u1EA9u kh\xF4ng \u0111\xFAng";
|
|
136
|
+
case "auth/user-not-found":
|
|
137
|
+
return "T\xE0i kho\u1EA3n/m\u1EADt kh\u1EA9u kh\xF4ng \u0111\xFAng";
|
|
138
|
+
case "auth/weak-password":
|
|
139
|
+
return "Weak password! Please use stronger password.";
|
|
140
|
+
case "auth/email-already-in-use":
|
|
141
|
+
return "Email \u0111\xE3 \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng";
|
|
142
|
+
case "auth/account-exists-with-different-credential":
|
|
143
|
+
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";
|
|
144
|
+
case "auth/email-not-verified":
|
|
145
|
+
return "Email ch\u01B0a \u0111\u01B0\u1EE3c x\xE1c th\u1EF1c";
|
|
146
|
+
default:
|
|
147
|
+
return "\u0110\xE3 c\xF3 l\u1ED7i x\u1EA3y ra";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async signInWithEmailAndPassword(email, password) {
|
|
151
|
+
try {
|
|
152
|
+
await this.ensureInitialized();
|
|
153
|
+
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
154
|
+
const signInResponse = await firebaseAuth2.signInWithEmailAndPassword(this.auth, email, password);
|
|
155
|
+
const { user } = signInResponse;
|
|
156
|
+
const data = this.transformUserData(user);
|
|
157
|
+
const { emailVerified } = data;
|
|
158
|
+
if (!emailVerified) {
|
|
159
|
+
await this.signOut();
|
|
160
|
+
localStorage.removeItem("phygital-user-info");
|
|
161
|
+
localStorage.removeItem(accessTokenKey);
|
|
162
|
+
localStorage.removeItem(refreshTokenKey);
|
|
163
|
+
throw new Error("Email is not verified");
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
errorCode: "",
|
|
167
|
+
data
|
|
168
|
+
};
|
|
169
|
+
} catch (err) {
|
|
170
|
+
const errorCode = this.translateErrorCode(err.code);
|
|
171
|
+
return {
|
|
172
|
+
errorCode,
|
|
173
|
+
data: null
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async signInWithGoogle() {
|
|
178
|
+
try {
|
|
179
|
+
await this.ensureInitialized();
|
|
180
|
+
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
181
|
+
const signInResponse = await firebaseAuth2.signInWithPopup(this.auth, this.googleProvider);
|
|
182
|
+
const { user } = signInResponse;
|
|
183
|
+
const data = this.transformUserData(user);
|
|
184
|
+
const { emailVerified } = data;
|
|
185
|
+
if (!emailVerified) {
|
|
186
|
+
await this.signOut();
|
|
187
|
+
throw new Error("Email is not verified");
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
errorCode: "",
|
|
191
|
+
data
|
|
192
|
+
};
|
|
193
|
+
} catch (err) {
|
|
194
|
+
const errorCode = this.translateErrorCode(err.code);
|
|
195
|
+
return {
|
|
196
|
+
errorCode,
|
|
197
|
+
data: null
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async signUp(email, password) {
|
|
202
|
+
try {
|
|
203
|
+
await this.ensureInitialized();
|
|
204
|
+
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
205
|
+
const signUpResponse = await firebaseAuth2.createUserWithEmailAndPassword(this.auth, email, password);
|
|
206
|
+
const { user } = signUpResponse;
|
|
207
|
+
const data = this.transformUserData(user);
|
|
208
|
+
return {
|
|
209
|
+
errorCode: "",
|
|
210
|
+
data
|
|
211
|
+
};
|
|
212
|
+
} catch (err) {
|
|
213
|
+
const errorCode = this.translateErrorCode(err.code);
|
|
214
|
+
return {
|
|
215
|
+
errorCode,
|
|
216
|
+
data: null
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async signOut() {
|
|
221
|
+
try {
|
|
222
|
+
await this.ensureInitialized();
|
|
223
|
+
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
224
|
+
await firebaseAuth2.signOut(this.auth);
|
|
225
|
+
} catch (err) {
|
|
226
|
+
console.log("Firebase signOut error:", err);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
async sendPasswordResetEmail(email) {
|
|
230
|
+
await this.ensureInitialized();
|
|
231
|
+
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
232
|
+
const actionCodeSettings = {
|
|
233
|
+
url: window.location.origin,
|
|
234
|
+
handleCodeInApp: true
|
|
235
|
+
};
|
|
236
|
+
await firebaseAuth2.sendPasswordResetEmail(this.auth, email, actionCodeSettings);
|
|
237
|
+
}
|
|
238
|
+
async sendEmailVerification() {
|
|
239
|
+
await this.ensureInitialized();
|
|
240
|
+
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
241
|
+
if (!this.auth.currentUser) {
|
|
242
|
+
throw new Error("No current user");
|
|
243
|
+
}
|
|
244
|
+
const actionCodeSettings = {
|
|
245
|
+
url: window.location.origin,
|
|
246
|
+
handleCodeInApp: true
|
|
247
|
+
};
|
|
248
|
+
await firebaseAuth2.sendEmailVerification(this.auth.currentUser, actionCodeSettings);
|
|
249
|
+
}
|
|
250
|
+
async changePassword(newPassword) {
|
|
251
|
+
await this.ensureInitialized();
|
|
252
|
+
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
253
|
+
const user = this.auth.currentUser;
|
|
254
|
+
if (!user) {
|
|
255
|
+
throw new Error("No current user");
|
|
256
|
+
}
|
|
257
|
+
return firebaseAuth2.updatePassword(user, newPassword);
|
|
258
|
+
}
|
|
259
|
+
onAuthStateChanged(callback) {
|
|
260
|
+
if (typeof window === "undefined") {
|
|
261
|
+
return () => {
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
let unsubscriber = null;
|
|
265
|
+
this.ensureInitialized().then(async () => {
|
|
266
|
+
const { firebaseAuth: firebaseAuth2 } = await getFirebaseModules();
|
|
267
|
+
unsubscriber = firebaseAuth2.onAuthStateChanged(this.auth, (user) => {
|
|
268
|
+
if (user && user.emailVerified) {
|
|
269
|
+
const userData = this.transformUserData(user);
|
|
270
|
+
callback(userData);
|
|
271
|
+
} else {
|
|
272
|
+
callback(null);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
return () => {
|
|
277
|
+
if (unsubscriber) {
|
|
278
|
+
unsubscriber();
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
getCurrentUser() {
|
|
283
|
+
if (typeof window === "undefined" || !this.initialized) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
const user = this.auth.currentUser;
|
|
287
|
+
if (user && user.emailVerified) {
|
|
288
|
+
return this.transformUserData(user);
|
|
289
|
+
}
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// src/modules/auth/services/authServiceFactory.ts
|
|
297
|
+
var authServiceInstance, createAuthService, getAuthService, resetAuthService;
|
|
298
|
+
var init_authServiceFactory = __esm({
|
|
299
|
+
"src/modules/auth/services/authServiceFactory.ts"() {
|
|
300
|
+
"use strict";
|
|
301
|
+
init_FirebaseAuthService();
|
|
302
|
+
authServiceInstance = null;
|
|
303
|
+
createAuthService = (config) => {
|
|
304
|
+
if (!authServiceInstance) {
|
|
305
|
+
authServiceInstance = new FirebaseAuthService(config.firebaseConfig);
|
|
306
|
+
}
|
|
307
|
+
return authServiceInstance;
|
|
308
|
+
};
|
|
309
|
+
getAuthService = () => {
|
|
310
|
+
return authServiceInstance;
|
|
311
|
+
};
|
|
312
|
+
resetAuthService = () => {
|
|
313
|
+
authServiceInstance = null;
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
// src/modules/auth/services/index.ts
|
|
319
|
+
var services_exports = {};
|
|
320
|
+
__export(services_exports, {
|
|
321
|
+
FirebaseAuthService: () => FirebaseAuthService,
|
|
322
|
+
createAuthService: () => createAuthService,
|
|
323
|
+
getAuthService: () => getAuthService,
|
|
324
|
+
resetAuthService: () => resetAuthService
|
|
325
|
+
});
|
|
326
|
+
var init_services = __esm({
|
|
327
|
+
"src/modules/auth/services/index.ts"() {
|
|
328
|
+
"use strict";
|
|
329
|
+
init_FirebaseAuthService();
|
|
330
|
+
init_authServiceFactory();
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// src/index.ts
|
|
335
|
+
var index_exports = {};
|
|
336
|
+
__export(index_exports, {
|
|
337
|
+
AchievementRuleActionType: () => AchievementRuleActionType,
|
|
338
|
+
AchievementServiceProvider: () => AchievementServiceProvider,
|
|
339
|
+
AchievementType: () => AchievementType,
|
|
340
|
+
AuthProvider: () => AuthProvider,
|
|
341
|
+
CampaignState: () => CampaignState,
|
|
342
|
+
CmentityRewardType: () => CmentityRewardType,
|
|
343
|
+
NotificationProvider: () => NotificationProvider,
|
|
344
|
+
RewardClaimStatus: () => RewardClaimStatus,
|
|
345
|
+
TapquestCoreProvider: () => TapquestCoreProvider,
|
|
346
|
+
TaskType: () => TaskType,
|
|
347
|
+
UserSourceType: () => UserSourceType,
|
|
348
|
+
accessTokenKey: () => accessTokenKey,
|
|
349
|
+
checkDeviceUid: () => checkDeviceUid,
|
|
350
|
+
chipAuthTokenKey: () => chipAuthTokenKey,
|
|
351
|
+
cn: () => cn,
|
|
352
|
+
convertSnakeToCamel: () => convertSnakeToCamel,
|
|
353
|
+
createRefreshTokenFunction: () => createRefreshTokenFunction,
|
|
354
|
+
deviceUIDKey: () => deviceUIDKey,
|
|
355
|
+
fileToBase64: () => fileToBase64,
|
|
356
|
+
filterLocationsByProperty: () => filterLocationsByProperty,
|
|
357
|
+
generateDeviceId: () => generateDeviceId,
|
|
358
|
+
getAccessToken: () => getAccessToken,
|
|
359
|
+
getActionsFromAchievementRule: () => getActionsFromAchievementRule,
|
|
360
|
+
getChipAuthToken: () => getChipAuthToken,
|
|
361
|
+
getDeviceUid: () => getDeviceUid,
|
|
362
|
+
getLocationIdsFromAchievementRule: () => getLocationIdsFromAchievementRule,
|
|
363
|
+
getRefreshToken: () => getRefreshToken,
|
|
364
|
+
getRetryAttemptsRefreshToken: () => getRetryAttemptsRefreshToken,
|
|
365
|
+
getUserInfo: () => getUserInfo,
|
|
366
|
+
httpMaxRetries: () => httpMaxRetries,
|
|
367
|
+
isAchievementCompleted: () => isAchievementCompleted,
|
|
368
|
+
locationQueryKeys: () => locationQueryKeys,
|
|
369
|
+
memoriesKey: () => memoriesKey,
|
|
370
|
+
parse: () => parse,
|
|
371
|
+
refreshTokenKey: () => refreshTokenKey,
|
|
372
|
+
removeAccessToken: () => removeAccessToken,
|
|
373
|
+
removeChipAuthToken: () => removeChipAuthToken,
|
|
374
|
+
removeDeviceUid: () => removeDeviceUid,
|
|
375
|
+
removeRefreshToken: () => removeRefreshToken,
|
|
376
|
+
removeUserInfo: () => removeUserInfo,
|
|
377
|
+
resetMemoriesQuery: () => resetMemoriesQuery,
|
|
378
|
+
retryAttemptsRefreshToken: () => retryAttemptsRefreshToken,
|
|
379
|
+
setAccessToken: () => setAccessToken,
|
|
380
|
+
setChipAuthToken: () => setChipAuthToken,
|
|
381
|
+
setDeviceUid: () => setDeviceUid,
|
|
382
|
+
setRefreshToken: () => setRefreshToken,
|
|
383
|
+
setRetryAttemptsRefreshToken: () => setRetryAttemptsRefreshToken,
|
|
384
|
+
setUserInfo: () => setUserInfo,
|
|
385
|
+
sortLocationsByIndex: () => sortLocationsByIndex,
|
|
386
|
+
useAchievementProgress: () => useAchievementProgress,
|
|
387
|
+
useAchivementPlusRewardModel: () => achivementPlusRewardModel_default,
|
|
388
|
+
useAuth: () => useAuth,
|
|
389
|
+
useCampaignDetail: () => useOneCampaign,
|
|
390
|
+
useCancelUserRewardsRequest: () => useCancelUserRewardsRequest,
|
|
391
|
+
useChipScanStory: () => useChipScanStory,
|
|
392
|
+
useClaimUserReward: () => useClaimUserReward,
|
|
393
|
+
useClearUserRewardCache: () => useClearUserRewardCache,
|
|
394
|
+
useCreateMemory: () => useCreateMemory,
|
|
395
|
+
useCreateModelGroupReward: () => useCreateModelGroupReward,
|
|
396
|
+
useCreateRewardModel: () => useApiCreateRewardModel,
|
|
397
|
+
useDataTracking: () => useDataTracking,
|
|
398
|
+
useDeleteRewardModel: () => useApiDeleteRewardModel,
|
|
399
|
+
useGenerateFansipanCertificate: () => useGenerateFansipanCertificate,
|
|
400
|
+
useGenerateTemplateCertificate: () => useGenerateTemplateCertificate,
|
|
401
|
+
useGenerateThaocamvienCertificate: () => useGenerateThaocamvienCertificate,
|
|
402
|
+
useGetRewardModel: () => useApiGetRewardModel,
|
|
403
|
+
useGetUserRewards: () => useGetUserRewards,
|
|
404
|
+
useInfiniteMemories: () => useInfiniteMemories,
|
|
405
|
+
useListRewardModels: () => useApiListRewardModels,
|
|
406
|
+
useLocationDetail: () => useOneLocation,
|
|
407
|
+
useLocationProgress: () => useUserCampaignsCompletedLocation,
|
|
408
|
+
useLocationsList: () => useManyLocations,
|
|
409
|
+
useManyAchievementProgress: () => useManyAchievementProgress,
|
|
410
|
+
useManyAchievements: () => useManyAchievements,
|
|
411
|
+
useManyAchievementsRewardModels: () => useManyAchievementsRewardModels,
|
|
412
|
+
useManyChildrenAchievements: () => useManyChildrenAchievements,
|
|
413
|
+
useManyMemory: () => useManyMemory,
|
|
414
|
+
useManyUserActionLocations: () => useManyUserActionLocations,
|
|
415
|
+
useManyUserRewards: () => useManyUserRewards,
|
|
416
|
+
useMyProfile: () => useMyProfile,
|
|
417
|
+
useOneAchievement: () => useOneAchievement,
|
|
418
|
+
useOneMemory: () => useOneMemory,
|
|
419
|
+
useOneUserCampaign: () => useOneUserCampaign,
|
|
420
|
+
usePGLCoreService: () => usePGLCoreService,
|
|
421
|
+
useScanChip: () => useScanChip,
|
|
422
|
+
useSendEmail: () => useSendEmail,
|
|
423
|
+
useSyncCheckin: () => useSyncCheckin,
|
|
424
|
+
useUpdateMyProfile: () => useUpdateMyProfile,
|
|
425
|
+
useUpdateRewardModel: () => useApiUpdateRewardModel,
|
|
426
|
+
useUploadMedia: () => useUploadMedia,
|
|
427
|
+
useUserAchievementAction: () => useUserAchievementAction,
|
|
428
|
+
useUserCampaignAction: () => useUserCampaignAction,
|
|
429
|
+
useV1ListRewards: () => useV1ListRewards,
|
|
430
|
+
userInfoKey: () => userInfoKey
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// src/modules/achievement/hooks/index.ts
|
|
434
|
+
import { useManyAchievementProgress as useManyAchievementProgressCore } from "@phygitallabs/achievement";
|
|
435
|
+
import { useManyAchievementProgressByDevice as useManyAchievementProgressByDeviceCore } from "@phygitallabs/api-core";
|
|
436
|
+
import {
|
|
437
|
+
useAchievementProgress,
|
|
438
|
+
useManyAchievements,
|
|
439
|
+
useUserAchievementAction,
|
|
440
|
+
useManyChildrenAchievements,
|
|
441
|
+
useOneAchievement,
|
|
442
|
+
useManyAchievementsRewardModels
|
|
443
|
+
} from "@phygitallabs/achievement";
|
|
444
|
+
|
|
445
|
+
// src/modules/achievement/helpers/index.ts
|
|
446
|
+
var getLocationIdsFromAchievementRule = (achievement) => {
|
|
447
|
+
if (!achievement.rule) return [];
|
|
448
|
+
const locationIds = [];
|
|
449
|
+
Object.values(achievement.rule).forEach((ruleList) => {
|
|
450
|
+
if (!ruleList.rules) return;
|
|
451
|
+
ruleList.rules.forEach((rule) => {
|
|
452
|
+
if (!rule.filter) return;
|
|
453
|
+
Object.values(rule.filter).forEach((filterList) => {
|
|
454
|
+
if (!filterList.filters) return;
|
|
455
|
+
filterList.filters.forEach((filter) => {
|
|
456
|
+
if (filter.label === "location_id" && filter.value) {
|
|
457
|
+
if (Array.isArray(filter.value)) {
|
|
458
|
+
locationIds.push(...filter.value);
|
|
459
|
+
} else {
|
|
460
|
+
locationIds.push(filter.value);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
return Array.from(new Set(locationIds));
|
|
468
|
+
};
|
|
469
|
+
var getActionsFromAchievementRule = (achievement) => {
|
|
470
|
+
if (!achievement.rule) return [];
|
|
471
|
+
const actions = [];
|
|
472
|
+
Object.values(achievement.rule).forEach((ruleList) => {
|
|
473
|
+
if (!ruleList.rules) return;
|
|
474
|
+
ruleList.rules.forEach((rule) => {
|
|
475
|
+
if (rule.action) {
|
|
476
|
+
actions.push(rule.action);
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
return Array.from(new Set(actions));
|
|
481
|
+
};
|
|
482
|
+
var isAchievementCompleted = (achievement) => {
|
|
483
|
+
return achievement.isCompleted || achievement.overallPercentage === 100;
|
|
484
|
+
};
|
|
485
|
+
function convertSnakeToCamel(obj) {
|
|
486
|
+
if (obj === null || obj === void 0) {
|
|
487
|
+
return obj;
|
|
488
|
+
}
|
|
489
|
+
if (Array.isArray(obj)) {
|
|
490
|
+
return obj.map(
|
|
491
|
+
(item) => convertSnakeToCamel(item)
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
if (typeof obj === "object" && obj.constructor === Object) {
|
|
495
|
+
const converted = {};
|
|
496
|
+
for (const key in obj) {
|
|
497
|
+
if (obj.hasOwnProperty(key)) {
|
|
498
|
+
const camelKey = key.replace(
|
|
499
|
+
/_([a-z])/g,
|
|
500
|
+
(_, letter) => letter.toUpperCase()
|
|
501
|
+
);
|
|
502
|
+
converted[camelKey] = convertSnakeToCamel(
|
|
503
|
+
obj[key]
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
return converted;
|
|
508
|
+
}
|
|
509
|
+
return obj;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// src/modules/achievement/hooks/index.ts
|
|
513
|
+
var useManyAchievementProgress = (params, options) => {
|
|
514
|
+
const isLoggedIn = !!params.userId;
|
|
515
|
+
const queryParams = isLoggedIn ? {
|
|
516
|
+
achievementIds: params.achievementIds,
|
|
517
|
+
userId: params.userId,
|
|
518
|
+
applicationId: params.applicationId
|
|
519
|
+
} : {
|
|
520
|
+
achievement_ids: params.achievementIds,
|
|
521
|
+
device_uid: params.deviceUid,
|
|
522
|
+
applicationId: params.applicationId
|
|
523
|
+
};
|
|
524
|
+
if (isLoggedIn) {
|
|
525
|
+
return useManyAchievementProgressCore(
|
|
526
|
+
queryParams,
|
|
527
|
+
{
|
|
528
|
+
...options,
|
|
529
|
+
select: (data) => data.map((item) => ({
|
|
530
|
+
...item,
|
|
531
|
+
isCompleted: isAchievementCompleted(item)
|
|
532
|
+
}))
|
|
533
|
+
}
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
return useManyAchievementProgressByDeviceCore(
|
|
537
|
+
queryParams,
|
|
538
|
+
{
|
|
539
|
+
...options,
|
|
540
|
+
select: (data) => {
|
|
541
|
+
const camelCaseData = convertSnakeToCamel(data);
|
|
542
|
+
return camelCaseData.map((item) => ({
|
|
543
|
+
...item,
|
|
544
|
+
isCompleted: isAchievementCompleted(item)
|
|
545
|
+
}));
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
);
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
// src/modules/achievement/types/index.ts
|
|
552
|
+
import {
|
|
553
|
+
AchievementRuleActionType,
|
|
554
|
+
AchievementServiceProvider
|
|
555
|
+
} from "@phygitallabs/achievement";
|
|
556
|
+
var AchievementType = /* @__PURE__ */ ((AchievementType2) => {
|
|
557
|
+
AchievementType2["DEFAULT"] = "default";
|
|
558
|
+
AchievementType2["MULTIPLE_CHECK_INS"] = "multiple_check_ins";
|
|
559
|
+
AchievementType2["RANDOM_CHECK_INS"] = "random_check_ins";
|
|
560
|
+
AchievementType2["GROUP_MISSION"] = "group_mission";
|
|
561
|
+
return AchievementType2;
|
|
562
|
+
})(AchievementType || {});
|
|
563
|
+
|
|
564
|
+
// src/modules/reward/hooks/useRewardService.ts
|
|
565
|
+
import {
|
|
566
|
+
useManyUserRewards,
|
|
567
|
+
useGetUserRewards,
|
|
568
|
+
useClaimUserReward,
|
|
569
|
+
useApiListRewardModels,
|
|
570
|
+
useApiGetRewardModel,
|
|
571
|
+
useApiCreateRewardModel,
|
|
572
|
+
useApiUpdateRewardModel,
|
|
573
|
+
useApiDeleteRewardModel,
|
|
574
|
+
useCreateModelGroupReward,
|
|
575
|
+
useClearUserRewardCache,
|
|
576
|
+
useV1ListRewards
|
|
577
|
+
} from "@phygitallabs/reward/src/hooks";
|
|
578
|
+
|
|
579
|
+
// src/modules/reward/types/enums.ts
|
|
580
|
+
import {
|
|
581
|
+
CmentityRewardType
|
|
582
|
+
} from "@phygitallabs/reward";
|
|
583
|
+
var RewardClaimStatus = /* @__PURE__ */ ((RewardClaimStatus2) => {
|
|
584
|
+
RewardClaimStatus2["NOT_CLAIMED"] = "not_claimed";
|
|
585
|
+
RewardClaimStatus2["CLAIMED"] = "claimed";
|
|
586
|
+
RewardClaimStatus2["IN_PROGRESS"] = "in_progress";
|
|
587
|
+
RewardClaimStatus2["FAILED"] = "failed";
|
|
588
|
+
return RewardClaimStatus2;
|
|
589
|
+
})(RewardClaimStatus || {});
|
|
590
|
+
|
|
591
|
+
// src/modules/notification/index.ts
|
|
592
|
+
var notification_exports = {};
|
|
593
|
+
__export(notification_exports, {
|
|
594
|
+
NotificationProvider: () => NotificationProvider
|
|
595
|
+
});
|
|
596
|
+
__reExport(notification_exports, notification_api_star);
|
|
597
|
+
import * as notification_api_star from "@phygitallabs/notification-api";
|
|
598
|
+
|
|
599
|
+
// src/modules/notification/providers/index.tsx
|
|
600
|
+
import { NotificationProvider as NotificationProviderApi } from "@phygitallabs/notification-api";
|
|
601
|
+
|
|
602
|
+
// src/constants/service.ts
|
|
603
|
+
var serviceApiUrl = {
|
|
604
|
+
dev: {
|
|
605
|
+
API_BASE_URL: "https://backend-dev.nomion.io",
|
|
606
|
+
API_BASE_CORE_URL: "https://backend-dev.nomion.io/core",
|
|
607
|
+
API_ACHIEVEMENT_URL: "https://backend-dev.nomion.io/achievement",
|
|
608
|
+
API_REWARD_URL: "https://backend-dev.nomion.io/reward",
|
|
609
|
+
API_GENERATE_CERTIFICATE_URL: "https://media-prc-dev.nomion.io/api",
|
|
610
|
+
API_NOTIFICATION_SOCKET_URL: "https://backend-dev.nomion.io/notification-ws/ws"
|
|
611
|
+
},
|
|
612
|
+
staging: {
|
|
613
|
+
API_BASE_URL: "https://backend-staging.nomion.io",
|
|
614
|
+
API_BASE_CORE_URL: "https://backend-staging.nomion.io/core",
|
|
615
|
+
API_ACHIEVEMENT_URL: "https://backend-staging.nomion.io/achievement",
|
|
616
|
+
API_REWARD_URL: "https://backend-staging.nomion.io/reward",
|
|
617
|
+
API_GENERATE_CERTIFICATE_URL: "https://media-prc-staging.nomion.io/api",
|
|
618
|
+
API_NOTIFICATION_SOCKET_URL: "https://backend-staging.nomion.io/notification-ws/ws"
|
|
619
|
+
},
|
|
620
|
+
production: {
|
|
621
|
+
API_BASE_URL: "https://backend.nomion.io",
|
|
622
|
+
API_BASE_CORE_URL: "https://backend.nomion.io/core",
|
|
623
|
+
API_ACHIEVEMENT_URL: "https://backend.nomion.io/achievement",
|
|
624
|
+
API_REWARD_URL: "https://backend.nomion.io/reward",
|
|
625
|
+
API_GENERATE_CERTIFICATE_URL: "https://media-prc.nomion.io/api",
|
|
626
|
+
API_NOTIFICATION_SOCKET_URL: "https://backend.nomion.io/notification-ws/ws"
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
var service_default = serviceApiUrl;
|
|
630
|
+
|
|
631
|
+
// src/modules/notification/providers/index.tsx
|
|
632
|
+
import { jsx } from "react/jsx-runtime";
|
|
633
|
+
var NotificationProvider = ({
|
|
634
|
+
children,
|
|
635
|
+
autoConnect = true,
|
|
636
|
+
environment = "dev",
|
|
637
|
+
user,
|
|
638
|
+
onWebSocketOpen,
|
|
639
|
+
onWebSocketClose,
|
|
640
|
+
onWebSocketMessage
|
|
641
|
+
}) => {
|
|
642
|
+
const webSocketUrl = service_default[environment]?.API_NOTIFICATION_SOCKET_URL;
|
|
643
|
+
return /* @__PURE__ */ jsx(
|
|
644
|
+
NotificationProviderApi,
|
|
645
|
+
{
|
|
646
|
+
userUid: user.id,
|
|
647
|
+
accessToken: user.accessToken,
|
|
648
|
+
webSocketUrl,
|
|
649
|
+
autoConnect,
|
|
650
|
+
onWebSocketOpen,
|
|
651
|
+
onWebSocketClose,
|
|
652
|
+
onWebSocketMessage,
|
|
653
|
+
children
|
|
654
|
+
}
|
|
655
|
+
);
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
// src/index.ts
|
|
659
|
+
__reExport(index_exports, notification_exports);
|
|
660
|
+
|
|
661
|
+
// src/modules/memory/hooks/index.ts
|
|
662
|
+
import { useOneMemory, useManyMemory, useInfiniteMemories, useCreateMemory, useUploadMedia, resetMemoriesQuery, memoriesKey } from "@phygitallabs/api-core";
|
|
663
|
+
|
|
664
|
+
// src/modules/auth/providers/AuthProvider.tsx
|
|
665
|
+
import { createContext, useEffect, useContext } from "react";
|
|
666
|
+
|
|
667
|
+
// src/store/hooks.ts
|
|
668
|
+
import { useDispatch, useSelector } from "react-redux";
|
|
669
|
+
var useAppDispatch = () => useDispatch();
|
|
670
|
+
var useAppSelector = useSelector;
|
|
671
|
+
|
|
672
|
+
// src/modules/auth/store/authSlice.ts
|
|
673
|
+
import { createSlice } from "@reduxjs/toolkit";
|
|
674
|
+
|
|
675
|
+
// src/modules/auth/helpers/index.ts
|
|
676
|
+
init_constants();
|
|
677
|
+
import { v4 as uuidv4 } from "uuid";
|
|
678
|
+
|
|
679
|
+
// src/modules/auth/helpers/refreshToken.ts
|
|
680
|
+
import mem from "mem";
|
|
681
|
+
var REFRESH_TOKEN_CONFIG = {
|
|
682
|
+
maxAge: 1e4
|
|
683
|
+
// 10 seconds cache
|
|
684
|
+
};
|
|
685
|
+
var createRefreshTokenFunction = (config) => {
|
|
686
|
+
const refreshTokenFn = async () => {
|
|
687
|
+
try {
|
|
688
|
+
const session = getUserInfo();
|
|
689
|
+
const refreshToken = getRefreshToken();
|
|
690
|
+
if (!refreshToken) {
|
|
691
|
+
removeUserInfo();
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
const params = new URLSearchParams();
|
|
695
|
+
params.append("grant_type", "refresh_token");
|
|
696
|
+
params.append("refresh_token", refreshToken);
|
|
697
|
+
const fetchData = {
|
|
698
|
+
method: "POST",
|
|
699
|
+
headers: new Headers({
|
|
700
|
+
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
|
|
701
|
+
}),
|
|
702
|
+
body: params
|
|
703
|
+
};
|
|
704
|
+
const response = await fetch(
|
|
705
|
+
`https://securetoken.googleapis.com/v1/token?key=${config.firebaseApiKey}`,
|
|
706
|
+
fetchData
|
|
707
|
+
);
|
|
708
|
+
const data = await response.json();
|
|
709
|
+
if (data.error) {
|
|
710
|
+
removeUserInfo();
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
const newSession = {
|
|
714
|
+
...session,
|
|
715
|
+
accessToken: data.access_token,
|
|
716
|
+
refreshToken: data.refresh_token
|
|
717
|
+
};
|
|
718
|
+
setUserInfo(newSession);
|
|
719
|
+
return newSession;
|
|
720
|
+
} catch {
|
|
721
|
+
removeUserInfo();
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
return mem(refreshTokenFn, { maxAge: REFRESH_TOKEN_CONFIG.maxAge });
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
// src/modules/auth/helpers/index.ts
|
|
728
|
+
var generateDeviceId = async () => {
|
|
729
|
+
try {
|
|
730
|
+
const deviceFingerprint = await generateDeviceFingerprint();
|
|
731
|
+
return deviceFingerprint;
|
|
732
|
+
} catch (error) {
|
|
733
|
+
console.error("Error generating device fingerprint:", error);
|
|
734
|
+
return uuidv4();
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
var generateDeviceFingerprint = async () => {
|
|
738
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
739
|
+
const fingerprintRaw = [
|
|
740
|
+
navigator.userAgent,
|
|
741
|
+
navigator.language,
|
|
742
|
+
screen.width,
|
|
743
|
+
screen.height,
|
|
744
|
+
screen.colorDepth,
|
|
745
|
+
Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
746
|
+
navigator.platform,
|
|
747
|
+
navigator.hardwareConcurrency,
|
|
748
|
+
timestamp
|
|
749
|
+
// Include timestamp
|
|
750
|
+
].join("::");
|
|
751
|
+
const encoder = new TextEncoder();
|
|
752
|
+
const data = encoder.encode(fingerprintRaw);
|
|
753
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
754
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
755
|
+
const fingerprint = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
756
|
+
return fingerprint;
|
|
757
|
+
};
|
|
758
|
+
var getDeviceUid = () => {
|
|
759
|
+
if (typeof window === "undefined") return null;
|
|
760
|
+
return localStorage.getItem(deviceUIDKey);
|
|
761
|
+
};
|
|
762
|
+
var setDeviceUid = (deviceId) => {
|
|
763
|
+
if (typeof window === "undefined") return;
|
|
764
|
+
localStorage.setItem(deviceUIDKey, deviceId);
|
|
765
|
+
};
|
|
766
|
+
var removeDeviceUid = () => {
|
|
767
|
+
if (typeof window === "undefined") return;
|
|
768
|
+
localStorage.removeItem(deviceUIDKey);
|
|
769
|
+
};
|
|
770
|
+
var checkDeviceUid = async () => {
|
|
771
|
+
let deviceUID = getDeviceUid();
|
|
772
|
+
if (!deviceUID) {
|
|
773
|
+
deviceUID = await generateDeviceId();
|
|
774
|
+
setDeviceUid(deviceUID);
|
|
775
|
+
}
|
|
776
|
+
return deviceUID;
|
|
777
|
+
};
|
|
778
|
+
var getChipAuthToken = () => {
|
|
779
|
+
if (typeof window === "undefined") return null;
|
|
780
|
+
return localStorage.getItem(chipAuthTokenKey);
|
|
781
|
+
};
|
|
782
|
+
var setChipAuthToken = (value) => {
|
|
783
|
+
if (typeof window === "undefined") return;
|
|
784
|
+
localStorage.setItem(chipAuthTokenKey, value);
|
|
785
|
+
};
|
|
786
|
+
var removeChipAuthToken = () => {
|
|
787
|
+
if (typeof window === "undefined") return;
|
|
788
|
+
localStorage.removeItem(chipAuthTokenKey);
|
|
789
|
+
};
|
|
790
|
+
var getRetryAttemptsRefreshToken = () => {
|
|
791
|
+
if (typeof window === "undefined") return null;
|
|
792
|
+
return localStorage.getItem(retryAttemptsRefreshToken);
|
|
793
|
+
};
|
|
794
|
+
var setRetryAttemptsRefreshToken = (value) => {
|
|
795
|
+
if (typeof window === "undefined") return;
|
|
796
|
+
localStorage.setItem(retryAttemptsRefreshToken, value);
|
|
797
|
+
};
|
|
798
|
+
var getAccessToken = () => {
|
|
799
|
+
if (typeof window === "undefined") return null;
|
|
800
|
+
return localStorage.getItem(accessTokenKey);
|
|
801
|
+
};
|
|
802
|
+
var setAccessToken = (value) => {
|
|
803
|
+
if (typeof window === "undefined") return;
|
|
804
|
+
localStorage.setItem(accessTokenKey, value);
|
|
805
|
+
};
|
|
806
|
+
var removeAccessToken = () => {
|
|
807
|
+
if (typeof window === "undefined") return;
|
|
808
|
+
localStorage.removeItem(accessTokenKey);
|
|
809
|
+
};
|
|
810
|
+
var getRefreshToken = () => {
|
|
811
|
+
if (typeof window === "undefined") return null;
|
|
812
|
+
return localStorage.getItem(refreshTokenKey);
|
|
813
|
+
};
|
|
814
|
+
var setRefreshToken = (value) => {
|
|
815
|
+
if (typeof window === "undefined") return;
|
|
816
|
+
localStorage.setItem(refreshTokenKey, value);
|
|
817
|
+
};
|
|
818
|
+
var removeRefreshToken = () => {
|
|
819
|
+
if (typeof window === "undefined") return;
|
|
820
|
+
localStorage.removeItem(refreshTokenKey);
|
|
821
|
+
};
|
|
822
|
+
var getUserInfo = () => {
|
|
823
|
+
if (typeof window === "undefined") return null;
|
|
824
|
+
const userInfo = localStorage.getItem(userInfoKey);
|
|
825
|
+
if (!userInfo) return null;
|
|
826
|
+
try {
|
|
827
|
+
return JSON.parse(userInfo);
|
|
828
|
+
} catch (error) {
|
|
829
|
+
console.error("Failed to parse stored user data:", error);
|
|
830
|
+
return null;
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
var setUserInfo = (userData) => {
|
|
834
|
+
if (typeof window === "undefined") return;
|
|
835
|
+
localStorage.setItem(userInfoKey, JSON.stringify(userData));
|
|
836
|
+
};
|
|
837
|
+
var removeUserInfo = () => {
|
|
838
|
+
if (typeof window === "undefined") return;
|
|
839
|
+
localStorage.removeItem(userInfoKey);
|
|
840
|
+
};
|
|
841
|
+
|
|
842
|
+
// src/modules/auth/store/authSlice.ts
|
|
843
|
+
var defaultUser = {
|
|
844
|
+
uid: "",
|
|
845
|
+
id: "",
|
|
846
|
+
userName: "",
|
|
847
|
+
displayName: "",
|
|
848
|
+
avatar: "/images/default-avatar.jpg",
|
|
849
|
+
email: "",
|
|
850
|
+
exp: 0,
|
|
851
|
+
emailVerified: false,
|
|
852
|
+
refreshToken: "",
|
|
853
|
+
accessToken: "",
|
|
854
|
+
role: "NULL" /* NULL */,
|
|
855
|
+
scanStatus: false
|
|
856
|
+
};
|
|
857
|
+
var initialState = {
|
|
858
|
+
user: defaultUser,
|
|
859
|
+
isSignedIn: false,
|
|
860
|
+
pending: true
|
|
861
|
+
};
|
|
862
|
+
var authSlice = createSlice({
|
|
863
|
+
name: "auth",
|
|
864
|
+
initialState,
|
|
865
|
+
reducers: {
|
|
866
|
+
signIn: (state, action) => {
|
|
867
|
+
const userData = action.payload;
|
|
868
|
+
state.user = userData;
|
|
869
|
+
state.isSignedIn = true;
|
|
870
|
+
state.pending = false;
|
|
871
|
+
setUserInfo(userData);
|
|
872
|
+
setAccessToken(userData.accessToken);
|
|
873
|
+
setRefreshToken(userData.refreshToken);
|
|
874
|
+
},
|
|
875
|
+
signOut: (state) => {
|
|
876
|
+
state.user = defaultUser;
|
|
877
|
+
state.isSignedIn = false;
|
|
878
|
+
state.pending = false;
|
|
879
|
+
removeUserInfo();
|
|
880
|
+
removeAccessToken();
|
|
881
|
+
removeRefreshToken();
|
|
882
|
+
},
|
|
883
|
+
updateScanStatus: (state, action) => {
|
|
884
|
+
state.user.scanStatus = action.payload;
|
|
885
|
+
setUserInfo(state.user);
|
|
886
|
+
},
|
|
887
|
+
refreshUser: (state, action) => {
|
|
888
|
+
const userData = action.payload;
|
|
889
|
+
if (userData) {
|
|
890
|
+
state.user = userData;
|
|
891
|
+
state.isSignedIn = true;
|
|
892
|
+
state.pending = false;
|
|
893
|
+
setUserInfo(userData);
|
|
894
|
+
setAccessToken(userData.accessToken);
|
|
895
|
+
setRefreshToken(userData.refreshToken);
|
|
896
|
+
}
|
|
897
|
+
},
|
|
898
|
+
setPending: (state, action) => {
|
|
899
|
+
state.pending = action.payload;
|
|
900
|
+
},
|
|
901
|
+
initializeFromStorage: (state) => {
|
|
902
|
+
const storedUser = getUserInfo();
|
|
903
|
+
const accessToken = getAccessToken();
|
|
904
|
+
if (storedUser && accessToken) {
|
|
905
|
+
state.user = storedUser;
|
|
906
|
+
state.isSignedIn = true;
|
|
907
|
+
}
|
|
908
|
+
state.pending = false;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
var {
|
|
913
|
+
signIn,
|
|
914
|
+
signOut,
|
|
915
|
+
updateScanStatus,
|
|
916
|
+
refreshUser,
|
|
917
|
+
setPending,
|
|
918
|
+
initializeFromStorage
|
|
919
|
+
} = authSlice.actions;
|
|
920
|
+
var selectUser = (state) => state.auth.user;
|
|
921
|
+
var selectIsSignedIn = (state) => state.auth.isSignedIn;
|
|
922
|
+
var selectIsLoading = (state) => state.auth.pending;
|
|
923
|
+
var authSlice_default = authSlice.reducer;
|
|
924
|
+
|
|
925
|
+
// src/modules/auth/providers/AuthProvider.tsx
|
|
926
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
927
|
+
var AuthContext = createContext(null);
|
|
928
|
+
function AuthProvider({ children, authService, authCallbacks }) {
|
|
929
|
+
const dispatch = useAppDispatch();
|
|
930
|
+
useEffect(() => {
|
|
931
|
+
dispatch(initializeFromStorage());
|
|
932
|
+
const unsubscribe = authService.onAuthStateChanged((user2) => {
|
|
933
|
+
if (user2) {
|
|
934
|
+
dispatch(signIn(user2));
|
|
935
|
+
if (authCallbacks?.onUserIdentify && user2.email) {
|
|
936
|
+
authCallbacks.onUserIdentify({
|
|
937
|
+
email: user2.email,
|
|
938
|
+
name: user2.displayName,
|
|
939
|
+
avatar: user2.avatar,
|
|
940
|
+
uid: user2.uid
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
if (authCallbacks?.onSignInSuccess) {
|
|
944
|
+
authCallbacks.onSignInSuccess(user2);
|
|
945
|
+
}
|
|
946
|
+
} else {
|
|
947
|
+
dispatch(signOut());
|
|
948
|
+
if (authCallbacks?.onTrackingReset) {
|
|
949
|
+
authCallbacks.onTrackingReset();
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
dispatch(setPending(false));
|
|
953
|
+
});
|
|
954
|
+
return () => {
|
|
955
|
+
unsubscribe();
|
|
956
|
+
};
|
|
957
|
+
}, [authService, dispatch, authCallbacks]);
|
|
958
|
+
const user = useAppSelector(selectUser);
|
|
959
|
+
const isSignedIn = useAppSelector(selectIsSignedIn);
|
|
960
|
+
const isLoading = useAppSelector(selectIsLoading);
|
|
961
|
+
const signInWithCredential = async (email, password) => {
|
|
962
|
+
const result = await authService.signInWithEmailAndPassword(email, password);
|
|
963
|
+
if (result.data && authCallbacks?.onSignInSuccess) {
|
|
964
|
+
authCallbacks.onSignInSuccess(result.data);
|
|
965
|
+
} else if (result.errorCode && authCallbacks?.onSignInError) {
|
|
966
|
+
authCallbacks.onSignInError(result.errorCode);
|
|
967
|
+
}
|
|
968
|
+
return result;
|
|
969
|
+
};
|
|
970
|
+
const signInWithGoogle = async () => {
|
|
971
|
+
const result = await authService.signInWithGoogle();
|
|
972
|
+
if (result.data && authCallbacks?.onSignInSuccess) {
|
|
973
|
+
authCallbacks.onSignInSuccess(result.data);
|
|
974
|
+
return result;
|
|
975
|
+
} else if (result.errorCode && authCallbacks?.onSignInError) {
|
|
976
|
+
authCallbacks.onSignInError(result.errorCode);
|
|
977
|
+
}
|
|
978
|
+
return null;
|
|
979
|
+
};
|
|
980
|
+
const signUp = async (email, password) => {
|
|
981
|
+
const result = await authService.signUp(email, password);
|
|
982
|
+
if (result.data && authCallbacks?.onSignUpSuccess) {
|
|
983
|
+
authCallbacks.onSignUpSuccess(result.data);
|
|
984
|
+
} else if (result.errorCode && authCallbacks?.onSignUpError) {
|
|
985
|
+
authCallbacks.onSignUpError(result.errorCode);
|
|
986
|
+
}
|
|
987
|
+
return result;
|
|
988
|
+
};
|
|
989
|
+
const signOut2 = async () => {
|
|
990
|
+
await authService.signOut();
|
|
991
|
+
dispatch(signOut());
|
|
992
|
+
if (authCallbacks?.onSignOutSuccess) {
|
|
993
|
+
authCallbacks.onSignOutSuccess();
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
const forgotPassword = async (email) => {
|
|
997
|
+
return await authService.sendPasswordResetEmail(email);
|
|
998
|
+
};
|
|
999
|
+
const sendEmailVerification = async () => {
|
|
1000
|
+
return await authService.sendEmailVerification();
|
|
1001
|
+
};
|
|
1002
|
+
const changePassword = async (newPassword) => {
|
|
1003
|
+
return await authService.changePassword(newPassword);
|
|
1004
|
+
};
|
|
1005
|
+
const updateScanStatus2 = (status) => {
|
|
1006
|
+
dispatch(updateScanStatus(status));
|
|
1007
|
+
};
|
|
1008
|
+
const refreshUser2 = (userData) => {
|
|
1009
|
+
dispatch(refreshUser(userData));
|
|
1010
|
+
};
|
|
1011
|
+
const contextValue = {
|
|
1012
|
+
authService,
|
|
1013
|
+
authCallbacks,
|
|
1014
|
+
// User state
|
|
1015
|
+
user,
|
|
1016
|
+
isSignedIn,
|
|
1017
|
+
isLoading,
|
|
1018
|
+
// Auth actions
|
|
1019
|
+
signInWithCredential,
|
|
1020
|
+
signInWithGoogle,
|
|
1021
|
+
signUp,
|
|
1022
|
+
signOut: signOut2,
|
|
1023
|
+
// Password actions
|
|
1024
|
+
forgotPassword,
|
|
1025
|
+
sendEmailVerification,
|
|
1026
|
+
changePassword,
|
|
1027
|
+
// User management
|
|
1028
|
+
updateScanStatus: updateScanStatus2,
|
|
1029
|
+
refreshUser: refreshUser2
|
|
1030
|
+
};
|
|
1031
|
+
return /* @__PURE__ */ jsx2(AuthContext.Provider, { value: contextValue, children });
|
|
1032
|
+
}
|
|
1033
|
+
var useAuth = () => {
|
|
1034
|
+
const authContext = useContext(AuthContext);
|
|
1035
|
+
if (!authContext) {
|
|
1036
|
+
throw new Error("useAuth must be used within an AuthProvider");
|
|
1037
|
+
}
|
|
1038
|
+
return authContext;
|
|
1039
|
+
};
|
|
1040
|
+
|
|
1041
|
+
// src/modules/auth/index.ts
|
|
1042
|
+
init_constants();
|
|
1043
|
+
|
|
1044
|
+
// src/modules/user-profile/hooks/index.ts
|
|
1045
|
+
import { useMyProfile, useUpdateMyProfile, useSyncCheckin, useCancelUserRewardsRequest } from "@phygitallabs/api-core";
|
|
1046
|
+
|
|
1047
|
+
// src/modules/user-profile/types/index.ts
|
|
1048
|
+
import { UserSourceType } from "@phygitallabs/api-core";
|
|
1049
|
+
|
|
1050
|
+
// src/modules/scan-chip/hooks/index.tsx
|
|
1051
|
+
import { useEffect as useEffect2 } from "react";
|
|
1052
|
+
import { useChipScanStory } from "@phygitallabs/api-core";
|
|
1053
|
+
import { usePGLCoreService } from "@phygitallabs/api-core";
|
|
1054
|
+
function useScanChip({ token, id, onScanChipError }) {
|
|
1055
|
+
const { updateHeaders } = usePGLCoreService();
|
|
1056
|
+
useEffect2(() => {
|
|
1057
|
+
if (!!token) {
|
|
1058
|
+
const header = {
|
|
1059
|
+
"Chip-Authorization": token
|
|
1060
|
+
};
|
|
1061
|
+
setChipAuthToken(token);
|
|
1062
|
+
updateHeaders(header);
|
|
1063
|
+
}
|
|
1064
|
+
}, [token, updateHeaders]);
|
|
1065
|
+
const { data, isLoading, isError, isSuccess } = useChipScanStory({
|
|
1066
|
+
token,
|
|
1067
|
+
id
|
|
1068
|
+
});
|
|
1069
|
+
useEffect2(() => {
|
|
1070
|
+
if (isError) {
|
|
1071
|
+
onScanChipError?.();
|
|
1072
|
+
}
|
|
1073
|
+
}, [isError, onScanChipError]);
|
|
1074
|
+
if (!data)
|
|
1075
|
+
return {
|
|
1076
|
+
data: null,
|
|
1077
|
+
isLoading,
|
|
1078
|
+
isError,
|
|
1079
|
+
isSuccess
|
|
1080
|
+
};
|
|
1081
|
+
return {
|
|
1082
|
+
data: {
|
|
1083
|
+
externalUrl: data?.external_url,
|
|
1084
|
+
campaignDetail: data?.project,
|
|
1085
|
+
locationDetail: data?.location,
|
|
1086
|
+
scanCounter: data?.scan_counter,
|
|
1087
|
+
campaignId: data?.campaign_id,
|
|
1088
|
+
chipModelId: data?.chip_model_id,
|
|
1089
|
+
organizationId: data?.organization_id,
|
|
1090
|
+
projectId: data?.project_id,
|
|
1091
|
+
locationId: data?.location_id,
|
|
1092
|
+
chipUid: data?.uid
|
|
1093
|
+
},
|
|
1094
|
+
isLoading,
|
|
1095
|
+
isError,
|
|
1096
|
+
isSuccess
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
// src/modules/campaign/hooks/useCampaignService.ts
|
|
1101
|
+
import {
|
|
1102
|
+
useOneCampaign,
|
|
1103
|
+
useUserCampaignAction,
|
|
1104
|
+
useOneUserCampaign
|
|
1105
|
+
} from "@phygitallabs/api-core";
|
|
1106
|
+
|
|
1107
|
+
// src/modules/campaign/types/enums.ts
|
|
1108
|
+
import {
|
|
1109
|
+
CampaignState
|
|
1110
|
+
} from "@phygitallabs/api-core";
|
|
1111
|
+
|
|
1112
|
+
// src/modules/campaign/types/campaign.ts
|
|
1113
|
+
var TaskType = /* @__PURE__ */ ((TaskType2) => {
|
|
1114
|
+
TaskType2["CHECK_IN"] = "check_in";
|
|
1115
|
+
TaskType2["CREATE_MEMORY"] = "create_memory";
|
|
1116
|
+
TaskType2["FILL_FORM"] = "fill_form";
|
|
1117
|
+
TaskType2["SHARE"] = "share";
|
|
1118
|
+
return TaskType2;
|
|
1119
|
+
})(TaskType || {});
|
|
1120
|
+
|
|
1121
|
+
// src/modules/location/hooks/useLocationService.ts
|
|
1122
|
+
import {
|
|
1123
|
+
useManyLocations,
|
|
1124
|
+
useOneLocation,
|
|
1125
|
+
useUserCampaignsCompletedLocation,
|
|
1126
|
+
useManyUserActionLocations,
|
|
1127
|
+
locationQueryKeys
|
|
1128
|
+
} from "@phygitallabs/api-core";
|
|
1129
|
+
|
|
1130
|
+
// src/modules/location/utils/locationHelpers.ts
|
|
1131
|
+
var sortLocationsByIndex = (locations) => {
|
|
1132
|
+
return [...locations].sort((a, b) => (a.index ?? 0) - (b.index ?? 0));
|
|
1133
|
+
};
|
|
1134
|
+
var filterLocationsByProperty = (locations, propertyName, value) => {
|
|
1135
|
+
return locations.filter((location) => location[propertyName] === value);
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
// src/modules/generate-certificate/hooks/index.ts
|
|
1139
|
+
import {
|
|
1140
|
+
useGenerateThaocamvienCertificate,
|
|
1141
|
+
useGenerateTemplateCertificate,
|
|
1142
|
+
useGenerateFansipanCertificate
|
|
1143
|
+
} from "@phygitallabs/generate-certificate";
|
|
1144
|
+
|
|
1145
|
+
// src/modules/data-tracking/hooks/index.ts
|
|
1146
|
+
import posthog from "posthog-js";
|
|
1147
|
+
var pushEventToDataLayer = (event, data) => {
|
|
1148
|
+
try {
|
|
1149
|
+
window.dataLayer = window.dataLayer || [];
|
|
1150
|
+
window.dataLayer.push({
|
|
1151
|
+
event,
|
|
1152
|
+
...data
|
|
1153
|
+
});
|
|
1154
|
+
} catch (error) {
|
|
1155
|
+
console.error(error);
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
var pushEventToGA = (eventName, eventData) => {
|
|
1159
|
+
if (typeof gtag != "function") {
|
|
1160
|
+
console.error("gtag is not a function");
|
|
1161
|
+
return;
|
|
1162
|
+
}
|
|
1163
|
+
gtag("event", eventName, eventData);
|
|
1164
|
+
};
|
|
1165
|
+
var pushEventToPosthog = (eventName, eventData) => {
|
|
1166
|
+
posthog.capture(eventName, eventData);
|
|
1167
|
+
};
|
|
1168
|
+
function useDataTracking() {
|
|
1169
|
+
const trackEvent = (eventName, eventData, useTools) => {
|
|
1170
|
+
useTools = useTools || ["gtm"];
|
|
1171
|
+
if (useTools.includes("gtm") && typeof window !== "undefined") {
|
|
1172
|
+
pushEventToDataLayer(eventName, eventData);
|
|
1173
|
+
}
|
|
1174
|
+
if (useTools.includes("ga") && typeof gtag == "function") {
|
|
1175
|
+
pushEventToGA(eventName, eventData);
|
|
1176
|
+
}
|
|
1177
|
+
if (useTools.includes("posthog") && typeof posthog == "function") {
|
|
1178
|
+
pushEventToPosthog(eventName, eventData);
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1181
|
+
return {
|
|
1182
|
+
trackEvent
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// src/providers/TapquestCoreProvider.tsx
|
|
1187
|
+
import { useMemo as useMemo2 } from "react";
|
|
1188
|
+
import { Provider } from "react-redux";
|
|
1189
|
+
import { PersistGate } from "redux-persist/integration/react";
|
|
1190
|
+
|
|
1191
|
+
// src/providers/ServicesProvider.tsx
|
|
1192
|
+
import { useEffect as useEffect3, useState, useMemo } from "react";
|
|
1193
|
+
import { PGLCoreServiceProvider } from "@phygitallabs/api-core";
|
|
1194
|
+
import { RewardServiceProvider } from "@phygitallabs/reward";
|
|
1195
|
+
import { AchievementServiceProvider as AchievementServiceProvider2 } from "@phygitallabs/achievement";
|
|
1196
|
+
import { GenerateCertificateServiceProvider } from "@phygitallabs/generate-certificate";
|
|
1197
|
+
import axios from "axios";
|
|
1198
|
+
import { Fragment, jsx as jsx3 } from "react/jsx-runtime";
|
|
1199
|
+
var ServicesProvider = ({
|
|
1200
|
+
children,
|
|
1201
|
+
queryClient,
|
|
1202
|
+
apiConfig = {
|
|
1203
|
+
environment: "dev",
|
|
1204
|
+
version: "v1"
|
|
1205
|
+
},
|
|
1206
|
+
firebaseConfig
|
|
1207
|
+
}) => {
|
|
1208
|
+
const { refreshUser: refreshUser2, signOut: signOut2 } = useAuth();
|
|
1209
|
+
const { environment, version } = apiConfig;
|
|
1210
|
+
const [commonServiceConfig, setCommonServiceConfig] = useState(null);
|
|
1211
|
+
const memoizedRefreshToken = useMemo(() => {
|
|
1212
|
+
if (!firebaseConfig?.apiKey) {
|
|
1213
|
+
console.warn("Firebase API key not provided, refresh token functionality will not work");
|
|
1214
|
+
return null;
|
|
1215
|
+
}
|
|
1216
|
+
return createRefreshTokenFunction({
|
|
1217
|
+
firebaseApiKey: firebaseConfig.apiKey
|
|
1218
|
+
});
|
|
1219
|
+
}, [firebaseConfig?.apiKey]);
|
|
1220
|
+
useEffect3(() => {
|
|
1221
|
+
const initClient = async () => {
|
|
1222
|
+
try {
|
|
1223
|
+
const deviceUid = await checkDeviceUid();
|
|
1224
|
+
const responseInterceptors = {
|
|
1225
|
+
onFulfilled: (response) => response,
|
|
1226
|
+
onRejected: async (error) => {
|
|
1227
|
+
const originalRequest = error.config;
|
|
1228
|
+
if (error.response?.status === 401 && !originalRequest._retry) {
|
|
1229
|
+
const retryAttempts = parseInt(
|
|
1230
|
+
getRetryAttemptsRefreshToken() || "0",
|
|
1231
|
+
10
|
|
1232
|
+
);
|
|
1233
|
+
if (retryAttempts >= httpMaxRetries) {
|
|
1234
|
+
await signOut2();
|
|
1235
|
+
return Promise.reject(error);
|
|
1236
|
+
}
|
|
1237
|
+
setRetryAttemptsRefreshToken(`${retryAttempts + 1}`);
|
|
1238
|
+
originalRequest._retry = true;
|
|
1239
|
+
try {
|
|
1240
|
+
if (!memoizedRefreshToken) {
|
|
1241
|
+
await signOut2();
|
|
1242
|
+
return Promise.reject(error);
|
|
1243
|
+
}
|
|
1244
|
+
const result = await memoizedRefreshToken();
|
|
1245
|
+
if (result?.accessToken) {
|
|
1246
|
+
originalRequest.headers["Authorization"] = `Bearer ${result.accessToken}`;
|
|
1247
|
+
setRetryAttemptsRefreshToken("0");
|
|
1248
|
+
refreshUser2(result);
|
|
1249
|
+
return axios(originalRequest);
|
|
1250
|
+
}
|
|
1251
|
+
} catch (refreshError) {
|
|
1252
|
+
console.log("Failed to refresh token:", refreshError);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
return Promise.reject(error);
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
const requestInterceptors = {
|
|
1259
|
+
onFulfilled: (config2) => {
|
|
1260
|
+
const currentToken = getAccessToken();
|
|
1261
|
+
if (currentToken && !config2.headers.Authorization) {
|
|
1262
|
+
config2.headers.Authorization = `Bearer ${currentToken}`;
|
|
1263
|
+
}
|
|
1264
|
+
return config2;
|
|
1265
|
+
},
|
|
1266
|
+
onRejected: (error) => Promise.reject(error)
|
|
1267
|
+
};
|
|
1268
|
+
const axiosConfig = {
|
|
1269
|
+
headers: {
|
|
1270
|
+
"Content-Type": "application/json",
|
|
1271
|
+
"Device-UID": deviceUid
|
|
1272
|
+
}
|
|
1273
|
+
};
|
|
1274
|
+
const config = {
|
|
1275
|
+
queryClient,
|
|
1276
|
+
axiosConfig,
|
|
1277
|
+
responseInterceptors,
|
|
1278
|
+
requestInterceptors,
|
|
1279
|
+
useDevTool: true
|
|
1280
|
+
};
|
|
1281
|
+
setCommonServiceConfig(config);
|
|
1282
|
+
} catch (error) {
|
|
1283
|
+
console.error(error);
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
initClient();
|
|
1287
|
+
}, [queryClient]);
|
|
1288
|
+
if (!commonServiceConfig) {
|
|
1289
|
+
return /* @__PURE__ */ jsx3(Fragment, {});
|
|
1290
|
+
}
|
|
1291
|
+
return /* @__PURE__ */ jsx3(
|
|
1292
|
+
PGLCoreServiceProvider,
|
|
1293
|
+
{
|
|
1294
|
+
...commonServiceConfig,
|
|
1295
|
+
baseURL: `${service_default[environment].API_BASE_URL}/${version}`,
|
|
1296
|
+
baseCoreURL: `${service_default[environment].API_BASE_CORE_URL}/${version}`,
|
|
1297
|
+
children: /* @__PURE__ */ jsx3(
|
|
1298
|
+
RewardServiceProvider,
|
|
1299
|
+
{
|
|
1300
|
+
...commonServiceConfig,
|
|
1301
|
+
baseURL: `${service_default[environment].API_REWARD_URL}/v1`,
|
|
1302
|
+
children: /* @__PURE__ */ jsx3(
|
|
1303
|
+
AchievementServiceProvider2,
|
|
1304
|
+
{
|
|
1305
|
+
...commonServiceConfig,
|
|
1306
|
+
baseURL: `${service_default[environment].API_ACHIEVEMENT_URL}/${version}`,
|
|
1307
|
+
children: /* @__PURE__ */ jsx3(
|
|
1308
|
+
GenerateCertificateServiceProvider,
|
|
1309
|
+
{
|
|
1310
|
+
...commonServiceConfig,
|
|
1311
|
+
baseURL: `${service_default[environment].API_GENERATE_CERTIFICATE_URL}/v1`,
|
|
1312
|
+
children
|
|
1313
|
+
}
|
|
1314
|
+
)
|
|
1315
|
+
}
|
|
1316
|
+
)
|
|
1317
|
+
}
|
|
1318
|
+
)
|
|
1319
|
+
}
|
|
1320
|
+
);
|
|
1321
|
+
};
|
|
1322
|
+
|
|
1323
|
+
// src/store/index.ts
|
|
1324
|
+
import { configureStore } from "@reduxjs/toolkit";
|
|
1325
|
+
import storage from "redux-persist/lib/storage";
|
|
1326
|
+
import { persistReducer, persistStore } from "redux-persist";
|
|
1327
|
+
var authPersistConfig = {
|
|
1328
|
+
key: "tapquest-auth",
|
|
1329
|
+
storage,
|
|
1330
|
+
whitelist: ["user", "isSignedIn"]
|
|
1331
|
+
// Only persist user and sign-in status
|
|
1332
|
+
};
|
|
1333
|
+
var persistedAuthReducer = persistReducer(authPersistConfig, authSlice.reducer);
|
|
1334
|
+
var store = configureStore({
|
|
1335
|
+
reducer: {
|
|
1336
|
+
auth: persistedAuthReducer
|
|
1337
|
+
},
|
|
1338
|
+
middleware: (getDefaultMiddleware) => getDefaultMiddleware({
|
|
1339
|
+
serializableCheck: {
|
|
1340
|
+
// Ignore redux-persist actions
|
|
1341
|
+
ignoredActions: [
|
|
1342
|
+
"persist/FLUSH",
|
|
1343
|
+
"persist/REHYDRATE",
|
|
1344
|
+
"persist/PAUSE",
|
|
1345
|
+
"persist/PERSIST",
|
|
1346
|
+
"persist/PURGE",
|
|
1347
|
+
"persist/REGISTER"
|
|
1348
|
+
]
|
|
1349
|
+
}
|
|
1350
|
+
})
|
|
1351
|
+
});
|
|
1352
|
+
var persistor = persistStore(store);
|
|
1353
|
+
|
|
1354
|
+
// src/providers/TapquestCoreProvider.tsx
|
|
1355
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1356
|
+
var TapquestCoreProvider = ({
|
|
1357
|
+
children,
|
|
1358
|
+
queryClient,
|
|
1359
|
+
apiConfig,
|
|
1360
|
+
firebaseConfig,
|
|
1361
|
+
authCallbacks
|
|
1362
|
+
}) => {
|
|
1363
|
+
const internalAuthService = useMemo2(() => {
|
|
1364
|
+
if (firebaseConfig && typeof window !== "undefined") {
|
|
1365
|
+
try {
|
|
1366
|
+
const { createAuthService: createAuthService2 } = (init_services(), __toCommonJS(services_exports));
|
|
1367
|
+
return createAuthService2({ firebaseConfig });
|
|
1368
|
+
} catch (error) {
|
|
1369
|
+
console.warn("Failed to create auth service from firebase config:", error);
|
|
1370
|
+
return null;
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
return null;
|
|
1374
|
+
}, [firebaseConfig]);
|
|
1375
|
+
return /* @__PURE__ */ jsx4(Provider, { store, children: /* @__PURE__ */ jsx4(PersistGate, { loading: null, persistor, children: /* @__PURE__ */ jsx4(
|
|
1376
|
+
AuthProvider,
|
|
1377
|
+
{
|
|
1378
|
+
authService: internalAuthService,
|
|
1379
|
+
authCallbacks,
|
|
1380
|
+
children: /* @__PURE__ */ jsx4(
|
|
1381
|
+
ServicesProvider,
|
|
1382
|
+
{
|
|
1383
|
+
queryClient,
|
|
1384
|
+
apiConfig,
|
|
1385
|
+
firebaseConfig,
|
|
1386
|
+
children
|
|
1387
|
+
}
|
|
1388
|
+
)
|
|
1389
|
+
}
|
|
1390
|
+
) }) });
|
|
1391
|
+
};
|
|
1392
|
+
|
|
1393
|
+
// src/modules/achivementWithReward/hooks/achivementPlusRewardModel.ts
|
|
1394
|
+
import { useManyAchievements as useManyAchievements2 } from "@phygitallabs/achievement";
|
|
1395
|
+
import { useCreateModelGroupReward as useCreateModelGroupReward2 } from "@phygitallabs/reward/src/hooks/useGroupReward";
|
|
1396
|
+
import { useEffect as useEffect4, useMemo as useMemo3 } from "react";
|
|
1397
|
+
function buildMappedAchievements(achievements, groupRewardData) {
|
|
1398
|
+
if (!groupRewardData?.reward_models) return [];
|
|
1399
|
+
const rewardModels = groupRewardData.reward_models;
|
|
1400
|
+
return achievements.map((achievement, achievementIndex) => {
|
|
1401
|
+
const parentReward = rewardModels[achievementIndex]?.[0] || null;
|
|
1402
|
+
const subAchievements = achievement.subAchievementIds?.map((subId, subIndex) => {
|
|
1403
|
+
const reward = rewardModels[achievementIndex * (achievement.subAchievementIds?.length || 0) + subIndex + 1]?.[0] || null;
|
|
1404
|
+
return {
|
|
1405
|
+
id: subId,
|
|
1406
|
+
reward_model: reward
|
|
1407
|
+
};
|
|
1408
|
+
}) || [];
|
|
1409
|
+
return {
|
|
1410
|
+
id: achievement.id,
|
|
1411
|
+
name: achievement.name,
|
|
1412
|
+
reward_model: parentReward,
|
|
1413
|
+
subAchievements
|
|
1414
|
+
};
|
|
1415
|
+
});
|
|
1416
|
+
}
|
|
1417
|
+
var useAchivementPlusRewardModel = ({ campaignId }) => {
|
|
1418
|
+
const { data: achievements, isLoading: isLoadingAchievements } = useManyAchievements2(
|
|
1419
|
+
{
|
|
1420
|
+
"filter.labels": { campaign_id: campaignId },
|
|
1421
|
+
"filter.type": "group_mission",
|
|
1422
|
+
"pagination.limit": 200
|
|
1423
|
+
},
|
|
1424
|
+
{ enabled: !!campaignId }
|
|
1425
|
+
);
|
|
1426
|
+
const groupRewardIds = useMemo3(() => {
|
|
1427
|
+
if (!achievements?.data) return [];
|
|
1428
|
+
return achievements.data.map((achievement) => achievement.groupRewardId).filter((id) => id !== void 0);
|
|
1429
|
+
}, [achievements?.data]);
|
|
1430
|
+
const {
|
|
1431
|
+
mutate: fetchGroupRewardModels,
|
|
1432
|
+
data: groupRewardModelsData,
|
|
1433
|
+
isPending: isPendingGroupRewardModels
|
|
1434
|
+
} = useCreateModelGroupReward2();
|
|
1435
|
+
useEffect4(() => {
|
|
1436
|
+
if (groupRewardIds.length > 0) {
|
|
1437
|
+
fetchGroupRewardModels({ group_reward_ids: groupRewardIds });
|
|
1438
|
+
}
|
|
1439
|
+
}, [groupRewardIds, fetchGroupRewardModels]);
|
|
1440
|
+
const mappedAchievements = useMemo3(() => {
|
|
1441
|
+
if (!groupRewardModelsData?.data || !achievements?.data) return [];
|
|
1442
|
+
return buildMappedAchievements(achievements.data, groupRewardModelsData.data);
|
|
1443
|
+
}, [groupRewardModelsData, achievements?.data]);
|
|
1444
|
+
return {
|
|
1445
|
+
mappedAchievements,
|
|
1446
|
+
isLoading: isLoadingAchievements || isPendingGroupRewardModels
|
|
1447
|
+
};
|
|
1448
|
+
};
|
|
1449
|
+
var achivementPlusRewardModel_default = useAchivementPlusRewardModel;
|
|
1450
|
+
|
|
1451
|
+
// src/modules/send-email/hooks/index.ts
|
|
1452
|
+
import { useSendEmail } from "@phygitallabs/api-core";
|
|
1453
|
+
|
|
1454
|
+
// src/helper/helpers.ts
|
|
1455
|
+
import { cn, parse, fileToBase64 } from "@phygitallabs/helpers";
|
|
1456
|
+
export {
|
|
1457
|
+
AchievementRuleActionType,
|
|
1458
|
+
AchievementServiceProvider,
|
|
1459
|
+
AchievementType,
|
|
1460
|
+
AuthProvider,
|
|
1461
|
+
CampaignState,
|
|
1462
|
+
CmentityRewardType,
|
|
1463
|
+
NotificationProvider,
|
|
1464
|
+
RewardClaimStatus,
|
|
1465
|
+
TapquestCoreProvider,
|
|
1466
|
+
TaskType,
|
|
1467
|
+
UserSourceType,
|
|
1468
|
+
accessTokenKey,
|
|
1469
|
+
checkDeviceUid,
|
|
1470
|
+
chipAuthTokenKey,
|
|
1471
|
+
cn,
|
|
1472
|
+
convertSnakeToCamel,
|
|
1473
|
+
createRefreshTokenFunction,
|
|
1474
|
+
deviceUIDKey,
|
|
1475
|
+
fileToBase64,
|
|
1476
|
+
filterLocationsByProperty,
|
|
1477
|
+
generateDeviceId,
|
|
1478
|
+
getAccessToken,
|
|
1479
|
+
getActionsFromAchievementRule,
|
|
1480
|
+
getChipAuthToken,
|
|
1481
|
+
getDeviceUid,
|
|
1482
|
+
getLocationIdsFromAchievementRule,
|
|
1483
|
+
getRefreshToken,
|
|
1484
|
+
getRetryAttemptsRefreshToken,
|
|
1485
|
+
getUserInfo,
|
|
1486
|
+
httpMaxRetries,
|
|
1487
|
+
isAchievementCompleted,
|
|
1488
|
+
locationQueryKeys,
|
|
1489
|
+
memoriesKey,
|
|
1490
|
+
parse,
|
|
1491
|
+
refreshTokenKey,
|
|
1492
|
+
removeAccessToken,
|
|
1493
|
+
removeChipAuthToken,
|
|
1494
|
+
removeDeviceUid,
|
|
1495
|
+
removeRefreshToken,
|
|
1496
|
+
removeUserInfo,
|
|
1497
|
+
resetMemoriesQuery,
|
|
1498
|
+
retryAttemptsRefreshToken,
|
|
1499
|
+
setAccessToken,
|
|
1500
|
+
setChipAuthToken,
|
|
1501
|
+
setDeviceUid,
|
|
1502
|
+
setRefreshToken,
|
|
1503
|
+
setRetryAttemptsRefreshToken,
|
|
1504
|
+
setUserInfo,
|
|
1505
|
+
sortLocationsByIndex,
|
|
1506
|
+
useAchievementProgress,
|
|
1507
|
+
achivementPlusRewardModel_default as useAchivementPlusRewardModel,
|
|
1508
|
+
useAuth,
|
|
1509
|
+
useOneCampaign as useCampaignDetail,
|
|
1510
|
+
useCancelUserRewardsRequest,
|
|
1511
|
+
useChipScanStory,
|
|
1512
|
+
useClaimUserReward,
|
|
1513
|
+
useClearUserRewardCache,
|
|
1514
|
+
useCreateMemory,
|
|
1515
|
+
useCreateModelGroupReward,
|
|
1516
|
+
useApiCreateRewardModel as useCreateRewardModel,
|
|
1517
|
+
useDataTracking,
|
|
1518
|
+
useApiDeleteRewardModel as useDeleteRewardModel,
|
|
1519
|
+
useGenerateFansipanCertificate,
|
|
1520
|
+
useGenerateTemplateCertificate,
|
|
1521
|
+
useGenerateThaocamvienCertificate,
|
|
1522
|
+
useApiGetRewardModel as useGetRewardModel,
|
|
1523
|
+
useGetUserRewards,
|
|
1524
|
+
useInfiniteMemories,
|
|
1525
|
+
useApiListRewardModels as useListRewardModels,
|
|
1526
|
+
useOneLocation as useLocationDetail,
|
|
1527
|
+
useUserCampaignsCompletedLocation as useLocationProgress,
|
|
1528
|
+
useManyLocations as useLocationsList,
|
|
1529
|
+
useManyAchievementProgress,
|
|
1530
|
+
useManyAchievements,
|
|
1531
|
+
useManyAchievementsRewardModels,
|
|
1532
|
+
useManyChildrenAchievements,
|
|
1533
|
+
useManyMemory,
|
|
1534
|
+
useManyUserActionLocations,
|
|
1535
|
+
useManyUserRewards,
|
|
1536
|
+
useMyProfile,
|
|
1537
|
+
useOneAchievement,
|
|
1538
|
+
useOneMemory,
|
|
1539
|
+
useOneUserCampaign,
|
|
1540
|
+
usePGLCoreService,
|
|
1541
|
+
useScanChip,
|
|
1542
|
+
useSendEmail,
|
|
1543
|
+
useSyncCheckin,
|
|
1544
|
+
useUpdateMyProfile,
|
|
1545
|
+
useApiUpdateRewardModel as useUpdateRewardModel,
|
|
1546
|
+
useUploadMedia,
|
|
1547
|
+
useUserAchievementAction,
|
|
1548
|
+
useUserCampaignAction,
|
|
1549
|
+
useV1ListRewards,
|
|
1550
|
+
userInfoKey
|
|
1551
|
+
};
|
|
1552
|
+
//# sourceMappingURL=index.js.map
|