@jetthai/cuora 1.0.25 → 1.0.26

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/api/activity.js +46 -0
  3. package/api/auth.js +15 -0
  4. package/api/common.js +4 -0
  5. package/api/game.js +32 -0
  6. package/api/index.js +9 -0
  7. package/api/mailbox.js +20 -0
  8. package/api/payment.js +63 -0
  9. package/api/user.js +19 -0
  10. package/index.js +3 -58
  11. package/machine/activity/activity.js +73 -0
  12. package/machine/activity/continue_deposit_activity.js +132 -0
  13. package/machine/activity/deposit_activity.js +86 -0
  14. package/machine/activity/diamond_shop_activity.js +163 -0
  15. package/machine/activity/fafafa_activity.js +131 -0
  16. package/machine/activity/index.js +21 -0
  17. package/machine/activity/invite_friends_activity.js +121 -0
  18. package/machine/activity/ranking_activity.js +76 -0
  19. package/machine/activity/return_bonus_activity.js +150 -0
  20. package/machine/activity/specify_bets_activity.js +116 -0
  21. package/machine/auth.js +245 -0
  22. package/machine/auth_otp.js +191 -0
  23. package/machine/check.js +113 -0
  24. package/machine/common.js +163 -0
  25. package/machine/deposit.js +236 -0
  26. package/machine/error.js +72 -0
  27. package/machine/game.js +265 -0
  28. package/machine/game_favorite.js +123 -0
  29. package/machine/game_search.js +248 -0
  30. package/machine/inbox.js +246 -0
  31. package/machine/index.js +37 -0
  32. package/machine/merge.js +57 -0
  33. package/machine/payment_data.js +81 -0
  34. package/machine/reward.js +73 -0
  35. package/machine/setting.js +37 -0
  36. package/machine/side.js +147 -0
  37. package/machine/withdraw.js +367 -0
  38. package/package.json +3 -2
  39. package/request/config.js +18 -0
  40. package/request/cookie.js +52 -0
  41. package/request/request.js +97 -0
  42. package/plugin/activity.js +0 -289
  43. package/plugin/core.js +0 -518
  44. package/plugin/game.js +0 -474
  45. package/plugin/inbox.js +0 -216
  46. package/plugin/information.js +0 -57
  47. package/plugin/job/network.js +0 -61
  48. package/plugin/payment.js +0 -257
  49. package/plugin/request.js +0 -225
  50. package/plugin/search.js +0 -277
  51. package/plugin/user.js +0 -198
