@chainlesschain/personal-data-hub 0.4.28 → 0.4.30

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 (204) hide show
  1. package/README.md +13 -5
  2. package/lib/adapters/social-douyin-adb/usage-profile-reader.js +253 -0
  3. package/lib/adapters/social-douyin-adb/watch-history-reader.js +104 -31
  4. package/lib/adapters/social-toutiao-adb/article-reader.js +202 -0
  5. package/lib/analysis-skills/overview.js +24 -4
  6. package/lib/analysis-skills/spending.js +63 -2
  7. package/lib/analysis-skills/timeline.js +11 -6
  8. package/lib/prompt-builder.js +15 -1
  9. package/lib/query-parser.js +38 -8
  10. package/package.json +4 -1
  11. package/__tests__/adapter-guide.test.js +0 -47
  12. package/__tests__/adapter-spec.test.js +0 -78
  13. package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
  14. package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
  15. package/__tests__/adapters/ai-chat-history.test.js +0 -396
  16. package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
  17. package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
  18. package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
  19. package/__tests__/adapters/apple-health.test.js +0 -95
  20. package/__tests__/adapters/bank-family.test.js +0 -125
  21. package/__tests__/adapters/biz-tianyancha.test.js +0 -159
  22. package/__tests__/adapters/browser-history-chrome.test.js +0 -377
  23. package/__tests__/adapters/browser-history-edge.test.js +0 -159
  24. package/__tests__/adapters/car-mercedesme.test.js +0 -74
  25. package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
  26. package/__tests__/adapters/doc-camscanner.test.js +0 -147
  27. package/__tests__/adapters/doc-platforms.test.js +0 -177
  28. package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
  29. package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
  30. package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
  31. package/__tests__/adapters/email-adapter.test.js +0 -742
  32. package/__tests__/adapters/email-classifier.test.js +0 -347
  33. package/__tests__/adapters/email-imap-session.test.js +0 -334
  34. package/__tests__/adapters/email-parser.test.js +0 -244
  35. package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
  36. package/__tests__/adapters/email-providers.test.js +0 -84
  37. package/__tests__/adapters/email-retry-progress.test.js +0 -294
  38. package/__tests__/adapters/email-templates.test.js +0 -822
  39. package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
  40. package/__tests__/adapters/finance-alipay-live.test.js +0 -258
  41. package/__tests__/adapters/finance-dcep.test.js +0 -74
  42. package/__tests__/adapters/fitness-joyrun.test.js +0 -82
  43. package/__tests__/adapters/game-genshin-live.test.js +0 -238
  44. package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
  45. package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
  46. package/__tests__/adapters/git-activity.test.js +0 -222
  47. package/__tests__/adapters/gov-12123.test.js +0 -103
  48. package/__tests__/adapters/gov-ixiamen.test.js +0 -150
  49. package/__tests__/adapters/gov-tax.test.js +0 -135
  50. package/__tests__/adapters/health-meiyou.test.js +0 -125
  51. package/__tests__/adapters/local-files.test.js +0 -264
  52. package/__tests__/adapters/local-im-pc.test.js +0 -154
  53. package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
  54. package/__tests__/adapters/music-kugou.test.js +0 -187
  55. package/__tests__/adapters/music-qq.test.js +0 -112
  56. package/__tests__/adapters/netease-music-live.test.js +0 -244
  57. package/__tests__/adapters/netease-music.test.js +0 -74
  58. package/__tests__/adapters/pc-local-discovery.test.js +0 -141
  59. package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
  60. package/__tests__/adapters/reading-family.test.js +0 -108
  61. package/__tests__/adapters/recruit-boss.test.js +0 -180
  62. package/__tests__/adapters/shell-history.test.js +0 -180
  63. package/__tests__/adapters/shopping-base.test.js +0 -179
  64. package/__tests__/adapters/shopping-dianping.test.js +0 -239
  65. package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
  66. package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
  67. package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
  68. package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
  69. package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
  70. package/__tests__/adapters/social-csdn.test.js +0 -175
  71. package/__tests__/adapters/social-dongchedi.test.js +0 -165
  72. package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
  73. package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
  74. package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
  75. package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
  76. package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
  77. package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -192
  78. package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
  79. package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
  80. package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
  81. package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
  82. package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
  83. package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
  84. package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
  85. package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
  86. package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
  87. package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
  88. package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
  89. package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
  90. package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
  91. package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
  92. package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
  93. package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
  94. package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
  95. package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
  96. package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
  97. package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
  98. package/__tests__/adapters/social-zhihu.test.js +0 -246
  99. package/__tests__/adapters/system-data-adapter.test.js +0 -443
  100. package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
  101. package/__tests__/adapters/system-data-android.test.js +0 -519
  102. package/__tests__/adapters/system-data-disclosure.test.js +0 -153
  103. package/__tests__/adapters/travel-12306.test.js +0 -512
  104. package/__tests__/adapters/travel-amap.test.js +0 -219
  105. package/__tests__/adapters/travel-baidu-map.test.js +0 -305
  106. package/__tests__/adapters/travel-base.test.js +0 -205
  107. package/__tests__/adapters/travel-ctrip.test.js +0 -377
  108. package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
  109. package/__tests__/adapters/travel-didi.test.js +0 -204
  110. package/__tests__/adapters/travel-tencent-map.test.js +0 -207
  111. package/__tests__/adapters/travel-tongcheng.test.js +0 -289
  112. package/__tests__/adapters/video-platforms.test.js +0 -152
  113. package/__tests__/adapters/video-xigua.test.js +0 -106
  114. package/__tests__/adapters/vscode.test.js +0 -299
  115. package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
  116. package/__tests__/adapters/wechat-env-probe.test.js +0 -162
  117. package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
  118. package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
  119. package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
  120. package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
  121. package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
  122. package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
  123. package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
  124. package/__tests__/adapters/weread.test.js +0 -123
  125. package/__tests__/adapters/wework-pc.test.js +0 -124
  126. package/__tests__/adapters/win-recent.test.js +0 -192
  127. package/__tests__/analysis-skills.test.js +0 -679
  128. package/__tests__/analysis.test.js +0 -1845
  129. package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
  130. package/__tests__/batch.test.js +0 -133
  131. package/__tests__/bridges-cc-kg.test.js +0 -231
  132. package/__tests__/bridges-cc-llm.test.js +0 -191
  133. package/__tests__/bridges-cc-rag.test.js +0 -162
  134. package/__tests__/categories.test.js +0 -92
  135. package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
  136. package/__tests__/e2e/full-user-journey.test.js +0 -188
  137. package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
  138. package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
  139. package/__tests__/entity-resolver-stages.test.js +0 -411
  140. package/__tests__/entity-resolver-vault.test.js +0 -249
  141. package/__tests__/entity-resolver.test.js +0 -526
  142. package/__tests__/fitness-keep-snapshot.test.js +0 -224
  143. package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
  144. package/__tests__/ids.test.js +0 -45
  145. package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
  146. package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
  147. package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
  148. package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
  149. package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
  150. package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
  151. package/__tests__/key-providers.test.js +0 -126
  152. package/__tests__/kg-derive.test.js +0 -219
  153. package/__tests__/llm-client.test.js +0 -122
  154. package/__tests__/longtail-adapters.test.js +0 -281
  155. package/__tests__/messaging-qq-snapshot.test.js +0 -294
  156. package/__tests__/mobile-extractor-encrypted.test.js +0 -460
  157. package/__tests__/mobile-extractor.test.js +0 -288
  158. package/__tests__/mock-adapter.test.js +0 -93
  159. package/__tests__/prompt-builder.test.js +0 -249
  160. package/__tests__/query-parser.test.js +0 -302
  161. package/__tests__/rag-derive.test.js +0 -169
  162. package/__tests__/registry-readiness.test.js +0 -292
  163. package/__tests__/registry.test.js +0 -420
  164. package/__tests__/salvage-ingest.test.js +0 -97
  165. package/__tests__/schemas.test.js +0 -331
  166. package/__tests__/shopping-adapters.test.js +0 -392
  167. package/__tests__/shopping-eleme-snapshot.test.js +0 -454
  168. package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
  169. package/__tests__/shopping-snapshot.test.js +0 -438
  170. package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
  171. package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
  172. package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
  173. package/__tests__/sidecar-supervisor.test.js +0 -128
  174. package/__tests__/sign-providers.test.js +0 -62
  175. package/__tests__/social-adapters.test.js +0 -280
  176. package/__tests__/social-bilibili-snapshot.test.js +0 -278
  177. package/__tests__/social-douban-snapshot.test.js +0 -351
  178. package/__tests__/social-douyin-im-direct-read.test.js +0 -377
  179. package/__tests__/social-douyin-salvage-collector.test.js +0 -98
  180. package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
  181. package/__tests__/social-douyin-snapshot.test.js +0 -256
  182. package/__tests__/social-kuaishou-snapshot.test.js +0 -362
  183. package/__tests__/social-toutiao-snapshot.test.js +0 -366
  184. package/__tests__/social-weibo-snapshot.test.js +0 -234
  185. package/__tests__/social-weibo-sqlite-device.test.js +0 -174
  186. package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
  187. package/__tests__/sqlite-leaf-salvage.test.js +0 -97
  188. package/__tests__/travel-adapters.test.js +0 -483
  189. package/__tests__/travel-maps-snapshot.test.js +0 -426
  190. package/__tests__/vault-driver-error.test.js +0 -74
  191. package/__tests__/vault-search-helpers.test.js +0 -104
  192. package/__tests__/vault-search.test.js +0 -423
  193. package/__tests__/vault.test.js +0 -767
  194. package/__tests__/wechat-adapter.test.js +0 -594
  195. package/__tests__/whatsapp-adapter.test.js +0 -138
  196. package/scripts/_make-fixture-all.js +0 -126
  197. package/scripts/_make-fixture-contacts.js +0 -84
  198. package/scripts/evaluate-entity-resolver.js +0 -213
  199. package/scripts/run-native-tests-sandbox.sh +0 -55
  200. package/scripts/smoke-phase-5-5.js +0 -196
  201. package/scripts/smoke-phase-5-7.js +0 -181
  202. package/scripts/smoke-system-data-contacts.js +0 -309
  203. package/scripts/smoke-system-data.js +0 -312
  204. package/vitest.config.js +0 -88
