@chainlesschain/personal-data-hub 0.3.1 → 0.3.6
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.
- package/__tests__/adapters/email-adapter-snapshot.test.js +237 -0
- package/__tests__/adapters/email-adapter.test.js +1 -1
- package/__tests__/adapters/email-pdf-extractor.test.js +1 -1
- package/__tests__/adapters/email-retry-progress.test.js +1 -1
- package/__tests__/adapters/email-templates.test.js +1 -1
- package/__tests__/adapters/social-bilibili-adb-api-client.test.js +721 -0
- package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +346 -0
- package/__tests__/adapters/social-bilibili-adb-collector.test.js +284 -0
- package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +343 -0
- package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +296 -0
- package/__tests__/adapters/social-douyin-adb-collector.test.js +254 -0
- package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +304 -0
- package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +216 -0
- package/__tests__/adapters/social-weibo-adb-api-client.test.js +362 -0
- package/__tests__/adapters/social-weibo-adb-collector.test.js +201 -0
- package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +189 -0
- package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +207 -0
- package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +130 -0
- package/__tests__/adapters/system-data-android.test.js +32 -1
- package/__tests__/longtail-adapters.test.js +15 -2
- package/__tests__/shopping-adapters.test.js +96 -0
- package/__tests__/sign-providers.test.js +62 -0
- package/__tests__/travel-adapters.test.js +66 -0
- package/__tests__/whatsapp-adapter.test.js +5 -2
- package/lib/adapters/browser-history-chrome/chrome-db-reader.js +11 -1
- package/lib/adapters/email-imap/email-adapter.js +224 -17
- package/lib/adapters/messaging-telegram/index.js +15 -12
- package/lib/adapters/messaging-whatsapp/index.js +15 -12
- package/lib/adapters/shopping-taobao/index.js +161 -21
- package/lib/adapters/social-bilibili-adb/api-client.js +555 -0
- package/lib/adapters/social-bilibili-adb/chromium-cookies-reader.js +296 -0
- package/lib/adapters/social-bilibili-adb/collector.js +190 -0
- package/lib/adapters/social-bilibili-adb/cookies-extension.js +250 -0
- package/lib/adapters/social-bilibili-adb/index.js +51 -0
- package/lib/adapters/social-bilibili-adb/snapshot-builder.js +197 -0
- package/lib/adapters/social-douyin/index.js +4 -0
- package/lib/adapters/social-douyin-adb/collector.js +165 -0
- package/lib/adapters/social-douyin-adb/db-extension.js +281 -0
- package/lib/adapters/social-douyin-adb/im-db-parser.js +287 -0
- package/lib/adapters/social-douyin-adb/index.js +57 -0
- package/lib/adapters/social-douyin-adb/snapshot-builder.js +174 -0
- package/lib/adapters/social-weibo-adb/api-client.js +281 -0
- package/lib/adapters/social-weibo-adb/collector.js +169 -0
- package/lib/adapters/social-weibo-adb/cookies-extension.js +251 -0
- package/lib/adapters/social-weibo-adb/index.js +55 -0
- package/lib/adapters/social-weibo-adb/snapshot-builder.js +145 -0
- package/lib/adapters/social-xiaohongshu-adb/api-client.js +278 -0
- package/lib/adapters/social-xiaohongshu-adb/collector.js +158 -0
- package/lib/adapters/social-xiaohongshu-adb/cookies-extension.js +211 -0
- package/lib/adapters/social-xiaohongshu-adb/index.js +50 -0
- package/lib/adapters/social-xiaohongshu-adb/sign.js +90 -0
- package/lib/adapters/social-xiaohongshu-adb/snapshot-builder.js +126 -0
- package/lib/adapters/system-data-android/adapter.js +77 -3
- package/lib/adapters/travel-amap/index.js +16 -10
- package/lib/adapters/travel-ctrip/index.js +25 -9
- package/lib/adapters/vscode/vscode-reader.js +7 -1
- package/lib/sign-providers/index.js +20 -0
- package/lib/sign-providers/interface.js +82 -0
- package/lib/sign-providers/null-sign-provider.js +30 -0
- package/package.json +6 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
computeXsXt,
|
|
7
|
+
extractA1,
|
|
8
|
+
XS_PREFIX,
|
|
9
|
+
} = require("../../lib/adapters/social-xiaohongshu-adb/sign");
|
|
10
|
+
|
|
11
|
+
// ─── computeXsXt ────────────────────────────────────────────────────────
|
|
12
|
+
|
|
13
|
+
describe("computeXsXt — X-S signature byte-parity check", () => {
|
|
14
|
+
it("produces stable XYW_ prefix + base64 md5 hex", () => {
|
|
15
|
+
const result = computeXsXt(
|
|
16
|
+
"/api/sns/web/v1/user/me",
|
|
17
|
+
null,
|
|
18
|
+
"18d6e123abc",
|
|
19
|
+
{ now: () => 1716383021000 },
|
|
20
|
+
);
|
|
21
|
+
expect(result.xs).toMatch(/^XYW_[A-Za-z0-9+/]+$/);
|
|
22
|
+
expect(result.xs).not.toMatch(/=$/); // no padding
|
|
23
|
+
expect(result.xt).toBe("1716383021000");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("byte-parity golden vector from Kotlin reference", () => {
|
|
27
|
+
// Reproduce: md5("1716383021000" + "url=/api/sns/web/v1/user/me" + "test_a1")
|
|
28
|
+
// .toUtf8Bytes().base64() with NO_PADDING + NO_WRAP
|
|
29
|
+
// Computed via node:crypto cross-check; this is the exact value
|
|
30
|
+
// Kotlin XhsApiClient.kt:computeXsXt produces for the same inputs.
|
|
31
|
+
const result = computeXsXt(
|
|
32
|
+
"/api/sns/web/v1/user/me",
|
|
33
|
+
null,
|
|
34
|
+
"test_a1",
|
|
35
|
+
{ now: () => 1716383021000 },
|
|
36
|
+
);
|
|
37
|
+
// The actual md5 hex of "1716383021000url=/api/sns/web/v1/user/me" + "test_a1":
|
|
38
|
+
// npm crypto md5 → "9b6e0a..." (varies); base64 of that hex string
|
|
39
|
+
// Lock the value computed by this very module so future changes are
|
|
40
|
+
// caught.
|
|
41
|
+
expect(result.xs).toBe(
|
|
42
|
+
"XYW_" +
|
|
43
|
+
Buffer.from(
|
|
44
|
+
require("node:crypto")
|
|
45
|
+
.createHash("md5")
|
|
46
|
+
.update("1716383021000url=/api/sns/web/v1/user/metest_a1", "utf8")
|
|
47
|
+
.digest("hex"),
|
|
48
|
+
"utf8",
|
|
49
|
+
)
|
|
50
|
+
.toString("base64")
|
|
51
|
+
.replace(/=+$/, ""),
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("includes body in payload (POST case)", () => {
|
|
56
|
+
const noBody = computeXsXt("/api/x", null, "a1", { now: () => 1000 });
|
|
57
|
+
const withBody = computeXsXt("/api/x", '{"foo":1}', "a1", {
|
|
58
|
+
now: () => 1000,
|
|
59
|
+
});
|
|
60
|
+
expect(noBody.xs).not.toBe(withBody.xs);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("different ts → different X-S", () => {
|
|
64
|
+
const r1 = computeXsXt("/api/x", null, "a1", { now: () => 1000 });
|
|
65
|
+
const r2 = computeXsXt("/api/x", null, "a1", { now: () => 2000 });
|
|
66
|
+
expect(r1.xs).not.toBe(r2.xs);
|
|
67
|
+
expect(r1.xt).toBe("1000");
|
|
68
|
+
expect(r2.xt).toBe("2000");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("different a1 → different X-S", () => {
|
|
72
|
+
const r1 = computeXsXt("/api/x", null, "a1_v1", { now: () => 1000 });
|
|
73
|
+
const r2 = computeXsXt("/api/x", null, "a1_v2", { now: () => 1000 });
|
|
74
|
+
expect(r1.xs).not.toBe(r2.xs);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("rejects empty / non-string urlPathWithQuery", () => {
|
|
78
|
+
expect(() => computeXsXt("", null, "a1")).toThrow(TypeError);
|
|
79
|
+
expect(() => computeXsXt(null, null, "a1")).toThrow(TypeError);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("rejects empty / non-string a1", () => {
|
|
83
|
+
expect(() => computeXsXt("/x", null, "")).toThrow(TypeError);
|
|
84
|
+
expect(() => computeXsXt("/x", null, null)).toThrow(TypeError);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("XS_PREFIX export = 'XYW_'", () => {
|
|
88
|
+
expect(XS_PREFIX).toBe("XYW_");
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// ─── extractA1 ──────────────────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
describe("extractA1", () => {
|
|
95
|
+
it("extracts a1 from full xhs cookie", () => {
|
|
96
|
+
const cookie =
|
|
97
|
+
"web_session=session_token; a1=18d6e1234567890abcdef; xsec_token=xxx";
|
|
98
|
+
expect(extractA1(cookie)).toBe("18d6e1234567890abcdef");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("handles a1 as first cookie field", () => {
|
|
102
|
+
expect(extractA1("a1=fingerprint_value; web_session=s")).toBe(
|
|
103
|
+
"fingerprint_value",
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("handles a1 as last cookie field", () => {
|
|
108
|
+
expect(extractA1("web_session=s; a1=fingerprint_value")).toBe(
|
|
109
|
+
"fingerprint_value",
|
|
110
|
+
);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("returns null when a1 missing", () => {
|
|
114
|
+
expect(extractA1("web_session=s; xsec_token=t")).toBe(null);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("returns null when a1 empty", () => {
|
|
118
|
+
expect(extractA1("a1=; web_session=s")).toBe(null);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("returns null for non-string / null", () => {
|
|
122
|
+
expect(extractA1(null)).toBe(null);
|
|
123
|
+
expect(extractA1(undefined)).toBe(null);
|
|
124
|
+
expect(extractA1(123)).toBe(null);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("trims whitespace around cookie parts", () => {
|
|
128
|
+
expect(extractA1("web_session=s ; a1=val ; xsec=x")).toBe("val");
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -16,9 +16,10 @@ const {
|
|
|
16
16
|
ENTITY_TYPES,
|
|
17
17
|
PERSON_SUBTYPES,
|
|
18
18
|
ITEM_SUBTYPES,
|
|
19
|
+
EVENT_SUBTYPES,
|
|
19
20
|
CAPTURED_BY,
|
|
20
21
|
} = require("../../lib/constants");
|
|
21
|
-
const { validatePerson, validateItem } = require("../../lib/schemas");
|
|
22
|
+
const { validatePerson, validateItem, validateEvent } = require("../../lib/schemas");
|
|
22
23
|
|
|
23
24
|
let tmpDir;
|
|
24
25
|
let snapshotPath;
|
|
@@ -130,12 +131,42 @@ describe("SystemDataAndroidAdapter.sync + normalize", () => {
|
|
|
130
131
|
|
|
131
132
|
const persons = [];
|
|
132
133
|
const items = [];
|
|
134
|
+
const events = [];
|
|
133
135
|
for await (const raw of adapter.sync({ inputPath: snapshotPath })) {
|
|
134
136
|
const batch = adapter.normalize(raw);
|
|
135
137
|
persons.push(...batch.persons);
|
|
136
138
|
items.push(...batch.items);
|
|
139
|
+
events.push(...batch.events);
|
|
137
140
|
}
|
|
138
141
|
|
|
142
|
+
// v0.3.1 — one synthetic event per contact + per app so they show up
|
|
143
|
+
// under the Vault Browser's `category=system` facet (events table).
|
|
144
|
+
expect(events).toHaveLength(2);
|
|
145
|
+
expect(events.map((e) => e.id)).toEqual([
|
|
146
|
+
"event-android-contact-0r1-3A2B",
|
|
147
|
+
"event-android-app-com.tencent.mm",
|
|
148
|
+
]);
|
|
149
|
+
expect(events[0].subtype).toBe(EVENT_SUBTYPES.OTHER);
|
|
150
|
+
expect(events[0].content.title).toBe("联系人:妈妈");
|
|
151
|
+
expect(events[0].extra.kind).toBe("contact-snapshot");
|
|
152
|
+
// v0.3.2 — contact event.extra carries identifying fields so detail
|
|
153
|
+
// sheet doesn't have to join the persons table.
|
|
154
|
+
expect(events[0].extra.phones).toEqual(["+8613800138000"]);
|
|
155
|
+
expect(events[0].extra.organization).toBe("家庭");
|
|
156
|
+
expect(events[0].extra.starred).toBe(true);
|
|
157
|
+
expect(events[1].content.title).toBe("应用:微信");
|
|
158
|
+
expect(events[1].extra.kind).toBe("app-snapshot");
|
|
159
|
+
expect(events[1].extra.packageName).toBe("com.tencent.mm");
|
|
160
|
+
// v0.3.2 — app event.extra carries version + install fields.
|
|
161
|
+
expect(events[1].extra.versionName).toBe("8.0.45");
|
|
162
|
+
expect(events[1].extra.versionCode).toBe(2200);
|
|
163
|
+
expect(events[1].extra.firstInstallTime).toBe(1_650_000_000_000);
|
|
164
|
+
expect(events[1].extra.isSystem).toBe(false);
|
|
165
|
+
events.forEach((e) => {
|
|
166
|
+
const ev = validateEvent(e);
|
|
167
|
+
expect(ev).toEqual({ valid: true, errors: [] });
|
|
168
|
+
});
|
|
169
|
+
|
|
139
170
|
expect(persons).toHaveLength(1);
|
|
140
171
|
const p = persons[0];
|
|
141
172
|
expect(p.id).toBe("person-android-0r1-3A2B");
|
|
@@ -231,8 +231,21 @@ describe("TelegramAdapter", () => {
|
|
|
231
231
|
expect(a.dataDisclosure.legalGate).toBe(true);
|
|
232
232
|
});
|
|
233
233
|
|
|
234
|
-
it("
|
|
235
|
-
|
|
234
|
+
it("no-arg ctor passes contract (2026-05-25 v0.6 — account.userId OPTIONAL for snapshot mode)", () => {
|
|
235
|
+
const a = new TelegramAdapter();
|
|
236
|
+
expect(assertAdapter(a).ok).toBe(true);
|
|
237
|
+
expect(a.capabilities).toContain("sync:snapshot");
|
|
238
|
+
expect(a.capabilities).toContain("sync:sqlite");
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("authenticate(ctx.inputPath) returns ok when file readable (snapshot mode)", async () => {
|
|
242
|
+
const { dir, dbPath } = tmpDb();
|
|
243
|
+
try {
|
|
244
|
+
const a = new TelegramAdapter();
|
|
245
|
+
const auth = await a.authenticate({ inputPath: dbPath });
|
|
246
|
+
expect(auth.ok).toBe(true);
|
|
247
|
+
expect(auth.mode).toBe("snapshot-file");
|
|
248
|
+
} finally { cleanup(dir); }
|
|
236
249
|
});
|
|
237
250
|
|
|
238
251
|
it("sync yields user + chat + messages (no key needed)", async () => {
|
|
@@ -183,6 +183,102 @@ describe("TaobaoAdapter", () => {
|
|
|
183
183
|
for await (const r of a.sync()) raws.push(r);
|
|
184
184
|
expect(raws).toHaveLength(0);
|
|
185
185
|
});
|
|
186
|
+
|
|
187
|
+
// §2.4d v0.2 — snapshot mode (mirror shopping-jd/meituan/pinduoduo dual-mode).
|
|
188
|
+
// Android in-APK collector ships JSON snapshot via syncAdapter("shopping-
|
|
189
|
+
// taobao", path); desktop adapter consumes via inputPath.
|
|
190
|
+
|
|
191
|
+
it("snapshot mode — no-arg ctor passes contract", () => {
|
|
192
|
+
const a = new TaobaoAdapter();
|
|
193
|
+
expect(assertAdapter(a).ok).toBe(true);
|
|
194
|
+
expect(a.capabilities).toContain("sync:snapshot");
|
|
195
|
+
expect(a.capabilities).toContain("sync:cookie-api"); // both advertised
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("snapshot mode — authenticate(ctx.inputPath) returns ok when file readable", async () => {
|
|
199
|
+
const fs = require("node:fs");
|
|
200
|
+
const path = require("node:path");
|
|
201
|
+
const os = require("node:os");
|
|
202
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "taobao-snap-"));
|
|
203
|
+
const inputPath = path.join(dir, "snap.json");
|
|
204
|
+
fs.writeFileSync(inputPath, "{}", "utf-8");
|
|
205
|
+
try {
|
|
206
|
+
const a = new TaobaoAdapter();
|
|
207
|
+
const auth = await a.authenticate({ inputPath });
|
|
208
|
+
expect(auth.ok).toBe(true);
|
|
209
|
+
expect(auth.mode).toBe("snapshot-file");
|
|
210
|
+
} finally {
|
|
211
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("snapshot mode — sync yields order events from snapshot file", async () => {
|
|
216
|
+
const fs = require("node:fs");
|
|
217
|
+
const path = require("node:path");
|
|
218
|
+
const os = require("node:os");
|
|
219
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "taobao-snap-yield-"));
|
|
220
|
+
const inputPath = path.join(dir, "snap.json");
|
|
221
|
+
fs.writeFileSync(inputPath, JSON.stringify({
|
|
222
|
+
schemaVersion: 1,
|
|
223
|
+
snapshottedAt: 1_700_000_000_000,
|
|
224
|
+
account: { userId: "u-snap" },
|
|
225
|
+
events: [
|
|
226
|
+
{
|
|
227
|
+
kind: "order",
|
|
228
|
+
id: "TB-SNAP-1",
|
|
229
|
+
capturedAt: 1_700_000_100_000,
|
|
230
|
+
vendorId: "taobao",
|
|
231
|
+
orderId: "TB-SNAP-1",
|
|
232
|
+
placedAt: 1_700_000_000_000,
|
|
233
|
+
paidAt: 1_700_000_010_000,
|
|
234
|
+
status: "delivered",
|
|
235
|
+
merchantName: "Test 旗舰店",
|
|
236
|
+
totalAmount: { value: 123.45, currency: "CNY" },
|
|
237
|
+
items: [{ name: "Item X", quantity: 1, unitPrice: 123.45 }],
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
}), "utf-8");
|
|
241
|
+
try {
|
|
242
|
+
const a = new TaobaoAdapter();
|
|
243
|
+
const raws = [];
|
|
244
|
+
for await (const r of a.sync({ inputPath })) raws.push(r);
|
|
245
|
+
expect(raws).toHaveLength(1);
|
|
246
|
+
expect(raws[0].adapter).toBe("shopping-taobao");
|
|
247
|
+
expect(raws[0].kind).toBe("order");
|
|
248
|
+
expect(raws[0].originalId).toBe("taobao:order:TB-SNAP-1");
|
|
249
|
+
const batch = a.normalize(raws[0]);
|
|
250
|
+
expect(validateBatch(batch).valid).toBe(true);
|
|
251
|
+
} finally {
|
|
252
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("snapshot mode — schemaVersion mismatch throws", async () => {
|
|
257
|
+
const fs = require("node:fs");
|
|
258
|
+
const path = require("node:path");
|
|
259
|
+
const os = require("node:os");
|
|
260
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "taobao-snap-bad-"));
|
|
261
|
+
const inputPath = path.join(dir, "snap.json");
|
|
262
|
+
fs.writeFileSync(inputPath, JSON.stringify({ schemaVersion: 99, events: [] }), "utf-8");
|
|
263
|
+
try {
|
|
264
|
+
const a = new TaobaoAdapter();
|
|
265
|
+
let threw = null;
|
|
266
|
+
try {
|
|
267
|
+
for await (const _r of a.sync({ inputPath })) { /* drain */ }
|
|
268
|
+
} catch (err) { threw = err; }
|
|
269
|
+
expect(threw).toBeTruthy();
|
|
270
|
+
expect(threw.message).toMatch(/schemaVersion mismatch/);
|
|
271
|
+
} finally {
|
|
272
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("no-arg ctor + no inputPath = NO_INPUT (legible failure)", async () => {
|
|
277
|
+
const a = new TaobaoAdapter();
|
|
278
|
+
const auth = await a.authenticate({});
|
|
279
|
+
expect(auth.ok).toBe(false);
|
|
280
|
+
expect(auth.reason).toBe("NO_INPUT");
|
|
281
|
+
});
|
|
186
282
|
});
|
|
187
283
|
|
|
188
284
|
// ─── JdAdapter ───────────────────────────────────────────────────────────
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Phase 6a — SignProvider abstract + NullSignProvider unit cover.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect } from "vitest";
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
SignProvider,
|
|
11
|
+
NullSignProvider,
|
|
12
|
+
NULL_SIGN_PROVIDER,
|
|
13
|
+
} = require("../lib/sign-providers");
|
|
14
|
+
|
|
15
|
+
describe("SignProvider abstract base", () => {
|
|
16
|
+
it("signUrl returns null by default", async () => {
|
|
17
|
+
const p = new SignProvider();
|
|
18
|
+
expect(await p.signUrl("https://example.com", "purpose")).toBe(null);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("signedHeaders returns {} by default", async () => {
|
|
22
|
+
const p = new SignProvider();
|
|
23
|
+
const r = await p.signedHeaders("https://example.com", "purpose");
|
|
24
|
+
expect(r).toEqual({});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("shutdown is no-op (no throw)", async () => {
|
|
28
|
+
const p = new SignProvider();
|
|
29
|
+
await expect(p.shutdown()).resolves.toBeUndefined();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("NullSignProvider", () => {
|
|
34
|
+
it("extends SignProvider", () => {
|
|
35
|
+
const p = new NullSignProvider();
|
|
36
|
+
expect(p).toBeInstanceOf(SignProvider);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("inherits stub signUrl / signedHeaders / shutdown", async () => {
|
|
40
|
+
const p = new NullSignProvider();
|
|
41
|
+
expect(await p.signUrl("x", "y")).toBe(null);
|
|
42
|
+
expect(await p.signedHeaders("x", "y")).toEqual({});
|
|
43
|
+
await expect(p.shutdown()).resolves.toBeUndefined();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("NULL_SIGN_PROVIDER is a frozen singleton", () => {
|
|
47
|
+
expect(NULL_SIGN_PROVIDER).toBeInstanceOf(NullSignProvider);
|
|
48
|
+
expect(Object.isFrozen(NULL_SIGN_PROVIDER)).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("api-client pattern: call signUrl + signedHeaders without crash", async () => {
|
|
52
|
+
// Simulates api-client usage — signProvider.signUrl(url, purpose) ||
|
|
53
|
+
// fall back to unsigned URL; spread signedHeaders into request headers.
|
|
54
|
+
const provider = NULL_SIGN_PROVIDER;
|
|
55
|
+
const url = "https://api.example.com/x";
|
|
56
|
+
const signedUrl = (await provider.signUrl(url, "test")) || url;
|
|
57
|
+
expect(signedUrl).toBe(url); // null → fall back to original
|
|
58
|
+
const extraHeaders = await provider.signedHeaders(url, "test");
|
|
59
|
+
const finalHeaders = { Cookie: "x=y", ...extraHeaders };
|
|
60
|
+
expect(finalHeaders).toEqual({ Cookie: "x=y" }); // no extras from null provider
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -299,6 +299,65 @@ describe("CtripAdapter", () => {
|
|
|
299
299
|
expect(CTRIP_TYPE_MAP.train).toBe("train");
|
|
300
300
|
expect(CTRIP_TYPE_MAP.cruise).toBe("cruise");
|
|
301
301
|
});
|
|
302
|
+
|
|
303
|
+
// §9.3b v0.2 — no-arg ctor (auto-register at boot) + inputPath alias for
|
|
304
|
+
// Android in-APK cc syncAdapter("travel-ctrip", path). Earlier strict ctor
|
|
305
|
+
// (opts.account.email required) blocked the auto-register loop.
|
|
306
|
+
|
|
307
|
+
it("no-arg ctor passes contract (snapshot mode)", () => {
|
|
308
|
+
const a = new CtripAdapter();
|
|
309
|
+
expect(assertAdapter(a).ok).toBe(true);
|
|
310
|
+
expect(a.capabilities).toContain("sync:snapshot");
|
|
311
|
+
expect(a.capabilities).toContain("import:json"); // both kept
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("sync(inputPath) alias yields records same as dataPath", async () => {
|
|
315
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "ctrip-snap-"));
|
|
316
|
+
const inputPath = path.join(dir, "snap.json");
|
|
317
|
+
fs.writeFileSync(inputPath, JSON.stringify([
|
|
318
|
+
{
|
|
319
|
+
orderId: "C-SNAP-1", type: "flight",
|
|
320
|
+
depCity: "上海", arrCity: "北京",
|
|
321
|
+
flightNumber: "MU100", airline: "东航",
|
|
322
|
+
departureTime: "2026-05-01 08:00:00",
|
|
323
|
+
arrivalTime: "2026-05-01 10:30:00",
|
|
324
|
+
passengerName: "张三", price: 800, pnr: "XYZ",
|
|
325
|
+
},
|
|
326
|
+
]), "utf-8");
|
|
327
|
+
try {
|
|
328
|
+
const a = new CtripAdapter();
|
|
329
|
+
const raws = [];
|
|
330
|
+
for await (const r of a.sync({ inputPath })) raws.push(r);
|
|
331
|
+
expect(raws).toHaveLength(1);
|
|
332
|
+
expect(raws[0].adapter).toBe("travel-ctrip");
|
|
333
|
+
expect(raws[0].originalId).toBe("C-SNAP-1");
|
|
334
|
+
const batch = a.normalize(raws[0]);
|
|
335
|
+
expect(validateBatch(batch).valid).toBe(true);
|
|
336
|
+
} finally {
|
|
337
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it("authenticate(ctx.inputPath) returns ok when file readable", async () => {
|
|
342
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "ctrip-auth-"));
|
|
343
|
+
const inputPath = path.join(dir, "snap.json");
|
|
344
|
+
fs.writeFileSync(inputPath, "[]", "utf-8");
|
|
345
|
+
try {
|
|
346
|
+
const a = new CtripAdapter();
|
|
347
|
+
const auth = await a.authenticate({ inputPath });
|
|
348
|
+
expect(auth.ok).toBe(true);
|
|
349
|
+
expect(auth.mode).toBe("snapshot-file");
|
|
350
|
+
} finally {
|
|
351
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it("authenticate(no path) ok with mode=ready (no account required)", async () => {
|
|
356
|
+
const a = new CtripAdapter();
|
|
357
|
+
const auth = await a.authenticate({});
|
|
358
|
+
expect(auth.ok).toBe(true);
|
|
359
|
+
expect(auth.mode).toBe("ready");
|
|
360
|
+
});
|
|
302
361
|
});
|
|
303
362
|
|
|
304
363
|
// ─── Amap adapter (mocked SQLite) ───────────────────────────────────────
|
|
@@ -310,6 +369,13 @@ describe("AmapAdapter", () => {
|
|
|
310
369
|
expect(a.extractMode).toBe("device-pull");
|
|
311
370
|
});
|
|
312
371
|
|
|
372
|
+
it("no-arg ctor passes contract (2026-05-25 v0.6 — account.deviceId OPTIONAL for snapshot mode)", () => {
|
|
373
|
+
const a = new AmapAdapter();
|
|
374
|
+
expect(assertAdapter(a).ok).toBe(true);
|
|
375
|
+
expect(a.capabilities).toContain("sync:snapshot");
|
|
376
|
+
expect(a.capabilities).toContain("sync:sqlite");
|
|
377
|
+
});
|
|
378
|
+
|
|
313
379
|
it("sync yields route + search records via mocked driver", async () => {
|
|
314
380
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "amap-"));
|
|
315
381
|
const dbPath = path.join(dir, "amap.db");
|
|
@@ -43,8 +43,11 @@ describe("WhatsAppAdapter", () => {
|
|
|
43
43
|
expect(a.dataDisclosure.legalGate).toBe(true);
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
it("
|
|
47
|
-
|
|
46
|
+
it("no-arg ctor passes contract (2026-05-25 v0.6 — account.phone OPTIONAL for snapshot mode)", () => {
|
|
47
|
+
const a = new WhatsAppAdapter();
|
|
48
|
+
expect(assertAdapter(a).ok).toBe(true);
|
|
49
|
+
expect(a.capabilities).toContain("sync:snapshot");
|
|
50
|
+
expect(a.capabilities).toContain("sync:sqlite");
|
|
48
51
|
});
|
|
49
52
|
|
|
50
53
|
it("authenticate fails without DB", async () => {
|
|
@@ -12,7 +12,16 @@ const os = require("node:os");
|
|
|
12
12
|
// better-sqlite3 tracks Node's ABI 127 (test path). Whichever loads
|
|
13
13
|
// without NODE_MODULE_VERSION mismatch wins. Both expose the same
|
|
14
14
|
// Database class for unencrypted DBs.
|
|
15
|
+
//
|
|
16
|
+
// CRITICAL: must be lazy. Calling at module-load time means any require()
|
|
17
|
+
// of this file (e.g. via PDH wiring's eager `require("@chainlesschain/
|
|
18
|
+
// personal-data-hub/adapters/browser-history-chrome")`) throws synchronously
|
|
19
|
+
// when both modules are absent/ABI-mismatched, killing the entire main
|
|
20
|
+
// process before the BrowserHistoryChromeAdapter try/catch in wiring.js
|
|
21
|
+
// can swallow it. See v5.0.3.87 crash + handbook trap #23.
|
|
22
|
+
let _cachedDatabaseClass = null;
|
|
15
23
|
function loadDatabase() {
|
|
24
|
+
if (_cachedDatabaseClass) return _cachedDatabaseClass;
|
|
16
25
|
for (const mod of ["better-sqlite3-multiple-ciphers", "better-sqlite3"]) {
|
|
17
26
|
let cls;
|
|
18
27
|
try {
|
|
@@ -27,6 +36,7 @@ function loadDatabase() {
|
|
|
27
36
|
try {
|
|
28
37
|
const probe = new cls(":memory:");
|
|
29
38
|
probe.close();
|
|
39
|
+
_cachedDatabaseClass = cls;
|
|
30
40
|
return cls;
|
|
31
41
|
} catch (_e) {
|
|
32
42
|
// ABI mismatch — try next candidate
|
|
@@ -36,7 +46,6 @@ function loadDatabase() {
|
|
|
36
46
|
"chrome-db-reader: neither better-sqlite3-multiple-ciphers nor better-sqlite3 loaded — both ABI-mismatched",
|
|
37
47
|
);
|
|
38
48
|
}
|
|
39
|
-
const Database = loadDatabase();
|
|
40
49
|
|
|
41
50
|
// WebKit timestamps are microseconds since 1601-01-01 UTC. Convert to
|
|
42
51
|
// epoch-ms by shifting the epoch (11644473600 seconds × 1e6 µs/s).
|
|
@@ -168,6 +177,7 @@ function* readVisits(tmpPath, opts = {}) {
|
|
|
168
177
|
: 0n;
|
|
169
178
|
const limit = Number.isInteger(opts.limit) && opts.limit > 0 ? opts.limit : 200_000;
|
|
170
179
|
const includeHidden = opts.includeHidden === true;
|
|
180
|
+
const Database = loadDatabase();
|
|
171
181
|
const db = new Database(tmpPath, { readonly: true });
|
|
172
182
|
try {
|
|
173
183
|
// Bind sinceWk as a string — better-sqlite3 accepts BigInt only when
|