@jetthai/cuora 1.1.473-dev.0 → 1.1.474
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 +61 -66
- package/.husky/post-checkout +3 -3
- package/.husky/pre-push +1 -1
- package/.prettierignore +1 -2
- package/AGENTS.md +61 -66
- package/AI_PROMPT_SOURCE.md +61 -66
- package/CHANGELOG.md +6 -249
- package/CLAUDE.md +61 -66
- package/GEMINI.md +61 -66
- 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 +1 -14
- 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 -0
- 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/GEMINI.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? }` 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)
|
|
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
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,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
|
|
|
@@ -113,6 +111,7 @@ state machine service → request.send(api.xxx(params)) → Request class → AP
|
|
|
113
111
|
isPublic?: boolean, // true = no auth token required
|
|
114
112
|
headers?: object, // Custom headers (e.g. reCAPTCHA)
|
|
115
113
|
isFormData?: boolean, // true = multipart/form-data
|
|
114
|
+
silent?: boolean, // true = on failure, don't forward to errorHandler (still throws)
|
|
116
115
|
}
|
|
117
116
|
```
|
|
118
117
|
|
|
@@ -180,13 +179,16 @@ Token 5min TTL → fetchUserInfo success → extendToken resets TTL → poll aga
|
|
|
180
179
|
|
|
181
180
|
**Polling interval**: base `tick: 2000ms`, **multiplied by 5 while in a game** (becoming 10 seconds) to reduce server load during play.
|
|
182
181
|
|
|
183
|
-
**Login method routing** (
|
|
182
|
+
**Login method routing** (7 kinds):
|
|
184
183
|
|
|
185
184
|
| Event | Method | Special Handling |
|
|
186
185
|
| ---------------- | -------------------- | --------------------------------------------------------------- |
|
|
187
186
|
| `LOGIN_ID` | Account + password | reCAPTCHA header |
|
|
188
187
|
| `LOGIN_PHONE` | Phone number | reCAPTCHA header + country code |
|
|
189
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 |
|
|
190
192
|
| `LOGIN_TELEGRAM` | Telegram | additionalUserInfo |
|
|
191
193
|
| `LOGIN_3PARTY` | Third-party redirect | **Does not switch state**; uses `window.location.href` directly |
|
|
192
194
|
|
|
@@ -196,33 +198,33 @@ Token 5min TTL → fetchUserInfo success → extendToken resets TTL → poll aga
|
|
|
196
198
|
|
|
197
199
|
### 2.2 Canonical Deposit Pattern
|
|
198
200
|
|
|
199
|
-
|
|
201
|
+
All deposit state machines follow a unified core flow, with variants per payment method:
|
|
200
202
|
|
|
201
203
|
```
|
|
202
|
-
loading (
|
|
203
|
-
→
|
|
204
|
-
→
|
|
205
|
-
→
|
|
206
|
-
|
|
207
|
-
|
|
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
|
|
208
211
|
```
|
|
209
212
|
|
|
210
|
-
**
|
|
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 |
|
|
213
|
+
**Cash vs Non-Cash variants**:
|
|
218
214
|
|
|
219
|
-
|
|
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) |
|
|
220
222
|
|
|
221
|
-
|
|
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.
|
|
222
224
|
|
|
223
|
-
>
|
|
225
|
+
> ⚠️ **Naming inconsistency (easy to trip on)**: Non-Cash uses `promotion?.activityNo`, Cash uses `promotion?.promotionsNo`.
|
|
224
226
|
|
|
225
|
-
**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.
|
|
226
228
|
|
|
227
229
|
> ⚠️ **V2 API response format is inconsistent**: the same endpoint may return `{ data: {...} }` or just `{...}`, so every machine needs defensive handling:
|
|
228
230
|
>
|
|
@@ -233,36 +235,26 @@ loading (always + setInitData: takes paymentDetail from the factory context para
|
|
|
233
235
|
> })
|
|
234
236
|
> ```
|
|
235
237
|
|
|
236
|
-
**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.
|
|
237
239
|
|
|
238
240
|
### 2.3 Withdrawal Flow & OTP
|
|
239
241
|
|
|
240
|
-
|
|
242
|
+
**Five-step eligibility validation chain** (`withdraw_manual.js`); failing any step transitions to the corresponding blocking state:
|
|
241
243
|
|
|
242
244
|
```
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
|
249
251
|
```
|
|
250
252
|
|
|
251
|
-
|
|
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`.
|
|
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.
|
|
262
254
|
|
|
263
|
-
**
|
|
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`.
|
|
264
256
|
|
|
265
|
-
|
|
257
|
+
**Attachment types**: `withdraw` (normal withdrawal) vs `pool` (bonus / free-credit redemption, which calls the `restore` API).
|
|
266
258
|
|
|
267
259
|
### 2.4 Game Management
|
|
268
260
|
|
|
@@ -278,11 +270,11 @@ There are only 4 guards: `hasNoBank` (`REFRESH` only reloads when no account is
|
|
|
278
270
|
|
|
279
271
|
**receiveStatus enum**: `0` in progress / not yet eligible (→ `progress_status`), `1` claimed (→ `received`, terminal), `2` claimable (→ `receiveable`).
|
|
280
272
|
|
|
281
|
-
**Red-dot unread state
|
|
273
|
+
**Red-dot unread state**:
|
|
282
274
|
|
|
283
|
-
-
|
|
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}`
|
|
284
277
|
- 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
|
|
286
278
|
|
|
287
279
|
**Activity polling**: base interval `tick * 10 = 20 seconds`; **polling pauses while in a game (`isPlaying === true`)**. Fetching promotions additionally requires `hasToken`.
|
|
288
280
|
|
|
@@ -314,9 +306,10 @@ io(`${socketURL}/frontend`, {
|
|
|
314
306
|
|
|
315
307
|
### 2.7 Configuration & Live Info (Common Machine)
|
|
316
308
|
|
|
317
|
-
**
|
|
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).
|
|
318
310
|
|
|
319
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
|
|
320
313
|
- **Mailbox filtering**: if `customerMessageEnable === false`, the count of CUSTOMER-type messages is deducted from the mailbox total
|
|
321
314
|
|
|
322
315
|
### 2.8 API Request Lifecycle
|
|
@@ -336,7 +329,7 @@ io(`${socketURL}/frontend`, {
|
|
|
336
329
|
7. Custom paramsSerializer: special encoding for the q parameter (avoids double-encoding)
|
|
337
330
|
8. axios.request(config)
|
|
338
331
|
9. Response interceptor: response.data.error present → reject; Network Error / 404 → ERR_998 + Sentry
|
|
339
|
-
10. Error handling: ERR_F108 → isBlocked; ERR_800 (cancelled) → silent; everything else → errorHandler
|
|
332
|
+
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)
|
|
340
333
|
```
|
|
341
334
|
|
|
342
335
|
**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.**
|
|
@@ -354,6 +347,7 @@ io(`${socketURL}/frontend`, {
|
|
|
354
347
|
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").
|
|
355
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`).
|
|
356
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.**
|
|
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.
|
|
357
351
|
|
|
358
352
|
---
|
|
359
353
|
|
|
@@ -361,19 +355,19 @@ io(`${socketURL}/frontend`, {
|
|
|
361
355
|
|
|
362
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).
|
|
363
357
|
|
|
364
|
-
| Item | Current state
|
|
365
|
-
| ------------------------- |
|
|
366
|
-
| HTTP method casing | `'GET'` and `'get'` coexist (`request.js` calls `toUpperCase()` internally, so behavior is unaffected)
|
|
367
|
-
| Import paths | Some files self-reference via the `@jetthai/cuora` package name
|
|
368
|
-
| lodash extension | `'lodash/pickBy.js'` and `'lodash/pickBy'` coexist
|
|
369
|
-
| URL leading slash | A few APIs carry a leading slash
|
|
370
|
-
| Query parameter placement | A few write them straight into the URL (`register?${qs}`, `mail?include=cl`), bypassing serialization
|
|
371
|
-
| Initial state naming | `idle`
|
|
372
|
-
| Magic numbers and strings | Activity type IDs, error codes, TTLs, polling ticks, `'DEPOSIT'`/`'WITHDRAW'`, `receiveStatus`, `connectStatus` are scattered around
|
|
373
|
-
| Error handling | Three forms coexist: silent fallback to `idle` (most common, loses error info), transition to `fail`, infinite retry
|
|
374
|
-
| Parameter naming | e.g. `
|
|
375
|
-
| Parameter validation | The API layer has no validation at all (e.g.
|
|
376
|
-
| 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 |
|
|
377
371
|
|
|
378
372
|
---
|
|
379
373
|
|
|
@@ -385,11 +379,12 @@ io(`${socketURL}/frontend`, {
|
|
|
385
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`.
|
|
386
380
|
- **No rate limiting or backoff** — polling runs at a fixed interval and does not change on errors. Consider exponential backoff on errors.
|
|
387
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.
|
|
388
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.
|
|
389
|
-
- **Timer management** — countdowns are largely implemented with self-referencing `after: { 1000 }` transitions
|
|
390
|
-
- **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.
|
|
391
386
|
- **Unused context fields** — several state machines declare context fields that are never assigned or read.
|
|
392
|
-
- **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.
|
|
393
388
|
|
|
394
389
|
---
|
|
395
390
|
|
package/README.md
CHANGED
|
@@ -53,20 +53,20 @@ export default {
|
|
|
53
53
|
## Usage
|
|
54
54
|
|
|
55
55
|
```js
|
|
56
|
-
import { api, machine, Request, Config, constant, storage } from '@jetthai/cuora'
|
|
56
|
+
import { api, machine, Request, Config, util, constant, storage } from '@jetthai/cuora'
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
### 模組匯出
|
|
60
60
|
|
|
61
|
-
| 匯出名稱
|
|
62
|
-
|
|
|
63
|
-
| `api`
|
|
64
|
-
| `machine`
|
|
65
|
-
| `Request`
|
|
66
|
-
| `Config`
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
61
|
+
| 匯出名稱 | 說明 |
|
|
62
|
+
| ---------- | ------------------------------------------------------- |
|
|
63
|
+
| `api` | 各領域 API 模組的聚合物件(見下方 API 章節) |
|
|
64
|
+
| `machine` | XState 狀態機工廠函式的聚合物件(見下方 Machine 章節) |
|
|
65
|
+
| `Request` | Axios 封裝類別(攔截器、Token、版本控制) |
|
|
66
|
+
| `Config` | 設定類別(apiURL、clientId、appSecret 等) |
|
|
67
|
+
| `util` | 工具函式(`getDeviceToken`、`getDeviceTokenWithRetry`) |
|
|
68
|
+
| `constant` | 遊戲類型常數 |
|
|
69
|
+
| `storage` | localStorage 封裝(支援 TTL/過期) |
|
|
70
70
|
|
|
71
71
|
### Config
|
|
72
72
|
|
|
@@ -151,7 +151,7 @@ const service = interpret(authMachine).start()
|
|
|
151
151
|
### Utilities
|
|
152
152
|
|
|
153
153
|
```js
|
|
154
|
-
import { constant, storage } from '@jetthai/cuora'
|
|
154
|
+
import { util, constant, storage } from '@jetthai/cuora'
|
|
155
155
|
|
|
156
156
|
// LocalStorage 封裝,支援 TTL/過期機制
|
|
157
157
|
storage.set('key', value, ttl)
|
|
@@ -159,6 +159,7 @@ storage.get('key')
|
|
|
159
159
|
|
|
160
160
|
// 遊戲類型常數
|
|
161
161
|
constant.GAME_TYPE_LIST // 遊戲類型陣列,每筆為 { typeId, name, gameTypeMappingId }
|
|
162
|
+
constant.MY_FAVORITE // 'MyFavorite'
|
|
162
163
|
constant.GAME_SEARCH // 'GameSearch'
|
|
163
164
|
```
|
|
164
165
|
|
package/package.json
CHANGED
package/scripts/auto-version.js
CHANGED
|
@@ -14,15 +14,8 @@ const { version } = JSON.parse(readFileSync('package.json', 'utf8'))
|
|
|
14
14
|
console.log(`Branch: ${branch}`)
|
|
15
15
|
console.log(`Version: ${version}`)
|
|
16
16
|
|
|
17
|
-
// 推送 commit 到遠端(--no-verify 避免觸發 pre-push hook 造成無限迴圈)
|
|
18
|
-
execSync(`git push --no-verify ${remote} ${branch}`, { stdio: 'inherit' })
|
|
19
|
-
|
|
20
|
-
// 單獨推送 tag;tag 已存在於 remote 時視為成功(不中斷 npm publish)
|
|
21
|
-
try {
|
|
22
|
-
execSync(`git push --no-verify ${remote} refs/tags/v${version}`, { stdio: 'inherit' })
|
|
23
|
-
} catch {
|
|
24
|
-
console.warn(`⚠ tag v${version} push 失敗(可能已存在),繼續 npm publish`)
|
|
25
|
-
}
|
|
17
|
+
// 推送 commit 與 tag 到遠端(--no-verify 避免觸發 pre-push hook 造成無限迴圈)
|
|
18
|
+
execSync(`git push --no-verify --follow-tags ${remote} ${branch}`, { stdio: 'inherit' })
|
|
26
19
|
|
|
27
20
|
// 發布到 npm,使用分支名稱作為 dist-tag(例如 npm install @jetthai/cuora@dev)
|
|
28
21
|
try {
|
package/src/api/account.js
CHANGED
|
@@ -2,6 +2,7 @@ export default {
|
|
|
2
2
|
bindingStatus: () => ({ url: 'account-binding/status', method: 'GET' }),
|
|
3
3
|
applyBinding: (data) => ({ url: 'account-binding/bind', method: 'POST', params: data }),
|
|
4
4
|
bindingVerification: (data) => ({ url: 'account-binding/acknowledge', method: 'POST', params: data }),
|
|
5
|
+
bindThirdParty: (data) => ({ url: 'account-binding/bind-third-party', method: 'GET', params: data }),
|
|
5
6
|
bindPassword: (data) => ({ url: 'account-binding/bind-password', method: 'POST', params: data }),
|
|
6
7
|
resetOtp: (data) => ({ url: 'account-binding/reset-otp', method: 'POST', params: data }),
|
|
7
8
|
}
|
package/src/api/activity.js
CHANGED
|
@@ -18,12 +18,39 @@ export default {
|
|
|
18
18
|
params: { appSecret },
|
|
19
19
|
isPublic: true,
|
|
20
20
|
}),
|
|
21
|
+
getTournamentDetail: ({ activityNo, appSecret }) => ({
|
|
22
|
+
url: 'tournament/detail',
|
|
23
|
+
method: 'get',
|
|
24
|
+
params: { activityNo, appSecret },
|
|
25
|
+
isPublic: true,
|
|
26
|
+
}),
|
|
21
27
|
getActivityDetail: ({ activityNo, appSecret, silent = false }) => ({
|
|
22
28
|
url: 'activities',
|
|
23
29
|
method: 'get',
|
|
24
30
|
params: { activityNo, appSecret },
|
|
25
31
|
silent,
|
|
26
32
|
}),
|
|
33
|
+
getActivityRanking: ({ appSecret }) => ({
|
|
34
|
+
url: 'activities/activity/ranking',
|
|
35
|
+
method: 'get',
|
|
36
|
+
params: { appSecret },
|
|
37
|
+
isPublic: true,
|
|
38
|
+
}),
|
|
39
|
+
getAchievements: ({ limit, page, appSecret }) => ({
|
|
40
|
+
url: 'activities/achievements',
|
|
41
|
+
method: 'get',
|
|
42
|
+
params: {
|
|
43
|
+
limit,
|
|
44
|
+
page,
|
|
45
|
+
appSecret,
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
getAchievementsProgress: ({ achievementNo, appSecret }) => ({
|
|
49
|
+
url: 'activities/achievements/progress',
|
|
50
|
+
method: 'get',
|
|
51
|
+
params: { achievementNo, appSecret },
|
|
52
|
+
}),
|
|
53
|
+
getAchievementsIssued: () => ({ url: 'activities/achievements/issue', method: 'get' }),
|
|
27
54
|
postPromoCode: (promoCode) => ({
|
|
28
55
|
url: 'activities/promo',
|
|
29
56
|
method: 'post',
|
|
@@ -58,6 +85,7 @@ export default {
|
|
|
58
85
|
settleAmount: (data) => ({ url: 'activities/exchange/diamond/settle', method: 'post', params: data }),
|
|
59
86
|
exchange: (data) => ({ url: 'activities/exchange', method: 'post', params: data }),
|
|
60
87
|
collect: (data) => ({ url: 'activities/collect', method: 'post', params: data }),
|
|
88
|
+
getVipTable: ({ appSecret }) => ({ url: 'activities/viptable', method: 'get', params: { appSecret } }),
|
|
61
89
|
getLevelBonusInfo: () => ({ url: 'activities/level-bonus/info', method: 'get' }),
|
|
62
90
|
getRankingList: () => ({ url: 'activities/ranking', method: 'get' }),
|
|
63
91
|
getPublicRankingList: ({ appSecret }) => ({
|
|
@@ -66,12 +94,21 @@ export default {
|
|
|
66
94
|
isPublic: true,
|
|
67
95
|
params: { appSecret },
|
|
68
96
|
}),
|
|
97
|
+
exchangeDiamond: ({ activityNo, exchangeAward = [] }) => ({
|
|
98
|
+
url: 'activities/exchange/diamond',
|
|
99
|
+
method: 'post',
|
|
100
|
+
params: {
|
|
101
|
+
activityNo,
|
|
102
|
+
exchangeAward,
|
|
103
|
+
},
|
|
104
|
+
}),
|
|
69
105
|
getHonorBroadcast: ({ isPwa = false, appSecret }) => ({
|
|
70
106
|
url: 'activities/honorBroadcast',
|
|
71
107
|
method: 'get',
|
|
72
108
|
params: { isPwa, appSecret },
|
|
73
109
|
isPublic: true,
|
|
74
110
|
}),
|
|
111
|
+
getInstantRebateCollectTime: () => ({ url: 'activities/rebate/collectTime', method: 'get' }),
|
|
75
112
|
instantRebateEstimate: () => ({ url: 'activities/rebate/estimate', method: 'get' }),
|
|
76
113
|
instantRebateCollect: () => ({ url: 'activities/rebate/collect', method: 'get' }),
|
|
77
114
|
instantRebateHistory: ({ startDate, endDate, appSecret }) => ({
|
package/src/api/auth.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import pickBy from 'lodash/pickBy'
|
|
2
2
|
export default {
|
|
3
|
+
guestLogin: () => ({
|
|
4
|
+
url: 'guestLogin',
|
|
5
|
+
method: 'post',
|
|
6
|
+
isPublic: true,
|
|
7
|
+
}),
|
|
3
8
|
login: ({ username, password, provider, countryCode, phone, email, dt, reCaptchaToken, additionalUserInfo, loginType, isSignature, idToken }) => ({
|
|
4
9
|
url: 'login',
|
|
5
10
|
method: 'post',
|
|
@@ -7,6 +12,25 @@ export default {
|
|
|
7
12
|
isPublic: true,
|
|
8
13
|
headers: { 'x-access-captcha': reCaptchaToken },
|
|
9
14
|
}),
|
|
15
|
+
loginApp: ({ provider, accessToken, channel, subchannel, dt, from, id, name, picture }) => ({
|
|
16
|
+
url: 'appLogin',
|
|
17
|
+
method: 'post',
|
|
18
|
+
params: {
|
|
19
|
+
provider,
|
|
20
|
+
data: {
|
|
21
|
+
accessToken,
|
|
22
|
+
channel,
|
|
23
|
+
subchannel,
|
|
24
|
+
dt,
|
|
25
|
+
from,
|
|
26
|
+
id,
|
|
27
|
+
name,
|
|
28
|
+
picture,
|
|
29
|
+
provider,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
isPublic: true,
|
|
33
|
+
}),
|
|
10
34
|
register: ({ ac, fc = null, reCaptchaToken, dt, ...rest }) => {
|
|
11
35
|
const params = pickBy({ ac, fc }, (value) => {
|
|
12
36
|
return value !== undefined && value !== null
|
|
@@ -23,6 +47,13 @@ export default {
|
|
|
23
47
|
}
|
|
24
48
|
},
|
|
25
49
|
logout: () => ({ url: 'logout', method: 'post' }),
|
|
50
|
+
// bindGet for 'google' | 'zalo' | 'facebook'
|
|
51
|
+
bindGet: ({ x, provider, redirectURI }) => ({ url: 'bind', method: 'get', params: { x, provider, redirectURI } }),
|
|
52
|
+
bindPost: ({ provider, countryCode, phone, email }) => ({
|
|
53
|
+
url: 'bind',
|
|
54
|
+
method: 'post',
|
|
55
|
+
params: { provider, countryCode, phone, email },
|
|
56
|
+
}),
|
|
26
57
|
checkAccount: ({ account, nick_name, strategy, appSecret }) => ({
|
|
27
58
|
url: 'checkAccount',
|
|
28
59
|
method: 'post',
|
package/src/api/game.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export default {
|
|
2
|
+
getGameCategory: ({ id, first } = {}) => ({ method: 'get', url: 'game/list/v2/category', params: { id, first } }),
|
|
3
|
+
addFavoriteGame: (code) => ({ method: 'post', url: 'game/myfavorite/add', params: { games: [code] } }),
|
|
4
|
+
removeFavoriteGame: (code) => ({ method: 'post', url: 'game/myfavorite/remove', params: { games: [code] } }),
|
|
5
|
+
getStatements: () => ({ url: 'game/statements', method: 'get' }),
|
|
2
6
|
playGame: (params) => ({ url: 'game/play', method: 'get', params }),
|
|
3
7
|
demoGame: (params) => ({ url: 'game/demo', method: 'get', params, isPublic: true }),
|
|
4
8
|
logoutGame: ({ uid_site, provider_id }) => ({ url: 'game/logout', method: 'get', params: { uid_site, provider_id } }),
|
|
@@ -86,6 +90,12 @@ export default {
|
|
|
86
90
|
addListFavorite: (code) => ({ method: 'post', url: 'game/list/v3/addMyFavorite', params: { games: [code] } }),
|
|
87
91
|
removeListFavorite: (code) => ({ method: 'post', url: 'game/list/v3/removeMyFavorite', params: { games: [code] } }),
|
|
88
92
|
getGameInfo: ({ appSecret, gameCode }) => ({ method: 'get', url: 'game/info', params: { appSecret, gameCode } }),
|
|
93
|
+
getGameReplayInfo: ({ providerId, seqNo, lang, appSecret }) => ({
|
|
94
|
+
method: 'get',
|
|
95
|
+
url: 'game/gameReplay',
|
|
96
|
+
params: { providerId, seqNo, lang, appSecret },
|
|
97
|
+
isPublic: true,
|
|
98
|
+
}),
|
|
89
99
|
getFreeGameList: () => ({ method: 'get', url: 'activities/getFreeGameRewardList' }),
|
|
90
100
|
getFreeGameReward: ({ activityNo, receiveNo }) => ({ method: 'post', url: 'activities/getFreeGameReward', params: { activityNo, receiveNo } }),
|
|
91
101
|
getV3GameInfo: ({ appSecret, gameCodes }) => ({ method: 'post', url: 'game/list/v3/gameInfo', params: { appSecret, gameCodes } }),
|
package/src/api/payment.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export default {
|
|
2
|
+
getPaymentHistory: (returnDays) => ({ url: 'payment/v2/history', method: 'post', params: { returnDays } }),
|
|
3
|
+
getSpotMarket: () => ({ url: 'payment/v2/spotmarket', method: 'get' }),
|
|
2
4
|
getTransactionHistory: (payload) => ({
|
|
3
5
|
url: 'payment/v2/transactionHistory',
|
|
4
6
|
method: 'post',
|
|
@@ -57,6 +59,18 @@ export default {
|
|
|
57
59
|
getBankList: (paymentMethod) => ({ url: `payment/v2/${paymentMethod}/getBankList`, method: 'get' }),
|
|
58
60
|
getBindingBankList: ({ appSecret }) => ({ url: 'payment/v2/getBindingBankList', method: 'get', params: { appSecret }, isPublic: true }),
|
|
59
61
|
getBindingPaymentList: ({ appSecret }) => ({ url: 'payment/v2/getBindingPaymentList', method: 'get', params: { appSecret } }),
|
|
62
|
+
getWithdrawBankList: () => ({ url: 'payment/v2/getWithdrawBankList', method: 'get' }),
|
|
63
|
+
makeTransaction: ({ type, payload, paymentMethod }) => ({
|
|
64
|
+
url: `payment/v2/${paymentMethod}/transaction`,
|
|
65
|
+
method: 'post',
|
|
66
|
+
params: {
|
|
67
|
+
transferType: type,
|
|
68
|
+
...payload,
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
checkTransaction: (paymentMethod) => ({ url: `payment/v2/${paymentMethod}/checkTransaction`, method: 'post' }),
|
|
72
|
+
setBonusSetting: ({ bonus }) => ({ url: 'payment/v2/setting', method: 'post', params: { bonus } }),
|
|
73
|
+
getCurrentWithdrawRule: () => ({ url: 'payment/v2/getCurrentWithdrawRule', method: 'get' }),
|
|
60
74
|
getDoubleWalletWithdrawRule: ({ walletType }) => ({
|
|
61
75
|
url: 'payment/v2/withdrawRule',
|
|
62
76
|
method: 'post',
|
|
@@ -67,6 +81,7 @@ export default {
|
|
|
67
81
|
method: 'post',
|
|
68
82
|
params: { exchangeType, cryptoNetwork, targetAddress },
|
|
69
83
|
}),
|
|
84
|
+
mergeWallet: () => ({ url: 'payment/v2/mergeWallet', method: 'post' }),
|
|
70
85
|
getPaymentDetail: ({ transferType } = {}) => ({
|
|
71
86
|
url: 'payment/v2/paymentDetail',
|
|
72
87
|
method: 'post',
|
|
@@ -87,6 +102,11 @@ export default {
|
|
|
87
102
|
method: 'post',
|
|
88
103
|
params: { transferType: 'WITHDRAW', amount, cryptoCurrency, promotionsNo },
|
|
89
104
|
}),
|
|
105
|
+
getWithdrawExpectedResult: ({ method, amount, cryptoNetwork }) => ({
|
|
106
|
+
url: `payment/v2/${method}/expected/result`,
|
|
107
|
+
method: 'post',
|
|
108
|
+
params: { transferType: 'WITHDRAW', amount, cryptoNetwork },
|
|
109
|
+
}),
|
|
90
110
|
submitDepositTransactionCrypto: ({ method, amount, cryptoCurrency, cryptoNetwork, sourceAddress, promotionsNo, receipt }) => ({
|
|
91
111
|
url: `payment/v2/${method}/transaction`,
|
|
92
112
|
method: 'post',
|
|
@@ -173,6 +193,38 @@ export default {
|
|
|
173
193
|
applyerHolderName,
|
|
174
194
|
},
|
|
175
195
|
}),
|
|
196
|
+
submitWithdrawTransactionManual: ({
|
|
197
|
+
method,
|
|
198
|
+
amount,
|
|
199
|
+
applyerBankCode,
|
|
200
|
+
applyerAccountNumber,
|
|
201
|
+
applyerIfscCode,
|
|
202
|
+
branch,
|
|
203
|
+
holderName,
|
|
204
|
+
cryptoCurrency,
|
|
205
|
+
cryptoNetwork,
|
|
206
|
+
targetAddress,
|
|
207
|
+
}) => ({
|
|
208
|
+
url: `payment/v2/${method}/withdraw-otp/verify`,
|
|
209
|
+
method: 'post',
|
|
210
|
+
params: {
|
|
211
|
+
transferType: 'WITHDRAW',
|
|
212
|
+
amount,
|
|
213
|
+
applyerBankCode,
|
|
214
|
+
applyerAccountNumber,
|
|
215
|
+
applyerIfscCode,
|
|
216
|
+
branch,
|
|
217
|
+
holderName,
|
|
218
|
+
cryptoCurrency,
|
|
219
|
+
cryptoNetwork,
|
|
220
|
+
targetAddress,
|
|
221
|
+
},
|
|
222
|
+
}),
|
|
223
|
+
submitWithdrawTransactionAmb: ({ method, amount }) => ({
|
|
224
|
+
url: `payment/v2/${method}/transaction`,
|
|
225
|
+
method: 'post',
|
|
226
|
+
params: { transferType: 'WITHDRAW', amount },
|
|
227
|
+
}),
|
|
176
228
|
getPromotionsList: () => ({ url: `payment/v2/bankWallet/promotions`, method: 'get' }),
|
|
177
229
|
getWithdrawRulePreview: ({ applyType, applyNo, amount, isFreeGame }) => ({
|
|
178
230
|
url: `payment/v2/bankWallet/promotion/preview`,
|
|
@@ -208,5 +260,4 @@ export default {
|
|
|
208
260
|
isPublic: true,
|
|
209
261
|
}),
|
|
210
262
|
getPaymentPromotions: () => ({ url: 'payment/v2/promotions', method: 'get' }),
|
|
211
|
-
setBonusSetting: ({ bonus }) => ({ url: 'payment/v2/setting', method: 'post', params: { bonus } }),
|
|
212
263
|
}
|