@jetthai/cuora 1.0.65 → 1.0.66-sabai-2

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.
Files changed (92) hide show
  1. package/.husky/pre-commit +4 -0
  2. package/.prettierignore +1 -0
  3. package/CHANGELOG.md +642 -0
  4. package/README.md +6 -0
  5. package/dist/bundle.mjs +27623 -0
  6. package/package.json +13 -11
  7. package/rollup.config.js +12 -0
  8. package/src/api/activity.js +10 -3
  9. package/src/api/auth.js +47 -5
  10. package/src/api/game.js +64 -2
  11. package/src/api/index.js +9 -9
  12. package/src/api/payment.js +91 -7
  13. package/src/api/user.js +18 -0
  14. package/src/index.js +7 -5
  15. package/src/lib/fingerprint.js +5779 -0
  16. package/src/machine/activity/activity.js +97 -10
  17. package/src/machine/activity/affiliate_invite_friends_activity.js +216 -0
  18. package/src/machine/activity/continue_deposit_activity.js +1 -1
  19. package/src/machine/activity/deposit_activity.js +1 -1
  20. package/src/machine/activity/{diamond_shop_activity.js → diamond_shop_activity_fc.js} +33 -5
  21. package/src/machine/activity/{diamond_shop_activity_single_exchange.js → diamond_shop_activity_vn.js} +66 -21
  22. package/src/machine/activity/fafafa_activity.js +4 -2
  23. package/src/machine/activity/index.js +24 -10
  24. package/src/machine/activity/invite_friends_activity.js +3 -8
  25. package/src/machine/activity/mini_game_activity.js +68 -0
  26. package/src/machine/activity/ranking_activity.js +40 -46
  27. package/src/machine/activity/return_bonus_activity.js +5 -3
  28. package/src/machine/activity/roulette_activity_v2.js +81 -0
  29. package/src/machine/activity/sign_in_activity.js +149 -0
  30. package/src/machine/activity/specify_bets_activity.js +1 -1
  31. package/src/machine/activity/specify_turnover_activity.js +113 -0
  32. package/src/machine/activity/time_bomb_activity.js +80 -0
  33. package/src/machine/auth.js +234 -79
  34. package/src/machine/auth_otp_v2.js +177 -0
  35. package/src/machine/{auth_otp.js → auth_otp_v3.js} +80 -17
  36. package/src/machine/bank_binding.js +120 -0
  37. package/src/machine/bank_binding_amb.js +140 -0
  38. package/src/machine/bonus.js +75 -0
  39. package/src/machine/common.js +80 -17
  40. package/src/machine/deposit/amb.js +90 -0
  41. package/src/machine/deposit/crypto.js +267 -0
  42. package/src/machine/deposit/crypto_button.js +449 -0
  43. package/src/machine/{deposit.js → deposit/deposit_fc.js} +27 -15
  44. package/src/machine/deposit/direct.js +246 -0
  45. package/src/machine/deposit/float.js +295 -0
  46. package/src/machine/deposit/index.js +25 -0
  47. package/src/machine/deposit/loadcard_vn.js +390 -0
  48. package/src/machine/deposit/manual_vn.js +382 -0
  49. package/src/machine/deposit/qrcode_v2.js +451 -0
  50. package/src/machine/deposit/usdt.js +144 -0
  51. package/src/machine/deposit/vpay.js +292 -0
  52. package/src/machine/error.js +1 -1
  53. package/src/machine/game.js +17 -10
  54. package/src/machine/game_favorite.js +2 -2
  55. package/src/machine/game_favorite_v2.js +119 -0
  56. package/src/machine/game_hot_new.js +1 -1
  57. package/src/machine/game_search.js +3 -7
  58. package/src/machine/game_search_v2.js +379 -0
  59. package/src/machine/game_v2.js +381 -0
  60. package/src/machine/game_v2_1.js +442 -0
  61. package/src/machine/inbox.js +5 -6
  62. package/src/machine/index.js +58 -23
  63. package/src/machine/leaderboard.js +108 -0
  64. package/src/machine/merge.js +2 -2
  65. package/src/machine/payment_data.js +6 -5
  66. package/src/machine/promotions.js +170 -0
  67. package/src/machine/reward.js +84 -3
  68. package/src/machine/reward_fc.js +97 -0
  69. package/src/machine/roulette_v2.js +271 -0
  70. package/src/machine/setting.js +5 -2
  71. package/src/machine/side.js +34 -27
  72. package/src/machine/side_v2.js +200 -0
  73. package/src/machine/user_info.js +1 -1
  74. package/src/machine/user_reset_password.js +2 -2
  75. package/src/machine/user_sign_up.js +111 -56
  76. package/src/machine/vip_table.js +50 -0
  77. package/src/machine/welcome.js +6 -8
  78. package/src/machine/withdraw_amb.js +373 -0
  79. package/src/machine/withdraw_crypto.js +560 -0
  80. package/src/machine/withdraw_fc.js +251 -0
  81. package/src/machine/withdraw_vn.js +495 -0
  82. package/src/request/config.js +7 -1
  83. package/src/request/request.js +11 -15
  84. package/src/util/constant.js +2 -0
  85. package/src/util/deviceToken.js +33 -0
  86. package/src/util/index.js +6 -0
  87. package/src/util/storage.js +28 -0
  88. package/dist/index.js +0 -2
  89. package/dist/index.js.LICENSE.txt +0 -30
  90. package/src/machine/withdraw.js +0 -380
  91. package/src/request/cookie.js +0 -52
  92. package/webpack.config.js +0 -33
