@jetthai/cuora 1.2.0 → 2.0.0-beta.1

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 (166) hide show
  1. package/BREAKING_CHANGES.md +9 -0
  2. package/CHANGELOG.md +36 -0
  3. package/package.json +5 -2
  4. package/resetGitBranch.sh +16 -16
  5. package/src/api/account.js +8 -0
  6. package/src/api/auth.js +1 -1
  7. package/src/api/common.js +6 -1
  8. package/src/api/index.js +3 -1
  9. package/src/api/otp.js +5 -0
  10. package/src/api/user.js +1 -0
  11. package/src/machine/activity/activity.js +23 -19
  12. package/src/machine/activity/activity_cash.js +27 -22
  13. package/src/machine/activity/cash_rain_activity.js +1 -0
  14. package/src/machine/activity/continue_deposit_activity.js +1 -0
  15. package/src/machine/activity/deposit_activity.js +1 -0
  16. package/src/machine/activity/diamond_shop_activity_cash.js +7 -0
  17. package/src/machine/activity/diamond_shop_activity_fc.js +1 -0
  18. package/src/machine/activity/diamond_shop_activity_vn.js +1 -0
  19. package/src/machine/activity/fafafa_activity.js +1 -0
  20. package/src/machine/activity/friend_invite_friends_activity.js +7 -8
  21. package/src/machine/activity/instant_rebate_activity.js +1 -0
  22. package/src/machine/activity/invite_friends_activity.js +1 -0
  23. package/src/machine/activity/jackpot.js +1 -0
  24. package/src/machine/activity/mini_game_activity.js +1 -0
  25. package/src/machine/activity/otp_verified_activity.js +1 -0
  26. package/src/machine/activity/ranking_activity.js +1 -0
  27. package/src/machine/activity/return_bonus_activity.js +3 -1
  28. package/src/machine/activity/roulette_activity_v2.js +6 -0
  29. package/src/machine/activity/sign_in_activity.js +1 -0
  30. package/src/machine/activity/sign_in_monthly_activity.js +2 -1
  31. package/src/machine/activity/specify_bets_activity.js +1 -0
  32. package/src/machine/activity/specify_turnover_activity.js +1 -0
  33. package/src/machine/activity/time_bomb_activity.js +1 -0
  34. package/src/machine/activity/vip_card_activity.js +1 -0
  35. package/src/machine/auth.js +21 -8
  36. package/src/machine/auth_otp_v2.js +1 -0
  37. package/src/machine/auth_otp_v3.js +48 -11
  38. package/src/machine/bank_binding.js +1 -0
  39. package/src/machine/bank_binding_amb.js +1 -0
  40. package/src/machine/bonus.js +1 -0
  41. package/src/machine/common.js +41 -7
  42. package/src/machine/deposit/amb.js +1 -0
  43. package/src/machine/deposit/crypto_bank.js +20 -5
  44. package/src/machine/deposit/crypto_bank_cash.js +35 -9
  45. package/src/machine/deposit/crypto_qrcode.js +11 -1
  46. package/src/machine/deposit/crypto_qrcode_cash.js +24 -1
  47. package/src/machine/deposit/crypto_way.js +11 -5
  48. package/src/machine/deposit/crypto_way_cash.js +15 -6
  49. package/src/machine/deposit/deposit_fc.js +1 -0
  50. package/src/machine/deposit/direct.js +1 -0
  51. package/src/machine/deposit/direct_cash.js +1 -0
  52. package/src/machine/deposit/float.js +1 -0
  53. package/src/machine/deposit/krway.js +1 -0
  54. package/src/machine/deposit/loadcard_cash.js +2 -1
  55. package/src/machine/deposit/loadcard_vn.js +1 -0
  56. package/src/machine/deposit/manual_cash.js +18 -10
  57. package/src/machine/deposit/manual_vn.js +10 -5
  58. package/src/machine/deposit/qrcode_cash.js +6 -5
  59. package/src/machine/deposit/qrcode_v2.js +1 -0
  60. package/src/machine/deposit/usdt.js +23 -4
  61. package/src/machine/deposit/usdt_cash.js +15 -1
  62. package/src/machine/deposit/virtual_bank_cash.js +11 -9
  63. package/src/machine/deposit/virtual_bank_vn.js +1 -0
  64. package/src/machine/deposit/vpay.js +7 -0
  65. package/src/machine/error.js +1 -0
  66. package/src/machine/game_betslip.js +1 -0
  67. package/src/machine/game_favorite_v2.js +1 -0
  68. package/src/machine/game_hot_new.js +14 -2
  69. package/src/machine/game_info.js +5 -0
  70. package/src/machine/game_replay.js +1 -0
  71. package/src/machine/game_search_cash.js +13 -2
  72. package/src/machine/game_search_v2.js +1 -0
  73. package/src/machine/game_v2_1.js +129 -50
  74. package/src/machine/honor_board.js +19 -7
  75. package/src/machine/honor_board_cash.js +11 -8
  76. package/src/machine/inbox.js +93 -43
  77. package/src/machine/leaderboard.js +1 -0
  78. package/src/machine/merge.js +1 -0
  79. package/src/machine/navbar.js +3 -1
  80. package/src/machine/payment_data.js +1 -0
  81. package/src/machine/promotions.js +11 -18
  82. package/src/machine/ranking.js +5 -2
  83. package/src/machine/reward.js +1 -0
  84. package/src/machine/reward_cash.js +1 -0
  85. package/src/machine/reward_fc.js +1 -0
  86. package/src/machine/roulette_v2.js +18 -26
  87. package/src/machine/setting.js +1 -0
  88. package/src/machine/side.js +10 -4
  89. package/src/machine/side_cash.js +1 -0
  90. package/src/machine/side_v2.js +38 -24
  91. package/src/machine/user_info.js +1 -0
  92. package/src/machine/user_photo.js +1 -0
  93. package/src/machine/user_reset_password.js +5 -2
  94. package/src/machine/user_sign_up.js +1 -0
  95. package/src/machine/vip_table.js +1 -0
  96. package/src/machine/websocket.js +42 -14
  97. package/src/machine/welcome.js +1 -0
  98. package/src/machine/withdraw/withdraw_crypto_cash.js +1 -0
  99. package/src/machine/withdraw/withdraw_krway.js +1 -0
  100. package/src/machine/withdraw/withdraw_manual.js +16 -8
  101. package/src/machine/withdraw/withdraw_manual_cash.js +1 -0
  102. package/src/request/request.js +34 -30
  103. package/src/util/deviceToken.js +7 -6
  104. package/src/util/storage.js +4 -3
  105. package/test/api.behavior.test.js +69 -0
  106. package/test/api.contract.test.js +18 -0
  107. package/test/config.test.js +27 -0
  108. package/test/deviceToken.test.js +139 -0
  109. package/test/helpers.coverage.test.js +11 -0
  110. package/test/helpers.js +91 -0
  111. package/test/index.exports.test.js +14 -0
  112. package/test/machine.activity.core.coverage.test.js +337 -0
  113. package/test/machine.activity.gap.coverage.test.js +252 -0
  114. package/test/machine.activity.more.coverage.test.js +180 -0
  115. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +201 -0
  116. package/test/machine.activity_timer_bonus.coverage.test.js +136 -0
  117. package/test/machine.activity_welcome.low.coverage.test.js +211 -0
  118. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +201 -0
  119. package/test/machine.auth.coverage.test.js +215 -0
  120. package/test/machine.bank_binding.test.js +143 -0
  121. package/test/machine.binding_otp_krway.coverage.test.js +223 -0
  122. package/test/machine.contract.test.js +50 -0
  123. package/test/machine.crypto_bank.coverage.test.js +270 -0
  124. package/test/machine.crypto_way.coverage.test.js +108 -0
  125. package/test/machine.crypto_way_cash.coverage.test.js +114 -0
  126. package/test/machine.definition.test.js +137 -0
  127. package/test/machine.deposit.manual.coverage.test.js +365 -0
  128. package/test/machine.deposit_fc.coverage.test.js +126 -0
  129. package/test/machine.direct.coverage.test.js +96 -0
  130. package/test/machine.direct_cash.coverage.test.js +108 -0
  131. package/test/machine.error.coverage.test.js +37 -0
  132. package/test/machine.events.test.js +126 -0
  133. package/test/machine.favorite_jackpot.coverage.test.js +82 -0
  134. package/test/machine.float.coverage.test.js +136 -0
  135. package/test/machine.flow.test.js +226 -0
  136. package/test/machine.game_hot_new_vip_table.coverage.test.js +105 -0
  137. package/test/machine.game_search_cash.coverage.test.js +195 -0
  138. package/test/machine.game_search_v2.test.js +199 -0
  139. package/test/machine.game_user_profile.coverage.test.js +100 -0
  140. package/test/machine.honor_board.test.js +148 -0
  141. package/test/machine.inbox.common.coverage.test.js +304 -0
  142. package/test/machine.loadcard_cash.coverage.test.js +101 -0
  143. package/test/machine.loadcard_vn.coverage.test.js +122 -0
  144. package/test/machine.misc.coverage.test.js +361 -0
  145. package/test/machine.more2.coverage.test.js +261 -0
  146. package/test/machine.options.execution.test.js +272 -0
  147. package/test/machine.priority.coverage.test.js +629 -0
  148. package/test/machine.qrcode_cash.coverage.test.js +107 -0
  149. package/test/machine.qrcode_v2.coverage.test.js +121 -0
  150. package/test/machine.regression.test.js +82 -0
  151. package/test/machine.roulette_v2.test.js +142 -0
  152. package/test/machine.side_reward_reset.coverage.test.js +220 -0
  153. package/test/machine.targeted.coverage.test.js +313 -0
  154. package/test/machine.usdt.coverage.test.js +95 -0
  155. package/test/machine.usdt_cash.coverage.test.js +73 -0
  156. package/test/machine.vip_card_activity.test.js +114 -0
  157. package/test/machine.virtual_bank_cash.coverage.test.js +105 -0
  158. package/test/machine.virtual_bank_vn.coverage.test.js +105 -0
  159. package/test/machine.vpay.coverage.test.js +142 -0
  160. package/test/machine.withdraw_crypto_cash.coverage.test.js +166 -0
  161. package/test/machine.withdraw_krway.coverage.test.js +123 -0
  162. package/test/machine.withdraw_manual.coverage.test.js +185 -0
  163. package/test/machine.withdraw_manual_cash.coverage.test.js +123 -0
  164. package/test/request.test.js +325 -0
  165. package/test/util.storage.errors.test.js +47 -0
  166. package/test/util.test.js +41 -0
