@jetthai/cuora 1.1.472-dev.1 → 1.1.472-dev.2
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 +8 -0
- package/package.json +1 -1
- package/src/machine/auth_otp_v3.js +30 -16
- package/test/auth_otp_v3.test.js +192 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
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.1.472-dev.2](https://github.com/jetthai/cuora-module/compare/v1.1.472-dev.1...v1.1.472-dev.2) (2026-10-01)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **otp:** confirm auto verification from user status ([b3b40d8](https://github.com/jetthai/cuora-module/commit/b3b40d8dd42d438486a2110f85564ab3d839ea72))
|
|
11
|
+
* **otp:** require contact data before provider completion ([f70058b](https://github.com/jetthai/cuora-module/commit/f70058b6bcbbc6d048049326700a79249d043a03))
|
|
12
|
+
|
|
5
13
|
### [1.1.472-dev.1](https://github.com/jetthai/cuora-module/compare/v1.1.472-dev.0...v1.1.472-dev.1) (2026-10-01)
|
|
6
14
|
|
|
7
15
|
|
package/package.json
CHANGED
|
@@ -48,16 +48,29 @@ export default function (request) {
|
|
|
48
48
|
{ target: 'notVerified', cond: 'isNotVerified' },
|
|
49
49
|
],
|
|
50
50
|
},
|
|
51
|
+
autoVerifying: {
|
|
52
|
+
invoke: {
|
|
53
|
+
src: 'fetchUserInfo',
|
|
54
|
+
onDone: {
|
|
55
|
+
target: 'checkingAutoVerification',
|
|
56
|
+
actions: 'setUserInfo',
|
|
57
|
+
},
|
|
58
|
+
onError: { target: 'fail' },
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
checkingAutoVerification: {
|
|
62
|
+
always: [{ target: 'verified', cond: 'isVerified' }, { target: 'fail' }],
|
|
63
|
+
},
|
|
51
64
|
notVerified: {
|
|
52
65
|
initial: 'checkingStatus',
|
|
53
66
|
states: {
|
|
54
67
|
checkingStatus: {
|
|
55
68
|
invoke: {
|
|
56
69
|
src: 'verify',
|
|
57
|
-
onDone:
|
|
58
|
-
target: '
|
|
59
|
-
actions: 'setVerificationData',
|
|
60
|
-
|
|
70
|
+
onDone: [
|
|
71
|
+
{ target: '#auth_otp.autoVerifying', cond: 'doesNotNeedAcknowledge' },
|
|
72
|
+
{ target: 'otp', actions: 'setVerificationData' },
|
|
73
|
+
],
|
|
61
74
|
onError: {
|
|
62
75
|
target: 'errorChecking',
|
|
63
76
|
actions: 'setError',
|
|
@@ -86,20 +99,20 @@ export default function (request) {
|
|
|
86
99
|
sendingPhone: {
|
|
87
100
|
invoke: {
|
|
88
101
|
src: 'sendPhone',
|
|
89
|
-
onDone:
|
|
90
|
-
target: '
|
|
91
|
-
actions: 'setVerificationData',
|
|
92
|
-
|
|
102
|
+
onDone: [
|
|
103
|
+
{ target: '#auth_otp.autoVerifying', cond: 'doesNotNeedAcknowledge' },
|
|
104
|
+
{ target: 'otp', actions: 'setVerificationData' },
|
|
105
|
+
],
|
|
93
106
|
onError: { target: 'phone' },
|
|
94
107
|
},
|
|
95
108
|
},
|
|
96
109
|
sendingEmail: {
|
|
97
110
|
invoke: {
|
|
98
111
|
src: 'sendEmail',
|
|
99
|
-
onDone:
|
|
100
|
-
target: '
|
|
101
|
-
actions: 'setVerificationData',
|
|
102
|
-
|
|
112
|
+
onDone: [
|
|
113
|
+
{ target: '#auth_otp.autoVerifying', cond: 'doesNotNeedAcknowledge' },
|
|
114
|
+
{ target: 'otp', actions: 'setVerificationData' },
|
|
115
|
+
],
|
|
103
116
|
onError: { target: 'email' },
|
|
104
117
|
},
|
|
105
118
|
},
|
|
@@ -213,10 +226,11 @@ export default function (request) {
|
|
|
213
226
|
}),
|
|
214
227
|
},
|
|
215
228
|
guards: {
|
|
229
|
+
doesNotNeedAcknowledge: (context, event) => event.data?.needAcknowledge === false,
|
|
216
230
|
isVerified: (context, event) => {
|
|
217
231
|
const { strategy, userInfo } = context
|
|
218
|
-
if (strategy === 'phone') return !!userInfo?.phone_verification_status
|
|
219
|
-
if (strategy === 'email') return !!userInfo?.email_verification_status
|
|
232
|
+
if (strategy === 'phone') return !!(userInfo?.phone || userInfo?.tel) && !!userInfo?.phone_verification_status
|
|
233
|
+
if (strategy === 'email') return !!userInfo?.email && !!userInfo?.email_verification_status
|
|
220
234
|
return false
|
|
221
235
|
},
|
|
222
236
|
isNotVerified: (context, event) => {
|
|
@@ -228,11 +242,11 @@ export default function (request) {
|
|
|
228
242
|
},
|
|
229
243
|
isPhoneNotVerified: (context, event) => {
|
|
230
244
|
const { strategy, userInfo } = context
|
|
231
|
-
return strategy === 'phone' && !!userInfo && !userInfo.
|
|
245
|
+
return strategy === 'phone' && !!userInfo && !(userInfo.phone || userInfo.tel)
|
|
232
246
|
},
|
|
233
247
|
isEmailNotVerified: (context, event) => {
|
|
234
248
|
const { strategy, userInfo } = context
|
|
235
|
-
return strategy === 'email' && !!userInfo && !userInfo.
|
|
249
|
+
return strategy === 'email' && !!userInfo && !userInfo.email
|
|
236
250
|
},
|
|
237
251
|
hasNoPhone: (context, event) => {
|
|
238
252
|
const { error } = context
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { interpret } from 'xstate'
|
|
4
|
+
import authOtpV3 from '../src/machine/auth_otp_v3.js'
|
|
5
|
+
|
|
6
|
+
function waitForState(service, matches) {
|
|
7
|
+
if (service.state.matches(matches)) return Promise.resolve(service.state)
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const timeout = setTimeout(() => reject(new Error(`Timed out waiting for ${matches}`)), 1000)
|
|
10
|
+
service.onTransition((state) => {
|
|
11
|
+
if (!state.matches(matches)) return
|
|
12
|
+
clearTimeout(timeout)
|
|
13
|
+
resolve(state)
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
test('phone entry skips OTP only after /self confirms phone verification', async () => {
|
|
19
|
+
let selfReads = 0
|
|
20
|
+
const requests = []
|
|
21
|
+
const request = {
|
|
22
|
+
async send(descriptor) {
|
|
23
|
+
requests.push(descriptor.url)
|
|
24
|
+
if (descriptor.url === 'self') {
|
|
25
|
+
selfReads++
|
|
26
|
+
return {
|
|
27
|
+
phone: selfReads === 1 ? null : '123456789',
|
|
28
|
+
phone_verification_status: selfReads > 1,
|
|
29
|
+
email: null,
|
|
30
|
+
email_verification_status: false,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (descriptor.url === 'otp-verification-point/verify') return { needAcknowledge: false }
|
|
34
|
+
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
const service = interpret(authOtpV3(request)).start()
|
|
38
|
+
try {
|
|
39
|
+
service.send({ type: 'SET_STRATEGY', data: 'phone' })
|
|
40
|
+
await waitForState(service, 'notVerified.phone')
|
|
41
|
+
service.send({ type: 'SEND_PHONE', data: { countryCode: '886', phone: '123456789' } })
|
|
42
|
+
await waitForState(service, 'verified')
|
|
43
|
+
assert.equal(selfReads, 2)
|
|
44
|
+
assert.deepEqual(requests, ['self', 'otp-verification-point/verify', 'self'])
|
|
45
|
+
} finally {
|
|
46
|
+
service.stop()
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('email entry skips OTP only after /self confirms email verification', async () => {
|
|
51
|
+
let selfReads = 0
|
|
52
|
+
const request = {
|
|
53
|
+
async send(descriptor) {
|
|
54
|
+
if (descriptor.url === 'self') {
|
|
55
|
+
selfReads++
|
|
56
|
+
return {
|
|
57
|
+
phone: null,
|
|
58
|
+
phone_verification_status: false,
|
|
59
|
+
email: selfReads === 1 ? null : 'test@example.com',
|
|
60
|
+
email_verification_status: selfReads > 1,
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (descriptor.url === 'otp-verification-point/verify') return { needAcknowledge: false }
|
|
64
|
+
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
const service = interpret(authOtpV3(request)).start()
|
|
68
|
+
try {
|
|
69
|
+
service.send({ type: 'SET_STRATEGY', data: 'email' })
|
|
70
|
+
await waitForState(service, 'notVerified.email')
|
|
71
|
+
service.send({ type: 'SEND_EMAIL', data: { email: 'test@example.com' } })
|
|
72
|
+
await waitForState(service, 'verified')
|
|
73
|
+
assert.equal(selfReads, 2)
|
|
74
|
+
} finally {
|
|
75
|
+
service.stop()
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('existing phone auto verification checks /self before finishing', async () => {
|
|
80
|
+
let selfReads = 0
|
|
81
|
+
const request = {
|
|
82
|
+
async send(descriptor) {
|
|
83
|
+
if (descriptor.url === 'self') {
|
|
84
|
+
selfReads++
|
|
85
|
+
return {
|
|
86
|
+
phone: '123456789',
|
|
87
|
+
phone_verification_status: selfReads > 1,
|
|
88
|
+
email: null,
|
|
89
|
+
email_verification_status: false,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (descriptor.url === 'otp-verification-point/verify') return { needAcknowledge: false }
|
|
93
|
+
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
const service = interpret(authOtpV3(request)).start()
|
|
97
|
+
try {
|
|
98
|
+
service.send({ type: 'SET_STRATEGY', data: 'phone' })
|
|
99
|
+
await waitForState(service, 'verified')
|
|
100
|
+
assert.equal(selfReads, 2)
|
|
101
|
+
} finally {
|
|
102
|
+
service.stop()
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('needAcknowledge false never grants verification when /self is still unverified', async () => {
|
|
107
|
+
let verifyCalls = 0
|
|
108
|
+
const request = {
|
|
109
|
+
async send(descriptor) {
|
|
110
|
+
if (descriptor.url === 'self') {
|
|
111
|
+
return { phone: null, phone_verification_status: false, email: null, email_verification_status: false }
|
|
112
|
+
}
|
|
113
|
+
if (descriptor.url === 'otp-verification-point/verify') {
|
|
114
|
+
verifyCalls++
|
|
115
|
+
return { needAcknowledge: false }
|
|
116
|
+
}
|
|
117
|
+
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
const service = interpret(authOtpV3(request)).start()
|
|
121
|
+
try {
|
|
122
|
+
service.send({ type: 'SET_STRATEGY', data: 'phone' })
|
|
123
|
+
await waitForState(service, 'notVerified.phone')
|
|
124
|
+
service.send({ type: 'SEND_PHONE', data: { countryCode: '886', phone: '123456789' } })
|
|
125
|
+
await waitForState(service, 'fail')
|
|
126
|
+
assert.equal(verifyCalls, 1)
|
|
127
|
+
} finally {
|
|
128
|
+
service.stop()
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('needAcknowledge true keeps the existing OTP input route', async () => {
|
|
133
|
+
const request = {
|
|
134
|
+
async send(descriptor) {
|
|
135
|
+
if (descriptor.url === 'self') {
|
|
136
|
+
return { phone: null, phone_verification_status: false, email: null, email_verification_status: false }
|
|
137
|
+
}
|
|
138
|
+
if (descriptor.url === 'otp-verification-point/verify') {
|
|
139
|
+
return { needAcknowledge: true, request_id: 'test-request', ttl: 60000, countryCode: '886', phone: '123456789' }
|
|
140
|
+
}
|
|
141
|
+
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
142
|
+
},
|
|
143
|
+
}
|
|
144
|
+
const service = interpret(authOtpV3(request)).start()
|
|
145
|
+
try {
|
|
146
|
+
service.send({ type: 'SET_STRATEGY', data: 'phone' })
|
|
147
|
+
await waitForState(service, 'notVerified.phone')
|
|
148
|
+
service.send({ type: 'SEND_PHONE', data: { countryCode: '886', phone: '123456789' } })
|
|
149
|
+
await waitForState(service, 'notVerified.otp')
|
|
150
|
+
assert.equal(service.state.context.requestId, 'test-request')
|
|
151
|
+
} finally {
|
|
152
|
+
service.stop()
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
test('email without an address still requires input even if its verification flag is true', async () => {
|
|
157
|
+
const request = {
|
|
158
|
+
async send(descriptor) {
|
|
159
|
+
if (descriptor.url === 'self') {
|
|
160
|
+
return { phone: '123456789', phone_verification_status: true, email: null, email_verification_status: true }
|
|
161
|
+
}
|
|
162
|
+
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
const service = interpret(authOtpV3(request)).start()
|
|
166
|
+
try {
|
|
167
|
+
service.send({ type: 'SET_STRATEGY', data: 'email' })
|
|
168
|
+
await waitForState(service, 'notVerified.email')
|
|
169
|
+
assert.equal(service.state.matches('verified'), false)
|
|
170
|
+
} finally {
|
|
171
|
+
service.stop()
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
test('phone without a number still requires input even if its verification flag is true', async () => {
|
|
176
|
+
const request = {
|
|
177
|
+
async send(descriptor) {
|
|
178
|
+
if (descriptor.url === 'self') {
|
|
179
|
+
return { phone: null, phone_verification_status: true, email: 'test@example.com', email_verification_status: true }
|
|
180
|
+
}
|
|
181
|
+
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
182
|
+
},
|
|
183
|
+
}
|
|
184
|
+
const service = interpret(authOtpV3(request)).start()
|
|
185
|
+
try {
|
|
186
|
+
service.send({ type: 'SET_STRATEGY', data: 'phone' })
|
|
187
|
+
await waitForState(service, 'notVerified.phone')
|
|
188
|
+
assert.equal(service.state.matches('verified'), false)
|
|
189
|
+
} finally {
|
|
190
|
+
service.stop()
|
|
191
|
+
}
|
|
192
|
+
})
|