@@ -0,0 +1,495 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import findLastIndex from 'lodash/findLastIndex.js'
3
+ import payment from '../api/payment.js'
4
+ import common from '../api/common.js'
5
+ import user from '../api/user.js'
6
+
7
+ export default function (request) {
8
+ const { appSecret } = request.config
9
+ return createMachine(
10
+ {
11
+ id: 'withdraw_vn',
12
+ initial: 'loading',
13
+ context: {
14
+ siteConfig: null,
15
+ userInfo: null,
16
+ balance: null,
17
+ charge: null,
18
+ realAmount: null,
19
+ applyId: null,
20
+ methods: [],
21
+ paymentDetail: [],
22
+ bankInfo: [],
23
+ bankList: [],
24
+ withdrawLimit: null,
25
+ targetWithdrawLimit: null,
26
+ attachmentType: null, // null | 'withdraw' | 'pool'
27
+ maximumWithdrawAmount: 0,
28
+ enableWithdrawAmount: 0,
29
+ enableWithdraw: false,
30
+ withdrawRules: [],
31
+
32
+ amount: null,
33
+ bank: null,
34
+ branch: null,
35
+ accountNumber: null,
36
+ holderName: null,
37
+
38
+ // otp
39
+ requestId: null,
40
+ status: null,
41
+ target: null,
42
+ ttl: null,
43
+ },
44
+ states: {
45
+ loading: {
46
+ invoke: {
47
+ src: 'fetchInitData',
48
+ onDone: {
49
+ target: 'mode',
50
+ actions: ['setInitData', 'preset', 'updateWithdrawCondition'],
51
+ },
52
+ onError: {
53
+ target: 'fail',
54
+ },
55
+ },
56
+ },
57
+ mode: {
58
+ always: [{ target: 'free', cond: 'isFree' }, { target: 'cash' }],
59
+ },
60
+ free: {
61
+ initial: 'checking',
62
+ states: {
63
+ // loading: {
64
+ // invoke: {
65
+ // src: 'fetchWithdrawRules',
66
+ // onDone: {
67
+ // target: 'checking',
68
+ // actions: 'updateWithdrawCondition',
69
+ // },
70
+ // onError: {
71
+ // target: 'notConvertible',
72
+ // },
73
+ // },
74
+ // },
75
+ checking: {
76
+ always: [{ target: 'convertible', cond: 'isConvertible' }, { target: 'notConvertible' }],
77
+ },
78
+ notConvertible: {
79
+ on: {
80
+ GIVE_UP: {
81
+ target: 'givingUp',
82
+ },
83
+ },
84
+ },
85
+ givingUp: {
86
+ invoke: {
87
+ src: 'giveUp',
88
+ onDone: {
89
+ target: 'gaveUp',
90
+ },
91
+ onError: {
92
+ target: 'convertible',
93
+ },
94
+ },
95
+ },
96
+ gaveUp: {},
97
+ convertible: {
98
+ on: {
99
+ SUBMIT: {
100
+ target: 'converting',
101
+ actions: 'setAttachmentType',
102
+ },
103
+ },
104
+ },
105
+ converting: {
106
+ invoke: {
107
+ src: 'convertFreeCredit',
108
+ onDone: [
109
+ {
110
+ target: '#withdraw_vn.otp',
111
+ actions: 'setOtp',
112
+ cond: 'isOtpRequired',
113
+ },
114
+ { target: 'converted' },
115
+ ],
116
+ onError: {
117
+ target: 'convertible',
118
+ },
119
+ },
120
+ },
121
+ converted: {
122
+ always: [{ target: '#withdraw_vn.cash.withdrawable', cond: 'hasAttachmentType' }],
123
+ },
124
+ },
125
+ },
126
+ cash: {
127
+ initial: 'checking',
128
+ states: {
129
+ checking: {
130
+ always: [
131
+ { target: 'inProcessing', cond: 'haveProcessing' },
132
+ { target: 'notWithdrawable', cond: 'isNotWithdrawable' },
133
+ { target: 'unbound', cond: 'isBankNotBound' },
134
+ { target: 'withdrawable' },
135
+ ],
136
+ },
137
+ notWithdrawable: {},
138
+ unbound: {
139
+ // to bank_binding.js
140
+ },
141
+ inProcessing: {},
142
+ withdrawable: {
143
+ on: {
144
+ SET_CURRENT_BANK: {
145
+ actions: assign((context, event) => {
146
+ return {
147
+ bank: event.data,
148
+ }
149
+ }),
150
+ },
151
+ SET_AMOUNT: {
152
+ actions: assign((context, event) => {
153
+ return {
154
+ amount: event.data,
155
+ }
156
+ }),
157
+ },
158
+ SET_ATTACHMENT_TYPE: {
159
+ actions: 'setAttachmentType',
160
+ cond: 'isNewWalletMode',
161
+ },
162
+ SUBMIT: [
163
+ {
164
+ target: 'pooling',
165
+ cond: (context, event) => {
166
+ const { amount, attachmentType } = context
167
+ return attachmentType === 'pool' && amount > 0
168
+ },
169
+ },
170
+ {
171
+ target: 'submitting',
172
+ cond: 'isSubmittable',
173
+ },
174
+ ],
175
+ },
176
+ },
177
+ submitting: {
178
+ invoke: {
179
+ src: 'submitWithdraw',
180
+ onDone: [
181
+ {
182
+ target: '#withdraw_vn.otp',
183
+ actions: 'setOtp',
184
+ cond: 'isOtpRequired',
185
+ },
186
+ {
187
+ target: 'submitted',
188
+ },
189
+ ],
190
+ onError: {
191
+ target: 'withdrawable',
192
+ },
193
+ },
194
+ },
195
+ submitted: {
196
+ entry: assign((context, event) => {
197
+ const { applyId, balance, realAmount, charge } = event.data
198
+ return { applyId, balance, realAmount, charge }
199
+ }),
200
+ invoke: {
201
+ src: 'fetchPaymentData',
202
+ onDone: {
203
+ target: 'inProcessing',
204
+ actions: 'setPaymentData',
205
+ },
206
+ onError: {
207
+ target: '#withdraw_vn.fail',
208
+ },
209
+ },
210
+ },
211
+ pooling: {
212
+ invoke: {
213
+ src: 'pool',
214
+ onDone: { target: 'pooled' },
215
+ onError: {
216
+ target: 'withdrawable',
217
+ },
218
+ },
219
+ },
220
+ pooled: {},
221
+ },
222
+ },
223
+ otp: {
224
+ type: 'parallel',
225
+ states: {
226
+ countdown: {
227
+ after: {
228
+ 1000: {
229
+ target: 'countdown',
230
+ actions: 'decreaseTtl',
231
+ cond: (context) => context.ttl > 0,
232
+ },
233
+ },
234
+ },
235
+ verification: {
236
+ initial: 'idle',
237
+ states: {
238
+ idle: {
239
+ on: {
240
+ ACKNOWLEDGE: {
241
+ target: 'acknowledging',
242
+ },
243
+ RESET_OTP: {
244
+ target: 'reset',
245
+ },
246
+ BACK: [
247
+ {
248
+ target: '#withdraw_vn.free.convertible',
249
+ cond: 'isFree',
250
+ },
251
+ {
252
+ target: '#withdraw_vn.cash.withdrawable',
253
+ },
254
+ ],
255
+ },
256
+ },
257
+ acknowledging: {
258
+ invoke: {
259
+ src: 'acknowledge',
260
+ onDone: [
261
+ {
262
+ target: '#withdraw_vn.free.converted',
263
+ cond: 'isFree',
264
+ },
265
+ {
266
+ target: '#withdraw_vn.cash.submitted',
267
+ },
268
+ ],
269
+ onError: {
270
+ target: 'idle',
271
+ },
272
+ },
273
+ },
274
+ reset: {
275
+ invoke: {
276
+ src: 'resetOtp',
277
+ onDone: {
278
+ target: 'idle',
279
+ actions: 'setVerificationData',
280
+ },
281
+ onError: { target: 'idle' },
282
+ },
283
+ },
284
+ },
285
+ },
286
+ },
287
+ },
288
+ fail: {},
289
+ },
290
+ on: {
291
+ REFRESH: {
292
+ target: 'loading',
293
+ },
294
+ },
295
+ },
296
+ {
297
+ actions: {
298
+ setInitData: assign((context, event) => {
299
+ return {
300
+ paymentDetail: event.data.paymentDetail,
301
+ bankInfo: event.data.bankInfo,
302
+ bank: event.data.bankInfo[0],
303
+ bonus: event.data.bonus,
304
+ bankList: event.data.bankList,
305
+ }
306
+ }),
307
+ setPaymentData: assign((context, event) => {
308
+ return {
309
+ bankInfo: event.data.bankInfo,
310
+ bonus: event.data.bonus,
311
+ paymentDetail: event.data.paymentDetail,
312
+ }
313
+ }),
314
+ preset: assign((context, event) => {
315
+ const { userInfo, siteConfig } = event.data
316
+ const { withdraw_limit, target_withdraw_limit } = userInfo || {}
317
+ const balance = parseFloat(userInfo?.balance)
318
+ const methods = siteConfig?.paymentMethods?.withdraw || []
319
+ return {
320
+ withdrawLimit: Math.abs(withdraw_limit),
321
+ targetWithdrawLimit: Math.abs(target_withdraw_limit),
322
+ methods,
323
+ balance,
324
+ siteConfig,
325
+ userInfo,
326
+ attachmentType: siteConfig.walletMode > 0 ? 'withdraw' : null,
327
+ }
328
+ }),
329
+ updateWithdrawCondition: assign((context, event) => {
330
+ const { differAmountLimit, enableWithdraw, enableWithdrawAmount, maxWithdrawStatus, maximumWithdrawAmount, minimumWithdrawAmount } =
331
+ event.data?.withdrawRule
332
+
333
+ const withdrawRules = event.data?.withdrawRule?.rules || []
334
+ const rules = withdrawRules.filter((rule) => rule.maxWithdrawAmount > 0)
335
+
336
+ const { balance } = context
337
+ const lastMatchedIndex = findLastIndex(rules, (rule) => balance >= rule.greaterEqualThen)
338
+
339
+ let maxWithdrawAmount = 0
340
+
341
+ if (lastMatchedIndex > -1) {
342
+ rules[lastMatchedIndex].match = true
343
+ maxWithdrawAmount = rules[lastMatchedIndex].maxWithdrawAmount
344
+ } else if (rules.length > 0) {
345
+ maxWithdrawAmount = rules[0].maxWithdrawAmount
346
+ } else {
347
+ maxWithdrawAmount = balance
348
+ }
349
+
350
+ return {
351
+ maxWithdrawAmount,
352
+ enableWithdrawAmount: +enableWithdrawAmount,
353
+ enableWithdraw,
354
+ withdrawRules,
355
+ }
356
+ }),
357
+ setOtp: assign((context, event) => {
358
+ const { requestId, status, target, ttl } = event.data
359
+ return {
360
+ requestId,
361
+ status,
362
+ target,
363
+ ttl,
364
+ }
365
+ }),
366
+ decreaseTtl: assign((context, evnet) => {
367
+ const second = context.ttl
368
+ return {
369
+ ttl: Math.max(second - 1, 0),
370
+ }
371
+ }),
372
+ setVerificationData: assign((context, event) => {
373
+ const { requestId, ttl, target } = event.data
374
+ return {
375
+ requestId,
376
+ ttl,
377
+ target,
378
+ }
379
+ }),
380
+ setAttachmentType: assign((context, event) => {
381
+ return {
382
+ attachmentType: event.data,
383
+ }
384
+ }),
385
+ },
386
+ guards: {
387
+ isFree: (context, event) => {
388
+ return context.userInfo?.withdraw_rule !== 'DEFAULT'
389
+ },
390
+ hasAttachmentType: (context, event) => {
391
+ return ['withdraw', 'pool'].includes(context.attachmentType)
392
+ },
393
+ haveProcessing: (context, event) => {
394
+ return (context.paymentDetail?.[0]?.processing || []).length > 0
395
+ },
396
+ isWithdrawDisable: (context, event) => {
397
+ const { siteConfig } = context
398
+ const methods = siteConfig?.paymentMethods?.withdraw || []
399
+ return methods.length === 0
400
+ },
401
+ isBankNotBound: (context, event) => {
402
+ return !context.bankInfo?.length
403
+ },
404
+ isSubmittable: (context, event) => {
405
+ const { bank, amount } = context
406
+ return bank && amount > 0
407
+ },
408
+ isConvertible: (context, event) => {
409
+ const { balance, enableWithdraw } = context
410
+ return balance > 0 && enableWithdraw
411
+ },
412
+ isNotWithdrawable: (context, event) => {
413
+ const { balance, enableWithdraw, paymentDetail } = context
414
+ const minWithdrawAmount = paymentDetail[0]?.minimum || 0
415
+ return !enableWithdraw || balance < minWithdrawAmount
416
+ },
417
+ isOtpRequired: (context, event) => {
418
+ return event.data?.status === 'otp-verifying'
419
+ },
420
+ isNewWalletMode: (context, event) => context.siteConfig.walletMode > 0,
421
+ },
422
+ services: {
423
+ fetchInitData: async (context, event) => {
424
+ const [{ config }, userInfo, paymentDetail = [], { bonus, bankInfo }, withdrawRule] = await Promise.all([
425
+ request.send(common.getConfig({ appSecret })),
426
+ request.send(user.getUserInfo()),
427
+ request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' })),
428
+ request.send(payment.getPaymentInfo()),
429
+ request.send(payment.getCurrentWithdrawRule()),
430
+ ])
431
+ const siteConfig = JSON.parse(window.atob(config))
432
+ const method = paymentDetail.find((payment) => payment.category === 'manual').method
433
+ const bankList = await request.send(payment.getBankList(method))
434
+ const newBankInfo = bankInfo.map((item) => {
435
+ return { ...item, ...bankList.find((bank) => bank.bankCode === item.bankCode) }
436
+ })
437
+ return { siteConfig, userInfo, paymentDetail, bonus, bankInfo: newBankInfo, bankList, withdrawRule }
438
+ },
439
+ fetchPaymentData: async (context, event) => {
440
+ const paymentDetail = await request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' }))
441
+ const { bonus, bankInfo } = await request.send(payment.getPaymentInfo())
442
+ return { bonus, bankInfo, paymentDetail }
443
+ },
444
+ updatePaymentInfo: async (context, event) => {
445
+ const { bank, branch, accountNumber, holderName } = context
446
+ return await request.send(
447
+ payment.updatePaymentInfo({
448
+ bankCode: bank.bankCode,
449
+ branch,
450
+ bankAccount: accountNumber,
451
+ holderName,
452
+ })
453
+ )
454
+ },
455
+ fetchWithdrawRules: async (context, event) => {
456
+ return await request.send(payment.getCurrentWithdrawRule())
457
+ },
458
+ submitWithdraw: async (context, event) => {
459
+ const { bank, amount } = context
460
+ const { method } = context.paymentDetail[0]
461
+ const branchTemp = bank.bankCode === 'GCASH' ? '' : bank.branch
462
+ return await request.send(
463
+ payment.submitWithdrawTransactionVN({
464
+ method,
465
+ amount,
466
+ applyerBankCode: bank.bankCode,
467
+ applyerAccountNumber: bank.accountNumber,
468
+ branch: branchTemp,
469
+ holderName: bank.holderName,
470
+ })
471
+ )
472
+ },
473
+ convertFreeCredit: async (context, event) => {
474
+ return await request.send(payment.convertFreeCredit({ exchangeType: 1 }))
475
+ },
476
+ resetOtp: async (context, event) => {
477
+ const { requestId, target } = context
478
+ return await request.send(user.otpReset({ requestId, target }))
479
+ },
480
+ acknowledge: async (context, event) => {
481
+ const { requestId, target } = context
482
+ const code = event.data
483
+ return await request.send(user.otpAcknowledge({ requestId, target, code }))
484
+ },
485
+ pool: async (context, event) => {
486
+ const { amount } = context
487
+ return await request.send(payment.restore({ amount }))
488
+ },
489
+ giveUp: async (context, event) => {
490
+ return await request.send(payment.giveUp())
491
+ },
492
+ },
493
+ }
494
+ )
495
+ }
@@ -1,7 +1,9 @@
1
1
  import urljoin from 'url-join'
