@chainlesschain/personal-data-hub 0.4.29 → 0.4.31

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 (199) hide show
  1. package/lib/forensics/qq-nt-collect.js +190 -0
  2. package/lib/prompt-builder.js +15 -1
  3. package/package.json +8 -3
  4. package/__tests__/adapter-guide.test.js +0 -47
  5. package/__tests__/adapter-spec.test.js +0 -78
  6. package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
  7. package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
  8. package/__tests__/adapters/ai-chat-history.test.js +0 -396
  9. package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
  10. package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
  11. package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
  12. package/__tests__/adapters/apple-health.test.js +0 -95
  13. package/__tests__/adapters/bank-family.test.js +0 -125
  14. package/__tests__/adapters/biz-tianyancha.test.js +0 -159
  15. package/__tests__/adapters/browser-history-chrome.test.js +0 -377
  16. package/__tests__/adapters/browser-history-edge.test.js +0 -159
  17. package/__tests__/adapters/car-mercedesme.test.js +0 -74
  18. package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
  19. package/__tests__/adapters/doc-camscanner.test.js +0 -147
  20. package/__tests__/adapters/doc-platforms.test.js +0 -177
  21. package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
  22. package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
  23. package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
  24. package/__tests__/adapters/email-adapter.test.js +0 -742
  25. package/__tests__/adapters/email-classifier.test.js +0 -347
  26. package/__tests__/adapters/email-imap-session.test.js +0 -334
  27. package/__tests__/adapters/email-parser.test.js +0 -244
  28. package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
  29. package/__tests__/adapters/email-providers.test.js +0 -84
  30. package/__tests__/adapters/email-retry-progress.test.js +0 -294
  31. package/__tests__/adapters/email-templates.test.js +0 -822
  32. package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
  33. package/__tests__/adapters/finance-alipay-live.test.js +0 -258
  34. package/__tests__/adapters/finance-dcep.test.js +0 -74
  35. package/__tests__/adapters/fitness-joyrun.test.js +0 -82
  36. package/__tests__/adapters/game-genshin-live.test.js +0 -238
  37. package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
  38. package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
  39. package/__tests__/adapters/git-activity.test.js +0 -222
  40. package/__tests__/adapters/gov-12123.test.js +0 -103
  41. package/__tests__/adapters/gov-ixiamen.test.js +0 -150
  42. package/__tests__/adapters/gov-tax.test.js +0 -135
  43. package/__tests__/adapters/health-meiyou.test.js +0 -125
  44. package/__tests__/adapters/local-files.test.js +0 -264
  45. package/__tests__/adapters/local-im-pc.test.js +0 -154
  46. package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
  47. package/__tests__/adapters/music-kugou.test.js +0 -187
  48. package/__tests__/adapters/music-qq.test.js +0 -112
  49. package/__tests__/adapters/netease-music-live.test.js +0 -244
  50. package/__tests__/adapters/netease-music.test.js +0 -74
  51. package/__tests__/adapters/pc-local-discovery.test.js +0 -141
  52. package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
  53. package/__tests__/adapters/reading-family.test.js +0 -108
  54. package/__tests__/adapters/recruit-boss.test.js +0 -180
  55. package/__tests__/adapters/shell-history.test.js +0 -180
  56. package/__tests__/adapters/shopping-base.test.js +0 -179
  57. package/__tests__/adapters/shopping-dianping.test.js +0 -239
  58. package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
  59. package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
  60. package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
  61. package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
  62. package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
  63. package/__tests__/adapters/social-csdn.test.js +0 -175
  64. package/__tests__/adapters/social-dongchedi.test.js +0 -165
  65. package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
  66. package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
  67. package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
  68. package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
  69. package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
  70. package/__tests__/adapters/social-douyin-adb-usage-profile.test.js +0 -229
  71. package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -269
  72. package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
  73. package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
  74. package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
  75. package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
  76. package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
  77. package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
  78. package/__tests__/adapters/social-toutiao-adb-article.test.js +0 -155
  79. package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
  80. package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
  81. package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
  82. package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
  83. package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
  84. package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
  85. package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
  86. package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
  87. package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
  88. package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
  89. package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
  90. package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
  91. package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
  92. package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
  93. package/__tests__/adapters/social-zhihu.test.js +0 -246
  94. package/__tests__/adapters/system-data-adapter.test.js +0 -443
  95. package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
  96. package/__tests__/adapters/system-data-android.test.js +0 -519
  97. package/__tests__/adapters/system-data-disclosure.test.js +0 -153
  98. package/__tests__/adapters/travel-12306.test.js +0 -512
  99. package/__tests__/adapters/travel-amap.test.js +0 -219
  100. package/__tests__/adapters/travel-baidu-map.test.js +0 -305
  101. package/__tests__/adapters/travel-base.test.js +0 -205
  102. package/__tests__/adapters/travel-ctrip.test.js +0 -377
  103. package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
  104. package/__tests__/adapters/travel-didi.test.js +0 -204
  105. package/__tests__/adapters/travel-tencent-map.test.js +0 -207
  106. package/__tests__/adapters/travel-tongcheng.test.js +0 -289
  107. package/__tests__/adapters/video-platforms.test.js +0 -152
  108. package/__tests__/adapters/video-xigua.test.js +0 -106
  109. package/__tests__/adapters/vscode.test.js +0 -299
  110. package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
  111. package/__tests__/adapters/wechat-env-probe.test.js +0 -162
  112. package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
  113. package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
  114. package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
  115. package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
  116. package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
  117. package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
  118. package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
  119. package/__tests__/adapters/weread.test.js +0 -123
  120. package/__tests__/adapters/wework-pc.test.js +0 -124
  121. package/__tests__/adapters/win-recent.test.js +0 -192
  122. package/__tests__/analysis-skills.test.js +0 -754
  123. package/__tests__/analysis.test.js +0 -1845
  124. package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
  125. package/__tests__/batch.test.js +0 -133
  126. package/__tests__/bridges-cc-kg.test.js +0 -231
  127. package/__tests__/bridges-cc-llm.test.js +0 -191
  128. package/__tests__/bridges-cc-rag.test.js +0 -162
  129. package/__tests__/categories.test.js +0 -92
  130. package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
  131. package/__tests__/e2e/full-user-journey.test.js +0 -188
  132. package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
  133. package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
  134. package/__tests__/entity-resolver-stages.test.js +0 -411
  135. package/__tests__/entity-resolver-vault.test.js +0 -249
  136. package/__tests__/entity-resolver.test.js +0 -526
  137. package/__tests__/fitness-keep-snapshot.test.js +0 -224
  138. package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
  139. package/__tests__/ids.test.js +0 -45
  140. package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
  141. package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
  142. package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
  143. package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
  144. package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
  145. package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
  146. package/__tests__/key-providers.test.js +0 -126
  147. package/__tests__/kg-derive.test.js +0 -219
  148. package/__tests__/llm-client.test.js +0 -122
  149. package/__tests__/longtail-adapters.test.js +0 -281
  150. package/__tests__/messaging-qq-snapshot.test.js +0 -294
  151. package/__tests__/mobile-extractor-encrypted.test.js +0 -460
  152. package/__tests__/mobile-extractor.test.js +0 -288
  153. package/__tests__/mock-adapter.test.js +0 -93
  154. package/__tests__/prompt-builder.test.js +0 -249
  155. package/__tests__/query-parser.test.js +0 -365
  156. package/__tests__/rag-derive.test.js +0 -169
  157. package/__tests__/registry-readiness.test.js +0 -292
  158. package/__tests__/registry.test.js +0 -420
  159. package/__tests__/salvage-ingest.test.js +0 -97
  160. package/__tests__/schemas.test.js +0 -331
  161. package/__tests__/shopping-adapters.test.js +0 -392
  162. package/__tests__/shopping-eleme-snapshot.test.js +0 -454
  163. package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
  164. package/__tests__/shopping-snapshot.test.js +0 -438
  165. package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
  166. package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
  167. package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
  168. package/__tests__/sidecar-supervisor.test.js +0 -128
  169. package/__tests__/sign-providers.test.js +0 -62
  170. package/__tests__/social-adapters.test.js +0 -280
  171. package/__tests__/social-bilibili-snapshot.test.js +0 -278
  172. package/__tests__/social-douban-snapshot.test.js +0 -351
  173. package/__tests__/social-douyin-im-direct-read.test.js +0 -377
  174. package/__tests__/social-douyin-salvage-collector.test.js +0 -98
  175. package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
  176. package/__tests__/social-douyin-snapshot.test.js +0 -256
  177. package/__tests__/social-kuaishou-snapshot.test.js +0 -362
  178. package/__tests__/social-toutiao-snapshot.test.js +0 -366
  179. package/__tests__/social-weibo-snapshot.test.js +0 -234
  180. package/__tests__/social-weibo-sqlite-device.test.js +0 -174
  181. package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
  182. package/__tests__/sqlite-leaf-salvage.test.js +0 -97
  183. package/__tests__/travel-adapters.test.js +0 -483
  184. package/__tests__/travel-maps-snapshot.test.js +0 -426
  185. package/__tests__/vault-driver-error.test.js +0 -74
  186. package/__tests__/vault-search-helpers.test.js +0 -104
  187. package/__tests__/vault-search.test.js +0 -423
  188. package/__tests__/vault.test.js +0 -767
  189. package/__tests__/wechat-adapter.test.js +0 -594
  190. package/__tests__/whatsapp-adapter.test.js +0 -138
  191. package/scripts/_make-fixture-all.js +0 -126
  192. package/scripts/_make-fixture-contacts.js +0 -84
  193. package/scripts/evaluate-entity-resolver.js +0 -213
  194. package/scripts/run-native-tests-sandbox.sh +0 -55
  195. package/scripts/smoke-phase-5-5.js +0 -196
  196. package/scripts/smoke-phase-5-7.js +0 -181
  197. package/scripts/smoke-system-data-contacts.js +0 -309
  198. package/scripts/smoke-system-data.js +0 -312
  199. package/vitest.config.js +0 -88
