@jetthai/cuora 1.1.483-dev.4 → 1.1.485-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/CHANGELOG.md +42 -2
  2. package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +14 -0
  3. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +40 -0
  4. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +41 -0
  5. package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +87 -0
  6. package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +73 -0
  7. package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +309 -0
  8. package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +245 -0
  9. package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +9 -0
  10. package/e2e/feature-map.md +61 -0
  11. package/package.json +1 -1
  12. package/prepare-for-pr/JT-1776243420.md +85 -0
  13. package/prepare-for-pr/TI-16026/STATE.md +17 -0
  14. package/prepare-for-pr/TI-16026/after-prepare-authorization.md +3 -0
  15. package/prepare-for-pr/TI-16026/analysis.md +38 -0
  16. package/prepare-for-pr/TI-16026/answer-analyze-01.md +1 -0
  17. package/prepare-for-pr/TI-16026/answer-commit-01.md +2 -0
  18. package/prepare-for-pr/TI-16026/answer-commit-02.md +1 -0
  19. package/prepare-for-pr/TI-16026/bundle.json +18 -0
  20. package/prepare-for-pr/TI-16026/checklist.md +39 -0
  21. package/prepare-for-pr/TI-16026/claude-after-model +1 -0
  22. package/prepare-for-pr/TI-16026/claude-commit-session +1 -0
  23. package/prepare-for-pr/TI-16026/claude-harvest-session +1 -0
  24. package/prepare-for-pr/TI-16026/claude-hops/01-analyze.err +1 -0
  25. package/prepare-for-pr/TI-16026/claude-hops/01-analyze.out +2 -0
  26. package/prepare-for-pr/TI-16026/claude-hops/02-analyze.err +1 -0
  27. package/prepare-for-pr/TI-16026/claude-hops/02-analyze.out +4 -0
  28. package/prepare-for-pr/TI-16026/claude-hops/03-dev.err +1 -0
  29. package/prepare-for-pr/TI-16026/claude-hops/03-dev.out +4 -0
  30. package/prepare-for-pr/TI-16026/claude-hops/04-dev.err +1 -0
  31. package/prepare-for-pr/TI-16026/claude-hops/04-dev.out +4 -0
  32. package/prepare-for-pr/TI-16026/claude-hops/05-dev.err +1 -0
  33. package/prepare-for-pr/TI-16026/claude-hops/05-dev.out +3 -0
  34. package/prepare-for-pr/TI-16026/claude-hops/06-after.err +1 -0
  35. package/prepare-for-pr/TI-16026/claude-hops/06-after.out +2 -0
  36. package/prepare-for-pr/TI-16026/claude-hops/07-commit.err +1 -0
  37. package/prepare-for-pr/TI-16026/claude-hops/07-commit.out +2 -0
  38. package/prepare-for-pr/TI-16026/claude-hops/08-commit.err +1 -0
  39. package/prepare-for-pr/TI-16026/claude-hops/08-commit.out +2 -0
  40. package/prepare-for-pr/TI-16026/claude-hops/09-commit.err +1 -0
  41. package/prepare-for-pr/TI-16026/claude-hops/09-commit.out +8 -0
  42. package/prepare-for-pr/TI-16026/claude-hops/10-harvest.err +1 -0
  43. package/prepare-for-pr/TI-16026/claude-hops/10-harvest.out +3 -0
  44. package/prepare-for-pr/TI-16026/commit-note.md +5 -0
  45. package/prepare-for-pr/TI-16026/feature-map.before.md +61 -0
  46. package/prepare-for-pr/TI-16026/harvest-redaction.out +1 -0
  47. package/prepare-for-pr/TI-16026/harvest.md +37 -0
  48. package/prepare-for-pr/TI-16026/lessons.md +5 -0
  49. package/prepare-for-pr/TI-16026/open-questions.md +6 -0
  50. package/prepare-for-pr/TI-16026/publish.md +28 -0
  51. package/prepare-for-pr/TI-16026/review-convergence-response.md +3 -0
  52. package/prepare-for-pr/TI-16026/review-input/scope.md +18 -0
  53. package/prepare-for-pr/TI-16026/review-log.md +57 -0
  54. package/prepare-for-pr/TI-16026/review-notes.md +97 -0
  55. package/prepare-for-pr/TI-16026/review-response-r1.md +7 -0
  56. package/prepare-for-pr/TI-16026/spec-proposal.md +34 -0
  57. package/prepare-for-pr/TI-16026/spec-snapshot.md +291 -0
  58. package/prepare-for-pr/TI-16026/state-log.md +35 -0
  59. package/prepare-for-pr/TI-16026/user-messages/01.md +12 -0
  60. package/prepare-for-pr/TI-16026/user-messages/02.md +20 -0
  61. package/prepare-for-pr/TI-16026/user-messages/03.md +1 -0
  62. package/prepare-for-pr/TI-16026/user-messages/04.md +1 -0
  63. package/prepare-for-pr/TI-16026/user-messages/05.md +1 -0
  64. package/prepare-for-pr/TI-16026/user-messages/06.md +1 -0
  65. package/prepare-for-pr/TI-16026/user-messages/07.md +1 -0
  66. package/prepare-for-pr/TI-16026/user-messages/08.md +1 -0
  67. package/prepare-for-pr/TI-16026/user-messages/09.md +1 -0
  68. package/prepare-for-pr/TI-16026/user-messages/10.md +1 -0
  69. package/prepare-for-pr/TI-16026/user-messages/11.md +1 -0
  70. package/prepare-for-pr/TI-16026/user-messages/12.md +1 -0
  71. package/prepare-for-pr/TI-16026/user-messages/13.md +1 -0
  72. package/prepare-for-pr/TI-16026/user-messages/14.md +1 -0
  73. package/prepare-for-pr/TI-16026/user-messages/15.md +1 -0
  74. package/prepare-for-pr/TI-16026/user-messages/16.md +1 -0
  75. package/prepare-for-pr/TI-16026/user-messages/17.md +1 -0
  76. package/prepare-for-pr/TI-16026/user-messages/18.md +10 -0
  77. package/prepare-for-pr/TI-16026/user-messages/19.md +1 -0
  78. package/prepare-for-pr/TI-16026/user-messages/20.md +1 -0
  79. package/prepare-for-pr/TI-16026/user-messages/21.md +1 -0
  80. package/prepare-for-pr/TI-16026/user-messages/22.md +1 -0
  81. package/prepare-for-pr/TI-16026/user-messages/23.md +8 -0
  82. package/prepare-for-pr/TI-16026/user-question.md +24 -0
  83. package/prepare-for-pr/TI-16026/verify-after.md +15 -0
  84. package/prepare-for-pr/TI-16026.md +408 -0
  85. package/src/machine/websocket.js +380 -311
  86. package/src/machine/withdraw/withdraw_manual_cash.js +7 -4
  87. package/src/util/socketPolicy.js +57 -0
  88. package/test/withdraw_manual_cash.test.js +149 -0
  89. package/tests/websocket.test.mjs +779 -0