@@ -1,159 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect, beforeEach, afterEach } from "vitest";
4
- import { mkdtempSync, rmSync, mkdirSync } from "node:fs";
5
- import { join } from "node:path";
6
- import { tmpdir } from "node:os";
7
- import Database from "better-sqlite3";
8
-
9
- const {
10
- BrowserHistoryEdgeAdapter,
11
- BROWSER_HISTORY_EDGE_NAME,
12
- BROWSER_HISTORY_EDGE_VERSION,
13
- } = require("../../lib/adapters/browser-history-edge");
14
- const { assertAdapter } = require("../../lib/adapter-spec");
15
- const {
16
- EVENT_SUBTYPES,
17
- ITEM_SUBTYPES,
18
- } = require("../../lib/constants");
19
- const {
20
- epochMsToWebkitUs,
21
- defaultEdgeProfileDir,
22
- } = require("../../lib/adapters/browser-history-chrome/chrome-db-reader");
23
-
24
- let tmpDir;
25
- let profileDir;
26
- let historyPath;
27
-
28
- function buildHistoryFixture() {
29
- mkdirSync(profileDir, { recursive: true });
30
- const db = new Database(historyPath);
31
- db.exec(`
32
- CREATE TABLE urls(
33
- id INTEGER PRIMARY KEY AUTOINCREMENT,
34
- url LONGVARCHAR, title LONGVARCHAR,
35
- visit_count INTEGER DEFAULT 0 NOT NULL,
36
- typed_count INTEGER DEFAULT 0 NOT NULL,
37
- last_visit_time INTEGER NOT NULL,
38
- hidden INTEGER DEFAULT 0 NOT NULL
39
- );
40
- CREATE TABLE visits(
41
- id INTEGER PRIMARY KEY AUTOINCREMENT,
42
- url INTEGER NOT NULL,
43
- visit_time INTEGER NOT NULL,
44
- from_visit INTEGER,
45
- transition INTEGER DEFAULT 0 NOT NULL,
46
- visit_duration INTEGER DEFAULT 0 NOT NULL
47
- );
48
- `);
49
- const t = epochMsToWebkitUs(1_700_000_001_000).toString();
50
- db.prepare(
51
- "INSERT INTO urls(url, title, last_visit_time) VALUES('https://bing.com', 'Bing', ?)",
52
- ).run(t);
53
- db.prepare(
54
- "INSERT INTO visits(url, visit_time, transition) VALUES(1, ?, 1)",
55
- ).run(t);
56
- db.close();
57
- }
58
-
59
- beforeEach(() => {
60
- tmpDir = mkdtempSync(join(tmpdir(), "edge-adapter-test-"));
61
- profileDir = join(tmpDir, "Default");
62
- historyPath = join(profileDir, "History");
63
- });
64
-
65
- afterEach(() => {
66
- rmSync(tmpDir, { recursive: true, force: true });
67
- });
68
-
69
- describe("BrowserHistoryEdgeAdapter — contract + defaults", () => {
70
- it("conforms to PersonalDataAdapter contract", () => {
71
- const adapter = new BrowserHistoryEdgeAdapter();
72
- expect(assertAdapter(adapter)).toEqual({ ok: true });
73
- });
74
-
75
- it("identifies as browser-history-edge with edge-prefixed capabilities", () => {
76
- const adapter = new BrowserHistoryEdgeAdapter();
77
- expect(adapter.name).toBe(BROWSER_HISTORY_EDGE_NAME);
78
- expect(adapter.name).toBe("browser-history-edge");
79
- expect(adapter.version).toBe(BROWSER_HISTORY_EDGE_VERSION);
80
- expect(adapter.capabilities).toContain("sync:edge-history-sqlite");
81
- expect(adapter.capabilities).toContain("sync:edge-bookmarks-json");
82
- });
83
-
84
- it("defaultEdgeProfileDir resolves to platform-correct Edge path", () => {
85
- const dir = defaultEdgeProfileDir();
86
- expect(typeof dir === "string" || dir === null).toBe(true);
87
- if (process.platform === "win32" && process.env.LOCALAPPDATA) {
88
- expect(dir).toBe(
89
- join(process.env.LOCALAPPDATA, "Microsoft", "Edge", "User Data", "Default"),
90
- );
91
- }
92
- });
93
- });
94
-
95
- describe("BrowserHistoryEdgeAdapter — sync + normalize use edge prefix", () => {
96
- it("yields visits with edge-visit: originalId prefix", async () => {
97
- buildHistoryFixture();
98
- const adapter = new BrowserHistoryEdgeAdapter({ profilePath: profileDir });
99
- const raws = [];
100
- for await (const r of adapter.sync()) raws.push(r);
101
- expect(raws).toHaveLength(1);
102
- expect(raws[0].kind).toBe("visit");
103
- expect(raws[0].originalId).toMatch(/^edge-visit:/);
104
- });
105
-
106
- it("normalize emits browser='edge' in extra + event id prefixed edge", () => {
107
- const adapter = new BrowserHistoryEdgeAdapter();
108
- const { events } = adapter.normalize({
109
- kind: "visit",
110
- capturedAt: 1_700_000_000_000,
111
- payload: {
112
- visitId: 42,
113
- url: "https://bing.com",
114
- title: "Bing",
115
- visitTimeMs: 1_700_000_000_000,
116
- visitDurationMs: 0,
117
- transition: "link",
118
- rawTransition: 0,
119
- profileDir: "/p/Default",
120
- },
121
- });
122
- expect(events).toHaveLength(1);
123
- expect(events[0].extra.browser).toBe("edge");
124
- expect(events[0].id).toBe("event-edge-visit-42");
125
- expect(events[0].subtype).toBe(EVENT_SUBTYPES.BROWSE);
126
- expect(events[0].source.originalId).toBe("edge-visit:/p/Default:42");
127
- expect(events[0].source.adapter).toBe("browser-history-edge");
128
- });
129
-
130
- it("normalize bookmark emits browser='edge'", () => {
131
- const adapter = new BrowserHistoryEdgeAdapter();
132
- const { items } = adapter.normalize({
133
- kind: "bookmark",
134
- capturedAt: 1_700_000_000_000,
135
- payload: {
136
- guid: "g1",
137
- name: "Bing",
138
- url: "https://bing.com",
139
- dateAddedMs: 1_600_000_000_000,
140
- folderPath: "书签栏",
141
- profileDir: "/p/Default",
142
- },
143
- });
144
- expect(items).toHaveLength(1);
145
- expect(items[0].extra.browser).toBe("edge");
146
- expect(items[0].id).toBe("item-edge-bookmark-g1");
147
- expect(items[0].subtype).toBe(ITEM_SUBTYPES.LINK);
148
- expect(items[0].source.originalId).toBe("edge-bookmark:/p/Default:g1");
149
- });
150
-
151
- it("PROFILE_NOT_FOUND error message mentions edge, not chrome", async () => {
152
- const adapter = new BrowserHistoryEdgeAdapter({ profilePath: profileDir });
153
- const r = await adapter.authenticate({});
154
- expect(r.ok).toBe(false);
155
- expect(r.reason).toBe("PROFILE_NOT_FOUND");
156
- expect(r.message).toContain("edge");
157
- expect(r.message).not.toContain("Chrome");
158
- });
159
- });
@@ -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 mb = require("../../lib/adapters/car-mercedesme");
10
-
11
- function writeTmp(content) {
12
- const p = path.join(os.tmpdir(), `cc-mb-${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 = "mb_token=abc";
22
-
23
- describe("car-mercedesme", () => {
24
- it("name + tripToRecord (km direct + meters fallback; no id → null)", () => {
25
- expect(mb.NAME).toBe("car-mercedesme");
26
- const r = mb.tripToRecord({ tripId: "T1", startTime: 1716383000, endTime: 1716385000, startAddress: "家", endAddress: "公司", distanceKm: 12.4, plate: "京A12345" });
27
- expect(r).toMatchObject({ vendorId: "mercedesme", recordId: "T1", vehicleType: "car", carrier: "Mercedes me", vehicleNumber: "京A12345" });
28
- expect(r.from.name).toBe("家");
29
- expect(r.to.name).toBe("公司");
30
- expect(r.extras.distanceKm).toBeCloseTo(12.4, 2);
31
- // meters fallback
32
- expect(mb.tripToRecord({ tripId: "T2", distanceMeters: 5230 }).extras.distanceKm).toBeCloseTo(5.23, 2);
33
- expect(mb.tripToRecord({ startAddress: "x" })).toBe(null);
34
- });
35
- it("extractTrips tolerant", () => {
36
- expect(mb.extractTrips({ trips: [{ tripId: 1 }] })).toHaveLength(1);
37
- expect(mb.extractTrips({ data: { list: [{ tripId: 1 }] } })).toHaveLength(1);
38
- expect(mb.extractTrips({})).toEqual([]);
39
- });
40
-
41
- it("snapshot trip → car travel event", async () => {
42
- const SNAP = JSON.stringify({ trips: [{ tripId: "T1", startTime: 1716383000, endTime: 1716385000, startAddress: "家", endAddress: "公司", distanceKm: 12.4 }] });
43
- const p = writeTmp(SNAP);
44
- try {
45
- const a = new mb.MercedesMeAdapter();
46
- const items = await collect(a.sync({ inputPath: p }));
47
- expect(items).toHaveLength(1);
48
- expect(items[0].originalId).toBe("T1");
49
- const b = a.normalize(items[0]);
50
- expect(b.events[0].source.adapter).toBe("car-mercedesme");
51
- } finally {
52
- fs.unlinkSync(p);
53
- }
54
- });
55
-
56
- it("cookie-api: unverified + sign seam", async () => {
57
- let signed = 0;
58
- const a = new mb.MercedesMeAdapter({
59
- account: { cookies: COOKIES, userId: "u1" },
60
- signProvider: async () => { signed += 1; return "sig"; },
61
- fetchFn: async ({ query }) => (query.page > 1 ? { trips: [] } : { trips: [{ tripId: "T9", startTime: 1716383000, distanceMeters: 8000 }] }),
62
- });
63
- expect(await a.authenticate()).toMatchObject({ ok: true, mode: "cookie", unverified: true });
64
- const items = await collect(a.sync({}));
65
- expect(items).toHaveLength(1);
66
- expect(items[0].originalId).toBe("T9");
67
- expect(signed).toBeGreaterThan(0);
68
- });
69
-
70
- it("medium sensitivity; default fetch throws", async () => {
71
- expect(new mb.MercedesMeAdapter().dataDisclosure.sensitivity).toBe("medium");
72
- await expect(collect(new mb.MercedesMeAdapter({ account: { cookies: COOKIES } }).sync({}))).rejects.toThrow(/no fetchFn/);
73
- });
74
- });
@@ -1,102 +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 nd = require("../../lib/adapters/doc-baidu-netdisk");
10
-
11
- function writeTmp(content) {
12
- const p = path.join(os.tmpdir(), `cc-nd-${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
-
22
- const COOKIES = "BDUSS=abc; STOKEN=xyz";
23
-
24
- describe("doc-baidu-netdisk mappers", () => {
25
- it("name/version", () => {
26
- expect(nd.NAME).toBe("doc-baidu-netdisk");
27
- expect(nd.VERSION).toBe("0.1.0");
28
- });
29
- it("mapDoc maps netdisk fields; category + isdir → docType", () => {
30
- const rec = nd.mapDoc({ fs_id: 123, server_filename: "电影.mp4", category: 1, size: 999, server_mtime: 1716383000, path: "/影视/电影.mp4" });
31
- expect(rec).toMatchObject({ docId: "123", title: "电影.mp4", docType: "video" });
32
- expect(rec.updatedMs).toBe(1716383000000);
33
- expect(rec.extra.path).toBe("/影视/电影.mp4");
34
- expect(nd.mapDoc({ fs_id: 1, isdir: 1, server_filename: "我的资料" }).docType).toBe("folder");
35
- expect(nd.mapDoc({ fs_id: 2, server_filename: "报告.pdf" }).docType).toBe("doc"); // extension fallback
36
- expect(nd.mapDoc({ server_filename: "noid" })).toBe(null);
37
- });
38
- it("extractDocs tolerant", () => {
39
- expect(nd.extractDocs({ list: [{ fs_id: 1 }] })).toHaveLength(1);
40
- expect(nd.extractDocs({ data: { list: [{ fs_id: 1 }] } })).toHaveLength(1);
41
- expect(nd.extractDocs({})).toEqual([]);
42
- });
43
- });
44
-
45
- describe("BaiduNetdiskAdapter (via _document-base)", () => {
46
- const SNAP = JSON.stringify({
47
- schemaVersion: 1,
48
- snapshottedAt: 1716383000000,
49
- account: { userId: "u1" },
50
- events: [
51
- { kind: "document", id: "doc-F1", docId: "F1", title: "合同.pdf", docType: "doc", updatedTime: 1716383000, url: "/工作/合同.pdf" },
52
- ],
53
- });
54
-
55
- it("snapshot sync + normalize → event(post)+item(document)", async () => {
56
- const p = writeTmp(SNAP);
57
- try {
58
- const a = new nd.BaiduNetdiskAdapter();
59
- expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
60
- const items = await collect(a.sync({ inputPath: p }));
61
- expect(items).toHaveLength(1);
62
- const batch = a.normalize(items[0]);
63
- expect(batch.events[0].subtype).toBe("post");
64
- expect(batch.items[0].subtype).toBe("document");
65
- expect(batch.items[0].name).toBe("合同.pdf");
66
- expect(batch.items[0].extra.platform).toBe("baidu-netdisk");
67
- } finally {
68
- fs.unlinkSync(p);
69
- }
70
- });
71
-
72
- it("cookie-api: fetch + paginate + normalize", async () => {
73
- const pages = [
74
- { list: [{ fs_id: 7, server_filename: "照片.jpg", category: 3, server_mtime: 1716383000 }] },
75
- { list: [] },
76
- ];
77
- const calls = [];
78
- const a = new nd.BaiduNetdiskAdapter({
79
- account: { cookies: COOKIES, userId: "u1" },
80
- fetchFn: async ({ url, cookies, query, sign }) => {
81
- calls.push({ url, cookies, offset: query.offset, sign });
82
- return query.offset === 0 ? pages[0] : pages[1];
83
- },
84
- });
85
- expect(await a.authenticate()).toEqual({ ok: true, account: "u1", mode: "cookie" });
86
- const items = await collect(a.sync({}));
87
- expect(items).toHaveLength(1);
88
- expect(items[0].originalId).toBe("baidu-netdisk:document:7");
89
- expect(calls[0].cookies).toBe(COOKIES);
90
- expect(calls[0].sign).toBe(null);
91
- const batch = a.normalize(items[0]);
92
- expect(batch.items[0].name).toBe("照片.jpg");
93
- expect(batch.items[0].extra.docType).toBe("image");
94
- });
95
-
96
- it("default fetch throws; no input throws", async () => {
97
- const a = new nd.BaiduNetdiskAdapter({ account: { cookies: COOKIES } });
98
- await expect(collect(a.sync({}))).rejects.toThrow(/no fetchFn configured/);
99
- const b = new nd.BaiduNetdiskAdapter();
100
- await expect(collect(b.sync({}))).rejects.toThrow(/needs opts.inputPath/);
101
- });
102
- });
@@ -1,147 +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 cs = require("../../lib/adapters/doc-camscanner");
10
-
11
- function writeTmp(content) {
12
- const p = path.join(os.tmpdir(), `cc-cs-${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
-
22
- const COOKIES = "INTSIG_TOKEN=abc; PHPSESSID=xyz";
23
-
24
- describe("doc-camscanner mappers", () => {
25
- it("name/version", () => {
26
- expect(cs.NAME).toBe("doc-camscanner");
27
- expect(cs.VERSION).toBe("0.1.0");
28
- });
29
- it("mapDoc maps CamScanner fields; doc_type + extension → docType", () => {
30
- const rec = cs.mapDoc({
31
- sync_doc_id: "DOC123",
32
- title: "营业执照",
33
- doc_type: 2,
34
- page_num: 3,
35
- create_time: 1716383000,
36
- modify_time: 1716390000,
37
- pdf_url: "https://cs/DOC123.pdf",
38
- tags: ["证件"],
39
- });
40
- expect(rec).toMatchObject({ docId: "DOC123", title: "营业执照", docType: "certificate" });
41
- expect(rec.createdMs).toBe(1716383000000);
42
- expect(rec.updatedMs).toBe(1716390000000);
43
- expect(rec.url).toBe("https://cs/DOC123.pdf");
44
- expect(rec.extra.pageNum).toBe(3);
45
- expect(rec.extra.tags).toEqual(["证件"]);
46
- // extension fallback when no doc_type
47
- expect(cs.mapDoc({ doc_id: 1, title: "报表.xlsx" }).docType).toBe("excel");
48
- expect(cs.mapDoc({ doc_id: 2, title: "合同.pdf" }).docType).toBe("pdf");
49
- // default → scan
50
- expect(cs.mapDoc({ doc_id: 3, title: "随手拍" }).docType).toBe("scan");
51
- // no id → null
52
- expect(cs.mapDoc({ title: "noid" })).toBe(null);
53
- });
54
- it("extractDocs tolerant across shapes", () => {
55
- expect(cs.extractDocs({ docs: [{ doc_id: 1 }] })).toHaveLength(1);
56
- expect(cs.extractDocs({ list: [{ doc_id: 1 }] })).toHaveLength(1);
57
- expect(cs.extractDocs({ data: { docs: [{ doc_id: 1 }] } })).toHaveLength(1);
58
- expect(cs.extractDocs({})).toEqual([]);
59
- });
60
- });
61
-
62
- describe("CamScannerDocAdapter (via _document-base)", () => {
63
- const SNAP = JSON.stringify({
64
- schemaVersion: 1,
65
- snapshottedAt: 1716383000000,
66
- account: { userId: "u1" },
67
- events: [
68
- {
69
- kind: "document",
70
- id: "doc-S1",
71
- docId: "S1",
72
- title: "身份证扫描",
73
- docType: "certificate",
74
- updatedTime: 1716383000,
75
- url: "https://cs/S1.pdf",
76
- },
77
- ],
78
- });
79
-
80
- it("snapshot sync + normalize → event(post)+item(document)", async () => {
81
- const p = writeTmp(SNAP);
82
- try {
83
- const a = new cs.CamScannerDocAdapter();
84
- expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
85
- const items = await collect(a.sync({ inputPath: p }));
86
- expect(items).toHaveLength(1);
87
- const batch = a.normalize(items[0]);
88
- expect(batch.events[0].subtype).toBe("post");
89
- expect(batch.items[0].subtype).toBe("document");
90
- expect(batch.items[0].name).toBe("身份证扫描");
91
- expect(batch.items[0].extra.platform).toBe("camscanner");
92
- } finally {
93
- fs.unlinkSync(p);
94
- }
95
- });
96
-
97
- it("cookie-api: fetch + paginate + normalize", async () => {
98
- const pages = [
99
- { docs: [{ sync_doc_id: 7, title: "发票.pdf", doc_type: "pdf", modify_time: 1716383000 }] },
100
- { docs: [] },
101
- ];
102
- const calls = [];
103
- const a = new cs.CamScannerDocAdapter({
104
- account: { cookies: COOKIES, userId: "u1" },
105
- fetchFn: async ({ url, cookies, query, sign }) => {
106
- calls.push({ url, cookies, offset: query.offset, sign });
107
- return query.offset === 0 ? pages[0] : pages[1];
108
- },
109
- });
110
- expect(await a.authenticate()).toEqual({ ok: true, account: "u1", mode: "cookie" });
111
- const items = await collect(a.sync({}));
112
- expect(items).toHaveLength(1);
113
- expect(items[0].originalId).toBe("camscanner:document:7");
114
- expect(calls[0].cookies).toBe(COOKIES);
115
- expect(calls[0].sign).toBe(null);
116
- const batch = a.normalize(items[0]);
117
- expect(batch.items[0].name).toBe("发票.pdf");
118
- expect(batch.items[0].extra.docType).toBe("pdf");
119
- });
120
-
121
- it("cookie-api: signProvider seam invoked when present", async () => {
122
- let seen = null;
123
- const a = new cs.CamScannerDocAdapter({
124
- account: { cookies: COOKIES, userId: "u1" },
125
- signProvider: async ({ url, query }) => {
126
- seen = { url, offset: query.offset };
127
- return "sig-abc";
128
- },
129
- fetchFn: async ({ sign, query }) => {
130
- return query.offset === 0
131
- ? { docs: [{ sync_doc_id: "X", title: "t", _sign: sign }] }
132
- : { docs: [] };
133
- },
134
- });
135
- const items = await collect(a.sync({}));
136
- expect(items).toHaveLength(1);
137
- expect(seen.offset).toBe(0);
138
- expect(seen.url).toContain("intsig");
139
- });
140
-
141
- it("default fetch throws; no input throws", async () => {
142
- const a = new cs.CamScannerDocAdapter({ account: { cookies: COOKIES } });
143
- await expect(collect(a.sync({}))).rejects.toThrow(/no fetchFn configured/);
144
- const b = new cs.CamScannerDocAdapter();
145
- await expect(collect(b.sync({}))).rejects.toThrow(/needs opts.inputPath/);
146
- });
147
- });
@@ -1,177 +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 wps = require("../../lib/adapters/doc-wps");
10
- const tdocs = require("../../lib/adapters/doc-tencent-docs");
11
-
12
- function writeTmp(content) {
13
- const p = path.join(os.tmpdir(), `cc-doc-${crypto.randomUUID()}.json`);
14
- fs.writeFileSync(p, content, "utf-8");
15
- return p;
16
- }
17
-
18
- async function collect(gen) {
19
- const out = [];
20
- for await (const x of gen) out.push(x);
21
- return out;
22
- }
23
-
24
- const COOKIES = "wps_sid=abc; uid=1";
25
-
26
- describe("doc-wps constants + mappers", () => {
27
- it("exposes name/version", () => {
28
- expect(wps.NAME).toBe("doc-wps");
29
- expect(wps.VERSION).toBe("0.1.0");
30
- });
31
- it("mapDoc maps WPS fields + infers docType from extension", () => {
32
- const rec = wps.mapDoc({ id: "F1", fname: "预算.xlsx", ctime: 1716300000, mtime: 1716383000 });
33
- expect(rec).toMatchObject({ docId: "F1", title: "预算.xlsx", docType: "sheet" });
34
- expect(rec.createdMs).toBe(1716300000000);
35
- expect(rec.updatedMs).toBe(1716383000000);
36
- expect(rec.url).toContain("kdocs.cn");
37
- expect(wps.mapDoc({ id: "F2", fname: "方案.pptx" }).docType).toBe("slide");
38
- expect(wps.mapDoc({ id: "F3", fname: "说明.docx" }).docType).toBe("doc");
39
- expect(wps.mapDoc({ fname: "noid" })).toBe(null);
40
- });
41
- it("extractDocs tolerant of shapes", () => {
42
- expect(wps.extractDocs({ files: [{ id: 1 }] })).toHaveLength(1);
43
- expect(wps.extractDocs({ data: { files: [{ id: 1 }] } })).toHaveLength(1);
44
- expect(wps.extractDocs({})).toEqual([]);
45
- });
46
- });
47
-
48
- describe("doc-tencent-docs constants + mappers", () => {
49
- it("exposes name/version", () => {
50
- expect(tdocs.NAME).toBe("doc-tencent-docs");
51
- expect(tdocs.VERSION).toBe("0.1.0");
52
- });
53
- it("mapDoc maps Tencent fields + type codes", () => {
54
- const rec = tdocs.mapDoc({ id: "T1", title: "周报", type: "sheet", createTime: 1716300000, lastModifyTime: 1716383000 });
55
- expect(rec).toMatchObject({ docId: "T1", title: "周报", docType: "sheet" });
56
- expect(rec.url).toContain("docs.qq.com");
57
- expect(tdocs.mapDoc({ id: "T2", type: 2 }).docType).toBe("sheet");
58
- expect(tdocs.mapDoc({ id: "T3", type: "presentation" }).docType).toBe("slide");
59
- expect(tdocs.mapDoc({ title: "noid" })).toBe(null);
60
- });
61
- });
62
-
63
- describe("WpsDocAdapter snapshot mode", () => {
64
- const SNAP = JSON.stringify({
65
- schemaVersion: 1,
66
- snapshottedAt: 1716383000000,
67
- account: { userId: "u1" },
68
- events: [
69
- { kind: "document", id: "doc-D1", docId: "D1", title: "我的文档", docType: "doc", createdTime: 1716300000, updatedTime: 1716383000, url: "https://kdocs.cn/p/D1" },
70
- ],
71
- });
72
-
73
- it("authenticate validates inputPath", async () => {
74
- const p = writeTmp(SNAP);
75
- try {
76
- const a = new wps.WpsDocAdapter();
77
- expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
78
- expect((await a.authenticate({ inputPath: path.join(os.tmpdir(), "nope.json") })).reason).toBe("INPUT_PATH_UNREADABLE");
79
- } finally {
80
- fs.unlinkSync(p);
81
- }
82
- });
83
-
84
- it("sync yields doc + normalize → event(post)+item(document)", async () => {
85
- const p = writeTmp(SNAP);
86
- try {
87
- const a = new wps.WpsDocAdapter();
88
- const items = await collect(a.sync({ inputPath: p }));
89
- expect(items).toHaveLength(1);
90
- expect(items[0].originalId).toBe("wps:document:doc-D1");
91
- const batch = a.normalize(items[0]);
92
- expect(batch.events[0].subtype).toBe("post");
93
- expect(batch.events[0].content.title).toBe("文档: 我的文档");
94
- expect(batch.items[0].subtype).toBe("document");
95
- expect(batch.items[0].name).toBe("我的文档");
96
- expect(batch.items[0].extra.platform).toBe("wps");
97
- // event references the item
98
- expect(batch.events[0].extra.itemRef).toBe(batch.items[0].id);
99
- } finally {
100
- fs.unlinkSync(p);
101
- }
102
- });
103
-
104
- it("schemaVersion mismatch throws; normalize missing record throws", async () => {
105
- const p = writeTmp(JSON.stringify({ schemaVersion: 9, events: [] }));
106
- try {
107
- const a = new wps.WpsDocAdapter();
108
- await expect(collect(a.sync({ inputPath: p }))).rejects.toThrow(/schemaVersion mismatch/);
109
- expect(() => a.normalize({ payload: {} })).toThrow(/payload.record missing/);
110
- } finally {
111
- fs.unlinkSync(p);
112
- }
113
- });
114
- });
115
-
116
- describe("TencentDocsAdapter cookie-api mode", () => {
117
- it("authenticate cookie mode (userId optional)", async () => {
118
- const a = new tdocs.TencentDocsAdapter({ account: { cookies: COOKIES } });
119
- expect(await a.authenticate()).toEqual({ ok: true, account: null, mode: "cookie" });
120
- });
121
-
122
- it("sync fetches, paginates, normalizes", async () => {
123
- const pages = [
124
- { data: { files: [{ id: "T1", title: "项目计划", type: "doc", lastModifyTime: 1716383000 }] } },
125
- { data: { files: [] } },
126
- ];
127
- const calls = [];
128
- const fetchFn = async ({ url, cookies, query, sign }) => {
129
- calls.push({ url, cookies, offset: query.offset, sign });
130
- return query.offset === 0 ? pages[0] : pages[1];
131
- };
132
- const a = new tdocs.TencentDocsAdapter({ account: { cookies: COOKIES, userId: "u1" }, fetchFn });
133
- const items = await collect(a.sync({}));
134
- expect(items).toHaveLength(1);
135
- expect(items[0].originalId).toBe("tencent-docs:document:T1");
136
- expect(calls[0].cookies).toBe(COOKIES);
137
- expect(calls[0].sign).toBe(null);
138
- const batch = a.normalize(items[0]);
139
- expect(batch.items[0].name).toBe("项目计划");
140
- expect(batch.items[0].extra.platform).toBe("tencent-docs");
141
- });
142
-
143
- it("invokes signProvider when configured", async () => {
144
- const signCalls = [];
145
- const a = new tdocs.TencentDocsAdapter({
146
- account: { cookies: COOKIES },
147
- fetchFn: async ({ query }) => (query.offset === 0 ? { files: [{ id: "S1", title: "x" }] } : { files: [] }),
148
- signProvider: async (ctx) => { signCalls.push(ctx); return "SIG"; },
149
- });
150
- const items = await collect(a.sync({}));
151
- expect(items).toHaveLength(1);
152
- expect(signCalls.length).toBeGreaterThan(0);
153
- expect(signCalls[0].cookies).toBe(COOKIES);
154
- });
155
-
156
- it("sinceWatermark + limit + empty response", async () => {
157
- const a1 = new tdocs.TencentDocsAdapter({
158
- account: { cookies: COOKIES },
159
- fetchFn: async ({ query }) => query.offset === 0 ? { files: [
160
- { id: "NEW", title: "n", lastModifyTime: 2_000_000_000 },
161
- { id: "OLD", title: "o", lastModifyTime: 1_000_000_000 },
162
- ] } : { files: [] },
163
- });
164
- const got = await collect(a1.sync({ sinceWatermark: 1_500_000_000_000 }));
165
- expect(got.map((x) => x.originalId)).toEqual(["tencent-docs:document:NEW"]);
166
-
167
- const a2 = new tdocs.TencentDocsAdapter({ account: { cookies: COOKIES }, fetchFn: async () => "<html>login</html>" });
168
- expect(await collect(a2.sync({}))).toEqual([]);
169
- });
170
-
171
- it("default fetch throws; no input throws", async () => {
172
- const a = new tdocs.TencentDocsAdapter({ account: { cookies: COOKIES } });
173
- await expect(collect(a.sync({}))).rejects.toThrow(/no fetchFn configured/);
174
- const b = new tdocs.TencentDocsAdapter();
175
- await expect(collect(b.sync({}))).rejects.toThrow(/needs opts.inputPath/);
176
- });
177
- });