@@ -1,182 +0,0 @@
1
- /**
2
- * FAMILY-23 v0.1 — 王者荣耀 / 作业帮 / 支付宝 / 华为学习中心 collector scaffold 测试。
3
- * 各平台: 契约 + extractUid + sync NO_INPUT throw + snapshot sync + normalize → 合法 batch。
4
- */
5
- import { describe, it, expect } from "vitest";
6
- const fs = require("node:fs");
7
- const os = require("node:os");
8
- const path = require("node:path");
9
- const lib = require("../../lib");
10
- const { assertAdapter } = require("../../lib/adapter-spec");
11
- const { validateBatch } = require("../../lib/batch");
12
-
13
- const {
14
- HonorOfKingsApiClient,
15
- } = require("../../lib/adapters/game-honor-of-kings/api-client");
16
- const {
17
- ZuoyebangApiClient,
18
- } = require("../../lib/adapters/edu-zuoyebang/api-client");
19
- const { AlipayApiClient } = require("../../lib/adapters/finance-alipay/api-client");
20
- const {
21
- HuaweiLearningApiClient,
22
- } = require("../../lib/adapters/edu-huawei-learning/api-client");
23
-
24
- function writeSnapshot(obj) {
25
- const p = path.join(
26
- os.tmpdir(),
27
- `fam23-snap-${Date.now()}-${Math.random().toString(36).slice(2)}.json`,
28
- );
29
- fs.writeFileSync(p, JSON.stringify(obj), "utf-8");
30
- return p;
31
- }
32
-
33
- // platform → { Adapter, name, sensitivity, eventKind, eventSubtype, idKey }
34
- const PLATFORMS = [
35
- {
36
- label: "王者荣耀",
37
- Adapter: lib.HonorOfKingsAdapter,
38
- name: "game-honor-of-kings",
39
- version: "0.2.0", // live 营地 fetcher landed (see game-honor-of-kings-live.test.js)
40
- sensitivity: "medium",
41
- eventKind: "play",
42
- eventSubtype: "media",
43
- idKey: "hok-uid",
44
- sample: { kind: "play", id: "p1", durationMs: 1800000, mode: "rank", startAt: 1700000000000 },
45
- },
46
- {
47
- label: "作业帮",
48
- Adapter: lib.ZuoyebangAdapter,
49
- name: "edu-zuoyebang",
50
- version: "0.2.0", // live web fetcher landed (see edu-zuoyebang-live.test.js)
51
- sensitivity: "medium",
52
- eventKind: "study",
53
- eventSubtype: "other",
54
- idKey: "zuoyebang-uid",
55
- sample: { kind: "study", id: "s1", subject: "math", durationMs: 1200000, startAt: 1700000000000 },
56
- },
57
- {
58
- label: "支付宝",
59
- Adapter: lib.AlipayAdapter,
60
- name: "finance-alipay",
61
- version: "0.2.0", // live mobilegw fetcher landed (see finance-alipay-live.test.js)
62
- sensitivity: "high",
63
- eventKind: "order",
64
- eventSubtype: "payment",
65
- idKey: "alipay-uid",
66
- sample: { kind: "order", id: "o1", merchant: "便利店", amountFen: 350, direction: "out", startAt: 1700000000000 },
67
- },
68
- {
69
- label: "华为学习中心",
70
- Adapter: lib.HuaweiLearningAdapter,
71
- name: "edu-huawei-learning",
72
- version: "0.2.0", // live web fetcher landed (see edu-huawei-learning-live.test.js)
73
- sensitivity: "medium",
74
- eventKind: "study",
75
- eventSubtype: "other",
76
- idKey: "huawei-learning-uid",
77
- sample: { kind: "study", id: "h1", course: "物理", durationMs: 900000, startAt: 1700000000000 },
78
- },
79
- ];
80
-
81
- for (const P of PLATFORMS) {
82
- describe(`${P.label} (${P.name}) — FAMILY-23 v0.1`, () => {
83
- it("contract conformance + sensitivity", () => {
84
- const a = new P.Adapter();
85
- expect(assertAdapter(a).ok).toBe(true);
86
- expect(a.name).toBe(P.name);
87
- expect(a.version).toBe(P.version || "0.1.0");
88
- expect(a.dataDisclosure.sensitivity).toBe(P.sensitivity);
89
- expect(a.capabilities).toContain("sync:snapshot");
90
- });
91
-
92
- it("sync throws NO_INPUT without inputPath", async () => {
93
- const a = new P.Adapter();
94
- await expect(async () => {
95
- for await (const _ of a.sync({})) void _;
96
- }).rejects.toThrow(/inputPath/);
97
- });
98
-
99
- it("sync via snapshot yields profile + platform event", async () => {
100
- const snapPath = writeSnapshot({
101
- schemaVersion: 1,
102
- snapshottedAt: 1700000000000,
103
- account: { uid: "12345", displayName: "kid" },
104
- events: [
105
- { kind: "profile", id: "profile-12345", uid: "12345", nickname: "kid" },
106
- P.sample,
107
- ],
108
- });
109
- try {
110
- const a = new P.Adapter();
111
- const raws = [];
112
- for await (const r of a.sync({ inputPath: snapPath })) raws.push(r);
113
- expect(raws).toHaveLength(2);
114
- expect(raws[0].kind).toBe("profile");
115
- expect(raws[1].kind).toBe(P.eventKind);
116
- } finally {
117
- fs.unlinkSync(snapPath);
118
- }
119
- });
120
-
121
- it("normalize profile → person-self with platform uid; event → valid subtype", () => {
122
- const a = new P.Adapter();
123
- const profileBatch = a.normalize({
124
- adapter: P.name,
125
- kind: "profile",
126
- originalId: `${P.name}:profile:12345`,
127
- capturedAt: 1700000000000,
128
- payload: { kind: "profile", uid: "12345", nickname: "kid" },
129
- });
130
- expect(validateBatch(profileBatch).valid).toBe(true);
131
- expect(profileBatch.persons[0].subtype).toBe("self");
132
- expect(profileBatch.persons[0].identifiers[P.idKey]).toEqual(["12345"]);
133
-
134
- const eventBatch = a.normalize({
135
- adapter: P.name,
136
- kind: P.eventKind,
137
- originalId: `${P.name}:${P.eventKind}:1`,
138
- capturedAt: 1700000000000,
139
- payload: P.sample,
140
- });
141
- expect(validateBatch(eventBatch).valid).toBe(true);
142
- expect(eventBatch.events[0].subtype).toBe(P.eventSubtype);
143
- });
144
-
145
- it("normalize throws on missing payload", () => {
146
- const a = new P.Adapter();
147
- expect(() => a.normalize({})).toThrow(/payload missing/);
148
- });
149
- });
150
- }
151
-
152
- describe("FAMILY-23 extractUid cookie scrape", () => {
153
- it("王者荣耀: openid > uin > tencent_uid", () => {
154
- const c = new HonorOfKingsApiClient();
155
- expect(c.extractUid("openid=oABC1234XYZ; foo=bar")).toBe("oABC1234XYZ");
156
- expect(c.extractUid("uin=o0012345; x=y")).toBe("12345");
157
- expect(c.extractUid("tencent_uid=678; z=1")).toBe("678");
158
- expect(c.extractUid("foo=bar")).toBeNull();
159
- expect(c.lastError.code).toBe(-7);
160
- });
161
-
162
- it("作业帮: uid / student_id / passport_uid (opaque ZYBUSS → null)", () => {
163
- const c = new ZuoyebangApiClient();
164
- expect(c.extractUid("uid=111; ZYBUSS=opaque")).toBe("111");
165
- expect(c.extractUid("student_id=222")).toBe("222");
166
- expect(c.extractUid("ZYBUSS=onlyopaquetoken")).toBeNull();
167
- });
168
-
169
- it("支付宝: alipay_uid / userId / loginUserId", () => {
170
- const c = new AlipayApiClient();
171
- expect(c.extractUid("alipay_uid=2088123; t=x")).toBe("2088123");
172
- expect(c.extractUid("userId=999")).toBe("999");
173
- expect(c.extractUid("ALIPAYJSESSIONID=abc")).toBeNull();
174
- });
175
-
176
- it("华为学习中心: accountId / userId / huaweiUid", () => {
177
- const c = new HuaweiLearningApiClient();
178
- expect(c.extractUid("accountId=555; deviceId=abc")).toBe("555");
179
- expect(c.extractUid("huaweiUid=777")).toBe("777");
180
- expect(c.extractUid("deviceId=nonnumeric")).toBeNull();
181
- });
182
- });
@@ -1,258 +0,0 @@
1
- /**
2
- * FAMILY-23 v0.2 — finance-alipay LIVE mobilegw fetcher tests.
3
- * cookie (支付宝会话) → mgw.htm bill-list → snapshot-shaped events + adapter
4
- * live sync + signProvider seam + amount/direction derivation + error mapping.
5
- * All network via injected fetch. Endpoint shapes are best-effort (see
6
- * api-client header) — these tests pin the REQUEST CONSTRUCTION + PARSING
7
- * contract, not the live server, which can't be verified here.
8
- */
9
- "use strict";
10
-
11
- import { describe, it, expect } from "vitest";
12
-
13
- const { AlipayAdapter } = require("../../lib");
14
- const {
15
- AlipayApiClient,
16
- parseAmountYuan,
17
- deriveDirection,
18
- } = require("../../lib/adapters/finance-alipay/api-client");
19
- const { validateBatch } = require("../../lib/batch");
20
-
21
- const COOKIE = "ALIPAYJSESSIONID=sess-abc; userId=2088123";
22
- const COOKIE_TOKEN_ONLY = "ALIPAYJSESSIONID=sess-abc";
23
-
24
- function makeFetch(routes, calls) {
25
- return async (url, init) => {
26
- calls.push({
27
- url,
28
- body: (init && init.body) || null,
29
- headers: (init && init.headers) || {},
30
- });
31
- const route = routes.find((r) => url.includes(r.match));
32
- if (!route) return { ok: false, status: 404, text: async () => "not mapped" };
33
- return {
34
- ok: route.status ? route.status >= 200 && route.status < 300 : true,
35
- status: route.status || 200,
36
- text: async () =>
37
- typeof route.body === "string" ? route.body : JSON.stringify(route.body),
38
- };
39
- };
40
- }
41
-
42
- async function collect(iter) {
43
- const out = [];
44
- for await (const r of iter) out.push(r);
45
- return out;
46
- }
47
-
48
- describe("alipay amount/direction derivation", () => {
49
- it("parseAmountYuan handles number / signed string / currency noise", () => {
50
- expect(parseAmountYuan(12.5)).toEqual({ amountFen: 1250, sign: 1 });
51
- expect(parseAmountYuan("-25.00")).toEqual({ amountFen: 2500, sign: -1 });
52
- expect(parseAmountYuan("+3.50")).toEqual({ amountFen: 350, sign: 1 });
53
- expect(parseAmountYuan("¥ 1,200.00")).toEqual({ amountFen: 120000, sign: 1 });
54
- expect(parseAmountYuan("abc")).toBeNull();
55
- expect(parseAmountYuan(null)).toBeNull();
56
- });
57
-
58
- it("deriveDirection: explicit field wins, then amount sign, default out", () => {
59
- expect(deriveDirection("收入", -1)).toBe("in");
60
- expect(deriveDirection("支出", 1)).toBe("out");
61
- expect(deriveDirection("INCOME", 0)).toBe("in");
62
- expect(deriveDirection(null, 1)).toBe("in");
63
- expect(deriveDirection(null, -1)).toBe("out");
64
- expect(deriveDirection(null, 0)).toBe("out");
65
- });
66
- });
67
-
68
- describe("AlipayApiClient session probe", () => {
69
- it("hasSession accepts session token or numeric uid; rejects neither", () => {
70
- const c = new AlipayApiClient();
71
- expect(c.hasSession(COOKIE_TOKEN_ONLY)).toBe(true);
72
- expect(c.hasSession("userId=2088123")).toBe(true);
73
- expect(c.hasSession("foo=bar")).toBe(false);
74
- expect(c.lastError.code).toBe(-7);
75
- });
76
- });
77
-
78
- describe("AlipayApiClient.fetchSnapshot — live (mocked fetch)", () => {
79
- it("POSTs form-encoded operationType+requestData with cookie; parses bills", async () => {
80
- const calls = [];
81
- const fetch = makeFetch(
82
- [
83
- {
84
- match: "/mgw.htm",
85
- body: {
86
- resultStatus: 1000,
87
- result: {
88
- success: true,
89
- billList: [
90
- { billId: "b1", displayName: "便利店", amount: "-12.50", gmtCreate: 1700000000 },
91
- { tradeNo: "b2", merchantName: "红包", amount: "+5.00", inOut: "收入", createTime: "1700003600" },
92
- ],
93
- },
94
- },
95
- },
96
- ],
97
- calls,
98
- );
99
- const client = new AlipayApiClient({ fetch });
100
- const result = await client.fetchSnapshot(COOKIE);
101
- // profile derived from cookie scrape (no extra op)
102
- expect(result.account).toEqual({ uid: "2088123", displayName: null });
103
- const profile = result.events.find((e) => e.kind === "profile");
104
- expect(profile).toMatchObject({ uid: "2088123" });
105
- const orders = result.events.filter((e) => e.kind === "order");
106
- expect(orders).toHaveLength(2);
107
- expect(orders[0]).toMatchObject({
108
- id: "order-b1",
109
- merchant: "便利店",
110
- amountFen: 1250,
111
- direction: "out",
112
- startAt: 1700000000000,
113
- });
114
- expect(orders[1]).toMatchObject({
115
- id: "order-b2",
116
- merchant: "红包",
117
- amountFen: 500,
118
- direction: "in",
119
- startAt: 1700003600000,
120
- });
121
- const call = calls[0];
122
- expect(call.headers.Cookie).toBe(COOKIE);
123
- expect(call.headers["Content-Type"]).toContain("application/x-www-form-urlencoded");
124
- expect(call.body).toContain("operationType=alipay.mobile.bill.list");
125
- expect(call.body).toContain("requestData=");
126
- });
127
-
128
- it("parses result-as-JSON-string envelope (mgw double-encoding)", async () => {
129
- const fetch = makeFetch(
130
- [
131
- {
132
- match: "/mgw.htm",
133
- body: {
134
- resultStatus: 1000,
135
- result: JSON.stringify({ success: true, list: [{ id: "s1", title: "公交", amount: "-2.00", tradeTime: 1700000000 }] }),
136
- },
137
- },
138
- ],
139
- [],
140
- );
141
- const client = new AlipayApiClient({ fetch });
142
- const result = await client.fetchSnapshot(COOKIE_TOKEN_ONLY);
143
- // token-only cookie → no profile event, account null, orders still flow
144
- expect(result.account).toBeNull();
145
- expect(result.events.every((e) => e.kind === "order")).toBe(true);
146
- expect(result.events[0]).toMatchObject({ merchant: "公交", amountFen: 200, direction: "out" });
147
- });
148
-
149
- it("signProvider headers are merged into the request", async () => {
150
- const calls = [];
151
- const fetch = makeFetch(
152
- [{ match: "/mgw.htm", body: { resultStatus: 1000, result: { success: true, billList: [] } } }],
153
- calls,
154
- );
155
- const signProvider = {
156
- buildHeaders: async ({ operationType }) => ({ "X-Sign": `sig-of-${operationType}` }),
157
- };
158
- const client = new AlipayApiClient({ fetch, signProvider });
159
- await client.fetchSnapshot(COOKIE);
160
- expect(calls[0].headers["X-Sign"]).toBe("sig-of-alipay.mobile.bill.list");
161
- });
162
-
163
- it("maps mgw gateway error (resultStatus != 1000) to null + lastError", async () => {
164
- const fetch = makeFetch(
165
- [{ match: "/mgw.htm", body: { resultStatus: 2000, memo: "登录超时" } }],
166
- [],
167
- );
168
- const client = new AlipayApiClient({ fetch });
169
- expect(await client.fetchSnapshot(COOKIE)).toBeNull();
170
- expect(client.lastError.code).toBe(2000);
171
- expect(client.lastError.message).toContain("登录超时");
172
- });
173
-
174
- it("maps business failure (success:false) to null + lastError -6", async () => {
175
- const fetch = makeFetch(
176
- [{ match: "/mgw.htm", body: { resultStatus: 1000, result: { success: false, resultMessage: "无权限" } } }],
177
- [],
178
- );
179
- const client = new AlipayApiClient({ fetch });
180
- expect(await client.fetchSnapshot(COOKIE)).toBeNull();
181
- expect(client.lastError.code).toBe(-6);
182
- expect(client.lastError.message).toContain("无权限");
183
- });
184
-
185
- it("no session cookie → null + lastError -7 (no network)", async () => {
186
- const calls = [];
187
- const client = new AlipayApiClient({ fetch: makeFetch([], calls) });
188
- expect(await client.fetchSnapshot("foo=bar")).toBeNull();
189
- expect(client.lastError.code).toBe(-7);
190
- expect(calls).toHaveLength(0);
191
- });
192
-
193
- it("sign failure → null + lastError -5 (no network)", async () => {
194
- const calls = [];
195
- const client = new AlipayApiClient({
196
- fetch: makeFetch([], calls),
197
- signProvider: { buildHeaders: () => { throw new Error("key missing"); } },
198
- });
199
- expect(await client.fetchSnapshot(COOKIE)).toBeNull();
200
- expect(client.lastError.code).toBe(-5);
201
- expect(calls).toHaveLength(0);
202
- });
203
- });
204
-
205
- describe("AlipayAdapter — cookie (live) sync mode", () => {
206
- it("authenticate accepts session cookie; rejects sessionless", async () => {
207
- const a = new AlipayAdapter();
208
- expect((await a.authenticate({ cookie: COOKIE })).mode).toBe("cookie");
209
- const bad = await a.authenticate({ cookie: "foo=bar" });
210
- expect(bad.ok).toBe(false);
211
- expect(bad.reason).toBe("INVALID_COOKIE");
212
- });
213
-
214
- it("version/capabilities reflect v0.2 live mode", () => {
215
- const a = new AlipayAdapter();
216
- expect(a.version).toBe("0.2.0");
217
- expect(a.capabilities).toContain("sync:cookie");
218
- });
219
-
220
- it("sync via cookie yields profile+order raws → valid normalized batch", async () => {
221
- const fetch = makeFetch(
222
- [
223
- {
224
- match: "/mgw.htm",
225
- body: {
226
- resultStatus: 1000,
227
- result: { success: true, billList: [{ billId: "b1", displayName: "便利店", amount: "-12.50", gmtCreate: 1700000000 }] },
228
- },
229
- },
230
- ],
231
- [],
232
- );
233
- const a = new AlipayAdapter();
234
- const raws = await collect(a.sync({ cookie: COOKIE, fetch }));
235
- expect(raws.map((r) => r.kind).sort()).toEqual(["order", "profile"]);
236
- const profileRaw = raws.find((r) => r.kind === "profile");
237
- expect(profileRaw.originalId).toBe("alipay:profile:profile-2088123");
238
-
239
- for (const raw of raws) {
240
- expect(validateBatch(a.normalize(raw)).valid).toBe(true);
241
- }
242
- const profileBatch = a.normalize(profileRaw);
243
- expect(profileBatch.persons[0].identifiers["alipay-uid"]).toEqual(["2088123"]);
244
- const orderBatch = a.normalize(raws.find((r) => r.kind === "order"));
245
- expect(orderBatch.events[0].subtype).toBe("payment");
246
- expect(orderBatch.events[0].extra.amountFen).toBe(1250);
247
- expect(orderBatch.events[0].extra.direction).toBe("out");
248
- });
249
-
250
- it("sync via cookie throws (mapped lastError) on gateway error", async () => {
251
- const fetch = makeFetch(
252
- [{ match: "/mgw.htm", body: { resultStatus: 2000, memo: "登录超时" } }],
253
- [],
254
- );
255
- const a = new AlipayAdapter();
256
- await expect(collect(a.sync({ cookie: COOKIE, fetch }))).rejects.toThrow(/登录超时|code 2000/);
257
- });
258
- });
@@ -1,74 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
- const fs = require("node:fs");
5
- const path = require("node:path");
6
- const os = require("node:os");
7
- const crypto = require("node:crypto");
8
-
9
- const dc = require("../../lib/adapters/finance-dcep");
10
-
11
- function writeTmp(content) {
12
- const p = path.join(os.tmpdir(), `cc-dcep-${crypto.randomUUID()}.json`);
13
- fs.writeFileSync(p, content, "utf-8");
14
- return p;
15
- }
16
- async function collect(gen) {
17
- const out = [];
18
- for await (const x of gen) out.push(x);
19
- return out;
20
- }
21
- const COOKIES = "DCEP_SSO=abc";
22
-
23
- describe("finance-dcep", () => {
24
- it("name/version + mappers", () => {
25
- expect(dc.NAME).toBe("finance-dcep");
26
- expect(dc.normDirection({ direction: "收款" })).toBe("receive");
27
- expect(dc.normDirection({ amount: -5 })).toBe("pay");
28
- const t = dc.mapTx({ txId: "X1", time: 1716383000, amount: -12.5, merchant: "便利店", subWallet: "中行子钱包" });
29
- expect(t).toMatchObject({ txId: "X1", direction: "pay", counterparty: "便利店", walletType: "中行子钱包" });
30
- expect(t.amount).toBe(12.5);
31
- expect(dc.mapTx({ amount: 1 })).toBe(null);
32
- });
33
-
34
- it("snapshot → PAYMENT event; cookie-api unverified + sign", async () => {
35
- const SNAP = JSON.stringify({
36
- schemaVersion: 1,
37
- snapshottedAt: 1716383000000,
38
- account: { userId: "u1" },
39
- events: [{ kind: "transaction", id: "tx-X1", txId: "X1", time: 1716383000, amount: 12.5, direction: "pay", counterparty: "便利店" }],
40
- });
41
- const p = writeTmp(SNAP);
42
- try {
43
- const a = new dc.DcepAdapter();
44
- const items = await collect(a.sync({ inputPath: p }));
45
- expect(items).toHaveLength(1);
46
- const b = a.normalize(items[0]);
47
- expect(b.events[0].subtype).toBe("payment");
48
- expect(b.events[0].content.title).toContain("付款");
49
- expect(b.events[0].extra.amount).toBe(12.5);
50
- expect(items[0].originalId).toBe("dcep:transaction:X1");
51
- } finally {
52
- fs.unlinkSync(p);
53
- }
54
-
55
- let signed = 0;
56
- const a = new dc.DcepAdapter({
57
- account: { cookies: COOKIES, userId: "u1" },
58
- signProvider: async () => { signed += 1; return "sig"; },
59
- fetchFn: async ({ query }) => (query.page > 1 ? { list: [] } : { list: [{ txId: "X9", time: 1716383000, amount: 9.9, direction: "receive" }] }),
60
- });
61
- expect(await a.authenticate()).toMatchObject({ ok: true, mode: "cookie", unverified: true });
62
- const items = await collect(a.sync({}));
63
- expect(items).toHaveLength(1);
64
- expect(items[0].originalId).toBe("dcep:transaction:X9");
65
- expect(signed).toBeGreaterThan(0);
66
- });
67
-
68
- it("high sensitivity + legalGate; default fetch / no input throw", async () => {
69
- expect(new dc.DcepAdapter().dataDisclosure.sensitivity).toBe("high");
70
- expect(new dc.DcepAdapter().dataDisclosure.legalGate).toBe(true);
71
- await expect(collect(new dc.DcepAdapter({ account: { cookies: COOKIES } }).sync({}))).rejects.toThrow(/no fetchFn/);
72
- await expect(collect(new dc.DcepAdapter().sync({}))).rejects.toThrow(/needs opts.inputPath/);
73
- });
74
- });
@@ -1,82 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect } from "vitest";
4
- const fs = require("node:fs");
5
- const path = require("node:path");
6
- const os = require("node:os");
7
- const crypto = require("node:crypto");
8
-
9
- const jr = require("../../lib/adapters/fitness-joyrun");
10
-
11
- function writeTmp(content) {
12
- const p = path.join(os.tmpdir(), `cc-jr-${crypto.randomUUID()}.json`);
13
- fs.writeFileSync(p, content, "utf-8");
14
- return p;
15
- }
16
- async function collect(gen) {
17
- const out = [];
18
- for await (const x of gen) out.push(x);
19
- return out;
20
- }
21
- const COOKIES = "joyrun_sid=abc";
22
-
23
- describe("fitness-joyrun", () => {
24
- it("name + mapRun (meter wins; km*1000 fallback; no id → null)", () => {
25
- expect(jr.NAME).toBe("fitness-joyrun");
26
- const r = jr.mapRun({ fid: "R1", starttime: 1716383000, meter: 5230, second: 1800, pace: 344, dohas: 320, stepcount: 6400 });
27
- expect(r).toMatchObject({ runId: "R1", distanceMeters: 5230, durationSec: 1800, paceSecPerKm: 344, calories: 320, steps: 6400 });
28
- expect(r.timeMs).toBe(1716383000000);
29
- // distance given as km (5.23) with no meter field → *1000
30
- expect(jr.mapRun({ id: "R2", distance: 5.23 }).distanceMeters).toBeCloseTo(5230, 0);
31
- expect(jr.mapRun({ meter: 100 })).toBe(null);
32
- });
33
- it("extractList tolerant", () => {
34
- expect(jr.extractList({ data: { runs: [{ fid: 1 }] } })).toHaveLength(1);
35
- expect(jr.extractList({ list: [{ fid: 1 }] })).toHaveLength(1);
36
- expect(jr.extractList({})).toEqual([]);
37
- });
38
-
39
- it("snapshot → OTHER event with km title + run extras", async () => {
40
- const SNAP = JSON.stringify({
41
- schemaVersion: 1,
42
- snapshottedAt: 1716383000000,
43
- account: { userId: "u1" },
44
- events: [{ kind: "run", id: "r-R1", runId: "R1", time: 1716383000, distanceMeters: 5230, durationSec: 1800, paceSecPerKm: 344, calories: 320 }],
45
- });
46
- const p = writeTmp(SNAP);
47
- try {
48
- const a = new jr.JoyrunAdapter();
49
- const items = await collect(a.sync({ inputPath: p }));
50
- expect(items).toHaveLength(1);
51
- const b = a.normalize(items[0]);
52
- expect(b.events[0].subtype).toBe("other");
53
- expect(b.events[0].content.title).toBe("跑步 5.23 km");
54
- expect(b.events[0].extra.distanceMeters).toBe(5230);
55
- expect(b.events[0].extra.calories).toBe(320);
56
- expect(items[0].originalId).toBe("joyrun:run:R1");
57
- } finally {
58
- fs.unlinkSync(p);
59
- }
60
- });
61
-
62
- it("cookie-api: unverified flag + sign seam + paginate", async () => {
63
- let signed = 0;
64
- const a = new jr.JoyrunAdapter({
65
- account: { cookies: COOKIES, userId: "u1" },
66
- signProvider: async () => { signed += 1; return "sig"; },
67
- fetchFn: async ({ query }) => (query.page > 1 ? { list: [] } : { data: { runs: [{ fid: "R9", starttime: 1716383000, meter: 10000, second: 3600 }] } }),
68
- });
69
- expect(await a.authenticate()).toMatchObject({ ok: true, mode: "cookie", unverified: true });
70
- const items = await collect(a.sync({}));
71
- expect(items).toHaveLength(1);
72
- expect(items[0].originalId).toBe("joyrun:run:R9");
73
- expect(signed).toBeGreaterThan(0);
74
- });
75
-
76
- it("medium sensitivity (GPS route); default fetch / no input throw", async () => {
77
- expect(new jr.JoyrunAdapter().dataDisclosure.sensitivity).toBe("medium");
78
- expect(new jr.JoyrunAdapter().dataDisclosure.legalGate).toBe(false);
79
- await expect(collect(new jr.JoyrunAdapter({ account: { cookies: COOKIES } }).sync({}))).rejects.toThrow(/no fetchFn/);
80
- await expect(collect(new jr.JoyrunAdapter().sync({}))).rejects.toThrow(/needs opts.inputPath/);
81
- });
82
- });