@phygitallabs/tapquest-core 2.4.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 -18
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1524 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
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
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
+
mod
|
|
32
|
+
));
|
|
33
|
+
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
|
+
|
|
345
|
+
// src/index.ts
|
|
346
|
+
var index_exports = {};
|
|
347
|
+
__export(index_exports, {
|
|
348
|
+
AchievementRuleActionType: () => import_achievement3.AchievementRuleActionType,
|
|
349
|
+
AchievementServiceProvider: () => import_achievement3.AchievementServiceProvider,
|
|
350
|
+
AchievementType: () => AchievementType,
|
|
351
|
+
AuthProvider: () => AuthProvider,
|
|
352
|
+
CampaignState: () => import_api_core8.CampaignState,
|
|
353
|
+
CmentityRewardType: () => import_reward.CmentityRewardType,
|
|
354
|
+
NotificationProvider: () => NotificationProvider,
|
|
355
|
+
RewardClaimStatus: () => RewardClaimStatus,
|
|
356
|
+
TapquestCoreProvider: () => TapquestCoreProvider,
|
|
357
|
+
TaskType: () => TaskType,
|
|
358
|
+
UserSourceType: () => import_api_core4.UserSourceType,
|
|
359
|
+
accessTokenKey: () => accessTokenKey,
|
|
360
|
+
checkDeviceUid: () => checkDeviceUid,
|
|
361
|
+
chipAuthTokenKey: () => chipAuthTokenKey,
|
|
362
|
+
cn: () => import_helpers5.cn,
|
|
363
|
+
convertSnakeToCamel: () => convertSnakeToCamel,
|
|
364
|
+
createRefreshTokenFunction: () => createRefreshTokenFunction,
|
|
365
|
+
deviceUIDKey: () => deviceUIDKey,
|
|
366
|
+
fileToBase64: () => import_helpers5.fileToBase64,
|
|
367
|
+
filterLocationsByProperty: () => filterLocationsByProperty,
|
|
368
|
+
generateDeviceId: () => generateDeviceId,
|
|
369
|
+
getAccessToken: () => getAccessToken,
|
|
370
|
+
getActionsFromAchievementRule: () => getActionsFromAchievementRule,
|
|
371
|
+
getChipAuthToken: () => getChipAuthToken,
|
|
372
|
+
getDeviceUid: () => getDeviceUid,
|
|
373
|
+
getLocationIdsFromAchievementRule: () => getLocationIdsFromAchievementRule,
|
|
374
|
+
getRefreshToken: () => getRefreshToken,
|
|
375
|
+
getRetryAttemptsRefreshToken: () => getRetryAttemptsRefreshToken,
|
|
376
|
+
getUserInfo: () => getUserInfo,
|
|
377
|
+
httpMaxRetries: () => httpMaxRetries,
|
|
378
|
+
isAchievementCompleted: () => isAchievementCompleted,
|
|
379
|
+
locationQueryKeys: () => import_api_core9.locationQueryKeys,
|
|
380
|
+
memoriesKey: () => import_api_core2.memoriesKey,
|
|
381
|
+
parse: () => import_helpers5.parse,
|
|
382
|
+
refreshTokenKey: () => refreshTokenKey,
|
|
383
|
+
removeAccessToken: () => removeAccessToken,
|
|
384
|
+
removeChipAuthToken: () => removeChipAuthToken,
|
|
385
|
+
removeDeviceUid: () => removeDeviceUid,
|
|
386
|
+
removeRefreshToken: () => removeRefreshToken,
|
|
387
|
+
removeUserInfo: () => removeUserInfo,
|
|
388
|
+
resetMemoriesQuery: () => import_api_core2.resetMemoriesQuery,
|
|
389
|
+
retryAttemptsRefreshToken: () => retryAttemptsRefreshToken,
|
|
390
|
+
setAccessToken: () => setAccessToken,
|
|
391
|
+
setChipAuthToken: () => setChipAuthToken,
|
|
392
|
+
setDeviceUid: () => setDeviceUid,
|
|
393
|
+
setRefreshToken: () => setRefreshToken,
|
|
394
|
+
setRetryAttemptsRefreshToken: () => setRetryAttemptsRefreshToken,
|
|
395
|
+
setUserInfo: () => setUserInfo,
|
|
396
|
+
sortLocationsByIndex: () => sortLocationsByIndex,
|
|
397
|
+
useAchievementProgress: () => import_achievement2.useAchievementProgress,
|
|
398
|
+
useAchivementPlusRewardModel: () => achivementPlusRewardModel_default,
|
|
399
|
+
useAuth: () => useAuth,
|
|
400
|
+
useCampaignDetail: () => import_api_core7.useOneCampaign,
|
|
401
|
+
useCancelUserRewardsRequest: () => import_api_core3.useCancelUserRewardsRequest,
|
|
402
|
+
useChipScanStory: () => import_api_core5.useChipScanStory,
|
|
403
|
+
useClaimUserReward: () => import_hooks.useClaimUserReward,
|
|
404
|
+
useClearUserRewardCache: () => import_hooks.useClearUserRewardCache,
|
|
405
|
+
useCreateMemory: () => import_api_core2.useCreateMemory,
|
|
406
|
+
useCreateModelGroupReward: () => import_hooks.useCreateModelGroupReward,
|
|
407
|
+
useCreateRewardModel: () => import_hooks.useApiCreateRewardModel,
|
|
408
|
+
useDataTracking: () => useDataTracking,
|
|
409
|
+
useDeleteRewardModel: () => import_hooks.useApiDeleteRewardModel,
|
|
410
|
+
useGenerateFansipanCertificate: () => import_generate_certificate.useGenerateFansipanCertificate,
|
|
411
|
+
useGenerateTemplateCertificate: () => import_generate_certificate.useGenerateTemplateCertificate,
|
|
412
|
+
useGenerateThaocamvienCertificate: () => import_generate_certificate.useGenerateThaocamvienCertificate,
|
|
413
|
+
useGetRewardModel: () => import_hooks.useApiGetRewardModel,
|
|
414
|
+
useGetUserRewards: () => import_hooks.useGetUserRewards,
|
|
415
|
+
useInfiniteMemories: () => import_api_core2.useInfiniteMemories,
|
|
416
|
+
useListRewardModels: () => import_hooks.useApiListRewardModels,
|
|
417
|
+
useLocationDetail: () => import_api_core9.useOneLocation,
|
|
418
|
+
useLocationProgress: () => import_api_core9.useUserCampaignsCompletedLocation,
|
|
419
|
+
useLocationsList: () => import_api_core9.useManyLocations,
|
|
420
|
+
useManyAchievementProgress: () => useManyAchievementProgress,
|
|
421
|
+
useManyAchievements: () => import_achievement2.useManyAchievements,
|
|
422
|
+
useManyAchievementsRewardModels: () => import_achievement2.useManyAchievementsRewardModels,
|
|
423
|
+
useManyChildrenAchievements: () => import_achievement2.useManyChildrenAchievements,
|
|
424
|
+
useManyMemory: () => import_api_core2.useManyMemory,
|
|
425
|
+
useManyUserActionLocations: () => import_api_core9.useManyUserActionLocations,
|
|
426
|
+
useManyUserRewards: () => import_hooks.useManyUserRewards,
|
|
427
|
+
useMyProfile: () => import_api_core3.useMyProfile,
|
|
428
|
+
useOneAchievement: () => import_achievement2.useOneAchievement,
|
|
429
|
+
useOneMemory: () => import_api_core2.useOneMemory,
|
|
430
|
+
useOneUserCampaign: () => import_api_core7.useOneUserCampaign,
|
|
431
|
+
usePGLCoreService: () => import_api_core6.usePGLCoreService,
|
|
432
|
+
useScanChip: () => useScanChip,
|
|
433
|
+
useSendEmail: () => import_api_core11.useSendEmail,
|
|
434
|
+
useSyncCheckin: () => import_api_core3.useSyncCheckin,
|
|
435
|
+
useUpdateMyProfile: () => import_api_core3.useUpdateMyProfile,
|
|
436
|
+
useUpdateRewardModel: () => import_hooks.useApiUpdateRewardModel,
|
|
437
|
+
useUploadMedia: () => import_api_core2.useUploadMedia,
|
|
438
|
+
useUserAchievementAction: () => import_achievement2.useUserAchievementAction,
|
|
439
|
+
useUserCampaignAction: () => import_api_core7.useUserCampaignAction,
|
|
440
|
+
useV1ListRewards: () => import_hooks.useV1ListRewards,
|
|
441
|
+
userInfoKey: () => userInfoKey
|
|
442
|
+
});
|
|
443
|
+
module.exports = __toCommonJS(index_exports);
|
|
444
|
+
|
|
445
|
+
// src/modules/achievement/hooks/index.ts
|
|
446
|
+
var import_achievement = require("@phygitallabs/achievement");
|
|
447
|
+
var import_api_core = require("@phygitallabs/api-core");
|
|
448
|
+
var import_achievement2 = require("@phygitallabs/achievement");
|
|
449
|
+
|
|
450
|
+
// src/modules/achievement/helpers/index.ts
|
|
451
|
+
var getLocationIdsFromAchievementRule = (achievement) => {
|
|
452
|
+
if (!achievement.rule) return [];
|
|
453
|
+
const locationIds = [];
|
|
454
|
+
Object.values(achievement.rule).forEach((ruleList) => {
|
|
455
|
+
if (!ruleList.rules) return;
|
|
456
|
+
ruleList.rules.forEach((rule) => {
|
|
457
|
+
if (!rule.filter) return;
|
|
458
|
+
Object.values(rule.filter).forEach((filterList) => {
|
|
459
|
+
if (!filterList.filters) return;
|
|
460
|
+
filterList.filters.forEach((filter) => {
|
|
461
|
+
if (filter.label === "location_id" && filter.value) {
|
|
462
|
+
if (Array.isArray(filter.value)) {
|
|
463
|
+
locationIds.push(...filter.value);
|
|
464
|
+
} else {
|
|
465
|
+
locationIds.push(filter.value);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
return Array.from(new Set(locationIds));
|
|
473
|
+
};
|
|
474
|
+
var getActionsFromAchievementRule = (achievement) => {
|
|
475
|
+
if (!achievement.rule) return [];
|
|
476
|
+
const actions = [];
|
|
477
|
+
Object.values(achievement.rule).forEach((ruleList) => {
|
|
478
|
+
if (!ruleList.rules) return;
|
|
479
|
+
ruleList.rules.forEach((rule) => {
|
|
480
|
+
if (rule.action) {
|
|
481
|
+
actions.push(rule.action);
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
return Array.from(new Set(actions));
|
|
486
|
+
};
|
|
487
|
+
var isAchievementCompleted = (achievement) => {
|
|
488
|
+
return achievement.isCompleted || achievement.overallPercentage === 100;
|
|
489
|
+
};
|
|
490
|
+
function convertSnakeToCamel(obj) {
|
|
491
|
+
if (obj === null || obj === void 0) {
|
|
492
|
+
return obj;
|
|
493
|
+
}
|
|
494
|
+
if (Array.isArray(obj)) {
|
|
495
|
+
return obj.map(
|
|
496
|
+
(item) => convertSnakeToCamel(item)
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
if (typeof obj === "object" && obj.constructor === Object) {
|
|
500
|
+
const converted = {};
|
|
501
|
+
for (const key in obj) {
|
|
502
|
+
if (obj.hasOwnProperty(key)) {
|
|
503
|
+
const camelKey = key.replace(
|
|
504
|
+
/_([a-z])/g,
|
|
505
|
+
(_, letter) => letter.toUpperCase()
|
|
506
|
+
);
|
|
507
|
+
converted[camelKey] = convertSnakeToCamel(
|
|
508
|
+
obj[key]
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
return converted;
|
|
513
|
+
}
|
|
514
|
+
return obj;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// src/modules/achievement/hooks/index.ts
|
|
518
|
+
var useManyAchievementProgress = (params, options) => {
|
|
519
|
+
const isLoggedIn = !!params.userId;
|
|
520
|
+
const queryParams = isLoggedIn ? {
|
|
521
|
+
achievementIds: params.achievementIds,
|
|
522
|
+
userId: params.userId,
|
|
523
|
+
applicationId: params.applicationId
|
|
524
|
+
} : {
|
|
525
|
+
achievement_ids: params.achievementIds,
|
|
526
|
+
device_uid: params.deviceUid,
|
|
527
|
+
applicationId: params.applicationId
|
|
528
|
+
};
|
|
529
|
+
if (isLoggedIn) {
|
|
530
|
+
return (0, import_achievement.useManyAchievementProgress)(
|
|
531
|
+
queryParams,
|
|
532
|
+
{
|
|
533
|
+
...options,
|
|
534
|
+
select: (data) => data.map((item) => ({
|
|
535
|
+
...item,
|
|
536
|
+
isCompleted: isAchievementCompleted(item)
|
|
537
|
+
}))
|
|
538
|
+
}
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
return (0, import_api_core.useManyAchievementProgressByDevice)(
|
|
542
|
+
queryParams,
|
|
543
|
+
{
|
|
544
|
+
...options,
|
|
545
|
+
select: (data) => {
|
|
546
|
+
const camelCaseData = convertSnakeToCamel(data);
|
|
547
|
+
return camelCaseData.map((item) => ({
|
|
548
|
+
...item,
|
|
549
|
+
isCompleted: isAchievementCompleted(item)
|
|
550
|
+
}));
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
);
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// src/modules/achievement/types/index.ts
|
|
557
|
+
var import_achievement3 = require("@phygitallabs/achievement");
|
|
558
|
+
var AchievementType = /* @__PURE__ */ ((AchievementType2) => {
|
|
559
|
+
AchievementType2["DEFAULT"] = "default";
|
|
560
|
+
AchievementType2["MULTIPLE_CHECK_INS"] = "multiple_check_ins";
|
|
561
|
+
AchievementType2["RANDOM_CHECK_INS"] = "random_check_ins";
|
|
562
|
+
AchievementType2["GROUP_MISSION"] = "group_mission";
|
|
563
|
+
return AchievementType2;
|
|
564
|
+
})(AchievementType || {});
|
|
565
|
+
|
|
566
|
+
// src/modules/reward/hooks/useRewardService.ts
|
|
567
|
+
var import_hooks = require("@phygitallabs/reward/src/hooks");
|
|
568
|
+
|
|
569
|
+
// src/modules/reward/types/enums.ts
|
|
570
|
+
var import_reward = require("@phygitallabs/reward");
|
|
571
|
+
var RewardClaimStatus = /* @__PURE__ */ ((RewardClaimStatus2) => {
|
|
572
|
+
RewardClaimStatus2["NOT_CLAIMED"] = "not_claimed";
|
|
573
|
+
RewardClaimStatus2["CLAIMED"] = "claimed";
|
|
574
|
+
RewardClaimStatus2["IN_PROGRESS"] = "in_progress";
|
|
575
|
+
RewardClaimStatus2["FAILED"] = "failed";
|
|
576
|
+
return RewardClaimStatus2;
|
|
577
|
+
})(RewardClaimStatus || {});
|
|
578
|
+
|
|
579
|
+
// src/modules/notification/index.ts
|
|
580
|
+
var notification_exports = {};
|
|
581
|
+
__export(notification_exports, {
|
|
582
|
+
NotificationProvider: () => NotificationProvider
|
|
583
|
+
});
|
|
584
|
+
__reExport(notification_exports, require("@phygitallabs/notification-api"));
|
|
585
|
+
|
|
586
|
+
// src/modules/notification/providers/index.tsx
|
|
587
|
+
var import_notification_api = require("@phygitallabs/notification-api");
|
|
588
|
+
|
|
589
|
+
// src/constants/service.ts
|
|
590
|
+
var serviceApiUrl = {
|
|
591
|
+
dev: {
|
|
592
|
+
API_BASE_URL: "https://backend-dev.nomion.io",
|
|
593
|
+
API_BASE_CORE_URL: "https://backend-dev.nomion.io/core",
|
|
594
|
+
API_ACHIEVEMENT_URL: "https://backend-dev.nomion.io/achievement",
|
|
595
|
+
API_REWARD_URL: "https://backend-dev.nomion.io/reward",
|
|
596
|
+
API_GENERATE_CERTIFICATE_URL: "https://media-prc-dev.nomion.io/api",
|
|
597
|
+
API_NOTIFICATION_SOCKET_URL: "https://backend-dev.nomion.io/notification-ws/ws"
|
|
598
|
+
},
|
|
599
|
+
staging: {
|
|
600
|
+
API_BASE_URL: "https://backend-staging.nomion.io",
|
|
601
|
+
API_BASE_CORE_URL: "https://backend-staging.nomion.io/core",
|
|
602
|
+
API_ACHIEVEMENT_URL: "https://backend-staging.nomion.io/achievement",
|
|
603
|
+
API_REWARD_URL: "https://backend-staging.nomion.io/reward",
|
|
604
|
+
API_GENERATE_CERTIFICATE_URL: "https://media-prc-staging.nomion.io/api",
|
|
605
|
+
API_NOTIFICATION_SOCKET_URL: "https://backend-staging.nomion.io/notification-ws/ws"
|
|
606
|
+
},
|
|
607
|
+
production: {
|
|
608
|
+
API_BASE_URL: "https://backend.nomion.io",
|
|
609
|
+
API_BASE_CORE_URL: "https://backend.nomion.io/core",
|
|
610
|
+
API_ACHIEVEMENT_URL: "https://backend.nomion.io/achievement",
|
|
611
|
+
API_REWARD_URL: "https://backend.nomion.io/reward",
|
|
612
|
+
API_GENERATE_CERTIFICATE_URL: "https://media-prc.nomion.io/api",
|
|
613
|
+
API_NOTIFICATION_SOCKET_URL: "https://backend.nomion.io/notification-ws/ws"
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
var service_default = serviceApiUrl;
|
|
617
|
+
|
|
618
|
+
// src/modules/notification/providers/index.tsx
|
|
619
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
620
|
+
var NotificationProvider = ({
|
|
621
|
+
children,
|
|
622
|
+
autoConnect = true,
|
|
623
|
+
environment = "dev",
|
|
624
|
+
user,
|
|
625
|
+
onWebSocketOpen,
|
|
626
|
+
onWebSocketClose,
|
|
627
|
+
onWebSocketMessage
|
|
628
|
+
}) => {
|
|
629
|
+
const webSocketUrl = service_default[environment]?.API_NOTIFICATION_SOCKET_URL;
|
|
630
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
631
|
+
import_notification_api.NotificationProvider,
|
|
632
|
+
{
|
|
633
|
+
userUid: user.id,
|
|
634
|
+
accessToken: user.accessToken,
|
|
635
|
+
webSocketUrl,
|
|
636
|
+
autoConnect,
|
|
637
|
+
onWebSocketOpen,
|
|
638
|
+
onWebSocketClose,
|
|
639
|
+
onWebSocketMessage,
|
|
640
|
+
children
|
|
641
|
+
}
|
|
642
|
+
);
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
// src/index.ts
|
|
646
|
+
__reExport(index_exports, notification_exports, module.exports);
|
|
647
|
+
|
|
648
|
+
// src/modules/memory/hooks/index.ts
|
|
649
|
+
var import_api_core2 = require("@phygitallabs/api-core");
|
|
650
|
+
|
|
651
|
+
// src/modules/auth/providers/AuthProvider.tsx
|
|
652
|
+
var import_react = require("react");
|
|
653
|
+
|
|
654
|
+
// src/store/hooks.ts
|
|
655
|
+
var import_react_redux = require("react-redux");
|
|
656
|
+
var useAppDispatch = () => (0, import_react_redux.useDispatch)();
|
|
657
|
+
var useAppSelector = import_react_redux.useSelector;
|
|
658
|
+
|
|
659
|
+
// src/modules/auth/store/authSlice.ts
|
|
660
|
+
var import_toolkit = require("@reduxjs/toolkit");
|
|
661
|
+
|
|
662
|
+
// src/modules/auth/helpers/index.ts
|
|
663
|
+
init_constants();
|
|
664
|
+
var import_uuid = require("uuid");
|
|
665
|
+
|
|
666
|
+
// src/modules/auth/helpers/refreshToken.ts
|
|
667
|
+
var import_mem = __toESM(require("mem"), 1);
|
|
668
|
+
var REFRESH_TOKEN_CONFIG = {
|
|
669
|
+
maxAge: 1e4
|
|
670
|
+
// 10 seconds cache
|
|
671
|
+
};
|
|
672
|
+
var createRefreshTokenFunction = (config) => {
|
|
673
|
+
const refreshTokenFn = async () => {
|
|
674
|
+
try {
|
|
675
|
+
const session = getUserInfo();
|
|
676
|
+
const refreshToken = getRefreshToken();
|
|
677
|
+
if (!refreshToken) {
|
|
678
|
+
removeUserInfo();
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
const params = new URLSearchParams();
|
|
682
|
+
params.append("grant_type", "refresh_token");
|
|
683
|
+
params.append("refresh_token", refreshToken);
|
|
684
|
+
const fetchData = {
|
|
685
|
+
method: "POST",
|
|
686
|
+
headers: new Headers({
|
|
687
|
+
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
|
|
688
|
+
}),
|
|
689
|
+
body: params
|
|
690
|
+
};
|
|
691
|
+
const response = await fetch(
|
|
692
|
+
`https://securetoken.googleapis.com/v1/token?key=${config.firebaseApiKey}`,
|
|
693
|
+
fetchData
|
|
694
|
+
);
|
|
695
|
+
const data = await response.json();
|
|
696
|
+
if (data.error) {
|
|
697
|
+
removeUserInfo();
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
const newSession = {
|
|
701
|
+
...session,
|
|
702
|
+
accessToken: data.access_token,
|
|
703
|
+
refreshToken: data.refresh_token
|
|
704
|
+
};
|
|
705
|
+
setUserInfo(newSession);
|
|
706
|
+
return newSession;
|
|
707
|
+
} catch {
|
|
708
|
+
removeUserInfo();
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
return (0, import_mem.default)(refreshTokenFn, { maxAge: REFRESH_TOKEN_CONFIG.maxAge });
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
// src/modules/auth/helpers/index.ts
|
|
715
|
+
var generateDeviceId = async () => {
|
|
716
|
+
try {
|
|
717
|
+
const deviceFingerprint = await generateDeviceFingerprint();
|
|
718
|
+
return deviceFingerprint;
|
|
719
|
+
} catch (error) {
|
|
720
|
+
console.error("Error generating device fingerprint:", error);
|
|
721
|
+
return (0, import_uuid.v4)();
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
var generateDeviceFingerprint = async () => {
|
|
725
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
726
|
+
const fingerprintRaw = [
|
|
727
|
+
navigator.userAgent,
|
|
728
|
+
navigator.language,
|
|
729
|
+
screen.width,
|
|
730
|
+
screen.height,
|
|
731
|
+
screen.colorDepth,
|
|
732
|
+
Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
733
|
+
navigator.platform,
|
|
734
|
+
navigator.hardwareConcurrency,
|
|
735
|
+
timestamp
|
|
736
|
+
// Include timestamp
|
|
737
|
+
].join("::");
|
|
738
|
+
const encoder = new TextEncoder();
|
|
739
|
+
const data = encoder.encode(fingerprintRaw);
|
|
740
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
741
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
742
|
+
const fingerprint = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
743
|
+
return fingerprint;
|
|
744
|
+
};
|
|
745
|
+
var getDeviceUid = () => {
|
|
746
|
+
if (typeof window === "undefined") return null;
|
|
747
|
+
return localStorage.getItem(deviceUIDKey);
|
|
748
|
+
};
|
|
749
|
+
var setDeviceUid = (deviceId) => {
|
|
750
|
+
if (typeof window === "undefined") return;
|
|
751
|
+
localStorage.setItem(deviceUIDKey, deviceId);
|
|
752
|
+
};
|
|
753
|
+
var removeDeviceUid = () => {
|
|
754
|
+
if (typeof window === "undefined") return;
|
|
755
|
+
localStorage.removeItem(deviceUIDKey);
|
|
756
|
+
};
|
|
757
|
+
var checkDeviceUid = async () => {
|
|
758
|
+
let deviceUID = getDeviceUid();
|
|
759
|
+
if (!deviceUID) {
|
|
760
|
+
deviceUID = await generateDeviceId();
|
|
761
|
+
setDeviceUid(deviceUID);
|
|
762
|
+
}
|
|
763
|
+
return deviceUID;
|
|
764
|
+
};
|
|
765
|
+
var getChipAuthToken = () => {
|
|
766
|
+
if (typeof window === "undefined") return null;
|
|
767
|
+
return localStorage.getItem(chipAuthTokenKey);
|
|
768
|
+
};
|
|
769
|
+
var setChipAuthToken = (value) => {
|
|
770
|
+
if (typeof window === "undefined") return;
|
|
771
|
+
localStorage.setItem(chipAuthTokenKey, value);
|
|
772
|
+
};
|
|
773
|
+
var removeChipAuthToken = () => {
|
|
774
|
+
if (typeof window === "undefined") return;
|
|
775
|
+
localStorage.removeItem(chipAuthTokenKey);
|
|
776
|
+
};
|
|
777
|
+
var getRetryAttemptsRefreshToken = () => {
|
|
778
|
+
if (typeof window === "undefined") return null;
|
|
779
|
+
return localStorage.getItem(retryAttemptsRefreshToken);
|
|
780
|
+
};
|
|
781
|
+
var setRetryAttemptsRefreshToken = (value) => {
|
|
782
|
+
if (typeof window === "undefined") return;
|
|
783
|
+
localStorage.setItem(retryAttemptsRefreshToken, value);
|
|
784
|
+
};
|
|
785
|
+
var getAccessToken = () => {
|
|
786
|
+
if (typeof window === "undefined") return null;
|
|
787
|
+
return localStorage.getItem(accessTokenKey);
|
|
788
|
+
};
|
|
789
|
+
var setAccessToken = (value) => {
|
|
790
|
+
if (typeof window === "undefined") return;
|
|
791
|
+
localStorage.setItem(accessTokenKey, value);
|
|
792
|
+
};
|
|
793
|
+
var removeAccessToken = () => {
|
|
794
|
+
if (typeof window === "undefined") return;
|
|
795
|
+
localStorage.removeItem(accessTokenKey);
|
|
796
|
+
};
|
|
797
|
+
var getRefreshToken = () => {
|
|
798
|
+
if (typeof window === "undefined") return null;
|
|
799
|
+
return localStorage.getItem(refreshTokenKey);
|
|
800
|
+
};
|
|
801
|
+
var setRefreshToken = (value) => {
|
|
802
|
+
if (typeof window === "undefined") return;
|
|
803
|
+
localStorage.setItem(refreshTokenKey, value);
|
|
804
|
+
};
|
|
805
|
+
var removeRefreshToken = () => {
|
|
806
|
+
if (typeof window === "undefined") return;
|
|
807
|
+
localStorage.removeItem(refreshTokenKey);
|
|
808
|
+
};
|
|
809
|
+
var getUserInfo = () => {
|
|
810
|
+
if (typeof window === "undefined") return null;
|
|
811
|
+
const userInfo = localStorage.getItem(userInfoKey);
|
|
812
|
+
if (!userInfo) return null;
|
|
813
|
+
try {
|
|
814
|
+
return JSON.parse(userInfo);
|
|
815
|
+
} catch (error) {
|
|
816
|
+
console.error("Failed to parse stored user data:", error);
|
|
817
|
+
return null;
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
var setUserInfo = (userData) => {
|
|
821
|
+
if (typeof window === "undefined") return;
|
|
822
|
+
localStorage.setItem(userInfoKey, JSON.stringify(userData));
|
|
823
|
+
};
|
|
824
|
+
var removeUserInfo = () => {
|
|
825
|
+
if (typeof window === "undefined") return;
|
|
826
|
+
localStorage.removeItem(userInfoKey);
|
|
827
|
+
};
|
|
828
|
+
|
|
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
|
+
// src/modules/user-profile/hooks/index.ts
|
|
1032
|
+
var import_api_core3 = require("@phygitallabs/api-core");
|
|
1033
|
+
|
|
1034
|
+
// src/modules/user-profile/types/index.ts
|
|
1035
|
+
var import_api_core4 = require("@phygitallabs/api-core");
|
|
1036
|
+
|
|
1037
|
+
// src/modules/scan-chip/hooks/index.tsx
|
|
1038
|
+
var import_react2 = require("react");
|
|
1039
|
+
var import_api_core5 = require("@phygitallabs/api-core");
|
|
1040
|
+
var import_api_core6 = require("@phygitallabs/api-core");
|
|
1041
|
+
function useScanChip({ token, id, onScanChipError }) {
|
|
1042
|
+
const { updateHeaders } = (0, import_api_core6.usePGLCoreService)();
|
|
1043
|
+
(0, import_react2.useEffect)(() => {
|
|
1044
|
+
if (!!token) {
|
|
1045
|
+
const header = {
|
|
1046
|
+
"Chip-Authorization": token
|
|
1047
|
+
};
|
|
1048
|
+
setChipAuthToken(token);
|
|
1049
|
+
updateHeaders(header);
|
|
1050
|
+
}
|
|
1051
|
+
}, [token, updateHeaders]);
|
|
1052
|
+
const { data, isLoading, isError, isSuccess } = (0, import_api_core5.useChipScanStory)({
|
|
1053
|
+
token,
|
|
1054
|
+
id
|
|
1055
|
+
});
|
|
1056
|
+
(0, import_react2.useEffect)(() => {
|
|
1057
|
+
if (isError) {
|
|
1058
|
+
onScanChipError?.();
|
|
1059
|
+
}
|
|
1060
|
+
}, [isError, onScanChipError]);
|
|
1061
|
+
if (!data)
|
|
1062
|
+
return {
|
|
1063
|
+
data: null,
|
|
1064
|
+
isLoading,
|
|
1065
|
+
isError,
|
|
1066
|
+
isSuccess
|
|
1067
|
+
};
|
|
1068
|
+
return {
|
|
1069
|
+
data: {
|
|
1070
|
+
externalUrl: data?.external_url,
|
|
1071
|
+
campaignDetail: data?.project,
|
|
1072
|
+
locationDetail: data?.location,
|
|
1073
|
+
scanCounter: data?.scan_counter,
|
|
1074
|
+
campaignId: data?.campaign_id,
|
|
1075
|
+
chipModelId: data?.chip_model_id,
|
|
1076
|
+
organizationId: data?.organization_id,
|
|
1077
|
+
projectId: data?.project_id,
|
|
1078
|
+
locationId: data?.location_id,
|
|
1079
|
+
chipUid: data?.uid
|
|
1080
|
+
},
|
|
1081
|
+
isLoading,
|
|
1082
|
+
isError,
|
|
1083
|
+
isSuccess
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
// src/modules/campaign/hooks/useCampaignService.ts
|
|
1088
|
+
var import_api_core7 = require("@phygitallabs/api-core");
|
|
1089
|
+
|
|
1090
|
+
// src/modules/campaign/types/enums.ts
|
|
1091
|
+
var import_api_core8 = require("@phygitallabs/api-core");
|
|
1092
|
+
|
|
1093
|
+
// src/modules/campaign/types/campaign.ts
|
|
1094
|
+
var TaskType = /* @__PURE__ */ ((TaskType2) => {
|
|
1095
|
+
TaskType2["CHECK_IN"] = "check_in";
|
|
1096
|
+
TaskType2["CREATE_MEMORY"] = "create_memory";
|
|
1097
|
+
TaskType2["FILL_FORM"] = "fill_form";
|
|
1098
|
+
TaskType2["SHARE"] = "share";
|
|
1099
|
+
return TaskType2;
|
|
1100
|
+
})(TaskType || {});
|
|
1101
|
+
|
|
1102
|
+
// src/modules/location/hooks/useLocationService.ts
|
|
1103
|
+
var import_api_core9 = require("@phygitallabs/api-core");
|
|
1104
|
+
|
|
1105
|
+
// src/modules/location/utils/locationHelpers.ts
|
|
1106
|
+
var sortLocationsByIndex = (locations) => {
|
|
1107
|
+
return [...locations].sort((a, b) => (a.index ?? 0) - (b.index ?? 0));
|
|
1108
|
+
};
|
|
1109
|
+
var filterLocationsByProperty = (locations, propertyName, value) => {
|
|
1110
|
+
return locations.filter((location) => location[propertyName] === value);
|
|
1111
|
+
};
|
|
1112
|
+
|
|
1113
|
+
// src/modules/generate-certificate/hooks/index.ts
|
|
1114
|
+
var import_generate_certificate = require("@phygitallabs/generate-certificate");
|
|
1115
|
+
|
|
1116
|
+
// src/modules/data-tracking/hooks/index.ts
|
|
1117
|
+
var import_posthog_js = __toESM(require("posthog-js"), 1);
|
|
1118
|
+
var pushEventToDataLayer = (event, data) => {
|
|
1119
|
+
try {
|
|
1120
|
+
window.dataLayer = window.dataLayer || [];
|
|
1121
|
+
window.dataLayer.push({
|
|
1122
|
+
event,
|
|
1123
|
+
...data
|
|
1124
|
+
});
|
|
1125
|
+
} catch (error) {
|
|
1126
|
+
console.error(error);
|
|
1127
|
+
}
|
|
1128
|
+
};
|
|
1129
|
+
var pushEventToGA = (eventName, eventData) => {
|
|
1130
|
+
if (typeof gtag != "function") {
|
|
1131
|
+
console.error("gtag is not a function");
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
1134
|
+
gtag("event", eventName, eventData);
|
|
1135
|
+
};
|
|
1136
|
+
var pushEventToPosthog = (eventName, eventData) => {
|
|
1137
|
+
import_posthog_js.default.capture(eventName, eventData);
|
|
1138
|
+
};
|
|
1139
|
+
function useDataTracking() {
|
|
1140
|
+
const trackEvent = (eventName, eventData, useTools) => {
|
|
1141
|
+
useTools = useTools || ["gtm"];
|
|
1142
|
+
if (useTools.includes("gtm") && typeof window !== "undefined") {
|
|
1143
|
+
pushEventToDataLayer(eventName, eventData);
|
|
1144
|
+
}
|
|
1145
|
+
if (useTools.includes("ga") && typeof gtag == "function") {
|
|
1146
|
+
pushEventToGA(eventName, eventData);
|
|
1147
|
+
}
|
|
1148
|
+
if (useTools.includes("posthog") && typeof import_posthog_js.default == "function") {
|
|
1149
|
+
pushEventToPosthog(eventName, eventData);
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
return {
|
|
1153
|
+
trackEvent
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
// src/providers/TapquestCoreProvider.tsx
|
|
1158
|
+
var import_react4 = require("react");
|
|
1159
|
+
var import_react_redux2 = require("react-redux");
|
|
1160
|
+
var import_react5 = require("redux-persist/integration/react");
|
|
1161
|
+
|
|
1162
|
+
// src/providers/ServicesProvider.tsx
|
|
1163
|
+
var import_react3 = require("react");
|
|
1164
|
+
var import_api_core10 = require("@phygitallabs/api-core");
|
|
1165
|
+
var import_reward2 = require("@phygitallabs/reward");
|
|
1166
|
+
var import_achievement4 = require("@phygitallabs/achievement");
|
|
1167
|
+
var import_generate_certificate2 = require("@phygitallabs/generate-certificate");
|
|
1168
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
1169
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1170
|
+
var ServicesProvider = ({
|
|
1171
|
+
children,
|
|
1172
|
+
queryClient,
|
|
1173
|
+
apiConfig = {
|
|
1174
|
+
environment: "dev",
|
|
1175
|
+
version: "v1"
|
|
1176
|
+
},
|
|
1177
|
+
firebaseConfig
|
|
1178
|
+
}) => {
|
|
1179
|
+
const { refreshUser: refreshUser2, signOut: signOut2 } = useAuth();
|
|
1180
|
+
const { environment, version } = apiConfig;
|
|
1181
|
+
const [commonServiceConfig, setCommonServiceConfig] = (0, import_react3.useState)(null);
|
|
1182
|
+
const memoizedRefreshToken = (0, import_react3.useMemo)(() => {
|
|
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)(() => {
|
|
1192
|
+
const initClient = async () => {
|
|
1193
|
+
try {
|
|
1194
|
+
const deviceUid = await checkDeviceUid();
|
|
1195
|
+
const responseInterceptors = {
|
|
1196
|
+
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
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
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
|
+
},
|
|
1237
|
+
onRejected: (error) => Promise.reject(error)
|
|
1238
|
+
};
|
|
1239
|
+
const axiosConfig = {
|
|
1240
|
+
headers: {
|
|
1241
|
+
"Content-Type": "application/json",
|
|
1242
|
+
"Device-UID": deviceUid
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
const config = {
|
|
1246
|
+
queryClient,
|
|
1247
|
+
axiosConfig,
|
|
1248
|
+
responseInterceptors,
|
|
1249
|
+
requestInterceptors,
|
|
1250
|
+
useDevTool: true
|
|
1251
|
+
};
|
|
1252
|
+
setCommonServiceConfig(config);
|
|
1253
|
+
} catch (error) {
|
|
1254
|
+
console.error(error);
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
initClient();
|
|
1258
|
+
}, [queryClient]);
|
|
1259
|
+
if (!commonServiceConfig) {
|
|
1260
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, {});
|
|
1261
|
+
}
|
|
1262
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1263
|
+
import_api_core10.PGLCoreServiceProvider,
|
|
1264
|
+
{
|
|
1265
|
+
...commonServiceConfig,
|
|
1266
|
+
baseURL: `${service_default[environment].API_BASE_URL}/${version}`,
|
|
1267
|
+
baseCoreURL: `${service_default[environment].API_BASE_CORE_URL}/${version}`,
|
|
1268
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1269
|
+
import_reward2.RewardServiceProvider,
|
|
1270
|
+
{
|
|
1271
|
+
...commonServiceConfig,
|
|
1272
|
+
baseURL: `${service_default[environment].API_REWARD_URL}/v1`,
|
|
1273
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1274
|
+
import_achievement4.AchievementServiceProvider,
|
|
1275
|
+
{
|
|
1276
|
+
...commonServiceConfig,
|
|
1277
|
+
baseURL: `${service_default[environment].API_ACHIEVEMENT_URL}/${version}`,
|
|
1278
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1279
|
+
import_generate_certificate2.GenerateCertificateServiceProvider,
|
|
1280
|
+
{
|
|
1281
|
+
...commonServiceConfig,
|
|
1282
|
+
baseURL: `${service_default[environment].API_GENERATE_CERTIFICATE_URL}/v1`,
|
|
1283
|
+
children
|
|
1284
|
+
}
|
|
1285
|
+
)
|
|
1286
|
+
}
|
|
1287
|
+
)
|
|
1288
|
+
}
|
|
1289
|
+
)
|
|
1290
|
+
}
|
|
1291
|
+
);
|
|
1292
|
+
};
|
|
1293
|
+
|
|
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
|
+
// src/providers/TapquestCoreProvider.tsx
|
|
1326
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1327
|
+
var TapquestCoreProvider = ({
|
|
1328
|
+
children,
|
|
1329
|
+
queryClient,
|
|
1330
|
+
apiConfig,
|
|
1331
|
+
firebaseConfig,
|
|
1332
|
+
authCallbacks
|
|
1333
|
+
}) => {
|
|
1334
|
+
const internalAuthService = (0, import_react4.useMemo)(() => {
|
|
1335
|
+
if (firebaseConfig && typeof window !== "undefined") {
|
|
1336
|
+
try {
|
|
1337
|
+
const { createAuthService: createAuthService2 } = (init_services(), __toCommonJS(services_exports));
|
|
1338
|
+
return createAuthService2({ firebaseConfig });
|
|
1339
|
+
} catch (error) {
|
|
1340
|
+
console.warn("Failed to create auth service from firebase config:", error);
|
|
1341
|
+
return null;
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
return null;
|
|
1345
|
+
}, [firebaseConfig]);
|
|
1346
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_redux2.Provider, { store, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react5.PersistGate, { loading: null, persistor, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1347
|
+
AuthProvider,
|
|
1348
|
+
{
|
|
1349
|
+
authService: internalAuthService,
|
|
1350
|
+
authCallbacks,
|
|
1351
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1352
|
+
ServicesProvider,
|
|
1353
|
+
{
|
|
1354
|
+
queryClient,
|
|
1355
|
+
apiConfig,
|
|
1356
|
+
firebaseConfig,
|
|
1357
|
+
children
|
|
1358
|
+
}
|
|
1359
|
+
)
|
|
1360
|
+
}
|
|
1361
|
+
) }) });
|
|
1362
|
+
};
|
|
1363
|
+
|
|
1364
|
+
// src/modules/achivementWithReward/hooks/achivementPlusRewardModel.ts
|
|
1365
|
+
var import_achievement5 = require("@phygitallabs/achievement");
|
|
1366
|
+
var import_useGroupReward = require("@phygitallabs/reward/src/hooks/useGroupReward");
|
|
1367
|
+
var import_react6 = require("react");
|
|
1368
|
+
function buildMappedAchievements(achievements, groupRewardData) {
|
|
1369
|
+
if (!groupRewardData?.reward_models) return [];
|
|
1370
|
+
const rewardModels = groupRewardData.reward_models;
|
|
1371
|
+
return achievements.map((achievement, achievementIndex) => {
|
|
1372
|
+
const parentReward = rewardModels[achievementIndex]?.[0] || null;
|
|
1373
|
+
const subAchievements = achievement.subAchievementIds?.map((subId, subIndex) => {
|
|
1374
|
+
const reward = rewardModels[achievementIndex * (achievement.subAchievementIds?.length || 0) + subIndex + 1]?.[0] || null;
|
|
1375
|
+
return {
|
|
1376
|
+
id: subId,
|
|
1377
|
+
reward_model: reward
|
|
1378
|
+
};
|
|
1379
|
+
}) || [];
|
|
1380
|
+
return {
|
|
1381
|
+
id: achievement.id,
|
|
1382
|
+
name: achievement.name,
|
|
1383
|
+
reward_model: parentReward,
|
|
1384
|
+
subAchievements
|
|
1385
|
+
};
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
var useAchivementPlusRewardModel = ({ campaignId }) => {
|
|
1389
|
+
const { data: achievements, isLoading: isLoadingAchievements } = (0, import_achievement5.useManyAchievements)(
|
|
1390
|
+
{
|
|
1391
|
+
"filter.labels": { campaign_id: campaignId },
|
|
1392
|
+
"filter.type": "group_mission",
|
|
1393
|
+
"pagination.limit": 200
|
|
1394
|
+
},
|
|
1395
|
+
{ enabled: !!campaignId }
|
|
1396
|
+
);
|
|
1397
|
+
const groupRewardIds = (0, import_react6.useMemo)(() => {
|
|
1398
|
+
if (!achievements?.data) return [];
|
|
1399
|
+
return achievements.data.map((achievement) => achievement.groupRewardId).filter((id) => id !== void 0);
|
|
1400
|
+
}, [achievements?.data]);
|
|
1401
|
+
const {
|
|
1402
|
+
mutate: fetchGroupRewardModels,
|
|
1403
|
+
data: groupRewardModelsData,
|
|
1404
|
+
isPending: isPendingGroupRewardModels
|
|
1405
|
+
} = (0, import_useGroupReward.useCreateModelGroupReward)();
|
|
1406
|
+
(0, import_react6.useEffect)(() => {
|
|
1407
|
+
if (groupRewardIds.length > 0) {
|
|
1408
|
+
fetchGroupRewardModels({ group_reward_ids: groupRewardIds });
|
|
1409
|
+
}
|
|
1410
|
+
}, [groupRewardIds, fetchGroupRewardModels]);
|
|
1411
|
+
const mappedAchievements = (0, import_react6.useMemo)(() => {
|
|
1412
|
+
if (!groupRewardModelsData?.data || !achievements?.data) return [];
|
|
1413
|
+
return buildMappedAchievements(achievements.data, groupRewardModelsData.data);
|
|
1414
|
+
}, [groupRewardModelsData, achievements?.data]);
|
|
1415
|
+
return {
|
|
1416
|
+
mappedAchievements,
|
|
1417
|
+
isLoading: isLoadingAchievements || isPendingGroupRewardModels
|
|
1418
|
+
};
|
|
1419
|
+
};
|
|
1420
|
+
var achivementPlusRewardModel_default = useAchivementPlusRewardModel;
|
|
1421
|
+
|
|
1422
|
+
// src/modules/send-email/hooks/index.ts
|
|
1423
|
+
var import_api_core11 = require("@phygitallabs/api-core");
|
|
1424
|
+
|
|
1425
|
+
// src/helper/helpers.ts
|
|
1426
|
+
var import_helpers5 = require("@phygitallabs/helpers");
|
|
1427
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1428
|
+
0 && (module.exports = {
|
|
1429
|
+
AchievementRuleActionType,
|
|
1430
|
+
AchievementServiceProvider,
|
|
1431
|
+
AchievementType,
|
|
1432
|
+
AuthProvider,
|
|
1433
|
+
CampaignState,
|
|
1434
|
+
CmentityRewardType,
|
|
1435
|
+
NotificationProvider,
|
|
1436
|
+
RewardClaimStatus,
|
|
1437
|
+
TapquestCoreProvider,
|
|
1438
|
+
TaskType,
|
|
1439
|
+
UserSourceType,
|
|
1440
|
+
accessTokenKey,
|
|
1441
|
+
checkDeviceUid,
|
|
1442
|
+
chipAuthTokenKey,
|
|
1443
|
+
cn,
|
|
1444
|
+
convertSnakeToCamel,
|
|
1445
|
+
createRefreshTokenFunction,
|
|
1446
|
+
deviceUIDKey,
|
|
1447
|
+
fileToBase64,
|
|
1448
|
+
filterLocationsByProperty,
|
|
1449
|
+
generateDeviceId,
|
|
1450
|
+
getAccessToken,
|
|
1451
|
+
getActionsFromAchievementRule,
|
|
1452
|
+
getChipAuthToken,
|
|
1453
|
+
getDeviceUid,
|
|
1454
|
+
getLocationIdsFromAchievementRule,
|
|
1455
|
+
getRefreshToken,
|
|
1456
|
+
getRetryAttemptsRefreshToken,
|
|
1457
|
+
getUserInfo,
|
|
1458
|
+
httpMaxRetries,
|
|
1459
|
+
isAchievementCompleted,
|
|
1460
|
+
locationQueryKeys,
|
|
1461
|
+
memoriesKey,
|
|
1462
|
+
parse,
|
|
1463
|
+
refreshTokenKey,
|
|
1464
|
+
removeAccessToken,
|
|
1465
|
+
removeChipAuthToken,
|
|
1466
|
+
removeDeviceUid,
|
|
1467
|
+
removeRefreshToken,
|
|
1468
|
+
removeUserInfo,
|
|
1469
|
+
resetMemoriesQuery,
|
|
1470
|
+
retryAttemptsRefreshToken,
|
|
1471
|
+
setAccessToken,
|
|
1472
|
+
setChipAuthToken,
|
|
1473
|
+
setDeviceUid,
|
|
1474
|
+
setRefreshToken,
|
|
1475
|
+
setRetryAttemptsRefreshToken,
|
|
1476
|
+
setUserInfo,
|
|
1477
|
+
sortLocationsByIndex,
|
|
1478
|
+
useAchievementProgress,
|
|
1479
|
+
useAchivementPlusRewardModel,
|
|
1480
|
+
useAuth,
|
|
1481
|
+
useCampaignDetail,
|
|
1482
|
+
useCancelUserRewardsRequest,
|
|
1483
|
+
useChipScanStory,
|
|
1484
|
+
useClaimUserReward,
|
|
1485
|
+
useClearUserRewardCache,
|
|
1486
|
+
useCreateMemory,
|
|
1487
|
+
useCreateModelGroupReward,
|
|
1488
|
+
useCreateRewardModel,
|
|
1489
|
+
useDataTracking,
|
|
1490
|
+
useDeleteRewardModel,
|
|
1491
|
+
useGenerateFansipanCertificate,
|
|
1492
|
+
useGenerateTemplateCertificate,
|
|
1493
|
+
useGenerateThaocamvienCertificate,
|
|
1494
|
+
useGetRewardModel,
|
|
1495
|
+
useGetUserRewards,
|
|
1496
|
+
useInfiniteMemories,
|
|
1497
|
+
useListRewardModels,
|
|
1498
|
+
useLocationDetail,
|
|
1499
|
+
useLocationProgress,
|
|
1500
|
+
useLocationsList,
|
|
1501
|
+
useManyAchievementProgress,
|
|
1502
|
+
useManyAchievements,
|
|
1503
|
+
useManyAchievementsRewardModels,
|
|
1504
|
+
useManyChildrenAchievements,
|
|
1505
|
+
useManyMemory,
|
|
1506
|
+
useManyUserActionLocations,
|
|
1507
|
+
useManyUserRewards,
|
|
1508
|
+
useMyProfile,
|
|
1509
|
+
useOneAchievement,
|
|
1510
|
+
useOneMemory,
|
|
1511
|
+
useOneUserCampaign,
|
|
1512
|
+
usePGLCoreService,
|
|
1513
|
+
useScanChip,
|
|
1514
|
+
useSendEmail,
|
|
1515
|
+
useSyncCheckin,
|
|
1516
|
+
useUpdateMyProfile,
|
|
1517
|
+
useUpdateRewardModel,
|
|
1518
|
+
useUploadMedia,
|
|
1519
|
+
useUserAchievementAction,
|
|
1520
|
+
useUserCampaignAction,
|
|
1521
|
+
useV1ListRewards,
|
|
1522
|
+
userInfoKey
|
|
1523
|
+
});
|
|
1524
|
+
//# sourceMappingURL=index.cjs.map
|