@chainlesschain/personal-data-hub 0.1.0 → 0.2.1

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 (154) hide show
  1. package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +211 -0
  2. package/__tests__/adapters/ai-chat-health-checker.test.js +262 -0
  3. package/__tests__/adapters/ai-chat-history.test.js +396 -0
  4. package/__tests__/adapters/ai-chat-http-client.test.js +242 -0
  5. package/__tests__/adapters/ai-chat-vendors.test.js +874 -0
  6. package/__tests__/adapters/alipay-bill-adapter.test.js +538 -0
  7. package/__tests__/adapters/email-adapter.test.js +138 -1
  8. package/__tests__/adapters/email-classifier.test.js +347 -0
  9. package/__tests__/adapters/email-pdf-extractor.test.js +529 -0
  10. package/__tests__/adapters/email-retry-progress.test.js +294 -0
  11. package/__tests__/adapters/email-templates.test.js +699 -0
  12. package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +269 -0
  13. package/__tests__/adapters/system-data-adapter.test.js +440 -0
  14. package/__tests__/adapters/system-data-android-ingest.test.js +144 -0
  15. package/__tests__/adapters/system-data-android.test.js +387 -0
  16. package/__tests__/adapters/system-data-disclosure.test.js +153 -0
  17. package/__tests__/adapters/wechat-bootstrap.test.js +240 -0
  18. package/__tests__/adapters/wechat-env-probe.test.js +162 -0
  19. package/__tests__/adapters/wechat-frida-agent.test.js +191 -0
  20. package/__tests__/adapters/wechat-frida-integration.test.js +149 -0
  21. package/__tests__/adapters/wechat-frida-key-provider.test.js +188 -0
  22. package/__tests__/adapters/wechat-md5-key-provider.test.js +101 -0
  23. package/__tests__/analysis-skills.test.js +556 -0
  24. package/__tests__/analysis.test.js +329 -1
  25. package/__tests__/e2e/ai-chat-cross-source-journey.test.js +213 -0
  26. package/__tests__/e2e/full-user-journey.test.js +188 -0
  27. package/__tests__/entity-resolver-ingest-hook.test.js +177 -0
  28. package/__tests__/entity-resolver-stages.test.js +411 -0
  29. package/__tests__/entity-resolver-vault.test.js +246 -0
  30. package/__tests__/entity-resolver.test.js +526 -0
  31. package/__tests__/fixtures/entity-resolver-200-mock.json +96 -0
  32. package/__tests__/integration/ai-chat-history-registry.test.js +228 -0
  33. package/__tests__/integration/aichat-wizard-end-to-end.test.js +282 -0
  34. package/__tests__/integration/cross-adapter-pipelines.test.js +396 -0
  35. package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +390 -0
  36. package/__tests__/longtail-adapters.test.js +217 -0
  37. package/__tests__/mobile-extractor.test.js +288 -0
  38. package/__tests__/registry.test.js +4 -2
  39. package/__tests__/shopping-adapters.test.js +296 -0
  40. package/__tests__/sidecar-contacts-cross-validate.test.js +163 -0
  41. package/__tests__/sidecar-supervisor.test.js +120 -0
  42. package/__tests__/social-adapters.test.js +206 -0
  43. package/__tests__/travel-adapters.test.js +325 -0
  44. package/__tests__/vault.test.js +3 -3
  45. package/__tests__/wechat-adapter.test.js +476 -0
  46. package/__tests__/whatsapp-adapter.test.js +135 -0
  47. package/lib/adapter-spec.js +12 -0
  48. package/lib/adapters/_python-sidecar-base.js +207 -0
  49. package/lib/adapters/ai-chat-history/ai-chat-adapter.js +374 -0
  50. package/lib/adapters/ai-chat-history/cookie-auth.js +109 -0
  51. package/lib/adapters/ai-chat-history/cookie-capture-spec.js +331 -0
  52. package/lib/adapters/ai-chat-history/health-checker.js +210 -0
  53. package/lib/adapters/ai-chat-history/http-client.js +211 -0
  54. package/lib/adapters/ai-chat-history/index.js +28 -0
  55. package/lib/adapters/ai-chat-history/schema-map.js +258 -0
  56. package/lib/adapters/ai-chat-history/vendor-spec.js +86 -0
  57. package/lib/adapters/ai-chat-history/vendors/coze.js +179 -0
  58. package/lib/adapters/ai-chat-history/vendors/deepseek.js +199 -0
  59. package/lib/adapters/ai-chat-history/vendors/doubao.js +255 -0
  60. package/lib/adapters/ai-chat-history/vendors/dreamina.js +174 -0
  61. package/lib/adapters/ai-chat-history/vendors/hunyuan.js +176 -0
  62. package/lib/adapters/ai-chat-history/vendors/kimi.js +182 -0
  63. package/lib/adapters/ai-chat-history/vendors/qianfan.js +160 -0
  64. package/lib/adapters/ai-chat-history/vendors/tongyi.js +193 -0
  65. package/lib/adapters/ai-chat-history/vendors/zhipu.js +202 -0
  66. package/lib/adapters/ai-chat-history/wizard-controller.js +473 -0
  67. package/lib/adapters/alipay-bill/alipay-bill-adapter.js +311 -0
  68. package/lib/adapters/alipay-bill/counterparty.js +129 -0
  69. package/lib/adapters/alipay-bill/csv-parser.js +217 -0
  70. package/lib/adapters/alipay-bill/index.js +41 -0
  71. package/lib/adapters/alipay-bill/zip-decryptor.js +111 -0
  72. package/lib/adapters/email-imap/classifier.js +495 -0
  73. package/lib/adapters/email-imap/email-adapter.js +419 -8
  74. package/lib/adapters/email-imap/index.js +42 -0
  75. package/lib/adapters/email-imap/pdf-extractor.js +192 -0
  76. package/lib/adapters/email-imap/templates/bill.js +232 -0
  77. package/lib/adapters/email-imap/templates/government.js +120 -0
  78. package/lib/adapters/email-imap/templates/index.js +78 -0
  79. package/lib/adapters/email-imap/templates/order.js +186 -0
  80. package/lib/adapters/email-imap/templates/other.js +114 -0
  81. package/lib/adapters/email-imap/templates/register.js +113 -0
  82. package/lib/adapters/email-imap/templates/travel.js +157 -0
  83. package/lib/adapters/email-imap/templates/utils.js +275 -0
  84. package/lib/adapters/email-imap/transactions.js +234 -0
  85. package/lib/adapters/messaging-qq/index.js +158 -0
  86. package/lib/adapters/messaging-telegram/index.js +142 -0
  87. package/lib/adapters/messaging-whatsapp/index.js +189 -0
  88. package/lib/adapters/shopping-base/index.js +208 -0
  89. package/lib/adapters/shopping-jd/index.js +150 -0
  90. package/lib/adapters/shopping-meituan/index.js +154 -0
  91. package/lib/adapters/shopping-taobao/index.js +176 -0
  92. package/lib/adapters/social-bilibili/index.js +171 -0
  93. package/lib/adapters/social-douyin/index.js +116 -0
  94. package/lib/adapters/social-kuaishou/index.js +237 -0
  95. package/lib/adapters/social-toutiao/index.js +236 -0
  96. package/lib/adapters/social-weibo/index.js +164 -0
  97. package/lib/adapters/social-xiaohongshu/index.js +96 -0
  98. package/lib/adapters/system-data/disclosure.js +166 -0
  99. package/lib/adapters/system-data/index.js +34 -0
  100. package/lib/adapters/system-data/system-data-adapter.js +344 -0
  101. package/lib/adapters/system-data-android/adapter.js +348 -0
  102. package/lib/adapters/system-data-android/index.js +76 -0
  103. package/lib/adapters/travel-12306/index.js +151 -0
  104. package/lib/adapters/travel-amap/index.js +164 -0
  105. package/lib/adapters/travel-baidu-map/index.js +162 -0
  106. package/lib/adapters/travel-base/index.js +240 -0
  107. package/lib/adapters/travel-ctrip/index.js +151 -0
  108. package/lib/adapters/wechat/bootstrap.js +146 -0
  109. package/lib/adapters/wechat/content-parser.js +326 -0
  110. package/lib/adapters/wechat/db-reader.js +209 -0
  111. package/lib/adapters/wechat/env-probe.js +218 -0
  112. package/lib/adapters/wechat/frida-agent/loader.js +67 -0
  113. package/lib/adapters/wechat/frida-agent/wechat-key-hook.js +126 -0
  114. package/lib/adapters/wechat/index.js +37 -0
  115. package/lib/adapters/wechat/key-extractor.js +158 -0
  116. package/lib/adapters/wechat/key-providers/frida-key-provider.js +244 -0
  117. package/lib/adapters/wechat/key-providers/index.js +22 -0
  118. package/lib/adapters/wechat/key-providers/key-provider-base.js +44 -0
  119. package/lib/adapters/wechat/key-providers/md5-key-provider.js +81 -0
  120. package/lib/adapters/wechat/normalize.js +220 -0
  121. package/lib/adapters/wechat/wechat-adapter.js +205 -0
  122. package/lib/analysis-skills/base.js +113 -0
  123. package/lib/analysis-skills/footprint.js +167 -0
  124. package/lib/analysis-skills/index.js +58 -0
  125. package/lib/analysis-skills/interests.js +161 -0
  126. package/lib/analysis-skills/relations.js +226 -0
  127. package/lib/analysis-skills/spending.js +219 -0
  128. package/lib/analysis-skills/timeline.js +167 -0
  129. package/lib/analysis.js +191 -2
  130. package/lib/entity-resolver/embedding-stage.js +198 -0
  131. package/lib/entity-resolver/entity-resolver.js +384 -0
  132. package/lib/entity-resolver/index.js +42 -0
  133. package/lib/entity-resolver/llm-stage.js +191 -0
  134. package/lib/entity-resolver/rule-stage.js +208 -0
  135. package/lib/entity-resolver/worker.js +149 -0
  136. package/lib/index.js +131 -0
  137. package/lib/migrations.js +73 -0
  138. package/lib/mobile-extractor/android.js +193 -0
  139. package/lib/mobile-extractor/index.js +9 -0
  140. package/lib/mobile-extractor/ios.js +223 -0
  141. package/lib/prompt-builder.js +11 -1
  142. package/lib/query-parser.js +7 -1
  143. package/lib/registry.js +42 -0
  144. package/lib/sidecar/index.js +15 -0
  145. package/lib/sidecar/supervisor.js +359 -0
  146. package/lib/vault.js +343 -0
  147. package/package.json +36 -3
  148. package/scripts/_make-fixture-all.js +126 -0
  149. package/scripts/_make-fixture-contacts.js +84 -0
  150. package/scripts/evaluate-entity-resolver.js +213 -0
  151. package/scripts/smoke-phase-5-5.js +196 -0
  152. package/scripts/smoke-phase-5-7.js +181 -0
  153. package/scripts/smoke-system-data-contacts.js +309 -0
  154. package/scripts/smoke-system-data.js +312 -0