package/CHANGELOG.md CHANGED
@@ -2,9 +2,49 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- ### [1.1.483-dev.4](https://github.com/jetthai/cuora-module/compare/v1.1.483-dev.2...v1.1.483-dev.4) (2026-11-16)
5
+ ### [1.1.485-dev.0](https://github.com/jetthai/cuora-module/compare/v1.1.485...v1.1.485-dev.0) (2026-11-17)
6
6
 
7
- ### [1.1.483-dev.2](https://github.com/jetthai/cuora-module/compare/v1.1.483-dev.1...v1.1.483-dev.2) (2026-11-13)
7
+ ### [1.1.483-dev.4](https://github.com/jetthai/cuora-module/compare/v1.1.483...v1.1.483-dev.4) (2026-11-16)
8
+
9
+
10
+ ### ⚠ BREAKING CHANGES
11
+
12
+ * 下游在 OTP 關卡送出 OTP_VERIFIED / OTP_SKIP 後,必須在 bindBankChecking 送出
13
+ BIND_BANK_DONE 或 BIND_BANK_SKIP,否則會停在此關卡。目前僅 client-pwa-cash 使用本套件。
14
+
15
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16
+
17
+ ### Features
18
+
19
+ * **api:** add GeeMee click-id & front-event fields to sendPixel builder ([d33e488](https://github.com/jetthai/cuora-module/commit/d33e488062f81976cff35ea43ea0f2c366a2a615))
20
+ * **payment:** 恢復 setBonusSetting API ([ba1118d](https://github.com/jetthai/cuora-module/commit/ba1118dabbdd6ae5ca2b68ddf281c8dd6d67a59d))
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * **error:** 讓新錯誤可覆寫舊狀態避免 SET_ERROR 鎖死 ([4113751](https://github.com/jetthai/cuora-module/commit/4113751ee6cb4ced8fe1dc2fda0ce9fbac21ec06))
26
+ * **otp:** confirm auto verification from user status ([b3b40d8](https://github.com/jetthai/cuora-module/commit/b3b40d8dd42d438486a2110f85564ab3d839ea72))
27
+ * **otp:** require contact data before provider completion ([f70058b](https://github.com/jetthai/cuora-module/commit/f70058b6bcbbc6d048049326700a79249d043a03))
28
+ * **release:** 拆分 branch/tag push 避免 tag 衝突導致 npm publish 被跳過 ([f2c4baa](https://github.com/jetthai/cuora-module/commit/f2c4baa7de0bfe50b6b0c70c5a2ed8749116d72a))
29
+ * **request:** 非 public 請求缺少 token 時提前返回,不再送出後端 ([065095e](https://github.com/jetthai/cuora-module/commit/065095e31ffe1cb640f9aaf6c76bbd5c6892355c))
30
+ * **request:** 非 public 請求缺少 token 時改為 reject ERR_A103,觸發登出流程 ([e46281f](https://github.com/jetthai/cuora-module/commit/e46281f3ea16679404160366e4532969c3bf02ff))
31
+ * **withdraw:** 修正法幣提款計算錯誤時的狀態轉移 ([a951ba8](https://github.com/jetthai/cuora-module/commit/a951ba803cccd1564a7dbe2645ea7c8d50f7da31))
32
+
33
+
34
+ * [JT-1784011020] feat(auth): 新增 bindBankChecking 關卡,綁銀行完成前不進入 loginSuccess ([2b26e99](https://github.com/jetthai/cuora-module/commit/2b26e99eba3d37e8f954724b53da8ee3f75bec18))
35
+
36
+ ### [1.1.485](https://github.com/jetthai/cuora-module/compare/v1.1.484...v1.1.485) (2026-11-16)
37
+
38
+ ### Features
39
+
40
+ - **websocket:** migrate socket lifecycle and shared recovery policy ([092b5af](https://github.com/jetthai/cuora-module/commit/092b5afd7ca52cd1dbad53b45896dde0a7b3c022))
41
+
42
+ ### Bug Fixes
43
+
44
+ - **otp:** confirm auto verification from user status ([6adee39](https://github.com/jetthai/cuora-module/commit/6adee399a61ec5ac81c89a30036f89b222cf3920))
45
+ - **otp:** require contact data before provider completion ([03b2ee3](https://github.com/jetthai/cuora-module/commit/03b2ee306b4380103133d3709892341aca7db393))
46
+
47
+ ### [1.1.484](https://github.com/jetthai/cuora-module/compare/v1.1.483...v1.1.484) (2026-11-16)
8
48
 
9
49
  ### [1.1.483](https://github.com/jetthai/cuora-module/compare/v1.1.482...v1.1.483) (2026-11-09)
10
50
 
@@ -0,0 +1,14 @@
1
+ # cuora-module 分支轉移紀錄
2
+
3
+ - 日期:2026-10-14。
4
+ - 使用者指示:將原 worktree 的檔案複製到 `feat/sharon/JT-1790247240-socket` 並 push。
5
+ - 來源:`/Users/sharon/Documents/git-project/.worktrees/cuora-module/feat-sharon-JT-1790247240-socket`,當時分支為 `feat/sharon/JT-1791180540-onesignal`。
6
+ - 目的:`/Users/sharon/Documents/git-project/cuora-module`,分支為 `feat/sharon/JT-1790247240-socket`。
7
+ - 轉移:`src/machine/websocket.js`、`src/util/socketPolicy.js`、`tests/websocket.test.mjs` 與既有規劃/驗證文件;10 個來源檔案 SHA-256 一致。
8
+ - 原 worktree 保留;先前複製的 `feat-sharon-JT-1790247240-socket/` 子目錄不納入提交。
9
+ - OTP 原分支 `feat/sharon/JT-1789548840-otp` 保留;未提交的 `src/machine/auth_otp_v3.js`、`test/` 存於下列 stash,內容逐檔核對一致。
10
+ - OTP stash:`a3d753f7b4582da25dfa63a7e540dc18100d3b0b`,訊息為 `preserve OTP before JT-1790247240 socket transfer`。回到 OTP 分支後可使用 `git stash apply <stash hash>` 恢復,stash 目前保留。
11
+ - 目的目錄重新執行 `node --test tests/websocket.test.mjs`:47/47 通過;`git diff --check` 通過。
12
+ - 此次提交不變更套件版本,不執行 npm 套件發布。
13
+
14
+ 之前文件的「未 commit/push」是當時的歷史驗證狀態;本次另依使用者授權提交並推送上述 socket 分支。
@@ -0,0 +1,40 @@
1
+ [
2
+ {
3
+ "repo": "client-pwa-cash",
4
+ "path": "/Users/sharon/Documents/git-project/client-pwa-cash",
5
+ "branch": "feat/sharon/JT-1790247240-socket",
6
+ "base_branch": "release",
7
+ "base_sha": "f97917bdb3115161308bc4e5a71a0d8e45477a63",
8
+ "submodules": [
9
+ {
10
+ "path": "assets/map",
11
+ "before_gitlink": "3fb527ff8740f0b132df84014baaec31d4876155",
12
+ "after_sha": "3fb527ff8740f0b132df84014baaec31d4876155",
13
+ "remote_HEAD": "refs/remotes/origin/master",
14
+ "status": ""
15
+ },
16
+ {
17
+ "path": "configs",
18
+ "before_gitlink": "22e909731d1b1eb480ac3842c9a966e70707e0fa",
19
+ "after_sha": "22e909731d1b1eb480ac3842c9a966e70707e0fa",
20
+ "remote_HEAD": "refs/remotes/origin/master",
21
+ "status": ""
22
+ },
23
+ {
24
+ "path": "resources",
25
+ "before_gitlink": "9123ff5bb93e275ef1864ed1b43a97738725ecbe",
26
+ "after_sha": "9123ff5bb93e275ef1864ed1b43a97738725ecbe",
27
+ "remote_HEAD": "refs/remotes/origin/master",
28
+ "status": ""
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ "repo": "cuora-module",
34
+ "path": "/Users/sharon/Documents/git-project/.worktrees/cuora-module/feat-sharon-JT-1790247240-socket",
35
+ "branch": "feat/sharon/JT-1790247240-socket",
36
+ "base_branch": "master",
37
+ "base_sha": "6b6cd8faf770a12257cf22235331efc85fb21e6a",
38
+ "submodules": []
39
+ }
40
+ ]
@@ -0,0 +1,41 @@
1
+ # JT-1790247240 cash/cuora 交付紀錄
2
+
3
+ cash/cuora 程式實作與本地候選包整合已完成,task review 與跨專案總審最終 PASS。正式 cash SDK 升版尚待修正版發布;目前 registry 1.1.476 不含這次修正。
4
+
5
+ | 專案 | 功能工作目錄 | 基底/branch |
6
+ | --------------- | -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
7
+ | client-pwa-cash | /Users/sharon/Documents/git-project/client-pwa-cash | origin/release f97917bdb3115161308bc4e5a71a0d8e45477a63;feat/sharon/JT-1790247240-socket |
8
+ | cuora-module | /Users/sharon/Documents/git-project/.worktrees/cuora-module/feat-sharon-JT-1790247240-socket | origin/master 6b6cd8faf770a12257cf22235331efc85fb21e6a;同名 branch |
9
+
10
+ 原 cuora-module 保留 OTP 分支與修改;所有 WebSocket 新程式在上列 worktree。PWA/SSR 完成的 production 檔案指紋已確認未變。
11
+
12
+ SDK 新增 src/util/socketPolicy.js(與 PWA 等價),重整唯一 socket owner、raw-token callback、websocket-only、ready/reset、active/retry/renew/blocked、120 秒 give-up、推播去重、UID proof/archive 與 stop cleanup。cash 保留原 deferred cuora websocket Proxy,加入 self proof metadata、user/auto、逐則推播、恢復 REST 補抓、訂單匹配及 shared GA claims。sent_orders 與後端 pixel 維持 REST 所有。
13
+
14
+ | root 最終實際驗證 | 結果/log |
15
+ | ----------------------------------------------- | ------------------------------------------------------------------------------------ |
16
+ | cash unit shell 展開 runner | 697/697,exit0;/private/tmp/jt-cash-root-final-unit.log |
17
+ | SDK 真實 XState4.25.0 unit | 47/47,exit0;/private/tmp/jt-cuora-root-final-tests.log |
18
+ | 實際 tarball 安裝後 SDK unit | 47/47,exit0;XState4.38.3/socket.io4.8.4;/private/tmp/jt-cuora-packed-tests-v2.log |
19
+ | 實際 packed SDK + cash layout integration | 5/5,exit0;/private/tmp/jt-cash-sdk-packed-integration.log |
20
+ | PWA/SSR/cuora 三份獨立 policy 表 | 327 assertions,exit0 |
21
+ | cash manifest violations | 0,exit0 |
22
+ | 修改來源格式、cash script 語法、兩端 diff check | 全通過 |
23
+ | task review/修正複審/最後跨專案總審 | PASS;renew subscriber background cleanup race 已先 RED 再 GREEN |
24
+
25
+ 候選 tarball:/private/tmp/jt-cuora-package-v2/jetthai-cuora-1.1.476.tgz(未發布、不是正式 registry 476)。來源 helper、websocket、test 打包內容逐檔與 worktree byte-identical。隔離安裝只在 /private/tmp/jt-cash-cuora-candidate-v2;正式 cash package/lock/registry SDK 未替換成測試本地 path。SDK 測試原 loader 假設 projectroot node_modules,隔離 hoistedpackage 驗證只調整暫時 test 副本為 import.meta.resolve('xstate'),production 來源未改。npm pack prepare 輸出前綴曾使 JSON parser 失敗,已正確解析並驗 archive;原 candidate 測試 loader 失敗與修正後 47/47 均記錄。
26
+
27
+ 待交付:發布修正版 SDK → cash 精確更新 package/lock/安裝版本 → 正式版本回歸與 browser/backend 驗收。沒有捏造發布版本或擅自 publish;目前程式與 candidate 驗證完成不等於 production 升級完成。
28
+
29
+ 尚未執行:真實 backend recovery/滾動重啟、六分頁 kicked、手機前背景、多站台、build、Modal Smoke。不宣稱全平台部署已完成。
30
+
31
+ 沒有 commit、push、PR、merge、publish 或 Notion 回寫。工作分支與未提交變更保留。
32
+
33
+ 詳細:[cash-module-preparation.json](cash-module-preparation.json)、[implementation-ledger.md](implementation-ledger.md)。各端 report 保存於相同任務目錄的 cash-report.md/module-report.md。
34
+
35
+ ## 2026-10-14 依使用者指定新增承接分支
36
+
37
+ cuora SDK WebSocket 程式、policy 與 47 項測試已由 `feat/sharon/JT-1791180540-onesignal` 承接;工作目錄仍為 `/Users/sharon/Documents/git-project/.worktrees/cuora-module/feat-sharon-JT-1790247240-socket`。基底仍是已審查的 `6b6cd8faf770a12257cf22235331efc85fb21e6a`,3 個程式/測試檔 SHA256 在切換前後一致。
38
+
39
+ 原 `/Users/sharon/Documents/git-project/cuora-module` 保留 `feat/sharon/JT-1789548840-otp`,auth_otp_v3.js 與 test/完整指紋及 git 狀態確認未變。新 branch 命名依使用者本次指定,其他前端 branch 不變。
40
+
41
+ 新 branch 重新驗證:`node --test tests/websocket.test.mjs` 47/47 通過,exit0;`git diff --check`通過。沒有 commit/push;工作樹變更保留。
@@ -0,0 +1,87 @@
1
+ # JT-1790247240 實作紀錄
2
+
3
+ - 使用者已授權新增功能分支並實作;最新範圍只含 PWA、SSR。
4
+ - cash/cuora 暫緩,不建立本單分支、不修改程式。限縮前已完成 tracking refs fetch,未改 source。
5
+ - Ruling: 分 repo 平行 agent — 使用者明確要求同步、各 repo 不共享修改檔案 — 若契約分歧需最後對照修正。
6
+ - Ruling: PWA 使用獨立 clone — 原 checkout assets/map 已偏離 gitlink,submodule 獨立性不可在 init 前可靠證明 — 多一次依賴安裝成本。
7
+ - Ruling: native create_worktree 未提供 repo/path 選項,cwd 為多 repo 根目錄;採 skill 指定隔離路徑與 clone。
8
+ - Ruling: SSR 保留乾淨原 checkout 開分支,遵守禁止新增單元測試層;以一次性 harness 驗證。
9
+ - Ruling: 入口規範化 URL,避免重複 frontend;不修改共用 nuxt.config/env。
10
+ - Ruling: 本次啟動授權涵蓋已列 SSR queue 與 retryAfterMs 文字下限修正。
11
+ - 準備完成:PWA base aae7902a…;SSR base 64f35607…;同名 feat/sharon/JT-1790247240-socket;完整 SHA 及 submodule 證據見 preparation.json。
12
+ - 工作進度:準備完成,PWA/SSR 實作開始。
13
+
14
+ - Ruling: 直接重讀 Notion 範例修正 brief:dedupe 回傳 true 表示重複;canResume 採 lastToken/lastAttemptAt,15 秒計自所有實際 attempt,而非只計 auto。兩 agent 已同步更正。
15
+ - SSR 最新 release 實際 layout 為 app/layouts/default.vue,替代初次計畫 client.vue 路徑。
16
+
17
+ - Root independent policy harness:node /private/tmp/jt-socket-policy-contract.mjs,exit 0,兩端合計 202 assertions 通過(實作仍在進行,最後再跑)。
18
+ - Ruling: Legacy payment 僅接受明確 event + applyId/transactionId;nested 及 top-level aliases 兩端一致,因 SSR 舊 tracking 呼叫確實取 top-level;缺事件或 ID 不猜去重。
19
+ - PWA npm ci 完成 exit 0;原 npm unit script 的引號 glob 在 Node20 不展開,沿用等價 node --test tests/unit/\*.test.cjs,避免無關 package script 變更。
20
+
21
+ - Task review PWA:WARN,3 個實際可重現 finding(give-up 後新重試預算、exhausted 額外 renew、self 前 user 重連丟失 archive);回到原 implementer 第 1 輪修正。
22
+ - Task review SSR:give-up 同問題已修;persistent sent_orders 的 first_deposit 回頁重複與空 applyId 吞 valid transactionId fallback 需修;原 implementer 第 1 輪修正。
23
+ - Cross-app policy regression 加入空/null applyId→transactionId 與有效 ID 0 邊界。
24
+ - SSR 全 lint:exit1,既有 server/plugins/locale-monitor.ts 3 個 any errors +8 warnings(baseline 未改),修改來源檔單独 lint clean;不擴大修無關程式。
25
+
26
+ - PWA task re-review PASS:22 targeted、620 full unit、追加 race harness、diff check 均 exit0。
27
+ - SSR round1 fixes 37 harness pass;剩餘 account isolation WARN 由 reviewer 以真實來源重現:tokenB/selfpending/staleuidA→userconnect→new uidB ready,錯誤保留 A 去重並 firstB 補抓。
28
+ - Ruling: SSR 與 PWA 同採 archive/defer,非空 token rotation 只待現有成功 self 確認 UID 後恢復/清除 cache;不新增 REST 驗證,不相信舊 userinfo。原 implementer 第 2 輪修正。
29
+ - Root updated policy matrix:218 assertions pass(空/nullapplyId fallback、ID0 included),最終所有修正後再驗證。
30
+
31
+ - SSR scoped round2 PASS:43/43,old/stale proof 不解除 gate、同 UID 恢復与異 UID 首次不 resync、auth/hidden/logout 驗證齊全。
32
+ - root 獨立最後驗證:PWA620/620、SSR43/43、policy218 assertions、PWA 格式/JS 语法、SSR5 來源 eslint/VuePug/manifest0violations 皆 exit0。
33
+ - Final broad review:WARN,只有 1 個確認 finding,SSR 跨世代共享失效 depositSyncPromise 使新 session 補抓被跳过(慢 REST→ 再次背景釋放重连 → 最新 resync 只等舊 promise)。
34
+ - Final 修正批次:原 SSR implementer 修 latest-generation 合并補抓、延遲 REST 回归,再做單次 scoped re-review;PWA 來源不变。
35
+
36
+ - Final batch resolved:SSR flight validity + one pending latest follow-up;old promise chain waits latest 有效結果,logout/token/unmount 拒絕晚回呼。
37
+ - root fresh SSR 驗證:45/45、5 source eslint、Vue/Pug、manifest0、diff check exit0;PWA source 及 policy 未變,先前 root620/620 與 218assertions 仍適用。
38
+ - Final scoped re-review PASS:原 doublebackground/慢 REST 與 logout2/2,unmount/tokenrotation finally2/2 追加實際源碼驗證通過。
39
+ - 工作完成狀態:PWA/SSR 程式與自動化完成、保留兩端分支與未提交變更。cash/cuora 暫緩;真實環境驗收、build/Modal Smoke 未執行。
40
+
41
+ ## PWA 移回原工作目錄
42
+
43
+ 依使用者指示,已將已審查的 5 個程式/測試檔及任務文件移入 `/Users/sharon/Documents/git-project/client-pwa`,目前分支 `feat/sharon/JT-1790247240-socket`;base 仍為 `aae7902a0c7097cedd4b886b43e42c248445ef6e`,5 檔 SHA256 與獨立 checkout 完全相同。
44
+
45
+ 移入前原目錄 release 與 submodule 均乾淨;map `fe3e9c72b818fef4b596d7cd4a4f93339b8e4ea4` 已切至已驗證的 `3fb527ff8740f0b132df84014baaec31d4876155`。原任務文件若內容不同已先備份至 `/private/tmp/jt-pwa-main-transfer-doc-backup`;獨立 checkout 保留。
46
+
47
+ 本次是將未提交變更移入本機目標分支,不自動 commit/push。
48
+
49
+ PWA 原目錄移入後驗證:`node --test tests/unit/*.test.cjs` 620/620 通過(exit0),`git diff --check`通過;5 來源/測試檔 byte-identical 及 map SHA 確認一致。log:`/private/tmp/jt-socket-pwa-main-unit.log`。
50
+
51
+ ## cash/cuora 接續實作
52
+
53
+ - 使用者已授權兩端實作,同票號同 branch;PWA/SSR 已完成不重新派工。
54
+ - cash prepare release=f97917bd…原 checkout;module master=6b6cd8fa…隔離 worktree,原 OTP 保留。
55
+ - 準備指令首次有非同步相依重疊,已確認全部 exit0 並重新順序執行 init→remote update,未報 lock 或狀態損失。
56
+ - Ruling: SDK 公開 factory/既有 events/context 保持,source/session-ready/generation/proof/claim 相容新增已在計畫授權內;不改 request/export/OTP。
57
+ - Ruling: package/lock 不捏造未發布版,隔離 candidate 验证本地 SDK 整合;正式 cash 升版需已發布修正版,測試 path 不入正式 lock。
58
+ - 介面掃描:module 產生 ready/resync/generation 及 payment claim;cash 消費其事件並作 guarded REST 補抓;共用事件由兩 agent 先約定,不能各自猜測。
59
+ - 兩 repo 功能檔案無共用寫入,依使用者先前平行授權分工,root 最後做跨 repointegration/review。
60
+
61
+ - SDK/UI 約定:AUTH_CHECKED{token,uidSite} proof-only、CHECK_SOCKET{source}、SESSION_READY{resync,generation}、ACTIVITY_INFO{data,eventName,generation}、ctx.generation、ctx.claimPaymentEvent(event,orderData) true=new,背景 disconnect preserveSession。
62
+ - Ruling: cash globalService 最小 WeakMap 記錄既有 self/preload 回應 capturedtoken,layout 只於實際 done.invoke 成功且 proof 當前時送 AUTH_CHECKED;不改 API/interceptor/authmachine/OTP,避免 staleuserinfo 冒充新身分。
63
+ - cash/module npmci 皆 exit0,cash 實際 SDK 已對齊 476;功能 SDKsource 仍未發布,後續隔離 candidate 驗整合。
64
+
65
+ - Root independent3-policycontract:327assertions exit0,含 errorpriority/cooldown/floors/TTL/capacity/emptyIDfallback/0ID。
66
+ - Ruling: equalopaque ID value 跨 applyId/transactionId 即共同 ID(cash 既有契約明示 socket.transactionId=REST.applyId);不同值僅由同一明確 payload 建立 alias,沒有共同 ID 不猜。SDK/Cash 同步、補 RED→GREEN 回歸。
67
+ - Ruling: active loss 後同 instance 未 recovered 新 ready 屬新 session,需補抓;僅連續重複 ready 不補。SDK publicgeneration 首 activeLoss 遞增、fixedcallbackepoch 獨立,避免舊 RESTflight 漏 latest 補抓。
68
+
69
+ - Candidate npm pack exit0;npm 仍執行 prepare/husky 且 stdout 包含前綴,初次 JSON 讀取失敗。已從 JSON list 位置解析並核對 3 個測試 source 檔 byte-identical;候選安裝只在/private/tmp,正式 cash package/lock 未改。
70
+
71
+ - Cash task review spec/quality PASS:source probes3/3,manifest0 及 diffcheck,report697unit/16focused/5candidateintegration;正式 SDK 升版仍待發布修正版。
72
+ - SDK task review WARN1:renew status 同步 subscriber 送 backgroundpreserve cleanup 後 continuation 無 guard 又建 socket;真實 Xstate4.25 重現。原 implementer 第 1 輪 epoch/token/aliveguard + RED→GREEN 修正,後續 scopedrereview。
73
+ - 候選包 v1 成功安裝于/tmp(XState4.38.3、socket.io4.8.4);packed tests 直接跑因測試 loader 假設 nestednode_modules/xstate 而失敗,屬 hoisted 依賴路徑的驗證腳本限制;production 包 3 來源檔 byte-identical。最終包 v2 以暫時 require.resolve loader 適配驗證,不改正式 source/npm 依賴。
74
+
75
+ - SDK round1 修正與 scopedrereview PASS:原 renewrelease repro sockets1/idle/noSocket,targeted5pass(42 未選);SDK 完整 47pass。
76
+ - root 候選 v2:打包 3 檔 byte-identical、隔離安裝、SDK47 與 actualpackedcashintegration5pass;正式 package/lock 未改。
77
+ - root 最後完整 checks:cash697、SDK47、packedSDK47、packedintegration5、policy327、manifest0、格式語法 diffcheck 都 exit0。
78
+ - Final wholecash/cuora review PASS,0 findings;原 OTP 保留,PWA/SSRsource 指紋未變。
79
+ - Task4A complete:SDK 程式與 candidate 驗證/review 完成,未發布。Task4B source complete:cash 程式與本地整合/review 完成,正式 SDK 精確升版待發布可取得版本。
80
+
81
+ ## 2026-10-14 依使用者指定新增承接分支
82
+
83
+ cuora SDK WebSocket 程式、policy 與 47 項測試已由 `feat/sharon/JT-1791180540-onesignal` 承接;工作目錄仍為 `/Users/sharon/Documents/git-project/.worktrees/cuora-module/feat-sharon-JT-1790247240-socket`。基底仍是已審查的 `6b6cd8faf770a12257cf22235331efc85fb21e6a`,3 個程式/測試檔 SHA256 在切換前後一致。
84
+
85
+ 原 `/Users/sharon/Documents/git-project/cuora-module` 保留 `feat/sharon/JT-1789548840-otp`,auth_otp_v3.js 與 test/完整指紋及 git 狀態確認未變。新 branch 命名依使用者本次指定,其他前端 branch 不變。
86
+
87
+ 新 branch 重新驗證:`node --test tests/websocket.test.mjs` 47/47 通過,exit0;`git diff --check`通過。沒有 commit/push;工作樹變更保留。
@@ -0,0 +1,73 @@
1
+ # JT-1790247240 cuora-module 實作報告
2
+
3
+ ## Change Summary
4
+
5
+ - Worktree:`/Users/sharon/Documents/git-project/.worktrees/cuora-module/feat-sharon-JT-1790247240-socket`;branch:`feat/sharon/JT-1790247240-socket`;baseline:`6b6cd8faf770a12257cf22235331efc85fb21e6a`(本次最新 `origin/master`)。依據 `/private/tmp/jt-cash-cuora-brief.md` 與 Notion 全平台連線契約,本次授權取代原 Step 4A/4B 暫緩。
6
+ - `src/util/socketPolicy.js`:四個介面 `decideNextStep`、`canResume`、`nextRetryDelay`、`createPushDedupe` 與已 review 的 PWA policy 完全相同;`cmp` exit 0。messageId 全域 opaque、legacy payment 僅使用明確 event 與非空訂單 ID(numeric 0 有效)、500 筆/10 分鐘上限。
7
+ - `src/machine/websocket.js`:保留 factory(request)、XState v4、公開 send/start/stop、既有事件、context 與 connected/idle 相容性。root callback service 是 socket 生命週期唯一 owner;公開 context 更新全部透過 `assign()`,closure 僅保存 owner 私有資源與 session cache。
8
+ - 無 token 不選線、不建立 io;同步 auth callback 讀最新 RAW token;僅 websocket;host 正規化只附一個 frontend。所有 await 前鎖定,捕捉 token/epoch;新 instance 前無條件移除舊 listener 並 disconnect,包括尚未 connected 的 instance。active Socket.IO 自動重连保留同 instance,首 loss 開始 120 秒 give-up;新有效觸發會重新選線。
9
+ - 初次 + 最多 3 自動 retry,1/2/4 秒 base、jitter 與 server retryAfterMs floor;外部 user/auto 不可越過選線、active、retry、give-up 的鎖。背景 cleanup 仍保留 outstanding retry floor。renew 最多立即一次;exhausted 額外失敗維持 exhausted,不重新取得 renew 或 retry 預算;auto 依每次實際 attempt 的 lastAttemptAt 等待至少 15 秒。
10
+ - `session-ready` 舊 string/新 object 與 recovered true 為 ready proof;connect 只更新 UI。active loss 重設 ready,但重複 loss 不重啟 give-up。首次/recovered/連續重複 ready 不 resync;曾 ready 的 fresh 非 recovered ready 才 resync。公開 generation 於失效、釋放與第一次 active loss 更新,固定 listener 使用另一個 epoch,讓同 instance 的新 session 也能使舊 REST flight 過期。
11
+ - AUTH_CHECKED 只接受與 request 最新 token 相符的既有 /self proof;換 token 先作廢舊 callback/await,verified session 暫存於 archive,收到 matching UID proof 才還原。未知 UID 延後選線與 user/auto 意圖,不讀舊 userInfo 作 proof、不新增 REST;不同 UID/logout 清 session、dedupe 與 claims。
12
+ - 四種 push 在 GA/下游 UI 副作用前去重,每則唯一 push 即時投遞 ACTIVITY_INFO,不依赖单 tick socketData 最後值。GA 保留 payment payload 與第二參數 eventID;shared claim 同時支援 REST applyId 與 socket transactionId 的相同 opaque 值,明確共同 payload 能註冊多個 alias,無共同 ID 不猜。SDK 不讀寫 sent_orders,不碰 REST pixel。
13
+ - 防止同步 subscriber race:retry/give-up 決策與鎖先完成才發布 diagnostic transition;push consumer 登出或 ready-status consumer cleanup 後不再發舊 session 事件;purchase analytics 中 token 改變後不再發舊 first_deposit。
14
+
15
+ ## Impact Scope
16
+
17
+ client-pwa-cash 需要使用以下與 implement_cash agent/root 已確認的 additive 契約。client-pwa/client-pwa-ssr 本次均未修改;SDK 既有 legacy consumer 不帶 proof 仍可 CONNECT/CHECK_SOCKET。
18
+
19
+ | 介面 | 契約 |
20
+ | --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
21
+ | `AUTH_CHECKED` | `{ token, uidSite }`,只能來自既有成功 /self;本事件不強制自動重連,僅在有先前被延後的意圖時恢復它 |
22
+ | `CHECK_SOCKET` | `{ source: 'user' \| 'auto' }`,預設 user |
23
+ | `SESSION_READY` | `{ resync: boolean, generation: number }`;layout 使用此事件判斷 REST resync |
24
+ | `ACTIVITY_INFO` | `{ data: 原始推播 payload, eventName, generation }`,每則唯一 push 均發送,payment 不再限 toast |
25
+ | `context.generation` | 可以 guard REST flight;active loss/background release 也使舊世代失效 |
26
+ | `context.claimPaymentEvent(event, orderData)` | true =新 claim,false =重複或當前 session 不安全;purchase/first_deposit 分開 claim,已知 aliases 共用。無 token/待 UID proof 回 false,無 ID 不猜、回 true |
27
+ | `DISCONNECT_SOCKET` | `{ preserveSession: true }` 為背景 cleanup,保留 session/blocked/retry floor;預設 false 為 logout/destroy,清全部 |
28
+
29
+ cash 可在 matching AUTH_CHECKED 後、CONNECT 前,將持久 sent_orders 以 applyId seed purchase 與 first_deposit claims;socket transactionId 相同值會被抑制。SDK 自己保留原 PUSH_ANALYTICS delivery,cash layout 不應再重報這份 socket GA。sent_orders 仍由 REST 寫入,REST-only backend Purchase pixel 保持 cash 所有。
30
+
31
+ 未修改 auth/OTP、request interceptor、API descriptors、exports、factory 必要參數或 package/lock 版本。原 `/Users/sharon/Documents/git-project/cuora-module` 的 OTP dirty working copy 未修改。沒有 commit、push、PR、publish、Notion 回寫。
32
+
33
+ ## Verification Method
34
+
35
+ 執行環境 Node `v20.19.6`,worktree isolated npm ci 由 root 完成(exit 0),實際安裝 XState `4.25.0`。測試載入實際 websocket source、實際 policy 與真實 XState interpret;僅替換 io 的外部 transport,搭配可控 clock/fetch/延後 selection。未加入 production-only-for-test 方法,未以 source snapshot 代替行為測試。
36
+
37
+ | 命令/階段 | 結果/exit | Log |
38
+ | ----------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ----------------------------------------------- |
39
+ | `node --test tests/websocket.test.mjs`,初始 RED | 20 tests,1 pass/19 fail,exit 1;缺少 anonymous guard、ready、claims、cleanup 等既有行為缺口 | `/private/tmp/cuora-sdk-red.log` |
40
+ | 同命令,首次 GREEN | 20/20,exit 0 | `/private/tmp/cuora-sdk-green1.log` |
41
+ | 第二 RED→GREEN(consumer logout/same-token UID/exhausted) | RED 22/25 pass、3 fail,exit 1;GREEN 25/25,exit 0 | `cuora-sdk-red2.log`/`cuora-sdk-green2.log` |
42
+ | 第三 RED→GREEN(background floor/constructor throw) | RED 25/27 pass、2 fail,exit 1;GREEN 27/27,exit 0 | `cuora-sdk-red3.log`/`cuora-sdk-green3.log` |
43
+ | 第四 RED→GREEN(auth-rejected/loss ready/aliases) | RED 27/31 pass、4 fail,exit 1;GREEN 31/31,exit 0;alias 語義後續依 root 確认調整,見第六輪 | `cuora-sdk-red4.log`/`cuora-sdk-green4.log` |
44
+ | 第五 RED→GREEN(loss/release generation) | RED 31/32 pass、1 fail,exit 1;GREEN 32/32,exit 0 | `cuora-sdk-red5.log`/`cuora-sdk-green5.log` |
45
+ | 第六 RED→GREEN(root opaque alias ruling/fresh seed) | RED 37/39 pass、2 fail,exit 1;GREEN 39/39,exit 0 | `/private/tmp/cuora-sdk-red6.log` |
46
+ | 第七 RED→GREEN(保留無 code 的 structured rejection) | RED 39/40 pass、1 fail,exit 1;GREEN 40/40,exit 0 | `/private/tmp/cuora-sdk-red7.log` |
47
+ | 第八 RED→GREEN(同步 status subscriber retry race) | RED 40/41 pass、1 fail,exit 1;GREEN 41/41,exit 0 | `/private/tmp/cuora-sdk-red8.log` |
48
+ | 第九 RED→GREEN(ready-status observer logout) | RED 41/42 pass、1 fail,exit 1;GREEN 42/42,exit 0 | `/private/tmp/cuora-sdk-red9.log` |
49
+ | 第十 RED→GREEN(purchase GA token rotation) | RED 42/43 pass、1 fail,exit 1;GREEN 43/43,exit 0 | `/private/tmp/cuora-sdk-red10.log` |
50
+ | `node --test tests/*.test.mjs`,review 前 full available suite | 43/43 pass,0 fail,exit 0 | `/private/tmp/cuora-sdk-final.log` |
51
+ | `node --test --test-name-pattern='renew status observer' tests/websocket.test.mjs`,review RED | 4 targeted:1 pass/3 fail,43 tests 因 pattern 未選;exit 1 | `/private/tmp/cuora-sdk-review-renew-red.log` |
52
+ | 同命令,review GREEN | **4/4 targeted pass**,43 tests 因 pattern 未選;exit 0 | `/private/tmp/cuora-sdk-review-renew-green.log` |
53
+ | `node --test tests/*.test.mjs`,review 後 final full available suite | **47/47 pass,0 fail/skip,exit 0** | `/private/tmp/cuora-sdk-review-full.log` |
54
+ | `./node_modules/.bin/prettier --check src/machine/websocket.js src/util/socketPolicy.js tests/websocket.test.mjs` | exit 0 | 工具输出 |
55
+ | `node --check src/machine/websocket.js`/`node --check src/util/socketPolicy.js` | 均 exit 0 | 工具输出 |
56
+ | `git diff --check` | exit 0 | 工具输出 |
57
+ | `cmp src/util/socketPolicy.js /Users/sharon/Documents/git-project/client-pwa/utils/socketPolicy.js` | exit 0,policy byte-equivalent | 工具输出 |
58
+
59
+ RED logs 的短檔名均位於 `/private/tmp/`。所有新發現的失败均記錄並修正;完整 suite 未跳過/取消測試(targeted pattern run 有明確列出的 43 個未選案例)。Repo 沒有 test/lint/build script,因此未執行不存在的 npm test/lint/build 命令。測試涵蓋 initial+3、renew/exhausted/give-up、actual lastAttemptAt、server floor、匿名、stale token/selection/logout/stop/restart、四種 push/同 tick 3 則、legacy dedupe/0/TTL/capacity、UID proof/archive、first/recovered/fresh ready/resync、cross REST/socket claims/GA payload 與 eventID、legacy public consumer,以及同步 subscriber cleanup races。
60
+
61
+ ### SDK scoped review round 1 修正
62
+
63
+ root 確認一項 WARN:renew 分支先發 `_SOCKET_STATUS`(`SESSION_TOKEN_INVALID`),再無條件執行 `attempt('auto', true)`;真實 XState 4.25 的同步 subscriber 若在 status 中發背景 preserveSession cleanup/default logout,舊 continuation 會重新選線並建第二條 socket。單純在 subscriber 換 token 也會讓舊 renewal 自動使用新身分開始 attempt。
64
+
65
+ 修正為 status 前捕捉 owner epoch/token,status 後要求 alive、epoch 未變、owner token 未變、request 最新 token 相同,才繼續 immediate renewal。未改公開 API。新四個行為案例覆蓋 background/logout/stop/token rotation:RED 精確重現前三個缺口(background/logout/rotation,stop 已通過),GREEN 後沒有多餘 selection/socket/timer/clientSocket;仍可由之後明確 user CHECK 正常恢復。完整 suite 增為 47/47。
66
+
67
+ source diff 於交付時為 `src/machine/websocket.js` 的 lifecycle 實作替換,新增 `src/util/socketPolicy.js`、`tests/websocket.test.mjs` 與本報告。新增檔案未 stage,`git diff --stat` 不含 untracked 新檔,需用 `git status --short` 同時檢查。
68
+
69
+ ## Follow-up Recommendations
70
+
71
+ - Source 保持 **1.1.476(未發布 candidate)**。正式 cash upgrade 需取得實際已發布的新 SDK 版本後再調整 release package/lock;不能假稱現有 registry 1.1.476 已含本次修正。
72
+ - root 負責 scoped review、隔離 temporary package 與 cash 真實 XState 下游整合;本報告只聲稱 SDK worktree 47 個行為測試及上述靜態檢查的結果。review 前的 temporary package v1 不含這次 guard 修正,需重打 final candidate。
73
+ - 尚未執行 browser/backend/手動網路中斷/多裝置/真實 server recovery/ModalSmoke;不得視為 pass。正式發版前需執行 Notion 驗收與 cash 實機 smoke,包含 backend REST pixel 一次、跨世代慢 REST 補抓與被踢 user-only 恢復。