@@ -0,0 +1,108 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import cryptoWayFactory from '../src/machine/deposit/crypto_way.js'
5
+
6
+ test('crypto_way covers actions, guards and services including precise amount add', async () => {
7
+ const sent = []
8
+ const request = {
9
+ config: { appSecret: 'secret' },
10
+ send: async (req) => {
11
+ sent.push(req)
12
+ if (req.url === 'payment/v2/paymentDetail') {
13
+ return [
14
+ {
15
+ category: 'cryptoWay',
16
+ method: 'crypto_way',
17
+ channel: 'USDT',
18
+ cryptoOptional: ['USDT'],
19
+ networkName: ['TRC20'],
20
+ minimum: 50,
21
+ maximum: 500,
22
+ },
23
+ {
24
+ category: 'cryptoWay',
25
+ method: 'crypto_way_eth',
26
+ channel: 'ETH',
27
+ cryptoOptional: ['ETH'],
28
+ networkName: ['ERC20'],
29
+ minimum: 80,
30
+ maximum: 800,
31
+ },
32
+ { category: 'other', method: 'ignored' },
33
+ ]
34
+ }
35
+ if (req.url === 'payment/v2/crypto_way/crypto/expected/result') {
36
+ return { data: { expectedAmount: 777 } }
37
+ }
38
+ if (req.url === 'payment/v2/crypto_way/transaction') {
39
+ return { applyId: 'TX-1' }
40
+ }
41
+ return {}
42
+ },
43
+ }
44
+
45
+ const machine = cryptoWayFactory(request)
46
+ const { actions, guards, services } = machine.options
47
+ const initial = machine.initialState.context
48
+
49
+ const fetched = await services.fetchPayments(initial)
50
+ assert.equal(fetched.length, 3)
51
+
52
+ const setPayment = actions.setPayment.assignment(initial, { data: fetched })
53
+ assert.equal(setPayment.cryptos.length, 2)
54
+ assert.equal(setPayment.selectedCrypto.label, 'USDT')
55
+ assert.equal(setPayment.selectedCrypto.network, 'TRC20')
56
+ assert.equal(setPayment.currentPayment.method, 'crypto_way')
57
+
58
+ const setCrypto = actions.setCrypto.assignment(setPayment, { data: { label: 'ETH' } })
59
+ assert.equal(setCrypto.selectedCrypto.label, 'ETH')
60
+ assert.equal(setCrypto.amount, null)
61
+ assert.equal(setCrypto.calculation, null)
62
+
63
+ const setCryptoNotFound = actions.setCrypto.assignment(setPayment, { data: { label: 'NOPE' } })
64
+ assert.equal(setCryptoNotFound.selectedCrypto, undefined)
65
+
66
+ assert.equal(actions.setAmount.assignment(initial, { data: '123' }).amount, '123')
67
+
68
+ const added = actions.inputAmount.assignment({ amount: '10.1' }, { data: '0.2' })
69
+ assert.equal(added.amount, 10.3)
70
+
71
+ assert.equal(actions.setAddress.assignment(initial, { data: '0xabc' }).sourceAddress, '0xabc')
72
+
73
+ assert.equal(actions.setCalculation.assignment(initial, { data: { data: { a: 1 } } }).calculation.a, 1)
74
+ assert.equal(actions.setCalculation.assignment(initial, { data: { b: 2 } }).calculation.b, 2)
75
+ assert.equal(actions.clearCalculation.assignment({ calculation: { ok: 1 } }, {}).calculation, null)
76
+ assert.equal(actions.setResult.assignment(initial, { data: { applyId: 'TX-2' } }).result.applyId, 'TX-2')
77
+ assert.equal(actions.setPromotion.assignment(initial, { data: { activityNo: 'A-1' } }).promotion.activityNo, 'A-1')
78
+
79
+ assert.equal(guards.isCalculable({ selectedCrypto: { minimum: 50, maximum: 100 }, amount: '60' }), true)
80
+ assert.equal(guards.isCalculable({ selectedCrypto: { minimum: 50, maximum: 100 }, amount: '10' }), false)
81
+ assert.equal(guards.isCalculable({ selectedCrypto: null, amount: '60' }), null)
82
+
83
+ assert.equal(guards.isSubmittable({ selectedCrypto: { method: 'x' }, amount: '1' }), '1')
84
+ assert.equal(guards.isSubmittable({ selectedCrypto: { method: 'x' }, amount: 0 }), 0)
85
+
86
+ const calcResult = await services.fetchCalculation({
87
+ selectedCrypto: { method: 'crypto_way', channel: 'USDT' },
88
+ amount: 456,
89
+ promotion: { activityNo: 'P-1' },
90
+ })
91
+ assert.equal(calcResult.data.expectedAmount, 777)
92
+
93
+ const submitResult = await services.submitDeposit({
94
+ selectedCrypto: { method: 'crypto_way', channel: 'USDT', network: 'TRC20' },
95
+ amount: 321,
96
+ })
97
+ assert.equal(submitResult.applyId, 'TX-1')
98
+
99
+ const calcReq = sent.find((entry) => entry.url === 'payment/v2/crypto_way/crypto/expected/result')
100
+ assert.equal(calcReq.params.amount, 456)
101
+ assert.equal(calcReq.params.cryptoCurrency, 'USDT')
102
+ assert.equal(calcReq.params.promotionsNo, 'P-1')
103
+
104
+ const submitReq = sent.find((entry) => entry.url === 'payment/v2/crypto_way/transaction')
105
+ assert.equal(submitReq.params.amount, 321)
106
+ assert.equal(submitReq.params.cryptoCurrency, 'USDT')
107
+ assert.equal(submitReq.params.cryptoNetwork, 'TRC20')
108
+ })
@@ -0,0 +1,114 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import cryptoWayCashFactory from '../src/machine/deposit/crypto_way_cash.js'
5
+
6
+ test('crypto_way_cash actions/guards/services cover amount, ttl and payload mapping', async () => {
7
+ const sent = []
8
+ const request = {
9
+ send: async (req) => {
10
+ sent.push(req)
11
+ if (req.url === 'payment/v2/crypto_way_cash/crypto/expected/result') return { data: { bonus: 10 } }
12
+ if (req.url === 'payment/v2/crypto_way_cash/transaction') return { applyId: 55, cdtime: 3000 }
13
+ return {}
14
+ },
15
+ }
16
+
17
+ const machine = cryptoWayCashFactory(request, {
18
+ paymentDetail: [
19
+ {
20
+ category: 'cryptoWay',
21
+ method: 'crypto_way_cash',
22
+ channel: 'USDT',
23
+ cryptoOptional: ['USDT'],
24
+ networkName: ['TRC20'],
25
+ optional: [100, 200],
26
+ minimum: 50,
27
+ maximum: 5000,
28
+ grandTotalEnable: 1,
29
+ },
30
+ {
31
+ category: 'cryptoWay',
32
+ method: 'crypto_way_cash_eth',
33
+ channel: 'ETH',
34
+ cryptoOptional: ['ETH'],
35
+ networkName: ['ERC20'],
36
+ optional: [300],
37
+ minimum: 80,
38
+ maximum: 8000,
39
+ grandTotalEnable: 0,
40
+ },
41
+ ],
42
+ promotion: { promotionsNo: 'P1', minimumAmount: 100 },
43
+ selectedAmount: 10,
44
+ })
45
+
46
+ const { actions, guards, services } = machine.options
47
+
48
+ const init = actions.setInitData.assignment(machine.initialState.context, {})
49
+ assert.equal(init.cryptos.length, 2)
50
+ assert.equal(init.selectedCrypto.label, 'USDT')
51
+ assert.equal(init.options.length, 2)
52
+
53
+ const initEmpty = actions.setInitData.assignment({ ...machine.initialState.context, paymentDetail: [] }, {})
54
+ assert.deepEqual(initEmpty.cryptos, [])
55
+ assert.equal(initEmpty.selectedCrypto, undefined)
56
+
57
+ assert.deepEqual(actions.setCrypto.assignment(init, { data: { label: 'NOPE' } }), {})
58
+ const setCrypto = actions.setCrypto.assignment(init, { data: { label: 'ETH' } })
59
+ assert.equal(setCrypto.selectedCrypto.label, 'ETH')
60
+ assert.equal(setCrypto.options[0], 300)
61
+
62
+ const amountPlus = actions.setAmount.assignment({ ...init, selectedAmount: '10.1', selectedCrypto: { grandTotalEnable: 1 } }, { data: '0.2' })
63
+ assert.equal(amountPlus.selectedAmount, 10.3)
64
+
65
+ const amountSet = actions.setAmount.assignment({ ...init, selectedCrypto: { grandTotalEnable: 0 } }, { data: '77' })
66
+ assert.equal(amountSet.selectedAmount, '77')
67
+
68
+ assert.equal(actions.inputAmount.assignment(machine.initialState.context, { data: '88' }).selectedAmount, '88')
69
+ assert.equal(actions.setAddress.assignment(machine.initialState.context, { data: '0xabc' }).sourceAddress, '0xabc')
70
+
71
+ assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { data: { x: 1 } } }).calculation, { x: 1 })
72
+ assert.deepEqual(actions.setCalculation.assignment(machine.initialState.context, { data: { y: 2 } }).calculation, { y: 2 })
73
+ assert.equal(actions.clearCalculation.assignment(machine.initialState.context, {}).calculation, null)
74
+
75
+ assert.equal(actions.setResult.assignment(machine.initialState.context, { data: { applyId: 1 } }).result.applyId, 1)
76
+
77
+ const promo = actions.setPromotion.assignment(
78
+ { selectedCrypto: { minimum: 120 }, selectedAmount: 50 },
79
+ { data: { promotionsNo: 'P2', minimumAmount: 200 } }
80
+ )
81
+ assert.equal(promo.selectedAmount, 200)
82
+ assert.equal(promo.calculation, null)
83
+
84
+ assert.equal(actions.setTtl.assignment(machine.initialState.context, { data: { cdtime: 3000 } }).ttl, 3000)
85
+ assert.equal(actions.decreaseTtl.assignment({ ttl: 3000 }, {}).ttl, 2000)
86
+ assert.equal(actions.decreaseTtl.assignment({ ttl: 500 }, {}).ttl, 0)
87
+
88
+ assert.equal(guards.isCalculable({ selectedCrypto: { minimum: 50, maximum: 100 }, selectedAmount: '80' }), true)
89
+ assert.equal(guards.isCalculable({ selectedCrypto: null, selectedAmount: '80' }), null)
90
+ assert.deepEqual(guards.isSubmittable({ selectedCrypto: { method: 'x' }, selectedAmount: '1', calculation: { ok: 1 } }), { ok: 1 })
91
+ assert.equal(guards.isSubmittable({ selectedCrypto: { method: 'x' }, selectedAmount: '1', calculation: null }), null)
92
+
93
+ const calc = await services.fetchCalculation(
94
+ { selectedCrypto: { method: 'crypto_way_cash', channel: 'USDT' }, selectedAmount: 123, promotion: { promotionsNo: 'P3' } },
95
+ {}
96
+ )
97
+ assert.equal(calc.data.bonus, 10)
98
+
99
+ const submitted = await services.submitDeposit(
100
+ {
101
+ selectedCrypto: { method: 'crypto_way_cash', channel: 'USDT', network: 'TRC20' },
102
+ selectedAmount: 456,
103
+ sourceAddress: 'ADDR1',
104
+ promotion: { promotionsNo: 'P4' },
105
+ },
106
+ {}
107
+ )
108
+ assert.equal(submitted.applyId, 55)
109
+
110
+ const submitReq = sent.find((entry) => entry.url === 'payment/v2/crypto_way_cash/transaction')
111
+ assert.equal(submitReq.params.cryptoCurrency, 'USDT')
112
+ assert.equal(submitReq.params.sourceAddress, 'ADDR1')
113
+ assert.equal(submitReq.params.promotionsNo, 'P4')
114
+ })
@@ -0,0 +1,137 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+
4
+ import machine from '../src/machine/index.js'
5
+
6
+ function getRefName(value) {
7
+ if (typeof value === 'string') {
8
+ return value
9
+ }
10
+ if (value && typeof value === 'object' && typeof value.type === 'string') {
11
+ return value.type
12
+ }
13
+ return null
14
+ }
15
+
16
+ function addActionRefs(targetSet, value) {
17
+ if (!value) return
18
+ if (Array.isArray(value)) {
19
+ for (const item of value) {
20
+ addActionRefs(targetSet, item)
21
+ }
22
+ return
23
+ }
24
+ const ref = getRefName(value)
25
+ if (ref && !ref.startsWith('xstate.')) {
26
+ targetSet.add(ref)
27
+ }
28
+ }
29
+
30
+ function addGuardRef(targetSet, cond) {
31
+ const ref = getRefName(cond)
32
+ if (ref && !ref.startsWith('xstate.')) {
33
+ targetSet.add(ref)
34
+ }
35
+ }
36
+
37
+ function inspectTransitions(transitionLike, refs) {
38
+ if (!transitionLike) return
39
+ const transitions = Array.isArray(transitionLike) ? transitionLike : [transitionLike]
40
+
41
+ for (const t of transitions) {
42
+ if (!t || typeof t !== 'object') continue
43
+ addActionRefs(refs.actions, t.actions)
44
+ addGuardRef(refs.guards, t.cond)
45
+ }
46
+ }
47
+
48
+ function walkStates(stateNodeConfig, refs) {
49
+ addActionRefs(refs.actions, stateNodeConfig.entry)
50
+ addActionRefs(refs.actions, stateNodeConfig.exit)
51
+
52
+ if (stateNodeConfig.invoke) {
53
+ const invokes = Array.isArray(stateNodeConfig.invoke) ? stateNodeConfig.invoke : [stateNodeConfig.invoke]
54
+ for (const inv of invokes) {
55
+ if (!inv || typeof inv !== 'object') continue
56
+ const srcRef = getRefName(inv.src)
57
+ if (srcRef && !srcRef.startsWith('xstate.')) {
58
+ refs.services.add(srcRef)
59
+ }
60
+ inspectTransitions(inv.onDone, refs)
61
+ inspectTransitions(inv.onError, refs)
62
+ }
63
+ }
64
+
65
+ inspectTransitions(stateNodeConfig.always, refs)
66
+
67
+ if (stateNodeConfig.on && typeof stateNodeConfig.on === 'object') {
68
+ for (const t of Object.values(stateNodeConfig.on)) {
69
+ inspectTransitions(t, refs)
70
+ }
71
+ }
72
+
73
+ if (stateNodeConfig.after && typeof stateNodeConfig.after === 'object') {
74
+ for (const [delayKey, transition] of Object.entries(stateNodeConfig.after)) {
75
+ if (!/^\d+$/.test(delayKey)) {
76
+ refs.delays.add(delayKey)
77
+ }
78
+ inspectTransitions(transition, refs)
79
+ }
80
+ }
81
+
82
+ if (stateNodeConfig.states && typeof stateNodeConfig.states === 'object') {
83
+ for (const child of Object.values(stateNodeConfig.states)) {
84
+ walkStates(child, refs)
85
+ }
86
+ }
87
+ }
88
+
89
+ const requestStub = {
90
+ config: {
91
+ apiURL: 'https://api.example.com',
92
+ apiVersion: 'v1',
93
+ clientId: 'client',
94
+ appSecret: 'secret',
95
+ platform: 'web',
96
+ version: '1.0.0',
97
+ fpToken: 'fp-token',
98
+ sentry: { captureException: () => {}, setTag: () => {} },
99
+ defaultChannel: 'web',
100
+ defaultSubchannel: 'home',
101
+ socketURL: 'wss://socket.example.com',
102
+ bucketName: 'bucket',
103
+ },
104
+ send: async () => ({}),
105
+ }
106
+
107
+ for (const [machineName, machineFactory] of Object.entries(machine)) {
108
+ test(`machine definition refs are resolvable: ${machineName}`, () => {
109
+ const m = machineFactory(requestStub, {})
110
+ const refs = {
111
+ actions: new Set(),
112
+ guards: new Set(),
113
+ services: new Set(),
114
+ delays: new Set(),
115
+ }
116
+
117
+ walkStates(m.config, refs)
118
+ inspectTransitions(m.config.on, refs)
119
+ addActionRefs(refs.actions, m.config.entry)
120
+ addActionRefs(refs.actions, m.config.exit)
121
+
122
+ const definedActions = new Set(Object.keys(m.options.actions || {}))
123
+ const definedGuards = new Set(Object.keys(m.options.guards || {}))
124
+ const definedServices = new Set(Object.keys(m.options.services || {}))
125
+ const definedDelays = new Set(Object.keys(m.options.delays || {}))
126
+
127
+ const missingActions = [...refs.actions].filter((name) => !definedActions.has(name))
128
+ const missingGuards = [...refs.guards].filter((name) => !definedGuards.has(name))
129
+ const missingServices = [...refs.services].filter((name) => !definedServices.has(name))
130
+ const missingDelays = [...refs.delays].filter((name) => !definedDelays.has(name))
131
+
132
+ assert.deepEqual(missingActions, [], `missing actions in ${machineName}: ${missingActions.join(', ')}`)
133
+ assert.deepEqual(missingGuards, [], `missing guards in ${machineName}: ${missingGuards.join(', ')}`)
134
+ assert.deepEqual(missingServices, [], `missing services in ${machineName}: ${missingServices.join(', ')}`)
135
+ assert.deepEqual(missingDelays, [], `missing delays in ${machineName}: ${missingDelays.join(', ')}`)
136
+ })
137
+ }