@jetthai/cuora 1.1.474 → 1.1.476-dev.0

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 (86) hide show
  1. package/.claude/commands/sync-ai-prompts.md +88 -1
  2. package/.claude/settings.local.json +3 -1
  3. package/.github/copilot-instructions.md +66 -61
  4. package/.husky/post-checkout +3 -3
  5. package/.husky/pre-push +1 -1
  6. package/.prettierignore +2 -1
  7. package/AGENTS.md +67 -62
  8. package/AI_PROMPT_SOURCE.md +67 -62
  9. package/CHANGELOG.md +261 -6
  10. package/CLAUDE.md +67 -62
  11. package/GEMINI.md +67 -62
  12. package/README.md +11 -12
  13. package/package.json +1 -1
  14. package/prepare-for-pr/JT-1776243420.md +85 -0
  15. package/scripts/auto-version.js +1 -0
  16. package/scripts/branch-auto-npm-publish.js +9 -2
  17. package/src/api/account.js +0 -1
  18. package/src/api/activity.js +0 -37
  19. package/src/api/auth.js +0 -31
  20. package/src/api/game.js +0 -10
  21. package/src/api/payment.js +1 -52
  22. package/src/api/user.js +0 -16
  23. package/src/index.js +2 -2
  24. package/src/machine/activity/activity_cash.js +14 -1
  25. package/src/machine/activity/diamond_shop_activity_cash.js +0 -1
  26. package/src/machine/activity/fafafa_activity.js +0 -10
  27. package/src/machine/activity/index.js +0 -12
  28. package/src/machine/auth.js +37 -59
  29. package/src/machine/auth_otp_v3.js +30 -19
  30. package/src/machine/common.js +0 -55
  31. package/src/machine/deposit/index.js +0 -28
  32. package/src/machine/deposit/manual_cash.js +0 -8
  33. package/src/machine/game_info.js +1 -12
  34. package/src/machine/game_v2_1.js +1 -89
  35. package/src/machine/honor_board_cash.js +15 -18
  36. package/src/machine/inbox.js +0 -12
  37. package/src/machine/index.js +0 -32
  38. package/src/machine/reward_cash.js +0 -39
  39. package/src/machine/user_reset_password.js +0 -13
  40. package/src/machine/user_sign_up.js +3 -0
  41. package/src/machine/websocket.js +0 -4
  42. package/src/machine/withdraw/index.js +0 -6
  43. package/src/request/request.js +0 -28
  44. package/src/util/constant.js +0 -1
  45. package/src/util/index.js +1 -4
  46. package/test/auth_otp_v3.test.js +192 -0
  47. package/src/machine/activity/activity.js +0 -209
  48. package/src/machine/activity/diamond_shop_activity_fc.js +0 -196
  49. package/src/machine/activity/diamond_shop_activity_vn.js +0 -178
  50. package/src/machine/activity/invite_friends_activity.js +0 -114
  51. package/src/machine/activity/mini_game_activity.js +0 -68
  52. package/src/machine/activity/return_bonus_activity.js +0 -153
  53. package/src/machine/auth_otp_v2.js +0 -177
  54. package/src/machine/bank_binding_amb.js +0 -146
  55. package/src/machine/bonus.js +0 -76
  56. package/src/machine/deposit/amb.js +0 -93
  57. package/src/machine/deposit/crypto_bank.js +0 -330
  58. package/src/machine/deposit/crypto_qrcode.js +0 -148
  59. package/src/machine/deposit/crypto_way.js +0 -252
  60. package/src/machine/deposit/deposit_fc.js +0 -272
  61. package/src/machine/deposit/direct.js +0 -310
  62. package/src/machine/deposit/float.js +0 -375
  63. package/src/machine/deposit/krway.js +0 -151
  64. package/src/machine/deposit/loadcard_vn.js +0 -351
  65. package/src/machine/deposit/manual_vn.js +0 -458
  66. package/src/machine/deposit/qrcode_v2.js +0 -338
  67. package/src/machine/deposit/usdt.js +0 -144
  68. package/src/machine/deposit/virtual_bank_vn.js +0 -269
  69. package/src/machine/deposit/vpay.js +0 -368
  70. package/src/machine/game_hot_new.js +0 -79
  71. package/src/machine/game_replay.js +0 -46
  72. package/src/machine/game_search_v2.js +0 -401
  73. package/src/machine/honor_board.js +0 -132
  74. package/src/machine/merge.js +0 -57
  75. package/src/machine/payment_data.js +0 -86
  76. package/src/machine/promotions.js +0 -170
  77. package/src/machine/reward.js +0 -255
  78. package/src/machine/reward_fc.js +0 -98
  79. package/src/machine/side.js +0 -154
  80. package/src/machine/side_v2.js +0 -211
  81. package/src/machine/vip_table.js +0 -57
  82. package/src/machine/welcome.js +0 -110
  83. package/src/machine/withdraw/withdraw_crypto_cash.js +0 -327
  84. package/src/machine/withdraw/withdraw_krway.js +0 -223
  85. package/src/machine/withdraw/withdraw_manual.js +0 -536
  86. package/src/util/math.js +0 -4
