@jetthai/cuora 1.1.467-dev.1 → 1.1.467

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 (83) hide show
  1. package/.claude/commands/sync-ai-prompts.md +1 -88
  2. package/.claude/settings.local.json +1 -3
  3. package/.github/copilot-instructions.md +57 -64
  4. package/.husky/post-checkout +3 -3
  5. package/.husky/pre-push +1 -1
  6. package/.prettierignore +1 -2
  7. package/AGENTS.md +57 -64
  8. package/AI_PROMPT_SOURCE.md +57 -64
  9. package/CHANGELOG.md +0 -141
  10. package/CLAUDE.md +57 -64
  11. package/GEMINI.md +57 -64
  12. package/README.md +12 -11
  13. package/package.json +1 -1
  14. package/scripts/auto-version.js +0 -1
  15. package/scripts/branch-auto-npm-publish.js +2 -9
  16. package/src/api/account.js +1 -0
  17. package/src/api/activity.js +37 -0
  18. package/src/api/auth.js +31 -0
  19. package/src/api/game.js +10 -0
  20. package/src/api/payment.js +52 -1
  21. package/src/api/user.js +28 -0
  22. package/src/index.js +2 -2
  23. package/src/machine/activity/activity.js +209 -0
  24. package/src/machine/activity/activity_cash.js +15 -23
  25. package/src/machine/activity/diamond_shop_activity_cash.js +1 -0
  26. package/src/machine/activity/diamond_shop_activity_fc.js +196 -0
  27. package/src/machine/activity/diamond_shop_activity_vn.js +178 -0
  28. package/src/machine/activity/fafafa_activity.js +10 -0
  29. package/src/machine/activity/index.js +12 -0
  30. package/src/machine/activity/invite_friends_activity.js +114 -0
  31. package/src/machine/activity/mini_game_activity.js +68 -0
  32. package/src/machine/activity/return_bonus_activity.js +153 -0
  33. package/src/machine/auth.js +60 -21
  34. package/src/machine/auth_otp_v2.js +177 -0
  35. package/src/machine/auth_otp_v3.js +3 -0
  36. package/src/machine/bank_binding_amb.js +146 -0
  37. package/src/machine/bonus.js +76 -0
  38. package/src/machine/common.js +55 -0
  39. package/src/machine/deposit/amb.js +93 -0
  40. package/src/machine/deposit/crypto_bank.js +330 -0
  41. package/src/machine/deposit/crypto_qrcode.js +148 -0
  42. package/src/machine/deposit/crypto_way.js +252 -0
  43. package/src/machine/deposit/deposit_fc.js +272 -0
  44. package/src/machine/deposit/direct.js +310 -0
  45. package/src/machine/deposit/float.js +375 -0
  46. package/src/machine/deposit/index.js +28 -0
  47. package/src/machine/deposit/krway.js +151 -0
  48. package/src/machine/deposit/loadcard_vn.js +351 -0
  49. package/src/machine/deposit/manual_cash.js +8 -0
  50. package/src/machine/deposit/manual_vn.js +458 -0
  51. package/src/machine/deposit/qrcode_v2.js +338 -0
  52. package/src/machine/deposit/usdt.js +144 -0
  53. package/src/machine/deposit/virtual_bank_vn.js +269 -0
  54. package/src/machine/deposit/vpay.js +368 -0
  55. package/src/machine/game_hot_new.js +79 -0
  56. package/src/machine/game_info.js +12 -1
  57. package/src/machine/game_replay.js +46 -0
  58. package/src/machine/game_search_v2.js +401 -0
  59. package/src/machine/game_v2_1.js +89 -1
  60. package/src/machine/honor_board.js +132 -0
  61. package/src/machine/inbox.js +12 -0
  62. package/src/machine/index.js +32 -0
  63. package/src/machine/merge.js +57 -0
  64. package/src/machine/payment_data.js +86 -0
  65. package/src/machine/promotions.js +170 -0
  66. package/src/machine/reward.js +255 -0
  67. package/src/machine/reward_cash.js +39 -0
  68. package/src/machine/reward_fc.js +98 -0
  69. package/src/machine/side.js +154 -0
  70. package/src/machine/side_v2.js +211 -0
  71. package/src/machine/user_reset_password.js +13 -0
  72. package/src/machine/user_sign_up.js +0 -3
  73. package/src/machine/vip_table.js +57 -0
  74. package/src/machine/websocket.js +4 -0
  75. package/src/machine/welcome.js +110 -0
  76. package/src/machine/withdraw/index.js +6 -0
  77. package/src/machine/withdraw/withdraw_crypto_cash.js +327 -0
  78. package/src/machine/withdraw/withdraw_krway.js +223 -0
  79. package/src/machine/withdraw/withdraw_manual.js +536 -0
  80. package/src/request/request.js +28 -0
  81. package/src/util/constant.js +1 -0
  82. package/src/util/index.js +4 -1
  83. package/src/util/math.js +4 -0
