@jetthai/cuora 1.0.180 → 1.0.181
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 +2 -0
- package/dist/bundle.mjs +709 -898
- package/package.json +1 -1
- package/src/index.js +2 -2
- package/src/machine/auth.js +16 -17
- package/src/machine/common.js +5 -6
- package/src/machine/user_sign_up.js +4 -5
- package/src/machine/welcome.js +3 -5
- package/src/request/request.js +5 -5
- package/src/util/index.js +3 -1
- package/src/util/storage.js +37 -0
- package/src/request/cookie.js +0 -52
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -2,6 +2,6 @@ import api from './api/index.js'
|
|
|
2
2
|
import machine from './machine/index.js'
|
|
3
3
|
import Request from './request/request.js'
|
|
4
4
|
import Config from './request/config.js'
|
|
5
|
-
import util, { constant } from './util/index.js'
|
|
5
|
+
import util, { constant, storage } from './util/index.js'
|
|
6
6
|
|
|
7
|
-
export { api, machine, Request, Config, util, constant }
|
|
7
|
+
export { api, machine, Request, Config, util, constant, storage }
|
package/src/machine/auth.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import urljoin from 'url-join'
|
|
2
|
-
import Cookies from 'universal-cookie'
|
|
3
2
|
import { assign, createMachine } from 'xstate'
|
|
4
3
|
import auth from '../api/auth.js'
|
|
5
4
|
import user from '../api/user.js'
|
|
5
|
+
import storage from '../util/storage.js'
|
|
6
6
|
import { getDeviceToken } from '../util/deviceToken.js'
|
|
7
7
|
|
|
8
8
|
// const urljoin = require('url-join')
|
|
@@ -14,7 +14,6 @@ export default function (request) {
|
|
|
14
14
|
const phoneCountryCode = 'phone_countrycode'
|
|
15
15
|
const accountPhoneKey = 'account_phone'
|
|
16
16
|
const accountEmailKey = 'account_email'
|
|
17
|
-
const cookies = new Cookies()
|
|
18
17
|
|
|
19
18
|
return createMachine(
|
|
20
19
|
{
|
|
@@ -234,7 +233,7 @@ export default function (request) {
|
|
|
234
233
|
}),
|
|
235
234
|
setLoginLocal: assign((context, event) => {
|
|
236
235
|
const { username, password } = event.data
|
|
237
|
-
|
|
236
|
+
storage.set(userKey, username, {
|
|
238
237
|
path: '/',
|
|
239
238
|
maxAge: 60 * 60 * 24,
|
|
240
239
|
})
|
|
@@ -247,13 +246,13 @@ export default function (request) {
|
|
|
247
246
|
}
|
|
248
247
|
}),
|
|
249
248
|
fetchToken: assign((context, event) => {
|
|
250
|
-
const token =
|
|
249
|
+
const token = storage.get(tokenKey)
|
|
251
250
|
return {
|
|
252
251
|
token,
|
|
253
252
|
}
|
|
254
253
|
}),
|
|
255
254
|
setToken: assign((context, event) => {
|
|
256
|
-
|
|
255
|
+
storage.set(tokenKey, event.data, {
|
|
257
256
|
path: '/',
|
|
258
257
|
maxAge: 300,
|
|
259
258
|
})
|
|
@@ -263,34 +262,34 @@ export default function (request) {
|
|
|
263
262
|
}),
|
|
264
263
|
setAccount: assign((context, event) => {
|
|
265
264
|
if (context.loginData.phone) {
|
|
266
|
-
|
|
267
|
-
|
|
265
|
+
storage.remove(accountEmailKey)
|
|
266
|
+
storage.set(accountPhoneKey, `${context.loginData.phone}`, {
|
|
268
267
|
path: '/',
|
|
269
268
|
maxAge: 60 * 60 * 24 * 7,
|
|
270
269
|
})
|
|
271
|
-
|
|
270
|
+
storage.set(phoneCountryCode, `${context.countryAbbr}_${context.loginData.countryCode}`, {
|
|
272
271
|
path: '/',
|
|
273
272
|
maxAge: 60 * 60 * 24 * 7,
|
|
274
273
|
})
|
|
275
274
|
} else if (context.loginData.email) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
275
|
+
storage.remove(accountPhoneKey)
|
|
276
|
+
storage.remove(phoneCountryCode)
|
|
277
|
+
storage.set(accountEmailKey, context.loginData.email, {
|
|
279
278
|
path: '/',
|
|
280
279
|
maxAge: 60 * 60 * 24 * 7,
|
|
281
280
|
})
|
|
282
281
|
}
|
|
283
282
|
}),
|
|
284
283
|
removeToken: assign((context, event) => {
|
|
285
|
-
|
|
284
|
+
storage.remove(tokenKey, {
|
|
286
285
|
path: '/',
|
|
287
286
|
maxAge: 300,
|
|
288
287
|
})
|
|
289
288
|
return { token: null }
|
|
290
289
|
}),
|
|
291
290
|
extendToken: assign((context, event) => {
|
|
292
|
-
const token =
|
|
293
|
-
|
|
291
|
+
const token = storage.get(tokenKey)
|
|
292
|
+
storage.set(tokenKey, token, {
|
|
294
293
|
path: '/',
|
|
295
294
|
maxAge: 300,
|
|
296
295
|
})
|
|
@@ -304,7 +303,7 @@ export default function (request) {
|
|
|
304
303
|
const messages = {
|
|
305
304
|
url: window.location.href,
|
|
306
305
|
list: [
|
|
307
|
-
{ channel:
|
|
306
|
+
{ channel: storage.get('channel'), subchannel: storage.get('subchannel') },
|
|
308
307
|
{ channel: defaultChannel, subchannel: defaultSubchannel },
|
|
309
308
|
{ channel: channel, subchannel: subchannel },
|
|
310
309
|
],
|
|
@@ -317,8 +316,8 @@ export default function (request) {
|
|
|
317
316
|
new URLSearchParams({
|
|
318
317
|
provider,
|
|
319
318
|
redirectURI: `${window.location.protocol}//${window.location.host}`,
|
|
320
|
-
channel:
|
|
321
|
-
subchannel:
|
|
319
|
+
channel: storage.get('channel') || channel || defaultChannel || 'official',
|
|
320
|
+
subchannel: storage.get('subchannel') || subchannel || defaultSubchannel || 'pwa',
|
|
322
321
|
// dt,
|
|
323
322
|
platform: 'pwa',
|
|
324
323
|
}).toString()
|
package/src/machine/common.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import UAParser from 'ua-parser-js'
|
|
2
|
-
import Cookies from 'universal-cookie'
|
|
3
2
|
import { assign, createMachine } from 'xstate'
|
|
4
3
|
import pickBy from 'lodash/pickBy.js'
|
|
5
4
|
import api from '../api/common.js'
|
|
5
|
+
import storage from '../util/storage.js'
|
|
6
6
|
|
|
7
7
|
// const pickBy = require('lodash/pickBy')
|
|
8
8
|
// const UAParser = require('ua-parser-js')
|
|
9
|
-
const cookies = new Cookies()
|
|
10
9
|
|
|
11
10
|
export default function (request) {
|
|
12
11
|
const { appSecret, defaultChannel, defaultSubchannel } = request.config
|
|
@@ -155,14 +154,14 @@ export default function (request) {
|
|
|
155
154
|
return
|
|
156
155
|
} else {
|
|
157
156
|
let urlParams = new URLSearchParams(window.location.search)
|
|
158
|
-
const channel = urlParams.get('channel') ||
|
|
159
|
-
const subchannel = urlParams.get('subchannel') ||
|
|
157
|
+
const channel = urlParams.get('channel') || storage.get('channel') || defaultChannel || 'official'
|
|
158
|
+
const subchannel = urlParams.get('subchannel') || storage.get('subchannel') || defaultSubchannel || 'pwa'
|
|
160
159
|
|
|
161
|
-
|
|
160
|
+
storage.set('channel', channel, {
|
|
162
161
|
path: '/',
|
|
163
162
|
maxAge: 60 * 60 * 24 * 7,
|
|
164
163
|
})
|
|
165
|
-
|
|
164
|
+
storage.set('subchannel', subchannel, {
|
|
166
165
|
path: '/',
|
|
167
166
|
maxAge: 60 * 60 * 24 * 7,
|
|
168
167
|
})
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
|
-
import Cookies from 'universal-cookie'
|
|
3
2
|
import auth from '../api/auth.js'
|
|
4
3
|
import { getDeviceToken } from '../util/deviceToken.js'
|
|
4
|
+
import storage from '../util/storage.js'
|
|
5
5
|
|
|
6
|
-
const cookies = new Cookies()
|
|
7
6
|
|
|
8
7
|
export default function (request) {
|
|
9
8
|
const { fpToken, sentry, defaultChannel, defaultSubchannel } = request.config
|
|
@@ -108,7 +107,7 @@ export default function (request) {
|
|
|
108
107
|
const messages = {
|
|
109
108
|
url: window.location.href,
|
|
110
109
|
list: [
|
|
111
|
-
{ channel:
|
|
110
|
+
{ channel: storage.get('channel'), subchannel: storage.get('subchannel') },
|
|
112
111
|
{ channel: defaultChannel, subchannel: defaultSubchannel },
|
|
113
112
|
{ channel: channel, subchannel: subchannel },
|
|
114
113
|
],
|
|
@@ -118,8 +117,8 @@ export default function (request) {
|
|
|
118
117
|
return await request.send(
|
|
119
118
|
auth.register({
|
|
120
119
|
...signUpData,
|
|
121
|
-
channel:
|
|
122
|
-
subchannel:
|
|
120
|
+
channel: storage.get('channel') || defaultChannel || channel,
|
|
121
|
+
subchannel: storage.get('subchannel') || defaultSubchannel || subchannel,
|
|
123
122
|
dt,
|
|
124
123
|
reCaptchaToken: context.reCaptchaToken,
|
|
125
124
|
})
|
package/src/machine/welcome.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
|
-
import Cookies from 'universal-cookie'
|
|
3
2
|
import payment from '../api/payment.js'
|
|
4
3
|
import user from '../api/user.js'
|
|
5
|
-
|
|
6
|
-
const cookies = new Cookies()
|
|
4
|
+
import storage from '../util/storage.js'
|
|
7
5
|
|
|
8
6
|
export default function (request) {
|
|
9
7
|
return createMachine(
|
|
@@ -71,7 +69,7 @@ export default function (request) {
|
|
|
71
69
|
const { bank_account, bank_setting_status, topup, verification_status, uid } = context.userInfo || {}
|
|
72
70
|
// const hasBankAccount = bank_account || bank_setting_status === 1 // sabai
|
|
73
71
|
const isComplete = topup === 1 || verification_status === 1
|
|
74
|
-
const isSent =
|
|
72
|
+
const isSent = storage.get(`welcome_${uid}`)
|
|
75
73
|
return !(isSent || isComplete)
|
|
76
74
|
},
|
|
77
75
|
isFilled: (context, event) => {
|
|
@@ -86,7 +84,7 @@ export default function (request) {
|
|
|
86
84
|
}
|
|
87
85
|
}),
|
|
88
86
|
setInfo: (context, event) => {
|
|
89
|
-
|
|
87
|
+
storage.set(`welcome_${context.userInfo.uid}`, 'done', {
|
|
90
88
|
path: '/',
|
|
91
89
|
maxAge: 60 * 60 * 24 * 365,
|
|
92
90
|
})
|
package/src/request/request.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import pickBy from 'lodash/pickBy.js'
|
|
2
|
-
import
|
|
2
|
+
import storage from '../util/storage.js'
|
|
3
3
|
|
|
4
4
|
// const pickBy = require('lodash/pickBy')
|
|
5
5
|
|
|
@@ -12,7 +12,7 @@ export default class Request {
|
|
|
12
12
|
this.axios = axios
|
|
13
13
|
this.source = axios.CancelToken.source()
|
|
14
14
|
this.config = config
|
|
15
|
-
this.
|
|
15
|
+
this.key = `cuora_${config.clientId}`
|
|
16
16
|
this.errorHandler = null
|
|
17
17
|
this.initialize()
|
|
18
18
|
}
|
|
@@ -21,8 +21,8 @@ export default class Request {
|
|
|
21
21
|
this.axios.interceptors.request.use((axiosConfig) => {
|
|
22
22
|
axiosConfig.headers['X-TH1GAMES-VERSION'] = this.config.version
|
|
23
23
|
axiosConfig.headers['X-TH1GAMES-PLATFORM'] = this.config.platform
|
|
24
|
-
if (this.
|
|
25
|
-
axiosConfig.headers.Authorization = this.
|
|
24
|
+
if (storage.get(this.key)) {
|
|
25
|
+
axiosConfig.headers.Authorization = storage.get(this.key)
|
|
26
26
|
}
|
|
27
27
|
return axiosConfig
|
|
28
28
|
})
|
|
@@ -50,7 +50,7 @@ export default class Request {
|
|
|
50
50
|
async send(req, customToken) {
|
|
51
51
|
try {
|
|
52
52
|
const cancelToken = customToken || this.source.token
|
|
53
|
-
this._checkToken(req, this.
|
|
53
|
+
this._checkToken(req, storage.get(this.key))
|
|
54
54
|
const requestConfig = this._createConfig(req, cancelToken)
|
|
55
55
|
const { data } = await this.axios.request(requestConfig)
|
|
56
56
|
return data
|
package/src/util/index.js
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// import Cookies from 'universal-cookie'
|
|
2
|
+
|
|
3
|
+
// const cookies = new Cookies()
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
get(name, options) {
|
|
7
|
+
//return cookies.get(name, options)
|
|
8
|
+
|
|
9
|
+
const itemStr = localStorage.getItem(name)
|
|
10
|
+
|
|
11
|
+
if (!itemStr) {
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const item = JSON.parse(itemStr)
|
|
16
|
+
if (new Date().getTime() > item.expiry) {
|
|
17
|
+
localStorage.removeItem(name)
|
|
18
|
+
return null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return item.value
|
|
22
|
+
},
|
|
23
|
+
set(name, value, options) {
|
|
24
|
+
// cookies.set(name, value, options)
|
|
25
|
+
|
|
26
|
+
const item = {
|
|
27
|
+
value,
|
|
28
|
+
expiry: new Date().getTime() + (options.maxAge || 0)*1000
|
|
29
|
+
}
|
|
30
|
+
localStorage.setItem(name, JSON.stringify(item))
|
|
31
|
+
},
|
|
32
|
+
remove(name, options) {
|
|
33
|
+
// cookies.remove(name, options)
|
|
34
|
+
|
|
35
|
+
localStorage.removeItem(name)
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/request/cookie.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import Cookies from 'universal-cookie'
|
|
2
|
-
|
|
3
|
-
export default class Cookie {
|
|
4
|
-
constructor(tokenKey) {
|
|
5
|
-
this.cookies = new Cookies()
|
|
6
|
-
this.tokenKey = tokenKey
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
setToken(token) {
|
|
10
|
-
this.cookies.set(this.tokenKey, token, {
|
|
11
|
-
path: '/',
|
|
12
|
-
maxAge: 300,
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
prolongToken() {
|
|
17
|
-
const token = this.getToken()
|
|
18
|
-
if (token) {
|
|
19
|
-
this.setToken(token)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getToken() {
|
|
24
|
-
return this.cookies.get(this.tokenKey)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
removeToken() {
|
|
28
|
-
this.cookies.remove(this.tokenKey, {
|
|
29
|
-
path: '/',
|
|
30
|
-
maxAge: 300,
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
setUser(user) {
|
|
35
|
-
this.cookies.set('cuora_tempuser', user, {
|
|
36
|
-
path: '/',
|
|
37
|
-
maxAge: 60 * 60 * 24,
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getUser() {
|
|
42
|
-
return this.cookies.get('cuora_tempuser')
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
set(name, value, options) {
|
|
46
|
-
this.cookies.set(name, value, options)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get(name, options) {
|
|
50
|
-
return this.cookies.get(name, options)
|
|
51
|
-
}
|
|
52
|
-
}
|