@@ -0,0 +1,269 @@
1
+ /**
2
+ * Phase 13.8+13.9 — Toutiao 今日头条 + Kuaishou 快手 v0.1 scaffold tests.
3
+ *
4
+ * Tests are intentionally focused on scaffold-quality guarantees:
5
+ * - Adapter contract conformance (assertAdapter ok)
6
+ * - Account validation (rejects missing uid)
7
+ * - sync() yields raw rows per `kind` from mocked SQLite driver
8
+ * - normalize() produces valid UnifiedSchema events with correct subtype
9
+ *
10
+ * Field-level assertions intentionally avoided — schema is待 fixture pin
11
+ * in Phase 13.10 (real-device E2E).
12
+ */
13
+
14
+ "use strict";
15
+
16
+ import { describe, it, expect } from "vitest";
17
+
18
+ const fs = require("node:fs");
19
+ const path = require("node:path");
20
+ const os = require("node:os");
21
+
22
+ const { ToutiaoAdapter, KuaishouAdapter } = require("../../lib");
23
+ const { assertAdapter } = require("../../lib/adapter-spec");
24
+ const { validateBatch } = require("../../lib/batch");
25
+
26
+ function makeMockDriver(scriptedRows) {
27
+ return function () {
28
+ return {
29
+ prepare(sql) {
30
+ return {
31
+ all() {
32
+ for (const [matchSubstr, rows] of scriptedRows) {
33
+ if (sql.includes(matchSubstr)) return rows;
34
+ }
35
+ throw new Error("no such table");
36
+ },
37
+ };
38
+ },
39
+ close() {},
40
+ };
41
+ };
42
+ }
43
+
44
+ function withFakeDb(fn) {
45
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pdh-scaffold-"));
46
+ const dbPath = path.join(dir, "fake.db");
47
+ fs.writeFileSync(dbPath, "fake");
48
+ return fn(dbPath);
49
+ }
50
+
51
+ // ─── ToutiaoAdapter ─────────────────────────────────────────────────────
52
+
53
+ describe("ToutiaoAdapter — Phase 13.8(+) v0.1 scaffold", () => {
54
+ it("contract conformance + sensitivity high (news reading reveals political/medical interest)", () => {
55
+ const a = new ToutiaoAdapter({ account: { uid: "u-1" } });
56
+ expect(assertAdapter(a).ok).toBe(true);
57
+ expect(a.name).toBe("social-toutiao");
58
+ expect(a.extractMode).toBe("device-pull");
59
+ expect(a.dataDisclosure.sensitivity).toBe("high");
60
+ });
61
+
62
+ it("rejects missing account.uid", () => {
63
+ expect(() => new ToutiaoAdapter({})).toThrow();
64
+ expect(() => new ToutiaoAdapter({ account: {} })).toThrow(/uid/);
65
+ });
66
+
67
+ it("sync yields read + collection + search raws via mocked driver", async () => {
68
+ await withFakeDb(async (dbPath) => {
69
+ const driver = makeMockDriver([
70
+ [
71
+ "FROM read_history",
72
+ [
73
+ { id: 1, item_id: "i-1", title: "新闻 A", read_time: 1700000000, category: "tech" },
74
+ { id: 2, item_id: "i-2", title: "新闻 B", read_time: 1700000010, category: "finance" },
75
+ ],
76
+ ],
77
+ [
78
+ "FROM collection_article",
79
+ [{ id: 1, item_id: "i-3", article_title: "深度长文", save_time: 1700001000 }],
80
+ ],
81
+ [
82
+ "FROM search_history",
83
+ [{ id: 1, keyword: "Rust 语言", search_time: 1700002000 }],
84
+ ],
85
+ ]);
86
+ const a = new ToutiaoAdapter({
87
+ account: { uid: "u-1" },
88
+ dbPath,
89
+ dbDriverFactory: () => driver,
90
+ });
91
+ const raws = [];
92
+ for await (const r of a.sync()) raws.push(r);
93
+ expect(raws.length).toBe(4);
94
+ expect(raws.filter((r) => r.payload.kind === "read")).toHaveLength(2);
95
+ expect(raws.filter((r) => r.payload.kind === "collection")).toHaveLength(1);
96
+ expect(raws.filter((r) => r.payload.kind === "search")).toHaveLength(1);
97
+ });
98
+ });
99
+
100
+ it("normalize maps read → browse / collection → like / search → post (all subtypes valid)", async () => {
101
+ const a = new ToutiaoAdapter({ account: { uid: "u-1" } });
102
+ const samples = [
103
+ {
104
+ kind: "read",
105
+ row: { id: 1, item_id: "i-1", title: "T1", read_time: 1700000000, category: "tech" },
106
+ expectedSubtype: "browse",
107
+ },
108
+ {
109
+ kind: "collection",
110
+ row: { id: 1, item_id: "i-2", article_title: "T2", save_time: 1700001000 },
111
+ expectedSubtype: "like",
112
+ },
113
+ {
114
+ kind: "search",
115
+ row: { id: 1, keyword: "Rust", search_time: 1700002000 },
116
+ expectedSubtype: "post",
117
+ },
118
+ ];
119
+ for (const s of samples) {
120
+ const batch = a.normalize({
121
+ adapter: "social-toutiao",
122
+ originalId: `${s.kind}-${s.row.id}`,
123
+ capturedAt: Date.now(),
124
+ payload: { row: s.row, kind: s.kind },
125
+ });
126
+ const v = validateBatch(batch);
127
+ expect(v.valid).toBe(true);
128
+ expect(batch.events[0].subtype).toBe(s.expectedSubtype);
129
+ expect(batch.events[0].source.adapter).toBe("social-toutiao");
130
+ }
131
+ });
132
+
133
+ it("normalize throws on missing payload.row (validator-friendly)", () => {
134
+ const a = new ToutiaoAdapter({ account: { uid: "u-1" } });
135
+ expect(() => a.normalize({ payload: {} })).toThrow(/row missing/);
136
+ });
137
+
138
+ it("search keyword preserved verbatim in content.title + extra.keyword", () => {
139
+ const a = new ToutiaoAdapter({ account: { uid: "u-1" } });
140
+ const batch = a.normalize({
141
+ adapter: "social-toutiao",
142
+ originalId: "search-1",
143
+ capturedAt: 1700002000_000,
144
+ payload: { row: { id: 1, keyword: "新冠 后遗症", search_time: 1700002000 }, kind: "search" },
145
+ });
146
+ expect(batch.events[0].content.title).toBe("新冠 后遗症");
147
+ expect(batch.events[0].extra.kind).toBe("search");
148
+ expect(batch.events[0].extra.keyword).toBe("新冠 后遗症");
149
+ });
150
+
151
+ it("sync gracefully exits when dbPath missing", async () => {
152
+ const a = new ToutiaoAdapter({ account: { uid: "u-1" }, dbPath: "/no/such/path.db" });
153
+ const raws = [];
154
+ for await (const r of a.sync()) raws.push(r);
155
+ expect(raws).toEqual([]);
156
+ });
157
+ });
158
+
159
+ // ─── KuaishouAdapter ────────────────────────────────────────────────────
160
+
161
+ describe("KuaishouAdapter — Phase 13.9(+) v0.1 scaffold", () => {
162
+ it("contract conformance + sensitivity medium (entertainment preference)", () => {
163
+ const a = new KuaishouAdapter({ account: { uid: "u-2" } });
164
+ expect(assertAdapter(a).ok).toBe(true);
165
+ expect(a.name).toBe("social-kuaishou");
166
+ expect(a.extractMode).toBe("device-pull");
167
+ expect(a.dataDisclosure.sensitivity).toBe("medium");
168
+ });
169
+
170
+ it("rejects missing account.uid", () => {
171
+ expect(() => new KuaishouAdapter({})).toThrow();
172
+ expect(() => new KuaishouAdapter({ account: {} })).toThrow(/uid/);
173
+ });
174
+
175
+ it("sync yields watch + collect + search raws via mocked driver", async () => {
176
+ await withFakeDb(async (dbPath) => {
177
+ const driver = makeMockDriver([
178
+ [
179
+ "FROM photo_history",
180
+ [
181
+ {
182
+ id: 1,
183
+ photo_id: "p-1",
184
+ caption: "搞笑视频",
185
+ view_time: 1700000000,
186
+ duration: 30,
187
+ author_name: "UpA",
188
+ },
189
+ ],
190
+ ],
191
+ [
192
+ "FROM user_collect",
193
+ [{ id: 1, photo_id: "p-2", caption: "美食 vlog", collect_time: 1700001000 }],
194
+ ],
195
+ [
196
+ "FROM search_record",
197
+ [{ id: 1, keyword: "广场舞", search_time: 1700002000 }],
198
+ ],
199
+ ]);
200
+ const a = new KuaishouAdapter({
201
+ account: { uid: "u-2" },
202
+ dbPath,
203
+ dbDriverFactory: () => driver,
204
+ });
205
+ const raws = [];
206
+ for await (const r of a.sync()) raws.push(r);
207
+ expect(raws.length).toBe(3);
208
+ expect(raws.filter((r) => r.payload.kind === "watch")).toHaveLength(1);
209
+ expect(raws.filter((r) => r.payload.kind === "collect")).toHaveLength(1);
210
+ expect(raws.filter((r) => r.payload.kind === "search")).toHaveLength(1);
211
+ });
212
+ });
213
+
214
+ it("normalize maps watch → browse / collect → like / search → post (all subtypes valid)", () => {
215
+ const a = new KuaishouAdapter({ account: { uid: "u-2" } });
216
+ const samples = [
217
+ {
218
+ kind: "watch",
219
+ row: { id: 1, photo_id: "p-1", caption: "C1", view_time: 1700000000, duration: 30 },
220
+ expectedSubtype: "browse",
221
+ },
222
+ {
223
+ kind: "collect",
224
+ row: { id: 1, photo_id: "p-2", caption: "C2", collect_time: 1700001000 },
225
+ expectedSubtype: "like",
226
+ },
227
+ {
228
+ kind: "search",
229
+ row: { id: 1, keyword: "广场舞", search_time: 1700002000 },
230
+ expectedSubtype: "post",
231
+ },
232
+ ];
233
+ for (const s of samples) {
234
+ const batch = a.normalize({
235
+ adapter: "social-kuaishou",
236
+ originalId: `${s.kind}-${s.row.id}`,
237
+ capturedAt: Date.now(),
238
+ payload: { row: s.row, kind: s.kind },
239
+ });
240
+ const v = validateBatch(batch);
241
+ expect(v.valid).toBe(true);
242
+ expect(batch.events[0].subtype).toBe(s.expectedSubtype);
243
+ expect(batch.events[0].source.adapter).toBe("social-kuaishou");
244
+ }
245
+ });
246
+
247
+ it("watch event extra carries photoId + duration + authorName", () => {
248
+ const a = new KuaishouAdapter({ account: { uid: "u-2" } });
249
+ const batch = a.normalize({
250
+ adapter: "social-kuaishou",
251
+ originalId: "watch-1",
252
+ capturedAt: 1700000000_000,
253
+ payload: {
254
+ row: {
255
+ id: 1,
256
+ photo_id: "p-1",
257
+ caption: "美食",
258
+ view_time: 1700000000,
259
+ duration: 60,
260
+ author_name: "FoodVlogger",
261
+ },
262
+ kind: "watch",
263
+ },
264
+ });
265
+ expect(batch.events[0].extra.photoId).toBe("p-1");
266
+ expect(batch.events[0].extra.duration).toBe(60);
267
+ expect(batch.events[0].extra.authorName).toBe("FoodVlogger");
268
+ });
269
+ });