@jetthai/cuora 1.1.483-dev.2 → 1.1.483
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/.claude/commands/sync-ai-prompts.md +1 -88
- package/.claude/settings.local.json +1 -3
- package/.github/copilot-instructions.md +10 -19
- package/.husky/post-checkout +3 -3
- package/.husky/pre-push +1 -1
- package/.prettierignore +1 -2
- package/AGENTS.md +10 -19
- package/AI_PROMPT_SOURCE.md +10 -19
- package/CHANGELOG.md +23 -344
- package/CLAUDE.md +10 -19
- package/GEMINI.md +10 -19
- package/package.json +1 -1
- package/scripts/auto-version.js +0 -1
- package/scripts/branch-auto-npm-publish.js +2 -9
- package/src/api/payment.js +0 -1
- package/src/machine/auth_otp_v3.js +20 -59
- package/src/machine/honor_board_cash.js +18 -15
- package/src/machine/reward_cash.js +2 -2
- package/src/machine/user_sign_up.js +0 -3
- package/src/util/constant.js +0 -4
- package/test/auth_otp_v3.test.js +0 -323
package/package.json
CHANGED
package/scripts/auto-version.js
CHANGED
|
@@ -14,15 +14,8 @@ const { version } = JSON.parse(readFileSync('package.json', 'utf8'))
|
|
|
14
14
|
console.log(`Branch: ${branch}`)
|
|
15
15
|
console.log(`Version: ${version}`)
|
|
16
16
|
|
|
17
|
-
// 推送 commit 到遠端(--no-verify 避免觸發 pre-push hook 造成無限迴圈)
|
|
18
|
-
execSync(`git push --no-verify ${remote} ${branch}`, { stdio: 'inherit' })
|
|
19
|
-
|
|
20
|
-
// 單獨推送 tag;tag 已存在於 remote 時視為成功(不中斷 npm publish)
|
|
21
|
-
try {
|
|
22
|
-
execSync(`git push --no-verify ${remote} refs/tags/v${version}`, { stdio: 'inherit' })
|
|
23
|
-
} catch {
|
|
24
|
-
console.warn(`⚠ tag v${version} push 失敗(可能已存在),繼續 npm publish`)
|
|
25
|
-
}
|
|
17
|
+
// 推送 commit 與 tag 到遠端(--no-verify 避免觸發 pre-push hook 造成無限迴圈)
|
|
18
|
+
execSync(`git push --no-verify --follow-tags ${remote} ${branch}`, { stdio: 'inherit' })
|
|
26
19
|
|
|
27
20
|
// 發布到 npm,使用分支名稱作為 dist-tag(例如 npm install @jetthai/cuora@dev)
|
|
28
21
|
try {
|
package/src/api/payment.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import user from '../api/user.js'
|
|
3
3
|
import otp from '../api/otp.js'
|
|
4
|
-
import { AUTO_VERIFY_MAX_USER_INFO_UPDATES, AUTO_VERIFY_WAIT_MS } from '../util/constant.js'
|
|
5
|
-
|
|
6
|
-
function isStrategyVerified(strategy, userInfo) {
|
|
7
|
-
if (strategy === 'phone') return !!(userInfo?.phone || userInfo?.tel) && !!userInfo?.phone_verification_status
|
|
8
|
-
if (strategy === 'email') return !!userInfo?.email && !!userInfo?.email_verification_status
|
|
9
|
-
return false
|
|
10
|
-
}
|
|
11
4
|
|
|
12
5
|
export default function (request) {
|
|
13
6
|
return createMachine(
|
|
@@ -25,7 +18,6 @@ export default function (request) {
|
|
|
25
18
|
requestId: null,
|
|
26
19
|
status: null,
|
|
27
20
|
ttl: 0,
|
|
28
|
-
autoVerifyUpdates: 0,
|
|
29
21
|
},
|
|
30
22
|
states: {
|
|
31
23
|
idle: {
|
|
@@ -56,44 +48,16 @@ export default function (request) {
|
|
|
56
48
|
{ target: 'notVerified', cond: 'isNotVerified' },
|
|
57
49
|
],
|
|
58
50
|
},
|
|
59
|
-
autoVerifying: {
|
|
60
|
-
invoke: {
|
|
61
|
-
src: 'fetchUserInfo',
|
|
62
|
-
onDone: {
|
|
63
|
-
target: 'checkingAutoVerification',
|
|
64
|
-
actions: 'setUserInfo',
|
|
65
|
-
},
|
|
66
|
-
onError: { target: 'fail' },
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
checkingAutoVerification: {
|
|
70
|
-
always: [{ target: 'verified', cond: 'isVerified' }, { target: 'autoVerifyWaiting' }],
|
|
71
|
-
},
|
|
72
|
-
// 後端寫入驗證狀態到 /self 反映之間有延遲(主動打的那次可能還是舊值),
|
|
73
|
-
// 改等下游轉送 auth 例行輪詢的 /self 結果,不另開輪詢以免重複打 /self
|
|
74
|
-
autoVerifyWaiting: {
|
|
75
|
-
entry: 'resetAutoVerifyUpdates',
|
|
76
|
-
after: {
|
|
77
|
-
AUTO_VERIFY_TIMEOUT: { target: 'fail' },
|
|
78
|
-
},
|
|
79
|
-
on: {
|
|
80
|
-
USER_INFO_UPDATED: [
|
|
81
|
-
{ target: 'verified', cond: 'isUpdatedUserInfoVerified', actions: 'setUserInfo' },
|
|
82
|
-
{ target: 'fail', cond: 'isLastAutoVerifyUpdate', actions: 'setUserInfo' },
|
|
83
|
-
{ actions: ['setUserInfo', 'countAutoVerifyUpdate'] },
|
|
84
|
-
],
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
51
|
notVerified: {
|
|
88
52
|
initial: 'checkingStatus',
|
|
89
53
|
states: {
|
|
90
54
|
checkingStatus: {
|
|
91
55
|
invoke: {
|
|
92
56
|
src: 'verify',
|
|
93
|
-
onDone:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
57
|
+
onDone: {
|
|
58
|
+
target: 'otp',
|
|
59
|
+
actions: 'setVerificationData',
|
|
60
|
+
},
|
|
97
61
|
onError: {
|
|
98
62
|
target: 'errorChecking',
|
|
99
63
|
actions: 'setError',
|
|
@@ -122,20 +86,20 @@ export default function (request) {
|
|
|
122
86
|
sendingPhone: {
|
|
123
87
|
invoke: {
|
|
124
88
|
src: 'sendPhone',
|
|
125
|
-
onDone:
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
89
|
+
onDone: {
|
|
90
|
+
target: 'otp',
|
|
91
|
+
actions: 'setVerificationData',
|
|
92
|
+
},
|
|
129
93
|
onError: { target: 'phone' },
|
|
130
94
|
},
|
|
131
95
|
},
|
|
132
96
|
sendingEmail: {
|
|
133
97
|
invoke: {
|
|
134
98
|
src: 'sendEmail',
|
|
135
|
-
onDone:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
99
|
+
onDone: {
|
|
100
|
+
target: 'otp',
|
|
101
|
+
actions: 'setVerificationData',
|
|
102
|
+
},
|
|
139
103
|
onError: { target: 'email' },
|
|
140
104
|
},
|
|
141
105
|
},
|
|
@@ -199,9 +163,6 @@ export default function (request) {
|
|
|
199
163
|
},
|
|
200
164
|
},
|
|
201
165
|
{
|
|
202
|
-
delays: {
|
|
203
|
-
AUTO_VERIFY_TIMEOUT: AUTO_VERIFY_WAIT_MS,
|
|
204
|
-
},
|
|
205
166
|
actions: {
|
|
206
167
|
setStrategy: assign((context, event) => {
|
|
207
168
|
return {
|
|
@@ -232,8 +193,6 @@ export default function (request) {
|
|
|
232
193
|
ttl: Math.max(ms - 1000, 0),
|
|
233
194
|
}
|
|
234
195
|
}),
|
|
235
|
-
resetAutoVerifyUpdates: assign(() => ({ autoVerifyUpdates: 0 })),
|
|
236
|
-
countAutoVerifyUpdate: assign((context) => ({ autoVerifyUpdates: context.autoVerifyUpdates + 1 })),
|
|
237
196
|
setError: assign((context, event) => {
|
|
238
197
|
return {
|
|
239
198
|
error: event.data,
|
|
@@ -254,10 +213,12 @@ export default function (request) {
|
|
|
254
213
|
}),
|
|
255
214
|
},
|
|
256
215
|
guards: {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
216
|
+
isVerified: (context, event) => {
|
|
217
|
+
const { strategy, userInfo } = context
|
|
218
|
+
if (strategy === 'phone') return !!userInfo?.phone_verification_status
|
|
219
|
+
if (strategy === 'email') return !!userInfo?.email_verification_status
|
|
220
|
+
return false
|
|
221
|
+
},
|
|
261
222
|
isNotVerified: (context, event) => {
|
|
262
223
|
const { strategy, userInfo } = context
|
|
263
224
|
if (!userInfo) return false
|
|
@@ -267,11 +228,11 @@ export default function (request) {
|
|
|
267
228
|
},
|
|
268
229
|
isPhoneNotVerified: (context, event) => {
|
|
269
230
|
const { strategy, userInfo } = context
|
|
270
|
-
return strategy === 'phone' && !!userInfo && !
|
|
231
|
+
return strategy === 'phone' && !!userInfo && !userInfo.phone_verification_status && !userInfo.phone
|
|
271
232
|
},
|
|
272
233
|
isEmailNotVerified: (context, event) => {
|
|
273
234
|
const { strategy, userInfo } = context
|
|
274
|
-
return strategy === 'email' && !!userInfo && !userInfo.email
|
|
235
|
+
return strategy === 'email' && !!userInfo && !userInfo.email_verification_status && !userInfo.email
|
|
275
236
|
},
|
|
276
237
|
hasNoPhone: (context, event) => {
|
|
277
238
|
const { error } = context
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import { createMachine, assign } from 'xstate'
|
|
2
2
|
import activity from '../api/activity.js'
|
|
3
3
|
|
|
4
|
-
const TAB_KEY_BY_TYPE = {
|
|
5
|
-
CASH_RAIN: 'cashRain',
|
|
6
|
-
DEPOSIT: 'deposit',
|
|
7
|
-
FREE_ROULETTE_SPIN: 'roulette',
|
|
8
|
-
JACKPOT: 'jackpot',
|
|
9
|
-
WIN_SCORE: 'bigWin',
|
|
10
|
-
WIN_MULTIPLIER: 'maxBet',
|
|
11
|
-
WITHDRAW: 'withdraw',
|
|
12
|
-
LATEST_BET: 'latestBet',
|
|
13
|
-
}
|
|
14
|
-
|
|
15
4
|
export default function (request) {
|
|
16
5
|
const { appSecret } = request.config
|
|
17
6
|
return createMachine(
|
|
@@ -28,7 +17,6 @@ export default function (request) {
|
|
|
28
17
|
bigWin: {},
|
|
29
18
|
maxBet: {},
|
|
30
19
|
withdraw: {},
|
|
31
|
-
latestBet: {},
|
|
32
20
|
},
|
|
33
21
|
states: {
|
|
34
22
|
fetching: {
|
|
@@ -56,8 +44,24 @@ export default function (request) {
|
|
|
56
44
|
actions: {
|
|
57
45
|
setHonorBoardList: assign((context, event) => {
|
|
58
46
|
return {
|
|
59
|
-
|
|
60
|
-
|
|
47
|
+
tabs: (event.data || []).map((list) => {
|
|
48
|
+
switch (list.type) {
|
|
49
|
+
case 'CASH_RAIN':
|
|
50
|
+
return 'cashRain'
|
|
51
|
+
case 'DEPOSIT':
|
|
52
|
+
return 'deposit'
|
|
53
|
+
case 'FREE_ROULETTE_SPIN':
|
|
54
|
+
return 'roulette'
|
|
55
|
+
case 'JACKPOT':
|
|
56
|
+
return 'jackpot'
|
|
57
|
+
case 'WIN_SCORE':
|
|
58
|
+
return 'bigWin'
|
|
59
|
+
case 'WIN_MULTIPLIER':
|
|
60
|
+
return 'maxBet'
|
|
61
|
+
case 'WITHDRAW':
|
|
62
|
+
return 'withdraw'
|
|
63
|
+
}
|
|
64
|
+
}),
|
|
61
65
|
cashRain: (event.data || []).find((item) => item.type === 'CASH_RAIN') || {},
|
|
62
66
|
deposit: (event.data || []).find((item) => item.type === 'DEPOSIT') || {},
|
|
63
67
|
roulette: (event.data || []).find((item) => item.type === 'FREE_ROULETTE_SPIN') || {},
|
|
@@ -65,7 +69,6 @@ export default function (request) {
|
|
|
65
69
|
bigWin: (event.data || []).find((item) => item.type === 'WIN_SCORE') || {},
|
|
66
70
|
maxBet: (event.data || []).find((item) => item.type === 'WIN_MULTIPLIER') || {},
|
|
67
71
|
withdraw: (event.data || []).find((item) => item.type === 'WITHDRAW') || {},
|
|
68
|
-
latestBet: (event.data || []).find((item) => item.type === 'LATEST_BET') || {},
|
|
69
72
|
}
|
|
70
73
|
}),
|
|
71
74
|
},
|
|
@@ -197,7 +197,7 @@ export default function (request, context) {
|
|
|
197
197
|
)
|
|
198
198
|
const getOtherRewardAPI = request.send(
|
|
199
199
|
activity.getRewardList({
|
|
200
|
-
rewardType: 'CASH,FREE,PRIZE
|
|
200
|
+
rewardType: 'CASH,FREE,PRIZE',
|
|
201
201
|
count: 30,
|
|
202
202
|
appSecret,
|
|
203
203
|
orderColumn,
|
|
@@ -212,7 +212,7 @@ export default function (request, context) {
|
|
|
212
212
|
const lang = context.lang
|
|
213
213
|
const getOtherRewardAPI = request.send(
|
|
214
214
|
activity.getRewardList({
|
|
215
|
-
rewardType: 'CASH,FREE,PRIZE
|
|
215
|
+
rewardType: 'CASH,FREE,PRIZE',
|
|
216
216
|
count: 30,
|
|
217
217
|
appSecret,
|
|
218
218
|
orderColumn,
|
|
@@ -107,7 +107,6 @@ export default function (request) {
|
|
|
107
107
|
return {
|
|
108
108
|
signUpData: {
|
|
109
109
|
provider: 'local',
|
|
110
|
-
birthday,
|
|
111
110
|
...pickBindData(event.data),
|
|
112
111
|
birthday,
|
|
113
112
|
email,
|
|
@@ -131,7 +130,6 @@ export default function (request) {
|
|
|
131
130
|
return {
|
|
132
131
|
signUpData: {
|
|
133
132
|
provider: 'phone',
|
|
134
|
-
birthday,
|
|
135
133
|
...pickBindData(event.data),
|
|
136
134
|
birthday,
|
|
137
135
|
email,
|
|
@@ -154,7 +152,6 @@ export default function (request) {
|
|
|
154
152
|
return {
|
|
155
153
|
signUpData: {
|
|
156
154
|
provider: 'email',
|
|
157
|
-
birthday,
|
|
158
155
|
...pickBindData(event.data),
|
|
159
156
|
birthday,
|
|
160
157
|
email,
|
package/src/util/constant.js
CHANGED
|
@@ -17,7 +17,3 @@ export const GAME_TYPE_LIST = [
|
|
|
17
17
|
{ typeId: 'TURBO', name: 'Turbo', gameTypeMappingId: 15 },
|
|
18
18
|
{ typeId: 'SPORT', name: 'Sports', gameTypeMappingId: 16 },
|
|
19
19
|
]
|
|
20
|
-
|
|
21
|
-
// OTP 自動驗證:主動打的 /self 未通過後,最多再等幾次 auth 例行輪詢的 /self、等待上限多久
|
|
22
|
-
export const AUTO_VERIFY_MAX_USER_INFO_UPDATES = 2
|
|
23
|
-
export const AUTO_VERIFY_WAIT_MS = 5000
|
package/test/auth_otp_v3.test.js
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
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, 'autoVerifyWaiting')
|
|
126
|
-
const stale = { phone: '123456789', phone_verification_status: false, email: null, email_verification_status: false }
|
|
127
|
-
service.send({ type: 'USER_INFO_UPDATED', data: stale })
|
|
128
|
-
assert.equal(service.state.matches('autoVerifyWaiting'), true)
|
|
129
|
-
service.send({ type: 'USER_INFO_UPDATED', data: stale })
|
|
130
|
-
assert.equal(service.state.matches('fail'), true)
|
|
131
|
-
assert.equal(verifyCalls, 1)
|
|
132
|
-
} finally {
|
|
133
|
-
service.stop()
|
|
134
|
-
}
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
const autoVerifyEntries = [
|
|
138
|
-
{
|
|
139
|
-
name: 'existing phone',
|
|
140
|
-
strategy: 'phone',
|
|
141
|
-
initialUser: { phone: '123456789', phone_verification_status: false },
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
name: 'filled phone',
|
|
145
|
-
strategy: 'phone',
|
|
146
|
-
initialUser: { phone: null, phone_verification_status: false },
|
|
147
|
-
fill: { type: 'SEND_PHONE', data: { countryCode: '886', phone: '123456789' } },
|
|
148
|
-
waitFor: 'notVerified.phone',
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
name: 'filled email',
|
|
152
|
-
strategy: 'email',
|
|
153
|
-
initialUser: { email: null, email_verification_status: false },
|
|
154
|
-
fill: { type: 'SEND_EMAIL', data: { email: 'test@example.com' } },
|
|
155
|
-
waitFor: 'notVerified.email',
|
|
156
|
-
},
|
|
157
|
-
]
|
|
158
|
-
|
|
159
|
-
// 第 1 次 /self 為進入流程時抓的,第 2 次為 verify 後主動打的;兩次都尚未反映驗證結果
|
|
160
|
-
function staleSelfRequest(strategy, initialUser) {
|
|
161
|
-
const requests = []
|
|
162
|
-
const contact = strategy === 'phone' ? { phone: '123456789' } : { email: 'test@example.com' }
|
|
163
|
-
return {
|
|
164
|
-
requests,
|
|
165
|
-
contact,
|
|
166
|
-
async send(descriptor) {
|
|
167
|
-
requests.push(descriptor.url)
|
|
168
|
-
if (descriptor.url === 'self') {
|
|
169
|
-
return requests.filter((url) => url === 'self').length === 1 ? { ...initialUser } : { ...initialUser, ...contact }
|
|
170
|
-
}
|
|
171
|
-
if (descriptor.url === 'otp-verification-point/verify') return { needAcknowledge: false }
|
|
172
|
-
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
173
|
-
},
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
async function startAutoVerify(entry) {
|
|
178
|
-
const request = staleSelfRequest(entry.strategy, entry.initialUser)
|
|
179
|
-
const service = interpret(authOtpV3(request)).start()
|
|
180
|
-
service.send({ type: 'SET_STRATEGY', data: entry.strategy })
|
|
181
|
-
if (entry.fill) {
|
|
182
|
-
await waitForState(service, entry.waitFor)
|
|
183
|
-
service.send(entry.fill)
|
|
184
|
-
}
|
|
185
|
-
await waitForState(service, 'autoVerifyWaiting')
|
|
186
|
-
return { service, request }
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
for (const entry of autoVerifyEntries) {
|
|
190
|
-
test(`${entry.name}: stale /self waits and passes on a later polled /self`, async () => {
|
|
191
|
-
const { service, request } = await startAutoVerify(entry)
|
|
192
|
-
try {
|
|
193
|
-
const statusKey = `${entry.strategy}_verification_status`
|
|
194
|
-
service.send({ type: 'USER_INFO_UPDATED', data: { ...request.contact, [statusKey]: false } })
|
|
195
|
-
assert.equal(service.state.matches('autoVerifyWaiting'), true)
|
|
196
|
-
service.send({ type: 'USER_INFO_UPDATED', data: { ...request.contact, [statusKey]: true } })
|
|
197
|
-
assert.equal(service.state.matches('verified'), true)
|
|
198
|
-
assert.equal(service.state.context.userInfo[statusKey], true)
|
|
199
|
-
assert.deepEqual(request.requests, ['self', 'otp-verification-point/verify', 'self'])
|
|
200
|
-
} finally {
|
|
201
|
-
service.stop()
|
|
202
|
-
}
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
test(`${entry.name}: two stale polled /self responses fail`, async () => {
|
|
206
|
-
const { service, request } = await startAutoVerify(entry)
|
|
207
|
-
try {
|
|
208
|
-
const stale = { ...request.contact, [`${entry.strategy}_verification_status`]: false }
|
|
209
|
-
service.send({ type: 'USER_INFO_UPDATED', data: stale })
|
|
210
|
-
service.send({ type: 'USER_INFO_UPDATED', data: stale })
|
|
211
|
-
assert.equal(service.state.matches('fail'), true)
|
|
212
|
-
assert.deepEqual(request.requests, ['self', 'otp-verification-point/verify', 'self'])
|
|
213
|
-
} finally {
|
|
214
|
-
service.stop()
|
|
215
|
-
}
|
|
216
|
-
})
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
test('auto verify waiting fails after the 5 second limit without polled /self', async (t) => {
|
|
220
|
-
t.mock.timers.enable({ apis: ['setTimeout'] })
|
|
221
|
-
const { service } = await startAutoVerify(autoVerifyEntries[0])
|
|
222
|
-
try {
|
|
223
|
-
t.mock.timers.tick(4999)
|
|
224
|
-
assert.equal(service.state.matches('autoVerifyWaiting'), true)
|
|
225
|
-
t.mock.timers.tick(1)
|
|
226
|
-
assert.equal(service.state.matches('fail'), true)
|
|
227
|
-
} finally {
|
|
228
|
-
service.stop()
|
|
229
|
-
}
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
test('the 5 second limit is not reset by a stale polled /self', async (t) => {
|
|
233
|
-
t.mock.timers.enable({ apis: ['setTimeout'] })
|
|
234
|
-
const { service, request } = await startAutoVerify(autoVerifyEntries[0])
|
|
235
|
-
try {
|
|
236
|
-
t.mock.timers.tick(4000)
|
|
237
|
-
service.send({ type: 'USER_INFO_UPDATED', data: { ...request.contact, phone_verification_status: false } })
|
|
238
|
-
t.mock.timers.tick(1000)
|
|
239
|
-
assert.equal(service.state.matches('fail'), true)
|
|
240
|
-
} finally {
|
|
241
|
-
service.stop()
|
|
242
|
-
}
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
test('USER_INFO_UPDATED outside auto verify waiting does not change state', async () => {
|
|
246
|
-
const request = {
|
|
247
|
-
async send(descriptor) {
|
|
248
|
-
if (descriptor.url === 'self') return { phone: null, phone_verification_status: false }
|
|
249
|
-
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
250
|
-
},
|
|
251
|
-
}
|
|
252
|
-
const service = interpret(authOtpV3(request)).start()
|
|
253
|
-
try {
|
|
254
|
-
service.send({ type: 'SET_STRATEGY', data: 'phone' })
|
|
255
|
-
await waitForState(service, 'notVerified.phone')
|
|
256
|
-
service.send({ type: 'USER_INFO_UPDATED', data: { phone: '123456789', phone_verification_status: true } })
|
|
257
|
-
assert.equal(service.state.matches('notVerified.phone'), true)
|
|
258
|
-
} finally {
|
|
259
|
-
service.stop()
|
|
260
|
-
}
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
test('needAcknowledge true keeps the existing OTP input route', async () => {
|
|
264
|
-
const request = {
|
|
265
|
-
async send(descriptor) {
|
|
266
|
-
if (descriptor.url === 'self') {
|
|
267
|
-
return { phone: null, phone_verification_status: false, email: null, email_verification_status: false }
|
|
268
|
-
}
|
|
269
|
-
if (descriptor.url === 'otp-verification-point/verify') {
|
|
270
|
-
return { needAcknowledge: true, request_id: 'test-request', ttl: 60000, countryCode: '886', phone: '123456789' }
|
|
271
|
-
}
|
|
272
|
-
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
273
|
-
},
|
|
274
|
-
}
|
|
275
|
-
const service = interpret(authOtpV3(request)).start()
|
|
276
|
-
try {
|
|
277
|
-
service.send({ type: 'SET_STRATEGY', data: 'phone' })
|
|
278
|
-
await waitForState(service, 'notVerified.phone')
|
|
279
|
-
service.send({ type: 'SEND_PHONE', data: { countryCode: '886', phone: '123456789' } })
|
|
280
|
-
await waitForState(service, 'notVerified.otp')
|
|
281
|
-
assert.equal(service.state.context.requestId, 'test-request')
|
|
282
|
-
} finally {
|
|
283
|
-
service.stop()
|
|
284
|
-
}
|
|
285
|
-
})
|
|
286
|
-
|
|
287
|
-
test('email without an address still requires input even if its verification flag is true', async () => {
|
|
288
|
-
const request = {
|
|
289
|
-
async send(descriptor) {
|
|
290
|
-
if (descriptor.url === 'self') {
|
|
291
|
-
return { phone: '123456789', phone_verification_status: true, email: null, email_verification_status: true }
|
|
292
|
-
}
|
|
293
|
-
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
294
|
-
},
|
|
295
|
-
}
|
|
296
|
-
const service = interpret(authOtpV3(request)).start()
|
|
297
|
-
try {
|
|
298
|
-
service.send({ type: 'SET_STRATEGY', data: 'email' })
|
|
299
|
-
await waitForState(service, 'notVerified.email')
|
|
300
|
-
assert.equal(service.state.matches('verified'), false)
|
|
301
|
-
} finally {
|
|
302
|
-
service.stop()
|
|
303
|
-
}
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
test('phone without a number still requires input even if its verification flag is true', async () => {
|
|
307
|
-
const request = {
|
|
308
|
-
async send(descriptor) {
|
|
309
|
-
if (descriptor.url === 'self') {
|
|
310
|
-
return { phone: null, phone_verification_status: true, email: 'test@example.com', email_verification_status: true }
|
|
311
|
-
}
|
|
312
|
-
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
313
|
-
},
|
|
314
|
-
}
|
|
315
|
-
const service = interpret(authOtpV3(request)).start()
|
|
316
|
-
try {
|
|
317
|
-
service.send({ type: 'SET_STRATEGY', data: 'phone' })
|
|
318
|
-
await waitForState(service, 'notVerified.phone')
|
|
319
|
-
assert.equal(service.state.matches('verified'), false)
|
|
320
|
-
} finally {
|
|
321
|
-
service.stop()
|
|
322
|
-
}
|
|
323
|
-
})
|