job-pro 1.0.11 → 1.0.12

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/dist/index.js +70 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -125,6 +125,9 @@ USAGE
125
125
  write ~/.jobpro/profile.json
126
126
  --interactive fills it via prompts.
127
127
  job-pro profile show print the loaded profile
128
+ job-pro find <keyword> search ALL 50 companies in parallel
129
+ [--limit N] [--companies a,b,c]
130
+ [--timeout ms] [--compact]
128
131
  job-pro --version
129
132
  job-pro help
130
133
 
@@ -1082,6 +1085,73 @@ async function main() {
1082
1085
  printStatus(compact);
1083
1086
  return;
1084
1087
  }
1088
+ if (cmd === "find") {
1089
+ const compact = args.includes("--compact");
1090
+ const keyword = args[1];
1091
+ if (!keyword || keyword.startsWith("--")) {
1092
+ die(`usage: job-pro find <keyword> [--limit N] [--companies a,b,c] [--timeout ms] [--compact]`);
1093
+ }
1094
+ const { args: aLimit, value: limitStr } = popFlagValue(args, "--limit");
1095
+ const { args: aCompanies, value: companiesStr } = popFlagValue(aLimit, "--companies");
1096
+ const { args: aTimeout, value: timeoutStr } = popFlagValue(aCompanies, "--timeout");
1097
+ void aTimeout;
1098
+ const limit = limitStr ? Math.max(1, parseInt(limitStr, 10)) : 3;
1099
+ const timeout = timeoutStr ? Math.max(1000, parseInt(timeoutStr, 10)) : 8000;
1100
+ const scope = companiesStr
1101
+ ? companiesStr.split(",").map((s) => s.trim()).filter(Boolean)
1102
+ : Object.keys(ADAPTERS);
1103
+ const unknown = scope.filter((c) => !(c in ADAPTERS));
1104
+ if (unknown.length > 0)
1105
+ die(`unknown company in --companies: ${unknown.join(", ")}`);
1106
+ const startedAt = Date.now();
1107
+ const settled = await Promise.all(scope.map(async (company) => {
1108
+ const adapter = ADAPTERS[company];
1109
+ const t0 = Date.now();
1110
+ let timer = null;
1111
+ try {
1112
+ const timeoutP = new Promise((resolve) => {
1113
+ timer = setTimeout(() => resolve({ timedOut: true }), timeout);
1114
+ });
1115
+ const searchP = adapter
1116
+ .searchPositions({ keyword, pageSize: limit })
1117
+ .then((r) => ({ ok: true, value: r }));
1118
+ const raced = await Promise.race([timeoutP, searchP]);
1119
+ const elapsed = Date.now() - t0;
1120
+ if ("timedOut" in raced) {
1121
+ return { company, ok: false, count: 0, positions: [], message: `timeout after ${timeout}ms`, elapsed_ms: elapsed };
1122
+ }
1123
+ const r = raced.value;
1124
+ if (r?.ok === false) {
1125
+ return { company, ok: false, count: 0, positions: [], message: r.message ?? "search failed", elapsed_ms: elapsed };
1126
+ }
1127
+ const positions = Array.isArray(r?.positions) ? r.positions.slice(0, limit) : [];
1128
+ return { company, ok: true, count: positions.length, positions, elapsed_ms: elapsed };
1129
+ }
1130
+ catch (err) {
1131
+ const elapsed = Date.now() - t0;
1132
+ const message = err instanceof Error ? err.message : String(err);
1133
+ return { company, ok: false, count: 0, positions: [], message, elapsed_ms: elapsed };
1134
+ }
1135
+ finally {
1136
+ if (timer)
1137
+ clearTimeout(timer);
1138
+ }
1139
+ }));
1140
+ const totalMs = Date.now() - startedAt;
1141
+ const withHits = settled.filter((r) => r.count > 0);
1142
+ const total = withHits.reduce((s, r) => s + r.count, 0);
1143
+ emit({
1144
+ ok: true,
1145
+ keyword,
1146
+ total,
1147
+ company_count: withHits.length,
1148
+ scanned_companies: scope.length,
1149
+ elapsed_ms: totalMs,
1150
+ results: withHits,
1151
+ failed: settled.filter((r) => !r.ok).map((r) => ({ company: r.company, message: r.message })),
1152
+ }, compact);
1153
+ return;
1154
+ }
1085
1155
  if (cmd === "profile") {
1086
1156
  const sub = args[1];
1087
1157
  if (sub === "init") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "job-pro",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Query Chinese big-tech campus recruiting from your terminal. 50 companies, all 50 live. 46 via each company's own API; the 4 with no public canonical feed (Hikvision, CICC, Cainiao, WeBank) surfaced via Liepin as a clearly-labeled third-party fallback. No signup, no token, no server.",
5
5
  "homepage": "https://job.ha7ch.com",
6
6
  "repository": "https://github.com/HA7CH/job-pro",