@jetthai/cuora 1.0.24 → 1.0.26

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 (51) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/api/activity.js +46 -0
  3. package/api/auth.js +15 -0
  4. package/api/common.js +4 -0
  5. package/api/game.js +32 -0
  6. package/api/index.js +9 -0
  7. package/api/mailbox.js +20 -0
  8. package/api/payment.js +63 -0
  9. package/api/user.js +19 -0
  10. package/index.js +3 -58
  11. package/machine/activity/activity.js +73 -0
  12. package/machine/activity/continue_deposit_activity.js +132 -0
  13. package/machine/activity/deposit_activity.js +86 -0
  14. package/machine/activity/diamond_shop_activity.js +163 -0
  15. package/machine/activity/fafafa_activity.js +131 -0
  16. package/machine/activity/index.js +21 -0
  17. package/machine/activity/invite_friends_activity.js +121 -0
  18. package/machine/activity/ranking_activity.js +76 -0
  19. package/machine/activity/return_bonus_activity.js +150 -0
  20. package/machine/activity/specify_bets_activity.js +116 -0
  21. package/machine/auth.js +245 -0
  22. package/machine/auth_otp.js +191 -0
  23. package/machine/check.js +113 -0
  24. package/machine/common.js +163 -0
  25. package/machine/deposit.js +236 -0
  26. package/machine/error.js +72 -0
  27. package/machine/game.js +265 -0
  28. package/machine/game_favorite.js +123 -0
  29. package/machine/game_search.js +248 -0
  30. package/machine/inbox.js +246 -0
  31. package/machine/index.js +37 -0
  32. package/machine/merge.js +57 -0
  33. package/machine/payment_data.js +81 -0
  34. package/machine/reward.js +73 -0
  35. package/machine/setting.js +37 -0
  36. package/machine/side.js +147 -0
  37. package/machine/withdraw.js +367 -0
  38. package/package.json +3 -2
  39. package/request/config.js +18 -0
  40. package/request/cookie.js +52 -0
  41. package/request/request.js +97 -0
  42. package/plugin/activity.js +0 -289
  43. package/plugin/core.js +0 -518
  44. package/plugin/game.js +0 -474
  45. package/plugin/inbox.js +0 -216
  46. package/plugin/information.js +0 -57
  47. package/plugin/job/network.js +0 -61
  48. package/plugin/payment.js +0 -257
  49. package/plugin/request.js +0 -225
  50. package/plugin/search.js +0 -277
  51. package/plugin/user.js +0 -198
