@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,438 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, it, expect, beforeEach } from "vitest";
4
-
5
- const fs = require("node:fs");
6
- const path = require("node:path");
7
- const os = require("node:os");
8
-
9
- const {
10
- JdAdapter,
11
- SNAPSHOT_SCHEMA_VERSION: JD_VERSION,
12
- } = require("../lib/adapters/shopping-jd");
13
- const {
14
- MeituanAdapter,
15
- SNAPSHOT_SCHEMA_VERSION: MT_VERSION,
16
- } = require("../lib/adapters/shopping-meituan");
17
- const { validateBatch } = require("../lib/batch");
18
-
19
- // §2.4b 购物双联 v0.2 — snapshot-mode tests, mirror of social-weibo-snapshot
20
- // & travel-maps-snapshot patterns.
21
- //
22
- // Snapshot mode is in-APK Android cc reading JSON written by Jd/Meituan
23
- // LocalCollector (WebView cookie scrape + OkHttp fetch order list). Cookie-
24
- // mode tests stay in legacy shopping-adapters tests.
25
-
26
- function writeSnapshot(dir, fileName, snapshot) {
27
- const p = path.join(dir, fileName);
28
- fs.writeFileSync(p, JSON.stringify(snapshot), "utf-8");
29
- return p;
30
- }
31
-
32
- describe("JdAdapter snapshot mode", () => {
33
- let tmpDir;
34
- beforeEach(() => {
35
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "jd-snap-"));
36
- });
37
-
38
- it("exports SNAPSHOT_SCHEMA_VERSION = 1", () => {
39
- expect(JD_VERSION).toBe(1);
40
- });
41
-
42
- it("constructor allows missing account (stateless snapshot mode)", () => {
43
- expect(() => new JdAdapter()).not.toThrow();
44
- expect(() => new JdAdapter({})).not.toThrow();
45
- });
46
-
47
- it("authenticate(inputPath) ok + mode=snapshot-file", async () => {
48
- const p = writeSnapshot(tmpDir, "shopping-jd.json", {
49
- schemaVersion: 1,
50
- snapshottedAt: Date.now(),
51
- events: [],
52
- });
53
- const a = new JdAdapter();
54
- const res = await a.authenticate({ inputPath: p });
55
- expect(res.ok).toBe(true);
56
- expect(res.mode).toBe("snapshot-file");
57
- });
58
-
59
- it("authenticate(inputPath) fails when path unreadable", async () => {
60
- const a = new JdAdapter();
61
- const res = await a.authenticate({ inputPath: path.join(tmpDir, "missing.json") });
62
- expect(res.ok).toBe(false);
63
- expect(res.reason).toBe("INPUT_PATH_UNREADABLE");
64
- });
65
-
66
- it("authenticate() with neither inputPath nor account returns NO_INPUT", async () => {
67
- const a = new JdAdapter();
68
- const res = await a.authenticate({});
69
- expect(res.ok).toBe(false);
70
- expect(res.reason).toBe("NO_INPUT");
71
- });
72
-
73
- it("rejects schemaVersion mismatch", async () => {
74
- const p = writeSnapshot(tmpDir, "shopping-jd.json", {
75
- schemaVersion: 99,
76
- snapshottedAt: Date.now(),
77
- events: [],
78
- });
79
- const a = new JdAdapter();
80
- let threw = null;
81
- try {
82
- for await (const _r of a.sync({ inputPath: p })) { /* drain */ }
83
- } catch (err) {
84
- threw = err;
85
- }
86
- expect(threw).toBeTruthy();
87
- expect(String(threw.message)).toMatch(/schemaVersion mismatch/);
88
- });
89
-
90
- it("rejects non-JSON snapshot (v0.3 will add HTML parsing)", async () => {
91
- const p = path.join(tmpDir, "shopping-jd.html");
92
- fs.writeFileSync(p, "<!DOCTYPE html><html><body>not json</body></html>", "utf-8");
93
- const a = new JdAdapter();
94
- let threw = null;
95
- try {
96
- for await (const _r of a.sync({ inputPath: p })) { /* drain */ }
97
- } catch (err) {
98
- threw = err;
99
- }
100
- expect(threw).toBeTruthy();
101
- expect(String(threw.message)).toMatch(/must be JSON.*v0\.3.*HTML/);
102
- });
103
-
104
- it("empty events array yields nothing", async () => {
105
- const p = writeSnapshot(tmpDir, "shopping-jd.json", {
106
- schemaVersion: 1,
107
- snapshottedAt: Date.now(),
108
- events: [],
109
- });
110
- const a = new JdAdapter();
111
- const raws = [];
112
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
113
- expect(raws.length).toBe(0);
114
- });
115
-
116
- it("order kind round-trip normalize cleanly + namespaced originalId", async () => {
117
- const now = Date.now();
118
- const p = writeSnapshot(tmpDir, "shopping-jd.json", {
119
- schemaVersion: 1,
120
- snapshottedAt: now,
121
- vendor: "jd",
122
- account: { pin: "alice_pin", displayName: "alice" },
123
- events: [
124
- {
125
- kind: "order",
126
- id: "order-J1",
127
- capturedAt: now - 1000,
128
- orderId: "JD200001",
129
- merchantName: "京东自营",
130
- items: [
131
- { name: "AirPods Pro 2", quantity: 1, unitPrice: 1899, sku: "100012345" },
132
- ],
133
- placedAt: now - 86400_000,
134
- paidAt: now - 86300_000,
135
- status: "delivered",
136
- totalAmount: { value: 1899, currency: "CNY" },
137
- recipient: "alice",
138
- shippingAddress: "厦门市象屿路 93 号",
139
- },
140
- ],
141
- });
142
- const a = new JdAdapter();
143
- const raws = [];
144
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
145
- expect(raws.length).toBe(1);
146
- expect(raws[0].kind).toBe("order");
147
- expect(raws[0].originalId).toMatch(/^jd:order:/);
148
-
149
- const batch = a.normalize(raws[0]);
150
- expect(validateBatch(batch).valid).toBe(true);
151
- // OrderRecord → events[0] = "purchase" subtype with merchant 京东自营 / amount 1899
152
- expect(batch.events.length).toBe(1);
153
- const merchantPerson = batch.persons.find((p) => p.names && p.names.includes("京东自营"));
154
- expect(merchantPerson).toBeTruthy();
155
- });
156
-
157
- it("respects opts.limit", async () => {
158
- const now = Date.now();
159
- const events = Array.from({ length: 5 }, (_, i) => ({
160
- kind: "order",
161
- id: `order-J${i}`,
162
- capturedAt: now - i * 100,
163
- orderId: `JD${i}`,
164
- merchantName: "京东自营",
165
- items: [],
166
- placedAt: now - i * 100,
167
- status: "delivered",
168
- totalAmount: { value: 100, currency: "CNY" },
169
- }));
170
- const p = writeSnapshot(tmpDir, "shopping-jd.json", {
171
- schemaVersion: 1,
172
- snapshottedAt: now,
173
- events,
174
- });
175
- const a = new JdAdapter();
176
- const raws = [];
177
- for await (const r of a.sync({ inputPath: p, limit: 2 })) raws.push(r);
178
- expect(raws.length).toBe(2);
179
- });
180
-
181
- it("filters unknown kinds (forward compat)", async () => {
182
- const now = Date.now();
183
- const p = writeSnapshot(tmpDir, "shopping-jd.json", {
184
- schemaVersion: 1,
185
- snapshottedAt: now,
186
- events: [
187
- {
188
- kind: "order",
189
- id: "order-J1",
190
- capturedAt: now,
191
- orderId: "JD1",
192
- merchantName: "京东",
193
- items: [],
194
- totalAmount: { value: 0, currency: "CNY" },
195
- },
196
- { kind: "future-kind", id: "x", capturedAt: now },
197
- { kind: "review", id: "rev1", capturedAt: now }, // hypothetical future
198
- ],
199
- });
200
- const a = new JdAdapter();
201
- const raws = [];
202
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
203
- expect(raws.length).toBe(1);
204
- expect(raws[0].kind).toBe("order");
205
- });
206
-
207
- it("snapshottedAt fallback when event capturedAt+placedAt+paidAt missing", async () => {
208
- const ts = 1700000000000;
209
- const p = writeSnapshot(tmpDir, "shopping-jd.json", {
210
- schemaVersion: 1,
211
- snapshottedAt: ts,
212
- events: [
213
- {
214
- kind: "order",
215
- id: "order-J1",
216
- orderId: "JD1",
217
- merchantName: "京东",
218
- items: [],
219
- status: "placed",
220
- totalAmount: { value: 0, currency: "CNY" },
221
- },
222
- ],
223
- });
224
- const a = new JdAdapter();
225
- const raws = [];
226
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
227
- expect(raws[0].capturedAt).toBe(ts);
228
- });
229
-
230
- it("sync() without inputPath OR cookies throws", async () => {
231
- const a = new JdAdapter();
232
- let threw = null;
233
- try {
234
- for await (const _r of a.sync({})) { /* drain */ }
235
- } catch (err) {
236
- threw = err;
237
- }
238
- expect(threw).toBeTruthy();
239
- expect(String(threw.message)).toMatch(/needs opts\.inputPath/);
240
- });
241
-
242
- it("legacy cookie mode still works (regression guard)", async () => {
243
- const a = new JdAdapter({
244
- account: { pin: "alice", cookies: "pt_key=abc; pt_pin=alice" },
245
- fetchFn: async () => ({
246
- orders: [
247
- {
248
- orderId: "JD-LEGACY-1",
249
- venderName: "京东自营",
250
- orderStartTime: "2026-05-22 10:00:00",
251
- orderTotalPrice: 99,
252
- productList: [
253
- { productName: "test", productQuantity: 1, productPrice: 99 },
254
- ],
255
- orderStatusText: "已完成",
256
- },
257
- ],
258
- }),
259
- });
260
- const raws = [];
261
- for await (const r of a.sync({})) raws.push(r);
262
- expect(raws.length).toBeGreaterThanOrEqual(1);
263
- expect(raws[0].originalId).toBe("JD-LEGACY-1");
264
- const batch = a.normalize(raws[0]);
265
- expect(validateBatch(batch).valid).toBe(true);
266
- });
267
- });
268
-
269
- describe("MeituanAdapter snapshot mode", () => {
270
- let tmpDir;
271
- beforeEach(() => {
272
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "meituan-snap-"));
273
- });
274
-
275
- it("exports SNAPSHOT_SCHEMA_VERSION = 1", () => {
276
- expect(MT_VERSION).toBe(1);
277
- });
278
-
279
- it("constructor allows missing account (stateless snapshot mode)", () => {
280
- expect(() => new MeituanAdapter()).not.toThrow();
281
- expect(() => new MeituanAdapter({})).not.toThrow();
282
- });
283
-
284
- it("authenticate(inputPath) ok", async () => {
285
- const p = writeSnapshot(tmpDir, "shopping-meituan.json", {
286
- schemaVersion: 1,
287
- snapshottedAt: Date.now(),
288
- events: [],
289
- });
290
- const a = new MeituanAdapter();
291
- const res = await a.authenticate({ inputPath: p });
292
- expect(res.ok).toBe(true);
293
- expect(res.mode).toBe("snapshot-file");
294
- });
295
-
296
- it("rejects schemaVersion mismatch", async () => {
297
- const p = writeSnapshot(tmpDir, "shopping-meituan.json", {
298
- schemaVersion: 99,
299
- snapshottedAt: Date.now(),
300
- events: [],
301
- });
302
- const a = new MeituanAdapter();
303
- let threw = null;
304
- try {
305
- for await (const _r of a.sync({ inputPath: p })) { /* drain */ }
306
- } catch (err) {
307
- threw = err;
308
- }
309
- expect(threw).toBeTruthy();
310
- expect(String(threw.message)).toMatch(/schemaVersion mismatch/);
311
- });
312
-
313
- it("rejects non-JSON snapshot (HTML defer to v0.3)", async () => {
314
- const p = path.join(tmpDir, "shopping-meituan.html");
315
- fs.writeFileSync(p, "<html>not json</html>", "utf-8");
316
- const a = new MeituanAdapter();
317
- let threw = null;
318
- try {
319
- for await (const _r of a.sync({ inputPath: p })) { /* drain */ }
320
- } catch (err) {
321
- threw = err;
322
- }
323
- expect(threw).toBeTruthy();
324
- expect(String(threw.message)).toMatch(/must be JSON.*v0\.3.*HTML/);
325
- });
326
-
327
- it("order round-trip normalize with carrier=美团 (waimai platform)", async () => {
328
- const now = Date.now();
329
- const p = writeSnapshot(tmpDir, "shopping-meituan.json", {
330
- schemaVersion: 1,
331
- snapshottedAt: now,
332
- vendor: "meituan",
333
- account: { userId: "alice_uid", displayName: "alice" },
334
- events: [
335
- {
336
- kind: "order",
337
- id: "order-MT1",
338
- capturedAt: now - 1000,
339
- orderId: "MT200001",
340
- merchantName: "肯德基(厦门集美店)",
341
- platform: "waimai",
342
- items: [
343
- { name: "黄金鸡块 5 块", quantity: 1, unitPrice: 15.5 },
344
- { name: "雪顶咖啡", quantity: 1, unitPrice: 16 },
345
- ],
346
- placedAt: now - 86400_000,
347
- paidAt: now - 86300_000,
348
- status: "delivered",
349
- totalAmount: { value: 31.5, currency: "CNY" },
350
- recipient: "alice",
351
- shippingAddress: "厦门市集美区某街道",
352
- },
353
- ],
354
- });
355
- const a = new MeituanAdapter();
356
- const raws = [];
357
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
358
- expect(raws.length).toBe(1);
359
- expect(raws[0].originalId).toMatch(/^meituan:order:/);
360
-
361
- const batch = a.normalize(raws[0]);
362
- expect(validateBatch(batch).valid).toBe(true);
363
- // Merchant is per-POI in waimai (not generic "美团")
364
- const merchant = batch.persons.find((p) => p.names && p.names.includes("肯德基(厦门集美店)"));
365
- expect(merchant).toBeTruthy();
366
- });
367
-
368
- it("filters unknown kinds (forward compat)", async () => {
369
- const now = Date.now();
370
- const p = writeSnapshot(tmpDir, "shopping-meituan.json", {
371
- schemaVersion: 1,
372
- snapshottedAt: now,
373
- events: [
374
- {
375
- kind: "order",
376
- id: "order-MT1",
377
- capturedAt: now,
378
- orderId: "MT1",
379
- merchantName: "测试餐厅",
380
- items: [],
381
- status: "placed",
382
- totalAmount: { value: 0, currency: "CNY" },
383
- },
384
- { kind: "speculative-coupon", id: "c1", capturedAt: now },
385
- ],
386
- });
387
- const a = new MeituanAdapter();
388
- const raws = [];
389
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
390
- expect(raws.length).toBe(1);
391
- expect(raws[0].kind).toBe("order");
392
- });
393
-
394
- it("snapshottedAt fallback when no timestamps in event", async () => {
395
- const ts = 1700000000000;
396
- const p = writeSnapshot(tmpDir, "shopping-meituan.json", {
397
- schemaVersion: 1,
398
- snapshottedAt: ts,
399
- events: [
400
- {
401
- kind: "order",
402
- id: "order-MT1",
403
- orderId: "MT1",
404
- merchantName: "test",
405
- items: [],
406
- status: "placed",
407
- totalAmount: { value: 0, currency: "CNY" },
408
- },
409
- ],
410
- });
411
- const a = new MeituanAdapter();
412
- const raws = [];
413
- for await (const r of a.sync({ inputPath: p })) raws.push(r);
414
- expect(raws[0].capturedAt).toBe(ts);
415
- });
416
-
417
- it("legacy cookie mode still works (regression guard)", async () => {
418
- const a = new MeituanAdapter({
419
- account: { userId: "alice", cookies: "iuuid=abc" },
420
- fetchFn: async () => ({
421
- orders: [
422
- {
423
- orderId: "MT-LEGACY-1",
424
- poiName: "测试餐厅",
425
- orderTime: "2026-05-22 12:00:00",
426
- totalPrice: 50,
427
- dishes: [{ name: "测试菜", quantity: 1, price: 50 }],
428
- statusDesc: "已完成",
429
- },
430
- ],
431
- }),
432
- });
433
- const raws = [];
434
- for await (const r of a.sync({})) raws.push(r);
435
- expect(raws.length).toBeGreaterThanOrEqual(1);
436
- expect(raws[0].originalId).toBe("MT-LEGACY-1");
437
- });
438
- });