2
2
 
3
+ // const urljoin = require('url-join')
4
+
3
5
  export default class Config {
4
- constructor({ apiURL, apiVersion, clientId, appSecret, platform, version }) {
6
+ constructor({ apiURL, apiVersion, clientId, appSecret, platform, version, fpToken, sentry, defaultChannel, defaultSubchannel }) {
5
7
  this.apiURL = apiURL
6
8
  this.apiVersion = apiVersion
7
9
  this.clientId = clientId
@@ -9,6 +11,10 @@ export default class Config {
9
11
  this.platform = platform
10
12
  this.version = version
11
13
  this.fullURL = urljoin(this.apiURL, this.apiVersion, this.clientId)
14
+ this.fpToken = fpToken // fingerprintjs token
15
+ this.sentry = sentry
16
+ this.defaultChannel = defaultChannel
17
+ this.defaultSubchannel = defaultSubchannel
12
18
  }
13
19
 
14
20
  setApiURL(url) {
@@ -1,5 +1,7 @@
1
- import pickBy from 'lodash/pickBy'
2
- import Cookie from './cookie'
1
+ import pickBy from 'lodash/pickBy.js'
2
+ import storage from '../util/storage.js'
3
+
4
+ // const pickBy = require('lodash/pickBy')
3
5
 
4
6
  function isValid(value) {
5
7
  return value !== undefined && value !== null
@@ -10,8 +12,9 @@ export default class Request {
10
12
  this.axios = axios
11
13
  this.source = axios.CancelToken.source()
12
14
  this.config = config
13
- this.cookie = new Cookie(`cuora_${config.clientId}`)
15
+ this.key = `cuora_${config.clientId}`
14
16
  this.errorHandler = null
17
+ this.hosts = []
15
18
  this.initialize()
16
19
  }
17
20
 
@@ -19,8 +22,8 @@ export default class Request {
19
22
  this.axios.interceptors.request.use((axiosConfig) => {
20
23
  axiosConfig.headers['X-TH1GAMES-VERSION'] = this.config.version
21
24
  axiosConfig.headers['X-TH1GAMES-PLATFORM'] = this.config.platform
22
- if (this.cookie.getToken()) {
23
- axiosConfig.headers.Authorization = this.cookie.getToken()
25
+ if (storage.get(this.key)) {
26
+ axiosConfig.headers.Authorization = storage.get(this.key)
24
27
  }
25
28
  return axiosConfig
26
29
  })
@@ -48,7 +51,7 @@ export default class Request {
48
51
  async send(req, customToken) {
49
52
  try {
50
53
  const cancelToken = customToken || this.source.token
51
- this._checkToken(req, this.cookie.getToken())
54
+ this._checkToken(req, storage.get(this.key))
52
55
  const requestConfig = this._createConfig(req, cancelToken)
53
56
  const { data } = await this.axios.request(requestConfig)
54
57
  return data
@@ -70,15 +73,7 @@ export default class Request {
70
73
  }
71
74
 
72
75
  _createConfig(req, cancelToken) {
73
- const { method, url, params, isPublic, isFormData } = req
74
- // const config = { baseURL: this.config.fullURL, method, url, cancelToken, isPublic: req.isPublic }
75
- // if (method.toUpperCase() === 'GET') {
76
- // config.params = pickBy(params, isValid)
77
- // } else {
78
- // config.data = pickBy(params, isValid)
79
- // }
80
- // return config
81
-
76
+ const { method, url, params, isPublic, isFormData, headers } = req
82
77
  if (isFormData) {
83
78
  return {
84
79
  baseURL: this.config.fullURL,
@@ -96,6 +91,7 @@ export default class Request {
96
91
  url,
97
92
  cancelToken,
98
93
  isPublic,
94
+ headers,
99
95
  [method.toUpperCase() === 'GET' ? 'params' : 'data']: pickBy(params, isValid),
100
96
  }
101
97
  }
@@ -0,0 +1,2 @@
1
+ export const MY_FAVORITE = 'MyFavorite'
2
+ export const GAME_SEARCH = 'GameSearch'
@@ -0,0 +1,33 @@
1
+ // import FingerprintJS from '@fingerprintjs/fingerprintjs-pro'
2
+ import uniqBy from 'lodash/uniqBy'
3
+ import { load } from '../lib/fingerprint.js'
4
+
5
+ const reg = /fnapi\d*/
6
+ // const reg = /(?<=https:\/\/)\w+(?=(\.\w+\.\w+))/
7
+
8
+ const getDeviceToken = async ({ fpToken, sentry, hosts }) => {
9
+ let dt, endpoints
10
+ try {
11
+ endpoints = uniqBy(
12
+ hosts.map((host) => host.replace(reg, 'fp')),
13
+ (url) => url
14
+ )
15
+ // const fp = await FingerprintJS.load({ apiKey: fpToken, endpoint: endpoints })
16
+ const fp = await load({ endpoint: endpoints })
17
+ const result = await fp.get({ timeout: 30000 })
18
+ dt = result.visitorId
19
+
20
+ if (!dt) {
21
+ throw new Error('[Device Token] No token from FingerprintJS.')
22
+ }
23
+
24
+ console.log('[Device Token]', `${dt} from ${endpoints}`)
25
+ } catch (error) {
26
+ console.error('[Device Token]', `${dt} from ${endpoints}`, error)
27
+ sentry?.captureException(error)
28
+ } finally {
29
+ return dt
30
+ }
31
+ }
32
+
33
+ export { getDeviceToken }
@@ -0,0 +1,6 @@
1
+ import { getDeviceToken } from './deviceToken.js'
2
+ import storage from './storage.js'
3
+ import * as constant from './constant.js'
4
+
5
+ export default { getDeviceToken }
6
+ export { constant, storage }
@@ -0,0 +1,28 @@
1
+ export default {
2
+ get(name, options) {
3
+ const itemStr = localStorage.getItem(name)
4
+
5
+ if (!itemStr) {
6
+ return null
7
+ }
8
+
9
+ const item = JSON.parse(itemStr)
10
+ if (item.expiry && new Date().getTime() > item.expiry) {
11
+ localStorage.removeItem(name)
12
+ return null
13
+ }
14
+
15
+ return item.value
16
+ },
17
+ set(name, value, options) {
18
+ const item = { value }
19
+
20
+ if (options?.maxAge) {
21
+ item.expiry = new Date().getTime() + options.maxAge * 1000
22
+ }
23
+ localStorage.setItem(name, JSON.stringify(item))
24
+ },
25
+ remove(name, options) {
26
+ localStorage.removeItem(name)
27
+ },
28
+ }