@jetthai/cuora 1.0.18 → 1.0.20
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 +1 -0
- package/package.json +1 -1
- package/plugin/activity.js +9 -0
- package/plugin/request.js +30 -7
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.20](https://github.com/jetthai/cuora-module/compare/v1.0.19...v1.0.20) (2021-08-23)
|
|
6
|
+
|
|
7
|
+
### [1.0.19](https://github.com/jetthai/cuora-module/compare/v1.0.18...v1.0.19) (2021-08-20)
|
|
8
|
+
|
|
5
9
|
### [1.0.18](https://github.com/jetthai/cuora-module/compare/v1.0.17...v1.0.18) (2021-08-20)
|
|
6
10
|
|
|
7
11
|
### [1.0.17](https://github.com/jetthai/cuora-module/compare/v1.0.16...v1.0.17) (2021-08-19)
|
package/index.js
CHANGED
package/package.json
CHANGED
package/plugin/activity.js
CHANGED
|
@@ -25,6 +25,11 @@ const api = {
|
|
|
25
25
|
params: { achievementNo, appSecret },
|
|
26
26
|
}),
|
|
27
27
|
getAchievementsIssued: () => ({ url: 'activities/achievements/issue', method: 'get' }),
|
|
28
|
+
postPromoCode: (promoCode) => ({
|
|
29
|
+
url: 'activities/promo',
|
|
30
|
+
method: 'post',
|
|
31
|
+
params: {promoCode}
|
|
32
|
+
})
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
const clientSecret = process.env.CLIENT_SECRET
|
|
@@ -270,6 +275,10 @@ function createStore({$request}) {
|
|
|
270
275
|
const { data } = await $request.send(api.getAchievementsProgress({ achievementNo, appSecret: clientSecret }))
|
|
271
276
|
return data
|
|
272
277
|
},
|
|
278
|
+
async postPromoCode({}, promoCode) {
|
|
279
|
+
const { data } = await $request.send(api.postPromoCode(promoCode))
|
|
280
|
+
return data
|
|
281
|
+
}
|
|
273
282
|
},
|
|
274
283
|
}
|
|
275
284
|
}
|
package/plugin/request.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import axiosRetry from 'axios-retry'
|
|
1
3
|
import pickBy from 'lodash/pickBy'
|
|
2
4
|
import Cookies from 'universal-cookie'
|
|
3
5
|
import urljoin from 'url-join'
|
|
4
6
|
|
|
7
|
+
axiosRetry(axios, {retries: 3})
|
|
8
|
+
|
|
5
9
|
class CuoraConfig {
|
|
6
10
|
constructor({ apiURL, apiVersion, clientId, imageUrl, product, version }) {
|
|
7
11
|
this._apiURL = apiURL
|
|
@@ -93,15 +97,23 @@ class Cookie {
|
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
class Request {
|
|
96
|
-
constructor(axios
|
|
100
|
+
constructor(axios) {
|
|
97
101
|
this.axios = axios
|
|
98
|
-
this.store =
|
|
102
|
+
this.store = null
|
|
99
103
|
this.source = axios.CancelToken.source()
|
|
104
|
+
this.config = null
|
|
105
|
+
this.cookie = null
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
setConfig(config) {
|
|
100
109
|
this.config = config
|
|
101
|
-
this.cookie = cookie
|
|
102
110
|
this.initialize()
|
|
103
111
|
}
|
|
104
|
-
|
|
112
|
+
|
|
113
|
+
setCookie(cookie) {
|
|
114
|
+
this.cookie = cookie
|
|
115
|
+
}
|
|
116
|
+
|
|
105
117
|
initialize() {
|
|
106
118
|
this.axios.interceptors.request.use((config) => {
|
|
107
119
|
config.headers['X-TH1GAMES-VERSION'] = this.config.version
|
|
@@ -127,7 +139,11 @@ class Request {
|
|
|
127
139
|
}
|
|
128
140
|
)
|
|
129
141
|
}
|
|
130
|
-
|
|
142
|
+
|
|
143
|
+
setStore(store) {
|
|
144
|
+
this.store = store
|
|
145
|
+
}
|
|
146
|
+
|
|
131
147
|
async send(req, customToken) {
|
|
132
148
|
try {
|
|
133
149
|
const cancelToken = customToken || this.source.token
|
|
@@ -204,8 +220,11 @@ class Request {
|
|
|
204
220
|
}
|
|
205
221
|
}
|
|
206
222
|
|
|
223
|
+
const request = new Request(axios)
|
|
224
|
+
|
|
207
225
|
export default (ctx, inject) => {
|
|
208
|
-
const {
|
|
226
|
+
const { store } = ctx
|
|
227
|
+
request.setStore(store)
|
|
209
228
|
const cuoraConfig = new CuoraConfig({
|
|
210
229
|
apiURL: process.env.API_URL,
|
|
211
230
|
apiVersion: process.env.API_VERSION,
|
|
@@ -214,6 +233,10 @@ export default (ctx, inject) => {
|
|
|
214
233
|
product: 'pwa',
|
|
215
234
|
version: 'v<%= options.version %>',
|
|
216
235
|
})
|
|
236
|
+
request.setConfig(cuoraConfig)
|
|
217
237
|
const cookie = new Cookie(`cuora_${cuoraConfig.clientId}`)
|
|
218
|
-
|
|
238
|
+
request.setCookie(cookie)
|
|
239
|
+
inject('request', request)
|
|
219
240
|
}
|
|
241
|
+
|
|
242
|
+
export { request }
|