@jetthai/cuora 1.0.19 → 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 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.20](https://github.com/jetthai/cuora-module/compare/v1.0.19...v1.0.20) (2021-08-23)
6
+
5
7
  ### [1.0.19](https://github.com/jetthai/cuora-module/compare/v1.0.18...v1.0.19) (2021-08-20)
6
8
 
7
9
  ### [1.0.18](https://github.com/jetthai/cuora-module/compare/v1.0.17...v1.0.18) (2021-08-20)
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import path from 'path'
2
+ export { request } from './plugin/request'
2
3
 
3
4
  export default function (moduleOptions) {
4
5
  const options = { ...this.options.cuora, ...moduleOptions }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
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, store, config, cookie) {
100
+ constructor(axios) {
97
101
  this.axios = axios
98
- this.store = 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 { $axios, store } = ctx
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
- inject('request', new Request($axios, store, cuoraConfig, cookie))
238
+ request.setCookie(cookie)
239
+ inject('request', request)
219
240
  }
241
+
242
+ export { request }