@jetthai/cuora 1.0.116 → 1.0.118
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/package.json +1 -1
- package/src/machine/auth.js +23 -8
- package/src/machine/auth_otp_v3.js +254 -0
- package/src/machine/common.js +3 -3
- package/src/machine/inbox.js +0 -2
- package/src/machine/index.js +2 -0
- package/src/machine/reward.js +3 -3
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.118](https://github.com/jetthai/cuora-module/compare/v1.0.117...v1.0.118) (2022-05-22)
|
|
6
|
+
|
|
7
|
+
### [1.0.117](https://github.com/jetthai/cuora-module/compare/v1.0.116...v1.0.117) (2022-05-18)
|
|
8
|
+
|
|
5
9
|
### [1.0.116](https://github.com/jetthai/cuora-module/compare/v1.0.115...v1.0.116) (2022-05-12)
|
|
6
10
|
|
|
7
11
|
### [1.0.115](https://github.com/jetthai/cuora-module/compare/v1.0.114...v1.0.115) (2022-05-12)
|
package/package.json
CHANGED
package/src/machine/auth.js
CHANGED
|
@@ -10,6 +10,8 @@ export default function (request) {
|
|
|
10
10
|
const { clientId, fpToken, sentry } = request.config
|
|
11
11
|
const tokenKey = `cuora_${clientId}`
|
|
12
12
|
const userKey = `cuora_tempuser`
|
|
13
|
+
const accountKeyPhone = 'account_phone'
|
|
14
|
+
const accountKeyEmail = 'account_email'
|
|
13
15
|
const cookies = new Cookies()
|
|
14
16
|
|
|
15
17
|
return createMachine(
|
|
@@ -247,6 +249,19 @@ export default function (request) {
|
|
|
247
249
|
token: event.data,
|
|
248
250
|
}
|
|
249
251
|
}),
|
|
252
|
+
setAccount: assign((context, event) => {
|
|
253
|
+
if (context.loginData.phone) {
|
|
254
|
+
cookies.set(accountKeyPhone, context.loginData.phone, {
|
|
255
|
+
path: '/',
|
|
256
|
+
maxAge: 60 * 60 * 24,
|
|
257
|
+
})
|
|
258
|
+
} else if (context.loginData.email) {
|
|
259
|
+
cookies.set(accountKeyEmail, context.loginData.email, {
|
|
260
|
+
path: '/',
|
|
261
|
+
maxAge: 60 * 60 * 24,
|
|
262
|
+
})
|
|
263
|
+
}
|
|
264
|
+
}),
|
|
250
265
|
removeToken: assign((context, event) => {
|
|
251
266
|
cookies.remove(tokenKey, {
|
|
252
267
|
path: '/',
|
|
@@ -268,14 +283,14 @@ export default function (request) {
|
|
|
268
283
|
const redirectURL = urljoin(
|
|
269
284
|
request.config.fullURL,
|
|
270
285
|
'login?' +
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
286
|
+
qs.stringify({
|
|
287
|
+
provider,
|
|
288
|
+
redirectURI: `${window.location.protocol}//${window.location.host}`,
|
|
289
|
+
channel: cookies.get('channel') || channel || 'official',
|
|
290
|
+
subchannel: cookies.get('subchannel') || subchannel || 'pwa',
|
|
291
|
+
// dt,
|
|
292
|
+
platform: 'pwa',
|
|
293
|
+
})
|
|
279
294
|
)
|
|
280
295
|
window.location.href = redirectURL
|
|
281
296
|
},
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { createMachine, assign } from 'xstate'
|
|
2
|
+
import api from '../api/user'
|
|
3
|
+
import user from '../api/user'
|
|
4
|
+
|
|
5
|
+
export default function (request) {
|
|
6
|
+
return createMachine(
|
|
7
|
+
{
|
|
8
|
+
id: 'auth_otp',
|
|
9
|
+
initial: 'idle',
|
|
10
|
+
context: {
|
|
11
|
+
strategy: null,
|
|
12
|
+
userInfo: null,
|
|
13
|
+
error: null,
|
|
14
|
+
countryCode: null,
|
|
15
|
+
phone: null,
|
|
16
|
+
email: null,
|
|
17
|
+
target: null,
|
|
18
|
+
requestId: null,
|
|
19
|
+
ttl: 0,
|
|
20
|
+
},
|
|
21
|
+
states: {
|
|
22
|
+
idle: {
|
|
23
|
+
on: {
|
|
24
|
+
SET_STRATEGY: {
|
|
25
|
+
target: 'fetching',
|
|
26
|
+
actions: 'setStrategy',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
fetching: {
|
|
31
|
+
invoke: {
|
|
32
|
+
src: 'fetchUserInfo',
|
|
33
|
+
onDone: {
|
|
34
|
+
target: 'checking',
|
|
35
|
+
actions: 'setUserInfo',
|
|
36
|
+
},
|
|
37
|
+
onError: {
|
|
38
|
+
target: 'fail',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
checking: {
|
|
43
|
+
always: [
|
|
44
|
+
{ target: 'verified', cond: 'isVerified' },
|
|
45
|
+
{ target: 'notVerified.email', cond: 'isEmailNotVerified' },
|
|
46
|
+
{ target: 'notVerified.phone', cond: 'isPhoneNotVerified' },
|
|
47
|
+
{ target: 'notVerified', cond: 'isNotVerified' },
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
notVerified: {
|
|
51
|
+
initial: 'checkingStatus',
|
|
52
|
+
states: {
|
|
53
|
+
checkingStatus: {
|
|
54
|
+
invoke: {
|
|
55
|
+
src: 'verify',
|
|
56
|
+
onDone: {
|
|
57
|
+
target: 'otp',
|
|
58
|
+
actions: 'setVerificationData',
|
|
59
|
+
},
|
|
60
|
+
onError: {
|
|
61
|
+
target: 'errorChecking',
|
|
62
|
+
actions: 'setError',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
errorChecking: {
|
|
67
|
+
always: [{ target: 'phone', cond: 'hasNoPhone' }, { target: '#auth_otp.fail' }],
|
|
68
|
+
},
|
|
69
|
+
phone: {
|
|
70
|
+
on: {
|
|
71
|
+
SEND_PHONE: {
|
|
72
|
+
target: 'sendingPhone',
|
|
73
|
+
actions: 'setPhone',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
email: {
|
|
78
|
+
on: {
|
|
79
|
+
SEND_EMAIL: {
|
|
80
|
+
target: 'sendingEmail',
|
|
81
|
+
actions: 'setEmail',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
sendingPhone: {
|
|
86
|
+
invoke: {
|
|
87
|
+
src: 'sendPhone',
|
|
88
|
+
onDone: {
|
|
89
|
+
target: 'checkingStatus',
|
|
90
|
+
},
|
|
91
|
+
onError: { target: 'phone' },
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
sendingEmail: {
|
|
95
|
+
invoke: {
|
|
96
|
+
src: 'sendEmail',
|
|
97
|
+
onDone: {
|
|
98
|
+
target: 'checkingStatus',
|
|
99
|
+
},
|
|
100
|
+
onError: { target: 'email' },
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
otp: {
|
|
104
|
+
type: 'parallel',
|
|
105
|
+
states: {
|
|
106
|
+
countdown: {
|
|
107
|
+
after: {
|
|
108
|
+
1000: {
|
|
109
|
+
target: 'countdown',
|
|
110
|
+
actions: 'decreaseTtl',
|
|
111
|
+
cond: (context) => context.ttl > 0,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
verification: {
|
|
116
|
+
initial: 'idle',
|
|
117
|
+
states: {
|
|
118
|
+
idle: {
|
|
119
|
+
on: {
|
|
120
|
+
SEND_OTP: {
|
|
121
|
+
target: 'acknowledging',
|
|
122
|
+
},
|
|
123
|
+
RESET_OTP: {
|
|
124
|
+
target: 'reset',
|
|
125
|
+
},
|
|
126
|
+
RESEND_PHONE: {
|
|
127
|
+
target: '#auth_otp.notVerified.phone',
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
acknowledging: {
|
|
132
|
+
invoke: {
|
|
133
|
+
src: 'acknowledge',
|
|
134
|
+
onDone: {
|
|
135
|
+
target: '#auth_otp.verified',
|
|
136
|
+
},
|
|
137
|
+
onError: {
|
|
138
|
+
target: 'idle',
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
reset: {
|
|
143
|
+
invoke: {
|
|
144
|
+
src: 'resetOtp',
|
|
145
|
+
onDone: {
|
|
146
|
+
target: 'idle',
|
|
147
|
+
actions: 'setVerificationData',
|
|
148
|
+
},
|
|
149
|
+
onError: { target: 'idle' },
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
verified: {},
|
|
159
|
+
fail: {},
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
actions: {
|
|
164
|
+
setStrategy: assign((context, event) => {
|
|
165
|
+
return {
|
|
166
|
+
strategy: event.data,
|
|
167
|
+
}
|
|
168
|
+
}),
|
|
169
|
+
setUserInfo: assign((context, event) => {
|
|
170
|
+
return {
|
|
171
|
+
userInfo: event.data,
|
|
172
|
+
}
|
|
173
|
+
}),
|
|
174
|
+
setVerificationData: assign((context, event) => {
|
|
175
|
+
const { requestId, ttl, target } = event.data
|
|
176
|
+
return {
|
|
177
|
+
requestId,
|
|
178
|
+
ttl: ttl * 1000,
|
|
179
|
+
target,
|
|
180
|
+
}
|
|
181
|
+
}),
|
|
182
|
+
decreaseTtl: assign((context, evnet) => {
|
|
183
|
+
const ms = context.ttl
|
|
184
|
+
return {
|
|
185
|
+
ttl: Math.max(ms - 1000, 0),
|
|
186
|
+
}
|
|
187
|
+
}),
|
|
188
|
+
setError: assign((context, event) => {
|
|
189
|
+
return {
|
|
190
|
+
error: event.data,
|
|
191
|
+
}
|
|
192
|
+
}),
|
|
193
|
+
setPhone: assign((context, event) => {
|
|
194
|
+
const { countryCode, phone } = event.data
|
|
195
|
+
return {
|
|
196
|
+
countryCode,
|
|
197
|
+
phone,
|
|
198
|
+
}
|
|
199
|
+
}),
|
|
200
|
+
setEmail: assign((context, event) => {
|
|
201
|
+
const { email } = event.data
|
|
202
|
+
return {
|
|
203
|
+
email,
|
|
204
|
+
}
|
|
205
|
+
}),
|
|
206
|
+
},
|
|
207
|
+
guards: {
|
|
208
|
+
isVerified: (context, event) => {
|
|
209
|
+
return context.userInfo?.verification_status === 1
|
|
210
|
+
},
|
|
211
|
+
isNotVerified: (context, event) => {
|
|
212
|
+
return context.userInfo && context.userInfo.verification_status !== 1
|
|
213
|
+
},
|
|
214
|
+
isPhoneNotVerified: (context, event) => {
|
|
215
|
+
const { strategy, userInfo } = context
|
|
216
|
+
return strategy === 'phone' && userInfo && userInfo.verification_status !== 1 && !userInfo.phone
|
|
217
|
+
},
|
|
218
|
+
isEmailNotVerified: (context, event) => {
|
|
219
|
+
const { strategy, userInfo } = context
|
|
220
|
+
return strategy === 'email' && userInfo && userInfo.verification_status !== 1 && !userInfo.email
|
|
221
|
+
},
|
|
222
|
+
hasNoPhone: (context, event) => {
|
|
223
|
+
const { error } = context
|
|
224
|
+
return error.code === 'ERR_F106'
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
services: {
|
|
228
|
+
fetchUserInfo: async (context, event) => {
|
|
229
|
+
return await request.send(api.getUserInfo())
|
|
230
|
+
},
|
|
231
|
+
verify: async (context, event) => {
|
|
232
|
+
return await request.send(api.verifyV2Initiate({ strategy: context.strategy }))
|
|
233
|
+
},
|
|
234
|
+
sendPhone: async (context, event) => {
|
|
235
|
+
const { countryCode, phone } = context
|
|
236
|
+
return await request.send(api.updateUserInfo({ countryCode, phone }))
|
|
237
|
+
},
|
|
238
|
+
sendEmail: async (context, event) => {
|
|
239
|
+
const { email } = context
|
|
240
|
+
return await request.send(api.updateUserInfo({ email }))
|
|
241
|
+
},
|
|
242
|
+
resetOtp: async (context, event) => {
|
|
243
|
+
const { requestId, target } = context
|
|
244
|
+
return await request.send(api.otpReset({ requestId, target }))
|
|
245
|
+
},
|
|
246
|
+
acknowledge: async (context, event) => {
|
|
247
|
+
const { requestId, target } = context
|
|
248
|
+
const code = event.data
|
|
249
|
+
return await request.send(user.otpAcknowledge({ requestId, target, code }))
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
}
|
|
253
|
+
)
|
|
254
|
+
}
|
package/src/machine/common.js
CHANGED
|
@@ -35,7 +35,7 @@ export default function (request) {
|
|
|
35
35
|
emergencyBroadcast: null,
|
|
36
36
|
normalBroadcast: null,
|
|
37
37
|
sentEmergencyBroadcastList: [],
|
|
38
|
-
sentNormalBroadcastList: []
|
|
38
|
+
sentNormalBroadcastList: [],
|
|
39
39
|
},
|
|
40
40
|
states: {
|
|
41
41
|
config: {
|
|
@@ -187,7 +187,7 @@ export default function (request) {
|
|
|
187
187
|
emergencyBroadcast: nextEmergencyBroadcast,
|
|
188
188
|
sentEmergencyBroadcastList: sentEmergencyList,
|
|
189
189
|
normalBroadcast: nextNormalBroadcast,
|
|
190
|
-
sentNormalBroadcastList: sentNormalList
|
|
190
|
+
sentNormalBroadcastList: sentNormalList,
|
|
191
191
|
}
|
|
192
192
|
}),
|
|
193
193
|
resetBroadcast: assign((context, event) => {
|
|
@@ -195,7 +195,7 @@ export default function (request) {
|
|
|
195
195
|
emergencyBroadcast: null,
|
|
196
196
|
sentEmergencyBroadcastList: [],
|
|
197
197
|
normalBroadcast: null,
|
|
198
|
-
sentNormalBroadcastList: []
|
|
198
|
+
sentNormalBroadcastList: [],
|
|
199
199
|
}
|
|
200
200
|
}),
|
|
201
201
|
},
|
package/src/machine/inbox.js
CHANGED
|
@@ -2,8 +2,6 @@ import { assign, createMachine } from 'xstate'
|
|
|
2
2
|
import mailbox from '../api/mailbox'
|
|
3
3
|
import activity from '../api/activity'
|
|
4
4
|
|
|
5
|
-
// todo - 自動開啟系統信
|
|
6
|
-
// todo - 更新未讀數量
|
|
7
5
|
const messageState = {
|
|
8
6
|
// always: [{ actions: 'showUnread', cond: 'isShowUnread' }],
|
|
9
7
|
initial: 'idle',
|
package/src/machine/index.js
CHANGED
|
@@ -25,6 +25,7 @@ import deposit from './deposit'
|
|
|
25
25
|
import bonus from './bonus'
|
|
26
26
|
import leaderboard from './leaderboard'
|
|
27
27
|
import auth_otp_v2 from './auth_otp_v2'
|
|
28
|
+
import auth_otp_v3 from './auth_otp_v3'
|
|
28
29
|
|
|
29
30
|
export default {
|
|
30
31
|
...activity,
|
|
@@ -55,4 +56,5 @@ export default {
|
|
|
55
56
|
bonus,
|
|
56
57
|
leaderboard,
|
|
57
58
|
auth_otp_v2,
|
|
59
|
+
auth_otp_v3,
|
|
58
60
|
}
|
package/src/machine/reward.js
CHANGED
|
@@ -10,7 +10,7 @@ export default function (request) {
|
|
|
10
10
|
context: {
|
|
11
11
|
otherRewardList: [],
|
|
12
12
|
pointsRewardList: [],
|
|
13
|
-
callback: () => {
|
|
13
|
+
callback: () => {},
|
|
14
14
|
},
|
|
15
15
|
states: {
|
|
16
16
|
timer: {
|
|
@@ -78,7 +78,7 @@ export default function (request) {
|
|
|
78
78
|
target: 'idle',
|
|
79
79
|
},
|
|
80
80
|
},
|
|
81
|
-
}
|
|
81
|
+
},
|
|
82
82
|
},
|
|
83
83
|
},
|
|
84
84
|
},
|
|
@@ -93,7 +93,7 @@ export default function (request) {
|
|
|
93
93
|
}),
|
|
94
94
|
setCallback: assign((context, event) => {
|
|
95
95
|
return {
|
|
96
|
-
callback: event.data?.callback || (() => {
|
|
96
|
+
callback: event.data?.callback || (() => {}),
|
|
97
97
|
}
|
|
98
98
|
}),
|
|
99
99
|
doCallback: (context, event) => {
|