@@ -1,15 +1,21 @@
1
+ import activity from './activity.js'
1
2
  import activity_cash from './activity_cash.js'
2
3
  import continue_deposit_activity from './continue_deposit_activity.js'
3
4
  import deposit_activity from './deposit_activity.js'
5
+ import diamond_shop_activity_fc from './diamond_shop_activity_fc.js'
6
+ import diamond_shop_activity_vn from './diamond_shop_activity_vn.js'
4
7
  import diamond_shop_activity_cash from './diamond_shop_activity_cash.js'
5
8
  import fafafa_activity from './fafafa_activity.js'
9
+ import invite_friends_activity from './invite_friends_activity.js'
6
10
  import jackpot from './jackpot.js'
7
11
  import friend_invite_friends_activity from './friend_invite_friends_activity.js'
8
12
  import ranking_activity from './ranking_activity.js'
13
+ import return_bonus_activity from './return_bonus_activity.js'
9
14
  import specify_bets_activity from './specify_bets_activity.js'
10
15
  import specify_turnover_activity from './specify_turnover_activity.js'
11
16
  import sign_in_activity from './sign_in_activity.js'
12
17
  import time_bomb_activity from './time_bomb_activity.js'
18
+ import mini_game_activity from './mini_game_activity.js'
13
19
  import roulette_activity_v2 from './roulette_activity_v2.js'
14
20
  import sign_in_monthly_activity from './sign_in_monthly_activity.js'
15
21
  import otp_verified_activity from './otp_verified_activity.js'
@@ -18,18 +24,24 @@ import instant_rebate_activity from './instant_rebate_activity.js'
18
24
  import cash_rain_activity from './cash_rain_activity.js'
19
25
 
