@jetthai/cuora 1.0.20 → 1.0.22
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 +4 -0
- package/index.js +0 -1
- package/package.json +1 -1
- package/plugin/job/network.js +3 -1
- package/plugin/payment.js +2 -2
- package/plugin/request.js +11 -28
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
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.22](https://github.com/jetthai/cuora-module/compare/v1.0.21...v1.0.22) (2021-08-25)
|
|
6
|
+
|
|
7
|
+
### [1.0.21](https://github.com/jetthai/cuora-module/compare/v1.0.20...v1.0.21) (2021-08-23)
|
|
8
|
+
|
|
5
9
|
### [1.0.20](https://github.com/jetthai/cuora-module/compare/v1.0.19...v1.0.20) (2021-08-23)
|
|
6
10
|
|
|
7
11
|
### [1.0.19](https://github.com/jetthai/cuora-module/compare/v1.0.18...v1.0.19) (2021-08-20)
|
package/index.js
CHANGED
package/package.json
CHANGED
package/plugin/job/network.js
CHANGED
|
@@ -3,6 +3,7 @@ export default async ({ $request }, inject) => {
|
|
|
3
3
|
if (!$request.config) {
|
|
4
4
|
throw Error('network plugin must be after CuoraConfig module')
|
|
5
5
|
}
|
|
6
|
+
// todo - prod bucket name btc-storage-rd / btc-storage-prod
|
|
6
7
|
const url = `https://storage.googleapis.com/btc-storage-rd/site_resources/${$request.config.clientId}/target/target.json`
|
|
7
8
|
const networkTester = new NetworkTester(url)
|
|
8
9
|
$request.config.apiURL = await networkTester.test()
|
|
@@ -40,7 +41,8 @@ class NetworkTester {
|
|
|
40
41
|
return url
|
|
41
42
|
} catch (error) {
|
|
42
43
|
console.error('[Network] Network Test Fail.', error)
|
|
43
|
-
return
|
|
44
|
+
// todo - return default apiURL
|
|
45
|
+
return
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
|
package/plugin/payment.js
CHANGED
|
@@ -205,7 +205,7 @@ function createStore({ $request }) {
|
|
|
205
205
|
try {
|
|
206
206
|
commit(`core/setLoading`, true, { root: true })
|
|
207
207
|
const { data } = await this.call('exchange', { appSecret: clientSecret, ...exchangeTarget })
|
|
208
|
-
await dispatch('getActivityDetail', exchangeTarget.activityNo, { root: true })
|
|
208
|
+
await dispatch('activity/getActivityDetail', exchangeTarget.activityNo, { root: true })
|
|
209
209
|
commit(`core/setLoading`, false, { root: true })
|
|
210
210
|
return data
|
|
211
211
|
} catch (err) {
|
|
@@ -214,7 +214,7 @@ function createStore({ $request }) {
|
|
|
214
214
|
},
|
|
215
215
|
async collect({ commit, dispatch }, activityNo) {
|
|
216
216
|
const { data } = await $request.sendWithLoading(api.collect({ appSecret: clientSecret }))
|
|
217
|
-
await dispatch('getActivityDetail', activityNo, { root: true })
|
|
217
|
+
await dispatch('activity/getActivityDetail', activityNo, { root: true })
|
|
218
218
|
},
|
|
219
219
|
async setBonusSetting({ commit, dispatch }, data) {
|
|
220
220
|
return await $request.sendWithLoading(api.setBonusSetting({ bonus: data }))
|
package/plugin/request.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import axios from 'axios'
|
|
2
|
-
import axiosRetry from 'axios-retry'
|
|
3
1
|
import pickBy from 'lodash/pickBy'
|
|
4
2
|
import Cookies from 'universal-cookie'
|
|
5
3
|
import urljoin from 'url-join'
|
|
6
4
|
|
|
7
|
-
axiosRetry(axios, {retries: 3})
|
|
8
|
-
|
|
9
5
|
class CuoraConfig {
|
|
10
6
|
constructor({ apiURL, apiVersion, clientId, imageUrl, product, version }) {
|
|
11
7
|
this._apiURL = apiURL
|
|
@@ -97,23 +93,16 @@ class Cookie {
|
|
|
97
93
|
}
|
|
98
94
|
|
|
99
95
|
class Request {
|
|
100
|
-
constructor(axios) {
|
|
96
|
+
constructor(axios, store, config, cookie) {
|
|
101
97
|
this.axios = axios
|
|
102
|
-
this.store =
|
|
98
|
+
this.store = store
|
|
103
99
|
this.source = axios.CancelToken.source()
|
|
104
|
-
this.config = null
|
|
105
|
-
this.cookie = null
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
setConfig(config) {
|
|
109
100
|
this.config = config
|
|
110
|
-
this.initialize()
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
setCookie(cookie) {
|
|
114
101
|
this.cookie = cookie
|
|
102
|
+
this.errorHandler = null
|
|
103
|
+
this.initialize()
|
|
115
104
|
}
|
|
116
|
-
|
|
105
|
+
|
|
117
106
|
initialize() {
|
|
118
107
|
this.axios.interceptors.request.use((config) => {
|
|
119
108
|
config.headers['X-TH1GAMES-VERSION'] = this.config.version
|
|
@@ -139,9 +128,9 @@ class Request {
|
|
|
139
128
|
}
|
|
140
129
|
)
|
|
141
130
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
this.
|
|
131
|
+
|
|
132
|
+
setErrorHandler(handler) {
|
|
133
|
+
this.errorHandler = handler
|
|
145
134
|
}
|
|
146
135
|
|
|
147
136
|
async send(req, customToken) {
|
|
@@ -153,6 +142,7 @@ class Request {
|
|
|
153
142
|
return data
|
|
154
143
|
} catch (error) {
|
|
155
144
|
if (error.code) {
|
|
145
|
+
this.errorHandler && this.errorHandler(error)
|
|
156
146
|
this.store.commit('core/setGlobalError', error)
|
|
157
147
|
}
|
|
158
148
|
throw error
|
|
@@ -220,11 +210,8 @@ class Request {
|
|
|
220
210
|
}
|
|
221
211
|
}
|
|
222
212
|
|
|
223
|
-
const request = new Request(axios)
|
|
224
|
-
|
|
225
213
|
export default (ctx, inject) => {
|
|
226
|
-
const { store } = ctx
|
|
227
|
-
request.setStore(store)
|
|
214
|
+
const { $axios, store } = ctx
|
|
228
215
|
const cuoraConfig = new CuoraConfig({
|
|
229
216
|
apiURL: process.env.API_URL,
|
|
230
217
|
apiVersion: process.env.API_VERSION,
|
|
@@ -233,10 +220,6 @@ export default (ctx, inject) => {
|
|
|
233
220
|
product: 'pwa',
|
|
234
221
|
version: 'v<%= options.version %>',
|
|
235
222
|
})
|
|
236
|
-
request.setConfig(cuoraConfig)
|
|
237
223
|
const cookie = new Cookie(`cuora_${cuoraConfig.clientId}`)
|
|
238
|
-
request
|
|
239
|
-
inject('request', request)
|
|
224
|
+
inject('request', new Request($axios, store, cuoraConfig, cookie))
|
|
240
225
|
}
|
|
241
|
-
|
|
242
|
-
export { request }
|