@chainlesschain/personal-data-hub 0.4.18 → 0.4.23
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/biz-tianyancha.test.js +159 -0
- package/__tests__/adapters/doc-camscanner.test.js +147 -0
- package/__tests__/adapters/gov-ixiamen.test.js +150 -0
- package/__tests__/adapters/gov-tax.test.js +135 -0
- package/__tests__/adapters/health-meiyou.test.js +125 -0
- package/__tests__/adapters/social-dongchedi.test.js +165 -0
- package/__tests__/adapters/video-xigua.test.js +106 -0
- package/__tests__/adapters/wework-pc.test.js +124 -0
- package/lib/adapter-guide.js +13 -3
- package/lib/adapters/biz-tianyancha/index.js +348 -0
- package/lib/adapters/doc-camscanner/index.js +102 -0
- package/lib/adapters/gov-ixiamen/index.js +380 -0
- package/lib/adapters/gov-tax/index.js +451 -0
- package/lib/adapters/health-meiyou/index.js +393 -0
- package/lib/adapters/social-dongchedi/index.js +360 -0
- package/lib/adapters/video-xigua/index.js +68 -0
- package/lib/adapters/wework-pc/index.js +31 -0
- package/lib/index.js +16 -0
- package/package.json +1 -1
|
@@ -0,0 +1,125 @@
|
|
|
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 my = require("../../lib/adapters/health-meiyou");
|
|
10
|
+
|
|
11
|
+
function writeTmp(content) {
|
|
12
|
+
const p = path.join(os.tmpdir(), `cc-my-${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 = "myclient_id=abc; sid=xyz";
|
|
23
|
+
|
|
24
|
+
describe("health-meiyou mappers", () => {
|
|
25
|
+
it("name/version", () => {
|
|
26
|
+
expect(my.NAME).toBe("health-meiyou");
|
|
27
|
+
expect(my.VERSION).toBe("0.1.0");
|
|
28
|
+
});
|
|
29
|
+
it("mapPeriod / mapRecord field aliases; no id → null", () => {
|
|
30
|
+
const p = my.mapPeriod({ record_id: "P1", start_date: 1716383000, end_date: 1716800000, cycle_length: 28, period_length: 5 });
|
|
31
|
+
expect(p).toMatchObject({ recordId: "P1", cycleLength: 28, periodLength: 5 });
|
|
32
|
+
expect(p.startMs).toBe(1716383000000);
|
|
33
|
+
expect(my.mapPeriod({})).toBe(null);
|
|
34
|
+
const r = my.mapRecord({ id: "R1", record_type: "mood", date: 1716383000, value: "开心", remark: "今天不错" });
|
|
35
|
+
expect(r).toMatchObject({ recordId: "R1", recordType: "mood", value: "开心", note: "今天不错" });
|
|
36
|
+
expect(my.mapRecord({ note: "noid" })).toBe(null);
|
|
37
|
+
});
|
|
38
|
+
it("extractList tolerant", () => {
|
|
39
|
+
expect(my.extractList({ list: [{ id: 1 }] })).toHaveLength(1);
|
|
40
|
+
expect(my.extractList({ data: { calendar: [{ id: 1 }] } })).toHaveLength(1);
|
|
41
|
+
expect(my.extractList({})).toEqual([]);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("MeiyouAdapter (snapshot + cookie-api)", () => {
|
|
46
|
+
const SNAP = JSON.stringify({
|
|
47
|
+
schemaVersion: 1,
|
|
48
|
+
snapshottedAt: 1716383000000,
|
|
49
|
+
account: { userId: "u1" },
|
|
50
|
+
events: [
|
|
51
|
+
{ kind: "period", id: "p-P1", recordId: "P1", startDate: 1716383000, endDate: 1716800000, cycleLength: 28, periodLength: 5 },
|
|
52
|
+
{ kind: "record", id: "r-R1", recordId: "R1", recordType: "mood", date: 1716383000, value: "开心" },
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("snapshot sync + normalize → period + record events", async () => {
|
|
57
|
+
const p = writeTmp(SNAP);
|
|
58
|
+
try {
|
|
59
|
+
const a = new my.MeiyouAdapter();
|
|
60
|
+
expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
|
|
61
|
+
const items = await collect(a.sync({ inputPath: p }));
|
|
62
|
+
expect(items).toHaveLength(2);
|
|
63
|
+
const period = a.normalize(items[0]);
|
|
64
|
+
expect(period.events[0].subtype).toBe("other");
|
|
65
|
+
expect(period.events[0].content.title).toBe("经期记录");
|
|
66
|
+
expect(period.events[0].extra.cycleLength).toBe(28);
|
|
67
|
+
expect(items[0].originalId).toBe("meiyou:period:P1");
|
|
68
|
+
const record = a.normalize(items[1]);
|
|
69
|
+
expect(record.events[0].extra.recordType).toBe("mood");
|
|
70
|
+
expect(record.events[0].extra.value).toBe("开心");
|
|
71
|
+
expect(items[1].originalId).toBe("meiyou:record:R1");
|
|
72
|
+
} finally {
|
|
73
|
+
fs.unlinkSync(p);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("dataDisclosure: high sensitivity + legalGate (reproductive health)", () => {
|
|
78
|
+
const a = new my.MeiyouAdapter();
|
|
79
|
+
expect(a.dataDisclosure.sensitivity).toBe("high");
|
|
80
|
+
expect(a.dataDisclosure.legalGate).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("include filter can exclude a kind", async () => {
|
|
84
|
+
const p = writeTmp(SNAP);
|
|
85
|
+
try {
|
|
86
|
+
const a = new my.MeiyouAdapter();
|
|
87
|
+
const items = await collect(a.sync({ inputPath: p, include: { record: false } }));
|
|
88
|
+
expect(items).toHaveLength(1);
|
|
89
|
+
expect(items[0].kind).toBe("period");
|
|
90
|
+
} finally {
|
|
91
|
+
fs.unlinkSync(p);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("cookie-api: best-effort fetch both kinds + unverified flag + sign seam", async () => {
|
|
96
|
+
const calls = [];
|
|
97
|
+
let signed = 0;
|
|
98
|
+
const a = new my.MeiyouAdapter({
|
|
99
|
+
account: { cookies: COOKIES, userId: "u1" },
|
|
100
|
+
signProvider: async () => {
|
|
101
|
+
signed += 1;
|
|
102
|
+
return "sig";
|
|
103
|
+
},
|
|
104
|
+
fetchFn: async ({ url, query }) => {
|
|
105
|
+
calls.push({ url, page: query.page });
|
|
106
|
+
if (query.page > 1) return { list: [] };
|
|
107
|
+
if (url.includes("/period")) return { list: [{ recordId: "P9", startDate: 1716383000, cycleLength: 30 }] };
|
|
108
|
+
return { list: [{ recordId: "R9", recordType: "weight", date: 1716383000, value: 55 }] };
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
const auth = await a.authenticate();
|
|
112
|
+
expect(auth).toMatchObject({ ok: true, mode: "cookie", unverified: true });
|
|
113
|
+
const items = await collect(a.sync({}));
|
|
114
|
+
expect(items).toHaveLength(2);
|
|
115
|
+
expect(items.map((i) => i.originalId).sort()).toEqual(["meiyou:period:P9", "meiyou:record:R9"]);
|
|
116
|
+
expect(signed).toBeGreaterThan(0);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("default fetch throws; no input throws", async () => {
|
|
120
|
+
const a = new my.MeiyouAdapter({ account: { cookies: COOKIES } });
|
|
121
|
+
await expect(collect(a.sync({}))).rejects.toThrow(/no fetchFn configured/);
|
|
122
|
+
const b = new my.MeiyouAdapter();
|
|
123
|
+
await expect(collect(b.sync({}))).rejects.toThrow(/needs opts.inputPath/);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
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 {
|
|
10
|
+
DongchediAdapter,
|
|
11
|
+
extractData,
|
|
12
|
+
isEnd,
|
|
13
|
+
NAME,
|
|
14
|
+
VERSION,
|
|
15
|
+
SNAPSHOT_SCHEMA_VERSION,
|
|
16
|
+
} = require("../../lib/adapters/social-dongchedi");
|
|
17
|
+
|
|
18
|
+
function writeTmp(content) {
|
|
19
|
+
const p = path.join(os.tmpdir(), `cc-dcd-${crypto.randomUUID()}.json`);
|
|
20
|
+
fs.writeFileSync(p, content, "utf-8");
|
|
21
|
+
return p;
|
|
22
|
+
}
|
|
23
|
+
async function collect(gen) {
|
|
24
|
+
const out = [];
|
|
25
|
+
for await (const x of gen) out.push(x);
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const COOKIES = "tt_webid=abc; sessionid=xyz";
|
|
30
|
+
|
|
31
|
+
const SNAP = JSON.stringify({
|
|
32
|
+
schemaVersion: 1,
|
|
33
|
+
snapshottedAt: 1716383000000,
|
|
34
|
+
account: { userId: "u1" },
|
|
35
|
+
events: [
|
|
36
|
+
{ kind: "favourite", id: "fav-1", itemId: "G1", title: "2026 新能源车横评", contentType: "article", url: "https://x/G1", capturedAt: 1716300000000 },
|
|
37
|
+
{ kind: "follow", id: "follow-S1", followId: "S1", name: "理想 L 系列", followType: "series", capturedAt: 1716320000000 },
|
|
38
|
+
],
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("constants + helpers", () => {
|
|
42
|
+
it("name/version/schema", () => {
|
|
43
|
+
expect(NAME).toBe("social-dongchedi");
|
|
44
|
+
expect(VERSION).toBe("0.1.0");
|
|
45
|
+
expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
|
|
46
|
+
});
|
|
47
|
+
it("extractData tolerant", () => {
|
|
48
|
+
expect(extractData({ data: [{ id: 1 }] })).toHaveLength(1);
|
|
49
|
+
expect(extractData({ data: { favorite_list: [{ id: 1 }] } })).toHaveLength(1);
|
|
50
|
+
expect(extractData({ data: { follow_list: [{ id: 1 }] } })).toHaveLength(1);
|
|
51
|
+
expect(extractData({})).toEqual([]);
|
|
52
|
+
});
|
|
53
|
+
it("isEnd reads has_more", () => {
|
|
54
|
+
expect(isEnd({ data: { has_more: false } })).toBe(true);
|
|
55
|
+
expect(isEnd({ has_more: 0 })).toBe(true);
|
|
56
|
+
expect(isEnd({ data: { has_more: true } })).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("DongchediAdapter snapshot mode", () => {
|
|
61
|
+
it("authenticate validates inputPath", async () => {
|
|
62
|
+
const p = writeTmp(SNAP);
|
|
63
|
+
try {
|
|
64
|
+
const a = new DongchediAdapter();
|
|
65
|
+
expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
|
|
66
|
+
expect((await a.authenticate({ inputPath: path.join(os.tmpdir(), "no-dcd.json") })).reason).toBe("INPUT_PATH_UNREADABLE");
|
|
67
|
+
} finally {
|
|
68
|
+
fs.unlinkSync(p);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("sync 2 kinds + normalize favourite→like / follow→person", async () => {
|
|
73
|
+
const p = writeTmp(SNAP);
|
|
74
|
+
try {
|
|
75
|
+
const a = new DongchediAdapter();
|
|
76
|
+
const items = await collect(a.sync({ inputPath: p }));
|
|
77
|
+
expect(items.map((x) => x.kind)).toEqual(["favourite", "follow"]);
|
|
78
|
+
|
|
79
|
+
const fav = a.normalize(items[0]);
|
|
80
|
+
expect(fav.events[0].subtype).toBe("like");
|
|
81
|
+
expect(fav.events[0].content.title).toBe("收藏: 2026 新能源车横评");
|
|
82
|
+
expect(fav.events[0].extra.contentType).toBe("article");
|
|
83
|
+
|
|
84
|
+
const fol = a.normalize(items[1]);
|
|
85
|
+
expect(fol.persons[0].subtype).toBe("contact");
|
|
86
|
+
expect(fol.persons[0].names).toEqual(["理想 L 系列"]);
|
|
87
|
+
expect(fol.persons[0].identifiers["dongchedi-id"]).toEqual(["S1"]);
|
|
88
|
+
expect(fol.persons[0].extra.followType).toBe("series");
|
|
89
|
+
} finally {
|
|
90
|
+
fs.unlinkSync(p);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("include + limit + schema mismatch + unknown kind", async () => {
|
|
95
|
+
const p = writeTmp(SNAP);
|
|
96
|
+
try {
|
|
97
|
+
const a = new DongchediAdapter();
|
|
98
|
+
expect((await collect(a.sync({ inputPath: p, include: { favourite: false } }))).map((x) => x.kind)).toEqual(["follow"]);
|
|
99
|
+
expect(await collect(a.sync({ inputPath: p, limit: 1 }))).toHaveLength(1);
|
|
100
|
+
expect(() => a.normalize({ kind: "bogus", payload: {} })).toThrow(/unknown kind/);
|
|
101
|
+
} finally {
|
|
102
|
+
fs.unlinkSync(p);
|
|
103
|
+
}
|
|
104
|
+
const bad = writeTmp(JSON.stringify({ schemaVersion: 9, events: [] }));
|
|
105
|
+
try {
|
|
106
|
+
const a = new DongchediAdapter();
|
|
107
|
+
await expect(collect(a.sync({ inputPath: bad }))).rejects.toThrow(/schemaVersion mismatch/);
|
|
108
|
+
} finally {
|
|
109
|
+
fs.unlinkSync(bad);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe("DongchediAdapter cookie-api mode", () => {
|
|
115
|
+
it("authenticate cookie (userId optional)", async () => {
|
|
116
|
+
const a = new DongchediAdapter({ account: { cookies: COOKIES } });
|
|
117
|
+
expect(await a.authenticate()).toEqual({ ok: true, account: null, mode: "cookie" });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("sync fetches favourites + follows, normalizes", async () => {
|
|
121
|
+
const byUrl = (u) => (u.includes("favorite") ? "favourite" : "follow");
|
|
122
|
+
const data = {
|
|
123
|
+
favourite: [{ group_id: "G1", title: "试驾视频", content_type: "video", create_time: 1716300000 }],
|
|
124
|
+
follow: [{ series_id: "S9", series_name: "比亚迪汉", follow_time: 1716320000 }],
|
|
125
|
+
};
|
|
126
|
+
const calls = [];
|
|
127
|
+
const a = new DongchediAdapter({
|
|
128
|
+
account: { cookies: COOKIES, userId: "u1" },
|
|
129
|
+
fetchFn: async ({ url, cookies, query, sign }) => {
|
|
130
|
+
const k = byUrl(url);
|
|
131
|
+
calls.push({ k, cookies, offset: query.offset, sign });
|
|
132
|
+
return { data: { list: query.offset === 0 ? data[k] : [], has_more: false } };
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
const items = await collect(a.sync({}));
|
|
136
|
+
expect(items.map((x) => x.kind).sort()).toEqual(["favourite", "follow"]);
|
|
137
|
+
expect(calls.every((c) => c.cookies === COOKIES && c.sign === null)).toBe(true);
|
|
138
|
+
const fav = a.normalize(items.find((x) => x.kind === "favourite"));
|
|
139
|
+
expect(fav.events[0].content.title).toBe("收藏: 试驾视频");
|
|
140
|
+
const fol = a.normalize(items.find((x) => x.kind === "follow"));
|
|
141
|
+
expect(fol.persons[0].names).toEqual(["比亚迪汉"]);
|
|
142
|
+
expect(fol.persons[0].extra.followType).toBe("series");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("invokes signProvider + limit + empty + default fetch + no input", async () => {
|
|
146
|
+
const signCalls = [];
|
|
147
|
+
const a = new DongchediAdapter({
|
|
148
|
+
account: { cookies: COOKIES },
|
|
149
|
+
fetchFn: async ({ query }) => ({ data: { list: query.offset === 0 ? [{ group_id: "G1", title: "x" }, { group_id: "G2", title: "y" }] : [], has_more: false } }),
|
|
150
|
+
signProvider: async (ctx) => { signCalls.push(ctx); return "x-bogus"; },
|
|
151
|
+
});
|
|
152
|
+
expect(await collect(a.sync({ limit: 1, include: { follow: false } }))).toHaveLength(1);
|
|
153
|
+
expect(signCalls.length).toBeGreaterThan(0);
|
|
154
|
+
expect(signCalls[0].cookies).toBe(COOKIES);
|
|
155
|
+
|
|
156
|
+
const a2 = new DongchediAdapter({ account: { cookies: COOKIES }, fetchFn: async () => "<html>login</html>" });
|
|
157
|
+
expect(await collect(a2.sync({}))).toEqual([]);
|
|
158
|
+
|
|
159
|
+
const a3 = new DongchediAdapter({ account: { cookies: COOKIES } });
|
|
160
|
+
await expect(collect(a3.sync({}))).rejects.toThrow(/no fetchFn configured/);
|
|
161
|
+
|
|
162
|
+
const a4 = new DongchediAdapter();
|
|
163
|
+
await expect(collect(a4.sync({}))).rejects.toThrow(/needs opts.inputPath/);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
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 { XiguaVideoAdapter, extractItems, mapItem, NAME, VERSION } = require("../../lib/adapters/video-xigua");
|
|
10
|
+
|
|
11
|
+
function writeTmp(content) {
|
|
12
|
+
const p = path.join(os.tmpdir(), `cc-xig-${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 = "sid_tt=abc; ttwid=xyz";
|
|
23
|
+
|
|
24
|
+
describe("video-xigua mappers", () => {
|
|
25
|
+
it("name/version", () => {
|
|
26
|
+
expect(NAME).toBe("video-xigua");
|
|
27
|
+
expect(VERSION).toBe("0.1.0");
|
|
28
|
+
});
|
|
29
|
+
it("mapItem reads nested article + bytedance fields", () => {
|
|
30
|
+
const rec = mapItem({ behot_time: 1716300000, article: { group_id: "G1", title: "城市骑行 vlog", video_duration: 620, user_name: "骑行小王" } });
|
|
31
|
+
expect(rec).toMatchObject({ videoId: "G1", title: "城市骑行 vlog", durationSec: 620, channel: "骑行小王" });
|
|
32
|
+
expect(rec.occurredAt).toBe(1716300000000);
|
|
33
|
+
expect(rec.url).toContain("ixigua.com");
|
|
34
|
+
expect(mapItem({ article: { title: "noid" } })).toBe(null);
|
|
35
|
+
});
|
|
36
|
+
it("mapItem reads flat item too", () => {
|
|
37
|
+
const rec = mapItem({ group_id: "G2", title: "测评", duration: 300, create_time: 1716310000 });
|
|
38
|
+
expect(rec).toMatchObject({ videoId: "G2", title: "测评", durationSec: 300 });
|
|
39
|
+
});
|
|
40
|
+
it("extractItems tolerant", () => {
|
|
41
|
+
expect(extractItems({ data: { history: [{ group_id: 1 }] } })).toHaveLength(1);
|
|
42
|
+
expect(extractItems({ data: { favorites: [{ group_id: 1 }] } })).toHaveLength(1);
|
|
43
|
+
expect(extractItems({})).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("XiguaVideoAdapter (via _video-base)", () => {
|
|
48
|
+
const SNAP = JSON.stringify({
|
|
49
|
+
schemaVersion: 1,
|
|
50
|
+
snapshottedAt: 1716383000000,
|
|
51
|
+
account: { userId: "u1" },
|
|
52
|
+
events: [
|
|
53
|
+
{ kind: "watch", id: "w1", videoId: "V1", title: "纪录片:长江", category: "documentary", durationSec: 3600, capturedAt: 1716300000000 },
|
|
54
|
+
{ kind: "favourite", id: "fa1", videoId: "V2", title: "搞笑合集" },
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("snapshot sync 2 kinds + normalize watch→media / favourite→like", async () => {
|
|
59
|
+
const p = writeTmp(SNAP);
|
|
60
|
+
try {
|
|
61
|
+
const a = new XiguaVideoAdapter();
|
|
62
|
+
const items = await collect(a.sync({ inputPath: p }));
|
|
63
|
+
expect(items.map((x) => x.kind)).toEqual(["watch", "favourite"]);
|
|
64
|
+
const w = a.normalize(items[0]);
|
|
65
|
+
expect(w.events[0].subtype).toBe("media");
|
|
66
|
+
expect(w.events[0].content.title).toBe("观看: 纪录片:长江");
|
|
67
|
+
expect(w.items[0].subtype).toBe("media");
|
|
68
|
+
expect(w.items[0].extra.platform).toBe("xigua");
|
|
69
|
+
const fav = a.normalize(items[1]);
|
|
70
|
+
expect(fav.events[0].subtype).toBe("like");
|
|
71
|
+
expect(fav.events[0].content.title).toBe("收藏: 搞笑合集");
|
|
72
|
+
} finally {
|
|
73
|
+
fs.unlinkSync(p);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("cookie-api fetch + normalize", async () => {
|
|
78
|
+
const byUrl = (u) => (u.includes("history") ? "watch" : "favourite");
|
|
79
|
+
const data = {
|
|
80
|
+
watch: [{ behot_time: 1716300000, article: { group_id: "C1", title: "汽车评测", video_duration: 500 } }],
|
|
81
|
+
favourite: [{ group_id: "C2", title: "美食教程" }],
|
|
82
|
+
};
|
|
83
|
+
const calls = [];
|
|
84
|
+
const a = new XiguaVideoAdapter({
|
|
85
|
+
account: { cookies: COOKIES, userId: "u1" },
|
|
86
|
+
fetchFn: async ({ url, cookies, query, sign }) => {
|
|
87
|
+
const k = byUrl(url);
|
|
88
|
+
calls.push({ k, cookies, page: query.page, sign });
|
|
89
|
+
return { data: { list: query.page === 1 ? data[k] : [] } };
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
expect(await a.authenticate()).toEqual({ ok: true, account: "u1", mode: "cookie" });
|
|
93
|
+
const items = await collect(a.sync({}));
|
|
94
|
+
expect(items.map((x) => x.kind).sort()).toEqual(["favourite", "watch"]);
|
|
95
|
+
expect(calls.every((c) => c.cookies === COOKIES && c.sign === null)).toBe(true);
|
|
96
|
+
const w = a.normalize(items.find((x) => x.kind === "watch"));
|
|
97
|
+
expect(w.events[0].content.title).toBe("观看: 汽车评测");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("default fetch throws; no input throws", async () => {
|
|
101
|
+
const a = new XiguaVideoAdapter({ account: { cookies: COOKIES } });
|
|
102
|
+
await expect(collect(a.sync({}))).rejects.toThrow(/no fetchFn configured/);
|
|
103
|
+
const b = new XiguaVideoAdapter();
|
|
104
|
+
await expect(collect(b.sync({}))).rejects.toThrow(/needs opts.inputPath/);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
|
|
5
|
+
const { WeWorkPcAdapter, NAME, VERSION } = require("../../lib/adapters/wework-pc");
|
|
6
|
+
const { partitionBatch } = require("../../lib/batch");
|
|
7
|
+
|
|
8
|
+
// fake driver answering sqlite_master + table_info + SELECT * by table
|
|
9
|
+
function makeFakeDb(spec) {
|
|
10
|
+
class FakeStmt {
|
|
11
|
+
constructor(sql) {
|
|
12
|
+
this.sql = sql;
|
|
13
|
+
}
|
|
14
|
+
all() {
|
|
15
|
+
const s = this.sql;
|
|
16
|
+
if (/type='table'/.test(s)) return (spec.tables || []).map((n) => ({ name: n }));
|
|
17
|
+
const ti = s.match(/table_info\("(\w+)"\)/);
|
|
18
|
+
if (ti) return spec.cols[ti[1]] || [];
|
|
19
|
+
const fr = s.match(/FROM "(\w+)"/);
|
|
20
|
+
if (fr) return spec.rows[fr[1]] || [];
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
get() {
|
|
24
|
+
return { n: 1 };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return class FakeDb {
|
|
28
|
+
// eslint-disable-next-line no-unused-vars
|
|
29
|
+
constructor(_p, _o) {}
|
|
30
|
+
prepare(sql) {
|
|
31
|
+
return new FakeStmt(sql);
|
|
32
|
+
}
|
|
33
|
+
pragma() {}
|
|
34
|
+
exec() {}
|
|
35
|
+
close() {}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// WeChat Work-ish message table: matches pattern + has time/sender/peer/content.
|
|
40
|
+
const SPEC = {
|
|
41
|
+
tables: ["chat_message", "session_meta", "sqlite_sequence"],
|
|
42
|
+
cols: {
|
|
43
|
+
chat_message: [
|
|
44
|
+
{ name: "localId" },
|
|
45
|
+
{ name: "createTime" },
|
|
46
|
+
{ name: "sender" },
|
|
47
|
+
{ name: "conversationId" },
|
|
48
|
+
{ name: "content" },
|
|
49
|
+
],
|
|
50
|
+
session_meta: [{ name: "vid" }, { name: "name" }],
|
|
51
|
+
},
|
|
52
|
+
rows: {
|
|
53
|
+
chat_message: [
|
|
54
|
+
{ localId: "m1", createTime: 1700000000, sender: "u1", conversationId: "c1", content: "项目周会 10 点" },
|
|
55
|
+
{ localId: "m2", createTime: 1700000010, sender: "u2", conversationId: "c1", content: "收到" },
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function adapter(spec, { exists = true } = {}) {
|
|
61
|
+
const a = new WeWorkPcAdapter({ dbPath: "/fake.db" });
|
|
62
|
+
a._deps.fs = { existsSync: () => exists, accessSync: () => {}, constants: { R_OK: 4 } };
|
|
63
|
+
a._deps.dbDriverFactory = () => makeFakeDb(spec);
|
|
64
|
+
return a;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function collect(iter) {
|
|
68
|
+
const out = [];
|
|
69
|
+
for await (const r of iter) out.push(r);
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
describe("WeWorkPcAdapter (企业微信 honest best-effort)", () => {
|
|
74
|
+
it("exposes name/version", () => {
|
|
75
|
+
expect(NAME).toBe("wework-pc");
|
|
76
|
+
expect(VERSION).toBe("0.1.0");
|
|
77
|
+
expect(new WeWorkPcAdapter().name).toBe("wework-pc");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("no-arg construct + device-pull + legalGate + APP_NOT_INSTALLED readiness", async () => {
|
|
81
|
+
const a = new WeWorkPcAdapter();
|
|
82
|
+
a._deps.discoveryDeps = {
|
|
83
|
+
fs: { existsSync: () => false, readdirSync: () => [], statSync: () => ({ size: 0 }), constants: { R_OK: 4 } },
|
|
84
|
+
home: "/no-home",
|
|
85
|
+
env: {},
|
|
86
|
+
};
|
|
87
|
+
expect(a.extractMode).toBe("device-pull");
|
|
88
|
+
expect(a.dataDisclosure.legalGate).toBe(true);
|
|
89
|
+
const r = await a.authenticate({ readinessOnly: true });
|
|
90
|
+
expect(r.reason).toBe("APP_NOT_INSTALLED");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("reads messages → valid events, platform=wework, raw preserved", async () => {
|
|
94
|
+
const a = adapter(SPEC);
|
|
95
|
+
const raws = await collect(a.sync({ dbPath: "/fake.db" }));
|
|
96
|
+
expect(raws).toHaveLength(2);
|
|
97
|
+
const merged = { events: [], persons: [], places: [], items: [], topics: [] };
|
|
98
|
+
for (const r of raws) {
|
|
99
|
+
const n = a.normalize(r);
|
|
100
|
+
for (const k of Object.keys(merged)) merged[k].push(...n[k]);
|
|
101
|
+
}
|
|
102
|
+
const { valid, invalidReasons } = partitionBatch(merged);
|
|
103
|
+
expect(invalidReasons).toHaveLength(0);
|
|
104
|
+
expect(valid.events).toHaveLength(2);
|
|
105
|
+
expect(valid.events[0].extra.platform).toBe("wework");
|
|
106
|
+
expect(valid.events[0].extra.textResolved).toBe(true);
|
|
107
|
+
expect(valid.events[0].extra.rawRow).toBeTruthy();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("emits local-im-read progress diagnostic", async () => {
|
|
111
|
+
const a = adapter(SPEC);
|
|
112
|
+
const ev = [];
|
|
113
|
+
await collect(a.sync({ dbPath: "/fake.db", onProgress: (e) => ev.push(e) }));
|
|
114
|
+
const d = ev.find((e) => e.phase === "local-im-read");
|
|
115
|
+
expect(d.messageTables).toContain("chat_message");
|
|
116
|
+
expect(d.messageCount).toBe(2);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("missing db yields nothing; unknown kind throws", async () => {
|
|
120
|
+
const a = adapter(SPEC, { exists: false });
|
|
121
|
+
expect(await collect(a.sync({ dbPath: "/no.db" }))).toHaveLength(0);
|
|
122
|
+
expect(() => new WeWorkPcAdapter().normalize({ kind: "x", payload: { kind: "x" } })).toThrow(/unknown kind/);
|
|
123
|
+
});
|
|
124
|
+
});
|
package/lib/adapter-guide.js
CHANGED
|
@@ -35,6 +35,8 @@ const DISPLAY_NAMES = Object.freeze({
|
|
|
35
35
|
"social-zhihu": "知乎",
|
|
36
36
|
"recruit-boss": "BOSS 直聘",
|
|
37
37
|
"social-csdn": "CSDN",
|
|
38
|
+
"social-dongchedi": "懂车帝",
|
|
39
|
+
"biz-tianyancha": "天眼查",
|
|
38
40
|
"social-douyin": "抖音",
|
|
39
41
|
"social-xiaohongshu": "小红书",
|
|
40
42
|
"social-toutiao": "今日头条",
|
|
@@ -47,6 +49,7 @@ const DISPLAY_NAMES = Object.freeze({
|
|
|
47
49
|
"qq-pc": "QQ(电脑版 NT)",
|
|
48
50
|
"dingtalk-pc": "钉钉(电脑版)",
|
|
49
51
|
"feishu-pc": "飞书(电脑版)",
|
|
52
|
+
"wework-pc": "企业微信(电脑版)",
|
|
50
53
|
"email-imap": "邮箱(IMAP)",
|
|
51
54
|
"finance-alipay": "支付宝",
|
|
52
55
|
"alipay-bill": "支付宝账单",
|
|
@@ -72,10 +75,15 @@ const DISPLAY_NAMES = Object.freeze({
|
|
|
72
75
|
"music-kugou": "酷狗音乐",
|
|
73
76
|
"video-iqiyi": "爱奇艺",
|
|
74
77
|
"video-tencent": "腾讯视频",
|
|
78
|
+
"video-xigua": "西瓜视频",
|
|
75
79
|
"weread": "微信读书",
|
|
76
80
|
"doc-wps": "WPS 云文档",
|
|
77
81
|
"doc-tencent-docs": "腾讯文档",
|
|
78
82
|
"doc-baidu-netdisk": "百度网盘",
|
|
83
|
+
"doc-camscanner": "扫描全能王",
|
|
84
|
+
"gov-ixiamen": "i厦门",
|
|
85
|
+
"health-meiyou": "美柚",
|
|
86
|
+
"gov-tax": "个人所得税",
|
|
79
87
|
"browser-history-chrome": "Chrome 浏览历史",
|
|
80
88
|
"browser-history-edge": "Edge 浏览历史",
|
|
81
89
|
"vscode": "VS Code",
|
|
@@ -88,7 +96,8 @@ const DISPLAY_NAMES = Object.freeze({
|
|
|
88
96
|
|
|
89
97
|
// Shared guide for honest best-effort desktop IM local-DB sources (钉钉/飞书).
|
|
90
98
|
function localImPcGuide(platform) {
|
|
91
|
-
const adapterName =
|
|
99
|
+
const adapterName =
|
|
100
|
+
platform === "钉钉" ? "dingtalk-pc" : platform === "企业微信" ? "wework-pc" : "feishu-pc";
|
|
92
101
|
return {
|
|
93
102
|
summary: `采集${platform}电脑版的聊天记录(来自本地数据库)。⚠️ v0.1 实验性:${platform}桌面库为私有结构、可能加密、随版本变化,文本解析为尽力而为,原始行会完整保留以便后续解析。`,
|
|
94
103
|
methods: [
|
|
@@ -406,6 +415,7 @@ const ADAPTER_OVERRIDES = Object.freeze({
|
|
|
406
415
|
|
|
407
416
|
"dingtalk-pc": localImPcGuide("钉钉"),
|
|
408
417
|
"feishu-pc": localImPcGuide("飞书"),
|
|
418
|
+
"wework-pc": localImPcGuide("企业微信"),
|
|
409
419
|
|
|
410
420
|
"social-bilibili": socialAdbGuide("哔哩哔哩", "观看历史 / 收藏 / 动态 / 关注"),
|
|
411
421
|
"social-weibo": socialAdbGuide("微博", "微博 / 收藏 / 关注"),
|
|
@@ -545,9 +555,9 @@ function getAdapterGuide(name, category) {
|
|
|
545
555
|
// usable standalone, e.g. CLI without a live readiness probe).
|
|
546
556
|
function _inferCategory(name) {
|
|
547
557
|
if (ADAPTER_OVERRIDES[name] && name === "wechat") return READINESS_CATEGORY.DEVICE;
|
|
548
|
-
if (/^(email-imap|finance-alipay|alipay-bill|ai-chat-history|weread|doc-wps|doc-tencent-docs|doc-baidu-netdisk|recruit-boss|social-csdn)$/.test(name))
|
|
558
|
+
if (/^(email-imap|finance-alipay|alipay-bill|ai-chat-history|weread|doc-wps|doc-tencent-docs|doc-baidu-netdisk|doc-camscanner|recruit-boss|social-csdn|social-dongchedi|biz-tianyancha|gov-ixiamen|health-meiyou|gov-tax)$/.test(name))
|
|
549
559
|
return READINESS_CATEGORY.CREDENTIAL;
|
|
550
|
-
if (/^(messaging-(telegram|whatsapp)|wechat|wechat-pc|messaging-qq|qq-pc|dingtalk-pc|feishu-pc|travel-amap)$/.test(name))
|
|
560
|
+
if (/^(messaging-(telegram|whatsapp)|wechat|wechat-pc|messaging-qq|qq-pc|dingtalk-pc|feishu-pc|wework-pc|travel-amap)$/.test(name))
|
|
551
561
|
return READINESS_CATEGORY.DEVICE;
|
|
552
562
|
if (
|
|
553
563
|
/^(browser-history-|vscode|win-recent|git-activity|shell-history|local-files|apple-health)/.test(
|