package/plugin/core.js DELETED
@@ -1,518 +0,0 @@
1
- const UAParser = require('ua-parser-js')
2
- const tick = 2000
3
- const clientSecret = process.env.CLIENT_SECRET
4
-
5
- const api = {
6
- getConfig: ({ appSecret }) => ({ url: 'getConfig', method: 'get', params: { appSecret }, public: true }),
7
- login: ({ username, password, provider, countryCode, phone }) => ({
8
- url: 'login',
9
- method: 'post',
10
- params: { username, password, provider, countryCode, phone },
11
- public: true,
12
- }),
13
- register: (data) => ({ url: 'register?channel=official&subchannel=pwa', method: 'post', params: data, public: true }),
14
- logout: () => ({ url: 'logout', method: 'post' }),
15
- feeds: () => ({ url: 'feeds', method: 'get', params: { appSecret: clientSecret }, public: true }),
16
- }
17
-
18
- function createStore({ $request }) {
19
- return {
20
- namespaced: true,
21
- state: () => ({
22
- config: {
23
- // name: process.env.NAME,
24
- clientId: process.env.CLIENT_ID,
25
- clientSecret: process.env.CLIENT_SECRET,
26
- version: process.env.API_VERSION,
27
- serviceUrl: process.env.API_URL,
28
- // officialUrl: process.env.OFFICIAL_URL,
29
- // clientURL: process.env.CLIENT_URL,
30
- // pool: process.env.POOL,
31
- // operationMode: process.env.OPERATION_MODE,
32
- // regions: process.env.REGIONS.split(','),
33
- imageUrl: process.env.IMAGE_URL,
34
- },
35
- authorized: false,
36
- token: null,
37
- globalError: null,
38
- globalLoading: false,
39
- errorHandlerMap: {
40
- ERR_999: 0,
41
- ERR_A201: 1,
42
- ERR_A204: 1,
43
- ERR_A103: 1,
44
- ERR_A104: 1,
45
- ERR_A108: 1,
46
- ERR_F108: 1,
47
- ERR_G112: 0,
48
- ERR_G106: 2,
49
- ERR_P113: 0,
50
- },
51
- settings: {},
52
- siteConfig: {},
53
- refreshing: false,
54
- registration: null,
55
- modal: null,
56
- floatBar: null,
57
- ua: null,
58
- verificationData: {},
59
- idleTimer: null,
60
- idleTime: 0,
61
- idleLimit: 180,
62
- animationInitData: null,
63
- refreshDataFlag: false,
64
- keepUserTimer: null,
65
- keepFreshTimer: null,
66
- }),
67
- getters: {
68
- getSiteConfig(state) {
69
- return state.siteConfig
70
- },
71
- getCSConfig(state, getters) {
72
- return (getters.getSiteConfig || {}).cs || null
73
- },
74
- getLoginMethods(state, getters) {
75
- const loginMethodsSettings = (getters.getSiteConfig || {}).loginMethods
76
- const availableMethods = []
77
- if (loginMethodsSettings) {
78
- for (const method in loginMethodsSettings) {
79
- if (loginMethodsSettings[method]) {
80
- availableMethods.push(method)
81
- }
82
- }
83
- }
84
- return availableMethods
85
- },
86
- getConfig(state) {
87
- return {
88
- ...state.config,
89
- cdn: state.config.pool ? state.config.pool + '/site_resources/' + state.config.clientId + '/webpool/' : '',
90
- }
91
- },
92
- hasForceValidation(state, getters) {
93
- return getters.getSiteConfig.forceValidation !== '0' ? getters.getSiteConfig.forceValidation : false
94
- },
95
- widgetsEnabled(state, getters) {
96
- return ((getters.getSiteConfig || {}).urls || {}).widget
97
- },
98
- getUserAgent(state) {
99
- return (state.ua || {}).ua || ''
100
- },
101
- isNativeApp(state, getters) {
102
- return getters.getUserAgent.includes('th1games')
103
- },
104
- isInAppBrowser(state, getters) {
105
- return (
106
- getters.getUserAgent.includes('Line') ||
107
- getters.getUserAgent.includes('FBAV') ||
108
- getters.getUserAgent.includes('th1games')
109
- )
110
- },
111
- officialLineAt(state, getters) {
112
- return encodeURIComponent((getters.getCSConfig || {}).lineat) || null
113
- },
114
- getVerificationData(state) {
115
- return state.verificationData
116
- },
117
- getSettings(state) {
118
- return state.settings
119
- },
120
- isMobileDevice(state) {
121
- return state.ua?.device?.type || false
122
- },
123
- isIOSDevice(state, getters) {
124
- return getters.isMobileDevice && state.ua?.device?.vendor === 'Apple'
125
- },
126
- getModal(state) {
127
- return state.modal
128
- },
129
- getFloatBar(state) {
130
- return state.floatBar
131
- },
132
- getRegistration(state) {
133
- return state.registration
134
- },
135
- isLoading(state) {
136
- return state.globalLoading
137
- },
138
- getError(state) {
139
- return state.globalError
140
- },
141
- isAuthorized(state, getters) {
142
- return state.authorized
143
- },
144
- isStandAlone(state, getters) {
145
- if (process.client) {
146
- return window.navigator.standalone === true
147
- } else {
148
- return false
149
- }
150
- },
151
- getIdleTime(state) {
152
- return state.idleTime
153
- },
154
- getAnimationInitData(state) {
155
- if (state.animationInitData) {
156
- return state.animationInitData
157
- } else {
158
- return false
159
- }
160
- },
161
- getLocale(state) {
162
- return ({ shorthand, isUnderline }) => {
163
- let localeMap = {
164
- zhTW: 'zh-TW',
165
- enUS: 'en-US',
166
- zhCN: 'zh-CN',
167
- thTH: 'th-TH',
168
- }
169
- if (isUnderline) {
170
- localeMap = {
171
- zhTW: 'zh_TW',
172
- enUS: 'en_US',
173
- zhCN: 'zh_CN',
174
- thTH: 'th_TH',
175
- }
176
- }
177
- return localeMap[shorthand]
178
- }
179
- },
180
- hasCLAchievements(state, getters) {
181
- return getters.getSiteConfig?.competitionLab?.achievements || false
182
- },
183
- },
184
- mutations: {
185
- // setToken(state, data) {
186
- // state.token = data
187
- // },
188
- setAuthorized(state, data) {
189
- state.authorized = data
190
- },
191
- setModal(state, data) {
192
- if (data && data.type === 'idle') {
193
- if (state.modal === null) {
194
- state.modal = data
195
- }
196
- } else {
197
- state.modal = data
198
- }
199
- },
200
- setFloatBar(state, data) {
201
- state.floatBar = data
202
- },
203
- setRefreshingStatus(state, data) {
204
- state.refreshing = data
205
- },
206
- setRegistration(state, data) {
207
- state.registration = data
208
- },
209
- setUpdateStatus(state, data) {
210
- state.updateExists = data
211
- },
212
- setLoading(state, isLoading) {
213
- state.globalLoading = isLoading
214
- },
215
- setVerificationData(state, data) {
216
- state.verificationData = data
217
- },
218
- setSiteConfig(state, config) {
219
- state.siteConfig = config
220
- },
221
- setSettings(state, data) {
222
- state.settings = { ...state.settings, ...data }
223
- },
224
- setUA(state, data) {
225
- state.ua = data
226
- },
227
- setGlobalError(state, payload) {
228
- if (payload) {
229
- const acceptableErrors = ['ERR_A113']
230
- if (!acceptableErrors.includes(payload.code)) {
231
- state.globalError = payload
232
- } else if (payload.code === 'ERR_A113') {
233
- this.$router.push('/')
234
- }
235
- } else {
236
- state.globalError = payload
237
- }
238
- },
239
- resetIdleTimer(state) {
240
- console.log('[Cuora] Reset Idle Timer')
241
- state.idleTimer = clearInterval(state.idleTimer)
242
- state.idleTime = 0
243
- },
244
- setIdleTimer(state, data) {
245
- state.idleTimer = data
246
- },
247
- setIdleTime(state, data) {
248
- state.idleTime++
249
- },
250
- setAnimationInitData(state, data) {
251
- state.animationInitData = data
252
- },
253
- setRefreshDataFlag(state, data) {
254
- state.refreshDataFlag = data
255
- },
256
- setKeepUserTimer(state, data) {
257
- state.keepUserTimer = data
258
- },
259
- setKeepFreshTimer(state, data) {
260
- state.keepFreshTimer = data
261
- },
262
- },
263
- actions: {
264
- checkVerification({ getters, commit, dispatch, rootGetters }) {
265
- // 特別注意排隊中不需驗證
266
- if (!rootGetters['user/isInline'] && getters.hasForceValidation && !rootGetters['user/isValidAccount']) {
267
- if (getters.getModal?.type !== 'verificationCancel') {
268
- commit('setModal', { type: 'verification' })
269
- }
270
- return false
271
- } else {
272
- if (getters.getModal?.type === 'verification') {
273
- commit('setModal', null)
274
- }
275
- return true
276
- }
277
- },
278
- setSettings({ state, dispatch, commit, getters }, data) {
279
- commit('setSettings', data)
280
- commit('localStorage/setSettings', getters.getSettings, { root: true })
281
- // 若有 locale 資訊,就去變更
282
- const lang = (data || {}).locale
283
- if (lang) {
284
- commit('SET_LANG', lang, { root: true })
285
- }
286
- },
287
- solveError({ state, commit, getters, rootGetters, dispatch }) {
288
- const solution = state.errorHandlerMap[getters.getError.code]
289
- switch (solution) {
290
- case 1:
291
- dispatch('detachToken')
292
- if (this.$bridge) {
293
- this.$bridge.callNativeHandler('resetAuth', null, (data) => {
294
- console.log('[Bridge] Auth Reset')
295
- })
296
- }
297
- this.$router.push('/')
298
- break
299
- case 2: // Promote
300
- if (rootGetters['user/userInfo'].retain >= 1) {
301
- commit('setModal', { type: 'mergeRetain' })
302
- } else {
303
- commit('setModal', { type: 'promotionTable' })
304
- }
305
- break
306
- default:
307
- console.log('Error Ignored')
308
- // 雖然錯誤忽略了,但若是玩家正在玩遊戲,也要踢回大廳
309
- if (this.state.route.fullPath === '/main/game') {
310
- dispatch('game/exitGame', null, { root: true })
311
- this.$router.push('/main').catch((err) => {
312
- console.log(err)
313
- })
314
- }
315
- }
316
- commit('setGlobalError', null)
317
- },
318
- setIdleTimer({ commit, getters }, data) {
319
- if (getters.getSiteConfig.idleTimer) {
320
- console.log('[Cuora] Set Idle Timer')
321
- commit('resetIdleTimer')
322
- commit(
323
- 'setIdleTimer',
324
- setInterval(() => {
325
- commit('setIdleTime')
326
- }, 1000)
327
- )
328
- }
329
- },
330
- async login({ state, commit, getters, rootGetters, dispatch }, data) {
331
- try {
332
- const loginResult = await $request.sendWithLoading(api.login(data))
333
- const token = loginResult.token
334
- $request.cookie.setToken(token)
335
- $request.cookie.setUser(data.username)
336
- await dispatch('checkAuth')
337
- return loginResult
338
- } catch (err) {
339
- console.log('[ ERR ] Login Fail')
340
- await dispatch('detachToken')
341
- throw err
342
- }
343
- },
344
- async checkAuth({ state, commit, getters, dispatch }, token) {
345
- try {
346
- commit('setLoading', true)
347
- if (token) {
348
- $request.cookie.setToken(token)
349
- }
350
- // if ($request.cookie.getToken()) {
351
- await dispatch('fetchUserInfo')
352
- commit('setAuthorized', true)
353
- dispatch('game/examineGame', null, { root: true })
354
- dispatch('refreshData')
355
- dispatch('keepAlive')
356
- return true
357
- // } else {
358
- // return false
359
- // }
360
- } catch (err) {
361
- console.error(err)
362
- return false
363
- } finally {
364
- commit(`setLoading`, false)
365
- }
366
- },
367
- async fetchUserInfo({ state, commit, getters, dispatch, rootGetters }) {
368
- try {
369
- await dispatch('user/getUserInfo', null, { root: true })
370
- $request.cookie.prolongToken()
371
- dispatch(`checkVerification`)
372
- // todo test inline
373
- if (rootGetters['user/userInfo']?.rank < 10) {
374
- // 如果排名在 10 名以內的話,暴力連續呼叫
375
- setTimeout(() => {
376
- dispatch('fetchUserInfo')
377
- }, 500)
378
- }
379
- // only for sabai
380
- if (!rootGetters['user/isInline'] && rootGetters['user/userInfo'].bank_account) {
381
- dispatch('payment/refreshAmbBankAccount', null, { root: true })
382
- }
383
- } catch (err) {
384
- await dispatch('detachToken')
385
- throw err
386
- }
387
- },
388
- async detachToken({ state, commit, getters, dispatch, rootGetters }) {
389
- commit('user/setUserInfoFlag', false, { root: true })
390
-
391
- console.info('TOKEN DETACHED')
392
- clearInterval(state.keepUserTimer)
393
- clearInterval(state.keepFreshTimer)
394
- clearInterval(rootGetters['game/getGameTimer'])
395
-
396
- $request.sourceUpdate()
397
- commit('setAuthorized', false)
398
- commit('payment/setRefreshBank', false, { root: true })
399
- $request.cookie.removeToken()
400
-
401
- // Reset Store
402
- commit(`activity/resetActivities`, null, { root: true })
403
- commit(`information/resetOutdateBroadcasts`, null, { root: true })
404
- commit(`game/reset`, null, { root: true })
405
- commit('user/setUserInfo', null, { root: true })
406
- },
407
- async refreshData({ state, commit, getters, dispatch, rootGetters }, refreshTarget) {
408
- // 重新請求基礎資料
409
- try {
410
- if (rootGetters['app/isPlaying'] || state.refreshDataFlag) {
411
- console.info('[Cuora] Refresh Ignored')
412
- return
413
- }
414
-
415
- commit('setRefreshDataFlag', true)
416
- console.info('[Cuora] Refreshing Feeds')
417
- await Promise.all([
418
- await dispatch('getFeeds'),
419
- await dispatch('activity/fetchActivities', null, { root: true }),
420
- await dispatch('activity/fetchAchievements', null, { root: true }),
421
- ])
422
- } catch (err) {
423
- throw err
424
- } finally {
425
- commit('setRefreshDataFlag', false)
426
- }
427
- },
428
- async signUp({ state, commit, getters, dispatch, rootGetters }, data) {
429
- try {
430
- const signUpResult = await $request.sendWithLoading(api.register(data))
431
- $request.cookie.setUser(data.username)
432
- return signUpResult
433
- } catch (err) {
434
- console.log('[ERR] Signup Fail')
435
- throw err
436
- }
437
- },
438
- async logout({ state, commit, getters, dispatch, rootGetters }) {
439
- try {
440
- await $request.send(api.logout())
441
- } catch (err) {
442
- console.log('[ERR] Logout Fail', err)
443
- } finally {
444
- dispatch('detachToken')
445
- }
446
- },
447
- async fetchSiteConfig({ state, commit, getters, dispatch, rootGetters }) {
448
- try {
449
- const { config } = await $request.send(api.getConfig({ appSecret: clientSecret }))
450
- const configObj = JSON.parse(window.atob(config))
451
- commit('payment/setPaymentMethods', configObj?.paymentMethods || {}, { root: true })
452
- commit('setSiteConfig', configObj)
453
- } catch (err) {
454
- console.log(err)
455
- }
456
- },
457
- checkStatus({ getters, commit, dispatch, rootGetters }) {
458
- if (rootGetters['user/userInfo']?.status !== 0) {
459
- commit('setGlobalError', { code: 'ERR_P113', message: 'Account locked.' })
460
- return false
461
- } else {
462
- return true
463
- }
464
- },
465
- detectUA({ state, commit }, ua) {
466
- const parser = new UAParser(ua)
467
- commit('setUA', parser.getResult())
468
- },
469
- async getFeeds({ commit, dispatch }) {
470
- const data = await $request.send(api.feeds())
471
- commit('information/setAnnouncements', data.announcementList, { root: true })
472
- commit('information/setBroadcasts', data.broadcastList, { root: true })
473
- const type = await dispatch('inbox/setSummary', data.mailBoxInfo, { root: true })
474
- if (type === 'system') {
475
- this.$SoundControl.sound.play('mailSystem')
476
- } else if (type === 'normal') {
477
- this.$SoundControl.sound.play('mail')
478
- }
479
- },
480
- keepAlive({ state, rootGetters, commit, dispatch }) {
481
- clearInterval(state.keepUserTimer)
482
- const keepUserTimer = setInterval(async () => {
483
- try {
484
- await dispatch('fetchUserInfo')
485
- } catch (err) {
486
- console.log(err)
487
- }
488
- }, tick * (rootGetters['app/isPlaying'] ? 5 : 1))
489
- commit('setKeepUserTimer', keepUserTimer)
490
-
491
- clearInterval(state.keepFreshTimer)
492
- const keepFreshTimer = setInterval(async () => {
493
- try {
494
- await dispatch('refreshData')
495
- } catch (err) {
496
- console.log(err)
497
- }
498
- }, tick * 10)
499
- commit('setKeepFreshTimer', keepFreshTimer)
500
-
501
- clearInterval(rootGetters['game/getGameTimer'])
502
- const gameTimer = setInterval(async () => {
503
- try {
504
- await dispatch('game/examineGame', null, { root: true })
505
- } catch (err) {
506
- console.log(err)
507
- }
508
- }, tick * 10)
509
- commit('game/setGameTimer', gameTimer, { root: true })
510
- },
511
- },
512
- }
513
- }
514
-
515
- export default (ctx, inject) => {
516
- const { store, $request } = ctx
517
- store.registerModule('core', createStore({ $request }))
518
- }