@@ -0,0 +1,116 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import api from '../../api/activity'
3
+
4
+ export default function (request) {
5
+ const { appSecret } = request.config
6
+ return createMachine(
7
+ {
8
+ id: 'specify_bets_activity',
9
+ context: {
10
+ activityNo: null,
11
+ activityDetail: null,
12
+ rewardType: null,
13
+ },
14
+ initial: 'idle',
15
+ states: {
16
+ idle: {
17
+ on: {
18
+ SET_ACTIVITY_NO: {
19
+ target: 'loading',
20
+ actions: 'setActivityNo',
21
+ },
22
+ },
23
+ },
24
+ loading: {
25
+ invoke: {
26
+ src: 'fetchActivityDetail',
27
+ onDone: {
28
+ target: 'loaded',
29
+ actions: 'setActivityDetail',
30
+ },
31
+ onError: {
32
+ target: 'idle',
33
+ },
34
+ },
35
+ },
36
+ loaded: {
37
+ always: [
38
+ { target: 'ongoing', cond: 'isOngoing' },
39
+ { target: 'received', cond: 'isReceived' },
40
+ { target: 'receivable', cond: 'isReceivable' },
41
+ ],
42
+ },
43
+ ongoing: {},
44
+ received: {},
45
+ receivable: {
46
+ on: {
47
+ RECEIVE_REWARD: {
48
+ target: 'receiving',
49
+ },
50
+ },
51
+ },
52
+ receiving: {
53
+ invoke: {
54
+ src: 'receiveReward',
55
+ onDone: {
56
+ target: 'animating',
57
+ actions: 'setRewardType',
58
+ },
59
+ onError: {
60
+ target: 'loaded',
61
+ },
62
+ },
63
+ },
64
+ animating: {
65
+ after: {
66
+ 0: {
67
+ target: 'loading',
68
+ },
69
+ },
70
+ },
71
+ },
72
+ },
73
+ {
74
+ actions: {
75
+ setActivityNo: assign((context, event) => {
76
+ return {
77
+ activityNo: event.data,
78
+ }
79
+ }),
80
+ setActivityDetail: assign((context, event) => {
81
+ return {
82
+ activityDetail: event.data,
83
+ }
84
+ }),
85
+ setRewardType: assign((context, event) => {
86
+ return {
87
+ rewardType: event.data.type,
88
+ }
89
+ }),
90
+ },
91
+ guards: {
92
+ isReceivable: (context, event) => {
93
+ return context.activityDetail?.receiveStatus === 2
94
+ },
95
+ isReceived: (context, event) => {
96
+ return context.activityDetail?.receiveStatus === 1
97
+ },
98
+ isOngoing: (context, event) => {
99
+ return context.activityDetail?.receiveStatus === 0
100
+ },
101
+ },
102
+ services: {
103
+ fetchActivityDetail: async (context, event) => {
104
+ const { activityNo } = context
105
+ const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
106
+ return data
107
+ },
108
+ receiveReward: async (context, event) => {
109
+ const { activityNo, receiveNo } = context.activityDetail
110
+ const { data } = await request.send(api.getReward({ activityNo, receiveNo, appSecret }))
111
+ return data
112
+ },
113
+ },
114
+ }
115
+ )
116
+ }
@@ -0,0 +1,245 @@
1
+ import urljoin from 'url-join'
2
+ import Cookies from 'universal-cookie'
3
+ import qs from 'qs'
4
+ import { assign, createMachine, send } from 'xstate'
5
+ import auth from '../api/auth'
6
+ import user from '../api/user'
7
+
8
+ export default function (request) {
9
+ const { fullURL, clientId } = request.config
10
+ const tokenKey = `cuora_${clientId}`
11
+ const userKey = `cuora_tempuser`
12
+ const cookies = new Cookies()
13
+
14
+ return createMachine(
15
+ {
16
+ id: 'auth',
17
+ initial: 'idle',
18
+ context: {
19
+ token: null,
20
+ tick: 2000,
21
+ isPlaying: false,
22
+ userInfo: {},
23
+ redirectURL: null,
24
+ },
25
+ states: {
26
+ idle: {
27
+ entry: 'fetchToken',
28
+ always: [{ target: 'login', cond: 'hasToken' }],
29
+ on: {
30
+ LOGIN_PHONE: {
31
+ target: 'authentication.phone',
32
+ },
33
+ LOGIN_LOCAL: {
34
+ target: 'authentication.local',
35
+ },
36
+ LOGIN_3PARTY: {
37
+ actions: 'redirectTo3Party',
38
+ },
39
+ LOGIN_TOKEN: {
40
+ actions: 'setToken',
41
+ },
42
+ },
43
+ },
44
+ authentication: {
45
+ states: {
46
+ phone: {
47
+ invoke: {
48
+ src: 'authenticateByPhone',
49
+ onDone: {
50
+ target: '#auth.login',
51
+ actions: 'setToken',
52
+ },
53
+ onError: {
54
+ target: '#auth.idle',
55
+ actions: 'removeToken',
56
+ },
57
+ },
58
+ },
59
+ local: {
60
+ invoke: {
61
+ src: 'authenticateByUsername',
62
+ onDone: {
63
+ target: '#auth.login',
64
+ actions: 'setToken',
65
+ },
66
+ onError: {
67
+ target: '#auth.idle',
68
+ actions: 'removeToken',
69
+ },
70
+ },
71
+ },
72
+ },
73
+ },
74
+ login: {
75
+ type: 'parallel',
76
+ states: {
77
+ schedule: {
78
+ initial: 'running',
79
+ states: {
80
+ running: {
81
+ invoke: {
82
+ src: 'fetchUserInfo',
83
+ onDone: {
84
+ target: 'pending',
85
+ actions: ['setUserInfo', 'extendToken'],
86
+ },
87
+ onError: {
88
+ target: '#auth.logout',
89
+ },
90
+ },
91
+ },
92
+ pending: {
93
+ after: {
94
+ TIMEOUT: {
95
+ target: 'running',
96
+ },
97
+ },
98
+ on: {
99
+ FETCH_USER_INFO: {
100
+ target: 'running',
101
+ },
102
+ },
103
+ },
104
+ },
105
+ },
106
+ user: {
107
+ initial: 'idle',
108
+ states: {
109
+ idle: {
110
+ on: {
111
+ MODIFY_USER_INFO: {
112
+ target: 'modifyingUserInfo',
113
+ },
114
+ },
115
+ },
116
+ modifyingUserInfo: {
117
+ invoke: {
118
+ src: 'modifyUserInfo',
119
+ onDone: {
120
+ target: 'idle',
121
+ actions: send({ type: 'FETCH_USER_INFO' }),
122
+ },
123
+ onError: {
124
+ target: 'idle',
125
+ },
126
+ },
127
+ },
128
+ },
129
+ },
130
+ },
131
+ on: {
132
+ LOGOUT: {
133
+ target: '#auth.logout',
134
+ },
135
+ },
136
+ },
137
+ logout: {
138
+ invoke: {
139
+ src: 'logout',
140
+ onDone: {
141
+ target: 'idle',
142
+ actions: 'removeToken',
143
+ },
144
+ onError: {
145
+ target: 'idle',
146
+ actions: 'removeToken',
147
+ },
148
+ },
149
+ },
150
+ },
151
+ },
152
+ {
153
+ delays: {
154
+ TIMEOUT: (context, event) => {
155
+ const { tick, isPlaying } = context
156
+ return tick * (isPlaying ? 5 : 1)
157
+ },
158
+ },
159
+ guards: {
160
+ hasToken: (context, event) => {
161
+ return context.token
162
+ },
163
+ isFirstLogin: (context, event) => {
164
+ const { bank_account, bank_setting_status } = context.userInfo || {}
165
+ return !!bank_account || bank_setting_status === 1
166
+ },
167
+ },
168
+ actions: {
169
+ fetchToken: assign((context, event) => {
170
+ const token = cookies.get(tokenKey)
171
+ return {
172
+ token,
173
+ }
174
+ }),
175
+ setToken: assign((context, event) => {
176
+ cookies.set(tokenKey, event.data, {
177
+ path: '/',
178
+ maxAge: 300,
179
+ })
180
+ return {
181
+ token: event.data,
182
+ }
183
+ }),
184
+ removeToken: assign((context, event) => {
185
+ cookies.remove(tokenKey, {
186
+ path: '/',
187
+ maxAge: 300,
188
+ })
189
+ return { token: null }
190
+ }),
191
+ extendToken: assign((context, event) => {
192
+ const token = cookies.get(tokenKey)
193
+ cookies.set(tokenKey, token, {
194
+ path: '/',
195
+ maxAge: 300,
196
+ })
197
+ return { token }
198
+ }),
199
+ redirectTo3Party: (context, event) => {
200
+ const redirectURL = urljoin(
201
+ fullURL,
202
+ 'login?' +
203
+ qs.stringify({
204
+ provider: event.data,
205
+ redirectURI: `${window.location.protocol}//${window.location.host}`,
206
+ channel: 'official',
207
+ subchannel: 'pwa',
208
+ })
209
+ )
210
+ window.location.href = redirectURL
211
+ },
212
+ setUserInfo: assign((context, event) => {
213
+ return {
214
+ userInfo: event.data,
215
+ }
216
+ }),
217
+ },
218
+ services: {
219
+ authenticateByUsername: async (context, event) => {
220
+ const { username, password } = event.data
221
+ cookies.set(userKey, username, {
222
+ path: '/',
223
+ maxAge: 60 * 60 * 24,
224
+ })
225
+ const { token } = await request.send(auth.login({ provider: 'local', username, password }))
226
+ return token
227
+ },
228
+ authenticateByPhone: async (context, event) => {
229
+ const { countryCode, phone, password } = event.data
230
+ const { token } = await request.send(auth.login({ provider: 'phone', countryCode, phone, password }))
231
+ return token
232
+ },
233
+ logout: async (context, event) => {
234
+ return await request.send(auth.logout())
235
+ },
236
+ fetchUserInfo: async (context, event) => {
237
+ return await request.send(user.getUserInfo())
238
+ },
239
+ modifyUserInfo: async (context, event) => {
240
+ return await request.send(user.modifyUserInfo(event.data))
241
+ },
242
+ },
243
+ }
244
+ )
245
+ }
@@ -0,0 +1,191 @@
1
+ import { createMachine, assign } from 'xstate'
2
+ import api from '../api/user'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'otp',
8
+ initial: 'idle',
9
+ context: {
10
+ userInfo: null,
11
+ error: null,
12
+ countryCode: null,
13
+ phone: null,
14
+ number: null,
15
+ requestId: null,
16
+ ttl: 0,
17
+ },
18
+ states: {
19
+ idle: {
20
+ always: [
21
+ { target: 'verified', cond: 'isVerified' },
22
+ { target: 'notVerified', cond: 'isNotVerified' },
23
+ ],
24
+ on: {
25
+ SET_USER_INFO: {
26
+ actions: 'setUserInfo',
27
+ },
28
+ },
29
+ },
30
+ notVerified: {
31
+ initial: 'checkingStatus',
32
+ states: {
33
+ checkingStatus: {
34
+ invoke: {
35
+ src: 'verify',
36
+ onDone: {
37
+ target: 'otp',
38
+ actions: 'setVerificationData',
39
+ },
40
+ onError: {
41
+ target: 'errorChecking',
42
+ actions: 'setError',
43
+ },
44
+ },
45
+ },
46
+ errorChecking: {
47
+ always: [{ target: 'phone', cond: 'hasNoPhone' }, { target: '#otp.fail' }],
48
+ },
49
+ phone: {
50
+ on: {
51
+ SEND_PHONE: {
52
+ target: 'sendingPhone',
53
+ actions: 'setPhone',
54
+ },
55
+ },
56
+ },
57
+ sendingPhone: {
58
+ invoke: {
59
+ src: 'sendPhone',
60
+ onDone: {
61
+ target: 'checkingStatus',
62
+ },
63
+ onError: { target: 'phone' },
64
+ },
65
+ },
66
+ otp: {
67
+ type: 'parallel',
68
+ states: {
69
+ countdown: {
70
+ after: {
71
+ 1000: {
72
+ target: 'countdown',
73
+ actions: 'decreaseTtl',
74
+ cond: (context) => context.ttl > 0,
75
+ },
76
+ },
77
+ },
78
+ verification: {
79
+ initial: 'idle',
80
+ states: {
81
+ idle: {
82
+ on: {
83
+ SEND_OTP: {
84
+ target: 'acknowledging',
85
+ },
86
+ RESET_OTP: {
87
+ target: 'reset',
88
+ },
89
+ RESEND_PHONE: {
90
+ target: '#otp.notVerified.phone',
91
+ },
92
+ },
93
+ },
94
+ acknowledging: {
95
+ invoke: {
96
+ src: 'acknowledge',
97
+ onDone: {
98
+ target: '#otp.verified',
99
+ },
100
+ onError: {
101
+ target: 'idle',
102
+ },
103
+ },
104
+ },
105
+ reset: {
106
+ invoke: {
107
+ src: 'resetOtp',
108
+ onDone: {
109
+ target: 'idle',
110
+ actions: 'setVerificationData',
111
+ },
112
+ onError: { target: 'idle' },
113
+ },
114
+ },
115
+ },
116
+ },
117
+ },
118
+ },
119
+ },
120
+ },
121
+ verified: {},
122
+ fail: {},
123
+ },
124
+ },
125
+ {
126
+ actions: {
127
+ setUserInfo: assign((context, event) => {
128
+ return {
129
+ userInfo: event.data,
130
+ }
131
+ }),
132
+ setVerificationData: assign((context, event) => {
133
+ const { number, requestId, ttl } = event.data
134
+ return {
135
+ number,
136
+ requestId,
137
+ ttl,
138
+ }
139
+ }),
140
+ decreaseTtl: assign((context, evnet) => {
141
+ const ms = context.ttl
142
+ return {
143
+ ttl: Math.max(ms - 1000, 0),
144
+ }
145
+ }),
146
+ setError: assign((context, event) => {
147
+ return {
148
+ error: event.data,
149
+ }
150
+ }),
151
+ setPhone: assign((context, event) => {
152
+ const { countryCode, phone } = event.data
153
+ return {
154
+ countryCode,
155
+ phone,
156
+ }
157
+ }),
158
+ },
159
+ guards: {
160
+ isVerified: (context, event) => {
161
+ return context.userInfo?.verification_status === 1
162
+ },
163
+ isNotVerified: (context, event) => {
164
+ return context.userInfo && context.userInfo.verification_status !== 1
165
+ },
166
+ hasNoPhone: (context, event) => {
167
+ const { error } = context
168
+ return error.code === 'ERR_F106'
169
+ },
170
+ },
171
+ services: {
172
+ verify: async (context, event) => {
173
+ return await request.send(api.verify())
174
+ },
175
+ sendPhone: async (context, event) => {
176
+ const { countryCode, phone } = context
177
+ return await request.send(api.modifyUserInfo({ countryCode, phone }))
178
+ },
179
+ resetOtp: async (context, event) => {
180
+ const { requestId, number } = context
181
+ return await request.send(api.resetOtp({ requestId, number }))
182
+ },
183
+ acknowledge: async (context, event) => {
184
+ const { requestId } = context
185
+ const code = event.data
186
+ return await request.send(api.acknowledge({ requestId, code }))
187
+ },
188
+ },
189
+ }
190
+ )
191
+ }
@@ -0,0 +1,113 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import Cookies from 'universal-cookie'
3
+ import payment from '../api/payment'
4
+ import user from '../api/user'
5
+
6
+ const cookies = new Cookies()
7
+
8
+ export default function (request) {
9
+ return createMachine(
10
+ {
11
+ id: 'check',
12
+ initial: 'idle',
13
+ context: {
14
+ userInfo: null,
15
+ bonus: null,
16
+ gender: null,
17
+ },
18
+ states: {
19
+ idle: {},
20
+ checking: {
21
+ always: [
22
+ { target: 'inline', cond: 'isInline' },
23
+ { target: 'inquiry', cond: 'isInquiryIncomplete' },
24
+ { target: 'completed' },
25
+ ],
26
+ },
27
+ inline: {},
28
+ inquiry: {
29
+ initial: 'inquiring',
30
+ states: {
31
+ inquiring: {
32
+ on: {
33
+ SET_BONUS: {
34
+ actions: 'setBonus',
35
+ },
36
+ SET_GENDER: {
37
+ actions: 'setGender',
38
+ },
39
+ SEND_INQUIRY_RESULT: {
40
+ target: 'submitting',
41
+ cond: 'isInquiryFilled',
42
+ },
43
+ },
44
+ },
45
+ submitting: {
46
+ invoke: {
47
+ src: 'sendInquiryResult',
48
+ onDone: {
49
+ target: '#check.completed',
50
+ },
51
+ onError: {
52
+ target: '#check.completed',
53
+ },
54
+ },
55
+ exit: 'setInfo',
56
+ },
57
+ },
58
+ },
59
+ completed: {},
60
+ },
61
+ on: {
62
+ SET_USER_INFO: {
63
+ target: 'checking',
64
+ actions: 'setUserInfo',
65
+ },
66
+ },
67
+ },
68
+ {
69
+ guards: {
70
+ isInline: (context, event) => {
71
+ return context.userInfo?.rank >= 0
72
+ },
73
+ isInquiryIncomplete: (context, event) => {
74
+ const { bank_account, bank_setting_status } = context.userInfo || {}
75
+ const hasBankAccount = bank_account || bank_setting_status === 1
76
+ return !hasBankAccount && !cookies.get('welcome')
77
+ },
78
+ isInquiryFilled: (context, event) => {
79
+ const { bonus, gender } = context
80
+ return bonus !== null && gender !== null
81
+ },
82
+ },
83
+ actions: {
84
+ setUserInfo: assign((context, event) => {
85
+ return {
86
+ userInfo: event.data,
87
+ }
88
+ }),
89
+ setInfo: (context, event) => {
90
+ cookies.set('welcome', 'done', {
91
+ path: '/',
92
+ maxAge: 60 * 60 * 24 * 365,
93
+ })
94
+ },
95
+ setBonus: assign((context, event) => {
96
+ return { bonus: event.data }
97
+ }),
98
+ setGender: assign((context, event) => {
99
+ return { gender: event.data }
100
+ }),
101
+ },
102
+ services: {
103
+ sendInquiryResult: async (context, event) => {
104
+ const { bonus, gender } = context
105
+ await Promise.all([
106
+ request.send(payment.setBonusSetting({ bonus })),
107
+ request.send(user.modifyUserInfo({ gender })),
108
+ ])
109
+ },
110
+ },
111
+ }
112
+ )
113
+ }