20
26
  export default {
27
+ activity,
21
28
  activity_cash,
22
29
  continue_deposit_activity,
23
30
  deposit_activity,
31
+ diamond_shop_activity_fc,
32
+ diamond_shop_activity_vn,
24
33
  diamond_shop_activity_cash,
25
34
  fafafa_activity,
35
+ invite_friends_activity,
26
36
  jackpot,
27
37
  friend_invite_friends_activity,
28
38
  ranking_activity,
39
+ return_bonus_activity,
29
40
  specify_bets_activity,
30
41
  specify_turnover_activity,
31
42
  sign_in_activity,
32
43
  time_bomb_activity,
44
+ mini_game_activity,
33
45
  roulette_activity_v2,
34
46
  sign_in_monthly_activity,
35
47
  otp_verified_activity,
@@ -0,0 +1,114 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import user from '../../api/user.js'
3
+ import api from '../../api/activity.js'
4
+
5
+ export default function (request) {
6
+ const { appSecret } = request.config
7
+ return createMachine(
8
+ {
9
+ id: 'invite_friends_activity',
10
+ context: {
11
+ activityNo: null,
12
+ bindingCode: null,
13
+ uidSite: null,
14
+ receiveNo: null,
15
+ friendCode: null,
16
+ downlineCount: 0,
17
+ },
18
+ initial: 'idle',
19
+ states: {
20
+ idle: {
21
+ on: {
22
+ FETCH_FRIEND_CODE: {
23
+ target: 'fetching',
24
+ },
25
+ BIND_FRIEND_CODE: {
26
+ target: 'binding',
27
+ actions: ['setActivityNo', 'setBindingCode', 'setUidSite'],
28
+ },
29
+ },
30
+ },
31
+ fetching: {
32
+ invoke: {
33
+ src: 'fetchFriends',
34
+ onDone: {
35
+ target: 'idle',
36
+ actions: 'setFriendCode',
37
+ },
38
+ onError: {
39
+ target: 'idle',
40
+ },
41
+ },
42
+ },
43
+ binding: {
44
+ invoke: {
45
+ src: 'postFriends',
46
+ onDone: {
47
+ target: 'awarding',
48
+ },
49
+ onError: {
50
+ target: 'idle',
51
+ },
52
+ },
53
+ },
54
+ awarding: {
55
+ invoke: {
56
+ src: 'awardPrize',
57
+ onDone: {
58
+ target: 'bound',
59
+ },
60
+ onError: {
61
+ target: 'idle',
62
+ },
63
+ },
64
+ },
65
+ bound: {
66
+ after: {
67
+ 0: {
68
+ target: 'idle',
69
+ },
70
+ },
71
+ },
72
+ },
73
+ },
74
+ {
75
+ actions: {
76
+ setFriendCode: assign((context, event) => {
77
+ const { friendCode, downlineCount } = event.data
78
+ return {
79
+ friendCode,
80
+ downlineCount,
81
+ }
82
+ }),
83
+ setBindingCode: assign((context, event) => {
84
+ return {
85
+ bindingCode: event.data.bindingCode,
86
+ }
87
+ }),
88
+ setActivityNo: assign((context, event) => {
89
+ return {
90
+ activityNo: event.data.activityNo,
91
+ }
92
+ }),
93
+ setUidSite: assign((context, event) => {
94
+ return {
95
+ uidSite: event.data.uidSite,
96
+ }
97
+ }),
98
+ },
99
+ services: {
100
+ postFriends: async (context, event) => {
101
+ return await request.send(user.postFriends({ friendCode: context.bindingCode }))
102
+ },
103
+ fetchFriends: async (context, event) => {
104
+ return await request.send(user.getFriends())
105
+ },
106
+ awardPrize: async (context, event) => {
107
+ const { activityNo, uidSite, bindingCode } = context
108
+ const { data } = await request.send(api.sentAward({ activityNo, uidSite, affiliateCode: bindingCode, appSecret }))
109
+ return data
110
+ },
111
+ },
112
+ }
113
+ )
114
+ }
@@ -0,0 +1,68 @@
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: 'mini_game_activity',
9
+ context: {
10
+ activityNo: null,
11
+ activityDetail: null,
12
+ },
13
+ initial: 'idle',
14
+ states: {
15
+ idle: {
16
+ on: {
17
+ SET_ACTIVITY_NO: {
18
+ target: 'loading',
19
+ actions: 'setActivityNo',
20
+ },
21
+ },
22
+ },
23
+ loading: {
24
+ invoke: {
25
+ src: 'fetchActivityDetail',
26
+ onDone: {
27
+ target: 'loaded',
28
+ actions: 'setActivityDetail',
29
+ },
30
+ onError: {
31
+ target: 'idle',
32
+ },
33
+ },
34
+ },
35
+ loaded: {},
36
+ },
37
+ },
38
+ {
39
+ actions: {
40
+ setActivityNo: assign((context, event) => {
41
+ return {
42
+ activityNo: event.data,
43
+ }
44
+ }),
45
+ setDiamondShopActivities: assign((context, event) => {
46
+ const rankActivities = event.data.filter((item) => item.activityType === 92)
47
+ return {
48
+ rankActivities,
49
+ activityNo: rankActivities?.[0]?.activityNo,
50
+ }
51
+ }),
52
+ setActivityDetail: assign((context, event) => {
53
+ return {
54
+ activityDetail: event.data,
55
+ }
56
+ }),
57
+ },
58
+ guards: {},
59
+ services: {
60
+ fetchActivityDetail: async (context, event) => {
61
+ const { activityNo } = context
62
+ const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
63
+ return data
64
+ },
65
+ },
66
+ }
67
+ )
68
+ }
@@ -0,0 +1,153 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import api from '../../api/activity.js'
3
+ import isEqual from 'lodash/isEqual.js'
4
+
5
+ // const isEqual = require('lodash/isEqual')
6
+
7
+ export default function (request) {
8
+ const { appSecret } = request.config
9
+ return createMachine(
10
+ {
11
+ id: 'return_bonus_activity',
12
+ context: {
13
+ activityNo: null,
14
+ activityDetail: null,
15
+ rewardList: [],
16
+ callback: () => {},
17
+ },
18
+ initial: 'idle',
19
+ states: {
20
+ idle: {
21
+ always: [{ target: 'loading', cond: 'hasActivityNo' }],
22
+ on: {
23
+ SET_REWARD_LIST: {
24
+ actions: 'setRewardList',
25
+ },
26
+ },
27
+ },
28
+ loading: {
29
+ invoke: {
30
+ src: 'fetchActivityDetail',
31
+ onDone: {
32
+ target: 'loaded',
33
+ actions: 'setActivityDetail',
34
+ },
35
+ onError: {
36
+ target: 'idle',
37
+ },
38
+ },
39
+ on: {
40
+ SET_REWARD_LIST: {
41
+ actions: 'setRewardList',
42
+ },
43
+ },
44
+ },
45
+ loaded: {
46
+ always: [{ target: 'receivable', cond: 'isReceivable' }, { target: 'notReceivableYet', cond: 'isNotReceivableYet' }, { target: 'empty' }],
47
+ },
48
+ receivable: {
49
+ on: {
50
+ RECEIVE_REWARD: {
51
+ target: 'receiving',
52
+ actions: 'setCallback',
53
+ },
54
+ },
55
+ },
56
+ notReceivableYet: {
57
+ after: {
58
+ 20000: {
59
+ target: 'loading',
60
+ },
61
+ },
62
+ },
63
+ empty: {
64
+ after: {
65
+ 20000: {
66
+ target: 'loading',
67
+ },
68
+ },
69
+ },
70
+ receiving: {
71
+ invoke: {
72
+ src: 'receiveReward',
73
+ onDone: {
74
+ target: 'loading',
75
+ actions: 'doCallback',
76
+ },
77
+ onError: {
78
+ target: 'loading',
79
+ },
80
+ },
81
+ },
82
+ },
83
+ on: {
84
+ SET_ACTIVITY_NO: {
85
+ target: '.idle',
86
+ actions: 'setActivityNo',
87
+ cond: 'isActivityChanged',
88
+ },
89
+ SET_REWARD_LIST: {
90
+ target: '.loaded',
91
+ actions: 'setRewardList',
92
+ },
93
+ },
94
+ },
95
+ {
96
+ actions: {
97
+ setActivityNo: assign((context, event) => {
98
+ return {
99
+ activityNo: event.data,
100
+ }
101
+ }),
102
+ setActivityDetail: assign((context, event) => {
103
+ return {
104
+ activityDetail: event.data,
105
+ }
106
+ }),
107
+ setRewardList: assign((context, event) => {
108
+ const rewardList = event.data.filter((item) => item.activityType === 4 && item.receiveStatus === 0)
109
+ return { rewardList }
110
+ }),
111
+ setCallback: assign((context, event) => {
112
+ return {
113
+ callback: event.data?.callback || (() => {}),
114
+ }
115
+ }),
116
+ doCallback: (context, event) => {
117
+ context.callback()
118
+ },
119
+ },
120
+ guards: {
121
+ isActivityChanged: (context, event) => {
122
+ return !isEqual(context.activityNo, event.data)
123
+ },
124
+ hasActivityNo: (context, event) => {
125
+ return context.activityNo
126
+ },
127
+ isReceivable: (context, event) => {
128
+ return context.rewardList?.length > 0
129
+ },
130
+ isNotReceivableYet: (context, event) => {
131
+ return !context.rewardList?.length && context.activityDetail?.rebateAmount > 0
132
+ },
133
+ },
134
+ services: {
135
+ fetchActivityDetail: async (context, event) => {
136
+ const { activityNo } = context
137
+ const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
138
+ return data
139
+ },
140
+ receiveReward: async (context, event) => {
141
+ const { activityNo, receiveNo } = context.rewardList[0]
142
+ const validateReceiveNo = Number(receiveNo) > 0 ? Number(receiveNo) : undefined
143
+ const { data } = await request.send(api.getReward({ activityNo, receiveNo: validateReceiveNo, appSecret }))
144
+ return data
145
+ },
146
+ fetchRewardList: async (context, event) => {
147
+ const { data } = await request.send(api.getRewardList({ appSecret, count: 30 }))
148
+ return data
149
+ },
150
+ },
151
+ }
152
+ )
153
+ }
@@ -10,17 +10,11 @@ import { readParamFromLocation, writeParam, normalize, AC_KEYS, FC_KEYS } from '
10
10
  export default function (request) {
11
11
  const { appSecret, clientId, sentry } = request.config
12
12
  const tokenKey = `cuora_${clientId}`
13
+ const userKey = `cuora_tempuser`
13
14
  const phoneCountryCode = 'phone_countrycode'
14
15
  const accountPhoneKey = 'account_phone'
15
16
  const accountEmailKey = 'account_email'
16
17
  const accountUsernameKey = 'account_username'
17
- // loginMethods 的鍵 → setAccount 寫入的 storage key。
18
- // LOGIN_ID 與 LOGIN_LOCAL 都寫 accountUsernameKey,兩者在 loginMethods 都算 'local',此對照無法由 key 名反推。
19
- const rememberedAccountKeys = [
20
- ['local', accountUsernameKey],
21
- ['phone', accountPhoneKey],
22
- ['email', accountEmailKey],
23
- ]
24
18
 
25
19
  return createMachine(
26
20
  {
@@ -53,7 +47,7 @@ export default function (request) {
53
47
  src: 'fetchSiteConfig',
54
48
  onDone: {
55
49
  target: 'idle',
56
- actions: ['setSiteConfig', 'pruneRememberedAccounts'],
50
+ actions: 'setSiteConfig',
57
51
  },
58
52
  onError: {
59
53
  target: 'idle',
@@ -77,6 +71,32 @@ export default function (request) {
77
71
  },
78
72
  },
79
73
  },
74
+ authenticationGuest: {
75
+ invoke: {
76
+ src: 'authenticateGuest',
77
+ onDone: {
78
+ target: 'authenticated',
79
+ actions: 'setToken',
80
+ },
81
+ onError: {
82
+ target: 'idle',
83
+ actions: 'removeToken',
84
+ },
85
+ },
86
+ },
87
+ authenticationApp: {
88
+ invoke: {
89
+ src: 'authenticateApp',
90
+ onDone: {
91
+ target: 'authenticated',
92
+ actions: ['setToken'],
93
+ },
94
+ onError: {
95
+ target: 'idle',
96
+ actions: 'removeToken',
97
+ },
98
+ },
99
+ },
80
100
  authenticated: {
81
101
  invoke: {
82
102
  src: 'fetchUserInfo',
@@ -262,6 +282,9 @@ export default function (request) {
262
282
  CLEAR: {
263
283
  target: '.logout',
264
284
  },
285
+ LOGIN_GUEST: {
286
+ target: '.authenticationGuest',
287
+ },
265
288
  LOGIN_ID: {
266
289
  target: '.authentication',
267
290
  actions: ['setReCaptchaToken', 'setLoginId'],
@@ -274,9 +297,16 @@ export default function (request) {
274
297
  target: '.authentication',
275
298
  actions: ['setReCaptchaToken', 'setLoginEmail'],
276
299
  },
300
+ LOGIN_LOCAL: {
301
+ target: '.authentication',
302
+ actions: 'setLoginLocal',
303
+ },
277
304
  LOGIN_3PARTY: {
278
305
  actions: 'redirectTo3Party',
279
306
  },
307
+ LOGIN_APP: {
308
+ target: '.authenticationApp',
309
+ },
280
310
  LOGIN_TELEGRAM: {
281
311
  target: '.authentication',
282
312
  actions: 'setLoginTelegram',
@@ -311,19 +341,6 @@ export default function (request) {
311
341
  siteConfig: { ...event.data, loginMethods: pickBy(loginMethods), registerMethods: pickBy(registerMethods) },
312
342
  }
313
343
  }),
314
- // setAccount 寫入的帳號 TTL 是 31 天,且只互斥清除另外兩支 key,
315
- // 後台關掉某種登入方式後殘值仍在,下游會把它回填進已改型別的輸入框(例如把 email 填進 phone-only 站台)。
316
- // 非 assign action,故取得的是 setSiteConfig 套用後的 context。
317
- pruneRememberedAccounts: (context) => {
318
- // fetchSiteConfig 失敗會走 onError 不進到這裡;此處防的是回傳成功但 loginMethods 整包缺失,避免誤清全部記住的帳號。
319
- const enabledMethods = context.siteConfig?.loginMethods
320
- if (!enabledMethods || !Object.keys(enabledMethods).length) return
321
- rememberedAccountKeys.forEach(([method, key]) => {
322
- if (enabledMethods[method]) return
323
- storage.remove(key)
324
- if (method === 'phone') storage.remove(phoneCountryCode)
325
- })
326
- },
327
344
  setReCaptchaToken: assign((context, event) => {
328
345
  const { reCaptchaToken } = event.data
329
346
  return {
@@ -362,6 +379,20 @@ export default function (request) {
362
379
  },
363
380
  }
364
381
  }),
382
+ setLoginLocal: assign((context, event) => {
383
+ const { username, password } = event.data
384
+ storage.set(userKey, username, {
385
+ path: '/',
386
+ maxAge: 60 * 60 * 24,
387
+ })
388
+ return {
389
+ loginData: {
390
+ provider: 'local',
391
+ username,
392
+ password,
393
+ },
394
+ }
395
+ }),
365
396
  setLoginTelegram: assign((context, event) => {
366
397
  const { loginType, additionalUserInfo, isSignature, idToken } = event.data
367
398
  return {
@@ -508,11 +539,19 @@ export default function (request) {
508
539
  }),
509
540
  },
510
541
  services: {
542
+ authenticateApp: async (context, event) => {
543
+ const { token } = await request.send(auth.loginApp(event.data))
544
+ return token
545
+ },
511
546
  authenticate: async (context, event) => {
512
547
  const data = { ...context.loginData, reCaptchaToken: context.reCaptchaToken }
513
548
  const { token } = await request.send(auth.login(data))
514
549
  return token
515
550
  },
551
+ authenticateGuest: async (context, event) => {
552
+ const { token } = await request.send(auth.guestLogin())
553
+ return token
554
+ },
516
555
  logout: async (context, event) => {
517
556
  return await request.send(auth.logout())
518
557
  },
@@ -0,0 +1,177 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import user from '../api/user.js'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'auth_otp_v2',
8
+ initial: 'idle',
9
+ context: {
10
+ strategy: null,
11
+ requestId: null,
12
+ ttl: null,
13
+ target: {},
14
+ acknowledgeTtl: null,
15
+ newPassword: null,
16
+ },
17
+ states: {
18
+ idle: {
19
+ on: {
20
+ SET_OTP_INITIALIZATION: {
21
+ target: 'otp',
22
+ actions: 'setOtpResult',
23
+ },
24
+ SEND_OTP_EMAIL: {
25
+ target: 'otpFetching',
26
+ actions: 'setStrategyEmail',
27
+ },
28
+ SEND_OTP_PHONE: {
29
+ target: 'otpFetching',
30
+ actions: 'setStrategyPhone',
31
+ },
32
+ },
33
+ },
34
+ otpFetching: {
35
+ invoke: {
36
+ src: 'sendOtp',
37
+ onDone: [
38
+ {
39
+ target: 'acknowledged',
40
+ cond: (context, event) => event.data.status === 'success-verified',
41
+ },
42
+ {
43
+ target: 'otp',
44
+ actions: 'setOtpResult',
45
+ },
46
+ ],
47
+ onError: {
48
+ target: 'idle',
49
+ },
50
+ },
51
+ },
52
+ otp: {
53
+ after: {
54
+ 1000: [
55
+ {
56
+ target: 'otp',
57
+ actions: 'decreaseTtl',
58
+ cond: (context) => context.ttl > 0,
59
+ },
60
+ {
61
+ target: 'idle',
62
+ },
63
+ ],
64
+ },
65
+ on: {
66
+ ACKNOWLEDGE: {
67
+ target: 'acknowledging',
68
+ },
69
+ BACK: {
70
+ target: 'idle',
71
+ },
72
+ RESET_OTP: {
73
+ target: 'otpResetting',
74
+ },
75
+ },
76
+ },
77
+ otpResetting: {
78
+ invoke: {
79
+ src: 'resetOtp',
80
+ onDone: {
81
+ target: 'otp',
82
+ actions: 'setOtpResult',
83
+ },
84
+ onError: {
85
+ target: 'otp',
86
+ },
87
+ },
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
+ },
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
+ // },
120
+ },
121
+ },
122
+ },
123
+ {
124
+ actions: {
125
+ setStrategyPhone: assign((context, event) => {
126
+ return {
127
+ strategy: 'phone',
128
+ }
129
+ }),
130
+ setStrategyEmail: assign((context, event) => {
131
+ return {
132
+ strategy: 'email',
133
+ }
134
+ }),
135
+ setOtpResult: assign((context, event) => {
136
+ const { requestId, ttl, target } = event.data
137
+ return {
138
+ requestId,
139
+ ttl,
140
+ target,
141
+ }
142
+ }),
143
+ decreaseTtl: assign((context, event) => {
144
+ return {
145
+ ttl: Math.max(context.ttl - 1, 0),
146
+ }
147
+ }),
148
+ setAcknowledgeResult: assign((context, event) => {
149
+ const { requestId, ttl, target } = event.data
150
+ return {
151
+ acknowledgeTtl: ttl,
152
+ }
153
+ }),
154
+ decreaseAcknowledgeTtl: assign((context, event) => {
155
+ return {
156
+ acknowledgeTtl: Math.max(context.acknowledgeTtl - 1, 0),
157
+ }
158
+ }),
159
+ },
160
+ services: {
161
+ sendOtp: async (context, event) => {
162
+ const { strategy } = context
163
+ return await request.send(user.verifyV2Initiate({ strategy }))
164
+ },
165
+ resetOtp: async (context, event) => {
166
+ const { requestId, target } = context
167
+ return await request.send(user.otpReset({ requestId, target }))
168
+ },
169
+ acknowledge: async (context, event) => {
170
+ const { requestId, target } = context
171
+ const code = event.data
172
+ return await request.send(user.otpAcknowledge({ requestId, target, code }))
173
+ },
174
+ },
175
+ }
176
+ )
177
+ }