@jetthai/cuora 1.0.43 → 1.0.45

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/.prettierrc CHANGED
@@ -3,5 +3,5 @@
3
3
  "tabWidth": 2,
4
4
  "semi": false,
5
5
  "singleQuote": true,
6
- "printWidth": 120
6
+ "printWidth": 150
7
7
  }
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.45](https://github.com/jetthai/cuora-module/compare/v1.0.44...v1.0.45) (2021-11-23)
6
+
7
+ ### [1.0.44](https://github.com/jetthai/cuora-module/compare/v1.0.43...v1.0.44) (2021-11-22)
8
+
5
9
  ### [1.0.43](https://github.com/jetthai/cuora-module/compare/v1.0.42...v1.0.43) (2021-11-22)
6
10
 
7
11
  ### [1.0.42](https://github.com/jetthai/cuora-module/compare/v1.0.41...v1.0.42) (2021-11-16)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
package/src/api/auth.js CHANGED
@@ -5,10 +5,10 @@ export default {
5
5
  params: { username, password, provider, countryCode, phone, email },
6
6
  isPublic: true,
7
7
  }),
8
- register: (data) => ({
9
- url: 'register?channel=official&subchannel=pwa',
8
+ register: ({ channel = 'official', subchannel = 'pwa', ...rest }) => ({
9
+ url: `register?channel=${channel}&subchannel=${subchannel}`,
10
10
  method: 'post',
11
- params: data,
11
+ params: rest,
12
12
  isPublic: true,
13
13
  }),
14
14
  logout: () => ({ url: 'logout', method: 'post' }),
package/src/api/user.js CHANGED
@@ -1,3 +1,6 @@
1
+ export const PASSWORD_RESET_INIT = 'otp-verifying'
2
+ export const PASSWORD_RESET_ALLOW = 'allow-change-password'
3
+
1
4
  export default {
2
5
  getUserInfo: () => ({ url: 'self', method: 'get' }),
3
6
  updateUserInfo: (data) => ({ url: 'self', method: 'post', params: data }),
@@ -8,12 +11,26 @@ export default {
8
11
  postAffiliate: ({ affiliateCode }) => ({ url: 'affiliate', method: 'post', params: { affiliateCode } }),
9
12
  passwordRecovery: (recoveryData) => ({ url: 'recovery', method: 'post', params: recoveryData, isPublic: true }),
10
13
  passwordAbandon: ({ number }) => ({ url: 'recovery/abandon', method: 'post', params: { number }, isPublic: true }),
11
- passwordAcknowledge: (acknowledgeData) => ({
12
- url: 'recovery/acknowledge',
14
+ passwordAcknowledge: (acknowledgeData) => ({ url: 'recovery/acknowledge', method: 'post', params: acknowledgeData, isPublic: true }),
15
+ verify: () => ({ url: 'verify', method: 'post' }),
16
+ acknowledge: ({ requestId, code }) => ({ url: 'acknowledge', method: 'post', params: { requestId, code } }),
17
+ passwordV2RecoveryInit: ({ provider, username, countryCode, phone, email }) => ({
18
+ url: 'recovery/v2/initiate',
13
19
  method: 'post',
14
- params: acknowledgeData,
20
+ params: { provider, username, countryCode, phone, email },
21
+ isPublic: true,
22
+ }),
23
+ passwordV2Acknowledge: ({ requestId, target, code }) => ({
24
+ url: 'recovery/v2/acknowledge',
25
+ method: 'post',
26
+ params: { requestId, target, code },
27
+ isPublic: true,
28
+ }),
29
+ passwordV2Abandon: ({ requestId, target }) => ({ url: 'recovery/v2/abandon', method: 'post', params: { requestId, target }, isPublic: true }),
30
+ passwordV2Change: ({ requestId, target, newPassword }) => ({
31
+ url: 'recovery/v2/changePassword',
32
+ method: 'post',
33
+ params: { requestId, target, newPassword },
15
34
  isPublic: true,
16
35
  }),
17
- verify: () => ({ url: 'verify', method: 'post' }),
18
- acknowledge: ({ requestId, code }) => ({ url: 'acknowledge', method: 'post', params: { requestId, code } }),
19
36
  }
@@ -105,9 +105,7 @@ export default function (request) {
105
105
  },
106
106
  awardPrize: async (context, event) => {
107
107
  const { activityNo, uidSite, bindingCode } = context
108
- const { data } = await request.send(
109
- api.sentAward({ activityNo, uidSite, affiliateCode: bindingCode, appSecret })
110
- )
108
+ const { data } = await request.send(api.sentAward({ activityNo, uidSite, affiliateCode: bindingCode, appSecret }))
111
109
  return data
112
110
  },
113
111
  },
@@ -19,6 +19,14 @@ export default function (request) {
19
19
  token: null,
20
20
  tick: 2000,
21
21
  isPlaying: false,
22
+ loginData: {
23
+ provider: '',
24
+ countryCode: null,
25
+ phone: null,
26
+ email: null,
27
+ username: null,
28
+ password: null,
29
+ },
22
30
  userInfo: {},
23
31
  redirectURL: null,
24
32
  },
@@ -28,13 +36,16 @@ export default function (request) {
28
36
  always: [{ target: 'login', cond: 'hasToken' }],
29
37
  on: {
30
38
  LOGIN_PHONE: {
31
- target: 'authentication.phone',
39
+ target: 'authentication',
40
+ actions: 'setLoginPhone',
32
41
  },
33
42
  LOGIN_EMAIL: {
34
- target: 'authentication.email',
43
+ target: 'authentication',
44
+ actions: 'setLoginEmail',
35
45
  },
36
46
  LOGIN_LOCAL: {
37
- target: 'authentication.local',
47
+ target: 'authentication',
48
+ actions: 'setLoginLocal',
38
49
  },
39
50
  LOGIN_3PARTY: {
40
51
  actions: 'redirectTo3Party',
@@ -45,45 +56,15 @@ export default function (request) {
45
56
  },
46
57
  },
47
58
  authentication: {
48
- states: {
49
- phone: {
50
- invoke: {
51
- src: 'authenticateByPhone',
52
- onDone: {
53
- target: '#auth.login',
54
- actions: 'setToken',
55
- },
56
- onError: {
57
- target: '#auth.idle',
58
- actions: 'removeToken',
59
- },
60
- },
61
- },
62
- local: {
63
- invoke: {
64
- src: 'authenticateByUsername',
65
- onDone: {
66
- target: '#auth.login',
67
- actions: 'setToken',
68
- },
69
- onError: {
70
- target: '#auth.idle',
71
- actions: 'removeToken',
72
- },
73
- },
59
+ invoke: {
60
+ src: 'authenticate',
61
+ onDone: {
62
+ target: 'login',
63
+ actions: 'setToken',
74
64
  },
75
- email: {
76
- invoke: {
77
- src: 'authenticateByEmail',
78
- onDone: {
79
- target: '#auth.login',
80
- actions: 'setToken',
81
- },
82
- onError: {
83
- target: '#auth.idle',
84
- actions: 'removeToken',
85
- },
86
- },
65
+ onError: {
66
+ target: 'idle',
67
+ actions: 'removeToken',
87
68
  },
88
69
  },
89
70
  },
@@ -163,6 +144,41 @@ export default function (request) {
163
144
  },
164
145
  },
165
146
  actions: {
147
+ setLoginPhone: assign((context, event) => {
148
+ const { countryCode, phone, password } = event.data
149
+ return {
150
+ loginData: {
151
+ provider: 'phone',
152
+ countryCode,
153
+ phone,
154
+ password,
155
+ },
156
+ }
157
+ }),
158
+ setLoginEmail: assign((context, event) => {
159
+ const { email, password } = event.data
160
+ return {
161
+ loginData: {
162
+ provider: 'email',
163
+ email,
164
+ password,
165
+ },
166
+ }
167
+ }),
168
+ setLoginLocal: assign((context, event) => {
169
+ const { username, password } = event.data
170
+ cookies.set(userKey, username, {
171
+ path: '/',
172
+ maxAge: 60 * 60 * 24,
173
+ })
174
+ return {
175
+ loginData: {
176
+ provider: 'local',
177
+ username,
178
+ password,
179
+ },
180
+ }
181
+ }),
166
182
  fetchToken: assign((context, event) => {
167
183
  const token = cookies.get(tokenKey)
168
184
  return {
@@ -213,23 +229,8 @@ export default function (request) {
213
229
  }),
214
230
  },
215
231
  services: {
216
- authenticateByUsername: async (context, event) => {
217
- const { username, password } = event.data
218
- cookies.set(userKey, username, {
219
- path: '/',
220
- maxAge: 60 * 60 * 24,
221
- })
222
- const { token } = await request.send(auth.login({ provider: 'local', username, password }))
223
- return token
224
- },
225
- authenticateByPhone: async (context, event) => {
226
- const { countryCode, phone, password } = event.data
227
- const { token } = await request.send(auth.login({ provider: 'phone', countryCode, phone, password }))
228
- return token
229
- },
230
- authenticateByEmail: async (context, event) => {
231
- const { email, password } = event.data
232
- const { token } = await request.send(auth.login({ provider: 'email', email, password }))
232
+ authenticate: async (context, event) => {
233
+ const { token } = await request.send(auth.login(context.loginData))
233
234
  return token
234
235
  },
235
236
  logout: async (context, event) => {
@@ -16,6 +16,8 @@ import setting from './setting'
16
16
  import side from './side'
17
17
  import withdraw from './withdraw'
18
18
  import user_info from './user_info'
19
+ import user_sign_up from './user_sign_up'
20
+ import user_reset_password from './user_reset_password'
19
21
 
20
22
  export default {
21
23
  ...activity,
@@ -36,4 +38,6 @@ export default {
36
38
  side,
37
39
  withdraw,
38
40
  user_info,
41
+ user_sign_up,
42
+ user_reset_password,
39
43
  }
@@ -0,0 +1,173 @@
1
+ import { createMachine, assign } from 'xstate'
2
+ import user from '../api/user'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'user_reset_password',
8
+ initial: 'idle',
9
+ context: {
10
+ otpParams: {
11
+ provider: '',
12
+ username: null,
13
+ countryCode: null,
14
+ phone: null,
15
+ email: null,
16
+ },
17
+ requestId: null,
18
+ ttl: null,
19
+ target: {},
20
+ },
21
+ states: {
22
+ idle: {
23
+ on: {
24
+ SEND_OTP_EMAIL: {
25
+ target: 'preflight',
26
+ actions: 'setOtpParamsEmail',
27
+ },
28
+ SEND_OTP_LOCAL: {
29
+ target: 'preflight',
30
+ actions: 'setOtpParamsLocal',
31
+ },
32
+ SEND_OTP_PHONE: {
33
+ target: 'preflight',
34
+ actions: 'setOtpParamsPhone',
35
+ },
36
+ },
37
+ },
38
+ preflight: {
39
+ invoke: {
40
+ src: 'sendOtp',
41
+ onDone: {
42
+ target: 'otp',
43
+ actions: 'setInitialResult',
44
+ },
45
+ onError: {
46
+ target: 'idle',
47
+ },
48
+ },
49
+ },
50
+ otp: {
51
+ after: {
52
+ 1000: {
53
+ target: 'otp',
54
+ actions: 'decreaseTtl',
55
+ cond: (context) => context.ttl > 0,
56
+ },
57
+ },
58
+ on: {
59
+ ACKNOWLEDGE: {
60
+ target: 'acknowledging',
61
+ },
62
+ BACK: {
63
+ target: 'idle',
64
+ },
65
+ RESEND_OTP: {
66
+ target: 'preflight',
67
+ },
68
+ },
69
+ },
70
+ acknowledging: {
71
+ invoke: {
72
+ src: 'acknowledge',
73
+ onDone: {
74
+ target: 'acknowledged',
75
+ },
76
+ onError: {
77
+ target: 'otp',
78
+ },
79
+ },
80
+ },
81
+ acknowledged: {
82
+ on: {
83
+ CHANGE: {
84
+ target: 'changing',
85
+ actions: 'setNewPassword',
86
+ },
87
+ },
88
+ },
89
+ changing: {
90
+ invoke: {
91
+ src: 'change',
92
+ onDone: {
93
+ target: 'changed',
94
+ },
95
+ onError: {
96
+ target: 'acknowledged',
97
+ },
98
+ },
99
+ },
100
+ changed: {},
101
+ },
102
+ },
103
+ {
104
+ actions: {
105
+ setOtpParamsPhone: assign((context, event) => {
106
+ const { countryCode, phone } = event.data
107
+ return {
108
+ otpParams: {
109
+ provider: 'phone',
110
+ countryCode,
111
+ phone,
112
+ },
113
+ }
114
+ }),
115
+ setOtpParamsLocal: assign((context, event) => {
116
+ const { username } = event.data
117
+ return {
118
+ otpParams: {
119
+ provider: 'local',
120
+ username,
121
+ },
122
+ }
123
+ }),
124
+ setOtpParamsEmail: assign((context, event) => {
125
+ const { email } = event.data
126
+ return {
127
+ otpParams: {
128
+ provider: 'email',
129
+ email,
130
+ },
131
+ }
132
+ }),
133
+ setInitialResult: assign((context, event) => {
134
+ const { requestId, ttl, target } = event.data
135
+ return {
136
+ requestId,
137
+ ttl,
138
+ target,
139
+ }
140
+ }),
141
+ decreaseTtl: assign((context, event) => {
142
+ return {
143
+ ttl: Math.max(context.ttl - 1, 0),
144
+ }
145
+ }),
146
+ setNewPassword: assign((context, event) => {
147
+ return {
148
+ newPassword: event.data,
149
+ }
150
+ }),
151
+ },
152
+ services: {
153
+ sendOtp: async (context, event) => {
154
+ const { requestId, target } = context
155
+ if (requestId) {
156
+ await request.send(user.passwordV2Abandon({ requestId, target }))
157
+ }
158
+ const { provider, username, countryCode, phone, email } = context.otpParams
159
+ return await request.send(user.passwordV2RecoveryInit({ provider, username, countryCode, phone, email }))
160
+ },
161
+ acknowledge: async (context, event) => {
162
+ const { requestId, target } = context
163
+ const code = event.data
164
+ return await request.send(user.passwordV2Acknowledge({ requestId, target, code }))
165
+ },
166
+ change: async (context, event) => {
167
+ const { requestId, target, newPassword } = context
168
+ return await request.send(user.passwordV2Change({ requestId, target, newPassword }))
169
+ },
170
+ },
171
+ }
172
+ )
173
+ }
@@ -0,0 +1,93 @@
1
+ import { createMachine, assign } from 'xstate'
2
+ import auth from '../api/auth'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'user_sign_up',
8
+ initial: 'idle',
9
+ context: {
10
+ email: '',
11
+ password: '',
12
+ },
13
+ states: {
14
+ idle: {
15
+ on: {
16
+ SIGN_UP: {
17
+ target: 'validating',
18
+ actions: 'setForm',
19
+ },
20
+ },
21
+ },
22
+ invalidFormat: {
23
+ on: {
24
+ SIGN_UP: {
25
+ target: 'validating',
26
+ actions: 'setForm',
27
+ },
28
+ },
29
+ },
30
+ shortPassword: {
31
+ on: {
32
+ SIGN_UP: {
33
+ target: 'validating',
34
+ actions: 'setForm',
35
+ },
36
+ },
37
+ },
38
+ validating: {
39
+ always: [
40
+ {
41
+ target: 'invalidFormat',
42
+ cond: 'isInvalidFormat',
43
+ },
44
+ {
45
+ target: 'shortPassword',
46
+ cond: 'isLessThan6Characters',
47
+ },
48
+ {
49
+ target: 'submitting',
50
+ },
51
+ ],
52
+ },
53
+ submitting: {
54
+ invoke: {
55
+ src: 'signUp',
56
+ onDone: {
57
+ target: 'success',
58
+ },
59
+ onError: {
60
+ target: 'idle',
61
+ },
62
+ },
63
+ },
64
+ success: {},
65
+ },
66
+ },
67
+ {
68
+ actions: {
69
+ setForm: assign((context, event) => {
70
+ const { email, password } = event.data
71
+ return {
72
+ email,
73
+ password,
74
+ }
75
+ }),
76
+ },
77
+ guards: {
78
+ isInvalidFormat: (context, event) => {
79
+ return !context.email || /[+-]/.test(context.email)
80
+ },
81
+ isLessThan6Characters: (context, event) => {
82
+ return context.password.length < 6
83
+ },
84
+ },
85
+ services: {
86
+ signUp: async (context, event) => {
87
+ const { email, password } = context
88
+ return await request.send(auth.register({ provider: 'email', email, password }))
89
+ },
90
+ },
91
+ }
92
+ )
93
+ }
@@ -104,10 +104,7 @@ export default function (request) {
104
104
  },
105
105
  updatingInfo: async (context, event) => {
106
106
  const { bonus, gender } = context
107
- await Promise.all([
108
- request.send(payment.setBonusSetting({ bonus })),
109
- request.send(user.updateUserInfo({ gender })),
110
- ])
107
+ await Promise.all([request.send(payment.setBonusSetting({ bonus })), request.send(user.updateUserInfo({ gender }))])
111
108
  },
112
109
  },
113
110
  }
@@ -1,45 +0,0 @@
1
- import { createMachine, assign } from 'xstate'
2
-
3
- export default function (request) {
4
- return createMachine(
5
- {
6
- id: 'sign_up',
7
- initial: '',
8
- context: {
9
- email: '',
10
- password: '',
11
- },
12
- states: {
13
- idle: {
14
- on: {
15
- submit: {
16
- target: 'validating',
17
- actions: 'setAccount',
18
- },
19
- },
20
- },
21
- validating: {
22
- always: [],
23
- },
24
- submittin: {},
25
- success: {},
26
- },
27
- },
28
- {
29
- guards: {
30
- valid: (context, event) => {
31
- return /^[^+-]*@/.test(context.password)
32
- },
33
- },
34
- actions: {
35
- setAccount: assign((context, event) => {
36
- const { email, password } = event.data
37
- return {
38
- email,
39
- password,
40
- }
41
- }),
42
- },
43
- }
44
- )
45
- }