@jetthai/cuora 1.1.488-dev.1 → 1.2.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.
Files changed (221) hide show
  1. package/.husky/pre-commit +3 -1
  2. package/.prettierignore +1 -2
  3. package/CHANGELOG.md +0 -746
  4. package/README.md +15 -299
  5. package/package.json +3 -6
  6. package/resetGitBranch.sh +101 -0
  7. package/src/api/activity.js +39 -24
  8. package/src/api/auth.js +35 -4
  9. package/src/api/common.js +1 -8
  10. package/src/api/game.js +10 -0
  11. package/src/api/index.js +1 -3
  12. package/src/api/payment.js +55 -18
  13. package/src/api/user.js +16 -11
  14. package/src/index.js +2 -2
  15. package/src/lib/fingerprint_v3_11_12.js +11433 -0
  16. package/src/machine/activity/activity.js +209 -0
  17. package/src/machine/activity/activity_cash.js +18 -71
  18. package/src/machine/activity/diamond_shop_activity_cash.js +1 -0
  19. package/src/machine/activity/diamond_shop_activity_fc.js +196 -0
  20. package/src/machine/activity/diamond_shop_activity_vn.js +178 -0
  21. package/src/machine/activity/fafafa_activity.js +10 -0
  22. package/src/machine/activity/index.js +12 -0
  23. package/src/machine/activity/invite_friends_activity.js +114 -0
  24. package/src/machine/activity/mini_game_activity.js +68 -0
  25. package/src/machine/activity/return_bonus_activity.js +153 -0
  26. package/src/machine/activity/roulette_activity_v2.js +0 -5
  27. package/src/machine/auth.js +140 -192
  28. package/src/machine/auth_otp_v2.js +177 -0
  29. package/src/machine/auth_otp_v3.js +32 -111
  30. package/src/machine/bank_binding.js +2 -2
  31. package/src/machine/bank_binding_amb.js +145 -0
  32. package/src/machine/bonus.js +75 -0
  33. package/src/machine/common.js +91 -27
  34. package/src/machine/deposit/amb.js +92 -0
  35. package/src/machine/deposit/crypto_bank.js +325 -0
  36. package/src/machine/deposit/crypto_bank_cash.js +8 -19
  37. package/src/machine/deposit/crypto_qrcode.js +148 -0
  38. package/src/machine/deposit/crypto_qrcode_cash.js +41 -26
  39. package/src/machine/deposit/crypto_way.js +247 -0
  40. package/src/machine/deposit/crypto_way_cash.js +32 -52
  41. package/src/machine/deposit/deposit_fc.js +271 -0
  42. package/src/machine/deposit/direct.js +310 -0
  43. package/src/machine/deposit/direct_cash.js +9 -8
  44. package/src/machine/deposit/float.js +374 -0
  45. package/src/machine/deposit/index.js +28 -0
  46. package/src/machine/deposit/krway.js +151 -0
  47. package/src/machine/deposit/loadcard_cash.js +31 -14
  48. package/src/machine/deposit/loadcard_vn.js +351 -0
  49. package/src/machine/deposit/manual_cash.js +10 -8
  50. package/src/machine/deposit/manual_vn.js +458 -0
  51. package/src/machine/deposit/qrcode_cash.js +30 -14
  52. package/src/machine/deposit/qrcode_v2.js +338 -0
  53. package/src/machine/deposit/usdt.js +144 -0
  54. package/src/machine/deposit/virtual_bank_cash.js +2 -5
  55. package/src/machine/deposit/virtual_bank_vn.js +269 -0
  56. package/src/machine/deposit/vpay.js +367 -0
  57. package/src/machine/error.js +0 -7
  58. package/src/machine/game_hot_new.js +79 -0
  59. package/src/machine/game_info.js +12 -5
  60. package/src/machine/game_replay.js +46 -0
  61. package/src/machine/game_search_v2.js +401 -0
  62. package/src/machine/game_v2_1.js +88 -58
  63. package/src/machine/honor_board.js +132 -0
  64. package/src/machine/honor_board_cash.js +18 -15
  65. package/src/machine/inbox.js +12 -0
  66. package/src/machine/index.js +32 -0
  67. package/src/machine/leaderboard.js +11 -8
  68. package/src/machine/merge.js +57 -0
  69. package/src/machine/payment_data.js +86 -0
  70. package/src/machine/promotions.js +170 -0
  71. package/src/machine/ranking.js +25 -43
  72. package/src/machine/reward.js +255 -0
  73. package/src/machine/reward_cash.js +41 -2
  74. package/src/machine/reward_fc.js +98 -0
  75. package/src/machine/roulette_v2.js +25 -20
  76. package/src/machine/side.js +154 -0
  77. package/src/machine/side_cash.js +2 -3
  78. package/src/machine/side_v2.js +209 -0
  79. package/src/machine/user_reset_password.js +15 -4
  80. package/src/machine/user_sign_up.js +60 -49
  81. package/src/machine/vip_table.js +57 -0
  82. package/src/machine/websocket.js +325 -378
  83. package/src/machine/welcome.js +110 -0
  84. package/src/machine/withdraw/index.js +6 -0
  85. package/src/machine/withdraw/withdraw_crypto_cash.js +327 -0
  86. package/src/machine/withdraw/withdraw_krway.js +222 -0
  87. package/src/machine/withdraw/withdraw_manual.js +533 -0
  88. package/src/machine/withdraw/withdraw_manual_cash.js +43 -74
  89. package/src/request/config.js +0 -2
  90. package/src/request/request.js +64 -231
  91. package/src/util/constant.js +2 -12
  92. package/src/util/deviceToken.js +59 -0
  93. package/src/util/index.js +4 -2
  94. package/src/util/math.js +4 -0
  95. package/.claude/commands/sync-ai-prompts.md +0 -180
  96. package/.claude/settings.local.json +0 -25
  97. package/.github/copilot-instructions.md +0 -459
  98. package/.husky/post-checkout +0 -32
  99. package/.husky/pre-push +0 -36
  100. package/AGENTS.md +0 -459
  101. package/AI_PROMPT_SOURCE.md +0 -457
  102. package/CLAUDE.md +0 -459
  103. package/GEMINI.md +0 -459
  104. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
  105. package/docs/kibana/play-providerId-error.md +0 -202
  106. package/docs/kibana/play-selectedWalletType.md +0 -1
  107. package/docs/kibana/play-selectedWalletType_2.md +0 -1
  108. package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
  109. package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
  110. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
  111. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
  112. package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
  113. package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
  114. package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
  115. package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
  116. package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
  117. package/e2e/feature-map.md +0 -19
  118. package/prepare-for-pr/JT-1776243420.md +0 -85
  119. package/prepare-for-pr/TI-16026/STATE.md +0 -18
  120. package/prepare-for-pr/TI-16026/after-prepare-authorization.md +0 -3
  121. package/prepare-for-pr/TI-16026/analysis.md +0 -38
  122. package/prepare-for-pr/TI-16026/answer-analyze-01.md +0 -1
  123. package/prepare-for-pr/TI-16026/answer-commit-01.md +0 -2
  124. package/prepare-for-pr/TI-16026/answer-commit-02.md +0 -1
  125. package/prepare-for-pr/TI-16026/bundle.json +0 -18
  126. package/prepare-for-pr/TI-16026/checklist.md +0 -196
  127. package/prepare-for-pr/TI-16026/checklist.unit-test-original.md +0 -39
  128. package/prepare-for-pr/TI-16026/claude-after-model +0 -1
  129. package/prepare-for-pr/TI-16026/claude-commit-session +0 -1
  130. package/prepare-for-pr/TI-16026/claude-harvest-session +0 -1
  131. package/prepare-for-pr/TI-16026/claude-hops/01-analyze.err +0 -1
  132. package/prepare-for-pr/TI-16026/claude-hops/01-analyze.out +0 -2
  133. package/prepare-for-pr/TI-16026/claude-hops/02-analyze.err +0 -1
  134. package/prepare-for-pr/TI-16026/claude-hops/02-analyze.out +0 -4
  135. package/prepare-for-pr/TI-16026/claude-hops/03-dev.err +0 -1
  136. package/prepare-for-pr/TI-16026/claude-hops/03-dev.out +0 -4
  137. package/prepare-for-pr/TI-16026/claude-hops/04-dev.err +0 -1
  138. package/prepare-for-pr/TI-16026/claude-hops/04-dev.out +0 -4
  139. package/prepare-for-pr/TI-16026/claude-hops/05-dev.err +0 -1
  140. package/prepare-for-pr/TI-16026/claude-hops/05-dev.out +0 -3
  141. package/prepare-for-pr/TI-16026/claude-hops/06-after.err +0 -1
  142. package/prepare-for-pr/TI-16026/claude-hops/06-after.out +0 -2
  143. package/prepare-for-pr/TI-16026/claude-hops/07-commit.err +0 -1
  144. package/prepare-for-pr/TI-16026/claude-hops/07-commit.out +0 -2
  145. package/prepare-for-pr/TI-16026/claude-hops/08-commit.err +0 -1
  146. package/prepare-for-pr/TI-16026/claude-hops/08-commit.out +0 -2
  147. package/prepare-for-pr/TI-16026/claude-hops/09-commit.err +0 -1
  148. package/prepare-for-pr/TI-16026/claude-hops/09-commit.out +0 -8
  149. package/prepare-for-pr/TI-16026/claude-hops/10-harvest.err +0 -1
  150. package/prepare-for-pr/TI-16026/claude-hops/10-harvest.out +0 -3
  151. package/prepare-for-pr/TI-16026/claude-hops/11-harvest.err +0 -1
  152. package/prepare-for-pr/TI-16026/claude-hops/11-harvest.out +0 -3
  153. package/prepare-for-pr/TI-16026/commit-note.md +0 -5
  154. package/prepare-for-pr/TI-16026/evidence-index.json +0 -215
  155. package/prepare-for-pr/TI-16026/feature-map.before.md +0 -61
  156. package/prepare-for-pr/TI-16026/harvest-redaction.json +0 -34
  157. package/prepare-for-pr/TI-16026/harvest-redaction.out +0 -37
  158. package/prepare-for-pr/TI-16026/harvest.md +0 -46
  159. package/prepare-for-pr/TI-16026/lessons.md +0 -5
  160. package/prepare-for-pr/TI-16026/note-harvest-redaction.md +0 -1
  161. package/prepare-for-pr/TI-16026/open-questions.md +0 -6
  162. package/prepare-for-pr/TI-16026/publish.md +0 -32
  163. package/prepare-for-pr/TI-16026/review-convergence-response.md +0 -3
  164. package/prepare-for-pr/TI-16026/review-input/scope.md +0 -18
  165. package/prepare-for-pr/TI-16026/review-log.md +0 -57
  166. package/prepare-for-pr/TI-16026/review-notes.md +0 -97
  167. package/prepare-for-pr/TI-16026/review-response-r1.md +0 -7
  168. package/prepare-for-pr/TI-16026/self-test-report.md +0 -67
  169. package/prepare-for-pr/TI-16026/spec-proposal.md +0 -34
  170. package/prepare-for-pr/TI-16026/spec-snapshot.md +0 -291
  171. package/prepare-for-pr/TI-16026/state-log.md +0 -57
  172. package/prepare-for-pr/TI-16026/user-messages/01.md +0 -12
  173. package/prepare-for-pr/TI-16026/user-messages/02.md +0 -20
  174. package/prepare-for-pr/TI-16026/user-messages/03.md +0 -1
  175. package/prepare-for-pr/TI-16026/user-messages/04.md +0 -1
  176. package/prepare-for-pr/TI-16026/user-messages/05.md +0 -1
  177. package/prepare-for-pr/TI-16026/user-messages/06.md +0 -1
  178. package/prepare-for-pr/TI-16026/user-messages/07.md +0 -1
  179. package/prepare-for-pr/TI-16026/user-messages/08.md +0 -1
  180. package/prepare-for-pr/TI-16026/user-messages/09.md +0 -1
  181. package/prepare-for-pr/TI-16026/user-messages/10.md +0 -1
  182. package/prepare-for-pr/TI-16026/user-messages/11.md +0 -1
  183. package/prepare-for-pr/TI-16026/user-messages/12.md +0 -1
  184. package/prepare-for-pr/TI-16026/user-messages/13.md +0 -1
  185. package/prepare-for-pr/TI-16026/user-messages/14.md +0 -1
  186. package/prepare-for-pr/TI-16026/user-messages/15.md +0 -1
  187. package/prepare-for-pr/TI-16026/user-messages/16.md +0 -1
  188. package/prepare-for-pr/TI-16026/user-messages/17.md +0 -1
  189. package/prepare-for-pr/TI-16026/user-messages/18.md +0 -10
  190. package/prepare-for-pr/TI-16026/user-messages/19.md +0 -1
  191. package/prepare-for-pr/TI-16026/user-messages/20.md +0 -1
  192. package/prepare-for-pr/TI-16026/user-messages/21.md +0 -1
  193. package/prepare-for-pr/TI-16026/user-messages/22.md +0 -1
  194. package/prepare-for-pr/TI-16026/user-messages/23.md +0 -8
  195. package/prepare-for-pr/TI-16026/user-messages/24.md +0 -24
  196. package/prepare-for-pr/TI-16026/user-question.md +0 -24
  197. package/prepare-for-pr/TI-16026/verify/metrics-check.json +0 -13
  198. package/prepare-for-pr/TI-16026/verify/redaction.json +0 -38
  199. package/prepare-for-pr/TI-16026/verify/row-closure.json +0 -45
  200. package/prepare-for-pr/TI-16026/verify/s04-ws-capture.md +0 -23
  201. package/prepare-for-pr/TI-16026/verify-after.md +0 -23
  202. package/prepare-for-pr/TI-16026/verify.json +0 -80
  203. package/prepare-for-pr/TI-16026.md +0 -408
  204. package/scripts/auto-version.js +0 -69
  205. package/scripts/auto-version.sh +0 -33
  206. package/scripts/branch-auto-npm-publish.js +0 -36
  207. package/scripts/check-version.sh +0 -36
  208. package/scripts/clean-tags.sh +0 -84
  209. package/src/api/account.js +0 -7
  210. package/src/api/otp.js +0 -5
  211. package/src/util/amount.js +0 -8
  212. package/src/util/err998SentryExtra.js +0 -26
  213. package/src/util/paramStore.js +0 -139
  214. package/src/util/socketPolicy.js +0 -57
  215. package/src/util/tokenStore.js +0 -44
  216. package/test/auth_otp_v3.test.js +0 -323
  217. package/test/auth_self_timeout.test.js +0 -171
  218. package/test/request_self.test.js +0 -288
  219. package/test/withdraw_manual_cash.test.js +0 -149
  220. package/tests/session.test.mjs +0 -177
  221. package/tests/websocket.test.mjs +0 -779
