@chainlesschain/personal-data-hub 0.4.29 → 0.4.31
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/lib/forensics/qq-nt-collect.js +190 -0
- package/lib/prompt-builder.js +15 -1
- package/package.json +8 -3
- package/__tests__/adapter-guide.test.js +0 -47
- package/__tests__/adapter-spec.test.js +0 -78
- package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
- package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
- package/__tests__/adapters/ai-chat-history.test.js +0 -396
- package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
- package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
- package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
- package/__tests__/adapters/apple-health.test.js +0 -95
- package/__tests__/adapters/bank-family.test.js +0 -125
- package/__tests__/adapters/biz-tianyancha.test.js +0 -159
- package/__tests__/adapters/browser-history-chrome.test.js +0 -377
- package/__tests__/adapters/browser-history-edge.test.js +0 -159
- package/__tests__/adapters/car-mercedesme.test.js +0 -74
- package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
- package/__tests__/adapters/doc-camscanner.test.js +0 -147
- package/__tests__/adapters/doc-platforms.test.js +0 -177
- package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
- package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
- package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
- package/__tests__/adapters/email-adapter.test.js +0 -742
- package/__tests__/adapters/email-classifier.test.js +0 -347
- package/__tests__/adapters/email-imap-session.test.js +0 -334
- package/__tests__/adapters/email-parser.test.js +0 -244
- package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
- package/__tests__/adapters/email-providers.test.js +0 -84
- package/__tests__/adapters/email-retry-progress.test.js +0 -294
- package/__tests__/adapters/email-templates.test.js +0 -822
- package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
- package/__tests__/adapters/finance-alipay-live.test.js +0 -258
- package/__tests__/adapters/finance-dcep.test.js +0 -74
- package/__tests__/adapters/fitness-joyrun.test.js +0 -82
- package/__tests__/adapters/game-genshin-live.test.js +0 -238
- package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
- package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
- package/__tests__/adapters/git-activity.test.js +0 -222
- package/__tests__/adapters/gov-12123.test.js +0 -103
- package/__tests__/adapters/gov-ixiamen.test.js +0 -150
- package/__tests__/adapters/gov-tax.test.js +0 -135
- package/__tests__/adapters/health-meiyou.test.js +0 -125
- package/__tests__/adapters/local-files.test.js +0 -264
- package/__tests__/adapters/local-im-pc.test.js +0 -154
- package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
- package/__tests__/adapters/music-kugou.test.js +0 -187
- package/__tests__/adapters/music-qq.test.js +0 -112
- package/__tests__/adapters/netease-music-live.test.js +0 -244
- package/__tests__/adapters/netease-music.test.js +0 -74
- package/__tests__/adapters/pc-local-discovery.test.js +0 -141
- package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
- package/__tests__/adapters/reading-family.test.js +0 -108
- package/__tests__/adapters/recruit-boss.test.js +0 -180
- package/__tests__/adapters/shell-history.test.js +0 -180
- package/__tests__/adapters/shopping-base.test.js +0 -179
- package/__tests__/adapters/shopping-dianping.test.js +0 -239
- package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
- package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
- package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
- package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
- package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
- package/__tests__/adapters/social-csdn.test.js +0 -175
- package/__tests__/adapters/social-dongchedi.test.js +0 -165
- package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
- package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
- package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
- package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
- package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
- package/__tests__/adapters/social-douyin-adb-usage-profile.test.js +0 -229
- package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -269
- package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
- package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
- package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
- package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
- package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
- package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
- package/__tests__/adapters/social-toutiao-adb-article.test.js +0 -155
- package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
- package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
- package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
- package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
- package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
- package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
- package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
- package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
- package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
- package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
- package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
- package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
- package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
- package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
- package/__tests__/adapters/social-zhihu.test.js +0 -246
- package/__tests__/adapters/system-data-adapter.test.js +0 -443
- package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
- package/__tests__/adapters/system-data-android.test.js +0 -519
- package/__tests__/adapters/system-data-disclosure.test.js +0 -153
- package/__tests__/adapters/travel-12306.test.js +0 -512
- package/__tests__/adapters/travel-amap.test.js +0 -219
- package/__tests__/adapters/travel-baidu-map.test.js +0 -305
- package/__tests__/adapters/travel-base.test.js +0 -205
- package/__tests__/adapters/travel-ctrip.test.js +0 -377
- package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
- package/__tests__/adapters/travel-didi.test.js +0 -204
- package/__tests__/adapters/travel-tencent-map.test.js +0 -207
- package/__tests__/adapters/travel-tongcheng.test.js +0 -289
- package/__tests__/adapters/video-platforms.test.js +0 -152
- package/__tests__/adapters/video-xigua.test.js +0 -106
- package/__tests__/adapters/vscode.test.js +0 -299
- package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
- package/__tests__/adapters/wechat-env-probe.test.js +0 -162
- package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
- package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
- package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
- package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
- package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
- package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
- package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
- package/__tests__/adapters/weread.test.js +0 -123
- package/__tests__/adapters/wework-pc.test.js +0 -124
- package/__tests__/adapters/win-recent.test.js +0 -192
- package/__tests__/analysis-skills.test.js +0 -754
- package/__tests__/analysis.test.js +0 -1845
- package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
- package/__tests__/batch.test.js +0 -133
- package/__tests__/bridges-cc-kg.test.js +0 -231
- package/__tests__/bridges-cc-llm.test.js +0 -191
- package/__tests__/bridges-cc-rag.test.js +0 -162
- package/__tests__/categories.test.js +0 -92
- package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
- package/__tests__/e2e/full-user-journey.test.js +0 -188
- package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
- package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
- package/__tests__/entity-resolver-stages.test.js +0 -411
- package/__tests__/entity-resolver-vault.test.js +0 -249
- package/__tests__/entity-resolver.test.js +0 -526
- package/__tests__/fitness-keep-snapshot.test.js +0 -224
- package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
- package/__tests__/ids.test.js +0 -45
- package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
- package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
- package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
- package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
- package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
- package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
- package/__tests__/key-providers.test.js +0 -126
- package/__tests__/kg-derive.test.js +0 -219
- package/__tests__/llm-client.test.js +0 -122
- package/__tests__/longtail-adapters.test.js +0 -281
- package/__tests__/messaging-qq-snapshot.test.js +0 -294
- package/__tests__/mobile-extractor-encrypted.test.js +0 -460
- package/__tests__/mobile-extractor.test.js +0 -288
- package/__tests__/mock-adapter.test.js +0 -93
- package/__tests__/prompt-builder.test.js +0 -249
- package/__tests__/query-parser.test.js +0 -365
- package/__tests__/rag-derive.test.js +0 -169
- package/__tests__/registry-readiness.test.js +0 -292
- package/__tests__/registry.test.js +0 -420
- package/__tests__/salvage-ingest.test.js +0 -97
- package/__tests__/schemas.test.js +0 -331
- package/__tests__/shopping-adapters.test.js +0 -392
- package/__tests__/shopping-eleme-snapshot.test.js +0 -454
- package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
- package/__tests__/shopping-snapshot.test.js +0 -438
- package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
- package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
- package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
- package/__tests__/sidecar-supervisor.test.js +0 -128
- package/__tests__/sign-providers.test.js +0 -62
- package/__tests__/social-adapters.test.js +0 -280
- package/__tests__/social-bilibili-snapshot.test.js +0 -278
- package/__tests__/social-douban-snapshot.test.js +0 -351
- package/__tests__/social-douyin-im-direct-read.test.js +0 -377
- package/__tests__/social-douyin-salvage-collector.test.js +0 -98
- package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
- package/__tests__/social-douyin-snapshot.test.js +0 -256
- package/__tests__/social-kuaishou-snapshot.test.js +0 -362
- package/__tests__/social-toutiao-snapshot.test.js +0 -366
- package/__tests__/social-weibo-snapshot.test.js +0 -234
- package/__tests__/social-weibo-sqlite-device.test.js +0 -174
- package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
- package/__tests__/sqlite-leaf-salvage.test.js +0 -97
- package/__tests__/travel-adapters.test.js +0 -483
- package/__tests__/travel-maps-snapshot.test.js +0 -426
- package/__tests__/vault-driver-error.test.js +0 -74
- package/__tests__/vault-search-helpers.test.js +0 -104
- package/__tests__/vault-search.test.js +0 -423
- package/__tests__/vault.test.js +0 -767
- package/__tests__/wechat-adapter.test.js +0 -594
- package/__tests__/whatsapp-adapter.test.js +0 -138
- package/scripts/_make-fixture-all.js +0 -126
- package/scripts/_make-fixture-contacts.js +0 -84
- package/scripts/evaluate-entity-resolver.js +0 -213
- package/scripts/run-native-tests-sandbox.sh +0 -55
- package/scripts/smoke-phase-5-5.js +0 -196
- package/scripts/smoke-phase-5-7.js +0 -181
- package/scripts/smoke-system-data-contacts.js +0 -309
- package/scripts/smoke-system-data.js +0 -312
- package/vitest.config.js +0 -88
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect } from "vitest";
|
|
4
|
-
const fs = require("node:fs");
|
|
5
|
-
const path = require("node:path");
|
|
6
|
-
const os = require("node:os");
|
|
7
|
-
const crypto = require("node:crypto");
|
|
8
|
-
|
|
9
|
-
const fanqie = require("../../lib/adapters/reading-fanqie");
|
|
10
|
-
const qimao = require("../../lib/adapters/reading-qimao");
|
|
11
|
-
|
|
12
|
-
function writeTmp(content) {
|
|
13
|
-
const p = path.join(os.tmpdir(), `cc-read-${crypto.randomUUID()}.json`);
|
|
14
|
-
fs.writeFileSync(p, content, "utf-8");
|
|
15
|
-
return p;
|
|
16
|
-
}
|
|
17
|
-
async function collect(gen) {
|
|
18
|
-
const out = [];
|
|
19
|
-
for await (const x of gen) out.push(x);
|
|
20
|
-
return out;
|
|
21
|
-
}
|
|
22
|
-
const COOKIES = "novel_sid=abc; uid=1";
|
|
23
|
-
|
|
24
|
-
describe("reading wrappers identity + mappers", () => {
|
|
25
|
-
it("names", () => {
|
|
26
|
-
expect(fanqie.NAME).toBe("reading-fanqie");
|
|
27
|
-
expect(qimao.NAME).toBe("reading-qimao");
|
|
28
|
-
expect(new fanqie.FanqieReadingAdapter().name).toBe("reading-fanqie");
|
|
29
|
-
expect(new qimao.QimaoReadingAdapter().name).toBe("reading-qimao");
|
|
30
|
-
});
|
|
31
|
-
it("low sensitivity, no legalGate", () => {
|
|
32
|
-
for (const A of [new fanqie.FanqieReadingAdapter(), new qimao.QimaoReadingAdapter()]) {
|
|
33
|
-
expect(A.dataDisclosure.sensitivity).toBe("low");
|
|
34
|
-
expect(A.dataDisclosure.legalGate).toBe(false);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
it("fanqie mapItem (book_id / book_name / read_progress)", () => {
|
|
38
|
-
const r = fanqie.mapItem({ book_id: "B1", book_name: "诡秘之主", author: "爱潜水的乌贼", category: "玄幻", read_progress: "0.42", last_chapter_title: "第100章", read_time: 1716383000 });
|
|
39
|
-
expect(r).toMatchObject({ bookId: "B1", title: "诡秘之主", author: "爱潜水的乌贼", category: "玄幻", chapter: "第100章" });
|
|
40
|
-
expect(r.progress).toBeCloseTo(0.42, 2);
|
|
41
|
-
expect(r.occurredAt).toBe(1716383000000);
|
|
42
|
-
expect(r.url).toContain("fanqienovel.com/page/B1");
|
|
43
|
-
expect(fanqie.mapItem({ book_name: "x" })).toBe(null);
|
|
44
|
-
});
|
|
45
|
-
it("qimao mapItem (book_id / title / read_proportion)", () => {
|
|
46
|
-
const r = qimao.mapItem({ book_id: "Q1", title: "大奉打更人", author: "卖报小郎君", read_proportion: 0.8 });
|
|
47
|
-
expect(r).toMatchObject({ bookId: "Q1", title: "大奉打更人", author: "卖报小郎君" });
|
|
48
|
-
expect(r.progress).toBeCloseTo(0.8, 2);
|
|
49
|
-
expect(qimao.mapItem({ title: "x" })).toBe(null);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe("FanqieReadingAdapter (snapshot + cookie-api via _reading-base)", () => {
|
|
54
|
-
const SNAP = JSON.stringify({
|
|
55
|
-
schemaVersion: 1,
|
|
56
|
-
snapshottedAt: 1716383000000,
|
|
57
|
-
account: { userId: "u1" },
|
|
58
|
-
events: [
|
|
59
|
-
{ kind: "read", id: "read-B1", bookId: "B1", title: "诡秘之主", author: "乌贼", category: "玄幻", progress: 0.42 },
|
|
60
|
-
{ kind: "favourite", id: "fav-B2", bookId: "B2", title: "全职高手", author: "蝴蝶蓝" },
|
|
61
|
-
],
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("read → MEDIA event + DOCUMENT item; favourite → LIKE event", async () => {
|
|
65
|
-
const p = writeTmp(SNAP);
|
|
66
|
-
try {
|
|
67
|
-
const a = new fanqie.FanqieReadingAdapter();
|
|
68
|
-
expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
|
|
69
|
-
const items = await collect(a.sync({ inputPath: p }));
|
|
70
|
-
expect(items).toHaveLength(2);
|
|
71
|
-
const read = a.normalize(items[0]);
|
|
72
|
-
expect(read.events[0].subtype).toBe("media");
|
|
73
|
-
expect(read.events[0].content.title).toContain("读了: 诡秘之主");
|
|
74
|
-
expect(read.items[0].subtype).toBe("document");
|
|
75
|
-
expect(read.items[0].extra.platform).toBe("fanqie");
|
|
76
|
-
expect(read.events[0].extra.progress).toBeCloseTo(0.42, 2);
|
|
77
|
-
expect(items[0].originalId).toBe("fanqie:read:read-B1");
|
|
78
|
-
const fav = a.normalize(items[1]);
|
|
79
|
-
expect(fav.events[0].subtype).toBe("like");
|
|
80
|
-
expect(fav.events[0].content.title).toContain("收藏: 全职高手");
|
|
81
|
-
} finally {
|
|
82
|
-
fs.unlinkSync(p);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("cookie-api: read + favourite fetch + sign seam", async () => {
|
|
87
|
-
let signed = 0;
|
|
88
|
-
const a = new fanqie.FanqieReadingAdapter({
|
|
89
|
-
account: { cookies: COOKIES, userId: "u1" },
|
|
90
|
-
signProvider: async () => { signed += 1; return "sig"; },
|
|
91
|
-
fetchFn: async ({ url, query }) => {
|
|
92
|
-
if (query.page > 1) return { list: [] };
|
|
93
|
-
if (url.includes("/history")) return { data: { list: [{ book_id: "B9", book_name: "斗破", read_time: 1716383000 }] } };
|
|
94
|
-
return { data: { books: [{ book_id: "B8", book_name: "遮天" }] } };
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
expect(await a.authenticate()).toEqual({ ok: true, account: "u1", mode: "cookie" });
|
|
98
|
-
const items = await collect(a.sync({}));
|
|
99
|
-
expect(items).toHaveLength(2);
|
|
100
|
-
expect(items.map((i) => i.originalId).sort()).toEqual(["fanqie:favourite:B8", "fanqie:read:B9"]);
|
|
101
|
-
expect(signed).toBeGreaterThan(0);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("default fetch / no input throw", async () => {
|
|
105
|
-
await expect(collect(new fanqie.FanqieReadingAdapter({ account: { cookies: COOKIES } }).sync({}))).rejects.toThrow(/no fetchFn/);
|
|
106
|
-
await expect(collect(new fanqie.FanqieReadingAdapter().sync({}))).rejects.toThrow(/needs opts.inputPath/);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect } from "vitest";
|
|
4
|
-
const fs = require("node:fs");
|
|
5
|
-
const path = require("node:path");
|
|
6
|
-
const os = require("node:os");
|
|
7
|
-
const crypto = require("node:crypto");
|
|
8
|
-
|
|
9
|
-
const {
|
|
10
|
-
BossZhipinAdapter,
|
|
11
|
-
extractData,
|
|
12
|
-
chatItemToRecord,
|
|
13
|
-
applicationItemToRecord,
|
|
14
|
-
NAME,
|
|
15
|
-
VERSION,
|
|
16
|
-
SNAPSHOT_SCHEMA_VERSION,
|
|
17
|
-
} = require("../../lib/adapters/recruit-boss");
|
|
18
|
-
|
|
19
|
-
function writeTmp(content) {
|
|
20
|
-
const p = path.join(os.tmpdir(), `cc-boss-${crypto.randomUUID()}.json`);
|
|
21
|
-
fs.writeFileSync(p, content, "utf-8");
|
|
22
|
-
return p;
|
|
23
|
-
}
|
|
24
|
-
async function collect(gen) {
|
|
25
|
-
const out = [];
|
|
26
|
-
for await (const x of gen) out.push(x);
|
|
27
|
-
return out;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const COOKIES = "wt2=abc; __zp_stoken__=xyz";
|
|
31
|
-
|
|
32
|
-
const SNAP = JSON.stringify({
|
|
33
|
-
schemaVersion: 1,
|
|
34
|
-
snapshottedAt: 1716383000000,
|
|
35
|
-
account: { userId: "u1", name: "我" },
|
|
36
|
-
events: [
|
|
37
|
-
{ kind: "chat", id: "chat-J1", jobId: "J1", jobTitle: "前端工程师", company: "字节跳动", hrName: "李 HR", hrId: "HR9", salary: "25-40K", city: "北京", lastChatTime: 1716300000 },
|
|
38
|
-
{ kind: "application", id: "apply-J2", jobId: "J2", jobTitle: "后端工程师", company: "腾讯", status: "已查看", deliverTime: 1716310000 },
|
|
39
|
-
],
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe("constants + item mappers", () => {
|
|
43
|
-
it("name/version/schema", () => {
|
|
44
|
-
expect(NAME).toBe("recruit-boss");
|
|
45
|
-
expect(VERSION).toBe("0.1.0");
|
|
46
|
-
expect(SNAPSHOT_SCHEMA_VERSION).toBe(1);
|
|
47
|
-
});
|
|
48
|
-
it("chatItemToRecord maps BOSS chat fields", () => {
|
|
49
|
-
const r = chatItemToRecord({ jobId: "J1", jobName: "前端", brandName: "字节", bossName: "王HR", bossId: "B1", salaryDesc: "30K", cityName: "深圳", lastChatTime: 1716300000 });
|
|
50
|
-
expect(r).toMatchObject({ id: "J1", jobTitle: "前端", company: "字节", hrName: "王HR", hrId: "B1", salary: "30K", city: "深圳" });
|
|
51
|
-
expect(r.occurredAt).toBe(1716300000000);
|
|
52
|
-
expect(chatItemToRecord({ jobName: "noid" })).toBe(null);
|
|
53
|
-
});
|
|
54
|
-
it("applicationItemToRecord maps delivery fields", () => {
|
|
55
|
-
const r = applicationItemToRecord({ jobId: "J2", jobName: "后端", brandName: "腾讯", statusDesc: "已查看", deliverTime: 1716310000 });
|
|
56
|
-
expect(r).toMatchObject({ id: "J2", jobTitle: "后端", company: "腾讯", status: "已查看" });
|
|
57
|
-
expect(r.occurredAt).toBe(1716310000000);
|
|
58
|
-
});
|
|
59
|
-
it("extractData tolerant (data/list/zpData.list)", () => {
|
|
60
|
-
expect(extractData({ data: [{ jobId: 1 }] })).toHaveLength(1);
|
|
61
|
-
expect(extractData({ zpData: { list: [{ jobId: 1 }] } })).toHaveLength(1);
|
|
62
|
-
expect(extractData({})).toEqual([]);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe("BossZhipinAdapter snapshot mode", () => {
|
|
67
|
-
it("authenticate validates inputPath", async () => {
|
|
68
|
-
const p = writeTmp(SNAP);
|
|
69
|
-
try {
|
|
70
|
-
const a = new BossZhipinAdapter();
|
|
71
|
-
expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
|
|
72
|
-
expect((await a.authenticate({ inputPath: path.join(os.tmpdir(), "no-boss.json") })).reason).toBe("INPUT_PATH_UNREADABLE");
|
|
73
|
-
} finally {
|
|
74
|
-
fs.unlinkSync(p);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("sync yields chat+application; normalize → interaction event + HR person", async () => {
|
|
79
|
-
const p = writeTmp(SNAP);
|
|
80
|
-
try {
|
|
81
|
-
const a = new BossZhipinAdapter();
|
|
82
|
-
const items = await collect(a.sync({ inputPath: p }));
|
|
83
|
-
expect(items.map((x) => x.kind)).toEqual(["chat", "application"]);
|
|
84
|
-
|
|
85
|
-
const chat = a.normalize(items[0]);
|
|
86
|
-
expect(chat.events[0].subtype).toBe("interaction");
|
|
87
|
-
expect(chat.events[0].content.title).toBe("沟通职位: 前端工程师 @ 字节跳动");
|
|
88
|
-
expect(chat.persons[0].subtype).toBe("contact");
|
|
89
|
-
expect(chat.persons[0].names).toEqual(["李 HR"]);
|
|
90
|
-
expect(chat.persons[0].identifiers["boss-hr-id"]).toEqual(["HR9"]);
|
|
91
|
-
expect(chat.events[0].participants).toContain(chat.persons[0].id);
|
|
92
|
-
|
|
93
|
-
const app = a.normalize(items[1]);
|
|
94
|
-
expect(app.events[0].content.title).toBe("投递简历: 后端工程师 @ 腾讯");
|
|
95
|
-
expect(app.events[0].extra.status).toBe("已查看");
|
|
96
|
-
expect(app.persons).toEqual([]);
|
|
97
|
-
} finally {
|
|
98
|
-
fs.unlinkSync(p);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("include filter + limit + schema mismatch + unknown kind", async () => {
|
|
103
|
-
const p = writeTmp(SNAP);
|
|
104
|
-
try {
|
|
105
|
-
const a = new BossZhipinAdapter();
|
|
106
|
-
expect((await collect(a.sync({ inputPath: p, include: { chat: false } }))).map((x) => x.kind)).toEqual(["application"]);
|
|
107
|
-
expect(await collect(a.sync({ inputPath: p, limit: 1 }))).toHaveLength(1);
|
|
108
|
-
expect(() => a.normalize({ kind: "bogus", payload: {} })).toThrow(/unknown kind/);
|
|
109
|
-
} finally {
|
|
110
|
-
fs.unlinkSync(p);
|
|
111
|
-
}
|
|
112
|
-
const bad = writeTmp(JSON.stringify({ schemaVersion: 9, events: [] }));
|
|
113
|
-
try {
|
|
114
|
-
const a = new BossZhipinAdapter();
|
|
115
|
-
await expect(collect(a.sync({ inputPath: bad }))).rejects.toThrow(/schemaVersion mismatch/);
|
|
116
|
-
} finally {
|
|
117
|
-
fs.unlinkSync(bad);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe("BossZhipinAdapter cookie-api mode", () => {
|
|
123
|
-
it("authenticate cookie mode (userId optional)", async () => {
|
|
124
|
-
const a = new BossZhipinAdapter({ account: { cookies: COOKIES } });
|
|
125
|
-
expect(await a.authenticate()).toEqual({ ok: true, account: null, mode: "cookie" });
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it("sync fetches chats + deliveries, normalizes", async () => {
|
|
129
|
-
const byUrl = (url) => (url.includes("contactList") ? "chats" : "deliveries");
|
|
130
|
-
const data = {
|
|
131
|
-
chats: [{ jobId: "C1", jobName: "全栈", brandName: "小米", bossName: "赵HR", bossId: "B2", lastChatTime: 1716300000 }],
|
|
132
|
-
deliveries: [{ jobId: "D1", jobName: "测试", brandName: "美团", statusDesc: "已投递", deliverTime: 1716310000 }],
|
|
133
|
-
};
|
|
134
|
-
const calls = [];
|
|
135
|
-
const fetchFn = async ({ url, cookies, query, sign }) => {
|
|
136
|
-
const k = byUrl(url);
|
|
137
|
-
calls.push({ k, cookies, page: query.page, sign });
|
|
138
|
-
return { zpData: { list: query.page === 1 ? data[k] : [] } };
|
|
139
|
-
};
|
|
140
|
-
const a = new BossZhipinAdapter({ account: { cookies: COOKIES }, fetchFn });
|
|
141
|
-
const items = await collect(a.sync({}));
|
|
142
|
-
expect(items.map((x) => x.kind).sort()).toEqual(["application", "chat"]);
|
|
143
|
-
expect(calls.every((c) => c.cookies === COOKIES && c.sign === null)).toBe(true);
|
|
144
|
-
const chat = a.normalize(items.find((x) => x.kind === "chat"));
|
|
145
|
-
expect(chat.events[0].content.title).toBe("沟通职位: 全栈 @ 小米");
|
|
146
|
-
expect(chat.persons[0].names).toEqual(["赵HR"]);
|
|
147
|
-
const app = a.normalize(items.find((x) => x.kind === "application"));
|
|
148
|
-
expect(app.events[0].content.title).toBe("投递简历: 测试 @ 美团");
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("invokes signProvider when configured", async () => {
|
|
152
|
-
const signCalls = [];
|
|
153
|
-
const a = new BossZhipinAdapter({
|
|
154
|
-
account: { cookies: COOKIES },
|
|
155
|
-
fetchFn: async ({ query }) => ({ zpData: { list: query.page === 1 ? [{ jobId: "C1", jobName: "x" }] : [] } }),
|
|
156
|
-
signProvider: async (ctx) => { signCalls.push(ctx); return "__zp_stoken__sig"; },
|
|
157
|
-
});
|
|
158
|
-
const items = await collect(a.sync({ include: { application: false } }));
|
|
159
|
-
expect(items.length).toBeGreaterThan(0);
|
|
160
|
-
expect(signCalls.length).toBeGreaterThan(0);
|
|
161
|
-
expect(signCalls[0].cookies).toBe(COOKIES);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it("limit + empty/login response + default fetch + no input", async () => {
|
|
165
|
-
const a1 = new BossZhipinAdapter({
|
|
166
|
-
account: { cookies: COOKIES },
|
|
167
|
-
fetchFn: async ({ query }) => ({ data: query.page === 1 ? [{ jobId: "C1", jobName: "a" }, { jobId: "C2", jobName: "b" }] : [] }),
|
|
168
|
-
});
|
|
169
|
-
expect(await collect(a1.sync({ limit: 1 }))).toHaveLength(1);
|
|
170
|
-
|
|
171
|
-
const a2 = new BossZhipinAdapter({ account: { cookies: COOKIES }, fetchFn: async () => "<html>login</html>" });
|
|
172
|
-
expect(await collect(a2.sync({}))).toEqual([]);
|
|
173
|
-
|
|
174
|
-
const a3 = new BossZhipinAdapter({ account: { cookies: COOKIES } });
|
|
175
|
-
await expect(collect(a3.sync({}))).rejects.toThrow(/no fetchFn configured/);
|
|
176
|
-
|
|
177
|
-
const a4 = new BossZhipinAdapter();
|
|
178
|
-
await expect(collect(a4.sync({}))).rejects.toThrow(/needs opts.inputPath/);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
4
|
-
import { mkdtempSync, rmSync, writeFileSync, utimesSync } from "node:fs";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { tmpdir } from "node:os";
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
ShellHistoryAdapter,
|
|
10
|
-
SHELL_HISTORY_NAME,
|
|
11
|
-
SHELL_HISTORY_VERSION,
|
|
12
|
-
} = require("../../lib/adapters/shell-history");
|
|
13
|
-
const { assertAdapter } = require("../../lib/adapter-spec");
|
|
14
|
-
const { EVENT_SUBTYPES } = require("../../lib/constants");
|
|
15
|
-
const { validateEvent } = require("../../lib/schemas");
|
|
16
|
-
|
|
17
|
-
let tmpDir;
|
|
18
|
-
|
|
19
|
-
function makeHistFile(name, lines, mtimeMs) {
|
|
20
|
-
const p = join(tmpDir, name);
|
|
21
|
-
writeFileSync(p, lines.join("\n") + "\n", "utf-8");
|
|
22
|
-
if (mtimeMs) utimesSync(p, mtimeMs / 1000, mtimeMs / 1000);
|
|
23
|
-
return p;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
beforeEach(() => {
|
|
27
|
-
tmpDir = mkdtempSync(join(tmpdir(), "shell-hist-test-"));
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
afterEach(() => {
|
|
31
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe("ShellHistoryAdapter — contract + identity", () => {
|
|
35
|
-
it("conforms to PersonalDataAdapter contract", () => {
|
|
36
|
-
expect(assertAdapter(new ShellHistoryAdapter())).toEqual({ ok: true });
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("identifies as shell-history with sync:shell-history-files capability", () => {
|
|
40
|
-
const a = new ShellHistoryAdapter();
|
|
41
|
-
expect(a.name).toBe(SHELL_HISTORY_NAME);
|
|
42
|
-
expect(a.name).toBe("shell-history");
|
|
43
|
-
expect(a.version).toBe(SHELL_HISTORY_VERSION);
|
|
44
|
-
expect(a.capabilities).toContain("sync:shell-history-files");
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe("ShellHistoryAdapter.sync", () => {
|
|
49
|
-
it("yields one row per non-blank line per configured shell", async () => {
|
|
50
|
-
const pwshFile = makeHistFile("pwsh.txt", ["ls", "git status", "", "npm test"], 1_700_000_010_000);
|
|
51
|
-
const bashFile = makeHistFile("bash.txt", ["cd /tmp", "make"], 1_700_000_020_000);
|
|
52
|
-
const a = new ShellHistoryAdapter({
|
|
53
|
-
sources: [
|
|
54
|
-
{ shell: "pwsh", file: pwshFile },
|
|
55
|
-
{ shell: "bash", file: bashFile },
|
|
56
|
-
],
|
|
57
|
-
});
|
|
58
|
-
const raws = [];
|
|
59
|
-
for await (const r of a.sync()) raws.push(r);
|
|
60
|
-
expect(raws).toHaveLength(5); // 3 pwsh (blank skipped) + 2 bash
|
|
61
|
-
expect(raws[0].payload.shell).toBe("pwsh");
|
|
62
|
-
expect(raws[0].payload.value).toBe("ls");
|
|
63
|
-
expect(raws[0].payload.snapshotTs).toBe(1_700_000_010_000);
|
|
64
|
-
expect(raws[3].payload.shell).toBe("bash");
|
|
65
|
-
expect(raws[3].payload.value).toBe("cd /tmp");
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("strips zsh extended history prefix", async () => {
|
|
69
|
-
const zshFile = makeHistFile(
|
|
70
|
-
"zsh.txt",
|
|
71
|
-
[
|
|
72
|
-
": 1700000001:0;ls -la",
|
|
73
|
-
": 1700000002:5;npm install",
|
|
74
|
-
"plain-line-without-prefix",
|
|
75
|
-
],
|
|
76
|
-
1_700_000_030_000,
|
|
77
|
-
);
|
|
78
|
-
const a = new ShellHistoryAdapter({ sources: [{ shell: "zsh", file: zshFile }] });
|
|
79
|
-
const raws = [];
|
|
80
|
-
for await (const r of a.sync()) raws.push(r);
|
|
81
|
-
expect(raws.map((r) => r.payload.value)).toEqual([
|
|
82
|
-
"ls -la",
|
|
83
|
-
"npm install",
|
|
84
|
-
"plain-line-without-prefix",
|
|
85
|
-
]);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("originalId disambiguates same command at different sourceIndex", async () => {
|
|
89
|
-
const f = makeHistFile("h.txt", ["ls", "ls", "ls"], 1_700_000_001_000);
|
|
90
|
-
const a = new ShellHistoryAdapter({ sources: [{ shell: "bash", file: f }] });
|
|
91
|
-
const raws = [];
|
|
92
|
-
for await (const r of a.sync()) raws.push(r);
|
|
93
|
-
const ids = raws.map((r) => r.originalId);
|
|
94
|
-
expect(new Set(ids).size).toBe(3);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("respects since filter (file mtime granularity)", async () => {
|
|
98
|
-
const oldF = makeHistFile("old.txt", ["a"], 1_700_000_001_000);
|
|
99
|
-
const newF = makeHistFile("new.txt", ["b"], 1_700_000_005_000);
|
|
100
|
-
const a = new ShellHistoryAdapter({
|
|
101
|
-
sources: [
|
|
102
|
-
{ shell: "pwsh", file: oldF },
|
|
103
|
-
{ shell: "bash", file: newF },
|
|
104
|
-
],
|
|
105
|
-
});
|
|
106
|
-
const raws = [];
|
|
107
|
-
for await (const r of a.sync({ since: 1_700_000_003_000 })) raws.push(r);
|
|
108
|
-
expect(raws.map((r) => r.payload.value)).toEqual(["b"]);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("respects limit", async () => {
|
|
112
|
-
const f = makeHistFile("h.txt", ["1", "2", "3", "4", "5"], 1_700_000_001_000);
|
|
113
|
-
const a = new ShellHistoryAdapter({ sources: [{ shell: "pwsh", file: f }] });
|
|
114
|
-
const raws = [];
|
|
115
|
-
for await (const r of a.sync({ limit: 2 })) raws.push(r);
|
|
116
|
-
expect(raws).toHaveLength(2);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("missing files silently produce nothing", async () => {
|
|
120
|
-
const a = new ShellHistoryAdapter({
|
|
121
|
-
sources: [{ shell: "pwsh", file: join(tmpDir, "nonexistent.txt") }],
|
|
122
|
-
});
|
|
123
|
-
const raws = [];
|
|
124
|
-
for await (const r of a.sync()) raws.push(r);
|
|
125
|
-
expect(raws).toHaveLength(0);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
describe("ShellHistoryAdapter.normalize", () => {
|
|
130
|
-
it("maps shell-command → Event(OTHER) with [shell] title prefix", () => {
|
|
131
|
-
const a = new ShellHistoryAdapter();
|
|
132
|
-
const { events } = a.normalize({
|
|
133
|
-
kind: "shell-command",
|
|
134
|
-
originalId: "shell-cmd:bash:0:abc",
|
|
135
|
-
capturedAt: 1_700_000_005_000,
|
|
136
|
-
payload: {
|
|
137
|
-
shell: "bash",
|
|
138
|
-
file: "/home/u/.bash_history",
|
|
139
|
-
value: "git status",
|
|
140
|
-
sourceIndex: 0,
|
|
141
|
-
snapshotTs: 1_700_000_001_000,
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
expect(events).toHaveLength(1);
|
|
145
|
-
const e = events[0];
|
|
146
|
-
expect(e.subtype).toBe(EVENT_SUBTYPES.OTHER);
|
|
147
|
-
expect(e.actor).toBe("self");
|
|
148
|
-
expect(e.content.title).toBe("[bash] git status");
|
|
149
|
-
expect(e.content.text).toBe("git status");
|
|
150
|
-
expect(e.occurredAt).toBe(1_700_000_001_000);
|
|
151
|
-
expect(e.extra.kind).toBe("shell-command");
|
|
152
|
-
expect(e.extra.shell).toBe("bash");
|
|
153
|
-
expect(validateEvent(e).valid).toBe(true);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("truncates long commands in title (keeps full text)", () => {
|
|
157
|
-
const a = new ShellHistoryAdapter();
|
|
158
|
-
const longCmd = "echo " + "x".repeat(300);
|
|
159
|
-
const { events } = a.normalize({
|
|
160
|
-
kind: "shell-command",
|
|
161
|
-
capturedAt: 1_700_000_000_000,
|
|
162
|
-
originalId: "shell-cmd:pwsh:0:long",
|
|
163
|
-
payload: {
|
|
164
|
-
shell: "pwsh",
|
|
165
|
-
value: longCmd,
|
|
166
|
-
sourceIndex: 0,
|
|
167
|
-
snapshotTs: 1_700_000_000_000,
|
|
168
|
-
},
|
|
169
|
-
});
|
|
170
|
-
expect(events[0].content.title.length).toBeLessThanOrEqual(101);
|
|
171
|
-
expect(events[0].content.title.endsWith("…")).toBe(true);
|
|
172
|
-
expect(events[0].content.text).toBe(longCmd);
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it("throws on unknown raw.kind", () => {
|
|
176
|
-
expect(() => new ShellHistoryAdapter().normalize({ kind: "bogus" })).toThrow(
|
|
177
|
-
/unknown raw\.kind=bogus/,
|
|
178
|
-
);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect } from "vitest";
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
normalizeOrderRecord,
|
|
7
|
-
mapStatusToSubtype,
|
|
8
|
-
CookieAuth,
|
|
9
|
-
} = require("../../lib/adapters/shopping-base");
|
|
10
|
-
|
|
11
|
-
describe("normalizeOrderRecord", () => {
|
|
12
|
-
const ORDER = {
|
|
13
|
-
vendorId: "jd",
|
|
14
|
-
orderId: "JD123456",
|
|
15
|
-
placedAt: 1716383021000,
|
|
16
|
-
paidAt: 1716383100000,
|
|
17
|
-
status: "delivered",
|
|
18
|
-
merchantName: "京东自营旗舰店",
|
|
19
|
-
totalAmount: { value: 299.9, currency: "CNY" },
|
|
20
|
-
items: [
|
|
21
|
-
{ name: "机械键盘", quantity: 1, unitPrice: 249.9, sku: "SKU1" },
|
|
22
|
-
{ name: "键帽", quantity: 2, unitPrice: 25 },
|
|
23
|
-
],
|
|
24
|
-
recipient: "张三",
|
|
25
|
-
shippingAddress: "上海市幸福路1号",
|
|
26
|
-
trackingNumber: "SF123",
|
|
27
|
-
extras: { shopId: "S1" },
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
it("throws on missing rec / orderId / merchantName", () => {
|
|
31
|
-
expect(() => normalizeOrderRecord(null)).toThrow(/rec required/);
|
|
32
|
-
expect(() => normalizeOrderRecord({})).toThrow(/orderId required/);
|
|
33
|
-
expect(() => normalizeOrderRecord({ orderId: "X" })).toThrow(
|
|
34
|
-
/merchantName required/,
|
|
35
|
-
);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("emits order event with amount out + items text + cross-source link extras", () => {
|
|
39
|
-
const batch = normalizeOrderRecord(ORDER, {
|
|
40
|
-
adapterName: "shopping-jd",
|
|
41
|
-
adapterVersion: "0.5.0",
|
|
42
|
-
});
|
|
43
|
-
expect(batch.events).toHaveLength(1);
|
|
44
|
-
const ev = batch.events[0];
|
|
45
|
-
expect(ev.subtype).toBe("order");
|
|
46
|
-
expect(ev.occurredAt).toBe(1716383021000);
|
|
47
|
-
expect(ev.actor).toBe("person-self");
|
|
48
|
-
expect(ev.content.title).toBe("京东自营旗舰店 订单 JD123456");
|
|
49
|
-
expect(ev.content.amount).toEqual({
|
|
50
|
-
value: 299.9,
|
|
51
|
-
currency: "CNY",
|
|
52
|
-
direction: "out",
|
|
53
|
-
});
|
|
54
|
-
expect(ev.content.text).toBe("机械键盘 x1; 键帽 x2");
|
|
55
|
-
expect(ev.extra).toMatchObject({
|
|
56
|
-
vendorId: "jd",
|
|
57
|
-
orderId: "JD123456",
|
|
58
|
-
merchantOrderNumber: "JD123456", // Email/Alipay cross-source link key
|
|
59
|
-
orderStatus: "delivered",
|
|
60
|
-
itemCount: 2,
|
|
61
|
-
recipient: "张三",
|
|
62
|
-
trackingNumber: "SF123",
|
|
63
|
-
paidAt: 1716383100000,
|
|
64
|
-
vendorExtras: { shopId: "S1" },
|
|
65
|
-
});
|
|
66
|
-
expect(ev.source).toMatchObject({
|
|
67
|
-
adapter: "shopping-jd",
|
|
68
|
-
adapterVersion: "0.5.0",
|
|
69
|
-
originalId: "JD123456",
|
|
70
|
-
capturedBy: "api",
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("emits merchant person + per-SKU item entities inheriting order currency", () => {
|
|
75
|
-
const batch = normalizeOrderRecord(ORDER, { adapterName: "shopping-jd" });
|
|
76
|
-
expect(batch.persons).toHaveLength(1);
|
|
77
|
-
expect(batch.persons[0]).toMatchObject({
|
|
78
|
-
subtype: "merchant",
|
|
79
|
-
names: ["京东自营旗舰店"],
|
|
80
|
-
});
|
|
81
|
-
expect(batch.items).toHaveLength(2);
|
|
82
|
-
expect(batch.items[0]).toMatchObject({
|
|
83
|
-
type: "item",
|
|
84
|
-
subtype: "product",
|
|
85
|
-
name: "机械键盘",
|
|
86
|
-
merchant: batch.persons[0].id,
|
|
87
|
-
price: { value: 249.9, currency: "CNY" },
|
|
88
|
-
});
|
|
89
|
-
expect(batch.items[0].extra).toMatchObject({ quantity: 1, sku: "SKU1" });
|
|
90
|
-
// nameless item entries are dropped
|
|
91
|
-
const withJunk = normalizeOrderRecord(
|
|
92
|
-
{ ...ORDER, items: [{ quantity: 3 }, { name: "ok" }] },
|
|
93
|
-
{},
|
|
94
|
-
);
|
|
95
|
-
expect(withJunk.items).toHaveLength(1);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("refund order → refund subtype with money direction IN", () => {
|
|
99
|
-
const batch = normalizeOrderRecord(
|
|
100
|
-
{ ...ORDER, status: "refunded" },
|
|
101
|
-
{ adapterName: "shopping-jd" },
|
|
102
|
-
);
|
|
103
|
-
expect(batch.events[0].subtype).toBe("refund");
|
|
104
|
-
expect(batch.events[0].content.amount.direction).toBe("in");
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("omits amount when totalAmount missing; occurredAt falls back to now", () => {
|
|
108
|
-
const before = Date.now();
|
|
109
|
-
const batch = normalizeOrderRecord({
|
|
110
|
-
orderId: "X1",
|
|
111
|
-
merchantName: "店",
|
|
112
|
-
});
|
|
113
|
-
expect(batch.events[0].content.amount).toBeUndefined();
|
|
114
|
-
expect(batch.events[0].occurredAt).toBeGreaterThanOrEqual(before);
|
|
115
|
-
expect(batch.events[0].extra.orderStatus).toBe("placed");
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe("mapStatusToSubtype", () => {
|
|
120
|
-
it("maps refund variants (en + 中文)", () => {
|
|
121
|
-
expect(mapStatusToSubtype("refunded")).toBe("refund");
|
|
122
|
-
expect(mapStatusToSubtype("REFUND_PENDING")).toBe("refund");
|
|
123
|
-
expect(mapStatusToSubtype("退款中")).toBe("refund");
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("maps cancel variants (en + 中文)", () => {
|
|
127
|
-
expect(mapStatusToSubtype("cancelled")).toBe("cancelled");
|
|
128
|
-
expect(mapStatusToSubtype("closed")).toBe("cancelled");
|
|
129
|
-
expect(mapStatusToSubtype("已取消")).toBe("cancelled");
|
|
130
|
-
expect(mapStatusToSubtype("已关闭")).toBe("cancelled");
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("everything else (placed/shipped/delivered/blank) → order", () => {
|
|
134
|
-
expect(mapStatusToSubtype("placed")).toBe("order");
|
|
135
|
-
expect(mapStatusToSubtype("shipped")).toBe("order");
|
|
136
|
-
expect(mapStatusToSubtype("delivered")).toBe("order");
|
|
137
|
-
expect(mapStatusToSubtype(undefined)).toBe("order");
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe("CookieAuth", () => {
|
|
142
|
-
it("requires platform; setCookies type-checks", () => {
|
|
143
|
-
expect(() => new CookieAuth({})).toThrow(/platform required/);
|
|
144
|
-
const c = new CookieAuth({ platform: "jd" });
|
|
145
|
-
expect(() => c.setCookies(42)).toThrow(/string required/);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it("toHeader returns raw string or null when empty", () => {
|
|
149
|
-
const c = new CookieAuth({ platform: "jd" });
|
|
150
|
-
expect(c.toHeader()).toBe(null);
|
|
151
|
-
c.setCookies("pt_key=abc; pt_pin=u1");
|
|
152
|
-
expect(c.toHeader()).toBe("pt_key=abc; pt_pin=u1");
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("validate: false on empty, true on non-empty, defers to injected validator", async () => {
|
|
156
|
-
const empty = new CookieAuth({ platform: "jd" });
|
|
157
|
-
expect(await empty.validate()).toBe(false);
|
|
158
|
-
const plain = new CookieAuth({ platform: "jd", cookies: "k=v" });
|
|
159
|
-
expect(await plain.validate()).toBe(true);
|
|
160
|
-
const probed = new CookieAuth({
|
|
161
|
-
platform: "jd",
|
|
162
|
-
cookies: "k=v",
|
|
163
|
-
validator: async (raw) => raw.includes("pt_key"),
|
|
164
|
-
});
|
|
165
|
-
expect(await probed.validate()).toBe(false);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("getCookieValue: case-insensitive, URI-decodes, escapes regex metachars", () => {
|
|
169
|
-
const c = new CookieAuth({
|
|
170
|
-
platform: "taobao",
|
|
171
|
-
cookies: "Name=%E5%BC%A0%E4%B8%89; a.b+c=literal; last=v",
|
|
172
|
-
});
|
|
173
|
-
expect(c.getCookieValue("name")).toBe("张三");
|
|
174
|
-
// dot/plus in cookie name must be treated literally, not as regex
|
|
175
|
-
expect(c.getCookieValue("a.b+c")).toBe("literal");
|
|
176
|
-
expect(c.getCookieValue("missing")).toBe(null);
|
|
177
|
-
expect(c.getCookieValue("")).toBe(null);
|
|
178
|
-
});
|
|
179
|
-
});
|