dsh-jobs 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/jobs-engine.cjs +202 -34
  2. package/package.json +1 -1
@@ -918,10 +918,6 @@ async function rawCaptureJsonDetailed(cdpUrl, roleKey, targetUrl, responsePatter
918
918
  });
919
919
  });
920
920
  }
921
- async function rawCaptureJson(cdpUrl, roleKey, targetUrl, responsePattern, timeoutMs, signal, validate) {
922
- const outcome = await rawCaptureJsonDetailed(cdpUrl, roleKey, targetUrl, responsePattern, timeoutMs, signal, validate);
923
- return outcome.data;
924
- }
925
921
  async function rawCaptureDocument(cdpUrl, roleKey, targetUrl, timeoutMs, signal) {
926
922
  if (signal?.aborted) return null;
927
923
  const entry = await rawEnsurePage(cdpUrl, roleKey, targetUrl);
@@ -1415,17 +1411,18 @@ function harvestJobs(root3, platform, base) {
1415
1411
  const plan = FIELD_PLANS[platform];
1416
1412
  const jobs = [];
1417
1413
  const seen = /* @__PURE__ */ new Set();
1418
- const visit = (value, depth) => {
1414
+ const visit = (value, depth, inheritedCompany = "") => {
1419
1415
  if (depth > 8 || !value) return;
1420
1416
  if (Array.isArray(value)) {
1421
- for (const entry of value) visit(entry, depth + 1);
1417
+ for (const entry of value) visit(entry, depth + 1, inheritedCompany);
1422
1418
  return;
1423
1419
  }
1424
1420
  if (typeof value !== "object") return;
1425
1421
  const item = value;
1422
+ const ownCompany = pickCompany(item, plan.company) || inheritedCompany;
1426
1423
  const title = pickText(item, plan.title);
1427
1424
  if (!title) {
1428
- for (const child of Object.values(item)) visit(child, depth + 1);
1425
+ for (const child of Object.values(item)) visit(child, depth + 1, ownCompany);
1429
1426
  return;
1430
1427
  }
1431
1428
  let link = pickText(item, plan.link);
@@ -1443,7 +1440,7 @@ function harvestJobs(root3, platform, base) {
1443
1440
  jobs.push({
1444
1441
  title,
1445
1442
  jobDetail: link,
1446
- company: pickCompany(item, plan.company) || void 0,
1443
+ company: ownCompany || void 0,
1447
1444
  salary: pickText(item, plan.salary) || void 0,
1448
1445
  address: pickText(item, plan.address) || void 0,
1449
1446
  ...item
@@ -15092,6 +15089,23 @@ function inspectRenderedDom(html3, platform, finalUrl) {
15092
15089
  addJob({ title: a.text(), href: a.attr("href") });
15093
15090
  });
15094
15091
  }
15092
+ } else if (platform === "51job") {
15093
+ $2('.joblist-item, [class*="joblist-item"], [class*="job-card"]').each((_, el) => {
15094
+ const card = $2(el);
15095
+ const link = card.find('a[href*="jobs.51job.com/"], a[href*="we.51job.com/"]').first();
15096
+ const href = link.attr("href");
15097
+ const title = card.find('.jname, [class*="job-name"], [class*="jname"]').first().text() || link.text();
15098
+ const salary = card.find('.sal, [class*="salary"]').first().text();
15099
+ const company = card.find('.cname, [class*="comp-name"], [class*="company"]').first().text();
15100
+ const address = card.find('.area, [class*="area"]').first().text();
15101
+ addJob({ title, href, salary, company, address });
15102
+ });
15103
+ if (!seen.size) {
15104
+ $2('a[href*="jobs.51job.com/"]').each((_, el) => {
15105
+ const a = $2(el);
15106
+ addJob({ title: a.text(), href: a.attr("href") });
15107
+ });
15108
+ }
15095
15109
  }
15096
15110
  const jobs = [...seen.values()];
15097
15111
  const accessRestricted = jobs.length === 0 && VERIFY_TEXT_PATTERN.test(`${pageTitle} ${bodyText}`);
@@ -15356,6 +15370,50 @@ async function snapshotProfile() {
15356
15370
  // src/platforms/zhaopin.ts
15357
15371
  var INITIAL_STATE_MARKER = "__INITIAL_STATE__=";
15358
15372
  var ZHAOPIN_API_PATTERN = /(?:cgate[^/]*\/[^?#]*getKeyWordCompanySearch|fe-api[^/]*\/[^?#]*\/search\/(?:base\/data|positions|position)|sou\.zhaopin\.com\/api\/)/i;
15373
+ var ZHAOPIN_CITY_CODES = {
15374
+ "\u5168\u56FD": "489",
15375
+ "\u5317\u4EAC": "530",
15376
+ "\u5929\u6D25": "531",
15377
+ "\u4E0A\u6D77": "538",
15378
+ "\u91CD\u5E86": "551",
15379
+ "\u77F3\u5BB6\u5E84": "565",
15380
+ "\u592A\u539F": "576",
15381
+ "\u6C88\u9633": "599",
15382
+ "\u5927\u8FDE": "600",
15383
+ "\u957F\u6625": "613",
15384
+ "\u54C8\u5C14\u6EE8": "622",
15385
+ "\u5357\u4EAC": "635",
15386
+ "\u65E0\u9521": "636",
15387
+ "\u82CF\u5DDE": "639",
15388
+ "\u676D\u5DDE": "653",
15389
+ "\u5B81\u6CE2": "654",
15390
+ "\u5408\u80A5": "664",
15391
+ "\u798F\u5DDE": "681",
15392
+ "\u53A6\u95E8": "682",
15393
+ "\u5357\u660C": "691",
15394
+ "\u6D4E\u5357": "702",
15395
+ "\u9752\u5C9B": "703",
15396
+ "\u90D1\u5DDE": "719",
15397
+ "\u6B66\u6C49": "736",
15398
+ "\u957F\u6C99": "749",
15399
+ "\u5E7F\u5DDE": "763",
15400
+ "\u6DF1\u5733": "765",
15401
+ "\u73E0\u6D77": "766",
15402
+ "\u4F5B\u5C71": "768",
15403
+ "\u4E1C\u839E": "779",
15404
+ "\u5357\u5B81": "785",
15405
+ "\u6D77\u53E3": "799",
15406
+ "\u6210\u90FD": "801",
15407
+ "\u8D35\u9633": "822",
15408
+ "\u6606\u660E": "831",
15409
+ "\u897F\u5B89": "854",
15410
+ "\u5170\u5DDE": "864"
15411
+ };
15412
+ function resolveZhaopinCityCode(city) {
15413
+ if (!city) return void 0;
15414
+ const clean = city.trim().replace(/市$/, "");
15415
+ return ZHAOPIN_CITY_CODES[clean];
15416
+ }
15359
15417
  function extractZhaopinState(html3) {
15360
15418
  const start = html3.indexOf(INITIAL_STATE_MARKER);
15361
15419
  if (start < 0) return null;
@@ -15373,7 +15431,9 @@ async function searchZhaopin(keyword, city, page, signal, timeoutMs = 22e3, filt
15373
15431
  return { status: "login_required", jobs: [], note: "\u672A\u53D1\u73B0\u7528\u6237\u6D4F\u89C8\u5668\u8C03\u8BD5\u7AEF\u53E3\u3002\u8C03\u7528\u767B\u5F55\u6D41\u7A0B\u81EA\u52A8\u62C9\u8D77\u771F\u5B9E\u6D4F\u89C8\u5668\u5E76\u76D1\u542C\u667A\u8054\u767B\u5F55\u72B6\u6001" };
15374
15432
  }
15375
15433
  const query = new URLSearchParams({ kw: keyword });
15376
- if (city) query.set("jl", city.replace(/市$/, ""));
15434
+ const cityCode = resolveZhaopinCityCode(city);
15435
+ if (cityCode) query.set("jl", cityCode);
15436
+ else if (city) query.set("jl", city.replace(/市$/, ""));
15377
15437
  if (page > 1) query.set("p", String(page));
15378
15438
  const targetUrl = `https://www.zhaopin.com/jobs?${query.toString()}`;
15379
15439
  const outcome = await rawCaptureJsonDetailed(
@@ -16157,7 +16217,40 @@ function solveAcwScV3(arg1) {
16157
16217
  }
16158
16218
  return output;
16159
16219
  }
16160
- function signedQuery(keyword, page) {
16220
+ var JOB51_CITY_CODES = {
16221
+ "\u5168\u56FD": "000000",
16222
+ "\u5317\u4EAC": "010000",
16223
+ "\u4E0A\u6D77": "020000",
16224
+ "\u5E7F\u5DDE": "030200",
16225
+ "\u6DF1\u5733": "040000",
16226
+ "\u5929\u6D25": "050000",
16227
+ "\u91CD\u5E86": "060000",
16228
+ "\u5357\u4EAC": "070200",
16229
+ "\u82CF\u5DDE": "070300",
16230
+ "\u65E0\u9521": "070400",
16231
+ "\u676D\u5DDE": "080200",
16232
+ "\u5B81\u6CE2": "080300",
16233
+ "\u6210\u90FD": "090200",
16234
+ "\u798F\u5DDE": "110200",
16235
+ "\u53A6\u95E8": "110300",
16236
+ "\u6D4E\u5357": "120200",
16237
+ "\u9752\u5C9B": "120300",
16238
+ "\u5408\u80A5": "150200",
16239
+ "\u90D1\u5DDE": "170200",
16240
+ "\u6B66\u6C49": "180200",
16241
+ "\u957F\u6C99": "190200",
16242
+ "\u897F\u5B89": "200200",
16243
+ "\u6C88\u9633": "230200",
16244
+ "\u5927\u8FDE": "230300",
16245
+ "\u4E1C\u839E": "030800",
16246
+ "\u4F5B\u5C71": "030600"
16247
+ };
16248
+ function resolve51jobCityCode(city) {
16249
+ if (!city) return "000000";
16250
+ const clean = city.trim().replace(/市$/, "");
16251
+ return JOB51_CITY_CODES[clean] ?? "000000";
16252
+ }
16253
+ function signedQuery(keyword, page, jobArea = "000000") {
16161
16254
  const timestamp2 = Math.floor(Date.now() / 1e3);
16162
16255
  const requestId = nodeCrypto.randomBytes(16).toString("hex");
16163
16256
  const query = new URLSearchParams({
@@ -16165,7 +16258,7 @@ function signedQuery(keyword, page) {
16165
16258
  timestamp: String(timestamp2),
16166
16259
  keyword,
16167
16260
  searchType: "2",
16168
- jobArea: "000000",
16261
+ jobArea,
16169
16262
  pageNum: String(page),
16170
16263
  pageSize: "20",
16171
16264
  requestId,
@@ -16177,15 +16270,15 @@ function signedQuery(keyword, page) {
16177
16270
  const sign = nodeCrypto.createHmac("sha256", JOB51_SIGN_KEY).update(pathWithQuery).digest("hex");
16178
16271
  return { pathWithQuery, sign };
16179
16272
  }
16180
- async function search51job(keyword, city, page, signal, timeoutMs = 15e3, filters2) {
16181
- void city;
16273
+ async function search51job(keyword, city, page, signal, timeoutMs = 2e4, filters2) {
16182
16274
  void filters2;
16183
- const { pathWithQuery, sign } = signedQuery(keyword, page);
16275
+ const jobArea = resolve51jobCityCode(city);
16276
+ const { pathWithQuery, sign } = signedQuery(keyword, page, jobArea);
16184
16277
  const apiPath = `https://we.51job.com${pathWithQuery}`;
16185
16278
  const headers = {
16186
16279
  sign,
16187
16280
  "user-agent": CHROME_UA,
16188
- referer: `https://we.51job.com/pc/search?keyword=${encodeURIComponent(keyword)}&searchType=2`,
16281
+ referer: `https://we.51job.com/pc/search?jobArea=${jobArea}&keyword=${encodeURIComponent(keyword)}&searchType=2`,
16189
16282
  accept: "application/json, text/plain, */*"
16190
16283
  };
16191
16284
  const first2 = await first51jobHop(apiPath, headers, signal);
@@ -16194,28 +16287,58 @@ async function search51job(keyword, city, page, signal, timeoutMs = 15e3, filter
16194
16287
  const cookie = `${first2.cookieName}=${first2.cookieValue}`;
16195
16288
  const retry = await fetch(apiPath, { headers: { ...headers, cookie }, signal: signal ?? void 0 }).catch(() => null);
16196
16289
  if (retry) {
16197
- const json2 = await retry.json().catch(() => null);
16198
- if (json2 && typeof json2 === "object") return finish51job(json2);
16290
+ const json = await retry.json().catch(() => null);
16291
+ if (json && typeof json === "object") return finish51job(json);
16199
16292
  }
16200
16293
  }
16201
16294
  const cdpUrl = await resolveCdpUrl();
16202
16295
  if (!cdpUrl) {
16203
16296
  return { status: "access_restricted", jobs: [] };
16204
16297
  }
16205
- const pageUrl = `https://we.51job.com/pc/search?keyword=${encodeURIComponent(keyword)}`;
16206
- const json = await rawCaptureJson(
16298
+ const pageUrl = `https://we.51job.com/pc/search?jobArea=${jobArea}&keyword=${encodeURIComponent(keyword)}&searchType=2`;
16299
+ const outcome = await rawCaptureJsonDetailed(
16207
16300
  cdpUrl,
16208
16301
  "51job-search",
16209
16302
  pageUrl,
16210
16303
  /\/api\/job\/search-pc\?/,
16211
- Math.max(timeoutMs - 2e3, 1e4),
16304
+ Math.max(timeoutMs, 18e3),
16212
16305
  signal,
16213
- // 忽略挑战/错误响应:等带职位数据的成功包
16214
- (json2) => Array.isArray(json2?.data) || JSON.stringify(json2).includes('"jobName"')
16306
+ (json) => Array.isArray(json?.data) || JSON.stringify(json).includes('"jobName"')
16215
16307
  );
16216
16308
  if (signal?.aborted) return null;
16217
- if (!json) return { status: "access_restricted", jobs: [] };
16218
- return finish51job(json);
16309
+ let diagnostics = {
16310
+ waitMs: outcome.waitMs,
16311
+ matchedRequestCount: outcome.matchedRequestCount,
16312
+ bodyLength: outcome.bodyLength,
16313
+ finalUrl: outcome.finalUrl,
16314
+ reason: outcome.reason
16315
+ };
16316
+ if (outcome.data) {
16317
+ const res = finish51job(outcome.data);
16318
+ return { ...res, coverage: "search_api", diagnostics };
16319
+ }
16320
+ const snapshot = await rawCaptureDomSnapshot(cdpUrl, "51job-search", pageUrl);
16321
+ if (snapshot) {
16322
+ const inspected = inspectRenderedDom(snapshot.html, "51job", snapshot.url);
16323
+ diagnostics = {
16324
+ ...diagnostics,
16325
+ finalUrl: snapshot.url,
16326
+ pageTitle: inspected.pageTitle || snapshot.title,
16327
+ bodyLength: Math.max(diagnostics.bodyLength ?? 0, inspected.bodyLength),
16328
+ fallbackUsed: true
16329
+ };
16330
+ if (inspected.jobs.length) {
16331
+ return { status: "ok", coverage: "rendered_dom", jobs: inspected.jobs, diagnostics: { ...diagnostics, reason: "rendered_dom_fallback" } };
16332
+ }
16333
+ if (inspected.accessRestricted) return { status: "access_restricted", jobs: [], diagnostics };
16334
+ if (inspected.loginWall) return { status: "login_required", jobs: [], diagnostics };
16335
+ }
16336
+ return {
16337
+ status: outcome.matchedRequestCount > 0 ? "parse_empty" : "capture_timeout",
16338
+ jobs: [],
16339
+ diagnostics,
16340
+ note: `51job \u5DF2\u8FDE\u63A5\u6D4F\u89C8\u5668\u4F46\u672A\u6355\u83B7\u5230\u804C\u4F4D\u6570\u636E\uFF08waitMs=${diagnostics.waitMs ?? 0}\uFF0Cmatched=${diagnostics.matchedRequestCount ?? 0}\uFF09\uFF0C\u5E76\u975E\u767B\u5F55\u5931\u6548`
16341
+ };
16219
16342
  }
16220
16343
  function finish51job(json) {
16221
16344
  const envelope = json;
@@ -16242,13 +16365,45 @@ async function first51jobHop(url, headers, signal) {
16242
16365
 
16243
16366
  // src/platforms/liepin.ts
16244
16367
  var LIEPIN_SEARCH_API_PATTERN = /(?:api-c\.liepin\.com\/api\/com\.liepin\.searchfront4c\.pc-search-job|pc-search-job)(?!-cond-init)(?:\?|$|\/)/i;
16245
- async function searchLiepin(keyword, page, signal, timeoutMs = 22e3, filters2) {
16368
+ var LIEPIN_CITY_CODES = {
16369
+ "\u5317\u4EAC": "010",
16370
+ "\u4E0A\u6D77": "020",
16371
+ "\u5929\u6D25": "030",
16372
+ "\u91CD\u5E86": "040",
16373
+ "\u5E7F\u5DDE": "050020",
16374
+ "\u6DF1\u5733": "050090",
16375
+ "\u4E1C\u839E": "050040",
16376
+ "\u4F5B\u5C71": "050050",
16377
+ "\u5357\u4EAC": "060020",
16378
+ "\u82CF\u5DDE": "060080",
16379
+ "\u65E0\u9521": "060100",
16380
+ "\u676D\u5DDE": "070020",
16381
+ "\u5B81\u6CE2": "070030",
16382
+ "\u5408\u80A5": "080020",
16383
+ "\u798F\u5DDE": "090020",
16384
+ "\u53A6\u95E8": "090040",
16385
+ "\u6D4E\u5357": "250020",
16386
+ "\u9752\u5C9B": "250070",
16387
+ "\u90D1\u5DDE": "150020",
16388
+ "\u6B66\u6C49": "170020",
16389
+ "\u957F\u6C99": "180020",
16390
+ "\u6210\u90FD": "280020",
16391
+ "\u897F\u5B89": "270020",
16392
+ "\u6C88\u9633": "210020",
16393
+ "\u5927\u8FDE": "210040"
16394
+ };
16395
+ async function searchLiepin(keyword, page, signal, timeoutMs = 22e3, filters2, city) {
16246
16396
  const cdpUrl = await resolveCdpUrl();
16247
16397
  if (!cdpUrl) {
16248
16398
  return { status: "login_required", jobs: [], note: "\u672A\u53D1\u73B0\u7528\u6237\u6D4F\u89C8\u5668\u8C03\u8BD5\u7AEF\u53E3\u3002\u8C03\u7528\u767B\u5F55\u6D41\u7A0B\u81EA\u52A8\u62C9\u8D77\u771F\u5B9E\u6D4F\u89C8\u5668\u5E76\u76D1\u542C\u730E\u8058\u767B\u5F55\u72B6\u6001" };
16249
16399
  }
16250
16400
  const native = liepinNativeFilters(filters2 ?? {});
16251
16401
  const query = new URLSearchParams({ key: keyword, currentPage: String(page) });
16402
+ const cityCode = city ? LIEPIN_CITY_CODES[city.trim().replace(/市$/, "")] : void 0;
16403
+ if (cityCode) {
16404
+ query.set("city", cityCode);
16405
+ query.set("dq", cityCode);
16406
+ }
16252
16407
  for (const [key, value] of Object.entries(native)) query.set(key, value);
16253
16408
  const target = `https://www.liepin.com/zhaopin/?${query.toString()}`;
16254
16409
  const outcome = await rawCaptureJsonDetailed(
@@ -16315,10 +16470,10 @@ function classifyLiepinError(code) {
16315
16470
  // src/platforms/registry.ts
16316
16471
  var PLATFORM_SEARCH = {
16317
16472
  zhipin: searchZhipin,
16318
- liepin: (keyword, _city, page, signal, timeoutMs, filters2) => searchLiepin(keyword, page, signal, timeoutMs, filters2),
16473
+ liepin: (keyword, city, page, signal, timeoutMs, filters2) => searchLiepin(keyword, page, signal, timeoutMs, filters2, city),
16319
16474
  zhaopin: searchZhaopin,
16320
- // 51job 签名直连为可选通道(默认关:公开页样本更稳定;开启拿全量字段,失败自动落回 S2)
16321
- ...process.env.MCP_JOBS_ENABLE_51JOB_API === "1" ? { "51job": (keyword, _city, page, signal, timeoutMs, filters2) => search51job(keyword, _city, page, signal, timeoutMs, filters2) } : {}
16475
+ // 51job 默认启用(免登录签名直连 + CDP 旁听 + DOM 降级);仅当显式设置 MCP_JOBS_DISABLE_51JOB_API=1 时关闭
16476
+ ...process.env.MCP_JOBS_DISABLE_51JOB_API === "1" ? {} : { "51job": (keyword, city, page, signal, timeoutMs, filters2) => search51job(keyword, city, page, signal, timeoutMs, filters2) }
16322
16477
  };
16323
16478
  var inflight = /* @__PURE__ */ new Map();
16324
16479
  async function platformApiSearch(platform, params, signal, timeoutMs = 15e3) {
@@ -16523,13 +16678,26 @@ function buildBrowserSearchUrl(platform, term, cityName = "") {
16523
16678
  if (code) params.set("city", code);
16524
16679
  return "https://www.zhipin.com/web/geek/jobs?" + params.toString();
16525
16680
  }
16526
- case "liepin":
16527
- return "https://www.liepin.com/zhaopin/?key=" + encodeURIComponent(term);
16528
- case "51job":
16529
- return "https://we.51job.com/pc/search?keyword=" + encodeURIComponent(term);
16681
+ case "liepin": {
16682
+ const params = new URLSearchParams({ key: term });
16683
+ const code = cityName ? LIEPIN_CITY_CODES[cityName] : void 0;
16684
+ if (code) {
16685
+ params.set("city", code);
16686
+ params.set("dq", code);
16687
+ }
16688
+ return "https://www.liepin.com/zhaopin/?" + params.toString();
16689
+ }
16690
+ case "51job": {
16691
+ const params = new URLSearchParams({ keyword: term, searchType: "2" });
16692
+ const area = resolve51jobCityCode(cityName);
16693
+ if (area !== "000000") params.set("jobArea", area);
16694
+ return "https://we.51job.com/pc/search?" + params.toString();
16695
+ }
16530
16696
  case "zhaopin": {
16531
16697
  const params = new URLSearchParams({ kw: term });
16532
- if (cityName) params.set("jl", cityName);
16698
+ const code = resolveZhaopinCityCode(cityName);
16699
+ if (code) params.set("jl", code);
16700
+ else if (cityName) params.set("jl", cityName);
16533
16701
  return "https://www.zhaopin.com/jobs?" + params.toString();
16534
16702
  }
16535
16703
  }
@@ -16716,7 +16884,7 @@ async function searchWorkBuddy(args = {}, parent2, take = 25) {
16716
16884
  }
16717
16885
  };
16718
16886
  }
16719
- if (!lastStatus && source !== "51job") {
16887
+ if (!lastStatus) {
16720
16888
  return {
16721
16889
  jobs: [],
16722
16890
  source: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-jobs",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "All-site job-search, application tracker, and watch-loop workbench for the DeepSeek Harness (dsh) across BOSS Zhipin, Liepin, 51job, and Zhaopin — with native DSH web UI, agent tools, and raw-CDP browser capture.",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",