@jetthai/cuora 1.1.474 → 1.1.476-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/commands/sync-ai-prompts.md +88 -1
- package/.claude/settings.local.json +3 -1
- package/.github/copilot-instructions.md +66 -61
- package/.husky/post-checkout +3 -3
- package/.husky/pre-push +1 -1
- package/.prettierignore +2 -1
- package/AGENTS.md +67 -62
- package/AI_PROMPT_SOURCE.md +67 -62
- package/CHANGELOG.md +261 -6
- package/CLAUDE.md +67 -62
- package/GEMINI.md +67 -62
- package/README.md +11 -12
- package/package.json +1 -1
- package/prepare-for-pr/JT-1776243420.md +85 -0
- package/scripts/auto-version.js +1 -0
- package/scripts/branch-auto-npm-publish.js +9 -2
- package/src/api/account.js +0 -1
- package/src/api/activity.js +0 -37
- package/src/api/auth.js +0 -31
- package/src/api/game.js +0 -10
- package/src/api/payment.js +1 -52
- package/src/api/user.js +0 -16
- package/src/index.js +2 -2
- package/src/machine/activity/activity_cash.js +14 -1
- package/src/machine/activity/diamond_shop_activity_cash.js +0 -1
- package/src/machine/activity/fafafa_activity.js +0 -10
- package/src/machine/activity/index.js +0 -12
- package/src/machine/auth.js +37 -59
- package/src/machine/auth_otp_v3.js +30 -19
- package/src/machine/common.js +0 -55
- package/src/machine/deposit/index.js +0 -28
- package/src/machine/deposit/manual_cash.js +0 -8
- package/src/machine/game_info.js +1 -12
- package/src/machine/game_v2_1.js +1 -89
- package/src/machine/honor_board_cash.js +15 -18
- package/src/machine/inbox.js +0 -12
- package/src/machine/index.js +0 -32
- package/src/machine/reward_cash.js +0 -39
- package/src/machine/user_reset_password.js +0 -13
- package/src/machine/user_sign_up.js +3 -0
- package/src/machine/websocket.js +0 -4
- package/src/machine/withdraw/index.js +0 -6
- package/src/request/request.js +0 -28
- package/src/util/constant.js +0 -1
- package/src/util/index.js +1 -4
- package/test/auth_otp_v3.test.js +192 -0
- package/src/machine/activity/activity.js +0 -209
- package/src/machine/activity/diamond_shop_activity_fc.js +0 -196
- package/src/machine/activity/diamond_shop_activity_vn.js +0 -178
- package/src/machine/activity/invite_friends_activity.js +0 -114
- package/src/machine/activity/mini_game_activity.js +0 -68
- package/src/machine/activity/return_bonus_activity.js +0 -153
- package/src/machine/auth_otp_v2.js +0 -177
- 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 -330
- package/src/machine/deposit/crypto_qrcode.js +0 -148
- package/src/machine/deposit/crypto_way.js +0 -252
- package/src/machine/deposit/deposit_fc.js +0 -272
- package/src/machine/deposit/direct.js +0 -310
- package/src/machine/deposit/float.js +0 -375
- package/src/machine/deposit/krway.js +0 -151
- package/src/machine/deposit/loadcard_vn.js +0 -351
- package/src/machine/deposit/manual_vn.js +0 -458
- package/src/machine/deposit/qrcode_v2.js +0 -338
- package/src/machine/deposit/usdt.js +0 -144
- package/src/machine/deposit/virtual_bank_vn.js +0 -269
- package/src/machine/deposit/vpay.js +0 -368
- package/src/machine/game_hot_new.js +0 -79
- package/src/machine/game_replay.js +0 -46
- package/src/machine/game_search_v2.js +0 -401
- package/src/machine/honor_board.js +0 -132
- package/src/machine/merge.js +0 -57
- package/src/machine/payment_data.js +0 -86
- package/src/machine/promotions.js +0 -170
- package/src/machine/reward.js +0 -255
- package/src/machine/reward_fc.js +0 -98
- package/src/machine/side.js +0 -154
- package/src/machine/side_v2.js +0 -211
- package/src/machine/vip_table.js +0 -57
- package/src/machine/welcome.js +0 -110
- package/src/machine/withdraw/withdraw_crypto_cash.js +0 -327
- package/src/machine/withdraw/withdraw_krway.js +0 -223
- package/src/machine/withdraw/withdraw_manual.js +0 -536
- package/src/util/math.js +0 -4
package/AGENTS.md
CHANGED
|
@@ -53,7 +53,7 @@ You are a senior full-stack engineer with world-class capability across UI/UX, A
|
|
|
53
53
|
Before delivering any code change, verify each of the following yourself:
|
|
54
54
|
|
|
55
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
|
|
56
|
+
- [ ] **Correct API descriptor object**: returns the `{ url, method, params?, isPublic?, headers?, isFormData? }` 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
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
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
|
|
59
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
|
|
@@ -99,7 +99,9 @@ state machine service → request.send(api.xxx(params)) → Request class → AP
|
|
|
99
99
|
| Request | `src/request/` | Token injection, V1→V2 path conversion, maintenance-mode detection, custom serialization, request cancellation |
|
|
100
100
|
| API | `src/api/` | Each function returns a **request descriptor object** (it does not send the request) |
|
|
101
101
|
| Machine | `src/machine/` | XState v4 state machines, factory pattern receiving `request` |
|
|
102
|
-
| Util | `src/util/` | storage (with `maxAge` TTL),
|
|
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.
|
|
103
105
|
|
|
104
106
|
**API descriptor object structure**:
|
|
105
107
|
|
|
@@ -111,7 +113,6 @@ state machine service → request.send(api.xxx(params)) → Request class → AP
|
|
|
111
113
|
isPublic?: boolean, // true = no auth token required
|
|
112
114
|
headers?: object, // Custom headers (e.g. reCAPTCHA)
|
|
113
115
|
isFormData?: boolean, // true = multipart/form-data
|
|
114
|
-
silent?: boolean, // true = on failure, don't forward to errorHandler (still throws)
|
|
115
116
|
}
|
|
116
117
|
```
|
|
117
118
|
|
|
@@ -179,52 +180,49 @@ Token 5min TTL → fetchUserInfo success → extendToken resets TTL → poll aga
|
|
|
179
180
|
|
|
180
181
|
**Polling interval**: base `tick: 2000ms`, **multiplied by 5 while in a game** (becoming 10 seconds) to reduce server load during play.
|
|
181
182
|
|
|
182
|
-
**Login method routing** (
|
|
183
|
+
**Login method routing** (5 kinds; `LOGIN_TOKEN` additionally follows the token recovery path described above):
|
|
183
184
|
|
|
184
185
|
| Event | Method | Special Handling |
|
|
185
186
|
| ---------------- | -------------------- | --------------------------------------------------------------- |
|
|
186
187
|
| `LOGIN_ID` | Account + password | reCAPTCHA header |
|
|
187
188
|
| `LOGIN_PHONE` | Phone number | reCAPTCHA header + country code |
|
|
188
189
|
| `LOGIN_EMAIL` | Email | reCAPTCHA header |
|
|
189
|
-
| `LOGIN_LOCAL` | Local account | Additionally stores `cuora_tempuser` (24h TTL) |
|
|
190
|
-
| `LOGIN_GUEST` | Guest | No auth credentials |
|
|
191
|
-
| `LOGIN_APP` | OAuth App | provider + accessToken |
|
|
192
190
|
| `LOGIN_TELEGRAM` | Telegram | additionalUserInfo |
|
|
193
191
|
| `LOGIN_3PARTY` | Third-party redirect | **Does not switch state**; uses `window.location.href` directly |
|
|
194
192
|
|
|
195
|
-
**OTP flow**: after a successful login it enters `otpChecking`, and only proceeds to `loginSuccess`
|
|
193
|
+
**OTP / bind-bank flow**: after a successful login it enters `otpChecking`; `OTP_VERIFIED` or `OTP_SKIP` moves it to `bindBankChecking`, and only `BIND_BANK_DONE` or `BIND_BANK_SKIP` proceeds to `loginSuccess` (either gate accepts `LOGOUT` to abort). Whether binding is required is decided by the downstream frontend; the machine only waits — **downstream must send one of these events in `bindBankChecking`, or the session stalls there**. The `tokenAuthenticated` path skips both gates.
|
|
196
194
|
|
|
197
195
|
**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.
|
|
198
196
|
|
|
199
197
|
### 2.2 Canonical Deposit Pattern
|
|
200
198
|
|
|
201
|
-
All deposit state machines follow a unified core flow, with variants per payment method:
|
|
199
|
+
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:
|
|
202
200
|
|
|
203
201
|
```
|
|
204
|
-
loading (
|
|
205
|
-
→
|
|
206
|
-
→
|
|
207
|
-
→
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
→ submitting → submitted
|
|
202
|
+
loading (always + setInitData: takes paymentDetail from the factory context parameter and filters this category's payment methods)
|
|
203
|
+
→ checking (invoke to fetch secondary data such as bank/network lists)
|
|
204
|
+
→ debouncing (entry clears calculation, after 1000ms debounce)
|
|
205
|
+
→ calculating (calls getDepositExpectedResult) → calculated (shows the calculation result)
|
|
206
|
+
→ loaded (the resting state when calculation isn't possible, waiting for the user to complete the options)
|
|
207
|
+
→ submitting → submitted
|
|
211
208
|
```
|
|
212
209
|
|
|
213
|
-
**
|
|
210
|
+
**Structural traits shared by the Cash machines** (differing from ordinary state machines — easy to trip on):
|
|
211
|
+
|
|
212
|
+
| Aspect | Convention |
|
|
213
|
+
| ------------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
214
|
+
| Constructor | `(request, context) => createMachine()` — initial data is **preloaded by the caller**, not fetched by the machine |
|
|
215
|
+
| loading phase | `always` transitions immediately, with no async request |
|
|
216
|
+
| Global events | `internal: false` (forces external transitions, ensuring entry/exit re-run) |
|
|
217
|
+
| Debounce | `debouncing` uses `after: { 1000 }` + `cond`, not a separate CALCULATE event |
|
|
214
218
|
|
|
215
|
-
|
|
216
|
-
| ------------- | ---------------------------------------- | ----------------------------------------------- |
|
|
217
|
-
| Constructor | `(request) => createMachine()` | `(request, context) => createMachine()` |
|
|
218
|
-
| Initial data | Fetched asynchronously (init → fetching) | Preloaded via the context parameter |
|
|
219
|
-
| loading phase | Two sub-states (init + fetching) | `always` jumps straight to checking |
|
|
220
|
-
| Global events | `internal: true` (default) | `internal: false` (forces external transitions) |
|
|
221
|
-
| Bank list | Re-fetched every time | `bankMap` cache (keyed by method) |
|
|
219
|
+
**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.
|
|
222
220
|
|
|
223
|
-
|
|
221
|
+
> ⚠️ **`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.
|
|
224
222
|
|
|
225
|
-
>
|
|
223
|
+
> ℹ️ `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.
|
|
226
224
|
|
|
227
|
-
**resultMap cache** (`
|
|
225
|
+
**resultMap cache** (`usdt_cash.js`): caches keyed by `selectedNetwork.value` to avoid re-fetching the same network address.
|
|
228
226
|
|
|
229
227
|
> ⚠️ **V2 API response format is inconsistent**: the same endpoint may return `{ data: {...} }` or just `{...}`, so every machine needs defensive handling:
|
|
230
228
|
>
|
|
@@ -235,26 +233,36 @@ loading (fetch siteConfig + bankList in parallel)
|
|
|
235
233
|
> })
|
|
236
234
|
> ```
|
|
237
235
|
|
|
238
|
-
**processing state check**: `
|
|
236
|
+
**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.
|
|
239
237
|
|
|
240
238
|
### 2.3 Withdrawal Flow & OTP
|
|
241
239
|
|
|
242
|
-
|
|
240
|
+
`src/machine/withdraw/` contains only one machine, `withdraw_manual_cash.js`. Main flow:
|
|
243
241
|
|
|
244
242
|
```
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
243
|
+
loading (fetchInitData: double-wallet rule gate + getBindingPaymentInfo + getPendingOrder)
|
|
244
|
+
→ checking (always: isProcessing → submitted, otherwise loaded)
|
|
245
|
+
→ loaded ──SET_AMOUNT──▶ debouncing (always: isSubmittable → calculated, otherwise back to loaded)
|
|
246
|
+
→ calculated → submitting / submitting_crypto
|
|
247
|
+
→ isOtpRequired → otp (parallel state)
|
|
248
|
+
→ otherwise → submitted
|
|
251
249
|
```
|
|
252
250
|
|
|
253
|
-
|
|
251
|
+
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.
|
|
252
|
+
|
|
253
|
+
**Double-wallet withdrawal rule gate** (`doubleWalletWithdrawLimitCheck` — the least intuitive part; the point is to save API calls):
|
|
254
|
+
|
|
255
|
+
| Value | Behavior |
|
|
256
|
+
| ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
257
|
+
| `'0'` | Fetch only the CASH `withdrawRule` |
|
|
258
|
+
| `'1'` | Fetch only the ACTIVITY `withdrawRule`; regardless of whether it qualifies, the CASH rule takes no part in the gate |
|
|
259
|
+
| `'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 |
|
|
260
|
+
|
|
261
|
+
`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`.
|
|
254
262
|
|
|
255
|
-
**
|
|
263
|
+
**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.
|
|
256
264
|
|
|
257
|
-
|
|
265
|
+
> ℹ️ `restore` in `api/payment.js` (bonus / free-credit redemption) currently has **no machine calling it**.
|
|
258
266
|
|
|
259
267
|
### 2.4 Game Management
|
|
260
268
|
|
|
@@ -270,11 +278,11 @@ loading (fetch siteConfig + bankList in parallel)
|
|
|
270
278
|
|
|
271
279
|
**receiveStatus enum**: `0` in progress / not yet eligible (→ `progress_status`), `1` claimed (→ `received`, terminal), `2` claimable (→ `receiveable`).
|
|
272
280
|
|
|
273
|
-
**Red-dot unread state
|
|
281
|
+
**Red-dot unread state** (`activity_cash.js`):
|
|
274
282
|
|
|
275
|
-
- `
|
|
276
|
-
- For other activities the read state is stored in localStorage under the key `unread_${activityNo}_${uidSite}`
|
|
283
|
+
- 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)
|
|
277
284
|
- Whenever `activityList` is updated, **clone the whole array** to avoid direct mutation
|
|
285
|
+
- The old `noRedActivity` type allowlist **no longer exists**; today every activity type is treated the same
|
|
278
286
|
|
|
279
287
|
**Activity polling**: base interval `tick * 10 = 20 seconds`; **polling pauses while in a game (`isPlaying === true`)**. Fetching promotions additionally requires `hasToken`.
|
|
280
288
|
|
|
@@ -306,10 +314,9 @@ io(`${socketURL}/frontend`, {
|
|
|
306
314
|
|
|
307
315
|
### 2.7 Configuration & Live Info (Common Machine)
|
|
308
316
|
|
|
309
|
-
**
|
|
317
|
+
**3 parallel sub-machines**: `config` (siteConfig + layoutConfig, event-triggered), `feed` (feeds + mailbox + promotions, 20-second polling), and `getAnnouncements` (event-triggered).
|
|
310
318
|
|
|
311
319
|
- **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.**
|
|
312
|
-
- **Broadcast rotation**: `picking` (5s) → `display` (5s) → `picking`, selecting `type === '0'` entries from `broadcastList`; already-shown items are added to `sentNormalBroadcastList` and not repeated
|
|
313
320
|
- **Mailbox filtering**: if `customerMessageEnable === false`, the count of CUSTOMER-type messages is deducted from the mailbox total
|
|
314
321
|
|
|
315
322
|
### 2.8 API Request Lifecycle
|
|
@@ -329,7 +336,7 @@ io(`${socketURL}/frontend`, {
|
|
|
329
336
|
7. Custom paramsSerializer: special encoding for the q parameter (avoids double-encoding)
|
|
330
337
|
8. axios.request(config)
|
|
331
338
|
9. Response interceptor: response.data.error present → reject; Network Error / 404 → ERR_998 + Sentry
|
|
332
|
-
10. Error handling: ERR_F108 → isBlocked
|
|
339
|
+
10. Error handling: ERR_F108 → isBlocked; ERR_800 (cancelled) → silent; everything else → errorHandler
|
|
333
340
|
```
|
|
334
341
|
|
|
335
342
|
**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.**
|
|
@@ -347,7 +354,6 @@ io(`${socketURL}/frontend`, {
|
|
|
347
354
|
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").
|
|
348
355
|
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`).
|
|
349
356
|
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.**
|
|
350
|
-
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.
|
|
351
357
|
|
|
352
358
|
---
|
|
353
359
|
|
|
@@ -355,19 +361,19 @@ io(`${socketURL}/frontend`, {
|
|
|
355
361
|
|
|
356
362
|
> 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).
|
|
357
363
|
|
|
358
|
-
| Item | Current state
|
|
359
|
-
| ------------------------- |
|
|
360
|
-
| HTTP method casing | `'GET'` and `'get'` coexist (`request.js` calls `toUpperCase()` internally, so behavior is unaffected)
|
|
361
|
-
| Import paths | Some files self-reference via the `@jetthai/cuora` package name
|
|
362
|
-
| lodash extension | `'lodash/pickBy.js'` and `'lodash/pickBy'` coexist
|
|
363
|
-
| URL leading slash | A few APIs carry a leading slash
|
|
364
|
-
| Query parameter placement | A few write them straight into the URL (`register?${qs}`, `mail?include=cl`), bypassing serialization
|
|
365
|
-
| Initial state naming | `idle` / `loading` / `fetching` / `
|
|
366
|
-
| Magic numbers and strings | Activity type IDs, error codes, TTLs, polling ticks, `'DEPOSIT'`/`'WITHDRAW'`, `receiveStatus`, `connectStatus` are scattered around | Centralize in `util/constant.js` (`ERROR_CODES` / `TTL` / `INTERVAL` / `TRANSFER_TYPE` / `RECEIVE_STATUS`) |
|
|
367
|
-
| Error handling | Three forms coexist: silent fallback to `idle` (most common, loses error info), transition to `fail`, infinite retry
|
|
368
|
-
| Parameter naming | e.g. `
|
|
369
|
-
| Parameter validation | The API layer has no validation at all (e.g. `
|
|
370
|
-
| Deprecated APIs |
|
|
364
|
+
| Item | Current state | Target |
|
|
365
|
+
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
366
|
+
| HTTP method casing | `'GET'` and `'get'` coexist (`request.js` calls `toUpperCase()` internally, so behavior is unaffected) | Consistently lowercase `'get'`/`'post'`/`'put'`/`'delete'` |
|
|
367
|
+
| Import paths | Some files self-reference via the `@jetthai/cuora` package name | Consistently relative paths (`'../../api/payment.js'`) |
|
|
368
|
+
| lodash extension | `'lodash/pickBy.js'` and `'lodash/pickBy'` coexist | Consistently **without** the extension |
|
|
369
|
+
| URL leading slash | A few APIs carry a leading slash | Omit it (unless deliberately bypassing `url-join`, in which case comment the reason) |
|
|
370
|
+
| Query parameter placement | A few write them straight into the URL (`register?${qs}`, `mail?include=cl`), bypassing serialization | Always use the `params` field |
|
|
371
|
+
| 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` |
|
|
372
|
+
| 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`) |
|
|
373
|
+
| 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 |
|
|
374
|
+
| Parameter naming | e.g. `getFreeGameReward(code)` is semantically unclear | Concrete names (`gameCode`) |
|
|
375
|
+
| 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 |
|
|
376
|
+
| Deprecated APIs | `getPaymentInfo` in `api/payment.js` carries a "deprecated" comment but still has callers | Add `@deprecated` first, then remove once confirmed unreferenced |
|
|
371
377
|
|
|
372
378
|
---
|
|
373
379
|
|
|
@@ -379,12 +385,11 @@ io(`${socketURL}/frontend`, {
|
|
|
379
385
|
- **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`.
|
|
380
386
|
- **No rate limiting or backoff** — polling runs at a fixed interval and does not change on errors. Consider exponential backoff on errors.
|
|
381
387
|
- **No automatic token refresh** — the response interceptor in `request.js` does not handle 401, so an expired token simply fails.
|
|
382
|
-
- **FingerprintJS bundling** — the FingerprintJS embedded in `src/lib/` is loaded at module initialization even when disabled. Consider switching to a dynamic `import()` for lazy loading.
|
|
383
388
|
- **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.
|
|
384
|
-
- **Timer management** — countdowns are largely implemented with self-referencing `after: { 1000 }` transitions, 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.
|
|
385
|
-
- **Large state machine files** — `game_v2_1.js
|
|
389
|
+
- **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.
|
|
390
|
+
- **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.
|
|
386
391
|
- **Unused context fields** — several state machines declare context fields that are never assigned or read.
|
|
387
|
-
- **lodash
|
|
392
|
+
- **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").
|
|
388
393
|
|
|
389
394
|
---
|
|
390
395
|
|
package/AI_PROMPT_SOURCE.md
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
每次交付程式碼異動前,請自行逐項確認:
|
|
52
52
|
|
|
53
53
|
- [ ] **符合現有規範**:四層架構分層清楚、XState v4 工廠模式(`export default function (request) { return createMachine(...) }`)、命名慣例、無 TypeScript
|
|
54
|
-
- [ ] **API 描述物件正確**:回傳 `{ url, method, params?, isPublic?, headers?, isFormData
|
|
54
|
+
- [ ] **API 描述物件正確**:回傳 `{ url, method, params?, isPublic?, headers?, isFormData? }` 結構;HTTP method 統一小寫;`isPublic: true` 端點需檢查是否需 `appSecret`;URL 不加前導斜線(除非刻意繞過 `url-join` 的 `baseURL`,且需註解原因)
|
|
55
55
|
- [ ] **V1→V2 路徑轉換**:新增 V2 端點需**手動**加入 `supportVersion2List`;含動態參數時用 `:param` 樣式;非標準路徑放 `specifyingPath` 映射表
|
|
56
56
|
- [ ] **狀態機規範**:context 修改一律用 `assign()` 不直接 mutate;深層物件用 `JSON.parse(JSON.stringify())` clone;初始狀態名稱依語意選用;`onError` 不要靜默轉 `idle` 而遺失錯誤資訊
|
|
57
57
|
- [ ] **記憶體安全**:XState callback service 註冊的 `setInterval` / `socket.on()` / `addEventListener` 等,**必須回傳清理函式**(如 `() => clientSocket.off(event, handler)`),避免重連時累積監聽器;Promise 內註冊的監聽器在 resolve / reject 後也要清理
|
|
@@ -97,7 +97,9 @@
|
|
|
97
97
|
| Request | `src/request/` | Token 注入、V1→V2 路徑轉換、維護模式偵測、自訂序列化、請求取消 |
|
|
98
98
|
| API | `src/api/` | 每個函式回傳**請求描述物件**(不發請求) |
|
|
99
99
|
| Machine | `src/machine/` | XState v4 狀態機,工廠模式接收 `request` |
|
|
100
|
-
| Util | `src/util/` | storage(含 `maxAge` TTL)、
|
|
100
|
+
| Util | `src/util/` | storage(含 `maxAge` TTL)、constant、err998SentryExtra |
|
|
101
|
+
|
|
102
|
+
> **deviceToken 不在本套件內**:`auth.js` / `user_sign_up.js` 取得裝置 Token 的方式是呼叫 `request.config.getDt?.()`——實作由下游前端在建立 `request` 時注入,本套件只負責呼叫。是否呼叫由 `siteConfig.dtVerify`(登入流程)或 `deviceTokenEnable` context(註冊流程)決定,未注入時 `?.()` 回傳 `undefined` 而不拋錯。
|
|
101
103
|
|
|
102
104
|
**API 描述物件結構**:
|
|
103
105
|
|
|
@@ -109,7 +111,6 @@
|
|
|
109
111
|
isPublic?: boolean, // true = 不需認證 Token
|
|
110
112
|
headers?: object, // 自訂 headers(如 reCAPTCHA)
|
|
111
113
|
isFormData?: boolean, // true = multipart/form-data
|
|
112
|
-
silent?: boolean, // true = 失敗時不轉發 errorHandler(仍會 throw)
|
|
113
114
|
}
|
|
114
115
|
```
|
|
115
116
|
|
|
@@ -177,52 +178,49 @@ Token 5min TTL → fetchUserInfo 成功 → extendToken 重設 TTL → 再次輪
|
|
|
177
178
|
|
|
178
179
|
**輪詢間隔**:基礎 `tick: 2000ms`,**遊戲中乘以 5**(變 10 秒),減少遊戲期間伺服器負擔。
|
|
179
180
|
|
|
180
|
-
**登入方式分流**(
|
|
181
|
+
**登入方式分流**(5 種;另有 `LOGIN_TOKEN` 走上述 Token 恢復路徑):
|
|
181
182
|
|
|
182
183
|
| 事件 | 方式 | 特殊處理 |
|
|
183
184
|
| ---------------- | ---------- | ------------------------------------------- |
|
|
184
185
|
| `LOGIN_ID` | 帳號密碼 | reCAPTCHA header |
|
|
185
186
|
| `LOGIN_PHONE` | 手機號碼 | reCAPTCHA header + 國碼 |
|
|
186
187
|
| `LOGIN_EMAIL` | Email | reCAPTCHA header |
|
|
187
|
-
| `LOGIN_LOCAL` | 本地帳號 | 額外存 `cuora_tempuser`(24h TTL) |
|
|
188
|
-
| `LOGIN_GUEST` | 訪客 | 無認證資料 |
|
|
189
|
-
| `LOGIN_APP` | OAuth App | provider + accessToken |
|
|
190
188
|
| `LOGIN_TELEGRAM` | Telegram | additionalUserInfo |
|
|
191
189
|
| `LOGIN_3PARTY` | 第三方跳轉 | **不切換狀態**,直接 `window.location.href` |
|
|
192
190
|
|
|
193
|
-
**OTP
|
|
191
|
+
**OTP/綁銀行流程**:登入成功後進入 `otpChecking`,等待 `OTP_VERIFIED` 或 `OTP_SKIP` 後進入 `bindBankChecking`,再等待 `BIND_BANK_DONE` 或 `BIND_BANK_SKIP` 才進入 `loginSuccess`(兩關都可送 `LOGOUT` 中止)。是否需要綁定由下游前端判斷,machine 只負責等待;**下游必須在 `bindBankChecking` 送出其中一個事件,否則會停在這一關**。`tokenAuthenticated` 路徑不經過這兩關。
|
|
194
192
|
|
|
195
193
|
**帳號持久化**:最後使用的登入帳號存 localStorage(31 天 TTL)供表單自動填入。**Token 過期不影響帳號記錄。**但 `fetchSiteConfig` 成功後的 `pruneRememberedAccounts` 會**比對 `siteConfig.loginMethods` 清掉已停用登入方式的殘留帳號**(`phone` 連同國碼一起刪)——拉設定這個看似唯讀的動作帶有刪 localStorage 的副作用,目的是避免後台關掉某種登入方式後,下游把舊值回填進已改型別的輸入框。`loginMethods` 整包缺失時不清除,以免誤刪全部。
|
|
196
194
|
|
|
197
195
|
### 2.2 存款流程模式(Canonical Deposit Pattern)
|
|
198
196
|
|
|
199
|
-
|
|
197
|
+
`src/machine/deposit/` 現存機器全為 cash 站專用(`*_cash.js`),**Non-Cash 版本已不在本套件內**。所有存款狀態機遵循統一核心流程,各支付方式有變體:
|
|
200
198
|
|
|
201
199
|
```
|
|
202
|
-
loading
|
|
203
|
-
→
|
|
204
|
-
→
|
|
205
|
-
→
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
→ submitting → submitted
|
|
200
|
+
loading(always + setInitData:從工廠 context 參數取出 paymentDetail 過濾出本類別支付方式)
|
|
201
|
+
→ checking(invoke 取得銀行/網路清單等次級資料)
|
|
202
|
+
→ debouncing(entry 清空 calculation,after 1000ms 防抖)
|
|
203
|
+
→ calculating(呼叫 getDepositExpectedResult)→ calculated(顯示計算結果)
|
|
204
|
+
→ loaded(不可計算時的停留狀態,等使用者補齊選項)
|
|
205
|
+
→ submitting → submitted
|
|
209
206
|
```
|
|
210
207
|
|
|
211
|
-
**Cash
|
|
208
|
+
**Cash machine 的共同結構特徵**(與一般狀態機不同、易踩之處):
|
|
209
|
+
|
|
210
|
+
| 面向 | 寫法 |
|
|
211
|
+
| ------------ | ------------------------------------------------------------------------------- |
|
|
212
|
+
| 建構子 | `(request, context) => createMachine()`——初始資料由**呼叫端預載入**,不自行抓取 |
|
|
213
|
+
| loading 階段 | `always` 立即跳轉,不做非同步請求 |
|
|
214
|
+
| 全域事件 | `internal: false`(強制外部轉換,確保 entry/exit 重跑) |
|
|
215
|
+
| 防抖 | `debouncing` 用 `after: { 1000 }` + `cond`,不是獨立的 CALCULATE 事件 |
|
|
212
216
|
|
|
213
|
-
|
|
214
|
-
| ------------ | ------------------------------ | --------------------------------------- |
|
|
215
|
-
| 建構子 | `(request) => createMachine()` | `(request, context) => createMachine()` |
|
|
216
|
-
| 初始資料 | 非同步取得(init → fetching) | context 參數預載入 |
|
|
217
|
-
| loading 階段 | 兩個子狀態(init + fetching) | `always` 直接跳至 checking |
|
|
218
|
-
| 全域事件 | `internal: true`(預設) | `internal: false`(強制外部轉換) |
|
|
219
|
-
| 銀行清單 | 每次重新取得 | `bankMap` 快取(依 method 為 key) |
|
|
217
|
+
**Promotion**:`SET_PROMOTION` 全域事件設定 promotion context,多數機器搭配 `isPromotionChanged` guard 避免同值重跑;`direct_cash.js` 另有 `bankMap` 依 method 為 key 快取銀行清單。
|
|
220
218
|
|
|
221
|
-
|
|
219
|
+
> ⚠️ **`promotionsNo` vs `activityNo`(易踩)**:**存款**流程的 promotion 一律用 `promotion?.promotionsNo`(7 台 deposit machine 與 `api/payment.js` 皆是);**活動系統**用的則是 `activityNo`。兩者是不同欄位,不可互換。
|
|
222
220
|
|
|
223
|
-
>
|
|
221
|
+
> ℹ️ `api/payment.js` 的 `getBonusPreview`(參數為 `promotionsNo`)目前**沒有任何 machine 呼叫**,`siteConfig.bonusPreviewEnable` 在本套件內也已無引用。要接回 bonus 預覽需自行接線。
|
|
224
222
|
|
|
225
|
-
**resultMap 快取**(`
|
|
223
|
+
**resultMap 快取**(`usdt_cash.js`):以 `selectedNetwork.value` 為 key 快取,避免重複取得同一網路地址。
|
|
226
224
|
|
|
227
225
|
> ⚠️ **V2 API 回應格式不一致**:同一端點可能回傳 `{ data: {...} }` 或直接 `{...}`,所有機器都需防禦性處理:
|
|
228
226
|
>
|
|
@@ -233,26 +231,36 @@ loading(平行取得 siteConfig + bankList)
|
|
|
233
231
|
> })
|
|
234
232
|
> ```
|
|
235
233
|
|
|
236
|
-
**processing 狀態檢查**:`
|
|
234
|
+
**processing 狀態檢查**:`manual_cash.js`、`virtual_bank_cash.js` 以 `isProcessing` guard 檢查是否有進行中的存款訂單,有則直接跳至 `submitted`,防止重複提交。
|
|
237
235
|
|
|
238
236
|
### 2.3 提款流程與 OTP
|
|
239
237
|
|
|
240
|
-
|
|
238
|
+
`src/machine/withdraw/` 只有 `withdraw_manual_cash.js` 一台。主流程:
|
|
241
239
|
|
|
242
240
|
```
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
241
|
+
loading(fetchInitData:雙錢包規則閘門 + getBindingPaymentInfo + getPendingOrder)
|
|
242
|
+
→ checking(always:isProcessing → submitted,否則 loaded)
|
|
243
|
+
→ loaded ──SET_AMOUNT──▶ debouncing(always:isSubmittable → calculated,否則回 loaded)
|
|
244
|
+
→ calculated → submitting / submitting_crypto
|
|
245
|
+
→ isOtpRequired → otp(平行狀態)
|
|
246
|
+
→ 否則 → submitted
|
|
249
247
|
```
|
|
250
248
|
|
|
251
|
-
|
|
249
|
+
只有 4 個 guard:`hasNoBank`(`REFRESH` 僅在無綁定帳戶時才重載)、`isProcessing`、`isSubmittable`(金額 > 0 且落在 `currentPayment.minimum`~`maximum`)、`isOtpRequired`。`userBanks` 是 `bankList` + `ewalletList` + `cryptoList` 三者攤平,預設選第一筆。
|
|
250
|
+
|
|
251
|
+
**雙錢包出款規則閘門**(`doubleWalletWithdrawLimitCheck`,最不直覺的一段,用意是省 API):
|
|
252
|
+
|
|
253
|
+
| 值 | 行為 |
|
|
254
|
+
| ----- | ------------------------------------------------------------------------------ |
|
|
255
|
+
| `'0'` | 只抓 CASH `withdrawRule` |
|
|
256
|
+
| `'1'` | 只抓 ACTIVITY `withdrawRule`,不論達標與否,CASH 規則都不參與閘門 |
|
|
257
|
+
| `'2'` | 先抓 ACTIVITY;**不可提**則直接採用它(略過 CASH),**達標**才續抓 CASH 為依據 |
|
|
258
|
+
|
|
259
|
+
`enableWithdraw` 刻意用 truthy 比較(`!activityRule?.enableWithdraw`)對齊 client-pwa-ssr,避免後端回傳 `1` 這類非布林 truthy 值時誤判。
|
|
252
260
|
|
|
253
|
-
|
|
261
|
+
**OTP 平行狀態**:`isOtpRequired` **只看回應是否含 `request_id`**(`number` / `email` 只用於顯示)。進入後 `countdown` 與 `verification` 兩個子狀態**平行運作**,倒數不阻塞驗證操作。`verification` 內 `idle` 可分岔到 `acknowledging`(成功 → 跳出 OTP 到頂層 `submitted`)或 `reset`(重發,成功 → 回 `idle` 並換新 `requestId`/`ttl`);`BACK` 事件直接回頂層 `calculated`。`ttl` 單位是**毫秒**,`decreaseTtl` 每秒 `Math.max(ttl - 1000, 0)`。
|
|
254
262
|
|
|
255
|
-
|
|
263
|
+
> ℹ️ `api/payment.js` 的 `restore`(獎金/免費額度兌換)目前**沒有任何 machine 呼叫**。
|
|
256
264
|
|
|
257
265
|
### 2.4 遊戲管理
|
|
258
266
|
|
|
@@ -268,11 +276,11 @@ loading(平行取得 siteConfig + bankList)
|
|
|
268
276
|
|
|
269
277
|
**receiveStatus 枚舉**:`0` 進行中/未達標(→ `progress_status`)、`1` 已領取(→ `received`,終態)、`2` 可領取(→ `receiveable`)。
|
|
270
278
|
|
|
271
|
-
|
|
279
|
+
**紅點未讀狀態**(`activity_cash.js`):
|
|
272
280
|
|
|
273
|
-
- `
|
|
274
|
-
- 其餘活動的已讀狀態以 `unread_${activityNo}_${uidSite}` 為 key 存 localStorage
|
|
281
|
+
- 已讀狀態以 `unread_${activityNo}_${uidSite}` 為 key 存 localStorage;**查無此 key 時預設 `unread = true`**(新活動一律亮紅點)
|
|
275
282
|
- 每次更新 `activityList` 時 **clone 整個陣列**避免直接修改
|
|
283
|
+
- 舊版的 `noRedActivity` 類型白名單**已不存在**,目前所有活動類型一視同仁
|
|
276
284
|
|
|
277
285
|
**活動輪詢**:基礎間隔 `tick * 10 = 20 秒`;**遊戲中(`isPlaying === true`)暫停輪詢**。Promotion 取得額外需 `hasToken`。
|
|
278
286
|
|
|
@@ -304,10 +312,9 @@ io(`${socketURL}/frontend`, {
|
|
|
304
312
|
|
|
305
313
|
### 2.7 設定與即時資訊(Common Machine)
|
|
306
314
|
|
|
307
|
-
**
|
|
315
|
+
**3 個平行子機器**:`config`(siteConfig + layoutConfig,事件觸發)、`feed`(feeds + 信箱 + promotions,20 秒輪詢)、`getAnnouncements`(事件觸發)。
|
|
308
316
|
|
|
309
317
|
- **siteConfig 解碼**:回應為編碼字串,`setConfig` action 中 base64 解碼才得到實際設定(`loginMethods`、`paymentMethods`、`csChat` 等)。**下游前端的 store 不再解碼一次。**
|
|
310
|
-
- **廣播輪播機制**:`picking`(5s)→ `display`(5s)→ `picking`,從 `broadcastList` 選 `type === '0'`,已顯示的加入 `sentNormalBroadcastList` 不再重複
|
|
311
318
|
- **信箱過濾**:若 `customerMessageEnable === false`,從信箱總數中扣除 CUSTOMER 類型訊息數
|
|
312
319
|
|
|
313
320
|
### 2.8 API 請求生命週期
|
|
@@ -327,7 +334,7 @@ io(`${socketURL}/frontend`, {
|
|
|
327
334
|
7. 自訂 paramsSerializer:q 參數特殊編碼(避免雙重編碼)
|
|
328
335
|
8. axios.request(config)
|
|
329
336
|
9. 回應攔截器:response.data.error 存在 → reject;Network Error / 404 → ERR_998 + Sentry
|
|
330
|
-
10. 錯誤處理:ERR_F108 → isBlocked
|
|
337
|
+
10. 錯誤處理:ERR_F108 → isBlocked;ERR_800(取消)→ 靜默;其餘 → errorHandler
|
|
331
338
|
```
|
|
332
339
|
|
|
333
340
|
**V1→V2 轉換**:`supportVersion2List` 支援動態路徑(如 `payment/v2/:paymentType/transaction`,`:param` 替換為 `[^/]+`);特殊路徑由 `specifyingPath` 硬編碼映射,其餘用 `/([a-z])([A-Z])/g` 自動轉換。**新增需要 V2 轉換的端點時必須手動加入清單。**
|
|
@@ -345,7 +352,6 @@ io(`${socketURL}/frontend`, {
|
|
|
345
352
|
9. **unfinished game 無限重試**:`error.js` 的 `unfinishedGame` 狀態在 `onError` 時回到自身,**無退避策略也無重試上限**(已知問題,見「已知技術債」)。
|
|
346
353
|
10. **`isMobile` 是字串非布林值**:`common.js` 中 `isMobile = userAgent?.device?.type`,回傳 `'mobile'`/`'tablet'`/`undefined`,判斷時需比較字串(如 `isMobile === 'mobile' ? 'y' : null`)。
|
|
347
354
|
11. **請求預設不附加 CancelToken**:`send(req, customToken)` 的取消功能為**選擇性啟用**。axios <0.22 的取消 handler 永不退訂——共用長壽命 token 會隨請求數累積 handler,導致掛機過夜 OOM(TI-15555)。**不要「順手」把 CancelToken 加回共用路徑。**
|
|
348
|
-
12. **`silent: true` 只略過 errorHandler**:錯誤仍會 throw 給呼叫端的 `onError`,`ERR_F108` 也照常路由;但其餘錯誤碼——**包含 `ERR_A104` 等登出類、`ERR_G106` 餘額不足**——都不會進 error machine。只用於背景呼叫、且 session 失效另有 `fetchUserInfo` 輪詢兜底的請求;使用者主動觸發的請求不可加。
|
|
349
355
|
|
|
350
356
|
---
|
|
351
357
|
|
|
@@ -353,19 +359,19 @@ io(`${socketURL}/frontend`, {
|
|
|
353
359
|
|
|
354
360
|
> 以下每一項在程式碼中都是**兩種寫法並存**——探索程式碼無法判斷哪個才是規範,因此必須明文記錄。新寫的程式碼一律採用「目標」欄;既有程式碼不主動大規模重構(範圍自律)。
|
|
355
361
|
|
|
356
|
-
| 項目 | 現況
|
|
357
|
-
| ------------------ |
|
|
358
|
-
| HTTP method 大小寫 | `'GET'` 與 `'get'` 並存(`request.js` 內部 `toUpperCase()`,功能不受影響)
|
|
359
|
-
| 匯入路徑 | 部分檔案用 `@jetthai/cuora` 套件名自我引用
|
|
360
|
-
| lodash 副檔名 | `'lodash/pickBy.js'` 與 `'lodash/pickBy'` 並存
|
|
361
|
-
| URL 前導斜線 | 少數 API 帶前導斜線
|
|
362
|
-
| 查詢參數位置 | 少數直接寫入 URL(`register?${qs}`、`mail?include=cl`),繞過序列化
|
|
363
|
-
| 初始狀態命名 | `idle` / `loading` / `fetching` / `
|
|
364
|
-
| 魔法數字與字串 | 活動類型 ID、錯誤碼、TTL、輪詢 tick、`'DEPOSIT'`/`'WITHDRAW'`、`receiveStatus`、`connectStatus`
|
|
365
|
-
| 錯誤處理 | 三種並存:靜默轉 `idle`(多數,錯誤資訊遺失)、轉 `fail`、無限重試
|
|
366
|
-
| 參數命名 | 如 `
|
|
367
|
-
| 參數驗證 | API 層無任何驗證(如 `
|
|
368
|
-
| 已棄用 API | `api/
|
|
362
|
+
| 項目 | 現況 | 目標 |
|
|
363
|
+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
|
|
364
|
+
| HTTP method 大小寫 | `'GET'` 與 `'get'` 並存(`request.js` 內部 `toUpperCase()`,功能不受影響) | 統一小寫 `'get'`/`'post'`/`'put'`/`'delete'` |
|
|
365
|
+
| 匯入路徑 | 部分檔案用 `@jetthai/cuora` 套件名自我引用 | 統一相對路徑(`'../../api/payment.js'`) |
|
|
366
|
+
| lodash 副檔名 | `'lodash/pickBy.js'` 與 `'lodash/pickBy'` 並存 | 統一**不帶**副檔名 |
|
|
367
|
+
| URL 前導斜線 | 少數 API 帶前導斜線 | 不加(除非刻意繞過 `url-join`,須註解原因) |
|
|
368
|
+
| 查詢參數位置 | 少數直接寫入 URL(`register?${qs}`、`mail?include=cl`),繞過序列化 | 一律用 `params` 欄位 |
|
|
369
|
+
| 初始狀態命名 | `idle`(27) / `loading`(13) / `fetching`(12) / `pending`(6) / `checking` / `init` 等混用 | 依語意:`idle`(等待操作)、`loading`(初始載入)、`fetching`(重新取得)、`submitting` / `submitted` |
|
|
370
|
+
| 魔法數字與字串 | 活動類型 ID、錯誤碼、TTL、輪詢 tick、`'DEPOSIT'`/`'WITHDRAW'`、`receiveStatus`、`connectStatus` 散佈各處;`util/constant.js` 目前**只有** `GAME_SEARCH` / `GAME_TYPE_LIST` 兩個遊戲分類常數 | 集中至 `util/constant.js`(`ERROR_CODES` / `TTL` / `INTERVAL` / `TRANSFER_TYPE` / `RECEIVE_STATUS`) |
|
|
371
|
+
| 錯誤處理 | 三種並存:靜默轉 `idle`(多數,錯誤資訊遺失)、轉 `fail`、無限重試 | `onError` 搭配 `actions: 'setError'` 保存錯誤至 context;區分可恢復 / 不可恢復;重試須設上限 |
|
|
372
|
+
| 參數命名 | 如 `getFreeGameReward(code)` 語意不明 | 具體命名(`gameCode`) |
|
|
373
|
+
| 參數驗證 | API 層無任何驗證(如 `checkDt()` 之後的動態路徑直接注入 URL) | 在系統邊界驗證:路徑參數非 undefined 且無路徑遍歷字元、金額為正數 |
|
|
374
|
+
| 已棄用 API | `api/payment.js` 的 `getPaymentInfo` 標了「棄用」註解但仍有呼叫端 | 先補 `@deprecated`,確認無引用後再移除 |
|
|
369
375
|
|
|
370
376
|
---
|
|
371
377
|
|
|
@@ -377,12 +383,11 @@ io(`${socketURL}/frontend`, {
|
|
|
377
383
|
- **無請求快取** — 高頻端點(`fetchUserInfo` 每 2–10 秒、`getConfig` 每次狀態機初始化、`getPaymentDetail` 每次進入存提款頁、`getActivityList` 每 20 秒)皆直打伺服器。可考慮 TTL 快取或 `stale-while-revalidate`。
|
|
378
384
|
- **無速率限制與退避** — 輪詢為固定間隔,錯誤時不變。可考慮錯誤時指數退避。
|
|
379
385
|
- **無 Token 自動刷新** — `request.js` 回應攔截器不處理 401,Token 過期即失敗。
|
|
380
|
-
- **FingerprintJS 打包** — `src/lib/` 內嵌的 FingerprintJS 即使停用也會在模組初始化載入。建議改動態 `import()` 懶載入。
|
|
381
386
|
- **無程式碼分割** — `machine/index.js` 即時匯入所有狀態機 + API + Socket.IO + lodash,匯入 `machine` 等於載入全部。建議支援個別匯入以啟用 tree-shaking。
|
|
382
|
-
- **計時器管理** — 大量以 `after: { 1000 }`
|
|
383
|
-
- **大型狀態機檔案** — `game_v2_1.js
|
|
387
|
+
- **計時器管理** — 大量以 `after: { 1000 }` 自我引用轉換做倒數(如 `withdraw_manual_cash.js` 的 OTP `countdown`),每秒一次狀態轉換(含 context clone + event dispatch)。建議改 callback service + `setInterval`,並**計算經過時間**而非逐次遞減以避免累積誤差。
|
|
388
|
+
- **大型狀態機檔案** — `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)、`crypto_bank_cash.js`(306) 皆超過 300 行,可拆為可組合的子狀態機。
|
|
384
389
|
- **未使用的 context 欄位** — 多個狀態機宣告了從未賦值或讀取的 context 欄位。
|
|
385
|
-
- **lodash
|
|
390
|
+
- **lodash 只為兩個函式而存在** — 全 repo 只有 5 處 import:`pickBy`(`request/request.js`、`api/auth.js`、`machine/auth.js`、`machine/common.js`)與 `isEqual`(`activity/fafafa_activity.js`),卻整包列為 dependency。兩者都可用原生實作替代以移除依賴;在那之前至少要先統一副檔名寫法(見「風格收斂目標」)。
|
|
386
391
|
|
|
387
392
|
---
|
|
388
393
|
|