@jetthai/cuora 1.1.476-dev.1 → 1.1.476
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 +1 -88
- package/.claude/settings.local.json +1 -3
- package/.github/copilot-instructions.md +58 -68
- package/.husky/post-checkout +3 -3
- package/.husky/pre-push +1 -1
- package/.prettierignore +1 -2
- package/AGENTS.md +59 -69
- package/AI_PROMPT_SOURCE.md +59 -69
- package/CHANGELOG.md +5 -273
- package/CLAUDE.md +59 -69
- package/GEMINI.md +59 -69
- package/README.md +12 -11
- package/package.json +1 -1
- package/scripts/auto-version.js +0 -1
- package/scripts/branch-auto-npm-publish.js +2 -9
- package/src/api/account.js +1 -0
- package/src/api/activity.js +37 -0
- package/src/api/auth.js +31 -0
- package/src/api/game.js +10 -0
- package/src/api/payment.js +52 -1
- package/src/api/user.js +16 -0
- package/src/index.js +2 -2
- package/src/machine/activity/activity.js +209 -0
- package/src/machine/activity/activity_cash.js +0 -1
- package/src/machine/activity/diamond_shop_activity_cash.js +1 -0
- package/src/machine/activity/diamond_shop_activity_fc.js +196 -0
- package/src/machine/activity/diamond_shop_activity_vn.js +178 -0
- package/src/machine/activity/fafafa_activity.js +10 -0
- package/src/machine/activity/index.js +12 -0
- package/src/machine/activity/invite_friends_activity.js +114 -0
- package/src/machine/activity/mini_game_activity.js +68 -0
- package/src/machine/activity/return_bonus_activity.js +153 -0
- package/src/machine/auth.js +59 -37
- package/src/machine/auth_otp_v2.js +177 -0
- package/src/machine/auth_otp_v3.js +19 -30
- package/src/machine/bank_binding_amb.js +146 -0
- package/src/machine/bonus.js +76 -0
- package/src/machine/common.js +55 -0
- package/src/machine/deposit/amb.js +93 -0
- package/src/machine/deposit/crypto_bank.js +330 -0
- package/src/machine/deposit/crypto_qrcode.js +148 -0
- package/src/machine/deposit/crypto_way.js +252 -0
- package/src/machine/deposit/deposit_fc.js +272 -0
- package/src/machine/deposit/direct.js +310 -0
- package/src/machine/deposit/float.js +375 -0
- package/src/machine/deposit/index.js +28 -0
- package/src/machine/deposit/krway.js +151 -0
- package/src/machine/deposit/loadcard_vn.js +351 -0
- package/src/machine/deposit/manual_cash.js +8 -0
- package/src/machine/deposit/manual_vn.js +458 -0
- package/src/machine/deposit/qrcode_v2.js +338 -0
- package/src/machine/deposit/usdt.js +144 -0
- package/src/machine/deposit/virtual_bank_vn.js +269 -0
- package/src/machine/deposit/vpay.js +368 -0
- package/src/machine/game_hot_new.js +79 -0
- package/src/machine/game_info.js +12 -1
- package/src/machine/game_replay.js +46 -0
- package/src/machine/game_search_v2.js +401 -0
- package/src/machine/game_v2_1.js +89 -1
- package/src/machine/honor_board.js +132 -0
- package/src/machine/honor_board_cash.js +18 -15
- package/src/machine/inbox.js +12 -0
- package/src/machine/index.js +32 -0
- package/src/machine/merge.js +57 -0
- package/src/machine/payment_data.js +86 -0
- package/src/machine/promotions.js +170 -0
- package/src/machine/reward.js +255 -0
- package/src/machine/reward_cash.js +39 -0
- package/src/machine/reward_fc.js +98 -0
- package/src/machine/side.js +154 -0
- package/src/machine/side_v2.js +211 -0
- package/src/machine/user_reset_password.js +13 -0
- package/src/machine/user_sign_up.js +0 -3
- package/src/machine/vip_table.js +57 -0
- package/src/machine/websocket.js +4 -0
- package/src/machine/welcome.js +110 -0
- package/src/machine/withdraw/index.js +6 -0
- package/src/machine/withdraw/withdraw_crypto_cash.js +327 -0
- package/src/machine/withdraw/withdraw_krway.js +223 -0
- package/src/machine/withdraw/withdraw_manual.js +536 -0
- package/src/request/request.js +28 -0
- package/src/util/constant.js +1 -0
- package/src/util/index.js +4 -1
- package/src/util/math.js +4 -0
- package/test/auth_otp_v3.test.js +0 -192
package/AGENTS.md
CHANGED
|
@@ -55,7 +55,7 @@ Before delivering any code change, verify each of the following yourself:
|
|
|
55
55
|
- [ ] **Follows existing conventions**: clear four-layer separation, XState v4 factory pattern (`export default function (request) { return createMachine(...) }`), naming conventions, no TypeScript
|
|
56
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
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
|
|
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
|
|
60
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
61
|
- [ ] **Error handling**: forward through `request.errorHandler` to the error machine, with correct branches for each special code (see "Error Code System")
|
|
@@ -99,9 +99,7 @@ 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), constant,
|
|
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.
|
|
102
|
+
| Util | `src/util/` | storage (with `maxAge` TTL), deviceToken, constant, math |
|
|
105
103
|
|
|
106
104
|
**API descriptor object structure**:
|
|
107
105
|
|
|
@@ -181,49 +179,52 @@ Token 5min TTL → fetchUserInfo success → extendToken resets TTL → poll aga
|
|
|
181
179
|
|
|
182
180
|
**Polling interval**: base `tick: 2000ms`, **multiplied by 5 while in a game** (becoming 10 seconds) to reduce server load during play.
|
|
183
181
|
|
|
184
|
-
**Login method routing** (
|
|
182
|
+
**Login method routing** (7 kinds):
|
|
185
183
|
|
|
186
184
|
| Event | Method | Special Handling |
|
|
187
185
|
| ---------------- | -------------------- | --------------------------------------------------------------- |
|
|
188
186
|
| `LOGIN_ID` | Account + password | reCAPTCHA header |
|
|
189
187
|
| `LOGIN_PHONE` | Phone number | reCAPTCHA header + country code |
|
|
190
188
|
| `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 |
|
|
191
192
|
| `LOGIN_TELEGRAM` | Telegram | additionalUserInfo |
|
|
192
193
|
| `LOGIN_3PARTY` | Third-party redirect | **Does not switch state**; uses `window.location.href` directly |
|
|
193
194
|
|
|
194
|
-
**OTP
|
|
195
|
+
**OTP flow**: after a successful login it enters `otpChecking`, and only proceeds to `loginSuccess` after an `OTP_VERIFIED` or `OTP_SKIP` event.
|
|
195
196
|
|
|
196
197
|
**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
|
|
|
198
199
|
### 2.2 Canonical Deposit Pattern
|
|
199
200
|
|
|
200
|
-
|
|
201
|
+
All deposit state machines follow a unified core flow, with variants per payment method:
|
|
201
202
|
|
|
202
203
|
```
|
|
203
|
-
loading (
|
|
204
|
-
→
|
|
205
|
-
→
|
|
206
|
-
→
|
|
207
|
-
|
|
208
|
-
|
|
204
|
+
loading (fetch siteConfig + bankList in parallel)
|
|
205
|
+
→ promotion (routing: has a minimum deposit → calculating, none → loaded)
|
|
206
|
+
→ loaded (user selects bank/amount)
|
|
207
|
+
→ debouncing (CALCULATE event, 1000ms debounce)
|
|
208
|
+
→ calculating (calls getDepositExpectedResult)
|
|
209
|
+
→ loaded/calculated (show the calculation result)
|
|
210
|
+
→ submitting → submitted
|
|
209
211
|
```
|
|
210
212
|
|
|
211
|
-
**
|
|
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 |
|
|
213
|
+
**Cash vs Non-Cash variants**:
|
|
219
214
|
|
|
220
|
-
|
|
215
|
+
| Aspect | Non-Cash (e.g. `direct.js`) | Cash (e.g. `direct_cash.js`) |
|
|
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) |
|
|
221
222
|
|
|
222
|
-
|
|
223
|
+
**Promotion & Bonus preview**: the `SET_PROMOTION` global event sets the promotion context; if `siteConfig.bonusPreviewEnable === true` and `promotion.activityNo !== 'none'`, `getBonusPreview` is additionally called.
|
|
223
224
|
|
|
224
|
-
>
|
|
225
|
+
> ⚠️ **Naming inconsistency (easy to trip on)**: Non-Cash uses `promotion?.activityNo`, Cash uses `promotion?.promotionsNo`.
|
|
225
226
|
|
|
226
|
-
**resultMap cache** (`usdt_cash.js`): caches keyed by `selectedNetwork.value` to avoid re-fetching the same network address.
|
|
227
|
+
**resultMap cache** (`usdt.js`, `usdt_cash.js`): caches keyed by `selectedNetwork.value` to avoid re-fetching the same network address.
|
|
227
228
|
|
|
228
229
|
> ⚠️ **V2 API response format is inconsistent**: the same endpoint may return `{ data: {...} }` or just `{...}`, so every machine needs defensive handling:
|
|
229
230
|
>
|
|
@@ -233,39 +234,27 @@ loading (always + setInitData: takes paymentDetail from the factory context para
|
|
|
233
234
|
> return { calculation: data || event.data }
|
|
234
235
|
> })
|
|
235
236
|
> ```
|
|
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
237
|
|
|
239
|
-
**processing state check**: `
|
|
238
|
+
**processing state check**: `crypto_bank.js` and `manual_cash.js` check at initialization whether there is an in-progress deposit order, and if so jump straight to `submitted` to prevent duplicate submission.
|
|
240
239
|
|
|
241
240
|
### 2.3 Withdrawal Flow & OTP
|
|
242
241
|
|
|
243
|
-
|
|
242
|
+
**Five-step eligibility validation chain** (`withdraw_manual.js`); failing any step transitions to the corresponding blocking state:
|
|
244
243
|
|
|
245
244
|
```
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
245
|
+
1. haveProcessing → is there a withdrawal in progress? (yes → inProcessing)
|
|
246
|
+
2. isBankNotBound → is a bank account bound? (no → unbound)
|
|
247
|
+
3. isNotWithdrawMinDepositAmount → is the minimum deposit threshold met?
|
|
248
|
+
4. isPassWithdrawCooldownTime → still within the cooldown?
|
|
249
|
+
5. isNotWIthdrawServiceTime → within the service window?
|
|
250
|
+
All passed → withdrawable
|
|
252
251
|
```
|
|
253
252
|
|
|
254
|
-
|
|
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`.
|
|
253
|
+
**OTP parallel states**: after a withdrawal is submitted, if the response contains `request_id` plus `number`/`email`, it enters OTP verification. `countdown` (decrementing the TTL each second) and `verification` (`idle → acknowledging → submitted`) run **in parallel**, so the countdown does not block verification actions.
|
|
265
254
|
|
|
266
|
-
**
|
|
255
|
+
**Withdrawal rules system**: the `withdrawRules` array is matched against the balance, using `findLastIndex` to find the **last** matching rule (the highest amount tier), which determines `maxWithdrawAmount`.
|
|
267
256
|
|
|
268
|
-
|
|
257
|
+
**Attachment types**: `withdraw` (normal withdrawal) vs `pool` (bonus / free-credit redemption, which calls the `restore` API).
|
|
269
258
|
|
|
270
259
|
### 2.4 Game Management
|
|
271
260
|
|
|
@@ -281,11 +270,11 @@ There are only 4 guards: `hasNoBank` (`REFRESH` only reloads when no account is
|
|
|
281
270
|
|
|
282
271
|
**receiveStatus enum**: `0` in progress / not yet eligible (→ `progress_status`), `1` claimed (→ `received`, terminal), `2` claimable (→ `receiveable`).
|
|
283
272
|
|
|
284
|
-
**Red-dot unread state
|
|
273
|
+
**Red-dot unread state**:
|
|
285
274
|
|
|
286
|
-
-
|
|
275
|
+
- `noRedActivity = [2, 4, 13, 20, 90, 91, 92]` — these activity types **never show a red dot**
|
|
276
|
+
- For other activities the read state is stored in localStorage under the key `unread_${activityNo}_${uidSite}`
|
|
287
277
|
- 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
278
|
|
|
290
279
|
**Activity polling**: base interval `tick * 10 = 20 seconds`; **polling pauses while in a game (`isPlaying === true`)**. Fetching promotions additionally requires `hasToken`.
|
|
291
280
|
|
|
@@ -317,9 +306,10 @@ io(`${socketURL}/frontend`, {
|
|
|
317
306
|
|
|
318
307
|
### 2.7 Configuration & Live Info (Common Machine)
|
|
319
308
|
|
|
320
|
-
**
|
|
309
|
+
**4 parallel sub-machines**: `config` (siteConfig + layoutConfig, event-triggered), `feed` (feeds + mailbox + promotions, 20-second polling), `getAnnouncements` (event-triggered), and `broadcast` (switching every 5 seconds).
|
|
321
310
|
|
|
322
311
|
- **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
|
|
323
313
|
- **Mailbox filtering**: if `customerMessageEnable === false`, the count of CUSTOMER-type messages is deducted from the mailbox total
|
|
324
314
|
|
|
325
315
|
### 2.8 API Request Lifecycle
|
|
@@ -358,7 +348,6 @@ io(`${socketURL}/frontend`, {
|
|
|
358
348
|
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
349
|
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
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.
|
|
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
351
|
|
|
363
352
|
---
|
|
364
353
|
|
|
@@ -366,19 +355,19 @@ io(`${socketURL}/frontend`, {
|
|
|
366
355
|
|
|
367
356
|
> 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
357
|
|
|
369
|
-
| Item | Current state
|
|
370
|
-
| ------------------------- |
|
|
371
|
-
| HTTP method casing | `'GET'` and `'get'` coexist (`request.js` calls `toUpperCase()` internally, so behavior is unaffected)
|
|
372
|
-
| Import paths | Some files self-reference via the `@jetthai/cuora` package name
|
|
373
|
-
| lodash extension | `'lodash/pickBy.js'` and `'lodash/pickBy'` coexist
|
|
374
|
-
| URL leading slash | A few APIs carry a leading slash
|
|
375
|
-
| Query parameter placement | A few write them straight into the URL (`register?${qs}`, `mail?include=cl`), bypassing serialization
|
|
376
|
-
| Initial state naming | `idle`
|
|
377
|
-
| Magic numbers and strings | Activity type IDs, error codes, TTLs, polling ticks, `'DEPOSIT'`/`'WITHDRAW'`, `receiveStatus`, `connectStatus` are scattered around
|
|
378
|
-
| Error handling | Three forms coexist: silent fallback to `idle` (most common, loses error info), transition to `fail`, infinite retry
|
|
379
|
-
| Parameter naming | e.g. `
|
|
380
|
-
| Parameter validation | The API layer has no validation at all (e.g.
|
|
381
|
-
| Deprecated APIs |
|
|
358
|
+
| Item | Current state | Target |
|
|
359
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
360
|
+
| HTTP method casing | `'GET'` and `'get'` coexist (`request.js` calls `toUpperCase()` internally, so behavior is unaffected) | Consistently lowercase `'get'`/`'post'`/`'put'`/`'delete'` |
|
|
361
|
+
| Import paths | Some files self-reference via the `@jetthai/cuora` package name | Consistently relative paths (`'../../api/payment.js'`) |
|
|
362
|
+
| lodash extension | `'lodash/pickBy.js'` and `'lodash/pickBy'` coexist | Consistently **without** the extension |
|
|
363
|
+
| URL leading slash | A few APIs carry a leading slash | Omit it (unless deliberately bypassing `url-join`, in which case comment the reason) |
|
|
364
|
+
| Query parameter placement | A few write them straight into the URL (`register?${qs}`, `mail?include=cl`), bypassing serialization | Always use the `params` field |
|
|
365
|
+
| Initial state naming | `idle` / `loading` / `fetching` / `init` / `preparing` are used interchangeably | By semantics: `idle` (awaiting action), `loading` (initial load), `fetching` (re-fetch), `submitting` / `submitted` |
|
|
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 | `onError` with `actions: 'setError'` to preserve the error in context; distinguish recoverable from unrecoverable; retries must have a cap |
|
|
368
|
+
| Parameter naming | e.g. `addFavoriteGame(code)` is semantically unclear | Concrete names (`gameCode`) |
|
|
369
|
+
| Parameter validation | The API layer has no validation at all (e.g. `makeTransaction({ paymentMethod })` injects straight into the URL) | Validate at the system boundary: path parameters non-undefined and free of path-traversal characters, amounts positive |
|
|
370
|
+
| Deprecated APIs | In `api/user.js`, V1 `passwordRecovery` coexists with the V2 `passwordV2*` family, with V1 unmarked | Add `@deprecated` first, then remove once confirmed unreferenced |
|
|
382
371
|
|
|
383
372
|
---
|
|
384
373
|
|
|
@@ -390,11 +379,12 @@ io(`${socketURL}/frontend`, {
|
|
|
390
379
|
- **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
380
|
- **No rate limiting or backoff** — polling runs at a fixed interval and does not change on errors. Consider exponential backoff on errors.
|
|
392
381
|
- **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.
|
|
393
383
|
- **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
|
|
395
|
-
- **Large state machine files** — `game_v2_1.js
|
|
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`, `auth.js`, `withdraw_manual.js`, `inbox.js`, `manual_vn.js`, `common.js`, and `game_search_v2.js` all exceed 300 lines and could be split into composable sub-machines.
|
|
396
386
|
- **Unused context fields** — several state machines declare context fields that are never assigned or read.
|
|
397
|
-
- **lodash
|
|
387
|
+
- **lodash can be replaced with natives** — only a handful of functions are actually used; `padStart` / `toNumber` can be swapped for natives directly, and `findLastIndex` is supported in modern browsers.
|
|
398
388
|
|
|
399
389
|
---
|
|
400
390
|
|
package/AI_PROMPT_SOURCE.md
CHANGED
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
- [ ] **符合現有規範**:四層架構分層清楚、XState v4 工廠模式(`export default function (request) { return createMachine(...) }`)、命名慣例、無 TypeScript
|
|
54
54
|
- [ ] **API 描述物件正確**:回傳 `{ url, method, params?, isPublic?, headers?, isFormData?, silent? }` 結構;HTTP method 統一小寫;`isPublic: true` 端點需檢查是否需 `appSecret`;URL 不加前導斜線(除非刻意繞過 `url-join` 的 `baseURL`,且需註解原因)
|
|
55
55
|
- [ ] **V1→V2 路徑轉換**:新增 V2 端點需**手動**加入 `supportVersion2List`;含動態參數時用 `:param` 樣式;非標準路徑放 `specifyingPath` 映射表
|
|
56
|
-
- [ ] **狀態機規範**:context 修改一律用 `assign()` 不直接 mutate;深層物件用 `JSON.parse(JSON.stringify())` clone;初始狀態名稱依語意選用;`onError` 不要靜默轉 `idle`
|
|
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 後也要清理
|
|
58
58
|
- [ ] **Token 生命週期**:Token 操作走 `getToken()` 與 `extendToken` action,不繞過攔截器自行注入;TTL 常數優先用既有定義;`fetchUserInfo` 失敗時讓 session 自然終止,不自行重試
|
|
59
59
|
- [ ] **錯誤處理**:透過 `request.errorHandler` 轉發至 error machine,各特殊碼有正確分支(見「錯誤代碼系統」)
|
|
@@ -97,9 +97,7 @@
|
|
|
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)、constant、
|
|
101
|
-
|
|
102
|
-
> **deviceToken 不在本套件內**:`auth.js` / `user_sign_up.js` 取得裝置 Token 的方式是呼叫 `request.config.getDt?.()`——實作由下游前端在建立 `request` 時注入,本套件只負責呼叫。是否呼叫由 `siteConfig.dtVerify`(登入流程)或 `deviceTokenEnable` context(註冊流程)決定,未注入時 `?.()` 回傳 `undefined` 而不拋錯。
|
|
100
|
+
| Util | `src/util/` | storage(含 `maxAge` TTL)、deviceToken、constant、math |
|
|
103
101
|
|
|
104
102
|
**API 描述物件結構**:
|
|
105
103
|
|
|
@@ -179,49 +177,52 @@ Token 5min TTL → fetchUserInfo 成功 → extendToken 重設 TTL → 再次輪
|
|
|
179
177
|
|
|
180
178
|
**輪詢間隔**:基礎 `tick: 2000ms`,**遊戲中乘以 5**(變 10 秒),減少遊戲期間伺服器負擔。
|
|
181
179
|
|
|
182
|
-
**登入方式分流**(
|
|
180
|
+
**登入方式分流**(7 種):
|
|
183
181
|
|
|
184
182
|
| 事件 | 方式 | 特殊處理 |
|
|
185
183
|
| ---------------- | ---------- | ------------------------------------------- |
|
|
186
184
|
| `LOGIN_ID` | 帳號密碼 | reCAPTCHA header |
|
|
187
185
|
| `LOGIN_PHONE` | 手機號碼 | reCAPTCHA header + 國碼 |
|
|
188
186
|
| `LOGIN_EMAIL` | Email | reCAPTCHA header |
|
|
187
|
+
| `LOGIN_LOCAL` | 本地帳號 | 額外存 `cuora_tempuser`(24h TTL) |
|
|
188
|
+
| `LOGIN_GUEST` | 訪客 | 無認證資料 |
|
|
189
|
+
| `LOGIN_APP` | OAuth App | provider + accessToken |
|
|
189
190
|
| `LOGIN_TELEGRAM` | Telegram | additionalUserInfo |
|
|
190
191
|
| `LOGIN_3PARTY` | 第三方跳轉 | **不切換狀態**,直接 `window.location.href` |
|
|
191
192
|
|
|
192
|
-
**OTP
|
|
193
|
+
**OTP 流程**:登入成功後進入 `otpChecking`,等待 `OTP_VERIFIED` 或 `OTP_SKIP` 事件才進入 `loginSuccess`。
|
|
193
194
|
|
|
194
195
|
**帳號持久化**:最後使用的登入帳號存 localStorage(31 天 TTL)供表單自動填入。**Token 過期不影響帳號記錄。**但 `fetchSiteConfig` 成功後的 `pruneRememberedAccounts` 會**比對 `siteConfig.loginMethods` 清掉已停用登入方式的殘留帳號**(`phone` 連同國碼一起刪)——拉設定這個看似唯讀的動作帶有刪 localStorage 的副作用,目的是避免後台關掉某種登入方式後,下游把舊值回填進已改型別的輸入框。`loginMethods` 整包缺失時不清除,以免誤刪全部。
|
|
195
196
|
|
|
196
197
|
### 2.2 存款流程模式(Canonical Deposit Pattern)
|
|
197
198
|
|
|
198
|
-
|
|
199
|
+
所有存款狀態機遵循統一核心流程,各支付方式有變體:
|
|
199
200
|
|
|
200
201
|
```
|
|
201
|
-
loading
|
|
202
|
-
→
|
|
203
|
-
→
|
|
204
|
-
→
|
|
205
|
-
|
|
206
|
-
|
|
202
|
+
loading(平行取得 siteConfig + bankList)
|
|
203
|
+
→ promotion(路由:有最低存款額 → calculating,無 → loaded)
|
|
204
|
+
→ loaded(使用者選擇銀行/金額)
|
|
205
|
+
→ debouncing(CALCULATE 事件,1000ms 防抖)
|
|
206
|
+
→ calculating(呼叫 getDepositExpectedResult)
|
|
207
|
+
→ loaded/calculated(顯示計算結果)
|
|
208
|
+
→ submitting → submitted
|
|
207
209
|
```
|
|
208
210
|
|
|
209
|
-
**Cash
|
|
210
|
-
|
|
211
|
-
| 面向 | 寫法 |
|
|
212
|
-
| ------------ | ------------------------------------------------------------------------------- |
|
|
213
|
-
| 建構子 | `(request, context) => createMachine()`——初始資料由**呼叫端預載入**,不自行抓取 |
|
|
214
|
-
| loading 階段 | `always` 立即跳轉,不做非同步請求 |
|
|
215
|
-
| 全域事件 | `internal: false`(強制外部轉換,確保 entry/exit 重跑) |
|
|
216
|
-
| 防抖 | `debouncing` 用 `after: { 1000 }` + `cond`,不是獨立的 CALCULATE 事件 |
|
|
211
|
+
**Cash vs Non-Cash 變體**:
|
|
217
212
|
|
|
218
|
-
|
|
213
|
+
| 面向 | Non-Cash(如 `direct.js`) | Cash(如 `direct_cash.js`) |
|
|
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) |
|
|
219
220
|
|
|
220
|
-
|
|
221
|
+
**Promotion & Bonus 預覽**:`SET_PROMOTION` 全域事件設定 promotion context;若 `siteConfig.bonusPreviewEnable === true` 且 `promotion.activityNo !== 'none'`,額外呼叫 `getBonusPreview`。
|
|
221
222
|
|
|
222
|
-
>
|
|
223
|
+
> ⚠️ **命名不一致(易踩)**:Non-Cash 用 `promotion?.activityNo`,Cash 用 `promotion?.promotionsNo`。
|
|
223
224
|
|
|
224
|
-
**resultMap 快取**(`usdt_cash.js`):以 `selectedNetwork.value` 為 key 快取,避免重複取得同一網路地址。
|
|
225
|
+
**resultMap 快取**(`usdt.js`、`usdt_cash.js`):以 `selectedNetwork.value` 為 key 快取,避免重複取得同一網路地址。
|
|
225
226
|
|
|
226
227
|
> ⚠️ **V2 API 回應格式不一致**:同一端點可能回傳 `{ data: {...} }` 或直接 `{...}`,所有機器都需防禦性處理:
|
|
227
228
|
>
|
|
@@ -231,39 +232,27 @@ loading(always + setInitData:從工廠 context 參數取出 paymentDetail
|
|
|
231
232
|
> return { calculation: data || event.data }
|
|
232
233
|
> })
|
|
233
234
|
> ```
|
|
234
|
-
>
|
|
235
|
-
> 此寫法假設 `event.data` 必為物件;`send()` 可能 resolve `undefined`,在 assign 內解構會拋錯卡死 machine(見 2.9 第 13 點)。
|
|
236
235
|
|
|
237
|
-
**processing 狀態檢查**:`
|
|
236
|
+
**processing 狀態檢查**:`crypto_bank.js`、`manual_cash.js` 初始化時檢查是否有進行中的存款訂單,有則直接跳至 `submitted`,防止重複提交。
|
|
238
237
|
|
|
239
238
|
### 2.3 提款流程與 OTP
|
|
240
239
|
|
|
241
|
-
|
|
240
|
+
**五步驟資格驗證鏈**(`withdraw_manual.js`),任一不過就轉到對應的擋下狀態:
|
|
242
241
|
|
|
243
242
|
```
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
243
|
+
1. haveProcessing → 有進行中的提款?(有 → inProcessing)
|
|
244
|
+
2. isBankNotBound → 已綁定銀行帳戶?(否 → unbound)
|
|
245
|
+
3. isNotWithdrawMinDepositAmount → 達到最低存款門檻?
|
|
246
|
+
4. isPassWithdrawCooldownTime → 在冷卻期?
|
|
247
|
+
5. isNotWIthdrawServiceTime → 在服務時間內?
|
|
248
|
+
全部通過 → withdrawable
|
|
250
249
|
```
|
|
251
250
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
**雙錢包出款規則閘門**(`doubleWalletWithdrawLimitCheck`,最不直覺的一段,用意是省 API):
|
|
255
|
-
|
|
256
|
-
| 值 | 行為 |
|
|
257
|
-
| ----- | ------------------------------------------------------------------------------ |
|
|
258
|
-
| `'0'` | 只抓 CASH `withdrawRule` |
|
|
259
|
-
| `'1'` | 只抓 ACTIVITY `withdrawRule`,不論達標與否,CASH 規則都不參與閘門 |
|
|
260
|
-
| `'2'` | 先抓 ACTIVITY;**不可提**則直接採用它(略過 CASH),**達標**才續抓 CASH 為依據 |
|
|
261
|
-
|
|
262
|
-
`enableWithdraw` 刻意用 truthy 比較(`!activityRule?.enableWithdraw`)對齊 client-pwa-ssr,避免後端回傳 `1` 這類非布林 truthy 值時誤判。
|
|
251
|
+
**OTP 平行狀態**:提款提交後若回應含 `request_id` 及 `number`/`email`,進入 OTP 驗證。`countdown`(每秒遞減 TTL)與 `verification`(`idle → acknowledging → submitted`)**平行運作**,倒數不阻塞驗證操作。
|
|
263
252
|
|
|
264
|
-
|
|
253
|
+
**提款規則系統**:`withdrawRules` 陣列依餘額匹配,用 `findLastIndex` 找**最後一個**符合條件的規則(最高金額級距)決定 `maxWithdrawAmount`。
|
|
265
254
|
|
|
266
|
-
|
|
255
|
+
**附件類型**:`withdraw`(正常提款)vs `pool`(獎金/免費額度兌換,呼叫 `restore` API)。
|
|
267
256
|
|
|
268
257
|
### 2.4 遊戲管理
|
|
269
258
|
|
|
@@ -279,11 +268,11 @@ loading(fetchInitData:雙錢包規則閘門 + getBindingPaymentInfo + getPen
|
|
|
279
268
|
|
|
280
269
|
**receiveStatus 枚舉**:`0` 進行中/未達標(→ `progress_status`)、`1` 已領取(→ `received`,終態)、`2` 可領取(→ `receiveable`)。
|
|
281
270
|
|
|
282
|
-
|
|
271
|
+
**紅點未讀狀態**:
|
|
283
272
|
|
|
284
|
-
-
|
|
273
|
+
- `noRedActivity = [2, 4, 13, 20, 90, 91, 92]` — 這些活動類型**永不顯示紅點**
|
|
274
|
+
- 其餘活動的已讀狀態以 `unread_${activityNo}_${uidSite}` 為 key 存 localStorage
|
|
285
275
|
- 每次更新 `activityList` 時 **clone 整個陣列**避免直接修改
|
|
286
|
-
- 舊版的 `noRedActivity` 類型白名單**已不存在**,目前所有活動類型一視同仁
|
|
287
276
|
|
|
288
277
|
**活動輪詢**:基礎間隔 `tick * 10 = 20 秒`;**遊戲中(`isPlaying === true`)暫停輪詢**。Promotion 取得額外需 `hasToken`。
|
|
289
278
|
|
|
@@ -315,9 +304,10 @@ io(`${socketURL}/frontend`, {
|
|
|
315
304
|
|
|
316
305
|
### 2.7 設定與即時資訊(Common Machine)
|
|
317
306
|
|
|
318
|
-
**
|
|
307
|
+
**4 個平行子機器**:`config`(siteConfig + layoutConfig,事件觸發)、`feed`(feeds + 信箱 + promotions,20 秒輪詢)、`getAnnouncements`(事件觸發)、`broadcast`(5 秒切換一則)。
|
|
319
308
|
|
|
320
309
|
- **siteConfig 解碼**:回應為編碼字串,`setConfig` action 中 base64 解碼才得到實際設定(`loginMethods`、`paymentMethods`、`csChat` 等)。**下游前端的 store 不再解碼一次。**
|
|
310
|
+
- **廣播輪播機制**:`picking`(5s)→ `display`(5s)→ `picking`,從 `broadcastList` 選 `type === '0'`,已顯示的加入 `sentNormalBroadcastList` 不再重複
|
|
321
311
|
- **信箱過濾**:若 `customerMessageEnable === false`,從信箱總數中扣除 CUSTOMER 類型訊息數
|
|
322
312
|
|
|
323
313
|
### 2.8 API 請求生命週期
|
|
@@ -356,7 +346,6 @@ io(`${socketURL}/frontend`, {
|
|
|
356
346
|
10. **`isMobile` 是字串非布林值**:`common.js` 中 `isMobile = userAgent?.device?.type`,回傳 `'mobile'`/`'tablet'`/`undefined`,判斷時需比較字串(如 `isMobile === 'mobile' ? 'y' : null`)。
|
|
357
347
|
11. **請求預設不附加 CancelToken**:`send(req, customToken)` 的取消功能為**選擇性啟用**。axios <0.22 的取消 handler 永不退訂——共用長壽命 token 會隨請求數累積 handler,導致掛機過夜 OOM(TI-15555)。**不要「順手」把 CancelToken 加回共用路徑。**
|
|
358
348
|
12. **`silent: true` 只略過 errorHandler**:錯誤仍會 throw 給呼叫端的 `onError`,`ERR_F108` 也照常路由;但其餘錯誤碼——**包含 `ERR_A104` 等登出類、`ERR_G106` 餘額不足**——都不會進 error machine。只用於背景呼叫、且 session 失效另有 `fetchUserInfo` 輪詢兜底的請求;使用者主動觸發的請求不可加。
|
|
359
|
-
13. **`send()` 不保證回傳物件,`assign()` 內不可拋錯**:維護中(`isBlocked`)的非 config 請求與 `ERR_800` 取消會讓 `send()` **resolve `undefined`**(不進 `onError`);200 但 body 非 JSON 時 resolve 字串,解構 `{ data }` 得到 `undefined`。XState v4 在 `assign()` 內拋錯會清空事件佇列且狀態不更新——machine 停在當前 invoke 狀態、`after` 輪詢中止,直到外部事件(如 `REFRESH`)才離開。**回應格式驗證放 service 內 `throw`(reject → `onError`)**;`onDone` 的每個 assign 都必須承受 service 所有可能的 resolve 值,含刻意 `return null` 的早退路徑。
|
|
360
349
|
|
|
361
350
|
---
|
|
362
351
|
|
|
@@ -364,19 +353,19 @@ io(`${socketURL}/frontend`, {
|
|
|
364
353
|
|
|
365
354
|
> 以下每一項在程式碼中都是**兩種寫法並存**——探索程式碼無法判斷哪個才是規範,因此必須明文記錄。新寫的程式碼一律採用「目標」欄;既有程式碼不主動大規模重構(範圍自律)。
|
|
366
355
|
|
|
367
|
-
| 項目 | 現況
|
|
368
|
-
| ------------------ |
|
|
369
|
-
| HTTP method 大小寫 | `'GET'` 與 `'get'` 並存(`request.js` 內部 `toUpperCase()`,功能不受影響)
|
|
370
|
-
| 匯入路徑 | 部分檔案用 `@jetthai/cuora` 套件名自我引用
|
|
371
|
-
| lodash 副檔名 | `'lodash/pickBy.js'` 與 `'lodash/pickBy'` 並存
|
|
372
|
-
| URL 前導斜線 | 少數 API 帶前導斜線
|
|
373
|
-
| 查詢參數位置 | 少數直接寫入 URL(`register?${qs}`、`mail?include=cl`),繞過序列化
|
|
374
|
-
| 初始狀態命名 | `idle`
|
|
375
|
-
| 魔法數字與字串 | 活動類型 ID、錯誤碼、TTL、輪詢 tick、`'DEPOSIT'`/`'WITHDRAW'`、`receiveStatus`、`connectStatus`
|
|
376
|
-
| 錯誤處理 | 三種並存:靜默轉 `idle`(多數,錯誤資訊遺失)、轉 `fail`、無限重試
|
|
377
|
-
| 參數命名 | 如 `
|
|
378
|
-
| 參數驗證 | API 層無任何驗證(如 `
|
|
379
|
-
| 已棄用 API | `api/
|
|
356
|
+
| 項目 | 現況 | 目標 |
|
|
357
|
+
| ------------------ | -------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
|
|
358
|
+
| HTTP method 大小寫 | `'GET'` 與 `'get'` 並存(`request.js` 內部 `toUpperCase()`,功能不受影響) | 統一小寫 `'get'`/`'post'`/`'put'`/`'delete'` |
|
|
359
|
+
| 匯入路徑 | 部分檔案用 `@jetthai/cuora` 套件名自我引用 | 統一相對路徑(`'../../api/payment.js'`) |
|
|
360
|
+
| lodash 副檔名 | `'lodash/pickBy.js'` 與 `'lodash/pickBy'` 並存 | 統一**不帶**副檔名 |
|
|
361
|
+
| URL 前導斜線 | 少數 API 帶前導斜線 | 不加(除非刻意繞過 `url-join`,須註解原因) |
|
|
362
|
+
| 查詢參數位置 | 少數直接寫入 URL(`register?${qs}`、`mail?include=cl`),繞過序列化 | 一律用 `params` 欄位 |
|
|
363
|
+
| 初始狀態命名 | `idle` / `loading` / `fetching` / `init` / `preparing` 混用 | 依語意:`idle`(等待操作)、`loading`(初始載入)、`fetching`(重新取得)、`submitting` / `submitted` |
|
|
364
|
+
| 魔法數字與字串 | 活動類型 ID、錯誤碼、TTL、輪詢 tick、`'DEPOSIT'`/`'WITHDRAW'`、`receiveStatus`、`connectStatus` 散佈各處 | 集中至 `util/constant.js`(`ERROR_CODES` / `TTL` / `INTERVAL` / `TRANSFER_TYPE` / `RECEIVE_STATUS`) |
|
|
365
|
+
| 錯誤處理 | 三種並存:靜默轉 `idle`(多數,錯誤資訊遺失)、轉 `fail`、無限重試 | `onError` 搭配 `actions: 'setError'` 保存錯誤至 context;區分可恢復 / 不可恢復;重試須設上限 |
|
|
366
|
+
| 參數命名 | 如 `addFavoriteGame(code)` 語意不明 | 具體命名(`gameCode`) |
|
|
367
|
+
| 參數驗證 | API 層無任何驗證(如 `makeTransaction({ paymentMethod })` 直接注入 URL) | 在系統邊界驗證:路徑參數非 undefined 且無路徑遍歷字元、金額為正數 |
|
|
368
|
+
| 已棄用 API | `api/user.js` 的 V1 `passwordRecovery` 與 V2 `passwordV2*` 並存,V1 無標記 | 先補 `@deprecated`,確認無引用後再移除 |
|
|
380
369
|
|
|
381
370
|
---
|
|
382
371
|
|
|
@@ -388,11 +377,12 @@ io(`${socketURL}/frontend`, {
|
|
|
388
377
|
- **無請求快取** — 高頻端點(`fetchUserInfo` 每 2–10 秒、`getConfig` 每次狀態機初始化、`getPaymentDetail` 每次進入存提款頁、`getActivityList` 每 20 秒)皆直打伺服器。可考慮 TTL 快取或 `stale-while-revalidate`。
|
|
389
378
|
- **無速率限制與退避** — 輪詢為固定間隔,錯誤時不變。可考慮錯誤時指數退避。
|
|
390
379
|
- **無 Token 自動刷新** — `request.js` 回應攔截器不處理 401,Token 過期即失敗。
|
|
380
|
+
- **FingerprintJS 打包** — `src/lib/` 內嵌的 FingerprintJS 即使停用也會在模組初始化載入。建議改動態 `import()` 懶載入。
|
|
391
381
|
- **無程式碼分割** — `machine/index.js` 即時匯入所有狀態機 + API + Socket.IO + lodash,匯入 `machine` 等於載入全部。建議支援個別匯入以啟用 tree-shaking。
|
|
392
|
-
- **計時器管理** — 大量以 `after: { 1000 }`
|
|
393
|
-
- **大型狀態機檔案** — `game_v2_1.js
|
|
382
|
+
- **計時器管理** — 大量以 `after: { 1000 }` 自我引用轉換做倒數,每秒一次狀態轉換(含 context clone + event dispatch)。建議改 callback service + `setInterval`,並**計算經過時間**而非逐次遞減以避免累積誤差。
|
|
383
|
+
- **大型狀態機檔案** — `game_v2_1.js`、`auth.js`、`withdraw_manual.js`、`inbox.js`、`manual_vn.js`、`common.js`、`game_search_v2.js` 皆超過 300 行,可拆為可組合的子狀態機。
|
|
394
384
|
- **未使用的 context 欄位** — 多個狀態機宣告了從未賦值或讀取的 context 欄位。
|
|
395
|
-
- **lodash
|
|
385
|
+
- **lodash 可原生替代** — 實際只用到少數幾個函式,`padStart` / `toNumber` 可直接換原生,`findLastIndex` 現代瀏覽器已支援。
|
|
396
386
|
|
|
397
387
|
---
|
|
398
388
|
|