@@ -1,36 +0,0 @@
1
- // 自動推送 commit + tag 並發布到 npm
2
- // 由 auto-version.sh 呼叫,接收參數:remote(遠端名稱)、branch(分支名稱)
3
-
4
- import { execSync } from 'node:child_process'
5
- import { readFileSync } from 'node:fs'
6
-
7
- // 取得遠端名稱與分支名稱(預設為 origin 和當前分支)
8
- const remote = process.argv[2] || 'origin'
9
- const branch = process.argv[3] || execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf8' }).trim()
10
-
11
- // 讀取 package.json 中的版號(此時已被 standard-version 更新過)
12
- const { version } = JSON.parse(readFileSync('package.json', 'utf8'))
13
-
14
- console.log(`Branch: ${branch}`)
15
- console.log(`Version: ${version}`)
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
- }
26
-
27
- // 發布到 npm,使用分支名稱作為 dist-tag(例如 npm install @jetthai/cuora@dev)
28
- try {
29
- execSync(`npm publish --tag ${branch}`, { stdio: 'inherit' })
30
- console.log(`✅ npm publish succeeded: ${version} (tag: ${branch})`)
31
- } catch {
32
- console.error(`❌ npm publish failed for ${version}. Please run "npm publish --tag ${branch}" manually.`)
33
- process.exit(1)
34
- }
35
-
36
- console.log(`Released ${version} on ${branch}`)
@@ -1,36 +0,0 @@
1
- #!/usr/bin/env sh
2
-
3
- # 檢查 package.json 的 version 是否符合 X.Y.Z 規範
4
- # 不符合則回退到 master 上最近一個符合規範的 tag (vX.Y.Z) 對應版號,並自動 commit
5
- # 找不到合規 tag 則 exit 1 中止流程
6
-
7
- PATTERN="^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"
8
- TAG_PATTERN="^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"
9
-
10
- CURRENT_VERSION=$(node -p "require('./package.json').version")
11
-
12
- if echo "$CURRENT_VERSION" | grep -Eq "$PATTERN"; then
13
- echo "Version $CURRENT_VERSION is valid, skipping."
14
- exit 0
15
- fi
16
-
17
- echo "Invalid version detected: $CURRENT_VERSION"
18
-
19
- # 從 HEAD 可達的 tag 中,依 commit 時間找最近一個符合 vX.Y.Z 的 tag
20
- LATEST_TAG=$(git tag -l 'v*' --merged HEAD --sort=-committerdate | grep -E "$TAG_PATTERN" | head -1)
21
-
22
- if [ -z "$LATEST_TAG" ]; then
23
- echo "ERROR: No valid vX.Y.Z tag found on current history. Aborting." >&2
24
- exit 1
25
- fi
26
-
27
- FALLBACK_VERSION=${LATEST_TAG#v}
28
- echo "Reverting version to latest valid tag: $LATEST_TAG ($FALLBACK_VERSION)"
29
-
30
- npm pkg set version="$FALLBACK_VERSION"
31
-
32
- git add package.json
33
- git commit --no-verify -m "chore: revert invalid version to $FALLBACK_VERSION"
34
-
35
- echo "Version reverted and committed. Re-run your push."
36
- exit 1
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env sh
2
-
3
- # 刪除不符合規範格式的本地與遠端 tag
4
- # 規範格式:v1.2.3(例如 v0.1.0、v1.12.123)
5
- #
6
- # 不符合規範 tag 的刪除規則:
7
- # 1. commit 不屬於任何分支 → 刪除(remote + local)
8
- # 2. commit 存在於 origin/master → 刪除(remote + local)
9
- # 3. commit 在 dev 或 qa 分支上 → 僅保留版本最新的一個,其餘刪除
10
- # 4. commit 在其他分支上 → 跳過保留
11
- PATTERN="^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"
12
-
13
- # 確保遠端 ref 為最新,避免本地 master 落後造成誤判
14
- git fetch origin --prune --tags
15
-
16
- # 刪除遠端 tag;若遠端本來就不存在則視為成功,其他失敗回傳非零並輸出錯誤訊息
17
- delete_remote_tag() {
18
- TAG=$1
19
- ERR=$(git push origin --no-verify --delete "$TAG" 2>&1)
20
- STATUS=$?
21
- if [ $STATUS -eq 0 ]; then
22
- return 0
23
- fi
24
- # 遠端本來就沒有此 tag → 視為成功
25
- case "$ERR" in
26
- *"remote ref does not exist"*|*"unable to delete"*"remote ref does not exist"*)
27
- return 0
28
- ;;
29
- esac
30
- echo " ⚠ 遠端 tag $TAG 刪除失敗,跳過本地刪除:$ERR" >&2
31
- return 1
32
- }
33
-
34
- # 安全刪除:先刪遠端,遠端成功才刪本地
35
- safe_delete_tag() {
36
- TAG=$1
37
- REASON=$2
38
- echo "刪除 tag $TAG($REASON)"
39
- if delete_remote_tag "$TAG"; then
40
- git tag -d "$TAG"
41
- fi
42
- }
43
-
44
- # 判斷 commit 是否位於 dev 或 qa 分支(含對應遠端分支)
45
- is_on_dev_or_qa() {
46
- git branch -a --contains "$1" 2>/dev/null \
47
- | sed 's/^[* ]*//' \
48
- | grep -qE '^(remotes/origin/)?(dev|qa)$'
49
- }
50
-
51
- TAGS=$(git tag -l | grep -vE "$PATTERN")
52
- if [ -n "$TAGS" ]; then
53
- echo "檢查不符合規範的 tag"
54
-
55
- # 先找出所有 commit 在 dev/qa 且未進 master 的 tag,版本最新的一個予以保留
56
- KEEP_DEVQA_TAG=$(
57
- for TAG in $TAGS; do
58
- TAG_COMMIT=$(git rev-list -n 1 "$TAG" 2>/dev/null)
59
- [ -z "$TAG_COMMIT" ] && continue
60
- git merge-base --is-ancestor "$TAG_COMMIT" origin/master 2>/dev/null && continue
61
- is_on_dev_or_qa "$TAG_COMMIT" && echo "$TAG"
62
- done | sort -V | tail -n 1
63
- )
64
-
65
- for TAG in $TAGS; do
66
- TAG_COMMIT=$(git rev-list -n 1 "$TAG" 2>/dev/null)
67
- BRANCHES=$(git branch -a --contains "$TAG_COMMIT" 2>/dev/null)
68
- if [ -z "$BRANCHES" ]; then
69
- safe_delete_tag "$TAG" "commit 不屬於任何分支"
70
- elif git merge-base --is-ancestor "$TAG_COMMIT" origin/master 2>/dev/null; then
71
- safe_delete_tag "$TAG" "commit 存在於 origin/master"
72
- elif is_on_dev_or_qa "$TAG_COMMIT"; then
73
- if [ "$TAG" = "$KEEP_DEVQA_TAG" ]; then
74
- echo "保留 tag $TAG(dev/qa 最新的一個)"
75
- else
76
- safe_delete_tag "$TAG" "dev/qa 僅保留最新的一個 tag"
77
- fi
78
- else
79
- echo "跳過 tag $TAG(commit 在其他分支上)"
80
- fi
81
- done
82
- else
83
- echo "未發現不符合規範的 tag"
84
- fi
@@ -1,7 +0,0 @@
1
- export default {
2
- bindingStatus: () => ({ url: 'account-binding/status', method: 'GET' }),
3
- applyBinding: (data) => ({ url: 'account-binding/bind', method: 'POST', params: data }),
4
- bindingVerification: (data) => ({ url: 'account-binding/acknowledge', method: 'POST', params: data }),
5
- bindPassword: (data) => ({ url: 'account-binding/bind-password', method: 'POST', params: data }),
6
- resetOtp: (data) => ({ url: 'account-binding/reset-otp', method: 'POST', params: data }),
7
- }
package/src/api/otp.js DELETED
@@ -1,5 +0,0 @@
1
- export default {
2
- verification: (data) => ({ url: 'otp-verification-point/verify', method: 'POST', params: data }),
3
- acknowledge: (data) => ({ url: 'otp-verification-point/acknowledge', method: 'POST', params: data }),
4
- reset: (data) => ({ url: 'otp-verification-point/reset-otp', method: 'POST', params: data }),
5
- }
@@ -1,8 +0,0 @@
1
- export function isAmountInRange(raw, payment) {
2
- if (!payment) return false
3
- const amount = Number(raw)
4
- if (!Number.isFinite(amount) || amount <= 0) return false
5
- const minimum = payment.minimum ?? 0
6
- const maximum = payment.maximum ?? Infinity
7
- return amount >= minimum && amount <= maximum
8
- }
@@ -1,26 +0,0 @@
1
- // ERR_998(Network Error / 404)Sentry 回報資料組裝工具
2
- // 集中組裝 tags/extra,避免在 request.js 內重複拼裝邏輯
3
- export function getErr998SentryExtra(request, config) {
4
- const method = config?.method || ''
5
- const endpoint = config?.url || ''
6
- const apiHost = request?.config?.apiURL || ''
7
- const uidSite = getUidSite()
8
-
9
- return {
10
- code: 'ERR_998',
11
- endpoint,
12
- method,
13
- site: request?.config?.clientId || '',
14
- ip: request?.clientIp || '',
15
- apiHost,
16
- uidSite,
17
- }
18
- }
19
-
20
- function getUidSite() {
21
- try {
22
- return (typeof window !== 'undefined' && window.$nuxt?.$store?.state?.userInfo?.uid_site) || ''
23
- } catch (error) {
24
- return ''
25
- }
26
- }
@@ -1,139 +0,0 @@
1
- import Cookies from 'universal-cookie'
2
- import storage from './storage.js'
3
-
4
- export const PARAM_MAX_AGE = 60 * 60 * 24 * 7
5
- export const AC_KEYS = ['ac', 'referralCode']
6
- export const FC_KEYS = ['fc', 'affiliate']
7
-
8
- const DIRTY_VALUES = ['undefined', 'null', 'NaN']
9
-
10
- const reportedOnce = new Set()
11
-
12
- function cookieJar() {
13
- return typeof document === 'undefined' ? null : new Cookies()
14
- }
15
-
16
- export function normalize(value) {
17
- if (value === undefined || value === null) return null
18
- const trimmed = String(value).trim()
19
- if (trimmed === '' || DIRTY_VALUES.includes(trimmed)) return null
20
- return trimmed
21
- }
22
-
23
- // storage.js 的 JSON.parse 未包在 try/catch 內,localStorage 若存有同名裸字串會 throw,
24
- // 未攔截會沿 xstate entry chain 往上炸掉整條 setUA→setAgent→setPixel→setKPixel→setFbclid
25
- function readLocal(name) {
26
- try {
27
- return normalize(storage.get(name))
28
- } catch (error) {
29
- return null
30
- }
31
- }
32
-
33
- function readCookie(name) {
34
- const jar = cookieJar()
35
- if (!jar) return null
36
- try {
37
- return normalize(jar.get(name, { doNotParse: true }))
38
- } catch (error) {
39
- return null
40
- }
41
- }
42
-
43
- export function readParam(urlParams, keys) {
44
- for (const key of keys) {
45
- const value = normalize(urlParams?.get?.(key))
46
- if (value) return { value, from: `url:${key}` }
47
- }
48
- for (const key of keys) {
49
- const value = readLocal(key)
50
- if (value) return { value, from: `local:${key}` }
51
- }
52
- for (const key of keys) {
53
- const value = readCookie(key)
54
- if (value) return { value, from: `cookie:${key}` }
55
- }
56
- return { value: null, from: 'none' }
57
- }
58
-
59
- export function readParamFromLocation(keys) {
60
- const search = typeof window === 'undefined' ? '' : window.location.search
61
- return readParam(new URLSearchParams(search), keys)
62
- }
63
-
64
- function report(sentry, name, medium, reason) {
65
- // 去重必須在確定送得出去之後才登錄,否則早於 sentry 注入的那次失敗會把 fingerprint 佔走,
66
- // 導致之後真正有 sentry 時被自己的去重擋掉、永遠不上報
67
- if (!sentry?.captureMessage) return
68
- const fingerprint = `${name}:${medium}:${reason}`
69
- if (reportedOnce.has(fingerprint)) return
70
- reportedOnce.add(fingerprint)
71
- sentry?.captureMessage?.(`[ParamStore] ${medium} persist ${reason}: ${name}`, {
72
- level: 'warning',
73
- tags: { feature: 'url-param-fallback', param_key: name, storage_medium: medium, failure_reason: reason },
74
- })
75
- }
76
-
77
- function clearParam(name) {
78
- const result = { local: 'ok', cookie: 'ok', cleared: true }
79
- try {
80
- storage.remove(name)
81
- } catch (error) {
82
- result.local = 'throw'
83
- }
84
- const jar = cookieJar()
85
- if (jar) {
86
- try {
87
- jar.remove(name, { path: '/' })
88
- } catch (error) {
89
- result.cookie = 'throw'
90
- }
91
- }
92
- return result
93
- }
94
-
95
- export function writeParam(name, value, options = {}) {
96
- const { sentry, allowClear = false } = options
97
- const normalized = normalize(value)
98
-
99
- if (normalized === null) {
100
- return allowClear ? clearParam(name) : { local: 'skipped', cookie: 'skipped', skipped: true }
101
- }
102
-
103
- const result = { local: 'ok', cookie: 'ok' }
104
-
105
- try {
106
- storage.set(name, normalized, { path: '/', maxAge: PARAM_MAX_AGE })
107
- } catch (error) {
108
- result.local = 'throw'
109
- }
110
- if (result.local === 'ok' && readLocal(name) !== normalized) {
111
- result.local = 'mismatch'
112
- }
113
-
114
- const jar = cookieJar()
115
- if (!jar) {
116
- result.cookie = 'unavailable'
117
- } else {
118
- try {
119
- jar.set(name, normalized, {
120
- path: '/',
121
- maxAge: PARAM_MAX_AGE,
122
- sameSite: 'lax',
123
- secure: typeof window !== 'undefined' && window.location.protocol === 'https:',
124
- })
125
- } catch (error) {
126
- result.cookie = 'throw'
127
- }
128
- if (result.cookie === 'ok' && readCookie(name) !== normalized) {
129
- result.cookie = 'mismatch'
130
- }
131
- }
132
-
133
- if (result.local !== 'ok') report(sentry, name, 'localStorage', result.local)
134
- if (result.cookie !== 'ok') report(sentry, name, 'cookie', result.cookie)
135
-
136
- return result
137
- }
138
-
139
- export default { PARAM_MAX_AGE, AC_KEYS, FC_KEYS, normalize, readParam, readParamFromLocation, writeParam }
@@ -1,57 +0,0 @@
1
- export function decideNextStep({ event, reason, err, active, ready, rejection } = {}) {
2
- if (event === 'kicked') return 'kicked'
3
- if (event === 'disconnect' && reason === 'io client disconnect') return 'none'
4
- if ((event === 'disconnect' && reason !== 'io server disconnect') || (event === 'connect_error' && active)) return 'socketio'
5
- const info = rejection || err?.data
6
- if (info) {
7
- if (info.code === 'MAX_CONNECTIONS') return 'kicked'
8
- if (info.code === 'SESSION_TOKEN_INVALID') return 'renew'
9
- if (info.retryable === false) return 'stop'
10
- if (info.retryable === true) return 'retry'
11
- }
12
- if (event === 'disconnect') return ready ? 'kicked' : 'retry'
13
- if (err?.message === 'session rejected') return 'renew'
14
- return 'retry'
15
- }
16
-
17
- export function canResume(state, currentToken, source = 'user', now = Date.now()) {
18
- if (!currentToken) return false
19
- if (currentToken !== state.lastToken) return true
20
- if (!state.blocked) return true
21
- if (state.blocked === 'stop') return false
22
- if (state.blocked === 'kicked') return source === 'user'
23
- if (state.blocked === 'exhausted') return source === 'user' || (source === 'auto' && now - state.lastAttemptAt >= 15000)
24
- return false
25
- }
26
-
27
- export function nextRetryDelay(attempt, retryAfterMs) {
28
- const count = Number.isFinite(attempt) ? Math.max(1, Math.floor(attempt)) : 1
29
- const base = Math.min(30000, 1000 * 2 ** Math.min(count - 1, 30))
30
- const floor = Number.isFinite(retryAfterMs) ? Math.max(0, retryAfterMs) : 0
31
- return Math.max(floor, Math.round(base * (0.5 + Math.random())))
32
- }
33
-
34
- export function createPushDedupe({ max = 500, ttlMs = 600000 } = {}) {
35
- const capacity = Number.isFinite(max) ? Math.max(1, Math.floor(max)) : 500
36
- const ttl = Number.isFinite(ttlMs) ? Math.max(0, ttlMs) : 600000
37
- const seen = new Map()
38
- return (eventName, data, now = Date.now()) => {
39
- for (const [key, timestamp] of seen) {
40
- if (now - timestamp >= ttl) seen.delete(key)
41
- }
42
- const messageId = data?._meta?.messageId
43
- const orderId = [data?.data?.applyId, data?.applyId, data?.data?.transactionId, data?.transactionId].find(
44
- (id) => id !== undefined && id !== null && id !== ''
45
- )
46
- const businessEvent = [data?.event, data?.data?.event].find((event) => event !== undefined && event !== null && event !== '')
47
- let key
48
- if (messageId !== undefined && messageId !== null && messageId !== '') key = JSON.stringify(['message', messageId])
49
- else if (eventName === 'payment-info' && businessEvent && orderId !== undefined && orderId !== null && orderId !== '')
50
- key = JSON.stringify(['payment', eventName, businessEvent, String(orderId)])
51
- if (!key) return false
52
- if (seen.has(key)) return true
53
- seen.set(key, now)
54
- while (seen.size > capacity) seen.delete(seen.keys().next().value)
55
- return false
56
- }
57
- }
@@ -1,44 +0,0 @@
1
- import storage from './storage.js'
2
- import { TOKEN_MAX_AGE } from './constant.js'
3
-
4
- // document.cookie 在受限的環境(sandbox iframe、停用 cookie)會直接拋錯:讀不到視為沒有,寫不進去就算了
5
- function read(name) {
6
- const prefix = `${name}=`
7
- try {
8
- const pair = document.cookie.split('; ').find((item) => item.startsWith(prefix))
9
- return pair ? decodeURIComponent(pair.slice(prefix.length)) || null : null
10
- } catch (error) {
11
- return null
12
- }
13
- }
14
-
15
- // 不帶 Domain:cookie 只屬於寫入它的網域,不跨子網域
16
- function write(name, value, maxAge) {
17
- try {
18
- const secure = location.protocol === 'https:' ? '; Secure' : ''
19
- document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=${maxAge}; SameSite=Lax${secure}`
20
- } catch (error) {
21
- console.error(`Error writing cookie: ${error}`)
22
- }
23
- }
24
-
25
- export default function createTokenStore(key) {
26
- // token 原本存在 localStorage;改放 cookie 後不沿用舊值,殘留的一併清掉
27
- storage.remove(key)
28
-
29
- const store = {
30
- get: () => read(key),
31
- set(token) {
32
- if (token) write(key, token, TOKEN_MAX_AGE)
33
- else store.clear()
34
- },
35
- // 以現有的值重寫一次,讓存活時間重新起算
36
- extend() {
37
- const token = read(key)
38
- if (token) write(key, token, TOKEN_MAX_AGE)
39
- return token
40
- },
41
- clear: () => write(key, '', 0),
42
- }
43
- return store
44
- }