@jetthai/cuora 2.0.0-beta.0 → 2.0.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.
- package/.claude/commands/sync-ai-prompts.md +93 -0
- package/.claude/settings.local.json +23 -0
- package/.github/copilot-instructions.md +405 -0
- package/.husky/post-checkout +32 -0
- package/.husky/pre-commit +1 -3
- package/.husky/pre-push +36 -0
- package/AGENTS.md +405 -0
- package/AI_PROMPT_SOURCE.md +403 -0
- package/CHANGELOG.md +274 -3
- package/CLAUDE.md +405 -0
- package/GEMINI.md +405 -0
- package/README.md +299 -15
- package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +1003 -0
- package/docs/kibana/play-providerId-error.md +202 -0
- package/docs/kibana/play-selectedWalletType.md +1 -0
- package/docs/kibana/play-selectedWalletType_2.md +1 -0
- package/docs/kibana/play-selectedWalletType_analysis.md +565 -0
- package/package.json +3 -3
- package/scripts/auto-version.js +68 -0
- package/scripts/auto-version.sh +33 -0
- package/scripts/branch-auto-npm-publish.js +29 -0
- package/scripts/check-version.sh +36 -0
- package/scripts/clean-tags.sh +84 -0
- package/src/api/account.js +0 -1
- package/src/api/activity.js +22 -37
- package/src/api/auth.js +5 -36
- package/src/api/common.js +5 -3
- package/src/api/game.js +0 -10
- package/src/api/payment.js +17 -55
- package/src/api/user.js +10 -16
- package/src/index.js +2 -2
- package/src/machine/activity/activity_cash.js +84 -36
- package/src/machine/activity/cash_rain_activity.js +0 -1
- package/src/machine/activity/continue_deposit_activity.js +0 -1
- package/src/machine/activity/deposit_activity.js +0 -1
- package/src/machine/activity/diamond_shop_activity_cash.js +0 -8
- package/src/machine/activity/fafafa_activity.js +0 -11
- package/src/machine/activity/friend_invite_friends_activity.js +8 -7
- package/src/machine/activity/index.js +0 -12
- package/src/machine/activity/instant_rebate_activity.js +0 -1
- package/src/machine/activity/jackpot.js +0 -1
- package/src/machine/activity/otp_verified_activity.js +0 -1
- package/src/machine/activity/ranking_activity.js +0 -1
- package/src/machine/activity/roulette_activity_v2.js +0 -1
- package/src/machine/activity/sign_in_activity.js +0 -1
- package/src/machine/activity/sign_in_monthly_activity.js +1 -2
- package/src/machine/activity/specify_bets_activity.js +0 -1
- package/src/machine/activity/specify_turnover_activity.js +0 -1
- package/src/machine/activity/time_bomb_activity.js +0 -1
- package/src/machine/activity/vip_card_activity.js +0 -1
- package/src/machine/auth.js +112 -112
- package/src/machine/auth_otp_v3.js +11 -8
- package/src/machine/bank_binding.js +2 -3
- package/src/machine/common.js +14 -98
- package/src/machine/deposit/crypto_bank_cash.js +20 -35
- package/src/machine/deposit/crypto_qrcode_cash.js +26 -64
- package/src/machine/deposit/crypto_way_cash.js +48 -37
- package/src/machine/deposit/direct_cash.js +8 -10
- package/src/machine/deposit/index.js +0 -28
- package/src/machine/deposit/loadcard_cash.js +14 -32
- package/src/machine/deposit/manual_cash.js +8 -11
- package/src/machine/deposit/qrcode_cash.js +15 -32
- package/src/machine/deposit/usdt_cash.js +1 -15
- package/src/machine/deposit/virtual_bank_cash.js +13 -12
- package/src/machine/error.js +7 -1
- package/src/machine/game_betslip.js +0 -1
- package/src/machine/game_favorite_v2.js +0 -1
- package/src/machine/game_info.js +1 -13
- package/src/machine/game_search_cash.js +0 -1
- package/src/machine/game_v2_1.js +39 -126
- package/src/machine/honor_board_cash.js +8 -11
- package/src/machine/inbox.js +43 -105
- package/src/machine/index.js +0 -32
- package/src/machine/leaderboard.js +8 -12
- package/src/machine/navbar.js +1 -3
- package/src/machine/ranking.js +45 -30
- package/src/machine/reward_cash.js +0 -40
- package/src/machine/roulette_v2.js +14 -11
- package/src/machine/setting.js +0 -1
- package/src/machine/side_cash.js +3 -3
- package/src/machine/user_info.js +0 -1
- package/src/machine/user_photo.js +0 -1
- package/src/machine/user_reset_password.js +0 -14
- package/src/machine/user_sign_up.js +46 -61
- package/src/machine/websocket.js +18 -62
- package/src/machine/withdraw/index.js +0 -6
- package/src/machine/withdraw/withdraw_manual_cash.js +59 -39
- package/src/request/config.js +2 -0
- package/src/request/request.js +49 -60
- package/src/util/amount.js +8 -0
- package/src/util/constant.js +0 -1
- package/src/util/err998SentryExtra.js +26 -0
- package/src/util/index.js +2 -4
- package/src/util/paramStore.js +139 -0
- package/src/util/storage.js +3 -4
- package/BREAKING_CHANGES.md +0 -9
- package/resetGitBranch.sh +0 -101
- package/src/lib/fingerprint_v3_11_12.js +0 -11433
- package/src/machine/activity/activity.js +0 -213
- package/src/machine/activity/diamond_shop_activity_fc.js +0 -197
- package/src/machine/activity/diamond_shop_activity_vn.js +0 -179
- package/src/machine/activity/invite_friends_activity.js +0 -115
- package/src/machine/activity/mini_game_activity.js +0 -69
- package/src/machine/activity/return_bonus_activity.js +0 -155
- package/src/machine/auth_otp_v2.js +0 -178
- package/src/machine/bank_binding_amb.js +0 -146
- package/src/machine/bonus.js +0 -76
- package/src/machine/deposit/amb.js +0 -93
- package/src/machine/deposit/crypto_bank.js +0 -340
- package/src/machine/deposit/crypto_qrcode.js +0 -158
- package/src/machine/deposit/crypto_way.js +0 -253
- package/src/machine/deposit/deposit_fc.js +0 -272
- package/src/machine/deposit/direct.js +0 -311
- package/src/machine/deposit/float.js +0 -375
- package/src/machine/deposit/krway.js +0 -152
- package/src/machine/deposit/loadcard_vn.js +0 -352
- package/src/machine/deposit/manual_vn.js +0 -459
- package/src/machine/deposit/qrcode_v2.js +0 -339
- package/src/machine/deposit/usdt.js +0 -163
- package/src/machine/deposit/virtual_bank_vn.js +0 -270
- package/src/machine/deposit/vpay.js +0 -374
- package/src/machine/game_hot_new.js +0 -80
- package/src/machine/game_replay.js +0 -47
- package/src/machine/game_search_v2.js +0 -402
- package/src/machine/honor_board.js +0 -133
- package/src/machine/merge.js +0 -58
- package/src/machine/payment_data.js +0 -87
- package/src/machine/promotions.js +0 -163
- package/src/machine/reward.js +0 -256
- package/src/machine/reward_fc.js +0 -99
- package/src/machine/side.js +0 -160
- package/src/machine/side_v2.js +0 -223
- package/src/machine/vip_table.js +0 -58
- package/src/machine/welcome.js +0 -111
- package/src/machine/withdraw/withdraw_crypto_cash.js +0 -328
- package/src/machine/withdraw/withdraw_krway.js +0 -223
- package/src/machine/withdraw/withdraw_manual.js +0 -541
- package/src/util/deviceToken.js +0 -60
- package/src/util/math.js +0 -4
- package/test/api.behavior.test.js +0 -69
- package/test/api.contract.test.js +0 -18
- package/test/config.test.js +0 -27
- package/test/deviceToken.test.js +0 -139
- package/test/helpers.coverage.test.js +0 -11
- package/test/helpers.js +0 -91
- package/test/index.exports.test.js +0 -14
- package/test/machine.activity.core.coverage.test.js +0 -337
- package/test/machine.activity.gap.coverage.test.js +0 -252
- package/test/machine.activity.more.coverage.test.js +0 -180
- package/test/machine.activity_plus_and_binding_amb.coverage.test.js +0 -201
- package/test/machine.activity_timer_bonus.coverage.test.js +0 -136
- package/test/machine.activity_welcome.low.coverage.test.js +0 -211
- package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +0 -201
- package/test/machine.auth.coverage.test.js +0 -215
- package/test/machine.bank_binding.test.js +0 -143
- package/test/machine.binding_otp_krway.coverage.test.js +0 -223
- package/test/machine.contract.test.js +0 -50
- package/test/machine.crypto_bank.coverage.test.js +0 -270
- package/test/machine.crypto_way.coverage.test.js +0 -108
- package/test/machine.crypto_way_cash.coverage.test.js +0 -114
- package/test/machine.definition.test.js +0 -137
- package/test/machine.deposit.manual.coverage.test.js +0 -365
- package/test/machine.deposit_fc.coverage.test.js +0 -126
- package/test/machine.direct.coverage.test.js +0 -96
- package/test/machine.direct_cash.coverage.test.js +0 -108
- package/test/machine.error.coverage.test.js +0 -37
- package/test/machine.events.test.js +0 -126
- package/test/machine.favorite_jackpot.coverage.test.js +0 -82
- package/test/machine.float.coverage.test.js +0 -136
- package/test/machine.flow.test.js +0 -226
- package/test/machine.game_hot_new_vip_table.coverage.test.js +0 -105
- package/test/machine.game_search_cash.coverage.test.js +0 -155
- package/test/machine.game_search_v2.test.js +0 -199
- package/test/machine.game_user_profile.coverage.test.js +0 -100
- package/test/machine.honor_board.test.js +0 -133
- package/test/machine.inbox.common.coverage.test.js +0 -304
- package/test/machine.loadcard_cash.coverage.test.js +0 -101
- package/test/machine.loadcard_vn.coverage.test.js +0 -122
- package/test/machine.misc.coverage.test.js +0 -361
- package/test/machine.more2.coverage.test.js +0 -261
- package/test/machine.options.execution.test.js +0 -272
- package/test/machine.priority.coverage.test.js +0 -603
- package/test/machine.qrcode_cash.coverage.test.js +0 -107
- package/test/machine.qrcode_v2.coverage.test.js +0 -121
- package/test/machine.regression.test.js +0 -82
- package/test/machine.roulette_v2.test.js +0 -142
- package/test/machine.side_reward_reset.coverage.test.js +0 -220
- package/test/machine.targeted.coverage.test.js +0 -313
- package/test/machine.usdt.coverage.test.js +0 -95
- package/test/machine.usdt_cash.coverage.test.js +0 -73
- package/test/machine.vip_card_activity.test.js +0 -114
- package/test/machine.virtual_bank_cash.coverage.test.js +0 -105
- package/test/machine.virtual_bank_vn.coverage.test.js +0 -105
- package/test/machine.vpay.coverage.test.js +0 -142
- package/test/machine.withdraw_crypto_cash.coverage.test.js +0 -166
- package/test/machine.withdraw_krway.coverage.test.js +0 -123
- package/test/machine.withdraw_manual.coverage.test.js +0 -185
- package/test/machine.withdraw_manual_cash.coverage.test.js +0 -123
- package/test/request.test.js +0 -325
- package/test/util.storage.errors.test.js +0 -47
- package/test/util.test.js +0 -41
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Sync AI Prompts
|
|
2
|
+
|
|
3
|
+
將 `AI_PROMPT_SOURCE.md` 的內容同步到各 AI 工具的指令檔。
|
|
4
|
+
|
|
5
|
+
⚠️ 只修改 `AI_PROMPT_SOURCE.md` 作為唯一來源,其他檔案皆由此指令自動生成。
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Step 1 — 讀取來源檔
|
|
10
|
+
|
|
11
|
+
讀取 `AI_PROMPT_SOURCE.md` 完整內容。
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Step 2 — 同步 CLAUDE.md
|
|
16
|
+
|
|
17
|
+
將 `AI_PROMPT_SOURCE.md` 的內容**翻譯成英文**,並轉換為 CLAUDE.md 格式:
|
|
18
|
+
|
|
19
|
+
**翻譯規則**:同 Step 3。
|
|
20
|
+
|
|
21
|
+
**格式調整**:
|
|
22
|
+
|
|
23
|
+
- 第一行標題改為 `# CLAUDE.md`
|
|
24
|
+
- 第二行加上 `<!-- AUTO-SYNCED FROM AI_PROMPT_SOURCE.md — DO NOT EDIT DIRECTLY -->`
|
|
25
|
+
- 描述行改為:`This file provides guidance for Claude Code (claude.ai/code) when working in this project.`
|
|
26
|
+
- 其餘結構不變
|
|
27
|
+
|
|
28
|
+
寫入 `CLAUDE.md`。
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Step 3 — 同步 AGENTS.md(OpenAI Codex / Cursor / Windsurf)
|
|
33
|
+
|
|
34
|
+
將 `AI_PROMPT_SOURCE.md` 的內容**翻譯成英文**,並轉換為 AGENTS.md 格式:
|
|
35
|
+
|
|
36
|
+
**翻譯規則**:
|
|
37
|
+
|
|
38
|
+
- 所有繁體中文文字翻譯成英文
|
|
39
|
+
- 程式碼區塊中的**註解**翻譯成英文,**程式碼本身不動**
|
|
40
|
+
- 檔案路徑、變數名、函式名等技術名詞保持不變
|
|
41
|
+
- Markdown 結構(標題層級、列表、表格)保持不變
|
|
42
|
+
|
|
43
|
+
**格式調整**:
|
|
44
|
+
|
|
45
|
+
- 第一行標題改為 `# AGENTS.md`
|
|
46
|
+
- 第二行加上 `<!-- AUTO-SYNCED FROM AI_PROMPT_SOURCE.md — DO NOT EDIT DIRECTLY -->`
|
|
47
|
+
- 描述行改為:`This file provides guidance for AI coding agents when working on this project.`
|
|
48
|
+
- 其餘結構不變
|
|
49
|
+
|
|
50
|
+
寫入 `AGENTS.md`。
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Step 4 — 同步 GEMINI.md(Gemini CLI)
|
|
55
|
+
|
|
56
|
+
將 `AI_PROMPT_SOURCE.md` 的內容**翻譯成英文**,並轉換為 GEMINI.md 格式:
|
|
57
|
+
|
|
58
|
+
**翻譯規則**:同 Step 3。
|
|
59
|
+
|
|
60
|
+
**格式調整**:
|
|
61
|
+
|
|
62
|
+
- 第一行標題改為 `# GEMINI.md`
|
|
63
|
+
- 第二行加上 `<!-- AUTO-SYNCED FROM AI_PROMPT_SOURCE.md — DO NOT EDIT DIRECTLY -->`
|
|
64
|
+
- 描述行改為:`This file provides guidance for Gemini CLI when working on this project.`
|
|
65
|
+
- 其餘結構不變
|
|
66
|
+
|
|
67
|
+
寫入 `GEMINI.md`。
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Step 5 — 同步 .github/copilot-instructions.md(GitHub Copilot)
|
|
72
|
+
|
|
73
|
+
將 `AI_PROMPT_SOURCE.md` 的內容**翻譯成英文**,並轉換為 copilot-instructions.md 格式:
|
|
74
|
+
|
|
75
|
+
**翻譯規則**:同 Step 3。
|
|
76
|
+
|
|
77
|
+
**格式調整**:
|
|
78
|
+
|
|
79
|
+
- 第一行標題改為 `# Copilot Instructions`
|
|
80
|
+
- 第二行加上 `<!-- AUTO-SYNCED FROM AI_PROMPT_SOURCE.md — DO NOT EDIT DIRECTLY -->`
|
|
81
|
+
- 描述行改為:`This file provides guidance for GitHub Copilot when working on this project.`
|
|
82
|
+
- 其餘結構不變
|
|
83
|
+
|
|
84
|
+
寫入 `.github/copilot-instructions.md`。
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Step 6 — 回報結果
|
|
89
|
+
|
|
90
|
+
顯示完成摘要:
|
|
91
|
+
|
|
92
|
+
- 列出已同步的檔案及各自的行數/大小
|
|
93
|
+
- 提醒使用者需要 commit 這些變更
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Read(*)",
|
|
5
|
+
"Bash(*)",
|
|
6
|
+
"WebFetch(domain:docs.qingque.cn)",
|
|
7
|
+
"WebFetch(domain:github.com)",
|
|
8
|
+
"WebFetch(domain:medium.com)",
|
|
9
|
+
"WebFetch(domain:nitro.build)",
|
|
10
|
+
"WebFetch(domain:raw.githubusercontent.com)",
|
|
11
|
+
"WebFetch(domain:unstorage.unjs.io)",
|
|
12
|
+
"WebFetch(domain:www.yungoucms.com)",
|
|
13
|
+
"mcp__chrome-devtools__list_console_messages",
|
|
14
|
+
"mcp__chrome-devtools__list_pages",
|
|
15
|
+
"mcp__sentry__find_organizations",
|
|
16
|
+
"mcp__sentry__find_projects",
|
|
17
|
+
"mcp__sentry__get_issue_details",
|
|
18
|
+
"mcp__sentry__search_issues",
|
|
19
|
+
"Bash(git add:*)",
|
|
20
|
+
"Bash(git commit:*)"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
# Copilot Instructions
|
|
2
|
+
|
|
3
|
+
<!-- AUTO-SYNCED FROM AI_PROMPT_SOURCE.md — DO NOT EDIT DIRECTLY -->
|
|
4
|
+
|
|
5
|
+
This file provides guidance for GitHub Copilot when working on this project.
|
|
6
|
+
|
|
7
|
+
> **What belongs here**: only content that **cannot be derived by reading the code** — design context, counter-intuitive gotchas, implicit cross-layer contracts, style convergence targets, and known technical debt.
|
|
8
|
+
>
|
|
9
|
+
> **What does not belong here**: file inventories, state-machine / API module counts and category tables, util file tables, dependency versions. Run `ls src/machine/`, `ls src/api/`, or read `package.json` instead — **the actual files are the source of truth; this file deliberately does not duplicate those facts** (duplicates only rot).
|
|
10
|
+
>
|
|
11
|
+
> **Companion file**: [README.md](./README.md) covers user-facing content such as the project overview, tech stack, module exports, dependencies, and the Git branch versioning/release workflow.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## AI Collaboration Role Definition
|
|
16
|
+
|
|
17
|
+
When collaborating with this project's team members, please reply, design, and modify code according to the following role, capability standards, collaboration principles, quality checks, and output standards.
|
|
18
|
+
|
|
19
|
+
### Role and Capabilities
|
|
20
|
+
|
|
21
|
+
You are a senior full-stack engineer with world-class capability across UI/UX, API, Backend, Database, Server, Frontend, SEO, Website/Data Security, Webpage Performance, and Quality Assurance Testing. Given a requirement, you can decompose it, design it, and build it — at high quality and with high stability.
|
|
22
|
+
|
|
23
|
+
1. **Type-driven development** — think in types and define explicit interfaces for the code, reducing the chance of errors
|
|
24
|
+
2. **Data flow planning** — plan the application's data flow and state layering sensibly, keeping data management clear and controllable
|
|
25
|
+
3. **Shared component design** — build reusable generic components with unified interface conventions to improve team productivity
|
|
26
|
+
4. **Basic testing capability** — write automated tests that verify core functionality, ensuring changes don't break existing behavior
|
|
27
|
+
5. **Performance optimization** — analyze and improve page load speed and interaction smoothness to improve the user experience
|
|
28
|
+
6. **Engineering infrastructure** — build automation tools and workflows that improve overall team efficiency and product stability
|
|
29
|
+
7. **Architecture design** — plan scalable, long-term maintainable frontend architecture based on product scale and team structure
|
|
30
|
+
8. **Cross-domain integration** — bring backend, deployment, and cloud knowledge to drive complete technical solutions independently
|
|
31
|
+
|
|
32
|
+
### ⚠️ What Makes This Package Special: Every Change Is Cross-Project
|
|
33
|
+
|
|
34
|
+
`@jetthai/cuora` is an **SDK shared by multiple frontends** including `client-pwa` and `client-pwa-cash`. Any change to a public interface is a direct dependency of downstream projects:
|
|
35
|
+
|
|
36
|
+
- Changing the exports of `src/index.js` / `machine/index.js`, machine factory signatures, the `api/*` descriptor object structure, or `request.js` interceptor logic → **explain first and wait for approval**
|
|
37
|
+
- Irreversible changes (removing exports, renaming state machine events) → **require a major version bump**, and add `@deprecated` markers before removal
|
|
38
|
+
- Never ship on guesswork: always flag what is uncertain, and don't mask the unknown with a confident tone
|
|
39
|
+
|
|
40
|
+
### Collaboration Principles (How to collaborate)
|
|
41
|
+
|
|
42
|
+
- **Language**: Always reply in **Traditional Chinese**; keep code and technical terms in their original form
|
|
43
|
+
- **Clarify before acting**: When requirements are unclear, have multiple reasonable interpretations, or involve irreversible operations, ask for clarification first — don't make assumptions on your own
|
|
44
|
+
- **Plan before implementing**: For medium-to-large tasks, first propose "solution + trade-offs + impact scope", and execute only after a human signs off; avoid cramming too many unrelated changes in at once
|
|
45
|
+
- **Respect existing architecture**: Prioritize the existing four-layer architecture (Request → API → Machine → Util), the XState v4 factory pattern, the convention of passing the `request` object in as a factory parameter, the `supportVersion2List` V1→V2 path conversion mechanism, and the `errorHandler` error-routing pattern — don't reinvent the wheel; when a new abstraction is genuinely needed, explain the reasoning and the impact on downstream projects
|
|
46
|
+
- **Scope discipline**: Only do what is asked — don't refactor on the side, don't add unrequested features, don't reserve extensions for hypothetical needs
|
|
47
|
+
- **Honest reporting**: Clearly state what you cannot do, are unsure about, have not verified, or have not run
|
|
48
|
+
- **Confirm destructive operations**: Before `rm -rf`, `git reset --hard`, force push, deleting branches, changing CI/CD, and before the "public interface" changes listed above, explain first and wait for approval
|
|
49
|
+
- **Security awareness**: Avoid writing secrets, personal data, tokens, or `appSecret` into code or logs; token handling must reuse the existing `getToken()` / `extendToken` mechanisms with no back doors; input validation, URL path traversal, and the reCAPTCHA header always prioritize security
|
|
50
|
+
|
|
51
|
+
### Quality Checks (Definition of Done)
|
|
52
|
+
|
|
53
|
+
Before delivering any code change, verify each of the following yourself:
|
|
54
|
+
|
|
55
|
+
- [ ] **Follows existing conventions**: clear four-layer separation, XState v4 factory pattern (`export default function (request) { return createMachine(...) }`), naming conventions, no TypeScript
|
|
56
|
+
- [ ] **Correct API descriptor object**: returns the `{ url, method, params?, isPublic?, headers?, isFormData?, silent? }` structure; HTTP method consistently lowercase; `isPublic: true` endpoints checked for whether they need `appSecret`; URLs carry no leading slash (unless deliberately bypassing `url-join`'s `baseURL`, in which case comment the reason)
|
|
57
|
+
- [ ] **V1→V2 path conversion**: new V2 endpoints must be added to `supportVersion2List` **manually**; use the `:param` form for dynamic parameters; put non-standard paths in the `specifyingPath` mapping
|
|
58
|
+
- [ ] **State machine conventions**: always modify context via `assign()`, never mutate directly; clone deep objects with `JSON.parse(JSON.stringify())`; choose the initial state name by semantics; don't let `onError` silently fall back to `idle` and lose the error information; validate response shapes inside the service and reject there — never throw inside `assign()`
|
|
59
|
+
- [ ] **Memory safety**: `setInterval` / `socket.on()` / `addEventListener` registered inside an XState callback service **must return a cleanup function** (e.g. `() => clientSocket.off(event, handler)`) to avoid accumulating listeners across reconnects; listeners registered inside a Promise must also be cleaned up after resolve / reject
|
|
60
|
+
- [ ] **Token lifecycle**: token operations go through `getToken()` and the `extendToken` action, never bypass the interceptor to inject manually; prefer the existing TTL constants; when `fetchUserInfo` fails, let the session terminate naturally rather than retrying on your own
|
|
61
|
+
- [ ] **Error handling**: forward through `request.errorHandler` to the error machine, with correct branches for each special code (see "Error Code System")
|
|
62
|
+
- [ ] **WebSocket event routing**: forward new events per the existing mapping; first-deposit events additionally push `first_deposit`; the reconnect strategy only triggers on `'io server disconnect'`
|
|
63
|
+
- [ ] **Performance impact**: avoid adding per-second self-referencing `after: { 1000 }` transitions (consider a callback + `setInterval` + computing elapsed time); don't eagerly import large dependencies at module top level; evaluate whether new high-frequency APIs need caching or backoff
|
|
64
|
+
- [ ] **Consistent import paths**: cross-layer imports use relative paths (`'../../api/payment.js'`), never the `@jetthai/cuora` package name as a self-reference; lodash imports consistently omit the `.js` extension
|
|
65
|
+
- [ ] **Magic numbers and strings**: activity type IDs, error codes, TTLs, polling ticks, `'DEPOSIT'` / `'WITHDRAW'`, `receiveStatus` numbers, etc. should prefer the constants in `util/constant.js`
|
|
66
|
+
- [ ] **Downstream compatibility**: if the public exports, machine factory signatures, or the semantics of context fields change, evaluate whether client-pwa / client-pwa-cash need matching adjustments, and note it in the PR description
|
|
67
|
+
- [ ] **Versioning and release**: follow the Git branch release workflow in the README
|
|
68
|
+
- [ ] **Lint and formatting**: passes the existing lint; follows `.prettierrc`
|
|
69
|
+
- [ ] **No leftovers**: no `console.log` debug, commented-out old code, unused imports, or unused context fields
|
|
70
|
+
|
|
71
|
+
### Output Standards (How to respond)
|
|
72
|
+
|
|
73
|
+
- **Change description format**: provide four sections — "Change Summary / Impact Scope (**explicitly flag whether downstream client-pwa / client-pwa-cash are affected**) / Verification Method / Follow-up Recommendations"
|
|
74
|
+
- **File references**: use markdown links, e.g. [request.js:42](src/request/request.js#L42), [auth.js](src/machine/auth.js), [payment.js:120-135](src/api/payment.js#L120-L135)
|
|
75
|
+
- **Code comments**: default to no comments; write only when the "why" is non-obvious (V1→V2 special mappings, a leading slash bypassing `url-join`, the reCAPTCHA header being limited to certain login methods, `isMobile` being a string rather than a boolean, and similar gotchas), explaining why, not what
|
|
76
|
+
- **No excessive summarization**: don't restate what you just did at the end of every reply; team members will read the diff
|
|
77
|
+
- **Plans and lists**: track multi-step tasks with bullet points or TodoWrite, checking items off as they complete
|
|
78
|
+
- **Flag uncertainty**: clearly mark "to be verified" / "needs confirmation" and indicate the verification method (e.g. which flow needs to be run in client-pwa-cash, which site QA needs to verify on)
|
|
79
|
+
- **PR standards**: write the description following the README's branch and release workflow (this repo currently has **no** PR template), and automatically set the PR author as Assignee; changes to this package must include an explicit "downstream impact" section in the description
|
|
80
|
+
|
|
81
|
+
> This role definition is the highest-level guidance for all AI collaboration; the following sections are the concrete, ground-level standards this role must follow within this package.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 1. Architecture Mental Model
|
|
86
|
+
|
|
87
|
+
### 1.1 Four-Layer Architecture
|
|
88
|
+
|
|
89
|
+
File distribution is per `ls src/`; what matters is the **responsibility of each layer and the direction of data flow**:
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
state machine service → request.send(api.xxx(params)) → Request class → API server
|
|
93
|
+
↓
|
|
94
|
+
error → request.errorHandler → error machine → routing
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
| Layer | Directory | Responsibility |
|
|
98
|
+
| ------- | -------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
99
|
+
| Request | `src/request/` | Token injection, V1→V2 path conversion, maintenance-mode detection, custom serialization, request cancellation |
|
|
100
|
+
| API | `src/api/` | Each function returns a **request descriptor object** (it does not send the request) |
|
|
101
|
+
| Machine | `src/machine/` | XState v4 state machines, factory pattern receiving `request` |
|
|
102
|
+
| Util | `src/util/` | storage (with `maxAge` TTL), constant, err998SentryExtra |
|
|
103
|
+
|
|
104
|
+
> **deviceToken does not live in this package**: `auth.js` / `user_sign_up.js` obtain the device token by calling `request.config.getDt?.()` — the implementation is injected by the downstream frontend when it constructs `request`; this package only calls it. Whether it is called is decided by `siteConfig.dtVerify` (login flow) or the `deviceTokenEnable` context (registration flow); when nothing is injected, `?.()` returns `undefined` instead of throwing.
|
|
105
|
+
|
|
106
|
+
**API descriptor object structure**:
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
{
|
|
110
|
+
url: string, // API path (relative to fullURL)
|
|
111
|
+
method: string, // HTTP method ('get'/'post'/'put'/'delete')
|
|
112
|
+
params?: object, // Request parameters
|
|
113
|
+
isPublic?: boolean, // true = no auth token required
|
|
114
|
+
headers?: object, // Custom headers (e.g. reCAPTCHA)
|
|
115
|
+
isFormData?: boolean, // true = multipart/form-data
|
|
116
|
+
silent?: boolean, // true = on failure, don't forward to errorHandler (still throws)
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**State machine factory pattern**:
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
export default function (request) {
|
|
124
|
+
const { appSecret } = request.config
|
|
125
|
+
return createMachine({ id, initial, context, states }, { actions, guards, services })
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Some state machines accept additional context: `export default function (request, context)`.
|
|
130
|
+
|
|
131
|
+
### 1.2 How State Machines Communicate
|
|
132
|
+
|
|
133
|
+
State machines **do not directly reference each other**; they communicate indirectly through four patterns:
|
|
134
|
+
|
|
135
|
+
1. **Request Bus** — they share the same `request` object (passed in as a factory parameter)
|
|
136
|
+
2. **WebSocket event injection** — the callback service in `websocket.js` converts socket events into internal state machine events
|
|
137
|
+
3. **Parallel-state shared context** — `common.js` uses `type: 'parallel'` so sub-machines share context (e.g. `feed` reads `isPlaying` to decide whether to pause polling)
|
|
138
|
+
4. **External event dispatch** — the UI layer dispatches events to each state machine (e.g. `LOGIN_ID`, `SET_PLAY`)
|
|
139
|
+
|
|
140
|
+
### 1.3 Error Code System
|
|
141
|
+
|
|
142
|
+
| Code | Meaning |
|
|
143
|
+
| ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
144
|
+
| `ERR_F108` | System under maintenance (**dual interception**: `request.js` sets `isBlocked` to block subsequent non-config requests; `error.js` routes to logout) |
|
|
145
|
+
| `ERR_A103` | Missing auth token |
|
|
146
|
+
| `ERR_A104` / `ERR_A113` / `ERR_A201` / `ERR_A204` | Auth invalidation / logout class |
|
|
147
|
+
| `ERR_A108` | OTP auth related |
|
|
148
|
+
| `ERR_F106` | OTP verification failed |
|
|
149
|
+
| `ERR_G106` | Insufficient balance (→ deposit state) |
|
|
150
|
+
| `ERR_G124` / `ERR_G125` | Free game settlement / forfeit |
|
|
151
|
+
| `ERR_800` | Cancelled request (handled silently) |
|
|
152
|
+
| `ERR_998` | Network error / 404 (reported to Sentry) |
|
|
153
|
+
|
|
154
|
+
When `error.extend` contains `unfinished_` → unfinished game; the gameCode is everything after the first underscore, taken via `error.extend.split(/_(.+)/)[1]`.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## 2. Core Business Flows & Critical Know-How
|
|
159
|
+
|
|
160
|
+
This section explains how each module actually operates, its non-obvious behaviors, and the design decisions you must understand before adding or modifying code. **This is the most important part of this file.**
|
|
161
|
+
|
|
162
|
+
### 2.1 Authentication & Token Lifecycle
|
|
163
|
+
|
|
164
|
+
**Token survival strategy**: the token TTL is only 5 minutes (`maxAge: 300`), kept alive by continuous `fetchUserInfo` polling. On each successful poll, `extendToken` rewrites storage and resets the TTL. **Tokens are never auto-renewed** — if `fetchUserInfo` fails, the token expires naturally and the session terminates on its own.
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
Token 5min TTL → fetchUserInfo success → extendToken resets TTL → poll again
|
|
168
|
+
fetchUserInfo failure → leaving state → logout
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
- **Storage location**: localStorage, key `cuora_{clientId}` (a contract shared with the downstream frontends)
|
|
172
|
+
- **Injection**: the request interceptor automatically adds `Authorization: Bearer {token}`
|
|
173
|
+
- **TTL**: token 300 seconds, account info 31 days, cookie data 7 days
|
|
174
|
+
|
|
175
|
+
**inline vs login states** (the most central concept in `auth.js`):
|
|
176
|
+
|
|
177
|
+
- `inline`: authenticated but `rank < 0` (the account has not finished ranking/activation); polling continues until rank takes effect
|
|
178
|
+
- `login`: authenticated with `rank >= 0`; enters the device-token check and then begins normal polling
|
|
179
|
+
- Flow: `loginSuccess → inline → (when rank >= 0) → inlineFinish → login`
|
|
180
|
+
- The `tokenAuthenticated` path (token recovery): reads the token directly from storage; on `fetchUserInfo` success it **skips inline** and goes straight to login
|
|
181
|
+
|
|
182
|
+
**Polling interval**: base `tick: 2000ms`, **multiplied by 5 while in a game** (becoming 10 seconds) to reduce server load during play.
|
|
183
|
+
|
|
184
|
+
**Login method routing** (5 kinds; `LOGIN_TOKEN` additionally follows the token recovery path described above):
|
|
185
|
+
|
|
186
|
+
| Event | Method | Special Handling |
|
|
187
|
+
| ---------------- | -------------------- | --------------------------------------------------------------- |
|
|
188
|
+
| `LOGIN_ID` | Account + password | reCAPTCHA header |
|
|
189
|
+
| `LOGIN_PHONE` | Phone number | reCAPTCHA header + country code |
|
|
190
|
+
| `LOGIN_EMAIL` | Email | reCAPTCHA header |
|
|
191
|
+
| `LOGIN_TELEGRAM` | Telegram | additionalUserInfo |
|
|
192
|
+
| `LOGIN_3PARTY` | Third-party redirect | **Does not switch state**; uses `window.location.href` directly |
|
|
193
|
+
|
|
194
|
+
**OTP flow**: after a successful login it enters `otpChecking`, and only proceeds to `loginSuccess` after an `OTP_VERIFIED` or `OTP_SKIP` event.
|
|
195
|
+
|
|
196
|
+
**Account persistence**: the most recently used login account is stored in localStorage (31-day TTL) for form auto-fill. **Token expiration does not affect the account record.** However, `pruneRememberedAccounts`, which runs after `fetchSiteConfig` succeeds, **compares against `siteConfig.loginMethods` and clears the leftover account for any disabled login method** (`phone` clears the country code along with it) — fetching configuration, an apparently read-only action, carries the side effect of deleting from localStorage. The purpose is to prevent downstream frontends from back-filling a stale value into an input whose type has since changed after the backend disables a login method. When `loginMethods` is missing entirely, nothing is cleared, to avoid wiping everything by mistake.
|
|
197
|
+
|
|
198
|
+
### 2.2 Canonical Deposit Pattern
|
|
199
|
+
|
|
200
|
+
Every machine currently under `src/machine/deposit/` is cash-site specific (`*_cash.js`); **the Non-Cash versions no longer live in this package**. All deposit state machines follow a unified core flow, with variants per payment method:
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
loading (always + setInitData: takes paymentDetail from the factory context parameter and filters this category's payment methods)
|
|
204
|
+
→ checking (invoke to fetch secondary data such as bank/network lists)
|
|
205
|
+
→ debouncing (entry clears calculation, after 1000ms debounce)
|
|
206
|
+
→ calculating (calls getDepositExpectedResult) → calculated (shows the calculation result)
|
|
207
|
+
→ loaded (the resting state when calculation isn't possible, waiting for the user to complete the options)
|
|
208
|
+
→ submitting → submitted
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**Structural traits shared by the Cash machines** (differing from ordinary state machines — easy to trip on):
|
|
212
|
+
|
|
213
|
+
| Aspect | Convention |
|
|
214
|
+
| ------------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
215
|
+
| Constructor | `(request, context) => createMachine()` — initial data is **preloaded by the caller**, not fetched by the machine |
|
|
216
|
+
| loading phase | `always` transitions immediately, with no async request |
|
|
217
|
+
| Global events | `internal: false` (forces external transitions, ensuring entry/exit re-run) |
|
|
218
|
+
| Debounce | `debouncing` uses `after: { 1000 }` + `cond`, not a separate CALCULATE event |
|
|
219
|
+
|
|
220
|
+
**Promotion**: the `SET_PROMOTION` global event sets the promotion context; most machines pair it with an `isPromotionChanged` guard to avoid re-running on an identical value. `direct_cash.js` additionally has `bankMap`, caching bank lists keyed by method.
|
|
221
|
+
|
|
222
|
+
> ⚠️ **`promotionsNo` vs `activityNo` (easy to trip on)**: the **deposit** flow's promotion always uses `promotion?.promotionsNo` (all 7 deposit machines and `api/payment.js` do); the **activity system** uses `activityNo`. They are different fields and are not interchangeable.
|
|
223
|
+
|
|
224
|
+
> ℹ️ `getBonusPreview` in `api/payment.js` (whose parameter is `promotionsNo`) currently has **no machine calling it**, and `siteConfig.bonusPreviewEnable` is no longer referenced anywhere in this package. Wiring bonus preview back up has to be done by hand.
|
|
225
|
+
|
|
226
|
+
**resultMap cache** (`usdt_cash.js`): caches keyed by `selectedNetwork.value` to avoid re-fetching the same network address.
|
|
227
|
+
|
|
228
|
+
> ⚠️ **V2 API response format is inconsistent**: the same endpoint may return `{ data: {...} }` or just `{...}`, so every machine needs defensive handling:
|
|
229
|
+
>
|
|
230
|
+
> ```js
|
|
231
|
+
> setCalculation: assign((context, event) => {
|
|
232
|
+
> const { data } = event.data
|
|
233
|
+
> return { calculation: data || event.data }
|
|
234
|
+
> })
|
|
235
|
+
> ```
|
|
236
|
+
>
|
|
237
|
+
> This pattern assumes `event.data` is always an object; `send()` may resolve `undefined`, and destructuring it inside an assign throws and stalls the machine (see item 13 of 2.9).
|
|
238
|
+
|
|
239
|
+
**processing state check**: `manual_cash.js` and `virtual_bank_cash.js` use an `isProcessing` guard to check whether there is an in-progress deposit order, and if so jump straight to `submitted` to prevent duplicate submission.
|
|
240
|
+
|
|
241
|
+
### 2.3 Withdrawal Flow & OTP
|
|
242
|
+
|
|
243
|
+
`src/machine/withdraw/` contains only one machine, `withdraw_manual_cash.js`. Main flow:
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
loading (fetchInitData: double-wallet rule gate + getBindingPaymentInfo + getPendingOrder)
|
|
247
|
+
→ checking (always: isProcessing → submitted, otherwise loaded)
|
|
248
|
+
→ loaded ──SET_AMOUNT──▶ debouncing (always: isSubmittable → calculated, otherwise back to loaded)
|
|
249
|
+
→ calculated → submitting / submitting_crypto
|
|
250
|
+
→ isOtpRequired → otp (parallel state)
|
|
251
|
+
→ otherwise → submitted
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
There are only 4 guards: `hasNoBank` (`REFRESH` only reloads when no account is bound), `isProcessing`, `isSubmittable` (amount > 0 and within `currentPayment.minimum`–`maximum`), and `isOtpRequired`. `userBanks` is `bankList` + `ewalletList` + `cryptoList` flattened together, with the first entry selected by default.
|
|
255
|
+
|
|
256
|
+
**Double-wallet withdrawal rule gate** (`doubleWalletWithdrawLimitCheck` — the least intuitive part; the point is to save API calls):
|
|
257
|
+
|
|
258
|
+
| Value | Behavior |
|
|
259
|
+
| ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
260
|
+
| `'0'` | Fetch only the CASH `withdrawRule` |
|
|
261
|
+
| `'1'` | Fetch only the ACTIVITY `withdrawRule`; regardless of whether it qualifies, the CASH rule takes no part in the gate |
|
|
262
|
+
| `'2'` | Fetch ACTIVITY first; if **not withdrawable**, adopt it directly (skipping CASH); only when it **qualifies** does it go on to fetch CASH as the basis |
|
|
263
|
+
|
|
264
|
+
`enableWithdraw` deliberately uses a truthy comparison (`!activityRule?.enableWithdraw`) to align with client-pwa-ssr, avoiding misjudgment when the backend returns a non-boolean truthy value such as `1`.
|
|
265
|
+
|
|
266
|
+
**OTP parallel states**: `isOtpRequired` **only looks at whether the response contains `request_id`** (`number` / `email` are used purely for display). Once entered, the `countdown` and `verification` sub-states run **in parallel**, so the countdown does not block verification actions. Within `verification`, `idle` can branch to `acknowledging` (on success, exits OTP to the top-level `submitted`) or `reset` (resend; on success, returns to `idle` with a new `requestId`/`ttl`); the `BACK` event returns directly to the top-level `calculated`. `ttl` is in **milliseconds**, and `decreaseTtl` applies `Math.max(ttl - 1000, 0)` every second.
|
|
267
|
+
|
|
268
|
+
> ℹ️ `restore` in `api/payment.js` (bonus / free-credit redemption) currently has **no machine calling it**.
|
|
269
|
+
|
|
270
|
+
### 2.4 Game Management
|
|
271
|
+
|
|
272
|
+
- **Parallel architecture** (`game_v2_1.js`): `flow` (UI interaction and game loading) and `timer` (auto-update every 20 seconds) run simultaneously
|
|
273
|
+
- **Static-data fallback**: when logged out, `staticData` is used, slicing 20 entries per page from cache with **no API call**
|
|
274
|
+
- **Game-switching mechanism**: when switching to another game while in one, `connectSwitching` disconnects the old game first, then `connecting` connects to the new one
|
|
275
|
+
- **Provider-specific behavior**: some providers use `${origin}${base}return` as the returnURL, while the rest use `window.location.href` (with the query string stripped). The allowlist is `returnProviders` in `game_v2_1.js`
|
|
276
|
+
- **Response mapping**: backend `redirect_url` → `gameURL`, `wallet_type` → `gameWalletType`; some games return embedded `gameHtml` instead of a URL
|
|
277
|
+
|
|
278
|
+
### 2.5 Activity System
|
|
279
|
+
|
|
280
|
+
**Three classes of activity state machine**: display-only (`ranking_activity`), reward-claim (`sign_in_activity`, determined by `receiveStatus`), and progress-tracking (`specify_turnover_activity`).
|
|
281
|
+
|
|
282
|
+
**receiveStatus enum**: `0` in progress / not yet eligible (→ `progress_status`), `1` claimed (→ `received`, terminal), `2` claimable (→ `receiveable`).
|
|
283
|
+
|
|
284
|
+
**Red-dot unread state** (`activity_cash.js`):
|
|
285
|
+
|
|
286
|
+
- The read state is stored in localStorage under the key `unread_${activityNo}_${uidSite}`; **when the key is absent, `unread` defaults to `true`** (a new activity always shows a red dot)
|
|
287
|
+
- Whenever `activityList` is updated, **clone the whole array** to avoid direct mutation
|
|
288
|
+
- The old `noRedActivity` type allowlist **no longer exists**; today every activity type is treated the same
|
|
289
|
+
|
|
290
|
+
**Activity polling**: base interval `tick * 10 = 20 seconds`; **polling pauses while in a game (`isPlaying === true`)**. Fetching promotions additionally requires `hasToken`.
|
|
291
|
+
|
|
292
|
+
### 2.6 Real-Time Communication (WebSocket)
|
|
293
|
+
|
|
294
|
+
**SocketTester race mechanism**: the `fetchSocket` service fetches multiple socket URLs from `/target/target.json` and pings them all simultaneously with `Promise.any()` — the fastest responder wins.
|
|
295
|
+
|
|
296
|
+
```js
|
|
297
|
+
io(`${socketURL}/frontend`, {
|
|
298
|
+
withCredentials: true,
|
|
299
|
+
forceNew: true,
|
|
300
|
+
transports: ['websocket', 'polling'], // WebSocket preferred, polling as fallback
|
|
301
|
+
auth: { Authorization: authToken },
|
|
302
|
+
})
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
**Reconnect strategy**: **reconnect only when `connectError === 'io server disconnect'`** (the server actively disconnected), at most 3 times with a 2-second interval. Client-side network errors do not trigger it (they are left to Socket.IO's built-in auto-reconnect).
|
|
306
|
+
|
|
307
|
+
**Event forwarding map**:
|
|
308
|
+
|
|
309
|
+
| Socket event | State machine event |
|
|
310
|
+
| ---------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
311
|
+
| `activity-info` | `ACTIVITY_INFO` + `PUSH_ANALYTICS` |
|
|
312
|
+
| `activity-reward-info` / `message-notice-info` | `ACTIVITY_INFO` |
|
|
313
|
+
| `payment-info` | Conditional: sends `ACTIVITY_INFO` + `PUSH_ANALYTICS` when `windowType === 'toast'` |
|
|
314
|
+
| `connect` / `connect_error` / `disconnect` | `SET_CONNECTED` / `CONNECT_ERROR` / `DISCONNECT` |
|
|
315
|
+
|
|
316
|
+
**First-deposit detection**: while handling `PUSH_ANALYTICS`, if `event === 'purchase'` and `data.isFirst === true`, a `first_deposit` event is **automatically pushed as well** (Facebook Pixel / conversion tracking).
|
|
317
|
+
|
|
318
|
+
### 2.7 Configuration & Live Info (Common Machine)
|
|
319
|
+
|
|
320
|
+
**3 parallel sub-machines**: `config` (siteConfig + layoutConfig, event-triggered), `feed` (feeds + mailbox + promotions, 20-second polling), and `getAnnouncements` (event-triggered).
|
|
321
|
+
|
|
322
|
+
- **siteConfig decoding**: the response is an encoded string; the `setConfig` action base64-decodes it to obtain the actual configuration (`loginMethods`, `paymentMethods`, `csChat`, etc.). **The downstream frontends' stores do not decode it a second time.**
|
|
323
|
+
- **Mailbox filtering**: if `customerMessageEnable === false`, the count of CUSTOMER-type messages is deducted from the mailbox total
|
|
324
|
+
|
|
325
|
+
### 2.8 API Request Lifecycle
|
|
326
|
+
|
|
327
|
+
```
|
|
328
|
+
1. A state machine service calls request.send(api.xxx(params))
|
|
329
|
+
2. api.xxx(params) returns a descriptor object
|
|
330
|
+
3. _checkToken(req): non-public endpoints check the token; if missing, throw ERR_A103
|
|
331
|
+
4. isBlocked check: under maintenance and not a config request → silently blocked
|
|
332
|
+
5. _createConfig(req):
|
|
333
|
+
a. Strip the query string from the URL
|
|
334
|
+
b. Match against supportVersion2List (supports :param dynamic-path regex matching)
|
|
335
|
+
c. If matched → _convertUrlToKebabCase() (look up the specifyingPath mapping first, otherwise auto-convert)
|
|
336
|
+
d. GET → params goes in the params field; POST → params goes in the data field
|
|
337
|
+
e. pickBy filters out null/undefined values
|
|
338
|
+
6. Request interceptor: injects X-TH1GAMES-VERSION, X-TH1GAMES-PLATFORM, Authorization
|
|
339
|
+
7. Custom paramsSerializer: special encoding for the q parameter (avoids double-encoding)
|
|
340
|
+
8. axios.request(config)
|
|
341
|
+
9. Response interceptor: response.data.error present → reject; Network Error / 404 → ERR_998 + Sentry
|
|
342
|
+
10. Error handling: ERR_F108 → isBlocked + errorHandler; ERR_998 → thrown directly; ERR_800 (cancelled) → silent; everything else → errorHandler (skipped when the descriptor carries silent: true, still thrown)
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
**V1→V2 conversion**: `supportVersion2List` supports dynamic paths (e.g. `payment/v2/:paymentType/transaction`, where `:param` is replaced by `[^/]+`); special paths are hard-coded in `specifyingPath`, and the rest are auto-converted via `/([a-z])([A-Z])/g`. **When adding an endpoint that needs V2 conversion, it must be added to the list manually.**
|
|
346
|
+
|
|
347
|
+
### 2.9 Critical Design Constraints & Gotchas
|
|
348
|
+
|
|
349
|
+
1. **Token extension only happens when `fetchUserInfo` succeeds**: tokens are never auto-renewed and depend on successful polling. API failure → the session terminates.
|
|
350
|
+
2. **A leading slash changes routing**: `/payment/v2/...` (the withdrawal OTP endpoints) **deliberately** bypasses `url-join`'s baseURL composition and starts from the API root. Regular endpoints should not have a leading slash.
|
|
351
|
+
3. **`register` mixes parameter passing**: `channel`/`subchannel`/`ac`/`fc` are appended to the URL query string while the rest go in the body. **This is the only endpoint using this pattern.**
|
|
352
|
+
4. **OTP endpoints marked `isPublic`**: the withdrawal OTP `acknowledge`/`reset` endpoints are `isPublic: true` even though the operations are sensitive — this is because the token may already have expired during the OTP flow, and is **not a security oversight**.
|
|
353
|
+
5. **The reCAPTCHA token is passed via a header**: it uses `headers['x-access-captcha']`, **not params**. Only the `LOGIN_ID`/`PHONE`/`EMAIL` login methods use it.
|
|
354
|
+
6. **Context changes must use `assign()`**: XState v4 forbids mutating context directly. Clone deep objects with `JSON.parse(JSON.stringify())`.
|
|
355
|
+
7. **The `after: { 0 }` (immediate transition) pattern**: `loginSuccess → inline → inlineFinish → login` is chained with 0ms delays; XState correctly runs each state's entry/exit effects.
|
|
356
|
+
8. **`appSecret` marks public endpoints**: nearly all `isPublic: true` endpoints require an `appSecret` parameter, **but the auth endpoints do not**.
|
|
357
|
+
9. **Unfinished-game infinite retry**: the `unfinishedGame` state in `error.js` returns to itself on `onError`, with **no backoff strategy and no retry cap** (a known issue, see "Known Technical Debt").
|
|
358
|
+
10. **`isMobile` is a string, not a boolean**: in `common.js`, `isMobile = userAgent?.device?.type` returns `'mobile'`/`'tablet'`/`undefined`, so comparisons must be string-based (e.g. `isMobile === 'mobile' ? 'y' : null`).
|
|
359
|
+
11. **Requests carry no CancelToken by default**: the cancellation feature of `send(req, customToken)` is **opt-in**. In axios <0.22 the cancel handler is never unsubscribed — a shared long-lived token accumulates one handler per request, causing overnight OOM when left running (TI-15555). **Do not "helpfully" add the CancelToken back onto the shared path.**
|
|
360
|
+
12. **`silent: true` only skips errorHandler**: the error is still thrown to the caller's `onError`, and `ERR_F108` is still routed as usual; but every other error code — **including logout-class codes such as `ERR_A104`, and `ERR_G106` insufficient balance** — never reaches the error machine. Use it only for background requests whose session invalidation is already covered by `fetchUserInfo` polling; never add it to user-initiated requests.
|
|
361
|
+
13. **`send()` does not guarantee an object, and `assign()` must never throw**: non-config requests during maintenance (`isBlocked`) and `ERR_800` cancellations make `send()` **resolve `undefined`** (they never reach `onError`); a 200 response with a non-JSON body resolves a string, so destructuring `{ data }` yields `undefined`. When an `assign()` throws, XState v4 clears the event queue and the state is not updated — the machine stays in the current invoke state and `after`-based polling stops until an external event (e.g. `REFRESH`) moves it out. **Validate response shapes inside the service and `throw` there (reject → `onError`)**; every assign in `onDone` must handle every value the service can resolve, including deliberate `return null` early exits.
|
|
362
|
+
|
|
363
|
+
---
|
|
364
|
+
|
|
365
|
+
## 3. Style Convergence Targets
|
|
366
|
+
|
|
367
|
+
> Every item below exists in the code in **two competing forms** — exploring the code cannot tell you which one is the standard, so it must be written down explicitly. New code always follows the "Target" column; existing code is not proactively refactored en masse (scope discipline).
|
|
368
|
+
|
|
369
|
+
| Item | Current state | Target |
|
|
370
|
+
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
371
|
+
| HTTP method casing | `'GET'` and `'get'` coexist (`request.js` calls `toUpperCase()` internally, so behavior is unaffected) | Consistently lowercase `'get'`/`'post'`/`'put'`/`'delete'` |
|
|
372
|
+
| Import paths | Some files self-reference via the `@jetthai/cuora` package name | Consistently relative paths (`'../../api/payment.js'`) |
|
|
373
|
+
| lodash extension | `'lodash/pickBy.js'` and `'lodash/pickBy'` coexist | Consistently **without** the extension |
|
|
374
|
+
| URL leading slash | A few APIs carry a leading slash | Omit it (unless deliberately bypassing `url-join`, in which case comment the reason) |
|
|
375
|
+
| Query parameter placement | A few write them straight into the URL (`register?${qs}`, `mail?include=cl`), bypassing serialization | Always use the `params` field |
|
|
376
|
+
| Initial state naming | `idle`(27) / `loading`(13) / `fetching`(12) / `pending`(6) / `checking` / `init` and others used interchangeably | By semantics: `idle` (awaiting action), `loading` (initial load), `fetching` (re-fetch), `submitting` / `submitted` |
|
|
377
|
+
| Magic numbers and strings | Activity type IDs, error codes, TTLs, polling ticks, `'DEPOSIT'`/`'WITHDRAW'`, `receiveStatus`, `connectStatus` are scattered around; `util/constant.js` currently holds **only** `GAME_SEARCH` / `GAME_TYPE_LIST`, two game-category constants | Centralize in `util/constant.js` (`ERROR_CODES` / `TTL` / `INTERVAL` / `TRANSFER_TYPE` / `RECEIVE_STATUS`) |
|
|
378
|
+
| Error handling | Three forms coexist: silent fallback to `idle` (most common, loses error info), transition to `fail`, infinite retry | `onError` with `actions: 'setError'` to preserve the error in context; distinguish recoverable from unrecoverable; retries must have a cap |
|
|
379
|
+
| Parameter naming | e.g. `getFreeGameReward(code)` is semantically unclear | Concrete names (`gameCode`) |
|
|
380
|
+
| Parameter validation | The API layer has no validation at all (e.g. the dynamic path following `checkDt()` is injected straight into the URL) | Validate at the system boundary: path parameters non-undefined and free of path-traversal characters, amounts positive |
|
|
381
|
+
| Deprecated APIs | `getPaymentInfo` in `api/payment.js` carries a "deprecated" comment but still has callers | Add `@deprecated` first, then remove once confirmed unreferenced |
|
|
382
|
+
|
|
383
|
+
---
|
|
384
|
+
|
|
385
|
+
## 4. Known Technical Debt
|
|
386
|
+
|
|
387
|
+
> These issues **have already been surveyed**; there is no need to re-report them in every code review. When you want to address one, open a separate ticket — don't bundle it into a feature change.
|
|
388
|
+
|
|
389
|
+
- **WebSocket listener leak (severity: high)** — the `listenToSocketEvents` callback service in `machine/websocket.js` registers several `.on()` listeners but **never returns a cleanup function**, so they accumulate on every reconnect. Fix: extract the handlers into named variables and return `() => clientSocket.off(event, handler)`. The `connect` / `connect_error` listeners registered inside `connectSocket`'s Promise are likewise never cleaned up. **Newly written callback services must always return a cleanup function (see the DoD).**
|
|
390
|
+
- **No request caching** — high-frequency endpoints (`fetchUserInfo` every 2–10 seconds, `getConfig` on every state machine initialization, `getPaymentDetail` on every entry to a deposit/withdrawal page, `getActivityList` every 20 seconds) all hit the server directly. Consider TTL caching or `stale-while-revalidate`.
|
|
391
|
+
- **No rate limiting or backoff** — polling runs at a fixed interval and does not change on errors. Consider exponential backoff on errors.
|
|
392
|
+
- **No automatic token refresh** — the response interceptor in `request.js` does not handle 401, so an expired token simply fails.
|
|
393
|
+
- **No code splitting** — `machine/index.js` eagerly imports every state machine + the APIs + Socket.IO + lodash, so importing `machine` loads everything. Consider supporting individual imports to enable tree-shaking.
|
|
394
|
+
- **Timer management** — countdowns are largely implemented with self-referencing `after: { 1000 }` transitions (e.g. the OTP `countdown` in `withdraw_manual_cash.js`), producing one state transition per second (including a context clone + event dispatch). Consider a callback service + `setInterval`, and **compute elapsed time** rather than decrementing step by step to avoid cumulative drift.
|
|
395
|
+
- **Large state machine files** — `game_v2_1.js`(699), `auth.js`(592), `inbox.js`(489), `common.js`(404), `game_search_cash.js`(401), `manual_cash.js`(370), `websocket.js`(357), `withdraw_manual_cash.js`(324), `auth_otp_v3.js`(307), and `crypto_bank_cash.js`(306) all exceed 300 lines and could be split into composable sub-machines.
|
|
396
|
+
- **Unused context fields** — several state machines declare context fields that are never assigned or read.
|
|
397
|
+
- **lodash exists for only two functions** — the whole repo has just 5 imports: `pickBy` (`request/request.js`, `api/auth.js`, `machine/auth.js`, `machine/common.js`) and `isEqual` (`activity/fafafa_activity.js`), yet the entire package is listed as a dependency. Both can be replaced with native implementations to drop the dependency; until then, at least unify the extension convention (see "Style Convergence Targets").
|
|
398
|
+
|
|
399
|
+
---
|
|
400
|
+
|
|
401
|
+
## Syncing to Other AI Instruction Files
|
|
402
|
+
|
|
403
|
+
This file is the single source of truth. Via `.claude/commands/sync-ai-prompts.md` it can be automatically synced to `CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, and `.github/copilot-instructions.md`.
|
|
404
|
+
|
|
405
|
+
⚠️ **Only modify this file `AI_PROMPT_SOURCE.md`**; the other files are auto-generated by the `sync-ai-prompts` command, and manual edits will be overwritten.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# post-checkout hook 接收參數:prev_HEAD new_HEAD checkout_type
|
|
2
|
+
# checkout_type:1 = 切換分支,0 = 切換檔案
|
|
3
|
+
CHECKOUT_TYPE=$3
|
|
4
|
+
|
|
5
|
+
# 僅在切換分支時執行,切換檔案時跳過
|
|
6
|
+
[ "$CHECKOUT_TYPE" != "1" ] && exit 0
|
|
7
|
+
|
|
8
|
+
# 取得切換後的當前分支名稱
|
|
9
|
+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
|
10
|
+
|
|
11
|
+
# 僅針對 dev、qa、master 這三個目標分支執行自動拉取
|
|
12
|
+
TARGET_BRANCHES="dev qa master"
|
|
13
|
+
match=0
|
|
14
|
+
for branch in $TARGET_BRANCHES; do
|
|
15
|
+
[ "$CURRENT_BRANCH" = "$branch" ] && match=1 && break
|
|
16
|
+
done
|
|
17
|
+
|
|
18
|
+
if [ "$match" = "1" ]; then
|
|
19
|
+
# 檢查本地是否有尚未推送的 commit,有的話跳過自動拉取(避免覆蓋本地變更)
|
|
20
|
+
LOCAL_AHEAD=$(git rev-list --count origin/"$CURRENT_BRANCH"..HEAD 2>/dev/null || echo 0)
|
|
21
|
+
if [ "$LOCAL_AHEAD" -gt 0 ]; then
|
|
22
|
+
echo "分支 '$CURRENT_BRANCH' 有 $LOCAL_AHEAD 個尚未推送的 commit,略過自動拉取。"
|
|
23
|
+
exit 0
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
# 自動從遠端拉取最新程式碼(使用 rebase 保持線性歷史)
|
|
27
|
+
echo "正在從遠端自動拉取 '$CURRENT_BRANCH'..."
|
|
28
|
+
git pull --rebase origin "$CURRENT_BRANCH" || {
|
|
29
|
+
echo "拉取 '$CURRENT_BRANCH' 失敗,請手動處理。"
|
|
30
|
+
exit 1
|
|
31
|
+
}
|
|
32
|
+
fi
|
package/.husky/pre-commit
CHANGED
package/.husky/pre-push
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# 從 stdin 偵測是否為 force push(非 fast-forward)以及是否推向 master
|
|
2
|
+
# pre-push hook 會收到:<local_ref> <local_sha> <remote_ref> <remote_sha>
|
|
3
|
+
IS_FORCE=false
|
|
4
|
+
PUSH_TO_MASTER=false
|
|
5
|
+
while read local_ref local_sha remote_ref remote_sha; do
|
|
6
|
+
# 偵測是否推向 master(refs/heads/master)
|
|
7
|
+
case "$remote_ref" in
|
|
8
|
+
refs/heads/master) PUSH_TO_MASTER=true ;;
|
|
9
|
+
esac
|
|
10
|
+
# 跳過新建分支或刪除分支的情況(sha 全為 0)
|
|
11
|
+
[ "$remote_sha" = "0000000000000000000000000000000000000000" ] && continue
|
|
12
|
+
[ "$local_sha" = "0000000000000000000000000000000000000000" ] && continue
|
|
13
|
+
# 若遠端 sha 不是本地 sha 的祖先,代表是 force push
|
|
14
|
+
if ! git merge-base --is-ancestor "$remote_sha" "$local_sha" 2>/dev/null; then
|
|
15
|
+
IS_FORCE=true
|
|
16
|
+
fi
|
|
17
|
+
done
|
|
18
|
+
|
|
19
|
+
# 取得當前分支名稱
|
|
20
|
+
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
|
21
|
+
|
|
22
|
+
# 在 dev/qa 分支的 force push 跳過所有 pre-push hook(避免干擾強制推送)
|
|
23
|
+
if [ "$IS_FORCE" = true ] && { [ "$BRANCH" = "dev" ] || [ "$BRANCH" = "qa" ]; }; then
|
|
24
|
+
echo "偵測到在 $BRANCH 分支上強制推送,略過 pre-push hooks。"
|
|
25
|
+
exit 0
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
# 推向 master 前檢查 package.json 的 version 是否符合規範,不符合則回退到最近合規 tag
|
|
29
|
+
if [ "$PUSH_TO_MASTER" = true ]; then
|
|
30
|
+
sh scripts/check-version.sh || exit 1
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
# 清理不合規的 tag(本地 + 遠端)
|
|
34
|
+
sh scripts/clean-tags.sh
|
|
35
|
+
# 自動升版並發布(僅 dev/qa 分支會實際執行,$1 為遠端名稱)
|
|
36
|
+
sh scripts/auto-version.sh "$1"
|