@jetthai/cuora 1.0.45 → 1.0.47

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,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.47](https://github.com/jetthai/cuora-module/compare/v1.0.46...v1.0.47) (2021-11-24)
6
+
7
+ ### [1.0.46](https://github.com/jetthai/cuora-module/compare/v1.0.45...v1.0.46) (2021-11-23)
8
+
5
9
  ### [1.0.45](https://github.com/jetthai/cuora-module/compare/v1.0.44...v1.0.45) (2021-11-23)
6
10
 
7
11
  ### [1.0.44](https://github.com/jetthai/cuora-module/compare/v1.0.43...v1.0.44) (2021-11-22)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.45",
3
+ "version": "1.0.47",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
package/src/api/user.js CHANGED
@@ -27,6 +27,7 @@ export default {
27
27
  isPublic: true,
28
28
  }),
29
29
  passwordV2Abandon: ({ requestId, target }) => ({ url: 'recovery/v2/abandon', method: 'post', params: { requestId, target }, isPublic: true }),
30
+ passwordV2ResetOtp: ({ requestId, target }) => ({ url: 'recovery/v2/reset', method: 'post', params: { requestId, target }, isPublic: true }),
30
31
  passwordV2Change: ({ requestId, target, newPassword }) => ({
31
32
  url: 'recovery/v2/changePassword',
32
33
  method: 'post',
@@ -17,30 +17,32 @@ export default function (request) {
17
17
  requestId: null,
18
18
  ttl: null,
19
19
  target: {},
20
+ acknowledgeTtl: null,
21
+ newPassword: null,
20
22
  },
21
23
  states: {
22
24
  idle: {
23
25
  on: {
24
26
  SEND_OTP_EMAIL: {
25
- target: 'preflight',
27
+ target: 'otpFetching',
26
28
  actions: 'setOtpParamsEmail',
27
29
  },
28
30
  SEND_OTP_LOCAL: {
29
- target: 'preflight',
31
+ target: 'otpFetching',
30
32
  actions: 'setOtpParamsLocal',
31
33
  },
32
34
  SEND_OTP_PHONE: {
33
- target: 'preflight',
35
+ target: 'otpFetching',
34
36
  actions: 'setOtpParamsPhone',
35
37
  },
36
38
  },
37
39
  },
38
- preflight: {
40
+ otpFetching: {
39
41
  invoke: {
40
42
  src: 'sendOtp',
41
43
  onDone: {
42
44
  target: 'otp',
43
- actions: 'setInitialResult',
45
+ actions: 'setOtpResult',
44
46
  },
45
47
  onError: {
46
48
  target: 'idle',
@@ -49,11 +51,16 @@ export default function (request) {
49
51
  },
50
52
  otp: {
51
53
  after: {
52
- 1000: {
53
- target: 'otp',
54
- actions: 'decreaseTtl',
55
- cond: (context) => context.ttl > 0,
56
- },
54
+ 1000: [
55
+ {
56
+ target: 'otp',
57
+ actions: 'decreaseTtl',
58
+ cond: (context) => context.ttl > 0,
59
+ },
60
+ {
61
+ target: 'idle',
62
+ },
63
+ ],
57
64
  },
58
65
  on: {
59
66
  ACKNOWLEDGE: {
@@ -62,23 +69,54 @@ export default function (request) {
62
69
  BACK: {
63
70
  target: 'idle',
64
71
  },
65
- RESEND_OTP: {
66
- target: 'preflight',
72
+ RESET_OTP: {
73
+ target: 'otpResetting',
67
74
  },
68
75
  },
69
76
  },
70
- acknowledging: {
77
+ otpResetting: {
71
78
  invoke: {
72
- src: 'acknowledge',
79
+ src: 'resetOtp',
73
80
  onDone: {
74
- target: 'acknowledged',
81
+ target: 'otp',
82
+ actions: 'setOtpResult',
75
83
  },
76
84
  onError: {
77
85
  target: 'otp',
78
86
  },
79
87
  },
80
88
  },
89
+ acknowledging: {
90
+ invoke: {
91
+ src: 'acknowledge',
92
+ onDone: {
93
+ target: 'acknowledged',
94
+ actions: 'setAcknowledgeResult',
95
+ },
96
+ onError: [
97
+ {
98
+ target: 'idle',
99
+ cond: (context, event) => event.data.code === 'ERR_A108',
100
+ },
101
+ {
102
+ target: 'otp',
103
+ },
104
+ ],
105
+ },
106
+ },
81
107
  acknowledged: {
108
+ after: {
109
+ 1000: [
110
+ {
111
+ target: 'acknowledged',
112
+ actions: 'decreaseAcknowledgeTtl',
113
+ cond: (context) => context.acknowledgeTtl > 0,
114
+ },
115
+ {
116
+ target: 'idle',
117
+ },
118
+ ],
119
+ },
82
120
  on: {
83
121
  CHANGE: {
84
122
  target: 'changing',
@@ -92,9 +130,15 @@ export default function (request) {
92
130
  onDone: {
93
131
  target: 'changed',
94
132
  },
95
- onError: {
96
- target: 'acknowledged',
97
- },
133
+ onError: [
134
+ {
135
+ target: 'idle',
136
+ cond: (context, event) => event.data.code === 'ERR_A108',
137
+ },
138
+ {
139
+ target: 'acknowledged',
140
+ },
141
+ ],
98
142
  },
99
143
  },
100
144
  changed: {},
@@ -130,7 +174,7 @@ export default function (request) {
130
174
  },
131
175
  }
132
176
  }),
133
- setInitialResult: assign((context, event) => {
177
+ setOtpResult: assign((context, event) => {
134
178
  const { requestId, ttl, target } = event.data
135
179
  return {
136
180
  requestId,
@@ -143,6 +187,17 @@ export default function (request) {
143
187
  ttl: Math.max(context.ttl - 1, 0),
144
188
  }
145
189
  }),
190
+ setAcknowledgeResult: assign((context, event) => {
191
+ const { requestId, ttl, target } = event.data
192
+ return {
193
+ acknowledgeTtl: ttl,
194
+ }
195
+ }),
196
+ decreaseAcknowledgeTtl: assign((context, event) => {
197
+ return {
198
+ acknowledgeTtl: Math.max(context.acknowledgeTtl - 1, 0),
199
+ }
200
+ }),
146
201
  setNewPassword: assign((context, event) => {
147
202
  return {
148
203
  newPassword: event.data,
@@ -151,13 +206,13 @@ export default function (request) {
151
206
  },
152
207
  services: {
153
208
  sendOtp: async (context, event) => {
154
- const { requestId, target } = context
155
- if (requestId) {
156
- await request.send(user.passwordV2Abandon({ requestId, target }))
157
- }
158
209
  const { provider, username, countryCode, phone, email } = context.otpParams
159
210
  return await request.send(user.passwordV2RecoveryInit({ provider, username, countryCode, phone, email }))
160
211
  },
212
+ resetOtp: async (context, event) => {
213
+ const { requestId, target } = context
214
+ return await request.send(user.passwordV2ResetOtp({ requestId, target }))
215
+ },
161
216
  acknowledge: async (context, event) => {
162
217
  const { requestId, target } = context
163
218
  const code = event.data
@@ -76,10 +76,10 @@ export default function (request) {
76
76
  },
77
77
  guards: {
78
78
  isInvalidFormat: (context, event) => {
79
- return !context.email || /[+-]/.test(context.email)
79
+ // return !context.email || /[+-]/.test(context.email)
80
80
  },
81
81
  isLessThan6Characters: (context, event) => {
82
- return context.password.length < 6
82
+ // return context.password.length < 6
83
83
  },
84
84
  },
85
85
  services: {
@@ -223,6 +223,7 @@ export default function (request) {
223
223
  let distance = 0,
224
224
  limit = 0,
225
225
  amount = 0
226
+
226
227
  if (lastMatchedIndex > -1) {
227
228
  rules[lastMatchedIndex].match = true
228
229
  amount = rules[lastMatchedIndex].maxWithdrawAmount
@@ -241,6 +242,7 @@ export default function (request) {
241
242
  } else {
242
243
  amount = balance
243
244
  }
245
+
244
246
  return {
245
247
  withdrawDistance: distance,
246
248
  withdrawAmount: amount,