@jetthai/cuora 1.0.1 → 1.0.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.0.2](https://github.com/jetthai/cuora-module/compare/v1.0.1...v1.0.2) (2021-08-05)
6
+
5
7
  ### 1.0.1 (2021-08-04)
6
8
 
7
9
  ### 1.0.1 (2021-08-04)
package/index.js CHANGED
@@ -3,6 +3,12 @@ import path from 'path'
3
3
  export default function (moduleOptions) {
4
4
  const options = { ...this.options.cuora, ...moduleOptions }
5
5
 
6
+ this.addPlugin({
7
+ src: path.resolve(__dirname, './plugin/job/network.js'),
8
+ options,
9
+ mode: 'client'
10
+ })
11
+
6
12
  this.addPlugin({
7
13
  src: path.resolve(__dirname, './plugin/search.js'),
8
14
  options,
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
8
8
  "release": "standard-version",
9
- "publish": "git push --follow-tags origin master && npm publish"
9
+ "push": "git push --follow-tags origin master && npm publish"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
@@ -29,7 +29,7 @@ const api = {
29
29
 
30
30
  const clientSecret = process.env.CLIENT_SECRET
31
31
 
32
- function createStore(request) {
32
+ function createStore({$request}) {
33
33
  return {
34
34
  namespaced: true,
35
35
  state: () => ({
@@ -212,7 +212,7 @@ function createStore(request) {
212
212
  actions: {
213
213
  async getActivityTypes({ commit }) {
214
214
  try {
215
- const types = await request(api.getActivityTypes({ appSecret: clientSecret }))
215
+ const types = await $request(api.getActivityTypes({ appSecret: clientSecret }))
216
216
  commit(`setActivities`, { types: types?.data || {} })
217
217
  } catch (err) {
218
218
  console.log(err)
@@ -220,7 +220,7 @@ function createStore(request) {
220
220
  },
221
221
  async getActivityList({ commit, getters, dispatch }) {
222
222
  try {
223
- const activities = await request(api.getActivityList({ appSecret: clientSecret, include: 'cl' }))
223
+ const activities = await $request(api.getActivityList({ appSecret: clientSecret, include: 'cl' }))
224
224
  commit(`setActivities`, { list: activities?.data || {} })
225
225
  const activitiesById = {}
226
226
  activities.data.forEach((val, index) => {
@@ -239,7 +239,7 @@ function createStore(request) {
239
239
  }
240
240
  },
241
241
  async getActivityDetail({ commit }, activityNo) {
242
- const { data } = await request(api.getActivityDetail({ activityNo, appSecret: clientSecret }))
242
+ const { data } = await $request(api.getActivityDetail({ activityNo, appSecret: clientSecret }))
243
243
  commit(`setSingleActivities`, { key: activityNo, data })
244
244
  return data
245
245
  },
@@ -253,7 +253,7 @@ function createStore(request) {
253
253
  async fetchAchievements({ rootGetters, commit }, pageIdx = 0) {
254
254
  try {
255
255
  if (rootGetters[`core/isAuthorized`] && !rootGetters['user/isInline']) {
256
- const achievements = await request(
256
+ const achievements = await $request(
257
257
  api.getAchievements({
258
258
  limit: 10,
259
259
  page: pageIdx,
@@ -267,7 +267,7 @@ function createStore(request) {
267
267
  }
268
268
  },
269
269
  async getAchievementDetail({}, achievementNo) {
270
- const { data } = await request(api.getAchievementsProgress({ achievementNo, appSecret: clientSecret }))
270
+ const { data } = await $request(api.getAchievementsProgress({ achievementNo, appSecret: clientSecret }))
271
271
  return data
272
272
  },
273
273
  },
@@ -276,5 +276,5 @@ function createStore(request) {
276
276
 
277
277
  export default (ctx, inject) => {
278
278
  const { store, $request } = ctx
279
- store.registerModule('activity', createStore($request))
279
+ store.registerModule('activity', createStore({$request}))
280
280
  }
package/plugin/core.js CHANGED
@@ -4,13 +4,18 @@ const clientSecret = process.env.CLIENT_SECRET
4
4
 
5
5
  const api = {
6
6
  getConfig: ({ appSecret }) => ({ url: 'getConfig', method: 'get', params: { appSecret }, public: true }),
7
- login: ({ username, password, provider, countryCode, phone }) => ({ url: 'login', method: 'post', params: { username, password, provider, countryCode, phone }, 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
+ }),
8
13
  register: (data) => ({ url: 'register?channel=official&subchannel=pwa', method: 'post', params: data, public: true }),
9
14
  logout: () => ({ url: 'logout', method: 'post' }),
10
15
  feeds: () => ({ url: 'feeds', method: 'get', params: { appSecret: clientSecret }, public: true }),
11
16
  }
12
17
 
13
- function createStore({$request, $ignoreErrorRequest, $loadingRequest, $updateSource, $cookie}) {
18
+ function createStore({ $request, $ignoreErrorRequest, $loadingRequest, $updateSource, $cookie }) {
14
19
  return {
15
20
  namespaced: true,
16
21
  state: () => ({
@@ -255,11 +260,7 @@ function createStore({$request, $ignoreErrorRequest, $loadingRequest, $updateSou
255
260
  actions: {
256
261
  checkVerification({ getters, commit, dispatch, rootGetters }) {
257
262
  // 特別注意排隊中不需驗證
258
- if (
259
- !rootGetters['user/isInline'] &&
260
- getters.hasForceValidation &&
261
- !rootGetters['user/isValidAccount']
262
- ) {
263
+ if (!rootGetters['user/isInline'] && getters.hasForceValidation && !rootGetters['user/isValidAccount']) {
263
264
  if (getters.getModal?.type !== 'verificationCancel') {
264
265
  commit('setModal', { type: 'verification' })
265
266
  }
@@ -343,6 +344,8 @@ function createStore({$request, $ignoreErrorRequest, $loadingRequest, $updateSou
343
344
  if ($cookie.getToken()) {
344
345
  await dispatch('fetchUserInfo')
345
346
  commit('setAuthorized', true)
347
+ dispatch('game/examineGame', null, { root: true })
348
+ dispatch('refreshData')
346
349
  dispatch('keepAlive')
347
350
  return true
348
351
  } else {
@@ -357,7 +360,8 @@ function createStore({$request, $ignoreErrorRequest, $loadingRequest, $updateSou
357
360
  },
358
361
  async fetchUserInfo({ state, commit, getters, dispatch, rootGetters }) {
359
362
  try {
360
- await dispatch('user/getUserInfo', null, {root: true})
363
+ await dispatch('user/getUserInfo', null, { root: true })
364
+ $cookie.prolongToken()
361
365
  dispatch(`checkVerification`)
362
366
  // todo test inline
363
367
  if (rootGetters['user/userInfo']?.rank < 10) {
@@ -376,6 +380,8 @@ function createStore({$request, $ignoreErrorRequest, $loadingRequest, $updateSou
376
380
  }
377
381
  },
378
382
  async detachToken({ state, commit, getters, dispatch, rootGetters }) {
383
+ commit('user/setUserInfoFlag', false, { root: true })
384
+
379
385
  console.info('TOKEN DETACHED')
380
386
  clearInterval(state.keepUserTimer)
381
387
  clearInterval(state.keepFreshTimer)
@@ -415,14 +421,11 @@ function createStore({$request, $ignoreErrorRequest, $loadingRequest, $updateSou
415
421
  },
416
422
  async signUp({ state, commit, getters, dispatch, rootGetters }, data) {
417
423
  try {
418
- commit(`setLoading`, true)
419
- const signUpResult = await $request(api.register(data))
424
+ const signUpResult = await $loadingRequest(api.register(data))
420
425
  $cookie.setUser(data.username)
421
- commit(`setLoading`, false)
422
426
  return signUpResult
423
427
  } catch (err) {
424
- commit(`setLoading`, false)
425
- console.log('[ ERR ] Signup Fail')
428
+ console.log('[ERR] Signup Fail')
426
429
  throw err
427
430
  }
428
431
  },
@@ -488,6 +491,16 @@ function createStore({$request, $ignoreErrorRequest, $loadingRequest, $updateSou
488
491
  }
489
492
  }, tick * 10)
490
493
  commit('setKeepFreshTimer', keepFreshTimer)
494
+
495
+ clearInterval(rootGetters['game/getGameTimer'])
496
+ const gameTimer = setInterval(async () => {
497
+ try {
498
+ await dispatch('game/examineGame', null, { root: true })
499
+ } catch (err) {
500
+ console.log(err)
501
+ }
502
+ }, tick * 10)
503
+ commit('game/setGameTimer', gameTimer, { root: true })
491
504
  },
492
505
  },
493
506
  }
@@ -495,5 +508,5 @@ function createStore({$request, $ignoreErrorRequest, $loadingRequest, $updateSou
495
508
 
496
509
  export default (ctx, inject) => {
497
510
  const { store, $request, $ignoreErrorRequest, $loadingRequest, $updateSource, $cookie } = ctx
498
- store.registerModule('core', createStore({$request, $ignoreErrorRequest, $loadingRequest, $updateSource, $cookie}))
511
+ store.registerModule('core', createStore({ $request, $ignoreErrorRequest, $loadingRequest, $updateSource, $cookie }))
499
512
  }
package/plugin/game.js CHANGED
@@ -11,7 +11,7 @@ const api = {
11
11
  logoutGame: ({ uid_site, provider_id }) => ({ url: 'game/logout', method: 'get', params: { uid_site, provider_id } }),
12
12
  }
13
13
 
14
- function createStore(request, loadingRequest) {
14
+ function createStore({$request, $loadingRequest}) {
15
15
  return {
16
16
  namespaced: true,
17
17
  state: () => ({
@@ -195,7 +195,7 @@ function createStore(request, loadingRequest) {
195
195
  setStatements(state, data) {
196
196
  state.statements = data
197
197
  },
198
- _setGameTimer(state, timer) {
198
+ setGameTimer(state, timer) {
199
199
  state.gameTimer = timer
200
200
  },
201
201
  },
@@ -205,7 +205,7 @@ function createStore(request, loadingRequest) {
205
205
  if (isPlayingGame(currentPath)) return
206
206
 
207
207
  const oldSHA = rootGetters['localStorage/getGameV2SHA']
208
- const newSHA = await request(api.getGameSHA())
208
+ const newSHA = await $request(api.getGameSHA())
209
209
  const isGameChanged = newSHA?.status !== oldSHA?.status
210
210
  const isCategoryChanged = newSHA?.category !== oldSHA?.category
211
211
 
@@ -213,7 +213,7 @@ function createStore(request, loadingRequest) {
213
213
  console.log(`[Gamehall] game changed`, newSHA?.status)
214
214
  commit(`localStorage/setGameV2SHA`, newSHA, { root: true })
215
215
  const oldStatus = rootGetters['localStorage/getGameV2Status']
216
- const newStatus = await request(api.getGameStatus())
216
+ const newStatus = await $request(api.getGameStatus())
217
217
  const infoChangedList = extractInfoChangedGames(oldStatus, newStatus)
218
218
  commit(`localStorage/setGameV2Status`, newStatus, { root: true })
219
219
 
@@ -244,7 +244,7 @@ function createStore(request, loadingRequest) {
244
244
  }
245
245
  },
246
246
  async addGameOption({ getters, commit, dispatch }, code) {
247
- const option = await request(api.getGameMap(code))
247
+ const option = await $request(api.getGameMap(code))
248
248
  if (Object.keys(option || {}).length > 0) {
249
249
  commit('_appendGameMap', { key: code, value: option })
250
250
  commit('_appendInverseGameMap', { key: code, value: option })
@@ -266,9 +266,9 @@ function createStore(request, loadingRequest) {
266
266
  if (!isInLocalStorage || fullScan === true) {
267
267
  // 首次使用
268
268
  const [newSHA, newStatus, option] = await Promise.all([
269
- request(api.getGameSHA()),
270
- request(api.getGameStatus()),
271
- request(api.getGameMap()),
269
+ $request(api.getGameSHA()),
270
+ $request(api.getGameStatus()),
271
+ $request(api.getGameMap()),
272
272
  ])
273
273
  commit('localStorage/setGameV2SHA', newSHA, { root: true })
274
274
  commit('localStorage/setGameV2Status', newStatus, { root: true })
@@ -287,7 +287,7 @@ function createStore(request, loadingRequest) {
287
287
 
288
288
  if (isInGamehall(currentPath)) {
289
289
  commit('_setCategoryId', id)
290
- const category = await request(api.getGameCategory({ id }))
290
+ const category = await $request(api.getGameCategory({ id }))
291
291
  const categoryChildren = category?.list || []
292
292
 
293
293
  if (state.primaryCategoryList.map((item) => item.category).includes(category.name)) {
@@ -299,7 +299,7 @@ function createStore(request, loadingRequest) {
299
299
  } else {
300
300
  commit('game/_setPrimaryCategoryList', categoryChildren, { root: true })
301
301
  const favoriteId = categoryChildren.find((item) => item.category === 'SYSTEM_MY_FAVORITE').id
302
- const category = await request(api.getGameCategory({ id: favoriteId }))
302
+ const category = await $request(api.getGameCategory({ id: favoriteId }))
303
303
  const list = category?.list || []
304
304
  commit('_setFavorite', { ...state.favorite, code: favoriteId, list: list.map((item) => item.g) })
305
305
  }
@@ -309,7 +309,7 @@ function createStore(request, loadingRequest) {
309
309
  try {
310
310
  const appendedList = [...getters.getFavoriteList, code]
311
311
  commit('_setFavoriteList', appendedList)
312
- await request(api.addFavoriteGame({ games: [code] }))
312
+ await $request(api.addFavoriteGame({ games: [code] }))
313
313
  } catch (err) {
314
314
  console.log(err)
315
315
  const restoredList = getters.getFavoriteList.filter((item) => item !== code)
@@ -320,7 +320,7 @@ function createStore(request, loadingRequest) {
320
320
  try {
321
321
  const reservedList = getters.getFavoriteList.filter((item) => item !== code)
322
322
  commit('_setFavoriteList', reservedList)
323
- await request(api.removeFavoriteGame({ games: [code] }))
323
+ await $request(api.removeFavoriteGame({ games: [code] }))
324
324
  } catch (err) {
325
325
  console.log(err)
326
326
  const restoredList = [...getters.getFavoriteList, code]
@@ -330,7 +330,7 @@ function createStore(request, loadingRequest) {
330
330
  async getStatements({ state, commit, getters, dispatch, rootState, rootGetters }) {
331
331
  try {
332
332
  commit(`core/setLoading`, true, { root: true })
333
- const data = await request(api.getStatements())
333
+ const data = await $request(api.getStatements())
334
334
  commit(`setStatements`, data)
335
335
  commit(`core/setLoading`, false, { root: true })
336
336
  return data
@@ -340,21 +340,21 @@ function createStore(request, loadingRequest) {
340
340
  }
341
341
  },
342
342
  async setPreference({}, defaultCategory) {
343
- return await request(api.setPreference({ defaultCategory }))
344
- },
345
- executeGameTimer({ state, commit, dispatch }) {
346
- clearInterval(state.gameTimer)
347
- dispatch('examineGame')
348
- const timer = setInterval(() => {
349
- dispatch('examineGame')
350
- }, 20000)
351
- commit('_setGameTimer', timer)
352
- },
343
+ return await $request(api.setPreference({ defaultCategory }))
344
+ },
345
+ // executeGameTimer({ state, commit, dispatch }) {
346
+ // clearInterval(state.gameTimer)
347
+ // dispatch('examineGame')
348
+ // const timer = setInterval(() => {
349
+ // dispatch('examineGame')
350
+ // }, 20000)
351
+ // commit('setGameTimer', timer)
352
+ // },
353
353
  async exitGame({ commit, rootGetters }) {
354
354
  const uid_site = rootGetters['user/userInfo'].uid_site
355
355
  const provider_id = rootGetters['gameStore/getCurrentProvider']
356
356
  if (provider_id) {
357
- await loadingRequest(api.logoutGame({ uid_site, provider_id }))
357
+ await $loadingRequest(api.logoutGame({ uid_site, provider_id }))
358
358
  }
359
359
  commit('setCurrentProvider', null)
360
360
  commit('setCurrentGameId', null)
@@ -386,7 +386,7 @@ function createStore(request, loadingRequest) {
386
386
  ? `${window.location.origin}/return`
387
387
  : window.location.href, // For providers to return.
388
388
  }
389
- const data = await request(api.playGame(params))
389
+ const data = await $request(api.playGame(params))
390
390
  commit('gameMatching', false)
391
391
  const targetUrl = data.redirect_url
392
392
  commit('setGameURL', targetUrl)
@@ -409,7 +409,7 @@ function createStore(request, loadingRequest) {
409
409
 
410
410
  export default (ctx, inject) => {
411
411
  const { store, $request, $loadingRequest } = ctx
412
- store.registerModule('game', createStore($request, $loadingRequest))
412
+ store.registerModule('game', createStore({$request, $loadingRequest}))
413
413
  }
414
414
 
415
415
  function extractInfoChangedGames(oldStatus, newStatus) {
package/plugin/inbox.js CHANGED
@@ -19,7 +19,7 @@ const api = {
19
19
  deleteMessage: ({ mid, isDelete }) => ({ url: 'mailbox/deleteMessage', method: 'post', params: { mid, isDelete } }),
20
20
  }
21
21
 
22
- function createStore(request) {
22
+ function createStore({$request}) {
23
23
  return {
24
24
  namespaced: true,
25
25
  state: () => ({
@@ -60,6 +60,11 @@ function createStore(request) {
60
60
  _getTabContent(state, getters) {
61
61
  return state.inbox.find((item) => item.tab === state.tab) || {}
62
62
  },
63
+ shouldOpenInbox(state, getters, rootState, rootGetters) {
64
+ const isEnable = rootGetters['core/getSiteConfig'].mailboxEnable === '1'
65
+ const isModalOpening = rootGetters['core/getModal']?.type
66
+ return isEnable && !state.isCrash && !isModalOpening && getters.hasSystemMessage
67
+ }
63
68
  },
64
69
  mutations: {
65
70
  _setSummary(state, data) {
@@ -89,7 +94,7 @@ function createStore(request) {
89
94
  },
90
95
  actions: {
91
96
  async initialize({ state, getters, commit, dispatch }) {
92
- const { data = [] } = await request(api.getMessageTypes())
97
+ const { data = [] } = await $request(api.getMessageTypes())
93
98
  const tabList = data?.map((item) => item.type)
94
99
  const inbox = tabList.map((type) => ({ tab: type, data: [], page: -1 }))
95
100
  commit('_setTabList', tabList)
@@ -107,7 +112,7 @@ function createStore(request) {
107
112
 
108
113
  if (!totalPage || maxIndex > nextIndex) {
109
114
  try {
110
- const data = await request(api.getMessageList({ type: tab, page: nextIndex }))
115
+ const data = await $request(api.getMessageList({ type: tab, page: nextIndex }))
111
116
  if (data.data.length === 0) {
112
117
  complete()
113
118
  return
@@ -199,7 +204,7 @@ function createStore(request) {
199
204
  }
200
205
  })
201
206
  commit('_setInbox', cloneInbox)
202
- request(api.updateMessage({ groupId: message.groupId, isRead: true }))
207
+ $request(api.updateMessage({ groupId: message.groupId, isRead: true }))
203
208
  },
204
209
  },
205
210
  }
@@ -207,5 +212,5 @@ function createStore(request) {
207
212
 
208
213
  export default (ctx, inject) => {
209
214
  const { store, $request } = ctx
210
- store.registerModule('inbox', createStore($request))
215
+ store.registerModule('inbox', createStore({$request}))
211
216
  }
@@ -1,4 +1,4 @@
1
- function createStore(request) {
1
+ function createStore({$request}) {
2
2
  return {
3
3
  namespaced: true,
4
4
  state: () => ({
@@ -53,5 +53,5 @@ function createStore(request) {
53
53
 
54
54
  export default (ctx, inject) => {
55
55
  const { store, $request } = ctx
56
- store.registerModule('information', createStore($request))
56
+ store.registerModule('information', createStore({$request}))
57
57
  }
@@ -0,0 +1,59 @@
1
+ const timeout = 60 * 1000
2
+ export default async ({ app, store, $cuoraConfig }, inject) => {
3
+ if (!$cuoraConfig) {
4
+ throw Error('network plugin must be after CuoraConfig module')
5
+ }
6
+ const url = `https://storage.googleapis.com/btc-storage-rd/site_resources/${$cuoraConfig.clientId}/target/target.json`
7
+ const networkTester = new NetworkTester(url)
8
+ $cuoraConfig.apiURL = await networkTester.test()
9
+ setInterval(async () => {
10
+ $cuoraConfig.apiURL = await networkTester.test()
11
+ }, timeout)
12
+ inject('networkTester', networkTester)
13
+ }
14
+
15
+ class NetworkTester {
16
+ constructor(url) {
17
+ this.url = url
18
+ this.host = []
19
+ this.cdn = []
20
+ }
21
+
22
+ async init() {
23
+ const target = await fetch(this.url)
24
+ const { host, cdn } = await target.json()
25
+ this.host = host
26
+ this.cdn = cdn
27
+ }
28
+
29
+ async test() {
30
+ try {
31
+ if (this.host.length === 0) {
32
+ await this.init()
33
+ }
34
+ const { url, index } = await Promise.any(
35
+ this.host.map((url, i) => {
36
+ return this.ping(url, i)
37
+ })
38
+ )
39
+ console.info(`[Network] Host ${index} is chosen. (${url})`)
40
+ return url
41
+ } catch (error) {
42
+ console.error('[Network] Network Test Fail.', error)
43
+ return this.host[0]
44
+ }
45
+ }
46
+
47
+ async ping(url, index) {
48
+ let ts, response
49
+ try {
50
+ ts = new Date().getTime()
51
+ response = await fetch(`${url}/health?ts=${ts}`)
52
+ return { url, index }
53
+ } finally {
54
+ const speed = new Date().getTime() - ts
55
+ const status = !!response?.ok ? 'Success' : 'Failure'
56
+ console.info(`[Network] Host: ${index}, URL: ${url}, Status: ${status}, Speed: ${speed}ms`)
57
+ }
58
+ }
59
+ }
package/plugin/payment.js CHANGED
@@ -31,7 +31,7 @@ const api = {
31
31
  mergeWallet: () => ({ url: 'payment/mergeWallet', method: 'post' }),
32
32
  }
33
33
 
34
- function createStore(request, loadingRequest, ignoreErrorRequest) {
34
+ function createStore({ $request, $loadingRequest, $ignoreErrorRequest }) {
35
35
  return {
36
36
  namespaced: true,
37
37
  state: () => ({
@@ -99,7 +99,7 @@ function createStore(request, loadingRequest, ignoreErrorRequest) {
99
99
  async getPaymentHistory({ commit, getters }) {
100
100
  try {
101
101
  commit(`core/setLoading`, true, { root: true })
102
- const data = await request(api.getPaymentHistory())
102
+ const data = await $request(api.getPaymentHistory())
103
103
  commit(`core/setLoading`, false, { root: true })
104
104
  return data
105
105
  } catch (err) {
@@ -110,7 +110,7 @@ function createStore(request, loadingRequest, ignoreErrorRequest) {
110
110
  async sentAward({ commit, getters, dispatch }, rewardTarget) {
111
111
  try {
112
112
  commit(`core/setLoading`, true, { root: true })
113
- const { data } = await request(api.sentAward({ appSecret: clientSecret, ...rewardTarget }))
113
+ const { data } = await $request(api.sentAward({ appSecret: clientSecret, ...rewardTarget }))
114
114
  await dispatch('activity/fetchActivities', null, { root: true })
115
115
  commit(`core/setLoading`, false, { root: true })
116
116
  return data
@@ -122,7 +122,7 @@ function createStore(request, loadingRequest, ignoreErrorRequest) {
122
122
  async getReward({ commit, getters, dispatch }, rewardTarget) {
123
123
  try {
124
124
  commit(`core/setLoading`, true, { root: true })
125
- const { data } = await request(api.getReward({ appSecret: clientSecret, ...rewardTarget }))
125
+ const { data } = await $request(api.getReward({ appSecret: clientSecret, ...rewardTarget }))
126
126
  await dispatch('activity/fetchActivities', null, { root: true })
127
127
  commit(`core/setLoading`, false, { root: true })
128
128
  return data
@@ -133,7 +133,7 @@ function createStore(request, loadingRequest, ignoreErrorRequest) {
133
133
  },
134
134
  async getRewardList({ commit }) {
135
135
  try {
136
- const rewards = await request(api.getRewardList({ count: 30, appSecret: clientSecret }))
136
+ const rewards = await $request(api.getRewardList({ count: 30, appSecret: clientSecret }))
137
137
  commit(`activity/setActivities`, { rewards: rewards?.data || {} }, { root: true })
138
138
  } catch (err) {
139
139
  console.log(err)
@@ -142,7 +142,7 @@ function createStore(request, loadingRequest, ignoreErrorRequest) {
142
142
  async getPaymentInfo({ commit }) {
143
143
  try {
144
144
  commit(`core/setLoading`, true, { root: true })
145
- const paymentInfo = await request(api.getPaymentInfo())
145
+ const paymentInfo = await $request(api.getPaymentInfo())
146
146
  commit(`core/setLoading`, false, { root: true })
147
147
  return paymentInfo
148
148
  } catch (err) {
@@ -151,13 +151,13 @@ function createStore(request, loadingRequest, ignoreErrorRequest) {
151
151
  }
152
152
  },
153
153
  async updatePaymentInfo({ dispatch }, payload) {
154
- const data = loadingRequest(api.updatePaymentInfo(payload))
154
+ const data = $loadingRequest(api.updatePaymentInfo(payload))
155
155
  await dispatch('core/fetchUserInfo', null, { root: true })
156
156
  return data
157
157
  },
158
158
  async fetchAvailableBanks({ commit }, paymentMethod = 'amb') {
159
159
  try {
160
- const data = await request(api.getBankList(paymentMethod))
160
+ const data = await $request(api.getBankList(paymentMethod))
161
161
  commit(`setAvailableBanks`, data)
162
162
  return data
163
163
  } catch (err) {
@@ -169,7 +169,7 @@ function createStore(request, loadingRequest, ignoreErrorRequest) {
169
169
  const status = await dispatch('core/checkStatus', null, { root: true })
170
170
  if (status === true) {
171
171
  commit(`core/setLoading`, true, { root: true })
172
- const data = await request(api.makeTransaction({ type, payload, paymentMethod }))
172
+ const data = await $request(api.makeTransaction({ type, payload, paymentMethod }))
173
173
  commit(`core/setLoading`, false, { root: true })
174
174
  return data
175
175
  } else {
@@ -183,13 +183,13 @@ function createStore(request, loadingRequest, ignoreErrorRequest) {
183
183
  const done = getters.getRefreshBank
184
184
  if (!done) {
185
185
  commit('setRefreshBank', true)
186
- await ignoreErrorRequest(api.makeTransaction( { type: 'DEPOSIT', payload: null, paymentMethod: 'amb' }))
186
+ await $ignoreErrorRequest(api.makeTransaction( { type: 'DEPOSIT', payload: null, paymentMethod: 'amb' }))
187
187
  }
188
188
  },
189
189
  async checkTransaction({ commit, dispatch }, paymentMethod) {
190
190
  try {
191
191
  commit(`core/setLoading`, true, { root: true })
192
- const data = await request(api.checkTransaction(paymentMethod))
192
+ const data = await $request(api.checkTransaction(paymentMethod))
193
193
  commit(`core/setLoading`, false, { root: true })
194
194
  return data
195
195
  } catch (err) {
@@ -209,23 +209,23 @@ function createStore(request, loadingRequest, ignoreErrorRequest) {
209
209
  }
210
210
  },
211
211
  async collect({ commit, dispatch }, activityNo) {
212
- const { data } = await loadingRequest(api.collect({ appSecret: clientSecret }))
212
+ const { data } = await $loadingRequest(api.collect({ appSecret: clientSecret }))
213
213
  await dispatch('getActivityDetail', activityNo, { root: true })
214
214
  },
215
215
  async setBonusSetting({ commit, dispatch }, data) {
216
- return await loadingRequest(api.setBonusSetting({ bonus: data }))
216
+ return await $loadingRequest(api.setBonusSetting({ bonus: data }))
217
217
  },
218
218
  async getCurrentWithdrawRule({ commit, dispatch }) {
219
- const currentRule = await request(api.getCurrentWithdrawRule())
219
+ const currentRule = await $request(api.getCurrentWithdrawRule())
220
220
  return ruleFormatter(currentRule.rules)
221
221
  },
222
222
  async convertFreeCredit({ dispatch }, exchangeType) {
223
- const convertResult = await loadingRequest(api.convertFreeCredit({ exchangeType }))
223
+ const convertResult = await $loadingRequest(api.convertFreeCredit({ exchangeType }))
224
224
  await dispatch('core/fetchUserInfo', null, { root: true })
225
225
  return convertResult
226
226
  },
227
227
  async mergeWallet({ dispatch }) {
228
- const convertResult = await loadingRequest(api.mergeWallet())
228
+ const convertResult = await $loadingRequest(api.mergeWallet())
229
229
  await dispatch('core/fetchUserInfo', null, { root: true })
230
230
  return convertResult
231
231
  },
@@ -235,7 +235,7 @@ function createStore(request, loadingRequest, ignoreErrorRequest) {
235
235
 
236
236
  export default (ctx, inject) => {
237
237
  const { store, $request, $loadingRequest, $ignoreErrorRequest } = ctx
238
- store.registerModule('payment', createStore($request, $loadingRequest, $ignoreErrorRequest))
238
+ store.registerModule('payment', createStore({ $request, $loadingRequest, $ignoreErrorRequest }))
239
239
  }
240
240
 
241
241
  function ruleFormatter(rules) {
package/plugin/request.js CHANGED
@@ -2,20 +2,43 @@ import pickBy from 'lodash/pickBy'
2
2
  import Cookies from 'universal-cookie'
3
3
  import urljoin from 'url-join'
4
4
 
5
- const apiURL = process.env.API_URL
6
- const apiVersion = process.env.API_VERSION
7
- const clientId = process.env.CLIENT_ID
8
- const product = 'pwa'
9
- // const version = process.env.npm_package_version
5
+ class CuoraConfig {
6
+ constructor({apiURL, apiVersion, clientId, product, version}) {
7
+ this._apiURL = apiURL
8
+ this._apiVersion = apiVersion
9
+ this._clientId = clientId
10
+ this.product = product
11
+ this.version = version
12
+ this.fullURL = urljoin(this._apiURL, this._apiVersion, this._clientId)
13
+ }
14
+
15
+ set apiURL(url) {
16
+ this._apiURL = url
17
+ this.fullURL = urljoin(this._apiURL, this._apiVersion, this._clientId)
18
+ }
19
+
20
+ get apiURL() {
21
+ return this._apiURL
22
+ }
23
+
24
+ set apiVersion(version) {
25
+ this._apiVersion = version
26
+ this.fullURL = urljoin(this._apiURL, this._apiVersion, this._clientId)
27
+ }
28
+
29
+ get apiVersion() {
30
+ return this._apiVersion
31
+ }
10
32
 
11
- // const apiURL = '<%= options.apiURL %>';
12
- // const apiVersion = '<%= options.apiVersion %>';
13
- // const clientId = '<%= options.clientId %>';
14
- // const product = '<%= options.product %>';
15
- const version = 'v<%= options.version %>'
33
+ set clientId(id) {
34
+ this._clientId = id
35
+ this.fullURL = urljoin(this._apiURL, this._apiVersion, this._clientId)
36
+ }
16
37
 
17
- const tokenKey = `cuora_${clientId}`
18
- const fullURL = urljoin(apiURL, apiVersion, clientId)
38
+ get clientId() {
39
+ return this._clientId
40
+ }
41
+ }
19
42
 
20
43
  class Cookie {
21
44
  constructor(tokenKey) {
@@ -30,6 +53,13 @@ class Cookie {
30
53
  })
31
54
  }
32
55
 
56
+ prolongToken() {
57
+ const token = this.getToken()
58
+ if (token) {
59
+ this.setToken(token)
60
+ }
61
+ }
62
+
33
63
  getToken() {
34
64
  return this.cookies.get(this.tokenKey)
35
65
  }
@@ -53,25 +83,30 @@ class Cookie {
53
83
  }
54
84
  }
55
85
 
86
+ const cuoraConfig = new CuoraConfig({
87
+ apiURL: process.env.API_URL,
88
+ apiVersion: process.env.API_VERSION,
89
+ clientId: process.env.CLIENT_ID,
90
+ product: 'pwa',
91
+ version: 'v<%= options.version %>'
92
+ })
93
+ const tokenKey = `cuora_${cuoraConfig.clientId}`
56
94
  const cookie = new Cookie(tokenKey)
57
95
 
58
- function createMethods($axios, store) {
59
- const instance = $axios.create({
60
- baseURL: fullURL,
61
- })
96
+ function createMethods($axios, store, cuoraConfig) {
62
97
  const CancelToken = $axios.CancelToken
63
98
  let source = CancelToken.source()
64
99
 
65
- instance.interceptors.request.use((config) => {
66
- config.headers['X-TH1GAMES-VERSION'] = version
67
- config.headers['X-TH1GAMES-PLATFORM'] = product
100
+ $axios.interceptors.request.use((config) => {
101
+ config.headers['X-TH1GAMES-VERSION'] = cuoraConfig.version
102
+ config.headers['X-TH1GAMES-PLATFORM'] = cuoraConfig.product
68
103
  if (cookie.getToken()) {
69
104
  config.headers.Authorization = cookie.getToken()
70
105
  }
71
106
  return config
72
107
  })
73
108
 
74
- instance.interceptors.response.use(
109
+ $axios.interceptors.response.use(
75
110
  function (response) {
76
111
  if (response.data.error) {
77
112
  return Promise.reject(response.data.error)
@@ -91,8 +126,8 @@ function createMethods($axios, store) {
91
126
  try {
92
127
  const cancelToken = customToken || source.token
93
128
  checkToken(req, cookie.getToken())
94
- const config = createConfig(req, cancelToken)
95
- const { data } = await instance.request(config)
129
+ const config = createConfig(cuoraConfig, req, cancelToken)
130
+ const { data } = await $axios.request(config)
96
131
  return data
97
132
  } catch (error) {
98
133
  if (error.code) {
@@ -106,8 +141,8 @@ function createMethods($axios, store) {
106
141
  store.commit('core/setLoading', true)
107
142
  const cancelToken = customToken || source.token
108
143
  checkToken(req, cookie.getToken())
109
- const config = createConfig(req, cancelToken)
110
- const { data } = await instance.request(config)
144
+ const config = createConfig(cuoraConfig, req, cancelToken)
145
+ const { data } = await $axios.request(config)
111
146
  return data
112
147
  } catch (error) {
113
148
  if (error.code) {
@@ -122,8 +157,8 @@ function createMethods($axios, store) {
122
157
  try {
123
158
  const cancelToken = customToken || source.token
124
159
  checkToken(req, cookie.getToken())
125
- const config = createConfig(req, cancelToken)
126
- const { data } = await instance.request(config)
160
+ const config = createConfig(cuoraConfig, req, cancelToken)
161
+ const { data } = await $axios.request(config)
127
162
  return data
128
163
  } catch (error) {
129
164
  console.log('[ Ignore Error ] ', error)
@@ -139,9 +174,9 @@ function createMethods($axios, store) {
139
174
  }
140
175
  }
141
176
 
142
- function createConfig(req, cancelToken) {
177
+ function createConfig(cuoraConfig, req, cancelToken) {
143
178
  const { method, url, params } = req
144
- const config = { method, url, cancelToken, public: req.public }
179
+ const config = { baseURL: cuoraConfig.fullURL, method, url, cancelToken, public: req.public }
145
180
  if (method.toUpperCase() === 'GET') {
146
181
  config.params = pickBy(params, checkValuable)
147
182
  } else {
@@ -162,12 +197,13 @@ function checkToken(req, token) {
162
197
 
163
198
  export default (ctx, inject) => {
164
199
  const { $axios, store } = ctx
165
- const { normal, loading, ignoreError, updateSource, generateSource } = createMethods($axios, store)
200
+ const { normal, loading, ignoreError, updateSource, generateSource } = createMethods($axios, store, cuoraConfig)
166
201
  inject('request', normal)
167
202
  inject('loadingRequest', loading)
168
203
  inject('ignoreErrorRequest', ignoreError)
169
204
  inject('updateSource', updateSource)
170
205
  inject('generateSource', generateSource)
171
206
  inject('cookie', cookie)
172
- inject('fullURL', fullURL)
207
+ inject('fullURL', cuoraConfig.fullURL)
208
+ inject('cuoraConfig', cuoraConfig)
173
209
  }
package/plugin/search.js CHANGED
@@ -22,7 +22,7 @@ const api = {
22
22
 
23
23
  let source = null
24
24
 
25
- function createStore(request, generateSource) {
25
+ function createStore({$request, $generateSource}) {
26
26
  return {
27
27
  namespaced: true,
28
28
  state: () => ({
@@ -229,14 +229,14 @@ function createStore(request, generateSource) {
229
229
  if (source) {
230
230
  source.cancel('Requests Cancelled')
231
231
  }
232
- source = generateSource()
233
- return await request(api.getGameTags({ q }), source.token)
232
+ source = $generateSource()
233
+ return await $request(api.getGameTags({ q }), source.token)
234
234
  },
235
235
  async getGameSearchList({}, { id, index, q, click, clickDefault }) {
236
- return await request(api.getGameSearchList({ id, index, q, click, clickDefault }))
236
+ return await $request(api.getGameSearchList({ id, index, q, click, clickDefault }))
237
237
  },
238
238
  async setGameSearchTrace({}, { traceId, tagId, tagIndex, gameCode, gameCodeIndex, query, click }) {
239
- return await request(
239
+ return await $request(
240
240
  api.setGameSearchTrace({
241
241
  traceId,
242
242
  tagId,
@@ -254,7 +254,7 @@ function createStore(request, generateSource) {
254
254
 
255
255
  export default (ctx, inject) => {
256
256
  const { store, $request, $generateSource } = ctx
257
- store.registerModule('search', createStore($request, $generateSource))
257
+ store.registerModule('search', createStore({$request, $generateSource}))
258
258
  }
259
259
 
260
260
  function wait(interval, fn) {
package/plugin/user.js CHANGED
@@ -8,12 +8,17 @@ const api = {
8
8
  getAffiliate: () => ({ url: 'affiliate', method: 'get' }),
9
9
  postAffiliate: ({ affiliateCode }) => ({ url: 'affiliate', method: 'post', params: { affiliateCode } }),
10
10
  passwordRecovery: (recoveryData) => ({ url: () => 'recovery', method: 'post', params: recoveryData, public: true }),
11
- passwordAbandon: ({number}) => ({ url: () => 'recovery/abandon', method: 'post', params: {number}, public: true }),
11
+ passwordAbandon: ({ number }) => ({
12
+ url: () => 'recovery/abandon',
13
+ method: 'post',
14
+ params: { number },
15
+ public: true,
16
+ }),
12
17
  passwordAcknowledge: (acknowledgeData) => ({
13
18
  url: () => 'recovery/acknowledge',
14
19
  method: 'post',
15
20
  params: acknowledgeData,
16
- public: true
21
+ public: true,
17
22
  }),
18
23
  verify: () => ({ url: 'verify', method: 'post' }),
19
24
  acknowledge: ({ requestId, code }) => ({ url: 'acknowledge', method: 'post', params: { requestId, code } }),
@@ -27,7 +32,7 @@ function createStore({ $request, $loadingRequest, $fullURL }) {
27
32
  savedLevel: null,
28
33
  isInline: false,
29
34
  recoveryData: {},
30
- userInfoFlag: false
35
+ userInfoFlag: false,
31
36
  }),
32
37
  getters: {
33
38
  isLocked(state, getters) {
@@ -101,17 +106,13 @@ function createStore({ $request, $loadingRequest, $fullURL }) {
101
106
  },
102
107
  setUserInfoFlag(state, data) {
103
108
  state.userInfoFlag = data
104
- }
109
+ },
105
110
  },
106
111
  actions: {
107
112
  async modifyUserInfo({ commit }, payload) {
108
113
  try {
109
- commit(`core/setLoading`, true, { root: true })
110
- const data = await $request(api.updateUserInfo(payload))
111
- commit(`core/setLoading`, false, { root: true })
112
- return data
114
+ return await $loadingRequest(api.updateUserInfo(payload))
113
115
  } catch (err) {
114
- commit(`core/setLoading`, false, { root: true })
115
116
  console.log(err)
116
117
  }
117
118
  },
@@ -129,24 +130,16 @@ function createStore({ $request, $loadingRequest, $fullURL }) {
129
130
  }
130
131
  },
131
132
  async changePassword({ commit }, payload) {
132
- try {
133
- commit(`core/setLoading`, true, { root: true })
134
- const data = await $request(api.changePassword(payload))
135
- commit(`core/setLoading`, false, { root: true })
136
- return data
137
- } catch (err) {
138
- commit(`core/setLoading`, false, { root: true })
139
- throw err
140
- }
133
+ return await $loadingRequest(api.changePassword(payload))
141
134
  },
142
135
  async resetOTP({ commit }, { requestId, number }) {
143
136
  try {
144
137
  commit(`core/setLoading`, true, { root: true })
145
138
  const data = await $request(api.reset({ requestId, number }))
146
139
  commit(`core/setVerificationData`, data, { root: true })
147
- commit(`core/setLoading`, false, { root: true })
148
140
  } catch (err) {
149
141
  console.log(err)
142
+ } finally {
150
143
  commit(`core/setLoading`, false, { root: true })
151
144
  }
152
145
  },
@@ -157,7 +150,7 @@ function createStore({ $request, $loadingRequest, $fullURL }) {
157
150
  return await $request(api.postAffiliate({ affiliateCode }))
158
151
  },
159
152
  async passwordAbandon({ commit }, number) {
160
- await $request(api.passwordAbandon({number}))
153
+ await $request(api.passwordAbandon({ number }))
161
154
  commit(`setRecoveryData`, {})
162
155
  },
163
156
  async passwordRecovery({ commit }, recoveryData) {