@@ -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
+ })
@@ -1,209 +0,0 @@
1
- import { createMachine, assign } from 'xstate'
2
- import activity from '../../api/activity.js'
3
- import payment from '../../api/payment.js'
4
-
5
- export default function (request) {
6
- const { appSecret } = request.config
7
- return createMachine(
8
- {
9
- id: 'activity',
10
- initial: 'init',
11
- context: {
12
- tick: 2000,
13
- specifyActivities: [4, 29, 34],
14
- activitiesDetailList: [],
15
- activityList: [],
16
- promotionList: [],
17
- activityMap: {},
18
- tournamentList: [],
19
- refs: {},
20
- uidSite: '',
21
- siteConfig: {},
22
- isPlaying: false,
23
- },
24
- states: {
25
- init: {
26
- on: {
27
- SET_CONFIG: {
28
- target: 'fetchingList',
29
- actions: 'setSiteConifg',
30
- },
31
- },
32
- },
33
- fetchingList: {
34
- invoke: {
35
- src: 'fetchList',
36
- onDone: {
37
- target: 'idle',
38
- actions: ['setActivityList', 'setTournamentList', 'setPromotionList'],
39
- },
40
- onError: {
41
- target: 'idle',
42
- },
43
- },
44
- },
45
- idle: {
46
- type: 'parallel',
47
- states: {
48
- activitiesDetail: {
49
- initial: 'checking',
50
- states: {
51
- checking: {
52
- always: [{ target: 'fetchActivityDetail', cond: 'hasSpecifyActivities' }, { target: 'end' }],
53
- },
54
- fetchActivityDetail: {
55
- invoke: {
56
- src: 'fetchActivitiesDetail',
57
- onDone: {
58
- target: 'end',
59
- actions: 'setActivitiesDetailList',
60
- },
61
- onError: {
62
- target: 'end',
63
- },
64
- },
65
- },
66
- end: {},
67
- },
68
- },
69
- pending: {
70
- after: {
71
- TIMEOUT: [
72
- { target: '#activity.fetchingList', cond: 'isNotInGame' },
73
- { target: '#activity.idle', cond: 'isInGame' },
74
- ],
75
- },
76
- on: {
77
- SET_UNREAD: {
78
- actions: 'setUnread',
79
- },
80
- RESET_ACTIVITIES: {
81
- actions: 'resetActivities',
82
- },
83
- },
84
- },
85
- },
86
- },
87
- },
88
- on: {
89
- REFRESH: {
90
- target: '#activity.fetchingList',
91
- actions: 'leaveGame',
92
- },
93
- },
94
- },
95
- {
96
- actions: {
97
- setSiteConifg: assign((context, event) => {
98
- return {
99
- siteConfig: event.data,
100
- }
101
- }),
102
- setTournamentList: assign((context, event) => {
103
- const { activityList } = event.data
104
- const tournamentList = activityList.filter((item) => item.tournament === 1)
105
- return {
106
- tournamentList,
107
- }
108
- }),
109
- setActivityList: assign((context, event) => {
110
- const noRedActivity = [2, 4, 13, 20, 90, 91, 92]
111
- const { uidSite } = context
112
- const { activityList } = event.data
113
- let list = JSON.parse(JSON.stringify(activityList))
114
- list.forEach((activity) => {
115
- const storageUnread = localStorage.getItem(`unread_${activity.activityNo}_${uidSite}`)
116
- if (noRedActivity.includes(activity.activityType)) {
117
- activity.unread = false
118
- } else if (storageUnread) {
119
- activity.unread = JSON.parse(storageUnread)
120
- } else {
121
- activity.unread = true
122
- }
123
- })
124
- return {
125
- activityList: list,
126
- }
127
- }),
128
- setPromotionList: assign((context, event) => {
129
- const { promotionList } = event.data
130
- return {
131
- promotionList,
132
- }
133
- }),
134
- setActivitiesDetailList: assign((context, event) => {
135
- return {
136
- activitiesDetailList: event.data.map((item) => item.data),
137
- }
138
- }),
139
- setUnread: assign((context, event) => {
140
- const { uidSite, activityNo, unread } = event.data
141
- const list = JSON.parse(JSON.stringify(context.activityList))
142
- localStorage.setItem(`unread_${activityNo}_${uidSite}`, `${unread}`)
143
- list.map((item) => {
144
- if (item.activityNo === activityNo) {
145
- item.unread = JSON.parse(`${unread}`)
146
- }
147
- return item
148
- })
149
- return {
150
- activityList: list,
151
- uidSite,
152
- }
153
- }),
154
- resetActivities: assign((context, event) => {
155
- return {
156
- isPlaying: true,
157
- }
158
- }),
159
- leaveGame: assign((context, event) => {
160
- return {
161
- isPlaying: false,
162
- }
163
- }),
164
- },
165
- guards: {
166
- hasSpecifyActivities: (context, event) => {
167
- const { activityList = [], specifyActivities = [] } = context
168
- const filterActivityList = activityList.filter((activity) => specifyActivities.includes(activity.activityType))
169
- return filterActivityList.length > 0
170
- },
171
- isInGame: (context, event) => {
172
- return context.isPlaying
173
- },
174
- isNotInGame: (context, event) => {
175
- return !context.isPlaying
176
- },
177
- },
178
- delays: {
179
- TIMEOUT: (context, event) => {
180
- const { tick } = context
181
- return tick * 10
182
- },
183
- },
184
- services: {
185
- fetchList: async (context, event) => {
186
- const hasToken = request.getToken()
187
- const apiCallable = hasToken
188
- const [{ data }, promotionList] = await Promise.all([
189
- hasToken ? request.send(activity.getActivityList({ appSecret })) : request.send(activity.getAllActivityList({ appSecret })),
190
- apiCallable && !context.isPlaying ? request.send(payment.getPromotionsList()) : [],
191
- ])
192
-
193
- return { activityList: data, promotionList }
194
- },
195
- fetchActivitiesDetail: async (context, event) => {
196
- await new Promise((resolve) => setTimeout(resolve, 1000)) // delay 1 second
197
-
198
- const { activityList = [], specifyActivities = [] } = context
199
- const filterActivityList = activityList.filter((activity) => specifyActivities.includes(activity.activityType))
200
- const promiseArray = filterActivityList.map((item) => {
201
- return request.send(activity.getActivityDetail({ activityNo: item.activityNo, appSecret }))
202
- })
203
- const activitiesDetail = await Promise.all(promiseArray)
204
- return activitiesDetail
205
- },
206
- },
207
- }
208
- )
209
- }
@@ -1,196 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import api from '../../api/activity.js'
3
-
4
- export default function (request) {
5
- const { appSecret } = request.config
6
- return createMachine(
7
- {
8
- id: 'diamond_shop_activity',
9
- context: {
10
- activityNo: null,
11
- activityDetail: null,
12
- awards: [],
13
- exchangeList: [],
14
- exchangeAward: 0,
15
- exchangePoint: 0,
16
- },
17
- initial: 'fetching',
18
- states: {
19
- fetching: {
20
- invoke: {
21
- src: 'fetchActivityList',
22
- onDone: {
23
- target: 'checking',
24
- actions: 'setDiamondShopActivities',
25
- },
26
- onError: {
27
- target: 'idle',
28
- },
29
- },
30
- },
31
- idle: {
32
- on: {
33
- SET_ACTIVITY_NO: {
34
- // todo - deprecated
35
- },
36
- },
37
- },
38
- checking: {
39
- always: [{ target: 'loading', cond: 'hasActivityNo' }],
40
- },
41
- loading: {
42
- invoke: {
43
- src: 'fetchActivityDetail',
44
- onDone: {
45
- target: 'loaded',
46
- actions: ['setActivityDetail', 'setAwardList'],
47
- },
48
- onError: {
49
- target: 'idle',
50
- },
51
- },
52
- },
53
- loaded: {
54
- on: {
55
- EXCHANGE: {
56
- target: 'exchanging',
57
- cond: 'isExchangeable',
58
- },
59
- ADD_TO_CART: {
60
- actions: ['addProduct', 'count'],
61
- },
62
- CLEAR_CART: {
63
- actions: ['clearCart', 'count'],
64
- },
65
- COLLECT: {
66
- target: 'collecting',
67
- cond: 'hasUnclaimedReward',
68
- },
69
- },
70
- },
71
- exchanging: {
72
- invoke: {
73
- src: 'exchange',
74
- onDone: {
75
- target: 'collecting',
76
- actions: ['clearCart', 'count'],
77
- },
78
- onError: {
79
- target: 'loaded',
80
- },
81
- },
82
- },
83
- collecting: {
84
- invoke: {
85
- src: 'collect',
86
- onDone: {
87
- target: 'collected',
88
- },
89
- onError: {
90
- target: 'collected',
91
- },
92
- },
93
- },
94
- collected: {
95
- after: {
96
- 0: {
97
- target: 'loaded',
98
- },
99
- },
100
- },
101
- },
102
- },
103
- {
104
- actions: {
105
- setActivityNo: assign((context, event) => {
106
- return {
107
- activityNo: event.data,
108
- }
109
- }),
110
- setDiamondShopActivities: assign((context, event) => {
111
- const rankActivities = event.data.filter((item) => item.activityType === 91)
112
- return {
113
- rankActivities,
114
- activityNo: rankActivities?.[0]?.activityNo,
115
- }
116
- }),
117
- setActivityDetail: assign((context, event) => {
118
- return {
119
- activityDetail: event.data,
120
- }
121
- }),
122
- setAwardList: assign((context, event) => {
123
- return {
124
- awardList: event.data?.awards || [],
125
- }
126
- }),
127
- addProduct: assign((context, event) => {
128
- return {
129
- exchangeList: [...context.exchangeList, event.data],
130
- }
131
- }),
132
- clearCart: assign((context, event) => {
133
- return {
134
- exchangeList: [],
135
- }
136
- }),
137
- count: assign((context, event) => {
138
- const { exchangeList } = context
139
- const { exchangeAward, exchangePoint } = exchangeList.reduce(
140
- ({ exchangeAward, exchangePoint }, item) => {
141
- return {
142
- exchangeAward: exchangeAward + item.award,
143
- exchangePoint: exchangePoint + item.points,
144
- }
145
- },
146
- { exchangeAward: 0, exchangePoint: 0 }
147
- )
148
- return {
149
- exchangeAward,
150
- exchangePoint,
151
- }
152
- }),
153
- },
154
- guards: {
155
- hasUnclaimedReward: (context, event) => {
156
- return context.activityDetail?.unclaimedReward?.length > 0
157
- },
158
- isExchangeable: (context, event) => {
159
- const { exchangeList } = context
160
- return exchangeList.length > 0
161
- },
162
- hasActivityNo: (context, event) => {
163
- return !!context.activityNo
164
- },
165
- },
166
- services: {
167
- fetchActivityList: async (context, event) => {
168
- const { data } = await request.send(api.getActivityList({ appSecret }))
169
- return data
170
- },
171
- fetchActivityDetail: async (context, event) => {
172
- const { activityNo } = context
173
- const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
174
- return data
175
- },
176
- exchange: async (context, event) => {
177
- const { activityNo, exchangeList } = context
178
- return await Promise.all(
179
- exchangeList.map((item) =>
180
- request.send(
181
- api.exchange({
182
- exchangeType: 1,
183
- activityNo,
184
- exchangeAward: item.award,
185
- })
186
- )
187
- )
188
- )
189
- },
190
- collect: async (context, event) => {
191
- return await request.send(api.collect({ appSecret }))
192
- },
193
- },
194
- }
195
- )
196
- }