@jetthai/cuora 1.0.20 → 1.0.21

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.21](https://github.com/jetthai/cuora-module/compare/v1.0.20...v1.0.21) (2021-08-23)
6
+
5
7
  ### [1.0.20](https://github.com/jetthai/cuora-module/compare/v1.0.19...v1.0.20) (2021-08-23)
6
8
 
7
9
  ### [1.0.19](https://github.com/jetthai/cuora-module/compare/v1.0.18...v1.0.19) (2021-08-20)
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import path from 'path'
2
- export { request } from './plugin/request'
3
2
 
4
3
  export default function (moduleOptions) {
5
4
  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.20",
3
+ "version": "1.0.21",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
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,15 @@ 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 = null
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.initialize()
115
103
  }
116
-
104
+
117
105
  initialize() {
118
106
  this.axios.interceptors.request.use((config) => {
119
107
  config.headers['X-TH1GAMES-VERSION'] = this.config.version
@@ -139,11 +127,7 @@ class Request {
139
127
  }
140
128
  )
141
129
  }
142
-
143
- setStore(store) {
144
- this.store = store
145
- }
146
-
130
+
147
131
  async send(req, customToken) {
148
132
  try {
149
133
  const cancelToken = customToken || this.source.token
@@ -220,11 +204,8 @@ class Request {
220
204
  }
221
205
  }
222
206
 
223
- const request = new Request(axios)
224
-
225
207
  export default (ctx, inject) => {
226
- const { store } = ctx
227
- request.setStore(store)
208
+ const { $axios, store } = ctx
228
209
  const cuoraConfig = new CuoraConfig({
229
210
  apiURL: process.env.API_URL,
230
211
  apiVersion: process.env.API_VERSION,
@@ -233,10 +214,6 @@ export default (ctx, inject) => {
233
214
  product: 'pwa',
234
215
  version: 'v<%= options.version %>',
235
216
  })
236
- request.setConfig(cuoraConfig)
237
217
  const cookie = new Cookie(`cuora_${cuoraConfig.clientId}`)
238
- request.setCookie(cookie)
239
- inject('request', request)
218
+ inject('request', new Request($axios, store, cuoraConfig, cookie))
240
219
  }
241
-
242
- export { request }