job-pro 1.0.11 → 1.0.13

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 +92 -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 | --text]
128
131
  job-pro --version
129
132
  job-pro help
130
133
 
@@ -1082,6 +1085,95 @@ async function main() {
1082
1085
  printStatus(compact);
1083
1086
  return;
1084
1087
  }
1088
+ if (cmd === "find") {
1089
+ const compact = args.includes("--compact");
1090
+ const textMode = args.includes("--text");
1091
+ const keyword = args[1];
1092
+ if (!keyword || keyword.startsWith("--")) {
1093
+ die(`usage: job-pro find <keyword> [--limit N] [--companies a,b,c] [--timeout ms] [--compact | --text]`);
1094
+ }
1095
+ const { args: aLimit, value: limitStr } = popFlagValue(args, "--limit");
1096
+ const { args: aCompanies, value: companiesStr } = popFlagValue(aLimit, "--companies");
1097
+ const { args: aTimeout, value: timeoutStr } = popFlagValue(aCompanies, "--timeout");
1098
+ void aTimeout;
1099
+ const limit = limitStr ? Math.max(1, parseInt(limitStr, 10)) : 3;
1100
+ const timeout = timeoutStr ? Math.max(1000, parseInt(timeoutStr, 10)) : 8000;
1101
+ const scope = companiesStr
1102
+ ? companiesStr.split(",").map((s) => s.trim()).filter(Boolean)
1103
+ : Object.keys(ADAPTERS);
1104
+ const unknown = scope.filter((c) => !(c in ADAPTERS));
1105
+ if (unknown.length > 0)
1106
+ die(`unknown company in --companies: ${unknown.join(", ")}`);
1107
+ const startedAt = Date.now();
1108
+ const settled = await Promise.all(scope.map(async (company) => {
1109
+ const adapter = ADAPTERS[company];
1110
+ const t0 = Date.now();
1111
+ let timer = null;
1112
+ try {
1113
+ const timeoutP = new Promise((resolve) => {
1114
+ timer = setTimeout(() => resolve({ timedOut: true }), timeout);
1115
+ });
1116
+ const searchP = adapter
1117
+ .searchPositions({ keyword, pageSize: limit })
1118
+ .then((r) => ({ ok: true, value: r }));
1119
+ const raced = await Promise.race([timeoutP, searchP]);
1120
+ const elapsed = Date.now() - t0;
1121
+ if ("timedOut" in raced) {
1122
+ return { company, ok: false, count: 0, positions: [], message: `timeout after ${timeout}ms`, elapsed_ms: elapsed };
1123
+ }
1124
+ const r = raced.value;
1125
+ if (r?.ok === false) {
1126
+ return { company, ok: false, count: 0, positions: [], message: r.message ?? "search failed", elapsed_ms: elapsed };
1127
+ }
1128
+ const positions = Array.isArray(r?.positions) ? r.positions.slice(0, limit) : [];
1129
+ return { company, ok: true, count: positions.length, positions, elapsed_ms: elapsed };
1130
+ }
1131
+ catch (err) {
1132
+ const elapsed = Date.now() - t0;
1133
+ const message = err instanceof Error ? err.message : String(err);
1134
+ return { company, ok: false, count: 0, positions: [], message, elapsed_ms: elapsed };
1135
+ }
1136
+ finally {
1137
+ if (timer)
1138
+ clearTimeout(timer);
1139
+ }
1140
+ }));
1141
+ const totalMs = Date.now() - startedAt;
1142
+ const withHits = settled.filter((r) => r.count > 0);
1143
+ const total = withHits.reduce((s, r) => s + r.count, 0);
1144
+ const failed = settled.filter((r) => !r.ok).map((r) => ({ company: r.company, message: r.message }));
1145
+ if (textMode) {
1146
+ console.log(`\nfind "${keyword}" — ${total} hit(s) across ${withHits.length}/${scope.length} companies (${totalMs}ms)\n`);
1147
+ for (const r of withHits) {
1148
+ console.log(`▌ ${r.company} (${r.count})`);
1149
+ for (const p of r.positions) {
1150
+ const title = (p.title ?? "").trim().replace(/\s+/g, " ");
1151
+ const loc = (p.work_cities ?? "").trim();
1152
+ console.log(` ${p.post_id ?? "?"} ${title}${loc ? ` — ${loc}` : ""}`);
1153
+ if (p.apply_url)
1154
+ console.log(` ${p.apply_url}`);
1155
+ }
1156
+ console.log("");
1157
+ }
1158
+ if (failed.length > 0) {
1159
+ console.log(`Failed (${failed.length}):`);
1160
+ for (const f of failed)
1161
+ console.log(` ${f.company}: ${f.message}`);
1162
+ }
1163
+ return;
1164
+ }
1165
+ emit({
1166
+ ok: true,
1167
+ keyword,
1168
+ total,
1169
+ company_count: withHits.length,
1170
+ scanned_companies: scope.length,
1171
+ elapsed_ms: totalMs,
1172
+ results: withHits,
1173
+ failed,
1174
+ }, compact);
1175
+ return;
1176
+ }
1085
1177
  if (cmd === "profile") {
1086
1178
  const sub = args[1];
1087
1179
  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.13",
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",