@chainlesschain/personal-data-hub 0.4.29 → 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 (198) hide show
  1. package/lib/prompt-builder.js +15 -1
  2. package/package.json +4 -1
  3. package/__tests__/adapter-guide.test.js +0 -47
  4. package/__tests__/adapter-spec.test.js +0 -78
  5. package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
  6. package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
  7. package/__tests__/adapters/ai-chat-history.test.js +0 -396
  8. package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
  9. package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
  10. package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
  11. package/__tests__/adapters/apple-health.test.js +0 -95
  12. package/__tests__/adapters/bank-family.test.js +0 -125
  13. package/__tests__/adapters/biz-tianyancha.test.js +0 -159
  14. package/__tests__/adapters/browser-history-chrome.test.js +0 -377
  15. package/__tests__/adapters/browser-history-edge.test.js +0 -159
  16. package/__tests__/adapters/car-mercedesme.test.js +0 -74
  17. package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
  18. package/__tests__/adapters/doc-camscanner.test.js +0 -147
  19. package/__tests__/adapters/doc-platforms.test.js +0 -177
  20. package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
  21. package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
  22. package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
  23. package/__tests__/adapters/email-adapter.test.js +0 -742
  24. package/__tests__/adapters/email-classifier.test.js +0 -347
  25. package/__tests__/adapters/email-imap-session.test.js +0 -334
  26. package/__tests__/adapters/email-parser.test.js +0 -244
  27. package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
  28. package/__tests__/adapters/email-providers.test.js +0 -84
  29. package/__tests__/adapters/email-retry-progress.test.js +0 -294
  30. package/__tests__/adapters/email-templates.test.js +0 -822
  31. package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
  32. package/__tests__/adapters/finance-alipay-live.test.js +0 -258
  33. package/__tests__/adapters/finance-dcep.test.js +0 -74
  34. package/__tests__/adapters/fitness-joyrun.test.js +0 -82
  35. package/__tests__/adapters/game-genshin-live.test.js +0 -238
  36. package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
  37. package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
  38. package/__tests__/adapters/git-activity.test.js +0 -222
  39. package/__tests__/adapters/gov-12123.test.js +0 -103
  40. package/__tests__/adapters/gov-ixiamen.test.js +0 -150
  41. package/__tests__/adapters/gov-tax.test.js +0 -135
  42. package/__tests__/adapters/health-meiyou.test.js +0 -125
  43. package/__tests__/adapters/local-files.test.js +0 -264
  44. package/__tests__/adapters/local-im-pc.test.js +0 -154
  45. package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
  46. package/__tests__/adapters/music-kugou.test.js +0 -187
  47. package/__tests__/adapters/music-qq.test.js +0 -112
  48. package/__tests__/adapters/netease-music-live.test.js +0 -244
  49. package/__tests__/adapters/netease-music.test.js +0 -74
  50. package/__tests__/adapters/pc-local-discovery.test.js +0 -141
  51. package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
  52. package/__tests__/adapters/reading-family.test.js +0 -108
  53. package/__tests__/adapters/recruit-boss.test.js +0 -180
  54. package/__tests__/adapters/shell-history.test.js +0 -180
  55. package/__tests__/adapters/shopping-base.test.js +0 -179
  56. package/__tests__/adapters/shopping-dianping.test.js +0 -239
  57. package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
  58. package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
  59. package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
  60. package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
  61. package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
  62. package/__tests__/adapters/social-csdn.test.js +0 -175
  63. package/__tests__/adapters/social-dongchedi.test.js +0 -165
  64. package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
  65. package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
  66. package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
  67. package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
  68. package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
  69. package/__tests__/adapters/social-douyin-adb-usage-profile.test.js +0 -229
  70. package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -269
  71. package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
  72. package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
  73. package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
  74. package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
  75. package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
  76. package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
  77. package/__tests__/adapters/social-toutiao-adb-article.test.js +0 -155
  78. package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
  79. package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
  80. package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
  81. package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
  82. package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
  83. package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
  84. package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
  85. package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
  86. package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
  87. package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
  88. package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
  89. package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
  90. package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
  91. package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
  92. package/__tests__/adapters/social-zhihu.test.js +0 -246
  93. package/__tests__/adapters/system-data-adapter.test.js +0 -443
  94. package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
  95. package/__tests__/adapters/system-data-android.test.js +0 -519
  96. package/__tests__/adapters/system-data-disclosure.test.js +0 -153
  97. package/__tests__/adapters/travel-12306.test.js +0 -512
  98. package/__tests__/adapters/travel-amap.test.js +0 -219
  99. package/__tests__/adapters/travel-baidu-map.test.js +0 -305
  100. package/__tests__/adapters/travel-base.test.js +0 -205
  101. package/__tests__/adapters/travel-ctrip.test.js +0 -377
  102. package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
  103. package/__tests__/adapters/travel-didi.test.js +0 -204
  104. package/__tests__/adapters/travel-tencent-map.test.js +0 -207
  105. package/__tests__/adapters/travel-tongcheng.test.js +0 -289
  106. package/__tests__/adapters/video-platforms.test.js +0 -152
  107. package/__tests__/adapters/video-xigua.test.js +0 -106
  108. package/__tests__/adapters/vscode.test.js +0 -299
  109. package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
  110. package/__tests__/adapters/wechat-env-probe.test.js +0 -162
  111. package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
  112. package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
  113. package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
  114. package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
  115. package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
  116. package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
  117. package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
  118. package/__tests__/adapters/weread.test.js +0 -123
  119. package/__tests__/adapters/wework-pc.test.js +0 -124
  120. package/__tests__/adapters/win-recent.test.js +0 -192
  121. package/__tests__/analysis-skills.test.js +0 -754
  122. package/__tests__/analysis.test.js +0 -1845
  123. package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
  124. package/__tests__/batch.test.js +0 -133
  125. package/__tests__/bridges-cc-kg.test.js +0 -231
  126. package/__tests__/bridges-cc-llm.test.js +0 -191
  127. package/__tests__/bridges-cc-rag.test.js +0 -162
  128. package/__tests__/categories.test.js +0 -92
  129. package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
  130. package/__tests__/e2e/full-user-journey.test.js +0 -188
  131. package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
  132. package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
  133. package/__tests__/entity-resolver-stages.test.js +0 -411
  134. package/__tests__/entity-resolver-vault.test.js +0 -249
  135. package/__tests__/entity-resolver.test.js +0 -526
  136. package/__tests__/fitness-keep-snapshot.test.js +0 -224
  137. package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
  138. package/__tests__/ids.test.js +0 -45
  139. package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
  140. package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
  141. package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
  142. package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
  143. package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
  144. package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
  145. package/__tests__/key-providers.test.js +0 -126
  146. package/__tests__/kg-derive.test.js +0 -219
  147. package/__tests__/llm-client.test.js +0 -122
  148. package/__tests__/longtail-adapters.test.js +0 -281
  149. package/__tests__/messaging-qq-snapshot.test.js +0 -294
  150. package/__tests__/mobile-extractor-encrypted.test.js +0 -460
  151. package/__tests__/mobile-extractor.test.js +0 -288
  152. package/__tests__/mock-adapter.test.js +0 -93
  153. package/__tests__/prompt-builder.test.js +0 -249
  154. package/__tests__/query-parser.test.js +0 -365
  155. package/__tests__/rag-derive.test.js +0 -169
  156. package/__tests__/registry-readiness.test.js +0 -292
  157. package/__tests__/registry.test.js +0 -420
  158. package/__tests__/salvage-ingest.test.js +0 -97
  159. package/__tests__/schemas.test.js +0 -331
  160. package/__tests__/shopping-adapters.test.js +0 -392
  161. package/__tests__/shopping-eleme-snapshot.test.js +0 -454
  162. package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
  163. package/__tests__/shopping-snapshot.test.js +0 -438
  164. package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
  165. package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
  166. package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
  167. package/__tests__/sidecar-supervisor.test.js +0 -128
  168. package/__tests__/sign-providers.test.js +0 -62
  169. package/__tests__/social-adapters.test.js +0 -280
  170. package/__tests__/social-bilibili-snapshot.test.js +0 -278
  171. package/__tests__/social-douban-snapshot.test.js +0 -351
  172. package/__tests__/social-douyin-im-direct-read.test.js +0 -377
  173. package/__tests__/social-douyin-salvage-collector.test.js +0 -98
  174. package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
  175. package/__tests__/social-douyin-snapshot.test.js +0 -256
  176. package/__tests__/social-kuaishou-snapshot.test.js +0 -362
  177. package/__tests__/social-toutiao-snapshot.test.js +0 -366
  178. package/__tests__/social-weibo-snapshot.test.js +0 -234
  179. package/__tests__/social-weibo-sqlite-device.test.js +0 -174
  180. package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
  181. package/__tests__/sqlite-leaf-salvage.test.js +0 -97
  182. package/__tests__/travel-adapters.test.js +0 -483
  183. package/__tests__/travel-maps-snapshot.test.js +0 -426
  184. package/__tests__/vault-driver-error.test.js +0 -74
  185. package/__tests__/vault-search-helpers.test.js +0 -104
  186. package/__tests__/vault-search.test.js +0 -423
  187. package/__tests__/vault.test.js +0 -767
  188. package/__tests__/wechat-adapter.test.js +0 -594
  189. package/__tests__/whatsapp-adapter.test.js +0 -138
  190. package/scripts/_make-fixture-all.js +0 -126
  191. package/scripts/_make-fixture-contacts.js +0 -84
  192. package/scripts/evaluate-entity-resolver.js +0 -213
  193. package/scripts/run-native-tests-sandbox.sh +0 -55
  194. package/scripts/smoke-phase-5-5.js +0 -196
  195. package/scripts/smoke-phase-5-7.js +0 -181
  196. package/scripts/smoke-system-data-contacts.js +0 -309
  197. package/scripts/smoke-system-data.js +0 -312
  198. 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
- });