@wport/cli 0.2.2 → 0.4.0

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/dist/index.js CHANGED
@@ -179,7 +179,7 @@ function isTimeoutAbort(err) {
179
179
  return false;
180
180
  }
181
181
  function buildUserAgent() {
182
- return `wport-cli/${"0.2.2"} (node ${process.version}; ${process.platform})`;
182
+ return `wport-cli/${"0.4.0"} (node ${process.version}; ${process.platform})`;
183
183
  }
184
184
  function unwrapDataResponse(body) {
185
185
  if (body && typeof body === "object" && "success" in body && "data" in body) {
@@ -187,6 +187,13 @@ function unwrapDataResponse(body) {
187
187
  }
188
188
  throw new CliError("Unexpected response shape: missing { success, data } wrapper", ExitCode.ServerOrNetworkError);
189
189
  }
190
+ function unwrapDataArray(body) {
191
+ const data = unwrapDataResponse(body);
192
+ if (!Array.isArray(data)) {
193
+ throw new CliError("Unexpected response shape: `data` is not an array", ExitCode.ServerOrNetworkError);
194
+ }
195
+ return data;
196
+ }
190
197
  function asPaginatedBody(body) {
191
198
  if (!body || typeof body !== "object") {
192
199
  throw new CliError("Unexpected response shape: not an object", ExitCode.ServerOrNetworkError);
@@ -633,6 +640,38 @@ function promptSecret(promptText, options = {}) {
633
640
  stdin.on("data", onData);
634
641
  });
635
642
  }
643
+ function readJsonInput(source, options = {}) {
644
+ const readStdin = options.readStdin ?? ((label) => readPipedStdin(label, { timeoutMs: options.timeoutMs }));
645
+ let raw;
646
+ if (source === "-") {
647
+ raw = readStdin("--file -");
648
+ } else {
649
+ try {
650
+ raw = (0, import_node_fs3.readFileSync)(source, "utf8");
651
+ } catch (err) {
652
+ throw new InvalidArgumentError(
653
+ `Cannot read --file "${source}": ${err.code ?? err.message}`
654
+ );
655
+ }
656
+ }
657
+ if (!raw.trim()) {
658
+ throw new InvalidArgumentError("Input is empty \u2014 expected a JSON body");
659
+ }
660
+ try {
661
+ return JSON.parse(raw);
662
+ } catch {
663
+ throw new InvalidArgumentError("Invalid JSON in input (parse failed)");
664
+ }
665
+ }
666
+ function readJsonObject(source, options = {}) {
667
+ const parsed = readJsonInput(source, options);
668
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
669
+ throw new InvalidArgumentError(
670
+ `Input must be a JSON object, got ${Array.isArray(parsed) ? "an array" : typeof parsed}`
671
+ );
672
+ }
673
+ return parsed;
674
+ }
636
675
 
637
676
  // src/commands/jobs/view.ts
638
677
  var import_picocolors2 = __toESM(require("picocolors"));
@@ -920,7 +959,7 @@ function registerDoctorCommand(program2) {
920
959
  ).action(async (_opts, command) => {
921
960
  const ctx = resolveContext(command);
922
961
  const line = (s = "") => process.stdout.write(s + "\n");
923
- line(`wport-cli ${"0.2.2"}`);
962
+ line(`wport-cli ${"0.4.0"}`);
924
963
  line(` bundled schema fingerprint: ${"839e8a891dfb"}`);
925
964
  line("");
926
965
  line("Resolved configuration:");
@@ -984,19 +1023,48 @@ async function enterpriseGet(opts, path, query) {
984
1023
  warnIfRateLimitLow(res.headers);
985
1024
  return { body, headers: res.headers };
986
1025
  }
1026
+ async function enterpriseWrite(method, opts, path, body, extra) {
1027
+ const url = new URL(`${opts.baseUrl}${ENTERPRISE_PREFIX}${path}`);
1028
+ const headers = {
1029
+ Authorization: `Bearer ${opts.apiKey}`,
1030
+ "Accept-Language": opts.locale,
1031
+ "User-Agent": buildUserAgent(),
1032
+ Accept: "application/json"
1033
+ };
1034
+ if (body !== void 0) headers["Content-Type"] = "application/json";
1035
+ if (extra?.idempotencyKey) headers["Idempotency-Key"] = extra.idempotencyKey;
1036
+ if (extra?.ifMatch) headers["If-Match"] = extra.ifMatch;
1037
+ const request = new Request(url, {
1038
+ method,
1039
+ headers,
1040
+ body: body !== void 0 ? JSON.stringify(body) : void 0
1041
+ });
1042
+ const res = await fetchWithTimeout(request, opts.timeoutMs);
1043
+ const respBody = await res.json().catch(() => null);
1044
+ if (!res.ok) throwEnterpriseHttpError(res.status, respBody);
1045
+ warnIfRateLimitLow(res.headers);
1046
+ return { body: respBody, headers: res.headers };
1047
+ }
1048
+ function enterprisePost(opts, path, body, extra) {
1049
+ return enterpriseWrite("POST", opts, path, body, extra);
1050
+ }
1051
+ function enterprisePatch(opts, path, body, extra) {
1052
+ return enterpriseWrite("PATCH", opts, path, body, extra);
1053
+ }
1054
+ function enterpriseDelete(opts, path, extra) {
1055
+ return enterpriseWrite("DELETE", opts, path, void 0, extra);
1056
+ }
987
1057
  function throwEnterpriseHttpError(status, body) {
988
1058
  const base = extractErrorMessage(body) ?? `HTTP ${status}`;
989
1059
  if (status === 401) {
990
1060
  throw new CliError(
991
- `${base}
992
- Key may have been revoked \u2014 run \`wport enterprise login\` to re-authenticate.`,
1061
+ `${base} \u2014 If your key has expired, rotate it in place: \`wport enterprise keys rotate <enc_id>\` (an expired key is still accepted for rotate). If it was revoked or is incorrect, obtain a valid key and run \`wport enterprise login\`.`,
993
1062
  ExitCode.ServerClientError
994
1063
  );
995
1064
  }
996
1065
  if (status === 403) {
997
1066
  throw new CliError(
998
- `${base}
999
- If your company account has been suspended, please contact support.`,
1067
+ `${base} \u2014 Your key may lack the required scope; rotate or issue a key that includes it. If your company account has been suspended, please contact support.`,
1000
1068
  ExitCode.ServerClientError
1001
1069
  );
1002
1070
  }
@@ -1281,11 +1349,291 @@ function registerEnterpriseJobsView(parent) {
1281
1349
  });
1282
1350
  }
1283
1351
 
1352
+ // src/commands/enterprise/jobs/create.ts
1353
+ var import_node_crypto = require("crypto");
1354
+ async function runJobsCreate(ctx, apiKey, source, idempotencyKey) {
1355
+ const jobBody = readJsonObject(source, { timeoutMs: ctx.timeoutMs });
1356
+ const { body } = await enterprisePost(
1357
+ { baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey },
1358
+ "/jobs",
1359
+ jobBody,
1360
+ { idempotencyKey }
1361
+ );
1362
+ const created = unwrapDataResponse(body);
1363
+ if (ctx.format === "json") {
1364
+ printJson(created);
1365
+ return;
1366
+ }
1367
+ process.stdout.write(`Created job: ${created.enc_id ?? ""}
1368
+ `);
1369
+ }
1370
+ function registerEnterpriseJobsCreate(parent) {
1371
+ parent.command("create").description('Create a job posting from a JSON file (use "-" to read stdin)').requiredOption("--file <path>", 'path to a JSON job body, or "-" for stdin').option("--idempotency-key <key>", "reuse across retries to avoid duplicate creates (default: a fresh UUID)").action(async (flags, command) => {
1372
+ const ctx = resolveContext(command);
1373
+ const globals = command.optsWithGlobals();
1374
+ const { key } = resolveApiKey(globals.apiKey);
1375
+ await runJobsCreate(ctx, key, flags.file, flags.idempotencyKey ?? (0, import_node_crypto.randomUUID)());
1376
+ });
1377
+ }
1378
+
1379
+ // src/commands/enterprise/jobs/update.ts
1380
+ var import_node_crypto2 = require("crypto");
1381
+
1382
+ // src/commands/enterprise/jobs/write-shared.ts
1383
+ function requireEncId(encId) {
1384
+ const trimmed = encId.trim();
1385
+ if (!trimmed) throw new CliError("enc_id must not be empty", ExitCode.InvalidArgument);
1386
+ return trimmed;
1387
+ }
1388
+
1389
+ // src/commands/enterprise/jobs/update.ts
1390
+ async function runJobsUpdate(ctx, apiKey, encId, source, idempotencyKey, ifMatch) {
1391
+ const trimmed = requireEncId(encId);
1392
+ const jobBody = readJsonObject(source, { timeoutMs: ctx.timeoutMs });
1393
+ const { body } = await enterprisePatch(
1394
+ { baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey },
1395
+ `/jobs/${encodeURIComponent(trimmed)}`,
1396
+ jobBody,
1397
+ { idempotencyKey, ifMatch }
1398
+ );
1399
+ const updated = unwrapDataResponse(body);
1400
+ if (ctx.format === "json") {
1401
+ printJson(updated);
1402
+ return;
1403
+ }
1404
+ process.stdout.write(`Updated job: ${updated.enc_id ?? trimmed}
1405
+ `);
1406
+ }
1407
+ function registerEnterpriseJobsUpdate(parent) {
1408
+ parent.command("update <enc_id>").description('Update a job posting from a JSON file (partial; use "-" for stdin)').requiredOption("--file <path>", 'path to a partial JSON job body, or "-" for stdin').option("--if-match <updated_at>", "optimistic lock: the job's current updated_at (409 if stale)").option("--idempotency-key <key>", "reuse across retries (default: a fresh UUID)").action(async (encId, flags, command) => {
1409
+ const ctx = resolveContext(command);
1410
+ const globals = command.optsWithGlobals();
1411
+ const { key } = resolveApiKey(globals.apiKey);
1412
+ await runJobsUpdate(ctx, key, encId, flags.file, flags.idempotencyKey ?? (0, import_node_crypto2.randomUUID)(), flags.ifMatch);
1413
+ });
1414
+ }
1415
+
1416
+ // src/commands/enterprise/jobs/lifecycle.ts
1417
+ var import_node_crypto3 = require("crypto");
1418
+ async function runJobsTransition(ctx, apiKey, encId, action, idempotencyKey) {
1419
+ const trimmed = requireEncId(encId);
1420
+ const { body } = await enterprisePatch(
1421
+ { baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey },
1422
+ `/jobs/${encodeURIComponent(trimmed)}/${action}`,
1423
+ {},
1424
+ { idempotencyKey }
1425
+ );
1426
+ const result = unwrapDataResponse(body);
1427
+ if (ctx.format === "json") {
1428
+ printJson(result);
1429
+ return;
1430
+ }
1431
+ const verb = action === "publish" ? "Published" : "Unpublished";
1432
+ process.stdout.write(`${verb} job: ${result.enc_id ?? trimmed}
1433
+ `);
1434
+ }
1435
+ async function runJobsDelete(ctx, apiKey, encId, confirm, idempotencyKey) {
1436
+ if (!confirm) {
1437
+ throw new CliError("Refusing to delete without --confirm (destructive, irreversible)", ExitCode.InvalidArgument);
1438
+ }
1439
+ const trimmed = requireEncId(encId);
1440
+ await enterpriseDelete(
1441
+ { baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey },
1442
+ `/jobs/${encodeURIComponent(trimmed)}`,
1443
+ { idempotencyKey }
1444
+ );
1445
+ if (ctx.format === "json") {
1446
+ printJson({ enc_id: trimmed, deleted: true });
1447
+ return;
1448
+ }
1449
+ process.stdout.write(`Deleted job: ${trimmed}
1450
+ `);
1451
+ }
1452
+ function registerEnterpriseJobsPublish(parent) {
1453
+ parent.command("publish <enc_id>").description("Publish a job posting").option("--idempotency-key <key>", "reuse across retries (default: a fresh UUID)").action(async (encId, flags, command) => {
1454
+ const ctx = resolveContext(command);
1455
+ const { key } = resolveApiKey(command.optsWithGlobals().apiKey);
1456
+ await runJobsTransition(ctx, key, encId, "publish", flags.idempotencyKey ?? (0, import_node_crypto3.randomUUID)());
1457
+ });
1458
+ }
1459
+ function registerEnterpriseJobsUnpublish(parent) {
1460
+ parent.command("unpublish <enc_id>").description("Unpublish (take down) a job posting").option("--idempotency-key <key>", "reuse across retries (default: a fresh UUID)").action(async (encId, flags, command) => {
1461
+ const ctx = resolveContext(command);
1462
+ const { key } = resolveApiKey(command.optsWithGlobals().apiKey);
1463
+ await runJobsTransition(ctx, key, encId, "unpublish", flags.idempotencyKey ?? (0, import_node_crypto3.randomUUID)());
1464
+ });
1465
+ }
1466
+ function registerEnterpriseJobsDelete(parent) {
1467
+ parent.command("delete <enc_id>").description("Delete a job posting (destructive; requires --confirm)").option("--confirm", "confirm this destructive, irreversible delete").option("--idempotency-key <key>", "reuse across retries (default: a fresh UUID)").action(async (encId, flags, command) => {
1468
+ const ctx = resolveContext(command);
1469
+ const { key } = resolveApiKey(command.optsWithGlobals().apiKey);
1470
+ await runJobsDelete(ctx, key, encId, flags.confirm === true, flags.idempotencyKey ?? (0, import_node_crypto3.randomUUID)());
1471
+ });
1472
+ }
1473
+
1474
+ // src/commands/enterprise/jobs/batch.ts
1475
+ var import_node_crypto4 = require("crypto");
1476
+ var BATCH_MIN = 1;
1477
+ var BATCH_MAX = 10;
1478
+ async function runJobsBatch(ctx, apiKey, source, confirm, idempotencyKey) {
1479
+ if (!confirm) {
1480
+ throw new CliError("Refusing to run batch create without --confirm", ExitCode.InvalidArgument);
1481
+ }
1482
+ const payload = readJsonObject(source, { timeoutMs: ctx.timeoutMs });
1483
+ const jobs = payload.jobs;
1484
+ if (!Array.isArray(jobs) || jobs.length < BATCH_MIN || jobs.length > BATCH_MAX) {
1485
+ throw new CliError(
1486
+ `Batch input must be { "jobs": [...] } with ${BATCH_MIN} to ${BATCH_MAX} items`,
1487
+ ExitCode.InvalidArgument
1488
+ );
1489
+ }
1490
+ const { body } = await enterprisePost(
1491
+ { baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey },
1492
+ "/jobs/batch",
1493
+ payload,
1494
+ { idempotencyKey }
1495
+ );
1496
+ const result = unwrapDataResponse(body);
1497
+ const succeeded = result.succeeded ?? [];
1498
+ const failed = result.failed ?? [];
1499
+ if (ctx.format === "json") {
1500
+ printJson(result);
1501
+ } else {
1502
+ process.stdout.write(`Batch: ${succeeded.length} succeeded, ${failed.length} failed (of ${jobs.length}).
1503
+ `);
1504
+ for (const s of succeeded)
1505
+ process.stdout.write(` ok [${s.index}] ${sanitizeForTerminal(String(s.enc_id ?? ""))}
1506
+ `);
1507
+ for (const f of failed)
1508
+ process.stdout.write(` fail [${f.index}] ${sanitizeForTerminal(String(f.error_path ?? ""))}
1509
+ `);
1510
+ }
1511
+ if (failed.length > 0) {
1512
+ throw new CliError(`${failed.length} of ${jobs.length} job(s) failed in batch create`, ExitCode.ServerClientError);
1513
+ }
1514
+ }
1515
+ function registerEnterpriseJobsBatch(parent) {
1516
+ parent.command("batch").description('Batch-create up to 10 jobs from a JSON file ({ "jobs": [...] }; requires --confirm)').requiredOption("--file <path>", 'path to a JSON { "jobs": [...] } body, or "-" for stdin').option("--confirm", "confirm this bulk write").option("--idempotency-key <key>", "reuse across retries (default: a fresh UUID)").action(async (flags, command) => {
1517
+ const ctx = resolveContext(command);
1518
+ const { key } = resolveApiKey(command.optsWithGlobals().apiKey);
1519
+ await runJobsBatch(ctx, key, flags.file, flags.confirm === true, flags.idempotencyKey ?? (0, import_node_crypto4.randomUUID)());
1520
+ });
1521
+ }
1522
+
1284
1523
  // src/commands/enterprise/jobs/index.ts
1285
1524
  function registerEnterpriseJobsCommand(parent) {
1286
- const jobs = parent.command("jobs").description("List and view your company job postings");
1525
+ const jobs = parent.command("jobs").description("Manage your company job postings");
1287
1526
  registerEnterpriseJobsList(jobs);
1288
1527
  registerEnterpriseJobsView(jobs);
1528
+ registerEnterpriseJobsCreate(jobs);
1529
+ registerEnterpriseJobsUpdate(jobs);
1530
+ registerEnterpriseJobsPublish(jobs);
1531
+ registerEnterpriseJobsUnpublish(jobs);
1532
+ registerEnterpriseJobsDelete(jobs);
1533
+ registerEnterpriseJobsBatch(jobs);
1534
+ }
1535
+
1536
+ // src/commands/enterprise/keys/list.ts
1537
+ function formatDate3(value) {
1538
+ return value ? String(value).slice(0, 10) : "";
1539
+ }
1540
+ function formatScopes(scopes) {
1541
+ return Array.isArray(scopes) ? scopes.join(",") : "";
1542
+ }
1543
+ async function runKeysList(ctx, apiKey) {
1544
+ const { body } = await enterpriseGet(
1545
+ { baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey },
1546
+ "/keys"
1547
+ );
1548
+ const keys = unwrapDataArray(body);
1549
+ if (ctx.format === "json") {
1550
+ printJson(keys);
1551
+ return;
1552
+ }
1553
+ printTable(
1554
+ keys,
1555
+ [
1556
+ { header: "ENC_ID", value: (r) => (r.enc_id ?? "").slice(0, 14) },
1557
+ { header: "NAME", value: (r) => r.name ?? "", maxWidth: 24 },
1558
+ { header: "LAST4", value: (r) => r.key_last4 ?? "" },
1559
+ { header: "SCOPES", value: (r) => formatScopes(r.scopes), maxWidth: 28 },
1560
+ { header: "STATUS", value: (r) => r.status ?? "" },
1561
+ { header: "EXPIRES", value: (r) => formatDate3(r.expires_at), maxWidth: 12 },
1562
+ { header: "LAST_USED", value: (r) => formatDate3(r.last_used_at), maxWidth: 12 }
1563
+ ],
1564
+ ctx.color
1565
+ );
1566
+ const active = keys.filter((k) => k.status === "active").length;
1567
+ process.stdout.write(dim(`${keys.length} key(s), ${active} active.`, ctx.color) + "\n");
1568
+ }
1569
+ function registerEnterpriseKeysList(parent) {
1570
+ parent.command("list").description("List your company API keys (masked)").action(async (_flags, command) => {
1571
+ const ctx = resolveContext(command);
1572
+ const globals = command.optsWithGlobals();
1573
+ const { key } = resolveApiKey(globals.apiKey);
1574
+ await runKeysList(ctx, key);
1575
+ });
1576
+ }
1577
+
1578
+ // src/commands/enterprise/keys/rotate.ts
1579
+ var ENTERPRISE_KEY_EXPIRY_DAYS = [30, 60, 90];
1580
+ function validateExpiryDays(raw) {
1581
+ if (raw === void 0) return void 0;
1582
+ if (!ENTERPRISE_KEY_EXPIRY_DAYS.includes(raw)) {
1583
+ throw new CliError(
1584
+ `Invalid --expiry-days ${raw}. Allowed: ${ENTERPRISE_KEY_EXPIRY_DAYS.join(", ")}`,
1585
+ ExitCode.InvalidArgument
1586
+ );
1587
+ }
1588
+ return raw;
1589
+ }
1590
+ async function runKeysRotate(ctx, apiKey, encId, flags) {
1591
+ const trimmed = encId.trim();
1592
+ if (!trimmed) throw new CliError("enc_id must not be empty", ExitCode.InvalidArgument);
1593
+ const expiryDays = validateExpiryDays(flags.expiryDays);
1594
+ const requestBody = {};
1595
+ if (expiryDays !== void 0) requestBody.expiry_days = expiryDays;
1596
+ const { body } = await enterprisePost(
1597
+ { baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey },
1598
+ `/keys/${encodeURIComponent(trimmed)}/rotate`,
1599
+ requestBody
1600
+ );
1601
+ const issued = unwrapDataResponse(body);
1602
+ if (ctx.format === "json") {
1603
+ printJson(issued);
1604
+ } else {
1605
+ const plaintext = issued.api_key ?? "";
1606
+ const shown = flags.reveal ? plaintext : maskKey(plaintext);
1607
+ const lines = [
1608
+ `New API key: ${sanitizeForTerminal(shown)}`,
1609
+ `enc_id: ${sanitizeForTerminal(issued.enc_id ?? "")}`,
1610
+ `scopes: ${sanitizeForTerminal((issued.scopes ?? []).join(","))}`,
1611
+ `expires_at: ${sanitizeForTerminal(issued.expires_at ?? "")}`
1612
+ ];
1613
+ process.stdout.write(lines.join("\n") + "\n");
1614
+ if (!flags.reveal) {
1615
+ process.stdout.write(dim("Re-run with --reveal to print the full key once.", ctx.color) + "\n");
1616
+ }
1617
+ }
1618
+ printWarn(
1619
+ `The previous key is now invalid. Update your ${API_KEY_ENV_VAR} env var / credential store, or run "wport enterprise login" with the new key.`,
1620
+ ctx.color
1621
+ );
1622
+ }
1623
+ function registerEnterpriseKeysRotate(parent) {
1624
+ parent.command("rotate <enc_id>").description("Rotate an API key in place (issues a new key, invalidates the old one)").option("--expiry-days <n>", "new key lifetime in days (30 | 60 | 90; default 90)", (v) => Number(v)).option("--reveal", "print the full new key (default masks all but the last 4 chars)").action(async (encId, flags, command) => {
1625
+ const ctx = resolveContext(command);
1626
+ const globals = command.optsWithGlobals();
1627
+ const { key } = resolveApiKey(globals.apiKey);
1628
+ await runKeysRotate(ctx, key, encId, flags);
1629
+ });
1630
+ }
1631
+
1632
+ // src/commands/enterprise/keys/index.ts
1633
+ function registerEnterpriseKeysCommand(parent) {
1634
+ const keys = parent.command("keys").description("List and rotate your company API keys");
1635
+ registerEnterpriseKeysList(keys);
1636
+ registerEnterpriseKeysRotate(keys);
1289
1637
  }
1290
1638
 
1291
1639
  // src/commands/enterprise/index.ts
@@ -1295,11 +1643,12 @@ function registerEnterpriseCommand(program2) {
1295
1643
  registerEnterpriseLogout(enterprise);
1296
1644
  registerEnterpriseWhoami(enterprise);
1297
1645
  registerEnterpriseJobsCommand(enterprise);
1646
+ registerEnterpriseKeysCommand(enterprise);
1298
1647
  }
1299
1648
 
1300
1649
  // src/index.ts
1301
1650
  var program = new import_commander.Command();
1302
- program.name("wport").description("wport CLI \u2014 terminal interface to the W101 Talent Search Hub public API").version("0.2.2", "-v, --version", "output the CLI version").option("--lang <locale>", "Accept-Language locale: zh-TW | en-US | vi-VN | th-TH | id-ID").option("--api <url>", "override API base URL").option("--output <fmt>", "output format: table | json").option("--no-color", "disable color output").option("--timeout <ms>", "HTTP timeout in milliseconds", (v) => Number(v));
1651
+ program.name("wport").description("wport CLI \u2014 terminal interface to the W101 Talent Search Hub public API").version("0.4.0", "-v, --version", "output the CLI version").option("--lang <locale>", "Accept-Language locale: zh-TW | en-US | vi-VN | th-TH | id-ID").option("--api <url>", "override API base URL").option("--output <fmt>", "output format: table | json").option("--no-color", "disable color output").option("--timeout <ms>", "HTTP timeout in milliseconds", (v) => Number(v));
1303
1652
  registerJobsCommand(program);
1304
1653
  registerConfigCommand(program);
1305
1654
  registerDoctorCommand(program);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/lib/errors.ts","../src/lib/output.ts","../src/commands/jobs/search.ts","../src/lib/api-client.ts","../src/lib/config-store.ts","../src/lib/global-opts.ts","../src/lib/path-utils.ts","../src/lib/concurrency.ts","../src/lib/io-helpers.ts","../src/commands/jobs/view.ts","../src/commands/jobs/index.ts","../src/commands/config/set.ts","../src/commands/config/get.ts","../src/commands/config/path.ts","../src/commands/config/reset.ts","../src/commands/config/index.ts","../src/commands/doctor.ts","../src/lib/enterprise-client.ts","../src/lib/credentials-store.ts","../src/commands/enterprise/login.ts","../src/commands/enterprise/logout.ts","../src/commands/enterprise/whoami.ts","../src/commands/enterprise/jobs/list.ts","../src/commands/enterprise/jobs/view.ts","../src/commands/enterprise/jobs/index.ts","../src/commands/enterprise/index.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { isCliError, ExitCode } from './lib/errors';\nimport { isColorEnabled, printError } from './lib/output';\nimport { registerJobsCommand } from './commands/jobs';\nimport { registerConfigCommand } from './commands/config';\nimport { registerDoctorCommand } from './commands/doctor';\nimport { registerEnterpriseCommand } from './commands/enterprise';\n\nconst program = new Command();\n\nprogram\n\t.name('wport')\n\t.description('wport CLI — terminal interface to the W101 Talent Search Hub public API')\n\t.version(__CLI_VERSION__, '-v, --version', 'output the CLI version')\n\t.option('--lang <locale>', 'Accept-Language locale: zh-TW | en-US | vi-VN | th-TH | id-ID')\n\t.option('--api <url>', 'override API base URL')\n\t.option('--output <fmt>', 'output format: table | json')\n\t.option('--no-color', 'disable color output')\n\t.option('--timeout <ms>', 'HTTP timeout in milliseconds', (v) => Number(v));\n\nregisterJobsCommand(program);\nregisterConfigCommand(program);\nregisterDoctorCommand(program);\nregisterEnterpriseCommand(program);\n\nprogram.exitOverride();\n\nprogram\n\t.parseAsync(process.argv)\n\t.then(() => process.exit(ExitCode.Success))\n\t.catch((err: unknown) => handleTopLevelError(err));\n\nfunction handleTopLevelError(err: unknown): never {\n\tconst color = isColorEnabled(false);\n\n\t// commander throws CommanderError on its own validation paths (help, version, unknown option).\n\tif (err && typeof err === 'object' && 'code' in err) {\n\t\tconst commanderErr = err as { code?: string; exitCode?: number; message?: string };\n\t\tif (commanderErr.code === 'commander.helpDisplayed' || commanderErr.code === 'commander.version') {\n\t\t\tprocess.exit(ExitCode.Success);\n\t\t}\n\t\t// commander 自己的 exitCode 多半是 1,不在 CLI 的 contract(0/2/3/4/5)內。\n\t\t// 任何 parsing / usage 失敗都當 InvalidArgument(2)。\n\t\tif (commanderErr.message) printError(commanderErr.message, color);\n\t\tprocess.exit(ExitCode.InvalidArgument);\n\t}\n\n\tif (isCliError(err)) {\n\t\tprintError(err.message, color);\n\t\tprocess.exit(err.exitCode);\n\t}\n\n\tconst fallbackMessage = err instanceof Error ? err.message : String(err);\n\tprintError(fallbackMessage, color);\n\tprocess.exit(ExitCode.ServerOrNetworkError);\n}\n","export const ExitCode = {\n\tSuccess: 0,\n\tInvalidArgument: 2,\n\tServerClientError: 3,\n\tServerOrNetworkError: 4,\n\tConfigCorrupt: 5,\n} as const;\n\nexport type ExitCodeValue = (typeof ExitCode)[keyof typeof ExitCode];\n\nexport class CliError extends Error {\n\treadonly exitCode: ExitCodeValue;\n\n\tconstructor(message: string, exitCode: ExitCodeValue) {\n\t\tsuper(message);\n\t\tthis.name = 'CliError';\n\t\tthis.exitCode = exitCode;\n\t}\n}\n\nexport class InvalidArgumentError extends CliError {\n\tconstructor(message: string) {\n\t\tsuper(message, ExitCode.InvalidArgument);\n\t\tthis.name = 'InvalidArgumentError';\n\t}\n}\n\nexport class ServerClientHttpError extends CliError {\n\treadonly status: number;\n\treadonly body: unknown;\n\tconstructor(message: string, status: number, body: unknown) {\n\t\tsuper(message, ExitCode.ServerClientError);\n\t\tthis.name = 'ServerClientHttpError';\n\t\tthis.status = status;\n\t\tthis.body = body;\n\t}\n}\n\nexport class NetworkError extends CliError {\n\treadonly cause?: unknown;\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(message, ExitCode.ServerOrNetworkError);\n\t\tthis.name = 'NetworkError';\n\t\tthis.cause = cause;\n\t}\n}\n\nexport class ConfigCorruptError extends CliError {\n\treadonly path?: string;\n\tconstructor(message: string, path?: string) {\n\t\tsuper(message, ExitCode.ConfigCorrupt);\n\t\tthis.name = 'ConfigCorruptError';\n\t\tthis.path = path;\n\t}\n}\n\nexport function isCliError(err: unknown): err is CliError {\n\treturn err instanceof CliError;\n}\n","import Table from 'cli-table3';\nimport pc from 'picocolors';\nimport { CliError, ExitCode } from './errors';\n\nexport type OutputFormat = 'table' | 'json';\n\n/**\n * 把 untrusted 字串(從 API 回來的 employer-controlled 內容)變成終端機可安全列印的形式。\n *\n * 防的是 terminal escape injection:\n * - CSI / OSC / DCS 等 ESC 開頭序列(清螢幕、改 title、移動游標、假超連結 phishing 等)\n * - 其他 C0 / C1 控制字元(保留 \\t \\n \\r 三個合法格式化字元)\n *\n * JSON 模式不需要 sanitize:JSON.stringify 會把 < 0x20 的字元 escape 成 \\uXXXX。\n * 只有 table / plain-text 印到 stdout/stderr 的字串走這個 helper。\n *\n * 用 new RegExp(string) 建構,所有控制字元以 \\\\uNNNN 形式撰寫,避免 source 內含 literal 控制字元。\n */\nconst ANSI_ESCAPE_SEQUENCE = new RegExp(\n\t[\n\t\t// CSI: ESC [ params intermediates final\n\t\t'\\\\u001B\\\\[[0-?]*[ -/]*[@-~]',\n\t\t// OSC: ESC ] payload (any chars except BEL/ESC) terminated by BEL or ESC \\\n\t\t'\\\\u001B\\\\][^\\\\u0007\\\\u001B]*(?:\\\\u0007|\\\\u001B\\\\\\\\)',\n\t\t// Two-char escapes: ESC + Fe final byte (0x40-0x5F = @ A B ... Z [ \\ ] ^ _).\n\t\t// 涵蓋 CSI([) / OSC(]) / DCS(P) / SOS(X) / ST(\\\\) / PM(^) / APC(_) intro。\n\t\t// CSI / OSC regex 在前面 OR-分支會先匹配對應序列;這條兜底所有未覆蓋 Fe。\n\t\t'\\\\u001B[@-_]',\n\t].join('|'),\n\t'g'\n);\n\n// 單行用:剝所有 C0(含 \\t \\n \\r)、DEL、C1。table cell、label-prefixed 標題、\n// error / warning 訊息都走這條 —— 即便 ANSI 已剝乾淨,殘留 \\r 仍能把 cursor 拉回\n// 行首蓋掉前面的內容;\\n 會打斷表格排版、可能偽造後續 row;\\t 寬度可變、\n// 搞壞 cli-table3 對齊。\nconst CONTROL_CHARS_STRICT = new RegExp('[\\\\u0000-\\\\u001F\\\\u007F\\\\u0080-\\\\u009F]', 'g');\n\n// 多行用:內部先把 \\r\\n / lone \\r 正規化成 \\n,再剝其他 C0(含 \\t)、DEL、C1。\n// 保留 \\n 作為合法段落分隔。Caller 不需事先做正規化。\nconst CONTROL_CHARS_MULTILINE = new RegExp('[\\\\u0000-\\\\u0009\\\\u000B-\\\\u001F\\\\u007F\\\\u0080-\\\\u009F]', 'g');\n\nexport function sanitizeForTerminal(s: string): string {\n\treturn s.replace(ANSI_ESCAPE_SEQUENCE, '').replace(CONTROL_CHARS_STRICT, '');\n}\n\nexport function sanitizeForTerminalMultiline(s: string): string {\n\treturn s.replace(ANSI_ESCAPE_SEQUENCE, '').replace(/\\r\\n?/g, '\\n').replace(CONTROL_CHARS_MULTILINE, '');\n}\n\nexport function resolveOutputFormat(explicit: string | undefined): OutputFormat {\n\tif (explicit === undefined) {\n\t\treturn process.stdout.isTTY ? 'table' : 'json';\n\t}\n\tif (explicit !== 'json' && explicit !== 'table') {\n\t\tthrow new CliError(`Invalid --output \"${explicit}\". Allowed: table, json`, ExitCode.InvalidArgument);\n\t}\n\treturn explicit;\n}\n\nexport function isColorEnabled(noColor: boolean | undefined): boolean {\n\tif (noColor === true) return false;\n\tif (process.env.NO_COLOR) return false;\n\treturn process.stdout.isTTY ?? false;\n}\n\nexport function printJson(value: unknown): void {\n\tprocess.stdout.write(JSON.stringify(value, null, 2) + '\\n');\n}\n\n/**\n * Emit one newline-delimited JSON record (ND-JSON). JSON.stringify escapes control\n * chars to \\uXXXX, so employer-controlled string values are terminal-safe without\n * extra sanitization. Used by `jobs view --batch`, where one record per line keeps a\n * single failure isolated to its own line.\n */\nexport function printNdjsonLine(value: unknown): void {\n\tprocess.stdout.write(JSON.stringify(value) + '\\n');\n}\n\nexport interface TableColumn<T> {\n\theader: string;\n\tvalue: (row: T) => string;\n\tmaxWidth?: number;\n}\n\nexport function printTable<T>(rows: T[], columns: TableColumn<T>[], color: boolean): void {\n\tif (rows.length === 0) {\n\t\tprocess.stdout.write(color ? pc.dim('(no results)\\n') : '(no results)\\n');\n\t\treturn;\n\t}\n\tconst table = new Table({\n\t\thead: columns.map((c) => (color ? pc.bold(c.header) : c.header)),\n\t\tstyle: { head: [], border: [] },\n\t\tcolWidths: columns.map((c) => c.maxWidth ?? null),\n\t\twordWrap: true,\n\t});\n\tfor (const row of rows) {\n\t\t// 每個 cell 的字串都過 sanitize:防 employer-controlled 內容(title/company/area/salary 等)注入 escape。\n\t\ttable.push(columns.map((c) => sanitizeForTerminal(c.value(row))));\n\t}\n\tprocess.stdout.write(table.toString() + '\\n');\n}\n\nexport function printError(message: string, color: boolean): void {\n\tconst prefix = color ? pc.red('Error:') : 'Error:';\n\t// Server 回的 error message 也視為 untrusted,sanitize。\n\tprocess.stderr.write(`${prefix} ${sanitizeForTerminal(message)}\\n`);\n}\n\nexport function printWarn(message: string, color: boolean): void {\n\tconst prefix = color ? pc.yellow('Warning:') : 'Warning:';\n\tprocess.stderr.write(`${prefix} ${sanitizeForTerminal(message)}\\n`);\n}\n\nexport function dim(text: string, color: boolean): string {\n\treturn color ? pc.dim(text) : text;\n}\n","import type { Command } from 'commander';\nimport { readFileSync } from 'node:fs';\nimport { asPaginatedBody, createApiClient, throwForHttpStatus } from '../../lib/api-client';\nimport { resolveContext } from '../../lib/global-opts';\nimport { CliError, ExitCode } from '../../lib/errors';\nimport { dim, printJson, printTable, printWarn } from '../../lib/output';\nimport { parseFieldsList, pickPaths } from '../../lib/path-utils';\nimport type { operations } from '../../generated/schema';\n\ninterface SearchFlags {\n\tkeyword?: string;\n\tlocation?: string[];\n\tcategory?: string[];\n\tpage?: number;\n\tpageSize?: number;\n\tjsonQuery?: string;\n\tfields?: string;\n\tminimal?: boolean;\n}\n\n/**\n * Compact field set for `--minimal` — the columns an agent almost always wants from a\n * search result, mirroring the table view minus the noise. Keeps `enc_id` first so the\n * output is directly pipeable into `jobs view -`.\n */\nconst MINIMAL_SEARCH_FIELDS = ['enc_id', 'title', 'company_name', 'area_display', 'salary_display'];\n\n/**\n * Query type derived from the generated OpenAPI schema for GET /api/jobs/search.\n * Adding a new field on the backend DTO + re-running gen:openapi will make this type\n * widen automatically; any flag we forget to map will surface as a TS error inside\n * buildQuery() instead of being silently dropped at runtime.\n */\ntype SearchQuery = NonNullable<operations['JobsController_searchJobs']['parameters']['query']>;\n\ninterface JobSearchItem {\n\tenc_id?: string;\n\tenc_company_id?: string;\n\tcompany_name?: string;\n\tcompany_logo_url?: string;\n\ttitle?: string;\n\tarea_display?: string;\n\tsalary_display?: string;\n\tsalary_currency_code?: string | null;\n\ttags?: string[];\n\tupdated_at?: string;\n\t[k: string]: unknown;\n}\n\nexport function registerJobsSearch(parent: Command): void {\n\tparent\n\t\t.command('search')\n\t\t.description(\n\t\t\t'Search public job listings. Sort is server-controlled (publish date, or relevance when --keyword is set); ' +\n\t\t\t\t'the orderBy / order query params are silently ignored, so this CLI intentionally exposes no sort flags. ' +\n\t\t\t\t'Run `wport doctor` for the full list of server quirks.'\n\t\t)\n\t\t.option('-k, --keyword <text>', 'keyword search (title / company name etc.)')\n\t\t.option('-l, --location <code...>', 'area code (repeatable, e.g. 6001001000)')\n\t\t.option('-c, --category <code...>', 'job classification code (repeatable)')\n\t\t.option('-p, --page <n>', 'page number (default 1)', (v) => Number(v))\n\t\t.option('-s, --page-size <n>', 'page size (default 10, max 100)', (v) => Number(v))\n\t\t.option('--json-query <file>', 'read full query body from JSON file (overrides other flags)')\n\t\t.option(\n\t\t\t'--fields <list>',\n\t\t\t'keep only these fields in each JSON result (comma-separated dotted paths, e.g. enc_id,title). JSON output only.'\n\t\t)\n\t\t.option('--minimal', `shorthand for --fields ${MINIMAL_SEARCH_FIELDS.join(',')}. JSON output only.`)\n\t\t.action(async (flags: SearchFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tconst fields = resolveSearchFields(flags);\n\t\t\tconst query = buildQuery(flags);\n\n\t\t\tconst client = createApiClient({\n\t\t\t\tbaseUrl: ctx.baseUrl,\n\t\t\t\tlocale: ctx.locale,\n\t\t\t\ttimeoutMs: ctx.timeoutMs,\n\t\t\t});\n\n\t\t\t// openapi-fetch consumes the response body itself; use `data` (success) or `error` (non-2xx).\n\t\t\tconst { data, error, response } = await client.GET('/api/jobs/search', {\n\t\t\t\tparams: { query },\n\t\t\t});\n\t\t\tif (!response.ok) throwForHttpStatus(response.status, error);\n\n\t\t\tconst paged = asPaginatedBody<JobSearchItem>(data);\n\n\t\t\tif (ctx.format === 'json') {\n\t\t\t\t// Field projection is client-side: it trims tokens the model has to read, not\n\t\t\t\t// bytes-on-the-wire (the server has no projection param). Pagination metadata is\n\t\t\t\t// preserved by spreading `paged` and only replacing `data`.\n\t\t\t\tconst body = fields ? { ...paged, data: paged.data.map((item) => pickPaths(item, fields)) } : paged;\n\t\t\t\tprintJson(body);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Table columns are fixed; --fields / --minimal are a JSON-only affordance. Warn\n\t\t\t// rather than silently ignore so the flag doesn't look broken.\n\t\t\tif (fields) {\n\t\t\t\tprintWarn('--fields / --minimal only affect JSON output; ignored for table. Use --output json.', ctx.color);\n\t\t\t}\n\n\t\t\tprintTable(\n\t\t\t\tpaged.data,\n\t\t\t\t[\n\t\t\t\t\t{ header: 'ENC_ID', value: (r) => truncate(r.enc_id ?? '', 14) },\n\t\t\t\t\t{ header: 'TITLE', value: (r) => r.title ?? '', maxWidth: 36 },\n\t\t\t\t\t{ header: 'COMPANY', value: (r) => r.company_name ?? '', maxWidth: 20 },\n\t\t\t\t\t{ header: 'LOCATION', value: (r) => r.area_display ?? '', maxWidth: 18 },\n\t\t\t\t\t{ header: 'SALARY', value: (r) => r.salary_display ?? '', maxWidth: 18 },\n\t\t\t\t\t{ header: 'UPDATED', value: (r) => formatDate(r.updated_at), maxWidth: 12 },\n\t\t\t\t],\n\t\t\t\tctx.color\n\t\t\t);\n\n\t\t\tconst head = `Showing page ${paged.currentPage}/${paged.totalPages} (${paged.data.length} of ${paged.totalCount} results).`;\n\t\t\tconst hint =\n\t\t\t\tpaged.totalPages > paged.currentPage ? ` Next: wport jobs search --page ${paged.currentPage + 1}` : '';\n\t\t\tprocess.stdout.write(dim(head + hint, ctx.color) + '\\n');\n\t\t});\n}\n\nfunction resolveSearchFields(flags: SearchFlags): string[] | undefined {\n\tif (flags.fields && flags.minimal) {\n\t\tthrow new CliError('Use either --fields or --minimal, not both', ExitCode.InvalidArgument);\n\t}\n\tif (flags.minimal) return [...MINIMAL_SEARCH_FIELDS];\n\tif (flags.fields) return parseFieldsList(flags.fields);\n\treturn undefined;\n}\n\nfunction buildQuery(flags: SearchFlags): SearchQuery {\n\tif (flags.jsonQuery) {\n\t\t// User-supplied JSON escape hatch — we trust the caller. Runtime validation will come\n\t\t// from the server side; this is the one spot the typed query is deliberately relaxed.\n\t\treturn readJsonQuery(flags.jsonQuery) as SearchQuery;\n\t}\n\tconst q: SearchQuery = {};\n\tif (flags.keyword) q.keyword = flags.keyword;\n\tif (flags.location?.length) q.area_codes = flags.location;\n\tif (flags.category?.length) q.job_classification_codes = flags.category;\n\tif (flags.page !== undefined) q.currentPage = flags.page;\n\tif (flags.pageSize !== undefined) q.pageSize = flags.pageSize;\n\treturn q;\n}\n\nfunction readJsonQuery(path: string): Record<string, unknown> {\n\tlet raw: string;\n\ttry {\n\t\traw = readFileSync(path, 'utf8');\n\t} catch (err) {\n\t\tthrow new CliError(`Cannot read --json-query file ${path}: ${(err as Error).message}`, ExitCode.InvalidArgument);\n\t}\n\ttry {\n\t\tconst parsed = JSON.parse(raw);\n\t\tif (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n\t\t\tthrow new Error(\n\t\t\t\tArray.isArray(parsed)\n\t\t\t\t\t? 'JSON root is an array; expected an object with query fields'\n\t\t\t\t\t: 'JSON root must be an object'\n\t\t\t);\n\t\t}\n\t\treturn parsed as Record<string, unknown>;\n\t} catch (err) {\n\t\tthrow new CliError(`Invalid JSON in ${path}: ${(err as Error).message}`, ExitCode.InvalidArgument);\n\t}\n}\n\nfunction truncate(s: string, max: number): string {\n\t// Fast path: UTF-16 code units (string.length) are always >= codepoint count,\n\t// so if byte-length already fits we don't need codepoint counting.\n\tif (s.length <= max) return s;\n\t// Array.from iterates by code-point, so surrogate pairs (emoji, supplementary\n\t// plane chars) aren't split mid-character. Doesn't handle grapheme clusters\n\t// (combining marks), but covers the common bilingual / emoji case.\n\tconst chars = Array.from(s);\n\tif (chars.length <= max) return s;\n\treturn chars.slice(0, max - 1).join('') + '…';\n}\n\nfunction formatDate(s: string | undefined): string {\n\tif (!s) return '';\n\tconst m = /^(\\d{4}-\\d{2}-\\d{2})/.exec(s);\n\treturn m ? m[1] : s;\n}\n","import createClient, { type Client } from 'openapi-fetch';\nimport type { paths } from '../generated/schema';\nimport { CliError, ExitCode, NetworkError, ServerClientHttpError } from './errors';\n\nexport interface ApiClientOptions {\n\tbaseUrl: string;\n\tlocale: string;\n\ttimeoutMs: number;\n}\n\nexport type ApiClient = Client<paths>;\n\n// Connection reuse for batch / repeated requests is handled by Node's built-in fetch\n// (undici): its global dispatcher pools keep-alive connections per origin, so multiple\n// requests from one process to the same host already reuse TCP/TLS without any setup\n// here. We deliberately don't ship a custom `undici` Agent — it'd add a runtime\n// dependency to nudge keepAliveTimeout (~4s default → longer) for near-zero gain on the\n// short-lived bursts `jobs view --batch` produces.\nexport function createApiClient(opts: ApiClientOptions): ApiClient {\n\treturn createClient<paths>({\n\t\tbaseUrl: opts.baseUrl,\n\t\theaders: {\n\t\t\t'Accept-Language': opts.locale,\n\t\t\t'User-Agent': buildUserAgent(),\n\t\t\tAccept: 'application/json',\n\t\t},\n\t\tfetch: (request: Request) => fetchWithTimeout(request, opts.timeoutMs),\n\t});\n}\n\nexport function fetchWithTimeout(request: Request, timeoutMs: number): Promise<Response> {\n\t// AbortSignal.timeout is available since Node 17.3 (engines requires >=18.17).\n\t// New Request inherits method/headers/body but overrides signal.\n\tconst timedRequest = new Request(request, { signal: AbortSignal.timeout(timeoutMs) });\n\treturn fetch(timedRequest).catch((err: unknown) => {\n\t\tif (isTimeoutAbort(err)) {\n\t\t\tthrow new NetworkError(`Request timed out after ${timeoutMs}ms`, err);\n\t\t}\n\t\t// TypeError: fetch failed → ECONNREFUSED / ENOTFOUND / TLS / proxy\n\t\tconst code = (err as { cause?: { code?: string } })?.cause?.code;\n\t\tconst detail = code ? code : ((err as Error)?.message ?? String(err));\n\t\tthrow new NetworkError(`Cannot reach upstream: ${detail}`, err);\n\t});\n}\n\nfunction isTimeoutAbort(err: unknown): boolean {\n\tif (err && typeof err === 'object' && 'name' in err) {\n\t\tconst name = (err as { name?: string }).name;\n\t\treturn name === 'TimeoutError' || name === 'AbortError';\n\t}\n\treturn false;\n}\n\nexport function buildUserAgent(): string {\n\treturn `wport-cli/${__CLI_VERSION__} (node ${process.version}; ${process.platform})`;\n}\n\n/**\n * W101 後端 `DataResponse<T>` wrapper:`{ success, statusCode, message, data: T }`。\n * 用於回傳「單筆」payload 的端點(例如 GET /api/jobs/:encId/view)。\n *\n * Shape 不符直接 throw CliError,不再 silent cast 把 wrapper 當 payload 回。\n *\n * 注意:`PaginatedResponse` 是另一種扁平結構\n * `{ success, statusCode, message, data: T[], currentPage, totalPages, pageSize, totalCount }`,\n * 不要對 paginated 回應用此函式 —— 會丟失 pagination 欄位。\n */\nexport function unwrapDataResponse<T>(body: unknown): T {\n\tif (body && typeof body === 'object' && 'success' in body && 'data' in body) {\n\t\treturn (body as { data: T }).data;\n\t}\n\tthrow new CliError('Unexpected response shape: missing { success, data } wrapper', ExitCode.ServerOrNetworkError);\n}\n\n/**\n * W101 後端 `PaginatedResponse<T>` wrapper(扁平):\n * `{ success, statusCode, message, data: T[], currentPage, totalPages, pageSize, totalCount }`。\n * 直接 cast,不剝外層;callers 從 `.data` 拿 list,從頂層欄位拿分頁 metadata。\n */\nexport interface PaginatedBody<T> {\n\tsuccess?: boolean;\n\tstatusCode?: number;\n\tmessage?: unknown;\n\tdata: T[];\n\tcurrentPage: number;\n\ttotalPages: number;\n\tpageSize: number;\n\ttotalCount: number;\n}\n\nexport function asPaginatedBody<T>(body: unknown): PaginatedBody<T> {\n\tif (!body || typeof body !== 'object') {\n\t\tthrow new CliError('Unexpected response shape: not an object', ExitCode.ServerOrNetworkError);\n\t}\n\tconst b = body as Record<string, unknown>;\n\tif (!Array.isArray(b.data)) {\n\t\tthrow new CliError('Unexpected response shape: missing `data` array', ExitCode.ServerOrNetworkError);\n\t}\n\tfor (const key of ['currentPage', 'totalPages', 'pageSize', 'totalCount'] as const) {\n\t\tif (typeof b[key] !== 'number') {\n\t\t\tthrow new CliError(`Unexpected response shape: missing or non-numeric \"${key}\"`, ExitCode.ServerOrNetworkError);\n\t\t}\n\t}\n\treturn body as PaginatedBody<T>;\n}\n\nexport function throwForHttpStatus(status: number, body: unknown): never {\n\tconst message = extractErrorMessage(body) ?? `HTTP ${status}`;\n\tif (status >= 400 && status < 500) {\n\t\tthrow new ServerClientHttpError(message, status, body);\n\t}\n\tthrow new CliError(message, ExitCode.ServerOrNetworkError);\n}\n\nexport function extractErrorMessage(body: unknown): string | null {\n\tif (typeof body === 'string') return body;\n\tif (body && typeof body === 'object') {\n\t\tconst obj = body as Record<string, unknown>;\n\t\t// NestJS class-validator default: message: string[]\n\t\tif (Array.isArray(obj.message)) {\n\t\t\tconst parts = obj.message.filter((m): m is string => typeof m === 'string');\n\t\t\tif (parts.length > 0) return parts.join('; ');\n\t\t}\n\t\tif (typeof obj.message === 'string') return obj.message;\n\t\t// i18n object 或 nested → 印 JSON tail\n\t\tif (obj.message && typeof obj.message === 'object') {\n\t\t\ttry {\n\t\t\t\treturn JSON.stringify(obj.message);\n\t\t\t} catch {\n\t\t\t\t/* ignore */\n\t\t\t}\n\t\t}\n\t\t// Enterprise API error body 帶 i18n path(如 error.enterprise.invalid_api_key),\n\t\t// message 缺席時讓 path 當最後可讀資訊(guard 直接丟 { path } 的情境)。\n\t\tif (typeof obj.path === 'string') return obj.path;\n\t\tif (typeof obj.error === 'string') return obj.error;\n\t}\n\treturn null;\n}\n","import {\n\texistsSync,\n\tmkdirSync,\n\treadFileSync,\n\tchmodSync,\n\topenSync,\n\twriteSync,\n\tcloseSync,\n\trenameSync,\n\tunlinkSync,\n} from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport envPaths from 'env-paths';\nimport { CliError, ExitCode } from './errors';\nimport { printWarn } from './output';\n\nexport const ALLOWED_LOCALES = ['zh-TW', 'en-US', 'vi-VN', 'th-TH', 'id-ID'] as const;\nexport type Locale = (typeof ALLOWED_LOCALES)[number];\n\nexport const ALLOWED_OUTPUT = ['table', 'json'] as const;\nexport type OutputPref = (typeof ALLOWED_OUTPUT)[number];\n\nexport interface CliConfig {\n\tlocale?: Locale;\n\toutput?: OutputPref;\n\ttimeout_ms?: number;\n}\n\nconst CONFIG_KEYS = ['locale', 'output', 'timeout_ms'] as const satisfies readonly (keyof CliConfig)[];\nexport type ConfigKey = (typeof CONFIG_KEYS)[number];\n\n/**\n * Keys recognised in older configs but no longer settable. Detected in parseConfig\n * to surface a one-time deprecation warning instead of silently dropping (which the\n * forward-compat path would do for genuinely unknown keys).\n *\n * `api_base_url` was removed in 0.1.2 — SSRF / credential exfil surface for a flag\n * external users don't actually need. Override via `WPORT_API_BASE` env var or `--api`.\n */\nconst DEPRECATED_CONFIG_KEYS = ['api_base_url'] as const;\ntype DeprecatedConfigKey = (typeof DEPRECATED_CONFIG_KEYS)[number];\n\n/** Per-key migration hint shown when a deprecated key is found in an existing config. */\nconst DEPRECATED_KEY_HINTS: Record<DeprecatedConfigKey, string> = {\n\tapi_base_url: 'Set the WPORT_API_BASE env var (or use --api) instead.',\n};\n\n// One-time latch so repeated loadConfig() calls (e.g. inside a batch run) emit the\n// deprecation notice at most once per process rather than spamming stderr.\nlet deprecationWarned = false;\n\n/** Per-key value type. validateAndCoerce<K> returns ConfigValueMap[K]. */\ntype ConfigValueMap = {\n\tlocale: Locale;\n\toutput: OutputPref;\n\ttimeout_ms: number;\n};\n\nexport function isConfigKey(key: string): key is ConfigKey {\n\treturn (CONFIG_KEYS as readonly string[]).includes(key);\n}\n\nexport function isDeprecatedConfigKey(key: string): key is DeprecatedConfigKey {\n\treturn (DEPRECATED_CONFIG_KEYS as readonly string[]).includes(key);\n}\n\nconst paths = envPaths('wport', { suffix: '' });\n\nexport function getConfigPath(): string {\n\treturn join(paths.config, 'config.json');\n}\n\n/**\n * Trust boundary:把外部 JSON object 收成型別正確的 CliConfig。\n * 每個 key 都走 validateAndCoerce,不認識的 key 直接 drop(forward compatible,\n * 未來新版多塞了 key、舊 CLI 不會炸)。\n */\nexport function parseConfig(raw: unknown): CliConfig {\n\tif (!raw || typeof raw !== 'object' || Array.isArray(raw)) {\n\t\tthrow new CliError('Config must be a JSON object', ExitCode.ConfigCorrupt);\n\t}\n\tconst input = raw as Record<string, unknown>;\n\n\t// Surface (once per process) any deprecated key still sitting in the user's config.\n\t// We warn + drop rather than error, so upgrading from <=0.1.1 never hard-fails; the\n\t// key's actual replacement (WPORT_API_BASE) is resolved elsewhere in global-opts.\n\tif (!deprecationWarned) {\n\t\tfor (const dep of DEPRECATED_CONFIG_KEYS) {\n\t\t\tif (dep in input) {\n\t\t\t\tdeprecationWarned = true;\n\t\t\t\tprintWarn(`Config key \"${dep}\" was removed in 0.1.2 and is ignored. ${DEPRECATED_KEY_HINTS[dep]}`, false);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst out: CliConfig = {};\n\tfor (const key of CONFIG_KEYS) {\n\t\tif (!(key in input)) continue;\n\t\tconst value = input[key];\n\t\ttry {\n\t\t\tconst coerced = validateAndCoerce(key, String(value));\n\t\t\t// Object.assign 形式避免 TS 5.5 在 `out[key] = coerced` 上推不出 ConfigValueMap[K]→CliConfig[K]\n\t\t\t// 的對應關係。validateAndCoerce 已是 generic、型別正確;此處只是 indexed assignment 的繞道。\n\t\t\tObject.assign(out, { [key]: coerced });\n\t\t} catch (err) {\n\t\t\tif (err instanceof CliError) {\n\t\t\t\tthrow new CliError(`Config key \"${key}\" invalid: ${err.message}`, ExitCode.ConfigCorrupt);\n\t\t\t}\n\t\t\tthrow err;\n\t\t}\n\t}\n\treturn out;\n}\n\nexport function loadConfig(): CliConfig {\n\tconst path = getConfigPath();\n\tif (!existsSync(path)) return {};\n\tlet raw: string;\n\ttry {\n\t\traw = readFileSync(path, 'utf8');\n\t} catch (err) {\n\t\tthrow new CliError(`Failed to read config at ${path}: ${(err as Error).message}`, ExitCode.ConfigCorrupt);\n\t}\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch (err) {\n\t\tthrow new CliError(`Failed to parse JSON at ${path}: ${(err as Error).message}`, ExitCode.ConfigCorrupt);\n\t}\n\treturn parseConfig(parsed);\n}\n\nexport function saveConfig(config: CliConfig): void {\n\tconst path = getConfigPath();\n\tmkdirSync(dirname(path), { recursive: true });\n\n\t// Atomic: write tmpfile (mode 0o600 from open()) → rename to final path (POSIX atomic).\n\t// 即使中途 crash,舊檔仍完整、不會留 truncated JSON 觸發 ConfigCorrupt 鎖死 CLI。\n\tconst tmpPath = `${path}.tmp.${process.pid}.${Date.now()}`;\n\tconst fd = openSync(tmpPath, 'w', 0o600);\n\ttry {\n\t\twriteSync(fd, JSON.stringify(config, null, 2) + '\\n');\n\t} catch (err) {\n\t\tcloseSync(fd);\n\t\ttry {\n\t\t\tunlinkSync(tmpPath);\n\t\t} catch {\n\t\t\t/* best effort cleanup */\n\t\t}\n\t\tthrow err;\n\t}\n\tcloseSync(fd);\n\n\t// POSIX: openSync's mode is masked by umask (umask can only narrow, never widen).\n\t// chmod restores 0o600 in case a permissive umask stripped owner bits; it cannot\n\t// expose the file to group/other. On Windows chmodSync is a no-op, skip entirely.\n\tif (process.platform !== 'win32') {\n\t\ttry {\n\t\t\tchmodSync(tmpPath, 0o600);\n\t\t} catch (err) {\n\t\t\tprintWarn(\n\t\t\t\t`Failed to chmod 0600 on config tmpfile: ${(err as Error).message}. ` +\n\t\t\t\t\t'Other users on this system may be able to read CLI config.',\n\t\t\t\tfalse\n\t\t\t);\n\t\t}\n\t}\n\n\trenameSync(tmpPath, path);\n}\n\nexport function validateAndCoerce<K extends ConfigKey>(key: K, value: string): ConfigValueMap[K] {\n\tswitch (key) {\n\t\tcase 'locale': {\n\t\t\tif (!(ALLOWED_LOCALES as readonly string[]).includes(value)) {\n\t\t\t\tthrow new CliError(\n\t\t\t\t\t`Invalid locale \"${value}\". Allowed: ${ALLOWED_LOCALES.join(', ')}`,\n\t\t\t\t\tExitCode.InvalidArgument\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn value as ConfigValueMap[K];\n\t\t}\n\t\tcase 'output': {\n\t\t\tif (!(ALLOWED_OUTPUT as readonly string[]).includes(value)) {\n\t\t\t\tthrow new CliError(\n\t\t\t\t\t`Invalid output \"${value}\". Allowed: ${ALLOWED_OUTPUT.join(', ')}`,\n\t\t\t\t\tExitCode.InvalidArgument\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn value as ConfigValueMap[K];\n\t\t}\n\t\tcase 'timeout_ms': {\n\t\t\tconst n = Number(value);\n\t\t\tif (!Number.isInteger(n) || n < 100 || n > 600_000) {\n\t\t\t\tthrow new CliError(\n\t\t\t\t\t`timeout_ms must be an integer between 100 and 600000 (got ${value})`,\n\t\t\t\t\tExitCode.InvalidArgument\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn n as ConfigValueMap[K];\n\t\t}\n\t}\n}\n\n// Internal helpers exposed for tests. Not part of the public CLI API.\nexport const __test__ = {\n\tresetDeprecationWarning(): void {\n\t\tdeprecationWarned = false;\n\t},\n};\n","import type { Command } from 'commander';\nimport { ALLOWED_LOCALES, loadConfig, type Locale, type CliConfig } from './config-store';\nimport { CliError, ExitCode } from './errors';\nimport { resolveOutputFormat, isColorEnabled, type OutputFormat } from './output';\n\n// Production public API. Local development overrides via the WPORT_API_BASE env var\n// or the `--api` flag. (The `api_base_url` config key was removed in 0.1.2 — keeping a\n// persisted, mutable base URL on disk is an SSRF / credential-exfil surface that\n// external users don't need.)\nconst DEFAULT_BASE_URL = 'https://api.wport.me';\nexport const API_BASE_ENV_VAR = 'WPORT_API_BASE';\nconst DEFAULT_LOCALE: Locale = 'zh-TW';\nconst DEFAULT_TIMEOUT_MS = 10_000;\n\nexport interface ResolvedContext {\n\tbaseUrl: string;\n\tlocale: Locale;\n\ttimeoutMs: number;\n\tformat: OutputFormat;\n\tcolor: boolean;\n\tconfig: CliConfig;\n}\n\ninterface RawGlobals {\n\tlang?: string;\n\tapi?: string;\n\toutput?: string;\n\tcolor?: boolean;\n\ttimeout?: number;\n}\n\nexport function resolveContext(command: Command): ResolvedContext {\n\tconst globals = command.optsWithGlobals() as RawGlobals;\n\tconst config = loadConfig();\n\n\treturn {\n\t\tbaseUrl: resolveBaseUrl(globals.api),\n\t\tlocale: resolveLocale(globals.lang, config),\n\t\ttimeoutMs: resolveTimeout(globals.timeout, config),\n\t\tformat: resolveOutputFormat(globals.output),\n\t\tcolor: isColorEnabled(globals.color === false),\n\t\tconfig,\n\t};\n}\n\n/**\n * Resolve the API base URL. Precedence: `--api` flag > WPORT_API_BASE env var > default.\n * The env var is just as untrusted as the (removed) config key, so it gets the same\n * http(s)-only validation to keep the SSRF surface closed.\n */\nfunction resolveBaseUrl(override: string | undefined): string {\n\tconst fromEnv = process.env[API_BASE_ENV_VAR]?.trim();\n\tif (override !== undefined) return validateBaseUrl(override, '--api');\n\tif (fromEnv) return validateBaseUrl(fromEnv, `${API_BASE_ENV_VAR} env var`);\n\treturn DEFAULT_BASE_URL;\n}\n\nfunction validateBaseUrl(raw: string, source: string): string {\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(raw);\n\t} catch {\n\t\tthrow new CliError(`Invalid API base URL from ${source}: ${raw}`, ExitCode.InvalidArgument);\n\t}\n\tif (url.protocol !== 'https:' && url.protocol !== 'http:') {\n\t\tthrow new CliError(\n\t\t\t`API base URL from ${source} must be http or https (got ${url.protocol})`,\n\t\t\tExitCode.InvalidArgument\n\t\t);\n\t}\n\treturn raw.replace(/\\/$/, '');\n}\n\nfunction resolveLocale(override: string | undefined, config: CliConfig): Locale {\n\tconst raw = override ?? config.locale ?? DEFAULT_LOCALE;\n\tif (!(ALLOWED_LOCALES as readonly string[]).includes(raw)) {\n\t\tthrow new CliError(`Invalid --lang \"${raw}\". Allowed: ${ALLOWED_LOCALES.join(', ')}`, ExitCode.InvalidArgument);\n\t}\n\treturn raw as Locale;\n}\n\nfunction resolveTimeout(override: number | undefined, config: CliConfig): number {\n\tconst raw = override ?? config.timeout_ms ?? DEFAULT_TIMEOUT_MS;\n\tif (!Number.isInteger(raw) || raw < 100 || raw > 600_000) {\n\t\tthrow new CliError(`Invalid --timeout ${raw} (must be integer 100..600000)`, ExitCode.InvalidArgument);\n\t}\n\treturn raw;\n}\n\n// Internal helpers exposed for tests. Not part of the public CLI API.\nexport const __test__ = {\n\tresolveBaseUrl,\n\tDEFAULT_BASE_URL,\n};\n","import { CliError, ExitCode } from './errors';\n\n/**\n * Read a value out of a nested object by dotted path (e.g. `job_info.job_title`).\n * Returns undefined if any segment is missing.\n *\n * Uses hasOwnProperty (not the `in` operator / direct index) so a path segment can\n * never traverse into `__proto__` / `constructor` and walk the prototype chain —\n * the input objects are server-controlled, so this is a deliberate safety boundary.\n */\nexport function getPath(obj: unknown, dottedPath: string): unknown {\n\tconst parts = dottedPath.split('.');\n\tlet cur: unknown = obj;\n\tfor (const p of parts) {\n\t\tif (cur && typeof cur === 'object' && Object.prototype.hasOwnProperty.call(cur, p)) {\n\t\t\tcur = (cur as Record<string, unknown>)[p];\n\t\t} else {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\treturn cur;\n}\n\n/**\n * Project an object down to a set of dotted paths, keyed by the path string itself\n * (so `pickPaths(job, ['job_info.job_title'])` → `{ 'job_info.job_title': '...' }`).\n *\n * Every requested path becomes a key so the shape is predictable across a list of\n * heterogeneous items: a missing path yields `null` rather than being dropped, which\n * keeps each row in `jobs search --fields` structurally identical for downstream tools.\n */\nexport function pickPaths(obj: unknown, paths: string[]): Record<string, unknown> {\n\tconst out: Record<string, unknown> = {};\n\tfor (const p of paths) {\n\t\tconst v = getPath(obj, p);\n\t\tout[p] = v === undefined ? null : v;\n\t}\n\treturn out;\n}\n\n/**\n * Parse a comma-separated `--fields` value into a trimmed, non-empty list.\n * Throws InvalidArgument if the result is empty (e.g. `--fields ,,`).\n */\nexport function parseFieldsList(raw: string): string[] {\n\tconst fields = raw\n\t\t.split(',')\n\t\t.map((s) => s.trim())\n\t\t.filter(Boolean);\n\tif (fields.length === 0) {\n\t\tthrow new CliError('--fields requires at least one field name', ExitCode.InvalidArgument);\n\t}\n\treturn fields;\n}\n","/**\n * Run `fn` over `items` with at most `limit` in flight at once, returning results in\n * the SAME order as the input (not completion order) so callers can correlate output\n * rows back to their input without threading an index through.\n *\n * `fn` is expected to handle its own errors (e.g. resolve to an error-shaped result);\n * a rejection from `fn` will reject the whole batch, so the batch caller wraps each\n * unit in try/catch to keep one failure from sinking the rest.\n */\nexport async function mapWithConcurrency<T, R>(\n\titems: readonly T[],\n\tlimit: number,\n\tfn: (item: T, index: number) => Promise<R>\n): Promise<R[]> {\n\tconst results = new Array<R>(items.length);\n\tlet cursor = 0;\n\n\tasync function worker(): Promise<void> {\n\t\tfor (;;) {\n\t\t\tconst index = cursor++;\n\t\t\tif (index >= items.length) return;\n\t\t\tresults[index] = await fn(items[index], index);\n\t\t}\n\t}\n\n\tconst workerCount = Math.min(Math.max(1, limit), items.length);\n\tawait Promise.all(Array.from({ length: workerCount }, () => worker()));\n\treturn results;\n}\n","import { readSync } from 'node:fs';\nimport { CliError, ExitCode, InvalidArgumentError } from './errors';\n\n/**\n * Reject with `CliError(ServerOrNetworkError)` if a promise doesn't settle within `ms`.\n *\n * Reserved for async user / network input paths that v0.2 will add (streaming jobs,\n * interactive prompts with deadlines). Existing call sites either use their own\n * mechanism (`api-client` uses `AbortSignal.timeout`, `reset.ts` uses an `'end'`\n * handler) or are synchronous (`readFileSync(0)`). Removing this until then would\n * just churn the import graph; keeping it documents the contract.\n *\n * @internal — exported for future call sites, not part of public CLI API\n */\nexport function withTimeout<T>(promise: Promise<T>, ms: number, label: string): Promise<T> {\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst t = setTimeout(() => {\n\t\t\treject(new CliError(`Timed out after ${ms}ms: ${label}`, ExitCode.ServerOrNetworkError));\n\t\t}, ms);\n\t\tpromise.then(\n\t\t\t(v) => {\n\t\t\t\tclearTimeout(t);\n\t\t\t\tresolve(v);\n\t\t\t},\n\t\t\t(err) => {\n\t\t\t\tclearTimeout(t);\n\t\t\t\treject(err);\n\t\t\t}\n\t\t);\n\t});\n}\n\n/** Convenience: throw InvalidArgumentError on TTY stdin reads with no piped input. */\nexport function ensureStdinPiped(label: string): void {\n\tif (process.stdin.isTTY) {\n\t\tthrow new InvalidArgumentError(`${label}: no data on stdin (run via pipe, or pass the value as an arg)`);\n\t}\n}\n\n/** Standalone backstop when a caller can't supply a `--timeout`-derived bound. */\nconst DEFAULT_STDIN_TIMEOUT_MS = 30_000;\n\nexport interface ReadPipedStdinOptions {\n\t/**\n\t * Upper bound (ms) on total time spent waiting for a slow / hung upstream pipe.\n\t * Callers pass the resolved `--timeout` so the limit is user-tunable; falls back to\n\t * DEFAULT_STDIN_TIMEOUT_MS when omitted.\n\t */\n\ttimeoutMs?: number;\n\t/** Injectable clock for tests; defaults to `Date.now`. */\n\tnow?: () => number;\n}\n\n/**\n * Synchronously drain piped stdin to a string, tolerating EAGAIN.\n *\n * A single `readFileSync(0)` / `readSync` can throw EAGAIN when stdin is a non-blocking\n * pipe whose upstream process is still producing (e.g. `wport jobs search ... | jq ... |\n * wport jobs view - --batch`): the fd has no data *right now* but isn't at EOF either.\n * Naively letting that throw makes the documented pipe workflow fail intermittently. We\n * retry on EAGAIN with a ~1ms synchronous sleep (Atomics.wait, to avoid a hot spin) and\n * stop on a zero-byte read or EOF.\n *\n * If the upstream neither produces data nor closes the pipe, the EAGAIN retry would spin\n * forever (the global `--timeout` only bounds HTTP, not stdin). We cap the total wait with\n * `timeoutMs` and surface a timeout as InvalidArgumentError rather than hanging silently.\n */\nexport function readPipedStdin(label: string, options: ReadPipedStdinOptions = {}): string {\n\tconst timeoutMs = options.timeoutMs ?? DEFAULT_STDIN_TIMEOUT_MS;\n\tconst now = options.now ?? Date.now;\n\tensureStdinPiped(label);\n\tconst chunks: Buffer[] = [];\n\tconst buf = Buffer.alloc(64 * 1024);\n\tconst sleeper = new Int32Array(new SharedArrayBuffer(4));\n\tconst deadline = now() + timeoutMs;\n\tfor (;;) {\n\t\tlet bytesRead: number;\n\t\ttry {\n\t\t\tbytesRead = readSync(0, buf, 0, buf.length, null);\n\t\t} catch (err) {\n\t\t\tconst code = (err as NodeJS.ErrnoException).code;\n\t\t\tif (code === 'EAGAIN') {\n\t\t\t\tif (now() > deadline) {\n\t\t\t\t\tthrow new InvalidArgumentError(`${label}: timed out after ${timeoutMs}ms waiting for piped stdin`);\n\t\t\t\t}\n\t\t\t\tAtomics.wait(sleeper, 0, 0, 1); // sleep ~1ms, then retry\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (code === 'EOF') break;\n\t\t\tthrow new InvalidArgumentError(`${label}: failed to read stdin: ${(err as Error).message}`);\n\t\t}\n\t\tif (bytesRead === 0) break;\n\t\tchunks.push(Buffer.from(buf.subarray(0, bytesRead)));\n\t}\n\treturn Buffer.concat(chunks).toString('utf8');\n}\n\nexport interface PromptSecretOptions {\n\t/** 注入點,預設用本檔的 readPipedStdin(測試可換 fake)。 */\n\treadPiped?: (label: string) => string;\n}\n\n/**\n * 互動式讀 secret:TTY 時 raw mode 隱藏輸入(不 echo、不進 shell history);\n * 非 TTY(CI / pipe)時直接讀整個 stdin。供 `wport enterprise login` 用。\n */\nexport function promptSecret(promptText: string, options: PromptSecretOptions = {}): Promise<string> {\n\tconst readPiped = options.readPiped ?? ((label: string) => readPipedStdin(label));\n\tif (!process.stdin.isTTY || !process.stdout.isTTY) {\n\t\treturn Promise.resolve(readPiped('login').trim());\n\t}\n\tprocess.stdout.write(promptText);\n\treturn new Promise<string>((resolve, reject) => {\n\t\tconst stdin = process.stdin;\n\t\tstdin.setRawMode(true);\n\t\tstdin.resume();\n\t\tstdin.setEncoding('utf8');\n\t\tlet buf = '';\n\t\tconst cleanup = (): void => {\n\t\t\tstdin.setRawMode(false);\n\t\t\tstdin.pause();\n\t\t\tstdin.off('data', onData);\n\t\t};\n\t\tconst onData = (chunk: string): void => {\n\t\t\tfor (const ch of chunk) {\n\t\t\t\tif (ch === '\u0003') {\n\t\t\t\t\t// Ctrl-C\n\t\t\t\t\tcleanup();\n\t\t\t\t\tprocess.stdout.write('\\n');\n\t\t\t\t\treject(new CliError('Aborted', ExitCode.InvalidArgument));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (ch === '\\r' || ch === '\\n') {\n\t\t\t\t\tcleanup();\n\t\t\t\t\tprocess.stdout.write('\\n');\n\t\t\t\t\tresolve(buf.trim());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (ch === '' || ch === '\\b') {\n\t\t\t\t\tbuf = buf.slice(0, -1);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tbuf += ch;\n\t\t\t}\n\t\t};\n\t\tstdin.on('data', onData);\n\t});\n}\n","import type { Command } from 'commander';\nimport { createApiClient, throwForHttpStatus, unwrapDataResponse, type ApiClient } from '../../lib/api-client';\nimport { resolveContext } from '../../lib/global-opts';\nimport { CliError, ExitCode } from '../../lib/errors';\nimport { dim, printJson, printNdjsonLine, sanitizeForTerminal, sanitizeForTerminalMultiline } from '../../lib/output';\nimport { getPath, parseFieldsList, pickPaths } from '../../lib/path-utils';\nimport { mapWithConcurrency } from '../../lib/concurrency';\nimport { readPipedStdin } from '../../lib/io-helpers';\nimport pc from 'picocolors';\n\ninterface ViewFlags {\n\tfield?: string;\n\tfields?: string;\n\tbatch?: boolean;\n\tconcurrency?: number;\n}\n\nconst DEFAULT_BATCH_CONCURRENCY = 5;\nconst MAX_BATCH_CONCURRENCY = 20;\n\n/** One ND-JSON record emitted per enc_id in --batch mode. */\ninterface BatchResult {\n\tenc_id: string;\n\tok: boolean;\n\tdata?: unknown;\n\terror?: string;\n}\n\n/** Projects a fetched job down to whatever --field / --fields asked for (or the whole job). */\ntype JobProjector = (job: JobView) => unknown;\n\n/**\n * JobViewVM 是嵌套結構(見 src/modules/jobs/view-models/job-view.vm.ts)。\n * 這裡只列我們顯示時會碰到的欄位,其他欄位走 [k: string]: unknown 保留。\n */\ninterface JobView {\n\tcompany_header_info?: {\n\t\tcompany_name?: string;\n\t\tcompany_icon_url?: string;\n\t\tenc_company_id?: string;\n\t\t[k: string]: unknown;\n\t};\n\tjob_description?: string;\n\tjob_info?: {\n\t\tjob_title?: string;\n\t\tarea_display?: string;\n\t\tsalary_display?: string;\n\t\tjob_feature_display?: string | null;\n\t\texperience_display?: string | null;\n\t\t[k: string]: unknown;\n\t};\n\tjob_information?: Record<string, unknown>;\n\trecruitment_conditions?: Record<string, unknown>;\n\tbenefits?: Record<string, unknown>;\n\tabout_company?: Record<string, unknown> | null;\n\tapplication_method?: Record<string, unknown> | null;\n\tstructured_data?: Record<string, unknown> | null;\n\t[k: string]: unknown;\n}\n\nexport function registerJobsView(parent: Command): void {\n\tparent\n\t\t.command('view <enc_id>')\n\t\t.description('View a single job. Pass \"-\" to read enc_id from stdin.')\n\t\t.option('--field <path>', 'output a single field as a raw value (dotted paths, e.g. job_info.job_title)')\n\t\t.option(\n\t\t\t'--fields <list>',\n\t\t\t'output selected fields as a JSON object (comma-separated dotted paths, e.g. job_info.job_title,company_header_info.company_name)'\n\t\t)\n\t\t.option(\n\t\t\t'--batch',\n\t\t\t'read newline-separated enc_ids from stdin and emit one ND-JSON record per job (requires \"-\" as the enc_id arg)'\n\t\t)\n\t\t.option(\n\t\t\t'--concurrency <n>',\n\t\t\t`max parallel requests in --batch mode (default ${DEFAULT_BATCH_CONCURRENCY}, max ${MAX_BATCH_CONCURRENCY})`,\n\t\t\t(v) => Number(v)\n\t\t)\n\t\t.action(async (encIdArg: string, flags: ViewFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tif (flags.field && flags.fields) {\n\t\t\t\tthrow new CliError(\n\t\t\t\t\t'Use either --field (single raw value) or --fields (JSON object), not both',\n\t\t\t\t\tExitCode.InvalidArgument\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst client = createApiClient({\n\t\t\t\tbaseUrl: ctx.baseUrl,\n\t\t\t\tlocale: ctx.locale,\n\t\t\t\ttimeoutMs: ctx.timeoutMs,\n\t\t\t});\n\n\t\t\tif (flags.batch) {\n\t\t\t\tawait runBatchView(encIdArg, flags, client, ctx.timeoutMs);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst encId = encIdArg === '-' ? readPipedStdin('view -', { timeoutMs: ctx.timeoutMs }).trim() : encIdArg;\n\t\t\tif (!encId) {\n\t\t\t\tthrow new CliError('enc_id is required', ExitCode.InvalidArgument);\n\t\t\t}\n\n\t\t\tconst { data, error, response } = await client.GET('/api/jobs/{encId}/view', {\n\t\t\t\tparams: { path: { encId } },\n\t\t\t});\n\t\t\tif (!response.ok) throwForHttpStatus(response.status, error);\n\n\t\t\tconst job = unwrapDataResponse<JobView>(data);\n\n\t\t\tif (flags.fields) {\n\t\t\t\t// Multi-field projection → JSON object keyed by dotted path. printJson uses\n\t\t\t\t// JSON.stringify, which escapes control chars to \\uXXXX, so employer-controlled\n\t\t\t\t// string values are safe without extra sanitization (same rationale as the\n\t\t\t\t// json branch below).\n\t\t\t\tprintJson(pickPaths(job, parseFieldsList(flags.fields)));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (flags.field) {\n\t\t\t\tconst v = getPath(job, flags.field);\n\t\t\t\tif (v === undefined) {\n\t\t\t\t\tthrow new CliError(`Field \"${flags.field}\" not present in response`, ExitCode.InvalidArgument);\n\t\t\t\t}\n\t\t\t\t// String values are employer-controlled and printed raw — sanitize. The multiline\n\t\t\t\t// variant preserves \\n (e.g. when --field selects job_description) but still strips\n\t\t\t\t// every other control char including \\r and \\t. JSON.stringify already escapes\n\t\t\t\t// < 0x20 to \\uXXXX so non-string paths don't need extra handling.\n\t\t\t\tconst out = typeof v === 'string' ? sanitizeForTerminalMultiline(v) : JSON.stringify(v, null, 2);\n\t\t\t\tprocess.stdout.write(out + '\\n');\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (ctx.format === 'json') {\n\t\t\t\tprintJson(job);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\trenderJobTable(job, encId, ctx.color);\n\t\t});\n}\n\n/**\n * --batch orchestration: read enc_ids off stdin, fetch each (bounded parallelism),\n * and stream one ND-JSON record per job. One failed enc_id becomes an `ok:false` line\n * rather than aborting the whole run. Output order matches input order.\n */\nasync function runBatchView(encIdArg: string, flags: ViewFlags, client: ApiClient, timeoutMs: number): Promise<void> {\n\tif (encIdArg !== '-') {\n\t\tthrow new CliError('--batch reads enc_ids from stdin; pass \"-\" as the enc_id argument', ExitCode.InvalidArgument);\n\t}\n\tconst encIds = parseBatchInput(readPipedStdin('view - --batch', { timeoutMs }));\n\tif (encIds.length === 0) {\n\t\tthrow new CliError('No enc_ids found on stdin', ExitCode.InvalidArgument);\n\t}\n\tconst concurrency = resolveBatchConcurrency(flags.concurrency);\n\tconst project = makeBatchProjector(flags);\n\tconst results = await runBatch(encIds, concurrency, (encId) => fetchJob(client, encId), project);\n\tfor (const record of results) printNdjsonLine(record);\n}\n\nasync function fetchJob(client: ApiClient, encId: string): Promise<JobView> {\n\tconst { data, error, response } = await client.GET('/api/jobs/{encId}/view', {\n\t\tparams: { path: { encId } },\n\t});\n\tif (!response.ok) throwForHttpStatus(response.status, error);\n\treturn unwrapDataResponse<JobView>(data);\n}\n\n/**\n * Pure batch driver (injectable fetcher) so the success/failure-mix behaviour is\n * testable without a live API. Each unit is wrapped so a rejected fetch turns into an\n * `ok:false` record instead of rejecting the whole batch.\n */\nasync function runBatch(\n\tencIds: string[],\n\tconcurrency: number,\n\tfetchOne: (encId: string) => Promise<JobView>,\n\tproject: JobProjector\n): Promise<BatchResult[]> {\n\treturn mapWithConcurrency(encIds, concurrency, async (encId): Promise<BatchResult> => {\n\t\ttry {\n\t\t\tconst job = await fetchOne(encId);\n\t\t\treturn { enc_id: encId, ok: true, data: project(job) };\n\t\t} catch (err) {\n\t\t\treturn { enc_id: encId, ok: false, error: err instanceof Error ? err.message : String(err) };\n\t\t}\n\t});\n}\n\nfunction makeBatchProjector(flags: ViewFlags): JobProjector {\n\tif (flags.fields) {\n\t\tconst paths = parseFieldsList(flags.fields);\n\t\treturn (job) => pickPaths(job, paths);\n\t}\n\tif (flags.field) {\n\t\tconst path = flags.field;\n\t\t// Missing path → null (keeps every record's shape stable across the batch),\n\t\t// unlike single-view --field which errors on a missing path.\n\t\treturn (job) => getPath(job, path) ?? null;\n\t}\n\treturn (job) => job;\n}\n\nfunction parseBatchInput(raw: string): string[] {\n\treturn raw\n\t\t.split('\\n')\n\t\t.map((s) => s.trim())\n\t\t.filter(Boolean);\n}\n\nfunction resolveBatchConcurrency(raw: number | undefined): number {\n\tconst n = raw ?? DEFAULT_BATCH_CONCURRENCY;\n\tif (!Number.isInteger(n) || n < 1 || n > MAX_BATCH_CONCURRENCY) {\n\t\tthrow new CliError(\n\t\t\t`--concurrency must be an integer between 1 and ${MAX_BATCH_CONCURRENCY} (got ${raw})`,\n\t\t\tExitCode.InvalidArgument\n\t\t);\n\t}\n\treturn n;\n}\n\nfunction renderJobTable(job: JobView, encId: string, color: boolean): void {\n\tconst label = (s: string) => (color ? pc.bold(s) : s);\n\t// All API string values are employer-controlled; sanitize before printing to defend\n\t// against terminal escape injection (clear screen, OSC 8 phishing hyperlinks, etc.).\n\tconst s = (v: string | undefined | null): string => (v ? sanitizeForTerminal(v) : '');\n\tconst info = job.job_info ?? {};\n\tconst company = job.company_header_info ?? {};\n\n\tconst lines: string[] = [];\n\tif (info.job_title) lines.push(`${label('Title:')} ${s(info.job_title)}`);\n\tif (company.company_name) lines.push(`${label('Company:')} ${s(company.company_name)}`);\n\tif (info.area_display) lines.push(`${label('Location:')} ${s(info.area_display)}`);\n\tif (info.salary_display) lines.push(`${label('Salary:')} ${s(info.salary_display)}`);\n\tif (info.job_feature_display) lines.push(`${label('Type:')} ${s(info.job_feature_display)}`);\n\tif (info.experience_display) lines.push(`${label('Experience:')} ${s(info.experience_display)}`);\n\t// encId comes from the CLI arg (user-provided) but pass through sanitize as a defense-in-depth.\n\tlines.push(dim(`enc_id: ${s(encId)}`, color));\n\tif (company.enc_company_id) lines.push(dim(`enc_company_id: ${s(company.enc_company_id)}`, color));\n\tprocess.stdout.write(lines.join('\\n') + '\\n');\n\n\tif (job.job_description) {\n\t\tprocess.stdout.write('\\n' + label('Description') + '\\n');\n\t\t// stripHtml only removes tags; sanitize afterwards in case the rich-text source\n\t\t// embedded raw escape sequences inside text nodes. Use the multiline variant so the\n\t\t// description's paragraph breaks (\\n) are preserved while \\r / \\t / other controls\n\t\t// are still stripped.\n\t\tprocess.stdout.write(renderDescription(job.job_description) + '\\n');\n\t}\n\n\tprocess.stdout.write(\n\t\t'\\n' +\n\t\t\tdim(\n\t\t\t\t'Tip: use --output json (or --field <dotted.path>, e.g. --field job_info.salary_display) for scripting.',\n\t\t\t\tcolor\n\t\t\t) +\n\t\t\t'\\n'\n\t);\n}\n\n/**\n * 後端 job_description 可能含 HTML(rich text);CLI 終端機列印時剝掉 tag。\n * 不做完整 HTML 解析 —— 只把 tag 拿掉、& 實體做最常見的還原。\n */\nfunction stripHtml(s: string): string {\n\treturn s\n\t\t.replace(/<\\/?(p|br|div|li|h[1-6])[^>]*>/gi, '\\n')\n\t\t.replace(/<[^>]+>/g, '')\n\t\t.replace(/&nbsp;/g, ' ')\n\t\t.replace(/&amp;/g, '&')\n\t\t.replace(/&lt;/g, '<')\n\t\t.replace(/&gt;/g, '>')\n\t\t.replace(/&quot;/g, '\"')\n\t\t.replace(/&#39;/g, \"'\")\n\t\t.replace(/\\n{3,}/g, '\\n\\n')\n\t\t.trim();\n}\n\nfunction renderDescription(html: string): string {\n\treturn sanitizeForTerminalMultiline(stripHtml(html));\n}\n\n// Internal helpers exposed for tests. Not part of the public CLI API.\nexport const __test__ = {\n\tstripHtml,\n\tgetPath,\n\trenderDescription,\n\trunBatch,\n\tmakeBatchProjector,\n\tparseBatchInput,\n\tresolveBatchConcurrency,\n};\n","import type { Command } from 'commander';\nimport { registerJobsSearch } from './search';\nimport { registerJobsView } from './view';\n\nexport function registerJobsCommand(program: Command): void {\n\tconst jobs = program.command('jobs').description('Search and view public job listings');\n\tregisterJobsSearch(jobs);\n\tregisterJobsView(jobs);\n}\n","import type { Command } from 'commander';\nimport { isConfigKey, isDeprecatedConfigKey, loadConfig, saveConfig, validateAndCoerce } from '../../lib/config-store';\nimport { CliError, ExitCode } from '../../lib/errors';\nimport { API_BASE_ENV_VAR } from '../../lib/global-opts';\n\nexport function registerConfigSet(parent: Command): void {\n\tparent\n\t\t.command('set <key> <value>')\n\t\t.description('Set a config value. Keys: locale, output, timeout_ms')\n\t\t.action((key: string, value: string) => {\n\t\t\tif (isDeprecatedConfigKey(key)) {\n\t\t\t\tthrow new CliError(\n\t\t\t\t\t`Config key \"${key}\" was removed in 0.1.2. Set the ${API_BASE_ENV_VAR} env var ` +\n\t\t\t\t\t\t`(or use the --api flag) instead.`,\n\t\t\t\t\tExitCode.InvalidArgument\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!isConfigKey(key)) {\n\t\t\t\tthrow new CliError(\n\t\t\t\t\t`Unknown config key \"${key}\". Allowed: locale, output, timeout_ms`,\n\t\t\t\t\tExitCode.InvalidArgument\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst coerced = validateAndCoerce(key, value);\n\t\t\tconst config = loadConfig();\n\t\t\t// Object.assign 形式避免 TS 5.5 在 `config[key] = coerced` 上推不出\n\t\t\t// ConfigValueMap[K]→CliConfig[K] 的對應;validateAndCoerce 已 generic、型別正確。\n\t\t\tObject.assign(config, { [key]: coerced });\n\t\t\tsaveConfig(config);\n\t\t\tprocess.stdout.write(`Set ${key} = ${JSON.stringify(coerced)}\\n`);\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { isConfigKey, loadConfig } from '../../lib/config-store';\nimport { CliError, ExitCode } from '../../lib/errors';\nimport { printJson } from '../../lib/output';\n\nexport function registerConfigGet(parent: Command): void {\n\tparent\n\t\t.command('get [key]')\n\t\t.description('Print config value(s). With no key, prints the whole config as JSON.')\n\t\t.action((key: string | undefined) => {\n\t\t\tconst config = loadConfig();\n\t\t\tif (key === undefined) {\n\t\t\t\tprintJson(config);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!isConfigKey(key)) {\n\t\t\t\tthrow new CliError(\n\t\t\t\t\t`Unknown config key \"${key}\". Allowed: locale, output, timeout_ms`,\n\t\t\t\t\tExitCode.InvalidArgument\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst value = (config as Record<string, unknown>)[key];\n\t\t\tif (value === undefined) {\n\t\t\t\tprocess.stdout.write('\\n');\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tprocess.stdout.write((typeof value === 'string' ? value : JSON.stringify(value)) + '\\n');\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { getConfigPath } from '../../lib/config-store';\n\nexport function registerConfigPath(parent: Command): void {\n\tparent\n\t\t.command('path')\n\t\t.description('Print the path to the config file (regardless of whether it exists)')\n\t\t.action(() => {\n\t\t\tprocess.stdout.write(getConfigPath() + '\\n');\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { existsSync, unlinkSync } from 'node:fs';\nimport { getConfigPath } from '../../lib/config-store';\nimport { InvalidArgumentError } from '../../lib/errors';\n\nexport function registerConfigReset(parent: Command): void {\n\tparent\n\t\t.command('reset')\n\t\t.description('Delete the config file')\n\t\t.option('-f, --force', 'skip the confirmation prompt')\n\t\t.action(async (opts: { force?: boolean }) => {\n\t\t\tconst path = getConfigPath();\n\t\t\tif (!existsSync(path)) {\n\t\t\t\tprocess.stdout.write('No config file to delete.\\n');\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!opts.force) {\n\t\t\t\tconst ok = await promptYesNo(`Delete config at ${path}? [y/N] `);\n\t\t\t\tif (!ok) {\n\t\t\t\t\tprocess.stdout.write('Aborted.\\n');\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tunlinkSync(path);\n\t\t\t} catch (err) {\n\t\t\t\tconst e = err as NodeJS.ErrnoException;\n\t\t\t\tif (e.code === 'ENOENT') {\n\t\t\t\t\t// Race with another process: someone deleted it between exists & unlink.\n\t\t\t\t\tprocess.stdout.write('No config file to delete (already removed).\\n');\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthrow new InvalidArgumentError(`Failed to delete config at ${path}: ${e.message}`);\n\t\t\t}\n\t\t\tprocess.stdout.write(`Deleted ${path}\\n`);\n\t\t});\n}\n\nfunction promptYesNo(prompt: string): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tprocess.stdout.write(prompt);\n\t\tlet buf = '';\n\t\tprocess.stdin.setEncoding('utf8');\n\t\tconst onData = (chunk: string) => {\n\t\t\tbuf += chunk;\n\t\t\tconst nl = buf.indexOf('\\n');\n\t\t\tif (nl >= 0) {\n\t\t\t\tcleanup();\n\t\t\t\tconst answer = buf.slice(0, nl).trim().toLowerCase();\n\t\t\t\tresolve(answer === 'y' || answer === 'yes');\n\t\t\t}\n\t\t};\n\t\tconst onEnd = () => {\n\t\t\tcleanup();\n\t\t\tprocess.stdout.write('\\n(no input — aborting)\\n');\n\t\t\tresolve(false);\n\t\t};\n\t\tconst cleanup = () => {\n\t\t\tprocess.stdin.removeListener('data', onData);\n\t\t\tprocess.stdin.removeListener('end', onEnd);\n\t\t\tprocess.stdin.pause();\n\t\t};\n\t\tprocess.stdin.on('data', onData);\n\t\tprocess.stdin.on('end', onEnd);\n\t});\n}\n","import type { Command } from 'commander';\nimport { registerConfigSet } from './set';\nimport { registerConfigGet } from './get';\nimport { registerConfigPath } from './path';\nimport { registerConfigReset } from './reset';\n\nexport function registerConfigCommand(program: Command): void {\n\tconst config = program.command('config').description('Manage CLI configuration');\n\tregisterConfigSet(config);\n\tregisterConfigGet(config);\n\tregisterConfigPath(config);\n\tregisterConfigReset(config);\n}\n","import type { Command } from 'commander';\nimport { existsSync } from 'node:fs';\nimport { createApiClient } from '../lib/api-client';\nimport { resolveContext } from '../lib/global-opts';\nimport { getConfigPath } from '../lib/config-store';\nimport { ExitCode } from '../lib/errors';\n\n/**\n * Query params the server accepts syntactically but silently ignores — surfacing them\n * here is the whole point: an agent reading `wport doctor` learns not to try to control\n * sort order (it can't), instead of discovering it the hard way via wrong-but-no-error\n * results. The CLI deliberately doesn't expose flags for these.\n */\nexport const SILENT_IGNORED_PARAMS = ['orderBy', 'order'];\n\nexport function registerDoctorCommand(program: Command): void {\n\tprogram\n\t\t.command('doctor')\n\t\t.description(\n\t\t\t'Diagnose CLI setup: resolved config, server reachability, schema fingerprint, and known server quirks.'\n\t\t)\n\t\t.action(async (_opts: unknown, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tconst line = (s = '') => process.stdout.write(s + '\\n');\n\n\t\t\tline(`wport-cli ${__CLI_VERSION__}`);\n\t\t\tline(` bundled schema fingerprint: ${__SCHEMA_HASH__}`);\n\t\t\tline('');\n\n\t\t\tline('Resolved configuration:');\n\t\t\tline(` API base URL: ${ctx.baseUrl}`);\n\t\t\tline(` locale: ${ctx.locale}`);\n\t\t\tline(` timeout: ${ctx.timeoutMs}ms`);\n\t\t\tconst cfgPath = getConfigPath();\n\t\t\tline(` config file: ${cfgPath}${existsSync(cfgPath) ? '' : ' (not present)'}`);\n\t\t\tline('');\n\n\t\t\tline('Server connectivity:');\n\t\t\tconst reachable = await probeServer(ctx, line);\n\t\t\tline('');\n\n\t\t\tline('Known server behaviours (read this before scripting an agent):');\n\t\t\tline(\n\t\t\t\t` • Sort is server-controlled. These query params are silently ignored: ${SILENT_IGNORED_PARAMS.join(', ')}.`\n\t\t\t);\n\t\t\tline(' • jobs search sorts by publish date, or by relevance when --keyword is set.');\n\t\t\tline(' • jobs view --batch caps parallelism (default 5, max 20) to stay friendly to the API.');\n\t\t\tline('');\n\n\t\t\tline('Schema drift:');\n\t\t\tline(' The fingerprint above identifies the OpenAPI contract this CLI was built against.');\n\t\t\tline(' Automated drift detection needs a server-side schema-version endpoint, which is');\n\t\t\tline(' not available yet — for now, compare fingerprints manually after a server release. [TODO]');\n\n\t\t\tif (!reachable) process.exit(ExitCode.ServerOrNetworkError);\n\t\t});\n}\n\n/**\n * Lightweight reachability probe: a 1-result search hits the real public endpoint\n * without pulling a meaningful payload. A network-layer failure is a hard \"unreachable\"\n * (caller exits non-zero); an HTTP response of any status still proves the host is\n * reachable, so we report the status but don't treat it as a connectivity failure.\n */\nasync function probeServer(\n\tctx: { baseUrl: string; locale: string; timeoutMs: number },\n\tline: (s?: string) => void\n): Promise<boolean> {\n\ttry {\n\t\tconst client = createApiClient({ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs });\n\t\tconst { response } = await client.GET('/api/jobs/search', { params: { query: { pageSize: 1 } } });\n\t\tif (response.ok) {\n\t\t\tline(` ✓ reachable (HTTP ${response.status})`);\n\t\t} else {\n\t\t\tline(` ! reachable, but server responded HTTP ${response.status}`);\n\t\t}\n\t\treturn true;\n\t} catch (err) {\n\t\tline(` ✗ unreachable: ${err instanceof Error ? err.message : String(err)}`);\n\t\treturn false;\n\t}\n}\n","import { buildUserAgent, extractErrorMessage, fetchWithTimeout, throwForHttpStatus } from './api-client';\nimport { CliError, ExitCode } from './errors';\nimport { printWarn } from './output';\n\nexport interface EnterpriseRequestOptions {\n\tbaseUrl: string; // resolveContext 產出,已去尾斜線\n\tlocale: string;\n\ttimeoutMs: number;\n\tapiKey: string;\n}\n\nexport interface EnterpriseGetResult {\n\tbody: unknown;\n\theaders: Headers;\n}\n\nconst ENTERPRISE_PREFIX = '/api/v1/enterprise';\n\n/**\n * 企業 API 唯讀 GET。手寫 wrapper 而非 openapi-fetch:openapi.yaml 缺 read 端點\n * response schema(spec §4.1 修訂),typed client 在這裡沒有可生成的型別。\n * timeout / 網路錯誤分類複用 api-client.fetchWithTimeout。\n */\nexport async function enterpriseGet(\n\topts: EnterpriseRequestOptions,\n\tpath: string,\n\tquery?: Record<string, string | number | undefined>\n): Promise<EnterpriseGetResult> {\n\tconst url = new URL(`${opts.baseUrl}${ENTERPRISE_PREFIX}${path}`);\n\tfor (const [k, v] of Object.entries(query ?? {})) {\n\t\tif (v !== undefined) url.searchParams.set(k, String(v));\n\t}\n\tconst request = new Request(url, {\n\t\theaders: {\n\t\t\tAuthorization: `Bearer ${opts.apiKey}`,\n\t\t\t'Accept-Language': opts.locale,\n\t\t\t'User-Agent': buildUserAgent(),\n\t\t\tAccept: 'application/json',\n\t\t},\n\t});\n\tconst res = await fetchWithTimeout(request, opts.timeoutMs);\n\tconst body: unknown = await res.json().catch(() => null);\n\tif (!res.ok) throwEnterpriseHttpError(res.status, body);\n\twarnIfRateLimitLow(res.headers);\n\treturn { body, headers: res.headers };\n}\n\n/** spec §5:401/403 加情境提示;其他狀態走共用 throwForHttpStatus。 */\nfunction throwEnterpriseHttpError(status: number, body: unknown): never {\n\tconst base = extractErrorMessage(body) ?? `HTTP ${status}`;\n\tif (status === 401) {\n\t\tthrow new CliError(\n\t\t\t`${base}\\nKey may have been revoked — run \\`wport enterprise login\\` to re-authenticate.`,\n\t\t\tExitCode.ServerClientError\n\t\t);\n\t}\n\tif (status === 403) {\n\t\tthrow new CliError(\n\t\t\t`${base}\\nIf your company account has been suspended, please contact support.`,\n\t\t\tExitCode.ServerClientError\n\t\t);\n\t}\n\tthrowForHttpStatus(status, body);\n}\n\n/** spec §5:剩餘配額 <10% 時 stderr 提醒(不阻斷;stderr 不污染 json stdout)。 */\nfunction warnIfRateLimitLow(headers: Headers): void {\n\tconst remaining = Number(headers.get('x-ratelimit-remaining'));\n\tconst limit = Number(headers.get('x-ratelimit-limit'));\n\tif (Number.isFinite(remaining) && Number.isFinite(limit) && limit > 0 && remaining / limit < 0.1) {\n\t\tprintWarn(`Rate limit nearly exhausted: ${remaining}/${limit} requests remaining this window.`, false);\n\t}\n}\n","import {\n\texistsSync,\n\treadFileSync,\n\tmkdirSync,\n\topenSync,\n\twriteSync,\n\tcloseSync,\n\tchmodSync,\n\trenameSync,\n\tunlinkSync,\n} from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport envPaths from 'env-paths';\nimport { CliError, ExitCode } from './errors';\nimport { printWarn } from './output';\n\nexport const API_KEY_ENV_VAR = 'WPORT_API_KEY';\nexport const KEY_PREFIX = 'wpk_live_';\n// Server contract(spec §2.1):wpk_live_ + 32 高熵字元。下限驗證擋手滑貼半截;\n// 不驗上限——server 端才是 key 有效性的唯一權威。\nconst KEY_MIN_LENGTH = KEY_PREFIX.length + 32;\n\nexport interface Credentials {\n\tapi_key: string;\n\tcompany_name: string;\n\tkey_last4: string;\n\tsaved_at: string;\n}\n\nexport type KeySource = 'flag' | 'env' | 'file';\n\nexport interface ResolvedKey {\n\tkey: string;\n\tsource: KeySource;\n}\n\nconst paths = envPaths('wport', { suffix: '' });\n\nexport function getCredentialsPath(): string {\n\treturn join(paths.config, 'credentials.json');\n}\n\nexport function isValidKeyFormat(key: string): boolean {\n\treturn key.startsWith(KEY_PREFIX) && key.length >= KEY_MIN_LENGTH && !/\\s/.test(key);\n}\n\n/** 任何輸出顯示 key 一律走這裡:只露末四碼。 */\nexport function maskKey(key: string): string {\n\treturn `${KEY_PREFIX}••••${key.slice(-4)}`;\n}\n\nexport function loadCredentials(): Credentials | null {\n\tconst path = getCredentialsPath();\n\tif (!existsSync(path)) return null;\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(readFileSync(path, 'utf8'));\n\t} catch (err) {\n\t\tthrow new CliError(\n\t\t\t`Failed to read credentials at ${path}: ${(err as Error).message}. Run \"wport enterprise login\" to recreate it.`,\n\t\t\tExitCode.ConfigCorrupt\n\t\t);\n\t}\n\tif (!parsed || typeof parsed !== 'object' || typeof (parsed as Record<string, unknown>).api_key !== 'string') {\n\t\tthrow new CliError(\n\t\t\t`Credentials file at ${path} is malformed. Run \"wport enterprise login\" to recreate it.`,\n\t\t\tExitCode.ConfigCorrupt\n\t\t);\n\t}\n\tconst raw = parsed as Record<string, unknown>;\n\tconst apiKey = raw.api_key as string;\n\treturn {\n\t\tapi_key: apiKey,\n\t\tcompany_name: typeof raw.company_name === 'string' ? raw.company_name : '',\n\t\tkey_last4: typeof raw.key_last4 === 'string' ? raw.key_last4 : apiKey.slice(-4),\n\t\tsaved_at: typeof raw.saved_at === 'string' ? raw.saved_at : '',\n\t};\n}\n\n// Atomic write 模式照抄 config-store.saveConfig:tmpfile(0o600) → rename。\n// credentials 比 config 更敏感,所以分檔(config 可能被使用者貼進 issue 除錯)。\nexport function saveCredentials(creds: Credentials): void {\n\tconst path = getCredentialsPath();\n\tmkdirSync(dirname(path), { recursive: true });\n\tconst tmpPath = `${path}.tmp.${process.pid}.${Date.now()}`;\n\tconst fd = openSync(tmpPath, 'w', 0o600);\n\ttry {\n\t\twriteSync(fd, JSON.stringify(creds, null, 2) + '\\n');\n\t} catch (err) {\n\t\tcloseSync(fd);\n\t\ttry {\n\t\t\tunlinkSync(tmpPath);\n\t\t} catch {\n\t\t\t/* best effort cleanup */\n\t\t}\n\t\tthrow err;\n\t}\n\tcloseSync(fd);\n\tif (process.platform !== 'win32') {\n\t\ttry {\n\t\t\tchmodSync(tmpPath, 0o600);\n\t\t} catch (err) {\n\t\t\tprintWarn(\n\t\t\t\t`Failed to chmod 0600 on credentials tmpfile: ${(err as Error).message}. ` +\n\t\t\t\t\t'Other users on this system may be able to read your API key.',\n\t\t\t\tfalse\n\t\t\t);\n\t\t}\n\t}\n\trenameSync(tmpPath, path);\n}\n\nexport function deleteCredentials(): boolean {\n\tconst path = getCredentialsPath();\n\tif (!existsSync(path)) return false;\n\tunlinkSync(path);\n\treturn true;\n}\n\n/**\n * Key 解析 precedence:--api-key flag > WPORT_API_KEY env > credentials.json。\n * 與 base url 解析(--api > WPORT_API_BASE > default,global-opts.ts)同款心智模型。\n */\nexport function resolveApiKey(flagValue?: string): ResolvedKey {\n\tif (flagValue !== undefined) {\n\t\tensureFormat(flagValue, '--api-key');\n\t\treturn { key: flagValue, source: 'flag' };\n\t}\n\tconst fromEnv = process.env[API_KEY_ENV_VAR]?.trim();\n\tif (fromEnv) {\n\t\tensureFormat(fromEnv, `${API_KEY_ENV_VAR} env var`);\n\t\treturn { key: fromEnv, source: 'env' };\n\t}\n\tconst creds = loadCredentials();\n\tif (creds) return { key: creds.api_key, source: 'file' };\n\tthrow new CliError(\n\t\t`No API key found. Run \"wport enterprise login\" or set the ${API_KEY_ENV_VAR} env var.`,\n\t\tExitCode.InvalidArgument\n\t);\n}\n\nfunction ensureFormat(key: string, source: string): void {\n\tif (!isValidKeyFormat(key)) {\n\t\t// 錯誤訊息絕不 echo key 原文(可能是手滑貼進來的其他 secret)\n\t\tthrow new CliError(`API key from ${source} is not a valid ${KEY_PREFIX} key`, ExitCode.InvalidArgument);\n\t}\n}\n","import type { Command } from 'commander';\nimport { resolveContext } from '../../lib/global-opts';\nimport { CliError, ExitCode } from '../../lib/errors';\nimport { promptSecret } from '../../lib/io-helpers';\nimport { enterpriseGet } from '../../lib/enterprise-client';\nimport {\n\tAPI_KEY_ENV_VAR,\n\tKEY_PREFIX,\n\tgetCredentialsPath,\n\tisValidKeyFormat,\n\tmaskKey,\n\tsaveCredentials,\n} from '../../lib/credentials-store';\nimport { printWarn } from '../../lib/output';\n\nexport interface LoginContext {\n\tbaseUrl: string;\n\tlocale: string;\n\ttimeoutMs: number;\n}\n\n/** login 核心(與 commander 解耦供測試):驗格式 → 打 API 驗 key → 存檔。 */\nexport async function performLogin(ctx: LoginContext, key: string): Promise<void> {\n\tif (!isValidKeyFormat(key)) {\n\t\t// 不 echo 輸入原文 —— 可能是手滑貼進來的其他 secret\n\t\tthrow new CliError(\n\t\t\t`That does not look like a valid ${KEY_PREFIX} key. Nothing was saved.`,\n\t\t\tExitCode.InvalidArgument\n\t\t);\n\t}\n\t// 任何非 200 都由 enterpriseGet 丟出(401/403 → CliError 附情境提示),不落檔。\n\t// 打 GET /me 兼作 key 驗證與公司名取得(取代舊的 /jobs?pageSize=1 驗證)。\n\tconst { body } = await enterpriseGet({ ...ctx, apiKey: key }, '/me');\n\tsaveCredentials({\n\t\tapi_key: key,\n\t\tcompany_name: extractCompanyName(body),\n\t\tkey_last4: key.slice(-4),\n\t\tsaved_at: new Date().toISOString(),\n\t});\n}\n\n/**\n * 從 GET /me 的 DataResponse({ data: { company: { enc_id, name } } })取公司名。\n * shape 非預期時回空字串 —— login 已驗 key(200),不該因回應格式小變動而失敗;\n * company_name 缺失只讓 whoami 退回顯示 (unknown)。\n */\nfunction extractCompanyName(body: unknown): string {\n\tif (body && typeof body === 'object') {\n\t\tconst data = (body as { data?: unknown }).data;\n\t\tif (data && typeof data === 'object') {\n\t\t\tconst company = (data as { company?: unknown }).company;\n\t\t\tif (company && typeof company === 'object') {\n\t\t\t\tconst name = (company as { name?: unknown }).name;\n\t\t\t\tif (typeof name === 'string') return name;\n\t\t\t}\n\t\t}\n\t}\n\treturn '';\n}\n\nexport function registerEnterpriseLogin(parent: Command): void {\n\tparent\n\t\t.command('login')\n\t\t.description('Validate and save an enterprise API key (prompts securely; pipe stdin in CI)')\n\t\t.action(async (_flags: unknown, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tconst key = await promptSecret(`Paste your API key (${KEY_PREFIX}...): `);\n\t\t\tawait performLogin({ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs }, key);\n\t\t\tprocess.stdout.write(`Logged in. Key ${maskKey(key)} saved to ${getCredentialsPath()}\\n`);\n\t\t\tif (process.platform === 'win32') {\n\t\t\t\tprintWarn(\n\t\t\t\t\t`On Windows file permissions are best-effort. For stricter isolation, prefer the ${API_KEY_ENV_VAR} env var.`,\n\t\t\t\t\tctx.color\n\t\t\t\t);\n\t\t\t}\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { deleteCredentials, getCredentialsPath } from '../../lib/credentials-store';\n\nexport function registerEnterpriseLogout(parent: Command): void {\n\tparent\n\t\t.command('logout')\n\t\t.description('Delete the saved enterprise API key')\n\t\t.action(() => {\n\t\t\tconst deleted = deleteCredentials();\n\t\t\tprocess.stdout.write(\n\t\t\t\tdeleted ? `Logged out. Removed ${getCredentialsPath()}\\n` : 'No saved credentials to remove.\\n'\n\t\t\t);\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { loadCredentials, maskKey, resolveApiKey } from '../../lib/credentials-store';\n\ninterface WhoamiGlobals {\n\tapiKey?: string;\n}\n\nexport function registerEnterpriseWhoami(parent: Command): void {\n\tparent\n\t\t.command('whoami')\n\t\t.description('Show which enterprise key is in effect (offline; reads local state only)')\n\t\t.action((_flags: unknown, command: Command) => {\n\t\t\tconst globals = command.optsWithGlobals() as WhoamiGlobals;\n\t\t\tconst resolved = resolveApiKey(globals.apiKey);\n\t\t\tconst creds = resolved.source === 'file' ? loadCredentials() : null;\n\t\t\tconst lines = [\n\t\t\t\t`key: ${maskKey(resolved.key)}`,\n\t\t\t\t`source: ${resolved.source}`,\n\t\t\t\t`company: ${creds?.company_name || '(unknown)'}`,\n\t\t\t];\n\t\t\tif (creds?.saved_at) lines.push(`saved: ${creds.saved_at}`);\n\t\t\tprocess.stdout.write(lines.join('\\n') + '\\n');\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { asPaginatedBody } from '../../../lib/api-client';\nimport { enterpriseGet } from '../../../lib/enterprise-client';\nimport { resolveApiKey } from '../../../lib/credentials-store';\nimport { resolveContext } from '../../../lib/global-opts';\nimport { CliError, ExitCode } from '../../../lib/errors';\nimport { dim, printJson, printTable } from '../../../lib/output';\nimport { parseFieldsList, pickPaths } from '../../../lib/path-utils';\n\ninterface ListFlags {\n\tpage?: number;\n\tpageSize?: number;\n\tkeyword?: string;\n\tstatus?: string;\n\tfields?: string;\n\tminimal?: boolean;\n}\n\n/**\n * Server 契約(EnterpriseJobsQueryDto.status: number,0=未刊登,1=已刊登)。\n * openapi.yaml 寫的 active|inactive|deleted 是 drift,送字串會 400 —— 一律走這個映射。\n */\nconst STATUS_MAP: Record<string, number> = { published: 1, unpublished: 0 };\n\nconst MINIMAL_LIST_FIELDS = ['enc_id', 'job_title', 'status', 'updated_at'];\n\n/** 欄位對齊 server EnterpriseJobVm(enterprise-job.vm.ts)。 */\ninterface EnterpriseJobItem {\n\tenc_id?: string;\n\tjob_title?: string | null;\n\tcode?: string | null;\n\tstatus?: number;\n\tcreated_at?: string | null;\n\tupdated_at?: string | null;\n\t[k: string]: unknown;\n}\n\nfunction mapStatusFlag(raw: string | undefined): number | undefined {\n\tif (raw === undefined) return undefined;\n\tif (raw in STATUS_MAP) return STATUS_MAP[raw];\n\tthrow new CliError(\n\t\t`Invalid --status \"${raw}\". Allowed: ${Object.keys(STATUS_MAP).join(', ')}`,\n\t\tExitCode.InvalidArgument\n\t);\n}\n\nexport function formatStatus(status: number | undefined): string {\n\tif (status === 1) return 'published';\n\tif (status === 0) return 'unpublished';\n\treturn status === undefined ? '' : String(status);\n}\n\nfunction formatDate(value: string | null | undefined): string {\n\treturn value ? String(value).slice(0, 10) : '';\n}\n\nexport function registerEnterpriseJobsList(parent: Command): void {\n\tparent\n\t\t.command('list')\n\t\t.description('List your company job postings')\n\t\t.option('--page <n>', 'page number (server: currentPage, default 1)', (v) => Number(v))\n\t\t.option('--page-size <n>', 'items per page (server: pageSize, default 10, max 100)', (v) => Number(v))\n\t\t.option('--keyword <kw>', 'filter by job title keyword')\n\t\t.option('--status <state>', 'filter by status: published | unpublished')\n\t\t.option('--fields <list>', 'output selected fields as JSON (comma-separated dotted paths)')\n\t\t.option('--minimal', `output only ${MINIMAL_LIST_FIELDS.join(',')} as JSON`)\n\t\t.action(async (flags: ListFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tif (flags.fields && flags.minimal) {\n\t\t\t\tthrow new CliError('Use either --fields or --minimal, not both', ExitCode.InvalidArgument);\n\t\t\t}\n\t\t\tconst globals = command.optsWithGlobals() as { apiKey?: string };\n\t\t\tconst { key } = resolveApiKey(globals.apiKey);\n\t\t\tconst { body } = await enterpriseGet(\n\t\t\t\t{ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey: key },\n\t\t\t\t'/jobs',\n\t\t\t\t{\n\t\t\t\t\tcurrentPage: flags.page,\n\t\t\t\t\tpageSize: flags.pageSize,\n\t\t\t\t\tkeyword: flags.keyword,\n\t\t\t\t\tstatus: mapStatusFlag(flags.status),\n\t\t\t\t}\n\t\t\t);\n\t\t\tconst paged = asPaginatedBody<EnterpriseJobItem>(body);\n\n\t\t\tconst projection = flags.minimal ? MINIMAL_LIST_FIELDS : flags.fields ? parseFieldsList(flags.fields) : undefined;\n\t\t\tif (projection || ctx.format === 'json') {\n\t\t\t\tprintJson(projection ? { ...paged, data: paged.data.map((row) => pickPaths(row, projection)) } : paged);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tprintTable(\n\t\t\t\tpaged.data,\n\t\t\t\t[\n\t\t\t\t\t{ header: 'ENC_ID', value: (r) => (r.enc_id ?? '').slice(0, 14) },\n\t\t\t\t\t{ header: 'TITLE', value: (r) => r.job_title ?? '', maxWidth: 36 },\n\t\t\t\t\t{ header: 'STATUS', value: (r) => formatStatus(r.status) },\n\t\t\t\t\t{ header: 'CODE', value: (r) => r.code ?? '', maxWidth: 16 },\n\t\t\t\t\t{ header: 'UPDATED', value: (r) => formatDate(r.updated_at), maxWidth: 12 },\n\t\t\t\t],\n\t\t\t\tctx.color\n\t\t\t);\n\t\t\tconst head = `Showing page ${paged.currentPage}/${paged.totalPages} (${paged.data.length} of ${paged.totalCount} jobs).`;\n\t\t\tconst hint =\n\t\t\t\tpaged.totalPages > paged.currentPage\n\t\t\t\t\t? ` Next: wport enterprise jobs list --page ${paged.currentPage + 1}`\n\t\t\t\t\t: '';\n\t\t\tprocess.stdout.write(dim(head + hint, ctx.color) + '\\n');\n\t\t});\n}\n\n// Internal helpers exposed for tests. Not part of the public CLI API.\nexport const __test__ = { mapStatusFlag, formatStatus };\n","import type { Command } from 'commander';\nimport { unwrapDataResponse } from '../../../lib/api-client';\nimport { enterpriseGet } from '../../../lib/enterprise-client';\nimport { resolveApiKey } from '../../../lib/credentials-store';\nimport { resolveContext } from '../../../lib/global-opts';\nimport { CliError, ExitCode } from '../../../lib/errors';\nimport { printJson, sanitizeForTerminal } from '../../../lib/output';\nimport { parseFieldsList, pickPaths } from '../../../lib/path-utils';\nimport { formatStatus } from './list';\n\ninterface ViewFlags {\n\tfields?: string;\n}\n\ninterface EnterpriseJobDetail {\n\tenc_id?: string;\n\tjob_title?: string | null;\n\tcode?: string | null;\n\tstatus?: number;\n\tcreated_at?: string | null;\n\tupdated_at?: string | null;\n\t[k: string]: unknown;\n}\n\nconst DETAIL_FIELDS: ReadonlyArray<string> = ['enc_id', 'job_title', 'code', 'status', 'created_at', 'updated_at'];\n\nfunction renderDetailLines(job: EnterpriseJobDetail): string[] {\n\tconst pad = Math.max(...DETAIL_FIELDS.map((f) => f.length)) + 1;\n\tconst lines: string[] = [];\n\tfor (const field of DETAIL_FIELDS) {\n\t\tconst raw = job[field];\n\t\tif (raw === null || raw === undefined) continue;\n\t\tconst value = field === 'status' ? formatStatus(raw as number) : String(raw);\n\t\tlines.push(`${(field + ':').padEnd(pad + 1)}${sanitizeForTerminal(value)}`);\n\t}\n\treturn lines;\n}\n\nexport function registerEnterpriseJobsView(parent: Command): void {\n\tparent\n\t\t.command('view <enc_id>')\n\t\t.description('View one of your company job postings')\n\t\t.option('--fields <list>', 'output selected fields as JSON (comma-separated dotted paths)')\n\t\t.action(async (encId: string, flags: ViewFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tif (!encId.trim()) {\n\t\t\t\tthrow new CliError('enc_id must not be empty', ExitCode.InvalidArgument);\n\t\t\t}\n\t\t\tconst globals = command.optsWithGlobals() as { apiKey?: string };\n\t\t\tconst { key } = resolveApiKey(globals.apiKey);\n\t\t\tconst { body } = await enterpriseGet(\n\t\t\t\t{ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey: key },\n\t\t\t\t`/jobs/${encodeURIComponent(encId.trim())}`\n\t\t\t);\n\t\t\tconst job = unwrapDataResponse<EnterpriseJobDetail>(body);\n\n\t\t\tif (flags.fields) {\n\t\t\t\tprintJson(pickPaths(job, parseFieldsList(flags.fields)));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (ctx.format === 'json') {\n\t\t\t\tprintJson(job);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tprocess.stdout.write(renderDetailLines(job).join('\\n') + '\\n');\n\t\t});\n}\n\n// Internal helpers exposed for tests. Not part of the public CLI API.\nexport const __test__ = { renderDetailLines };\n","import type { Command } from 'commander';\nimport { registerEnterpriseJobsList } from './list';\nimport { registerEnterpriseJobsView } from './view';\n\nexport function registerEnterpriseJobsCommand(parent: Command): void {\n\tconst jobs = parent.command('jobs').description('List and view your company job postings');\n\tregisterEnterpriseJobsList(jobs);\n\tregisterEnterpriseJobsView(jobs);\n}\n","import type { Command } from 'commander';\nimport { registerEnterpriseLogin } from './login';\nimport { registerEnterpriseLogout } from './logout';\nimport { registerEnterpriseWhoami } from './whoami';\nimport { registerEnterpriseJobsCommand } from './jobs';\n\nexport function registerEnterpriseCommand(program: Command): void {\n\tconst enterprise = program\n\t\t.command('enterprise')\n\t\t.description('Manage your company job postings with an enterprise API key')\n\t\t.option('--api-key <key>', 'one-off API key (prefer \"wport enterprise login\" or the WPORT_API_KEY env var)');\n\tregisterEnterpriseLogin(enterprise);\n\tregisterEnterpriseLogout(enterprise);\n\tregisterEnterpriseWhoami(enterprise);\n\tregisterEnterpriseJobsCommand(enterprise);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uBAAwB;;;ACAjB,IAAM,WAAW;AAAA,EACvB,SAAS;AAAA,EACT,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,sBAAsB;AAAA,EACtB,eAAe;AAChB;AAIO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAC1B;AAAA,EAET,YAAY,SAAiB,UAAyB;AACrD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EACjB;AACD;AAEO,IAAM,uBAAN,cAAmC,SAAS;AAAA,EAClD,YAAY,SAAiB;AAC5B,UAAM,SAAS,SAAS,eAAe;AACvC,SAAK,OAAO;AAAA,EACb;AACD;AAEO,IAAM,wBAAN,cAAoC,SAAS;AAAA,EAC1C;AAAA,EACA;AAAA,EACT,YAAY,SAAiB,QAAgB,MAAe;AAC3D,UAAM,SAAS,SAAS,iBAAiB;AACzC,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACb;AACD;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BAAyB,UAAU;AACnC,2BAAyB,UAAU;AACnC,gCAA8B,UAAU;AACzC;;;A1BPA,IAAM,UAAU,IAAI,yBAAQ;AAE5B,QACE,KAAK,OAAO,EACZ,YAAY,8EAAyE,EACrF,QAAQ,SAAiB,iBAAiB,wBAAwB,EAClE,OAAO,mBAAmB,+DAA+D,EACzF,OAAO,eAAe,uBAAuB,EAC7C,OAAO,kBAAkB,6BAA6B,EACtD,OAAO,cAAc,sBAAsB,EAC3C,OAAO,kBAAkB,gCAAgC,CAAC,MAAM,OAAO,CAAC,CAAC;AAE3E,oBAAoB,OAAO;AAC3B,sBAAsB,OAAO;AAC7B,sBAAsB,OAAO;AAC7B,0BAA0B,OAAO;AAEjC,QAAQ,aAAa;AAErB,QACE,WAAW,QAAQ,IAAI,EACvB,KAAK,MAAM,QAAQ,KAAK,SAAS,OAAO,CAAC,EACzC,MAAM,CAAC,QAAiB,oBAAoB,GAAG,CAAC;AAElD,SAAS,oBAAoB,KAAqB;AACjD,QAAM,QAAQ,eAAe,KAAK;AAGlC,MAAI,OAAO,OAAO,QAAQ,YAAY,UAAU,KAAK;AACpD,UAAM,eAAe;AACrB,QAAI,aAAa,SAAS,6BAA6B,aAAa,SAAS,qBAAqB;AACjG,cAAQ,KAAK,SAAS,OAAO;AAAA,IAC9B;AAGA,QAAI,aAAa,QAAS,YAAW,aAAa,SAAS,KAAK;AAChE,YAAQ,KAAK,SAAS,eAAe;AAAA,EACtC;AAEA,MAAI,WAAW,GAAG,GAAG;AACpB,eAAW,IAAI,SAAS,KAAK;AAC7B,YAAQ,KAAK,IAAI,QAAQ;AAAA,EAC1B;AAEA,QAAM,kBAAkB,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AACvE,aAAW,iBAAiB,KAAK;AACjC,UAAQ,KAAK,SAAS,oBAAoB;AAC3C;","names":["pc","Table","import_node_fs","createClient","envPaths","paths","import_node_fs","import_picocolors","paths","s","pc","program","import_node_fs","program","import_node_fs","program","import_node_fs","import_node_path","import_env_paths","paths","envPaths","formatDate","program"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/lib/errors.ts","../src/lib/output.ts","../src/commands/jobs/search.ts","../src/lib/api-client.ts","../src/lib/config-store.ts","../src/lib/global-opts.ts","../src/lib/path-utils.ts","../src/lib/concurrency.ts","../src/lib/io-helpers.ts","../src/commands/jobs/view.ts","../src/commands/jobs/index.ts","../src/commands/config/set.ts","../src/commands/config/get.ts","../src/commands/config/path.ts","../src/commands/config/reset.ts","../src/commands/config/index.ts","../src/commands/doctor.ts","../src/lib/enterprise-client.ts","../src/lib/credentials-store.ts","../src/commands/enterprise/login.ts","../src/commands/enterprise/logout.ts","../src/commands/enterprise/whoami.ts","../src/commands/enterprise/jobs/list.ts","../src/commands/enterprise/jobs/view.ts","../src/commands/enterprise/jobs/create.ts","../src/commands/enterprise/jobs/update.ts","../src/commands/enterprise/jobs/write-shared.ts","../src/commands/enterprise/jobs/lifecycle.ts","../src/commands/enterprise/jobs/batch.ts","../src/commands/enterprise/jobs/index.ts","../src/commands/enterprise/keys/list.ts","../src/commands/enterprise/keys/rotate.ts","../src/commands/enterprise/keys/index.ts","../src/commands/enterprise/index.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { isCliError, ExitCode } from './lib/errors';\nimport { isColorEnabled, printError } from './lib/output';\nimport { registerJobsCommand } from './commands/jobs';\nimport { registerConfigCommand } from './commands/config';\nimport { registerDoctorCommand } from './commands/doctor';\nimport { registerEnterpriseCommand } from './commands/enterprise';\n\nconst program = new Command();\n\nprogram\n\t.name('wport')\n\t.description('wport CLI — terminal interface to the W101 Talent Search Hub public API')\n\t.version(__CLI_VERSION__, '-v, --version', 'output the CLI version')\n\t.option('--lang <locale>', 'Accept-Language locale: zh-TW | en-US | vi-VN | th-TH | id-ID')\n\t.option('--api <url>', 'override API base URL')\n\t.option('--output <fmt>', 'output format: table | json')\n\t.option('--no-color', 'disable color output')\n\t.option('--timeout <ms>', 'HTTP timeout in milliseconds', (v) => Number(v));\n\nregisterJobsCommand(program);\nregisterConfigCommand(program);\nregisterDoctorCommand(program);\nregisterEnterpriseCommand(program);\n\nprogram.exitOverride();\n\nprogram\n\t.parseAsync(process.argv)\n\t.then(() => process.exit(ExitCode.Success))\n\t.catch((err: unknown) => handleTopLevelError(err));\n\nfunction handleTopLevelError(err: unknown): never {\n\tconst color = isColorEnabled(false);\n\n\t// commander throws CommanderError on its own validation paths (help, version, unknown option).\n\tif (err && typeof err === 'object' && 'code' in err) {\n\t\tconst commanderErr = err as { code?: string; exitCode?: number; message?: string };\n\t\tif (commanderErr.code === 'commander.helpDisplayed' || commanderErr.code === 'commander.version') {\n\t\t\tprocess.exit(ExitCode.Success);\n\t\t}\n\t\t// commander 自己的 exitCode 多半是 1,不在 CLI 的 contract(0/2/3/4/5)內。\n\t\t// 任何 parsing / usage 失敗都當 InvalidArgument(2)。\n\t\tif (commanderErr.message) printError(commanderErr.message, color);\n\t\tprocess.exit(ExitCode.InvalidArgument);\n\t}\n\n\tif (isCliError(err)) {\n\t\tprintError(err.message, color);\n\t\tprocess.exit(err.exitCode);\n\t}\n\n\tconst fallbackMessage = err instanceof Error ? err.message : String(err);\n\tprintError(fallbackMessage, color);\n\tprocess.exit(ExitCode.ServerOrNetworkError);\n}\n","export const ExitCode = {\n\tSuccess: 0,\n\tInvalidArgument: 2,\n\tServerClientError: 3,\n\tServerOrNetworkError: 4,\n\tConfigCorrupt: 5,\n} as const;\n\nexport type ExitCodeValue = (typeof ExitCode)[keyof typeof ExitCode];\n\nexport class CliError extends Error {\n\treadonly exitCode: ExitCodeValue;\n\n\tconstructor(message: string, exitCode: ExitCodeValue) {\n\t\tsuper(message);\n\t\tthis.name = 'CliError';\n\t\tthis.exitCode = exitCode;\n\t}\n}\n\nexport class InvalidArgumentError extends CliError {\n\tconstructor(message: string) {\n\t\tsuper(message, ExitCode.InvalidArgument);\n\t\tthis.name = 'InvalidArgumentError';\n\t}\n}\n\nexport class ServerClientHttpError extends CliError {\n\treadonly status: number;\n\treadonly body: unknown;\n\tconstructor(message: string, status: number, body: unknown) {\n\t\tsuper(message, ExitCode.ServerClientError);\n\t\tthis.name = 'ServerClientHttpError';\n\t\tthis.status = status;\n\t\tthis.body = body;\n\t}\n}\n\nexport class NetworkError extends CliError {\n\treadonly cause?: unknown;\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(message, ExitCode.ServerOrNetworkError);\n\t\tthis.name = 'NetworkError';\n\t\tthis.cause = cause;\n\t}\n}\n\nexport class ConfigCorruptError extends CliError {\n\treadonly path?: string;\n\tconstructor(message: string, path?: string) {\n\t\tsuper(message, ExitCode.ConfigCorrupt);\n\t\tthis.name = 'ConfigCorruptError';\n\t\tthis.path = path;\n\t}\n}\n\nexport function isCliError(err: unknown): err is CliError {\n\treturn err instanceof CliError;\n}\n","import Table from 'cli-table3';\nimport pc from 'picocolors';\nimport { CliError, ExitCode } from './errors';\n\nexport type OutputFormat = 'table' | 'json';\n\n/**\n * 把 untrusted 字串(從 API 回來的 employer-controlled 內容)變成終端機可安全列印的形式。\n *\n * 防的是 terminal escape injection:\n * - CSI / OSC / DCS 等 ESC 開頭序列(清螢幕、改 title、移動游標、假超連結 phishing 等)\n * - 其他 C0 / C1 控制字元(保留 \\t \\n \\r 三個合法格式化字元)\n *\n * JSON 模式不需要 sanitize:JSON.stringify 會把 < 0x20 的字元 escape 成 \\uXXXX。\n * 只有 table / plain-text 印到 stdout/stderr 的字串走這個 helper。\n *\n * 用 new RegExp(string) 建構,所有控制字元以 \\\\uNNNN 形式撰寫,避免 source 內含 literal 控制字元。\n */\nconst ANSI_ESCAPE_SEQUENCE = new RegExp(\n\t[\n\t\t// CSI: ESC [ params intermediates final\n\t\t'\\\\u001B\\\\[[0-?]*[ -/]*[@-~]',\n\t\t// OSC: ESC ] payload (any chars except BEL/ESC) terminated by BEL or ESC \\\n\t\t'\\\\u001B\\\\][^\\\\u0007\\\\u001B]*(?:\\\\u0007|\\\\u001B\\\\\\\\)',\n\t\t// Two-char escapes: ESC + Fe final byte (0x40-0x5F = @ A B ... Z [ \\ ] ^ _).\n\t\t// 涵蓋 CSI([) / OSC(]) / DCS(P) / SOS(X) / ST(\\\\) / PM(^) / APC(_) intro。\n\t\t// CSI / OSC regex 在前面 OR-分支會先匹配對應序列;這條兜底所有未覆蓋 Fe。\n\t\t'\\\\u001B[@-_]',\n\t].join('|'),\n\t'g'\n);\n\n// 單行用:剝所有 C0(含 \\t \\n \\r)、DEL、C1。table cell、label-prefixed 標題、\n// error / warning 訊息都走這條 —— 即便 ANSI 已剝乾淨,殘留 \\r 仍能把 cursor 拉回\n// 行首蓋掉前面的內容;\\n 會打斷表格排版、可能偽造後續 row;\\t 寬度可變、\n// 搞壞 cli-table3 對齊。\nconst CONTROL_CHARS_STRICT = new RegExp('[\\\\u0000-\\\\u001F\\\\u007F\\\\u0080-\\\\u009F]', 'g');\n\n// 多行用:內部先把 \\r\\n / lone \\r 正規化成 \\n,再剝其他 C0(含 \\t)、DEL、C1。\n// 保留 \\n 作為合法段落分隔。Caller 不需事先做正規化。\nconst CONTROL_CHARS_MULTILINE = new RegExp('[\\\\u0000-\\\\u0009\\\\u000B-\\\\u001F\\\\u007F\\\\u0080-\\\\u009F]', 'g');\n\nexport function sanitizeForTerminal(s: string): string {\n\treturn s.replace(ANSI_ESCAPE_SEQUENCE, '').replace(CONTROL_CHARS_STRICT, '');\n}\n\nexport function sanitizeForTerminalMultiline(s: string): string {\n\treturn s.replace(ANSI_ESCAPE_SEQUENCE, '').replace(/\\r\\n?/g, '\\n').replace(CONTROL_CHARS_MULTILINE, '');\n}\n\nexport function resolveOutputFormat(explicit: string | undefined): OutputFormat {\n\tif (explicit === undefined) {\n\t\treturn process.stdout.isTTY ? 'table' : 'json';\n\t}\n\tif (explicit !== 'json' && explicit !== 'table') {\n\t\tthrow new CliError(`Invalid --output \"${explicit}\". Allowed: table, json`, ExitCode.InvalidArgument);\n\t}\n\treturn explicit;\n}\n\nexport function isColorEnabled(noColor: boolean | undefined): boolean {\n\tif (noColor === true) return false;\n\tif (process.env.NO_COLOR) return false;\n\treturn process.stdout.isTTY ?? false;\n}\n\nexport function printJson(value: unknown): void {\n\tprocess.stdout.write(JSON.stringify(value, null, 2) + '\\n');\n}\n\n/**\n * Emit one newline-delimited JSON record (ND-JSON). JSON.stringify escapes control\n * chars to \\uXXXX, so employer-controlled string values are terminal-safe without\n * extra sanitization. Used by `jobs view --batch`, where one record per line keeps a\n * single failure isolated to its own line.\n */\nexport function printNdjsonLine(value: unknown): void {\n\tprocess.stdout.write(JSON.stringify(value) + '\\n');\n}\n\nexport interface TableColumn<T> {\n\theader: string;\n\tvalue: (row: T) => string;\n\tmaxWidth?: number;\n}\n\nexport function printTable<T>(rows: T[], columns: TableColumn<T>[], color: boolean): void {\n\tif (rows.length === 0) {\n\t\tprocess.stdout.write(color ? pc.dim('(no results)\\n') : '(no results)\\n');\n\t\treturn;\n\t}\n\tconst table = new Table({\n\t\thead: columns.map((c) => (color ? pc.bold(c.header) : c.header)),\n\t\tstyle: { head: [], border: [] },\n\t\tcolWidths: columns.map((c) => c.maxWidth ?? null),\n\t\twordWrap: true,\n\t});\n\tfor (const row of rows) {\n\t\t// 每個 cell 的字串都過 sanitize:防 employer-controlled 內容(title/company/area/salary 等)注入 escape。\n\t\ttable.push(columns.map((c) => sanitizeForTerminal(c.value(row))));\n\t}\n\tprocess.stdout.write(table.toString() + '\\n');\n}\n\nexport function printError(message: string, color: boolean): void {\n\tconst prefix = color ? pc.red('Error:') : 'Error:';\n\t// Server 回的 error message 也視為 untrusted,sanitize。\n\tprocess.stderr.write(`${prefix} ${sanitizeForTerminal(message)}\\n`);\n}\n\nexport function printWarn(message: string, color: boolean): void {\n\tconst prefix = color ? pc.yellow('Warning:') : 'Warning:';\n\tprocess.stderr.write(`${prefix} ${sanitizeForTerminal(message)}\\n`);\n}\n\nexport function dim(text: string, color: boolean): string {\n\treturn color ? pc.dim(text) : text;\n}\n","import type { Command } from 'commander';\nimport { readFileSync } from 'node:fs';\nimport { asPaginatedBody, createApiClient, throwForHttpStatus } from '../../lib/api-client';\nimport { resolveContext } from '../../lib/global-opts';\nimport { CliError, ExitCode } from '../../lib/errors';\nimport { dim, printJson, printTable, printWarn } from '../../lib/output';\nimport { parseFieldsList, pickPaths } from '../../lib/path-utils';\nimport type { operations } from '../../generated/schema';\n\ninterface SearchFlags {\n\tkeyword?: string;\n\tlocation?: string[];\n\tcategory?: string[];\n\tpage?: number;\n\tpageSize?: number;\n\tjsonQuery?: string;\n\tfields?: string;\n\tminimal?: boolean;\n}\n\n/**\n * Compact field set for `--minimal` — the columns an agent almost always wants from a\n * search result, mirroring the table view minus the noise. Keeps `enc_id` first so the\n * output is directly pipeable into `jobs view -`.\n */\nconst MINIMAL_SEARCH_FIELDS = ['enc_id', 'title', 'company_name', 'area_display', 'salary_display'];\n\n/**\n * Query type derived from the generated OpenAPI schema for GET /api/jobs/search.\n * Adding a new field on the backend DTO + re-running gen:openapi will make this type\n * widen automatically; any flag we forget to map will surface as a TS error inside\n * buildQuery() instead of being silently dropped at runtime.\n */\ntype SearchQuery = NonNullable<operations['JobsController_searchJobs']['parameters']['query']>;\n\ninterface JobSearchItem {\n\tenc_id?: string;\n\tenc_company_id?: string;\n\tcompany_name?: string;\n\tcompany_logo_url?: string;\n\ttitle?: string;\n\tarea_display?: string;\n\tsalary_display?: string;\n\tsalary_currency_code?: string | null;\n\ttags?: string[];\n\tupdated_at?: string;\n\t[k: string]: unknown;\n}\n\nexport function registerJobsSearch(parent: Command): void {\n\tparent\n\t\t.command('search')\n\t\t.description(\n\t\t\t'Search public job listings. Sort is server-controlled (publish date, or relevance when --keyword is set); ' +\n\t\t\t\t'the orderBy / order query params are silently ignored, so this CLI intentionally exposes no sort flags. ' +\n\t\t\t\t'Run `wport doctor` for the full list of server quirks.'\n\t\t)\n\t\t.option('-k, --keyword <text>', 'keyword search (title / company name etc.)')\n\t\t.option('-l, --location <code...>', 'area code (repeatable, e.g. 6001001000)')\n\t\t.option('-c, --category <code...>', 'job classification code (repeatable)')\n\t\t.option('-p, --page <n>', 'page number (default 1)', (v) => Number(v))\n\t\t.option('-s, --page-size <n>', 'page size (default 10, max 100)', (v) => Number(v))\n\t\t.option('--json-query <file>', 'read full query body from JSON file (overrides other flags)')\n\t\t.option(\n\t\t\t'--fields <list>',\n\t\t\t'keep only these fields in each JSON result (comma-separated dotted paths, e.g. enc_id,title). JSON output only.'\n\t\t)\n\t\t.option('--minimal', `shorthand for --fields ${MINIMAL_SEARCH_FIELDS.join(',')}. JSON output only.`)\n\t\t.action(async (flags: SearchFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tconst fields = resolveSearchFields(flags);\n\t\t\tconst query = buildQuery(flags);\n\n\t\t\tconst client = createApiClient({\n\t\t\t\tbaseUrl: ctx.baseUrl,\n\t\t\t\tlocale: ctx.locale,\n\t\t\t\ttimeoutMs: ctx.timeoutMs,\n\t\t\t});\n\n\t\t\t// openapi-fetch consumes the response body itself; use `data` (success) or `error` (non-2xx).\n\t\t\tconst { data, error, response } = await client.GET('/api/jobs/search', {\n\t\t\t\tparams: { query },\n\t\t\t});\n\t\t\tif (!response.ok) throwForHttpStatus(response.status, error);\n\n\t\t\tconst paged = asPaginatedBody<JobSearchItem>(data);\n\n\t\t\tif (ctx.format === 'json') {\n\t\t\t\t// Field projection is client-side: it trims tokens the model has to read, not\n\t\t\t\t// bytes-on-the-wire (the server has no projection param). Pagination metadata is\n\t\t\t\t// preserved by spreading `paged` and only replacing `data`.\n\t\t\t\tconst body = fields ? { ...paged, data: paged.data.map((item) => pickPaths(item, fields)) } : paged;\n\t\t\t\tprintJson(body);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Table columns are fixed; --fields / --minimal are a JSON-only affordance. Warn\n\t\t\t// rather than silently ignore so the flag doesn't look broken.\n\t\t\tif (fields) {\n\t\t\t\tprintWarn('--fields / --minimal only affect JSON output; ignored for table. Use --output json.', ctx.color);\n\t\t\t}\n\n\t\t\tprintTable(\n\t\t\t\tpaged.data,\n\t\t\t\t[\n\t\t\t\t\t{ header: 'ENC_ID', value: (r) => truncate(r.enc_id ?? '', 14) },\n\t\t\t\t\t{ header: 'TITLE', value: (r) => r.title ?? '', maxWidth: 36 },\n\t\t\t\t\t{ header: 'COMPANY', value: (r) => r.company_name ?? '', maxWidth: 20 },\n\t\t\t\t\t{ header: 'LOCATION', value: (r) => r.area_display ?? '', maxWidth: 18 },\n\t\t\t\t\t{ header: 'SALARY', value: (r) => r.salary_display ?? '', maxWidth: 18 },\n\t\t\t\t\t{ header: 'UPDATED', value: (r) => formatDate(r.updated_at), maxWidth: 12 },\n\t\t\t\t],\n\t\t\t\tctx.color\n\t\t\t);\n\n\t\t\tconst head = `Showing page ${paged.currentPage}/${paged.totalPages} (${paged.data.length} of ${paged.totalCount} results).`;\n\t\t\tconst hint =\n\t\t\t\tpaged.totalPages > paged.currentPage ? ` Next: wport jobs search --page ${paged.currentPage + 1}` : '';\n\t\t\tprocess.stdout.write(dim(head + hint, ctx.color) + '\\n');\n\t\t});\n}\n\nfunction resolveSearchFields(flags: SearchFlags): string[] | undefined {\n\tif (flags.fields && flags.minimal) {\n\t\tthrow new CliError('Use either --fields or --minimal, not both', ExitCode.InvalidArgument);\n\t}\n\tif (flags.minimal) return [...MINIMAL_SEARCH_FIELDS];\n\tif (flags.fields) return parseFieldsList(flags.fields);\n\treturn undefined;\n}\n\nfunction buildQuery(flags: SearchFlags): SearchQuery {\n\tif (flags.jsonQuery) {\n\t\t// User-supplied JSON escape hatch — we trust the caller. Runtime validation will come\n\t\t// from the server side; this is the one spot the typed query is deliberately relaxed.\n\t\treturn readJsonQuery(flags.jsonQuery) as SearchQuery;\n\t}\n\tconst q: SearchQuery = {};\n\tif (flags.keyword) q.keyword = flags.keyword;\n\tif (flags.location?.length) q.area_codes = flags.location;\n\tif (flags.category?.length) q.job_classification_codes = flags.category;\n\tif (flags.page !== undefined) q.currentPage = flags.page;\n\tif (flags.pageSize !== undefined) q.pageSize = flags.pageSize;\n\treturn q;\n}\n\nfunction readJsonQuery(path: string): Record<string, unknown> {\n\tlet raw: string;\n\ttry {\n\t\traw = readFileSync(path, 'utf8');\n\t} catch (err) {\n\t\tthrow new CliError(`Cannot read --json-query file ${path}: ${(err as Error).message}`, ExitCode.InvalidArgument);\n\t}\n\ttry {\n\t\tconst parsed = JSON.parse(raw);\n\t\tif (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n\t\t\tthrow new Error(\n\t\t\t\tArray.isArray(parsed)\n\t\t\t\t\t? 'JSON root is an array; expected an object with query fields'\n\t\t\t\t\t: 'JSON root must be an object'\n\t\t\t);\n\t\t}\n\t\treturn parsed as Record<string, unknown>;\n\t} catch (err) {\n\t\tthrow new CliError(`Invalid JSON in ${path}: ${(err as Error).message}`, ExitCode.InvalidArgument);\n\t}\n}\n\nfunction truncate(s: string, max: number): string {\n\t// Fast path: UTF-16 code units (string.length) are always >= codepoint count,\n\t// so if byte-length already fits we don't need codepoint counting.\n\tif (s.length <= max) return s;\n\t// Array.from iterates by code-point, so surrogate pairs (emoji, supplementary\n\t// plane chars) aren't split mid-character. Doesn't handle grapheme clusters\n\t// (combining marks), but covers the common bilingual / emoji case.\n\tconst chars = Array.from(s);\n\tif (chars.length <= max) return s;\n\treturn chars.slice(0, max - 1).join('') + '…';\n}\n\nfunction formatDate(s: string | undefined): string {\n\tif (!s) return '';\n\tconst m = /^(\\d{4}-\\d{2}-\\d{2})/.exec(s);\n\treturn m ? m[1] : s;\n}\n","import createClient, { type Client } from 'openapi-fetch';\nimport type { paths } from '../generated/schema';\nimport { CliError, ExitCode, NetworkError, ServerClientHttpError } from './errors';\n\nexport interface ApiClientOptions {\n\tbaseUrl: string;\n\tlocale: string;\n\ttimeoutMs: number;\n}\n\nexport type ApiClient = Client<paths>;\n\n// Connection reuse for batch / repeated requests is handled by Node's built-in fetch\n// (undici): its global dispatcher pools keep-alive connections per origin, so multiple\n// requests from one process to the same host already reuse TCP/TLS without any setup\n// here. We deliberately don't ship a custom `undici` Agent — it'd add a runtime\n// dependency to nudge keepAliveTimeout (~4s default → longer) for near-zero gain on the\n// short-lived bursts `jobs view --batch` produces.\nexport function createApiClient(opts: ApiClientOptions): ApiClient {\n\treturn createClient<paths>({\n\t\tbaseUrl: opts.baseUrl,\n\t\theaders: {\n\t\t\t'Accept-Language': opts.locale,\n\t\t\t'User-Agent': buildUserAgent(),\n\t\t\tAccept: 'application/json',\n\t\t},\n\t\tfetch: (request: Request) => fetchWithTimeout(request, opts.timeoutMs),\n\t});\n}\n\nexport function fetchWithTimeout(request: Request, timeoutMs: number): Promise<Response> {\n\t// AbortSignal.timeout is available since Node 17.3 (engines requires >=18.17).\n\t// New Request inherits method/headers/body but overrides signal.\n\tconst timedRequest = new Request(request, { signal: AbortSignal.timeout(timeoutMs) });\n\treturn fetch(timedRequest).catch((err: unknown) => {\n\t\tif (isTimeoutAbort(err)) {\n\t\t\tthrow new NetworkError(`Request timed out after ${timeoutMs}ms`, err);\n\t\t}\n\t\t// TypeError: fetch failed → ECONNREFUSED / ENOTFOUND / TLS / proxy\n\t\tconst code = (err as { cause?: { code?: string } })?.cause?.code;\n\t\tconst detail = code ? code : ((err as Error)?.message ?? String(err));\n\t\tthrow new NetworkError(`Cannot reach upstream: ${detail}`, err);\n\t});\n}\n\nfunction isTimeoutAbort(err: unknown): boolean {\n\tif (err && typeof err === 'object' && 'name' in err) {\n\t\tconst name = (err as { name?: string }).name;\n\t\treturn name === 'TimeoutError' || name === 'AbortError';\n\t}\n\treturn false;\n}\n\nexport function buildUserAgent(): string {\n\treturn `wport-cli/${__CLI_VERSION__} (node ${process.version}; ${process.platform})`;\n}\n\n/**\n * W101 後端 `DataResponse<T>` wrapper:`{ success, statusCode, message, data: T }`。\n * 用於回傳「單筆」payload 的端點(例如 GET /api/jobs/:encId/view)。\n *\n * Shape 不符直接 throw CliError,不再 silent cast 把 wrapper 當 payload 回。\n *\n * 注意:`PaginatedResponse` 是另一種扁平結構\n * `{ success, statusCode, message, data: T[], currentPage, totalPages, pageSize, totalCount }`,\n * 不要對 paginated 回應用此函式 —— 會丟失 pagination 欄位。\n */\nexport function unwrapDataResponse<T>(body: unknown): T {\n\tif (body && typeof body === 'object' && 'success' in body && 'data' in body) {\n\t\treturn (body as { data: T }).data;\n\t}\n\tthrow new CliError('Unexpected response shape: missing { success, data } wrapper', ExitCode.ServerOrNetworkError);\n}\n\n/**\n * W101 後端 `DataResponse<T[]>`(非分頁、data 為陣列):`{ success, statusCode, message, data: T[] }`。\n * 用於回傳「陣列」但不帶分頁 metadata 的端點(例如 GET /keys)。\n *\n * 先剝 wrapper(複用 unwrapDataResponse)再驗 data 為陣列。契約漂移時丟清晰 CliError,\n * 對齊 asPaginatedBody 的守衛行為,避免 caller 的 .filter/.map 丟原生 TypeError。\n */\nexport function unwrapDataArray<T>(body: unknown): T[] {\n\tconst data = unwrapDataResponse<unknown>(body);\n\tif (!Array.isArray(data)) {\n\t\tthrow new CliError('Unexpected response shape: `data` is not an array', ExitCode.ServerOrNetworkError);\n\t}\n\treturn data as T[];\n}\n\n/**\n * W101 後端 `PaginatedResponse<T>` wrapper(扁平):\n * `{ success, statusCode, message, data: T[], currentPage, totalPages, pageSize, totalCount }`。\n * 直接 cast,不剝外層;callers 從 `.data` 拿 list,從頂層欄位拿分頁 metadata。\n */\nexport interface PaginatedBody<T> {\n\tsuccess?: boolean;\n\tstatusCode?: number;\n\tmessage?: unknown;\n\tdata: T[];\n\tcurrentPage: number;\n\ttotalPages: number;\n\tpageSize: number;\n\ttotalCount: number;\n}\n\nexport function asPaginatedBody<T>(body: unknown): PaginatedBody<T> {\n\tif (!body || typeof body !== 'object') {\n\t\tthrow new CliError('Unexpected response shape: not an object', ExitCode.ServerOrNetworkError);\n\t}\n\tconst b = body as Record<string, unknown>;\n\tif (!Array.isArray(b.data)) {\n\t\tthrow new CliError('Unexpected response shape: missing `data` array', ExitCode.ServerOrNetworkError);\n\t}\n\tfor (const key of ['currentPage', 'totalPages', 'pageSize', 'totalCount'] as const) {\n\t\tif (typeof b[key] !== 'number') {\n\t\t\tthrow new CliError(`Unexpected response shape: missing or non-numeric \"${key}\"`, ExitCode.ServerOrNetworkError);\n\t\t}\n\t}\n\treturn body as PaginatedBody<T>;\n}\n\nexport function throwForHttpStatus(status: number, body: unknown): never {\n\tconst message = extractErrorMessage(body) ?? `HTTP ${status}`;\n\tif (status >= 400 && status < 500) {\n\t\tthrow new ServerClientHttpError(message, status, body);\n\t}\n\tthrow new CliError(message, ExitCode.ServerOrNetworkError);\n}\n\nexport function extractErrorMessage(body: unknown): string | null {\n\tif (typeof body === 'string') return body;\n\tif (body && typeof body === 'object') {\n\t\tconst obj = body as Record<string, unknown>;\n\t\t// NestJS class-validator default: message: string[]\n\t\tif (Array.isArray(obj.message)) {\n\t\t\tconst parts = obj.message.filter((m): m is string => typeof m === 'string');\n\t\t\tif (parts.length > 0) return parts.join('; ');\n\t\t}\n\t\tif (typeof obj.message === 'string') return obj.message;\n\t\t// i18n object 或 nested → 印 JSON tail\n\t\tif (obj.message && typeof obj.message === 'object') {\n\t\t\ttry {\n\t\t\t\treturn JSON.stringify(obj.message);\n\t\t\t} catch {\n\t\t\t\t/* ignore */\n\t\t\t}\n\t\t}\n\t\t// Enterprise API error body 帶 i18n path(如 error.enterprise.invalid_api_key),\n\t\t// message 缺席時讓 path 當最後可讀資訊(guard 直接丟 { path } 的情境)。\n\t\tif (typeof obj.path === 'string') return obj.path;\n\t\tif (typeof obj.error === 'string') return obj.error;\n\t}\n\treturn null;\n}\n","import {\n\texistsSync,\n\tmkdirSync,\n\treadFileSync,\n\tchmodSync,\n\topenSync,\n\twriteSync,\n\tcloseSync,\n\trenameSync,\n\tunlinkSync,\n} from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport envPaths from 'env-paths';\nimport { CliError, ExitCode } from './errors';\nimport { printWarn } from './output';\n\nexport const ALLOWED_LOCALES = ['zh-TW', 'en-US', 'vi-VN', 'th-TH', 'id-ID'] as const;\nexport type Locale = (typeof ALLOWED_LOCALES)[number];\n\nexport const ALLOWED_OUTPUT = ['table', 'json'] as const;\nexport type OutputPref = (typeof ALLOWED_OUTPUT)[number];\n\nexport interface CliConfig {\n\tlocale?: Locale;\n\toutput?: OutputPref;\n\ttimeout_ms?: number;\n}\n\nconst CONFIG_KEYS = ['locale', 'output', 'timeout_ms'] as const satisfies readonly (keyof CliConfig)[];\nexport type ConfigKey = (typeof CONFIG_KEYS)[number];\n\n/**\n * Keys recognised in older configs but no longer settable. Detected in parseConfig\n * to surface a one-time deprecation warning instead of silently dropping (which the\n * forward-compat path would do for genuinely unknown keys).\n *\n * `api_base_url` was removed in 0.1.2 — SSRF / credential exfil surface for a flag\n * external users don't actually need. Override via `WPORT_API_BASE` env var or `--api`.\n */\nconst DEPRECATED_CONFIG_KEYS = ['api_base_url'] as const;\ntype DeprecatedConfigKey = (typeof DEPRECATED_CONFIG_KEYS)[number];\n\n/** Per-key migration hint shown when a deprecated key is found in an existing config. */\nconst DEPRECATED_KEY_HINTS: Record<DeprecatedConfigKey, string> = {\n\tapi_base_url: 'Set the WPORT_API_BASE env var (or use --api) instead.',\n};\n\n// One-time latch so repeated loadConfig() calls (e.g. inside a batch run) emit the\n// deprecation notice at most once per process rather than spamming stderr.\nlet deprecationWarned = false;\n\n/** Per-key value type. validateAndCoerce<K> returns ConfigValueMap[K]. */\ntype ConfigValueMap = {\n\tlocale: Locale;\n\toutput: OutputPref;\n\ttimeout_ms: number;\n};\n\nexport function isConfigKey(key: string): key is ConfigKey {\n\treturn (CONFIG_KEYS as readonly string[]).includes(key);\n}\n\nexport function isDeprecatedConfigKey(key: string): key is DeprecatedConfigKey {\n\treturn (DEPRECATED_CONFIG_KEYS as readonly string[]).includes(key);\n}\n\nconst paths = envPaths('wport', { suffix: '' });\n\nexport function getConfigPath(): string {\n\treturn join(paths.config, 'config.json');\n}\n\n/**\n * Trust boundary:把外部 JSON object 收成型別正確的 CliConfig。\n * 每個 key 都走 validateAndCoerce,不認識的 key 直接 drop(forward compatible,\n * 未來新版多塞了 key、舊 CLI 不會炸)。\n */\nexport function parseConfig(raw: unknown): CliConfig {\n\tif (!raw || typeof raw !== 'object' || Array.isArray(raw)) {\n\t\tthrow new CliError('Config must be a JSON object', ExitCode.ConfigCorrupt);\n\t}\n\tconst input = raw as Record<string, unknown>;\n\n\t// Surface (once per process) any deprecated key still sitting in the user's config.\n\t// We warn + drop rather than error, so upgrading from <=0.1.1 never hard-fails; the\n\t// key's actual replacement (WPORT_API_BASE) is resolved elsewhere in global-opts.\n\tif (!deprecationWarned) {\n\t\tfor (const dep of DEPRECATED_CONFIG_KEYS) {\n\t\t\tif (dep in input) {\n\t\t\t\tdeprecationWarned = true;\n\t\t\t\tprintWarn(`Config key \"${dep}\" was removed in 0.1.2 and is ignored. ${DEPRECATED_KEY_HINTS[dep]}`, false);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst out: CliConfig = {};\n\tfor (const key of CONFIG_KEYS) {\n\t\tif (!(key in input)) continue;\n\t\tconst value = input[key];\n\t\ttry {\n\t\t\tconst coerced = validateAndCoerce(key, String(value));\n\t\t\t// Object.assign 形式避免 TS 5.5 在 `out[key] = coerced` 上推不出 ConfigValueMap[K]→CliConfig[K]\n\t\t\t// 的對應關係。validateAndCoerce 已是 generic、型別正確;此處只是 indexed assignment 的繞道。\n\t\t\tObject.assign(out, { [key]: coerced });\n\t\t} catch (err) {\n\t\t\tif (err instanceof CliError) {\n\t\t\t\tthrow new CliError(`Config key \"${key}\" invalid: ${err.message}`, ExitCode.ConfigCorrupt);\n\t\t\t}\n\t\t\tthrow err;\n\t\t}\n\t}\n\treturn out;\n}\n\nexport function loadConfig(): CliConfig {\n\tconst path = getConfigPath();\n\tif (!existsSync(path)) return {};\n\tlet raw: string;\n\ttry {\n\t\traw = readFileSync(path, 'utf8');\n\t} catch (err) {\n\t\tthrow new CliError(`Failed to read config at ${path}: ${(err as Error).message}`, ExitCode.ConfigCorrupt);\n\t}\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch (err) {\n\t\tthrow new CliError(`Failed to parse JSON at ${path}: ${(err as Error).message}`, ExitCode.ConfigCorrupt);\n\t}\n\treturn parseConfig(parsed);\n}\n\nexport function saveConfig(config: CliConfig): void {\n\tconst path = getConfigPath();\n\tmkdirSync(dirname(path), { recursive: true });\n\n\t// Atomic: write tmpfile (mode 0o600 from open()) → rename to final path (POSIX atomic).\n\t// 即使中途 crash,舊檔仍完整、不會留 truncated JSON 觸發 ConfigCorrupt 鎖死 CLI。\n\tconst tmpPath = `${path}.tmp.${process.pid}.${Date.now()}`;\n\tconst fd = openSync(tmpPath, 'w', 0o600);\n\ttry {\n\t\twriteSync(fd, JSON.stringify(config, null, 2) + '\\n');\n\t} catch (err) {\n\t\tcloseSync(fd);\n\t\ttry {\n\t\t\tunlinkSync(tmpPath);\n\t\t} catch {\n\t\t\t/* best effort cleanup */\n\t\t}\n\t\tthrow err;\n\t}\n\tcloseSync(fd);\n\n\t// POSIX: openSync's mode is masked by umask (umask can only narrow, never widen).\n\t// chmod restores 0o600 in case a permissive umask stripped owner bits; it cannot\n\t// expose the file to group/other. On Windows chmodSync is a no-op, skip entirely.\n\tif (process.platform !== 'win32') {\n\t\ttry {\n\t\t\tchmodSync(tmpPath, 0o600);\n\t\t} catch (err) {\n\t\t\tprintWarn(\n\t\t\t\t`Failed to chmod 0600 on config tmpfile: ${(err as Error).message}. ` +\n\t\t\t\t\t'Other users on this system may be able to read CLI config.',\n\t\t\t\tfalse\n\t\t\t);\n\t\t}\n\t}\n\n\trenameSync(tmpPath, path);\n}\n\nexport function validateAndCoerce<K extends ConfigKey>(key: K, value: string): ConfigValueMap[K] {\n\tswitch (key) {\n\t\tcase 'locale': {\n\t\t\tif (!(ALLOWED_LOCALES as readonly string[]).includes(value)) {\n\t\t\t\tthrow new CliError(\n\t\t\t\t\t`Invalid locale \"${value}\". Allowed: ${ALLOWED_LOCALES.join(', ')}`,\n\t\t\t\t\tExitCode.InvalidArgument\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn value as ConfigValueMap[K];\n\t\t}\n\t\tcase 'output': {\n\t\t\tif (!(ALLOWED_OUTPUT as readonly string[]).includes(value)) {\n\t\t\t\tthrow new CliError(\n\t\t\t\t\t`Invalid output \"${value}\". Allowed: ${ALLOWED_OUTPUT.join(', ')}`,\n\t\t\t\t\tExitCode.InvalidArgument\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn value as ConfigValueMap[K];\n\t\t}\n\t\tcase 'timeout_ms': {\n\t\t\tconst n = Number(value);\n\t\t\tif (!Number.isInteger(n) || n < 100 || n > 600_000) {\n\t\t\t\tthrow new CliError(\n\t\t\t\t\t`timeout_ms must be an integer between 100 and 600000 (got ${value})`,\n\t\t\t\t\tExitCode.InvalidArgument\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn n as ConfigValueMap[K];\n\t\t}\n\t}\n}\n\n// Internal helpers exposed for tests. Not part of the public CLI API.\nexport const __test__ = {\n\tresetDeprecationWarning(): void {\n\t\tdeprecationWarned = false;\n\t},\n};\n","import type { Command } from 'commander';\nimport { ALLOWED_LOCALES, loadConfig, type Locale, type CliConfig } from './config-store';\nimport { CliError, ExitCode } from './errors';\nimport { resolveOutputFormat, isColorEnabled, type OutputFormat } from './output';\n\n// Production public API. Local development overrides via the WPORT_API_BASE env var\n// or the `--api` flag. (The `api_base_url` config key was removed in 0.1.2 — keeping a\n// persisted, mutable base URL on disk is an SSRF / credential-exfil surface that\n// external users don't need.)\nconst DEFAULT_BASE_URL = 'https://api.wport.me';\nexport const API_BASE_ENV_VAR = 'WPORT_API_BASE';\nconst DEFAULT_LOCALE: Locale = 'zh-TW';\nconst DEFAULT_TIMEOUT_MS = 10_000;\n\nexport interface ResolvedContext {\n\tbaseUrl: string;\n\tlocale: Locale;\n\ttimeoutMs: number;\n\tformat: OutputFormat;\n\tcolor: boolean;\n\tconfig: CliConfig;\n}\n\ninterface RawGlobals {\n\tlang?: string;\n\tapi?: string;\n\toutput?: string;\n\tcolor?: boolean;\n\ttimeout?: number;\n}\n\nexport function resolveContext(command: Command): ResolvedContext {\n\tconst globals = command.optsWithGlobals() as RawGlobals;\n\tconst config = loadConfig();\n\n\treturn {\n\t\tbaseUrl: resolveBaseUrl(globals.api),\n\t\tlocale: resolveLocale(globals.lang, config),\n\t\ttimeoutMs: resolveTimeout(globals.timeout, config),\n\t\tformat: resolveOutputFormat(globals.output),\n\t\tcolor: isColorEnabled(globals.color === false),\n\t\tconfig,\n\t};\n}\n\n/**\n * Resolve the API base URL. Precedence: `--api` flag > WPORT_API_BASE env var > default.\n * The env var is just as untrusted as the (removed) config key, so it gets the same\n * http(s)-only validation to keep the SSRF surface closed.\n */\nfunction resolveBaseUrl(override: string | undefined): string {\n\tconst fromEnv = process.env[API_BASE_ENV_VAR]?.trim();\n\tif (override !== undefined) return validateBaseUrl(override, '--api');\n\tif (fromEnv) return validateBaseUrl(fromEnv, `${API_BASE_ENV_VAR} env var`);\n\treturn DEFAULT_BASE_URL;\n}\n\nfunction validateBaseUrl(raw: string, source: string): string {\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(raw);\n\t} catch {\n\t\tthrow new CliError(`Invalid API base URL from ${source}: ${raw}`, ExitCode.InvalidArgument);\n\t}\n\tif (url.protocol !== 'https:' && url.protocol !== 'http:') {\n\t\tthrow new CliError(\n\t\t\t`API base URL from ${source} must be http or https (got ${url.protocol})`,\n\t\t\tExitCode.InvalidArgument\n\t\t);\n\t}\n\treturn raw.replace(/\\/$/, '');\n}\n\nfunction resolveLocale(override: string | undefined, config: CliConfig): Locale {\n\tconst raw = override ?? config.locale ?? DEFAULT_LOCALE;\n\tif (!(ALLOWED_LOCALES as readonly string[]).includes(raw)) {\n\t\tthrow new CliError(`Invalid --lang \"${raw}\". Allowed: ${ALLOWED_LOCALES.join(', ')}`, ExitCode.InvalidArgument);\n\t}\n\treturn raw as Locale;\n}\n\nfunction resolveTimeout(override: number | undefined, config: CliConfig): number {\n\tconst raw = override ?? config.timeout_ms ?? DEFAULT_TIMEOUT_MS;\n\tif (!Number.isInteger(raw) || raw < 100 || raw > 600_000) {\n\t\tthrow new CliError(`Invalid --timeout ${raw} (must be integer 100..600000)`, ExitCode.InvalidArgument);\n\t}\n\treturn raw;\n}\n\n// Internal helpers exposed for tests. Not part of the public CLI API.\nexport const __test__ = {\n\tresolveBaseUrl,\n\tDEFAULT_BASE_URL,\n};\n","import { CliError, ExitCode } from './errors';\n\n/**\n * Read a value out of a nested object by dotted path (e.g. `job_info.job_title`).\n * Returns undefined if any segment is missing.\n *\n * Uses hasOwnProperty (not the `in` operator / direct index) so a path segment can\n * never traverse into `__proto__` / `constructor` and walk the prototype chain —\n * the input objects are server-controlled, so this is a deliberate safety boundary.\n */\nexport function getPath(obj: unknown, dottedPath: string): unknown {\n\tconst parts = dottedPath.split('.');\n\tlet cur: unknown = obj;\n\tfor (const p of parts) {\n\t\tif (cur && typeof cur === 'object' && Object.prototype.hasOwnProperty.call(cur, p)) {\n\t\t\tcur = (cur as Record<string, unknown>)[p];\n\t\t} else {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\treturn cur;\n}\n\n/**\n * Project an object down to a set of dotted paths, keyed by the path string itself\n * (so `pickPaths(job, ['job_info.job_title'])` → `{ 'job_info.job_title': '...' }`).\n *\n * Every requested path becomes a key so the shape is predictable across a list of\n * heterogeneous items: a missing path yields `null` rather than being dropped, which\n * keeps each row in `jobs search --fields` structurally identical for downstream tools.\n */\nexport function pickPaths(obj: unknown, paths: string[]): Record<string, unknown> {\n\tconst out: Record<string, unknown> = {};\n\tfor (const p of paths) {\n\t\tconst v = getPath(obj, p);\n\t\tout[p] = v === undefined ? null : v;\n\t}\n\treturn out;\n}\n\n/**\n * Parse a comma-separated `--fields` value into a trimmed, non-empty list.\n * Throws InvalidArgument if the result is empty (e.g. `--fields ,,`).\n */\nexport function parseFieldsList(raw: string): string[] {\n\tconst fields = raw\n\t\t.split(',')\n\t\t.map((s) => s.trim())\n\t\t.filter(Boolean);\n\tif (fields.length === 0) {\n\t\tthrow new CliError('--fields requires at least one field name', ExitCode.InvalidArgument);\n\t}\n\treturn fields;\n}\n","/**\n * Run `fn` over `items` with at most `limit` in flight at once, returning results in\n * the SAME order as the input (not completion order) so callers can correlate output\n * rows back to their input without threading an index through.\n *\n * `fn` is expected to handle its own errors (e.g. resolve to an error-shaped result);\n * a rejection from `fn` will reject the whole batch, so the batch caller wraps each\n * unit in try/catch to keep one failure from sinking the rest.\n */\nexport async function mapWithConcurrency<T, R>(\n\titems: readonly T[],\n\tlimit: number,\n\tfn: (item: T, index: number) => Promise<R>\n): Promise<R[]> {\n\tconst results = new Array<R>(items.length);\n\tlet cursor = 0;\n\n\tasync function worker(): Promise<void> {\n\t\tfor (;;) {\n\t\t\tconst index = cursor++;\n\t\t\tif (index >= items.length) return;\n\t\t\tresults[index] = await fn(items[index], index);\n\t\t}\n\t}\n\n\tconst workerCount = Math.min(Math.max(1, limit), items.length);\n\tawait Promise.all(Array.from({ length: workerCount }, () => worker()));\n\treturn results;\n}\n","import { readSync, readFileSync } from 'node:fs';\nimport { CliError, ExitCode, InvalidArgumentError } from './errors';\n\n/**\n * Reject with `CliError(ServerOrNetworkError)` if a promise doesn't settle within `ms`.\n *\n * Reserved for async user / network input paths that v0.2 will add (streaming jobs,\n * interactive prompts with deadlines). Existing call sites either use their own\n * mechanism (`api-client` uses `AbortSignal.timeout`, `reset.ts` uses an `'end'`\n * handler) or are synchronous (`readFileSync(0)`). Removing this until then would\n * just churn the import graph; keeping it documents the contract.\n *\n * @internal — exported for future call sites, not part of public CLI API\n */\nexport function withTimeout<T>(promise: Promise<T>, ms: number, label: string): Promise<T> {\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst t = setTimeout(() => {\n\t\t\treject(new CliError(`Timed out after ${ms}ms: ${label}`, ExitCode.ServerOrNetworkError));\n\t\t}, ms);\n\t\tpromise.then(\n\t\t\t(v) => {\n\t\t\t\tclearTimeout(t);\n\t\t\t\tresolve(v);\n\t\t\t},\n\t\t\t(err) => {\n\t\t\t\tclearTimeout(t);\n\t\t\t\treject(err);\n\t\t\t}\n\t\t);\n\t});\n}\n\n/** Convenience: throw InvalidArgumentError on TTY stdin reads with no piped input. */\nexport function ensureStdinPiped(label: string): void {\n\tif (process.stdin.isTTY) {\n\t\tthrow new InvalidArgumentError(`${label}: no data on stdin (run via pipe, or pass the value as an arg)`);\n\t}\n}\n\n/** Standalone backstop when a caller can't supply a `--timeout`-derived bound. */\nconst DEFAULT_STDIN_TIMEOUT_MS = 30_000;\n\nexport interface ReadPipedStdinOptions {\n\t/**\n\t * Upper bound (ms) on total time spent waiting for a slow / hung upstream pipe.\n\t * Callers pass the resolved `--timeout` so the limit is user-tunable; falls back to\n\t * DEFAULT_STDIN_TIMEOUT_MS when omitted.\n\t */\n\ttimeoutMs?: number;\n\t/** Injectable clock for tests; defaults to `Date.now`. */\n\tnow?: () => number;\n}\n\n/**\n * Synchronously drain piped stdin to a string, tolerating EAGAIN.\n *\n * A single `readFileSync(0)` / `readSync` can throw EAGAIN when stdin is a non-blocking\n * pipe whose upstream process is still producing (e.g. `wport jobs search ... | jq ... |\n * wport jobs view - --batch`): the fd has no data *right now* but isn't at EOF either.\n * Naively letting that throw makes the documented pipe workflow fail intermittently. We\n * retry on EAGAIN with a ~1ms synchronous sleep (Atomics.wait, to avoid a hot spin) and\n * stop on a zero-byte read or EOF.\n *\n * If the upstream neither produces data nor closes the pipe, the EAGAIN retry would spin\n * forever (the global `--timeout` only bounds HTTP, not stdin). We cap the total wait with\n * `timeoutMs` and surface a timeout as InvalidArgumentError rather than hanging silently.\n */\nexport function readPipedStdin(label: string, options: ReadPipedStdinOptions = {}): string {\n\tconst timeoutMs = options.timeoutMs ?? DEFAULT_STDIN_TIMEOUT_MS;\n\tconst now = options.now ?? Date.now;\n\tensureStdinPiped(label);\n\tconst chunks: Buffer[] = [];\n\tconst buf = Buffer.alloc(64 * 1024);\n\tconst sleeper = new Int32Array(new SharedArrayBuffer(4));\n\tconst deadline = now() + timeoutMs;\n\tfor (;;) {\n\t\tlet bytesRead: number;\n\t\ttry {\n\t\t\tbytesRead = readSync(0, buf, 0, buf.length, null);\n\t\t} catch (err) {\n\t\t\tconst code = (err as NodeJS.ErrnoException).code;\n\t\t\tif (code === 'EAGAIN') {\n\t\t\t\tif (now() > deadline) {\n\t\t\t\t\tthrow new InvalidArgumentError(`${label}: timed out after ${timeoutMs}ms waiting for piped stdin`);\n\t\t\t\t}\n\t\t\t\tAtomics.wait(sleeper, 0, 0, 1); // sleep ~1ms, then retry\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (code === 'EOF') break;\n\t\t\tthrow new InvalidArgumentError(`${label}: failed to read stdin: ${(err as Error).message}`);\n\t\t}\n\t\tif (bytesRead === 0) break;\n\t\tchunks.push(Buffer.from(buf.subarray(0, bytesRead)));\n\t}\n\treturn Buffer.concat(chunks).toString('utf8');\n}\n\nexport interface PromptSecretOptions {\n\t/** 注入點,預設用本檔的 readPipedStdin(測試可換 fake)。 */\n\treadPiped?: (label: string) => string;\n}\n\n/**\n * 互動式讀 secret:TTY 時 raw mode 隱藏輸入(不 echo、不進 shell history);\n * 非 TTY(CI / pipe)時直接讀整個 stdin。供 `wport enterprise login` 用。\n */\nexport function promptSecret(promptText: string, options: PromptSecretOptions = {}): Promise<string> {\n\tconst readPiped = options.readPiped ?? ((label: string) => readPipedStdin(label));\n\tif (!process.stdin.isTTY || !process.stdout.isTTY) {\n\t\treturn Promise.resolve(readPiped('login').trim());\n\t}\n\tprocess.stdout.write(promptText);\n\treturn new Promise<string>((resolve, reject) => {\n\t\tconst stdin = process.stdin;\n\t\tstdin.setRawMode(true);\n\t\tstdin.resume();\n\t\tstdin.setEncoding('utf8');\n\t\tlet buf = '';\n\t\tconst cleanup = (): void => {\n\t\t\tstdin.setRawMode(false);\n\t\t\tstdin.pause();\n\t\t\tstdin.off('data', onData);\n\t\t};\n\t\tconst onData = (chunk: string): void => {\n\t\t\tfor (const ch of chunk) {\n\t\t\t\tif (ch === '\u0003') {\n\t\t\t\t\t// Ctrl-C\n\t\t\t\t\tcleanup();\n\t\t\t\t\tprocess.stdout.write('\\n');\n\t\t\t\t\treject(new CliError('Aborted', ExitCode.InvalidArgument));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (ch === '\\r' || ch === '\\n') {\n\t\t\t\t\tcleanup();\n\t\t\t\t\tprocess.stdout.write('\\n');\n\t\t\t\t\tresolve(buf.trim());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (ch === '' || ch === '\\b') {\n\t\t\t\t\tbuf = buf.slice(0, -1);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tbuf += ch;\n\t\t\t}\n\t\t};\n\t\tstdin.on('data', onData);\n\t});\n}\n\nexport interface ReadJsonInputOptions {\n\t/** 傳給 readPipedStdin 的上限(通常帶 resolved --timeout)。 */\n\ttimeoutMs?: number;\n\t/** 注入點,預設用 readPipedStdin;測試可換 fake,避免真的讀 fd 0。 */\n\treadStdin?: (label: string) => string;\n}\n\n/**\n * 讀 `--file <path>` 的 JSON body 供寫入命令(jobs create/update/batch)使用。\n * `path === '-'` 讀 stdin(管線 / here-doc)。body 直送後端驗證,CLI 只負責讀取 + parse。\n *\n * 讀不到檔 / 空輸入 / JSON parse 失敗 → InvalidArgumentError(exit 2、不發請求),\n * 錯誤訊息不含檔案內容(可能含敏感資料)。\n */\nexport function readJsonInput(source: string, options: ReadJsonInputOptions = {}): unknown {\n\tconst readStdin = options.readStdin ?? ((label: string) => readPipedStdin(label, { timeoutMs: options.timeoutMs }));\n\tlet raw: string;\n\tif (source === '-') {\n\t\traw = readStdin('--file -');\n\t} else {\n\t\ttry {\n\t\t\traw = readFileSync(source, 'utf8');\n\t\t} catch (err) {\n\t\t\tthrow new InvalidArgumentError(\n\t\t\t\t`Cannot read --file \"${source}\": ${(err as NodeJS.ErrnoException).code ?? (err as Error).message}`\n\t\t\t);\n\t\t}\n\t}\n\tif (!raw.trim()) {\n\t\tthrow new InvalidArgumentError('Input is empty — expected a JSON body');\n\t}\n\ttry {\n\t\treturn JSON.parse(raw);\n\t} catch {\n\t\t// 不夾帶 err.message:Node 的 JSON.parse SyntaxError 會把輸入片段放進訊息,\n\t\t// 可能外洩 --file 內容(如 secret)。固定訊息,守住上面 docstring 的承諾。\n\t\tthrow new InvalidArgumentError('Invalid JSON in input (parse failed)');\n\t}\n}\n\n/**\n * 同 readJsonInput,但要求 parse 結果是 JSON 物件(非陣列 / 非純量)。\n * jobs create/update 的 body、batch 的 `{jobs:[...]}` 外層皆為物件;先本地擋,錯誤更清楚。\n */\nexport function readJsonObject(source: string, options: ReadJsonInputOptions = {}): Record<string, unknown> {\n\tconst parsed = readJsonInput(source, options);\n\tif (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n\t\tthrow new InvalidArgumentError(\n\t\t\t`Input must be a JSON object, got ${Array.isArray(parsed) ? 'an array' : typeof parsed}`\n\t\t);\n\t}\n\treturn parsed as Record<string, unknown>;\n}\n","import type { Command } from 'commander';\nimport { createApiClient, throwForHttpStatus, unwrapDataResponse, type ApiClient } from '../../lib/api-client';\nimport { resolveContext } from '../../lib/global-opts';\nimport { CliError, ExitCode } from '../../lib/errors';\nimport { dim, printJson, printNdjsonLine, sanitizeForTerminal, sanitizeForTerminalMultiline } from '../../lib/output';\nimport { getPath, parseFieldsList, pickPaths } from '../../lib/path-utils';\nimport { mapWithConcurrency } from '../../lib/concurrency';\nimport { readPipedStdin } from '../../lib/io-helpers';\nimport pc from 'picocolors';\n\ninterface ViewFlags {\n\tfield?: string;\n\tfields?: string;\n\tbatch?: boolean;\n\tconcurrency?: number;\n}\n\nconst DEFAULT_BATCH_CONCURRENCY = 5;\nconst MAX_BATCH_CONCURRENCY = 20;\n\n/** One ND-JSON record emitted per enc_id in --batch mode. */\ninterface BatchResult {\n\tenc_id: string;\n\tok: boolean;\n\tdata?: unknown;\n\terror?: string;\n}\n\n/** Projects a fetched job down to whatever --field / --fields asked for (or the whole job). */\ntype JobProjector = (job: JobView) => unknown;\n\n/**\n * JobViewVM 是嵌套結構(見 src/modules/jobs/view-models/job-view.vm.ts)。\n * 這裡只列我們顯示時會碰到的欄位,其他欄位走 [k: string]: unknown 保留。\n */\ninterface JobView {\n\tcompany_header_info?: {\n\t\tcompany_name?: string;\n\t\tcompany_icon_url?: string;\n\t\tenc_company_id?: string;\n\t\t[k: string]: unknown;\n\t};\n\tjob_description?: string;\n\tjob_info?: {\n\t\tjob_title?: string;\n\t\tarea_display?: string;\n\t\tsalary_display?: string;\n\t\tjob_feature_display?: string | null;\n\t\texperience_display?: string | null;\n\t\t[k: string]: unknown;\n\t};\n\tjob_information?: Record<string, unknown>;\n\trecruitment_conditions?: Record<string, unknown>;\n\tbenefits?: Record<string, unknown>;\n\tabout_company?: Record<string, unknown> | null;\n\tapplication_method?: Record<string, unknown> | null;\n\tstructured_data?: Record<string, unknown> | null;\n\t[k: string]: unknown;\n}\n\nexport function registerJobsView(parent: Command): void {\n\tparent\n\t\t.command('view <enc_id>')\n\t\t.description('View a single job. Pass \"-\" to read enc_id from stdin.')\n\t\t.option('--field <path>', 'output a single field as a raw value (dotted paths, e.g. job_info.job_title)')\n\t\t.option(\n\t\t\t'--fields <list>',\n\t\t\t'output selected fields as a JSON object (comma-separated dotted paths, e.g. job_info.job_title,company_header_info.company_name)'\n\t\t)\n\t\t.option(\n\t\t\t'--batch',\n\t\t\t'read newline-separated enc_ids from stdin and emit one ND-JSON record per job (requires \"-\" as the enc_id arg)'\n\t\t)\n\t\t.option(\n\t\t\t'--concurrency <n>',\n\t\t\t`max parallel requests in --batch mode (default ${DEFAULT_BATCH_CONCURRENCY}, max ${MAX_BATCH_CONCURRENCY})`,\n\t\t\t(v) => Number(v)\n\t\t)\n\t\t.action(async (encIdArg: string, flags: ViewFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tif (flags.field && flags.fields) {\n\t\t\t\tthrow new CliError(\n\t\t\t\t\t'Use either --field (single raw value) or --fields (JSON object), not both',\n\t\t\t\t\tExitCode.InvalidArgument\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst client = createApiClient({\n\t\t\t\tbaseUrl: ctx.baseUrl,\n\t\t\t\tlocale: ctx.locale,\n\t\t\t\ttimeoutMs: ctx.timeoutMs,\n\t\t\t});\n\n\t\t\tif (flags.batch) {\n\t\t\t\tawait runBatchView(encIdArg, flags, client, ctx.timeoutMs);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst encId = encIdArg === '-' ? readPipedStdin('view -', { timeoutMs: ctx.timeoutMs }).trim() : encIdArg;\n\t\t\tif (!encId) {\n\t\t\t\tthrow new CliError('enc_id is required', ExitCode.InvalidArgument);\n\t\t\t}\n\n\t\t\tconst { data, error, response } = await client.GET('/api/jobs/{encId}/view', {\n\t\t\t\tparams: { path: { encId } },\n\t\t\t});\n\t\t\tif (!response.ok) throwForHttpStatus(response.status, error);\n\n\t\t\tconst job = unwrapDataResponse<JobView>(data);\n\n\t\t\tif (flags.fields) {\n\t\t\t\t// Multi-field projection → JSON object keyed by dotted path. printJson uses\n\t\t\t\t// JSON.stringify, which escapes control chars to \\uXXXX, so employer-controlled\n\t\t\t\t// string values are safe without extra sanitization (same rationale as the\n\t\t\t\t// json branch below).\n\t\t\t\tprintJson(pickPaths(job, parseFieldsList(flags.fields)));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (flags.field) {\n\t\t\t\tconst v = getPath(job, flags.field);\n\t\t\t\tif (v === undefined) {\n\t\t\t\t\tthrow new CliError(`Field \"${flags.field}\" not present in response`, ExitCode.InvalidArgument);\n\t\t\t\t}\n\t\t\t\t// String values are employer-controlled and printed raw — sanitize. The multiline\n\t\t\t\t// variant preserves \\n (e.g. when --field selects job_description) but still strips\n\t\t\t\t// every other control char including \\r and \\t. JSON.stringify already escapes\n\t\t\t\t// < 0x20 to \\uXXXX so non-string paths don't need extra handling.\n\t\t\t\tconst out = typeof v === 'string' ? sanitizeForTerminalMultiline(v) : JSON.stringify(v, null, 2);\n\t\t\t\tprocess.stdout.write(out + '\\n');\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (ctx.format === 'json') {\n\t\t\t\tprintJson(job);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\trenderJobTable(job, encId, ctx.color);\n\t\t});\n}\n\n/**\n * --batch orchestration: read enc_ids off stdin, fetch each (bounded parallelism),\n * and stream one ND-JSON record per job. One failed enc_id becomes an `ok:false` line\n * rather than aborting the whole run. Output order matches input order.\n */\nasync function runBatchView(encIdArg: string, flags: ViewFlags, client: ApiClient, timeoutMs: number): Promise<void> {\n\tif (encIdArg !== '-') {\n\t\tthrow new CliError('--batch reads enc_ids from stdin; pass \"-\" as the enc_id argument', ExitCode.InvalidArgument);\n\t}\n\tconst encIds = parseBatchInput(readPipedStdin('view - --batch', { timeoutMs }));\n\tif (encIds.length === 0) {\n\t\tthrow new CliError('No enc_ids found on stdin', ExitCode.InvalidArgument);\n\t}\n\tconst concurrency = resolveBatchConcurrency(flags.concurrency);\n\tconst project = makeBatchProjector(flags);\n\tconst results = await runBatch(encIds, concurrency, (encId) => fetchJob(client, encId), project);\n\tfor (const record of results) printNdjsonLine(record);\n}\n\nasync function fetchJob(client: ApiClient, encId: string): Promise<JobView> {\n\tconst { data, error, response } = await client.GET('/api/jobs/{encId}/view', {\n\t\tparams: { path: { encId } },\n\t});\n\tif (!response.ok) throwForHttpStatus(response.status, error);\n\treturn unwrapDataResponse<JobView>(data);\n}\n\n/**\n * Pure batch driver (injectable fetcher) so the success/failure-mix behaviour is\n * testable without a live API. Each unit is wrapped so a rejected fetch turns into an\n * `ok:false` record instead of rejecting the whole batch.\n */\nasync function runBatch(\n\tencIds: string[],\n\tconcurrency: number,\n\tfetchOne: (encId: string) => Promise<JobView>,\n\tproject: JobProjector\n): Promise<BatchResult[]> {\n\treturn mapWithConcurrency(encIds, concurrency, async (encId): Promise<BatchResult> => {\n\t\ttry {\n\t\t\tconst job = await fetchOne(encId);\n\t\t\treturn { enc_id: encId, ok: true, data: project(job) };\n\t\t} catch (err) {\n\t\t\treturn { enc_id: encId, ok: false, error: err instanceof Error ? err.message : String(err) };\n\t\t}\n\t});\n}\n\nfunction makeBatchProjector(flags: ViewFlags): JobProjector {\n\tif (flags.fields) {\n\t\tconst paths = parseFieldsList(flags.fields);\n\t\treturn (job) => pickPaths(job, paths);\n\t}\n\tif (flags.field) {\n\t\tconst path = flags.field;\n\t\t// Missing path → null (keeps every record's shape stable across the batch),\n\t\t// unlike single-view --field which errors on a missing path.\n\t\treturn (job) => getPath(job, path) ?? null;\n\t}\n\treturn (job) => job;\n}\n\nfunction parseBatchInput(raw: string): string[] {\n\treturn raw\n\t\t.split('\\n')\n\t\t.map((s) => s.trim())\n\t\t.filter(Boolean);\n}\n\nfunction resolveBatchConcurrency(raw: number | undefined): number {\n\tconst n = raw ?? DEFAULT_BATCH_CONCURRENCY;\n\tif (!Number.isInteger(n) || n < 1 || n > MAX_BATCH_CONCURRENCY) {\n\t\tthrow new CliError(\n\t\t\t`--concurrency must be an integer between 1 and ${MAX_BATCH_CONCURRENCY} (got ${raw})`,\n\t\t\tExitCode.InvalidArgument\n\t\t);\n\t}\n\treturn n;\n}\n\nfunction renderJobTable(job: JobView, encId: string, color: boolean): void {\n\tconst label = (s: string) => (color ? pc.bold(s) : s);\n\t// All API string values are employer-controlled; sanitize before printing to defend\n\t// against terminal escape injection (clear screen, OSC 8 phishing hyperlinks, etc.).\n\tconst s = (v: string | undefined | null): string => (v ? sanitizeForTerminal(v) : '');\n\tconst info = job.job_info ?? {};\n\tconst company = job.company_header_info ?? {};\n\n\tconst lines: string[] = [];\n\tif (info.job_title) lines.push(`${label('Title:')} ${s(info.job_title)}`);\n\tif (company.company_name) lines.push(`${label('Company:')} ${s(company.company_name)}`);\n\tif (info.area_display) lines.push(`${label('Location:')} ${s(info.area_display)}`);\n\tif (info.salary_display) lines.push(`${label('Salary:')} ${s(info.salary_display)}`);\n\tif (info.job_feature_display) lines.push(`${label('Type:')} ${s(info.job_feature_display)}`);\n\tif (info.experience_display) lines.push(`${label('Experience:')} ${s(info.experience_display)}`);\n\t// encId comes from the CLI arg (user-provided) but pass through sanitize as a defense-in-depth.\n\tlines.push(dim(`enc_id: ${s(encId)}`, color));\n\tif (company.enc_company_id) lines.push(dim(`enc_company_id: ${s(company.enc_company_id)}`, color));\n\tprocess.stdout.write(lines.join('\\n') + '\\n');\n\n\tif (job.job_description) {\n\t\tprocess.stdout.write('\\n' + label('Description') + '\\n');\n\t\t// stripHtml only removes tags; sanitize afterwards in case the rich-text source\n\t\t// embedded raw escape sequences inside text nodes. Use the multiline variant so the\n\t\t// description's paragraph breaks (\\n) are preserved while \\r / \\t / other controls\n\t\t// are still stripped.\n\t\tprocess.stdout.write(renderDescription(job.job_description) + '\\n');\n\t}\n\n\tprocess.stdout.write(\n\t\t'\\n' +\n\t\t\tdim(\n\t\t\t\t'Tip: use --output json (or --field <dotted.path>, e.g. --field job_info.salary_display) for scripting.',\n\t\t\t\tcolor\n\t\t\t) +\n\t\t\t'\\n'\n\t);\n}\n\n/**\n * 後端 job_description 可能含 HTML(rich text);CLI 終端機列印時剝掉 tag。\n * 不做完整 HTML 解析 —— 只把 tag 拿掉、& 實體做最常見的還原。\n */\nfunction stripHtml(s: string): string {\n\treturn s\n\t\t.replace(/<\\/?(p|br|div|li|h[1-6])[^>]*>/gi, '\\n')\n\t\t.replace(/<[^>]+>/g, '')\n\t\t.replace(/&nbsp;/g, ' ')\n\t\t.replace(/&amp;/g, '&')\n\t\t.replace(/&lt;/g, '<')\n\t\t.replace(/&gt;/g, '>')\n\t\t.replace(/&quot;/g, '\"')\n\t\t.replace(/&#39;/g, \"'\")\n\t\t.replace(/\\n{3,}/g, '\\n\\n')\n\t\t.trim();\n}\n\nfunction renderDescription(html: string): string {\n\treturn sanitizeForTerminalMultiline(stripHtml(html));\n}\n\n// Internal helpers exposed for tests. Not part of the public CLI API.\nexport const __test__ = {\n\tstripHtml,\n\tgetPath,\n\trenderDescription,\n\trunBatch,\n\tmakeBatchProjector,\n\tparseBatchInput,\n\tresolveBatchConcurrency,\n};\n","import type { Command } from 'commander';\nimport { registerJobsSearch } from './search';\nimport { registerJobsView } from './view';\n\nexport function registerJobsCommand(program: Command): void {\n\tconst jobs = program.command('jobs').description('Search and view public job listings');\n\tregisterJobsSearch(jobs);\n\tregisterJobsView(jobs);\n}\n","import type { Command } from 'commander';\nimport { isConfigKey, isDeprecatedConfigKey, loadConfig, saveConfig, validateAndCoerce } from '../../lib/config-store';\nimport { CliError, ExitCode } from '../../lib/errors';\nimport { API_BASE_ENV_VAR } from '../../lib/global-opts';\n\nexport function registerConfigSet(parent: Command): void {\n\tparent\n\t\t.command('set <key> <value>')\n\t\t.description('Set a config value. Keys: locale, output, timeout_ms')\n\t\t.action((key: string, value: string) => {\n\t\t\tif (isDeprecatedConfigKey(key)) {\n\t\t\t\tthrow new CliError(\n\t\t\t\t\t`Config key \"${key}\" was removed in 0.1.2. Set the ${API_BASE_ENV_VAR} env var ` +\n\t\t\t\t\t\t`(or use the --api flag) instead.`,\n\t\t\t\t\tExitCode.InvalidArgument\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!isConfigKey(key)) {\n\t\t\t\tthrow new CliError(\n\t\t\t\t\t`Unknown config key \"${key}\". Allowed: locale, output, timeout_ms`,\n\t\t\t\t\tExitCode.InvalidArgument\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst coerced = validateAndCoerce(key, value);\n\t\t\tconst config = loadConfig();\n\t\t\t// Object.assign 形式避免 TS 5.5 在 `config[key] = coerced` 上推不出\n\t\t\t// ConfigValueMap[K]→CliConfig[K] 的對應;validateAndCoerce 已 generic、型別正確。\n\t\t\tObject.assign(config, { [key]: coerced });\n\t\t\tsaveConfig(config);\n\t\t\tprocess.stdout.write(`Set ${key} = ${JSON.stringify(coerced)}\\n`);\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { isConfigKey, loadConfig } from '../../lib/config-store';\nimport { CliError, ExitCode } from '../../lib/errors';\nimport { printJson } from '../../lib/output';\n\nexport function registerConfigGet(parent: Command): void {\n\tparent\n\t\t.command('get [key]')\n\t\t.description('Print config value(s). With no key, prints the whole config as JSON.')\n\t\t.action((key: string | undefined) => {\n\t\t\tconst config = loadConfig();\n\t\t\tif (key === undefined) {\n\t\t\t\tprintJson(config);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!isConfigKey(key)) {\n\t\t\t\tthrow new CliError(\n\t\t\t\t\t`Unknown config key \"${key}\". Allowed: locale, output, timeout_ms`,\n\t\t\t\t\tExitCode.InvalidArgument\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst value = (config as Record<string, unknown>)[key];\n\t\t\tif (value === undefined) {\n\t\t\t\tprocess.stdout.write('\\n');\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tprocess.stdout.write((typeof value === 'string' ? value : JSON.stringify(value)) + '\\n');\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { getConfigPath } from '../../lib/config-store';\n\nexport function registerConfigPath(parent: Command): void {\n\tparent\n\t\t.command('path')\n\t\t.description('Print the path to the config file (regardless of whether it exists)')\n\t\t.action(() => {\n\t\t\tprocess.stdout.write(getConfigPath() + '\\n');\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { existsSync, unlinkSync } from 'node:fs';\nimport { getConfigPath } from '../../lib/config-store';\nimport { InvalidArgumentError } from '../../lib/errors';\n\nexport function registerConfigReset(parent: Command): void {\n\tparent\n\t\t.command('reset')\n\t\t.description('Delete the config file')\n\t\t.option('-f, --force', 'skip the confirmation prompt')\n\t\t.action(async (opts: { force?: boolean }) => {\n\t\t\tconst path = getConfigPath();\n\t\t\tif (!existsSync(path)) {\n\t\t\t\tprocess.stdout.write('No config file to delete.\\n');\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!opts.force) {\n\t\t\t\tconst ok = await promptYesNo(`Delete config at ${path}? [y/N] `);\n\t\t\t\tif (!ok) {\n\t\t\t\t\tprocess.stdout.write('Aborted.\\n');\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tunlinkSync(path);\n\t\t\t} catch (err) {\n\t\t\t\tconst e = err as NodeJS.ErrnoException;\n\t\t\t\tif (e.code === 'ENOENT') {\n\t\t\t\t\t// Race with another process: someone deleted it between exists & unlink.\n\t\t\t\t\tprocess.stdout.write('No config file to delete (already removed).\\n');\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthrow new InvalidArgumentError(`Failed to delete config at ${path}: ${e.message}`);\n\t\t\t}\n\t\t\tprocess.stdout.write(`Deleted ${path}\\n`);\n\t\t});\n}\n\nfunction promptYesNo(prompt: string): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tprocess.stdout.write(prompt);\n\t\tlet buf = '';\n\t\tprocess.stdin.setEncoding('utf8');\n\t\tconst onData = (chunk: string) => {\n\t\t\tbuf += chunk;\n\t\t\tconst nl = buf.indexOf('\\n');\n\t\t\tif (nl >= 0) {\n\t\t\t\tcleanup();\n\t\t\t\tconst answer = buf.slice(0, nl).trim().toLowerCase();\n\t\t\t\tresolve(answer === 'y' || answer === 'yes');\n\t\t\t}\n\t\t};\n\t\tconst onEnd = () => {\n\t\t\tcleanup();\n\t\t\tprocess.stdout.write('\\n(no input — aborting)\\n');\n\t\t\tresolve(false);\n\t\t};\n\t\tconst cleanup = () => {\n\t\t\tprocess.stdin.removeListener('data', onData);\n\t\t\tprocess.stdin.removeListener('end', onEnd);\n\t\t\tprocess.stdin.pause();\n\t\t};\n\t\tprocess.stdin.on('data', onData);\n\t\tprocess.stdin.on('end', onEnd);\n\t});\n}\n","import type { Command } from 'commander';\nimport { registerConfigSet } from './set';\nimport { registerConfigGet } from './get';\nimport { registerConfigPath } from './path';\nimport { registerConfigReset } from './reset';\n\nexport function registerConfigCommand(program: Command): void {\n\tconst config = program.command('config').description('Manage CLI configuration');\n\tregisterConfigSet(config);\n\tregisterConfigGet(config);\n\tregisterConfigPath(config);\n\tregisterConfigReset(config);\n}\n","import type { Command } from 'commander';\nimport { existsSync } from 'node:fs';\nimport { createApiClient } from '../lib/api-client';\nimport { resolveContext } from '../lib/global-opts';\nimport { getConfigPath } from '../lib/config-store';\nimport { ExitCode } from '../lib/errors';\n\n/**\n * Query params the server accepts syntactically but silently ignores — surfacing them\n * here is the whole point: an agent reading `wport doctor` learns not to try to control\n * sort order (it can't), instead of discovering it the hard way via wrong-but-no-error\n * results. The CLI deliberately doesn't expose flags for these.\n */\nexport const SILENT_IGNORED_PARAMS = ['orderBy', 'order'];\n\nexport function registerDoctorCommand(program: Command): void {\n\tprogram\n\t\t.command('doctor')\n\t\t.description(\n\t\t\t'Diagnose CLI setup: resolved config, server reachability, schema fingerprint, and known server quirks.'\n\t\t)\n\t\t.action(async (_opts: unknown, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tconst line = (s = '') => process.stdout.write(s + '\\n');\n\n\t\t\tline(`wport-cli ${__CLI_VERSION__}`);\n\t\t\tline(` bundled schema fingerprint: ${__SCHEMA_HASH__}`);\n\t\t\tline('');\n\n\t\t\tline('Resolved configuration:');\n\t\t\tline(` API base URL: ${ctx.baseUrl}`);\n\t\t\tline(` locale: ${ctx.locale}`);\n\t\t\tline(` timeout: ${ctx.timeoutMs}ms`);\n\t\t\tconst cfgPath = getConfigPath();\n\t\t\tline(` config file: ${cfgPath}${existsSync(cfgPath) ? '' : ' (not present)'}`);\n\t\t\tline('');\n\n\t\t\tline('Server connectivity:');\n\t\t\tconst reachable = await probeServer(ctx, line);\n\t\t\tline('');\n\n\t\t\tline('Known server behaviours (read this before scripting an agent):');\n\t\t\tline(\n\t\t\t\t` • Sort is server-controlled. These query params are silently ignored: ${SILENT_IGNORED_PARAMS.join(', ')}.`\n\t\t\t);\n\t\t\tline(' • jobs search sorts by publish date, or by relevance when --keyword is set.');\n\t\t\tline(' • jobs view --batch caps parallelism (default 5, max 20) to stay friendly to the API.');\n\t\t\tline('');\n\n\t\t\tline('Schema drift:');\n\t\t\tline(' The fingerprint above identifies the OpenAPI contract this CLI was built against.');\n\t\t\tline(' Automated drift detection needs a server-side schema-version endpoint, which is');\n\t\t\tline(' not available yet — for now, compare fingerprints manually after a server release. [TODO]');\n\n\t\t\tif (!reachable) process.exit(ExitCode.ServerOrNetworkError);\n\t\t});\n}\n\n/**\n * Lightweight reachability probe: a 1-result search hits the real public endpoint\n * without pulling a meaningful payload. A network-layer failure is a hard \"unreachable\"\n * (caller exits non-zero); an HTTP response of any status still proves the host is\n * reachable, so we report the status but don't treat it as a connectivity failure.\n */\nasync function probeServer(\n\tctx: { baseUrl: string; locale: string; timeoutMs: number },\n\tline: (s?: string) => void\n): Promise<boolean> {\n\ttry {\n\t\tconst client = createApiClient({ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs });\n\t\tconst { response } = await client.GET('/api/jobs/search', { params: { query: { pageSize: 1 } } });\n\t\tif (response.ok) {\n\t\t\tline(` ✓ reachable (HTTP ${response.status})`);\n\t\t} else {\n\t\t\tline(` ! reachable, but server responded HTTP ${response.status}`);\n\t\t}\n\t\treturn true;\n\t} catch (err) {\n\t\tline(` ✗ unreachable: ${err instanceof Error ? err.message : String(err)}`);\n\t\treturn false;\n\t}\n}\n","import { buildUserAgent, extractErrorMessage, fetchWithTimeout, throwForHttpStatus } from './api-client';\nimport { CliError, ExitCode } from './errors';\nimport { printWarn } from './output';\n\nexport interface EnterpriseRequestOptions {\n\tbaseUrl: string; // resolveContext 產出,已去尾斜線\n\tlocale: string;\n\ttimeoutMs: number;\n\tapiKey: string;\n}\n\nexport interface EnterpriseGetResult {\n\tbody: unknown;\n\theaders: Headers;\n}\n\nexport interface EnterprisePostResult {\n\tbody: unknown;\n\theaders: Headers;\n}\n\n/** 寫入請求可選 headers。jobs 寫入端點強制 Idempotency-Key;update 支援 If-Match 樂觀鎖。 */\nexport interface EnterpriseWriteExtra {\n\t/** 帶上則加 `Idempotency-Key` header。jobs create/update/publish/unpublish/delete/batch 後端強制此 header(缺 → 400)。 */\n\tidempotencyKey?: string;\n\t/** 帶上則加 `If-Match` header(jobs update 樂觀鎖,值為目標 updated_at;版本不符 → 409)。 */\n\tifMatch?: string;\n}\n\nconst ENTERPRISE_PREFIX = '/api/v1/enterprise';\n\n/**\n * 企業 API 唯讀 GET。手寫 wrapper 而非 openapi-fetch:openapi.yaml 缺 read 端點\n * response schema(spec §4.1 修訂),typed client 在這裡沒有可生成的型別。\n * timeout / 網路錯誤分類複用 api-client.fetchWithTimeout。\n */\nexport async function enterpriseGet(\n\topts: EnterpriseRequestOptions,\n\tpath: string,\n\tquery?: Record<string, string | number | undefined>\n): Promise<EnterpriseGetResult> {\n\tconst url = new URL(`${opts.baseUrl}${ENTERPRISE_PREFIX}${path}`);\n\tfor (const [k, v] of Object.entries(query ?? {})) {\n\t\tif (v !== undefined) url.searchParams.set(k, String(v));\n\t}\n\tconst request = new Request(url, {\n\t\theaders: {\n\t\t\tAuthorization: `Bearer ${opts.apiKey}`,\n\t\t\t'Accept-Language': opts.locale,\n\t\t\t'User-Agent': buildUserAgent(),\n\t\t\tAccept: 'application/json',\n\t\t},\n\t});\n\tconst res = await fetchWithTimeout(request, opts.timeoutMs);\n\tconst body: unknown = await res.json().catch(() => null);\n\tif (!res.ok) throwEnterpriseHttpError(res.status, body);\n\twarnIfRateLimitLow(res.headers);\n\treturn { body, headers: res.headers };\n}\n\n/**\n * 企業 API 寫入共用底層(POST/PATCH/DELETE)。手寫 wrapper(與 enterpriseGet 同理由:\n * openapi.yaml 缺 write 端點 response schema)。timeout / 網路錯誤分類複用 fetchWithTimeout;\n * 4xx/5xx 走 throwEnterpriseHttpError。\n *\n * headers:有 body 才帶 Content-Type;`extra.idempotencyKey` → `Idempotency-Key`;\n * `extra.ifMatch` → `If-Match`。呼叫端決定要不要帶(keys rotate 不帶;jobs 寫入必帶)。\n */\nasync function enterpriseWrite(\n\tmethod: 'POST' | 'PATCH' | 'DELETE',\n\topts: EnterpriseRequestOptions,\n\tpath: string,\n\tbody?: Record<string, unknown>,\n\textra?: EnterpriseWriteExtra\n): Promise<EnterprisePostResult> {\n\tconst url = new URL(`${opts.baseUrl}${ENTERPRISE_PREFIX}${path}`);\n\tconst headers: Record<string, string> = {\n\t\tAuthorization: `Bearer ${opts.apiKey}`,\n\t\t'Accept-Language': opts.locale,\n\t\t'User-Agent': buildUserAgent(),\n\t\tAccept: 'application/json',\n\t};\n\tif (body !== undefined) headers['Content-Type'] = 'application/json';\n\tif (extra?.idempotencyKey) headers['Idempotency-Key'] = extra.idempotencyKey;\n\tif (extra?.ifMatch) headers['If-Match'] = extra.ifMatch;\n\tconst request = new Request(url, {\n\t\tmethod,\n\t\theaders,\n\t\tbody: body !== undefined ? JSON.stringify(body) : undefined,\n\t});\n\tconst res = await fetchWithTimeout(request, opts.timeoutMs);\n\tconst respBody: unknown = await res.json().catch(() => null);\n\tif (!res.ok) throwEnterpriseHttpError(res.status, respBody);\n\twarnIfRateLimitLow(res.headers);\n\treturn { body: respBody, headers: res.headers };\n}\n\n/**\n * 企業 API 寫入 POST。\n *\n * ⚠️ keys rotate 呼叫時**不帶** `extra`(後端 rotate 端點不掛 idempotency interceptor);\n * jobs create/batch 則必帶 `extra.idempotencyKey`(後端強制,缺 → 400)。\n */\nexport function enterprisePost(\n\topts: EnterpriseRequestOptions,\n\tpath: string,\n\tbody: Record<string, unknown>,\n\textra?: EnterpriseWriteExtra\n): Promise<EnterprisePostResult> {\n\treturn enterpriseWrite('POST', opts, path, body, extra);\n}\n\n/** 企業 API 寫入 PATCH(jobs update / publish / unpublish)。jobs 端點強制 Idempotency-Key。 */\nexport function enterprisePatch(\n\topts: EnterpriseRequestOptions,\n\tpath: string,\n\tbody: Record<string, unknown>,\n\textra?: EnterpriseWriteExtra\n): Promise<EnterprisePostResult> {\n\treturn enterpriseWrite('PATCH', opts, path, body, extra);\n}\n\n/** 企業 API 寫入 DELETE(jobs delete)。無 body;jobs 端點強制 Idempotency-Key。 */\nexport function enterpriseDelete(\n\topts: EnterpriseRequestOptions,\n\tpath: string,\n\textra?: EnterpriseWriteExtra\n): Promise<EnterprisePostResult> {\n\treturn enterpriseWrite('DELETE', opts, path, undefined, extra);\n}\n\n/**\n * spec §5 + pm_41 §3:401/403 附情境提示。\n *\n * ⚠️ 為何是「合併提示」而非按子類精準分流(2026-07-01 staging live smoke 實測校正):\n * 後端全域 `I18nExceptionFilter` 會把 guard 丟的 `{ path: 'error.enterprise.expired_api_key' }`\n * 翻成 `message` 後**丟掉 path**,實際 body 只有 `{ message(已翻譯), error, statusCode }`。\n * 過期 / 撤銷 / 無效在 client 端**同為 401、無機器可辨識訊號**(訊息是 DB i18n、5 語系、會改字,\n * 不可 regex)。所以無法「拆開給不同 next-step」,改給一則涵蓋兩種修法的提示。\n *\n * 這仍解掉 backlog §3.3 的核心痛點:舊版只寫「run login」,過期 key 重 login 仍 401 是死路;\n * 現在明確點出「過期 → keys rotate(過期 key 仍可 rotate)」這條出路。\n * 精準分流需後端在錯誤契約放穩定 `code`(全域 filter 變更),列為後端 follow-up。\n *\n * 提示一律單行:頂層 printError 走 sanitizeForTerminal 會剝掉 \\n。\n */\nfunction throwEnterpriseHttpError(status: number, body: unknown): never {\n\tconst base = extractErrorMessage(body) ?? `HTTP ${status}`;\n\tif (status === 401) {\n\t\tthrow new CliError(\n\t\t\t`${base} — If your key has expired, rotate it in place: \\`wport enterprise keys rotate <enc_id>\\` ` +\n\t\t\t\t'(an expired key is still accepted for rotate). ' +\n\t\t\t\t'If it was revoked or is incorrect, obtain a valid key and run `wport enterprise login`.',\n\t\t\tExitCode.ServerClientError\n\t\t);\n\t}\n\tif (status === 403) {\n\t\tthrow new CliError(\n\t\t\t`${base} — Your key may lack the required scope; rotate or issue a key that includes it. ` +\n\t\t\t\t'If your company account has been suspended, please contact support.',\n\t\t\tExitCode.ServerClientError\n\t\t);\n\t}\n\tthrowForHttpStatus(status, body);\n}\n\n/** spec §5:剩餘配額 <10% 時 stderr 提醒(不阻斷;stderr 不污染 json stdout)。 */\nfunction warnIfRateLimitLow(headers: Headers): void {\n\tconst remaining = Number(headers.get('x-ratelimit-remaining'));\n\tconst limit = Number(headers.get('x-ratelimit-limit'));\n\tif (Number.isFinite(remaining) && Number.isFinite(limit) && limit > 0 && remaining / limit < 0.1) {\n\t\tprintWarn(`Rate limit nearly exhausted: ${remaining}/${limit} requests remaining this window.`, false);\n\t}\n}\n","import {\n\texistsSync,\n\treadFileSync,\n\tmkdirSync,\n\topenSync,\n\twriteSync,\n\tcloseSync,\n\tchmodSync,\n\trenameSync,\n\tunlinkSync,\n} from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport envPaths from 'env-paths';\nimport { CliError, ExitCode } from './errors';\nimport { printWarn } from './output';\n\nexport const API_KEY_ENV_VAR = 'WPORT_API_KEY';\nexport const KEY_PREFIX = 'wpk_live_';\n// Server contract(spec §2.1):wpk_live_ + 32 高熵字元。下限驗證擋手滑貼半截;\n// 不驗上限——server 端才是 key 有效性的唯一權威。\nconst KEY_MIN_LENGTH = KEY_PREFIX.length + 32;\n\nexport interface Credentials {\n\tapi_key: string;\n\tcompany_name: string;\n\tkey_last4: string;\n\tsaved_at: string;\n}\n\nexport type KeySource = 'flag' | 'env' | 'file';\n\nexport interface ResolvedKey {\n\tkey: string;\n\tsource: KeySource;\n}\n\nconst paths = envPaths('wport', { suffix: '' });\n\nexport function getCredentialsPath(): string {\n\treturn join(paths.config, 'credentials.json');\n}\n\nexport function isValidKeyFormat(key: string): boolean {\n\treturn key.startsWith(KEY_PREFIX) && key.length >= KEY_MIN_LENGTH && !/\\s/.test(key);\n}\n\n/** 任何輸出顯示 key 一律走這裡:只露末四碼。 */\nexport function maskKey(key: string): string {\n\treturn `${KEY_PREFIX}••••${key.slice(-4)}`;\n}\n\nexport function loadCredentials(): Credentials | null {\n\tconst path = getCredentialsPath();\n\tif (!existsSync(path)) return null;\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(readFileSync(path, 'utf8'));\n\t} catch (err) {\n\t\tthrow new CliError(\n\t\t\t`Failed to read credentials at ${path}: ${(err as Error).message}. Run \"wport enterprise login\" to recreate it.`,\n\t\t\tExitCode.ConfigCorrupt\n\t\t);\n\t}\n\tif (!parsed || typeof parsed !== 'object' || typeof (parsed as Record<string, unknown>).api_key !== 'string') {\n\t\tthrow new CliError(\n\t\t\t`Credentials file at ${path} is malformed. Run \"wport enterprise login\" to recreate it.`,\n\t\t\tExitCode.ConfigCorrupt\n\t\t);\n\t}\n\tconst raw = parsed as Record<string, unknown>;\n\tconst apiKey = raw.api_key as string;\n\treturn {\n\t\tapi_key: apiKey,\n\t\tcompany_name: typeof raw.company_name === 'string' ? raw.company_name : '',\n\t\tkey_last4: typeof raw.key_last4 === 'string' ? raw.key_last4 : apiKey.slice(-4),\n\t\tsaved_at: typeof raw.saved_at === 'string' ? raw.saved_at : '',\n\t};\n}\n\n// Atomic write 模式照抄 config-store.saveConfig:tmpfile(0o600) → rename。\n// credentials 比 config 更敏感,所以分檔(config 可能被使用者貼進 issue 除錯)。\nexport function saveCredentials(creds: Credentials): void {\n\tconst path = getCredentialsPath();\n\tmkdirSync(dirname(path), { recursive: true });\n\tconst tmpPath = `${path}.tmp.${process.pid}.${Date.now()}`;\n\tconst fd = openSync(tmpPath, 'w', 0o600);\n\ttry {\n\t\twriteSync(fd, JSON.stringify(creds, null, 2) + '\\n');\n\t} catch (err) {\n\t\tcloseSync(fd);\n\t\ttry {\n\t\t\tunlinkSync(tmpPath);\n\t\t} catch {\n\t\t\t/* best effort cleanup */\n\t\t}\n\t\tthrow err;\n\t}\n\tcloseSync(fd);\n\tif (process.platform !== 'win32') {\n\t\ttry {\n\t\t\tchmodSync(tmpPath, 0o600);\n\t\t} catch (err) {\n\t\t\tprintWarn(\n\t\t\t\t`Failed to chmod 0600 on credentials tmpfile: ${(err as Error).message}. ` +\n\t\t\t\t\t'Other users on this system may be able to read your API key.',\n\t\t\t\tfalse\n\t\t\t);\n\t\t}\n\t}\n\trenameSync(tmpPath, path);\n}\n\nexport function deleteCredentials(): boolean {\n\tconst path = getCredentialsPath();\n\tif (!existsSync(path)) return false;\n\tunlinkSync(path);\n\treturn true;\n}\n\n/**\n * Key 解析 precedence:--api-key flag > WPORT_API_KEY env > credentials.json。\n * 與 base url 解析(--api > WPORT_API_BASE > default,global-opts.ts)同款心智模型。\n */\nexport function resolveApiKey(flagValue?: string): ResolvedKey {\n\tif (flagValue !== undefined) {\n\t\tensureFormat(flagValue, '--api-key');\n\t\treturn { key: flagValue, source: 'flag' };\n\t}\n\tconst fromEnv = process.env[API_KEY_ENV_VAR]?.trim();\n\tif (fromEnv) {\n\t\tensureFormat(fromEnv, `${API_KEY_ENV_VAR} env var`);\n\t\treturn { key: fromEnv, source: 'env' };\n\t}\n\tconst creds = loadCredentials();\n\tif (creds) return { key: creds.api_key, source: 'file' };\n\tthrow new CliError(\n\t\t`No API key found. Run \"wport enterprise login\" or set the ${API_KEY_ENV_VAR} env var.`,\n\t\tExitCode.InvalidArgument\n\t);\n}\n\nfunction ensureFormat(key: string, source: string): void {\n\tif (!isValidKeyFormat(key)) {\n\t\t// 錯誤訊息絕不 echo key 原文(可能是手滑貼進來的其他 secret)\n\t\tthrow new CliError(`API key from ${source} is not a valid ${KEY_PREFIX} key`, ExitCode.InvalidArgument);\n\t}\n}\n","import type { Command } from 'commander';\nimport { resolveContext } from '../../lib/global-opts';\nimport { CliError, ExitCode } from '../../lib/errors';\nimport { promptSecret } from '../../lib/io-helpers';\nimport { enterpriseGet } from '../../lib/enterprise-client';\nimport {\n\tAPI_KEY_ENV_VAR,\n\tKEY_PREFIX,\n\tgetCredentialsPath,\n\tisValidKeyFormat,\n\tmaskKey,\n\tsaveCredentials,\n} from '../../lib/credentials-store';\nimport { printWarn } from '../../lib/output';\n\nexport interface LoginContext {\n\tbaseUrl: string;\n\tlocale: string;\n\ttimeoutMs: number;\n}\n\n/** login 核心(與 commander 解耦供測試):驗格式 → 打 API 驗 key → 存檔。 */\nexport async function performLogin(ctx: LoginContext, key: string): Promise<void> {\n\tif (!isValidKeyFormat(key)) {\n\t\t// 不 echo 輸入原文 —— 可能是手滑貼進來的其他 secret\n\t\tthrow new CliError(\n\t\t\t`That does not look like a valid ${KEY_PREFIX} key. Nothing was saved.`,\n\t\t\tExitCode.InvalidArgument\n\t\t);\n\t}\n\t// 任何非 200 都由 enterpriseGet 丟出(401/403 → CliError 附情境提示),不落檔。\n\t// 打 GET /me 兼作 key 驗證與公司名取得(取代舊的 /jobs?pageSize=1 驗證)。\n\tconst { body } = await enterpriseGet({ ...ctx, apiKey: key }, '/me');\n\tsaveCredentials({\n\t\tapi_key: key,\n\t\tcompany_name: extractCompanyName(body),\n\t\tkey_last4: key.slice(-4),\n\t\tsaved_at: new Date().toISOString(),\n\t});\n}\n\n/**\n * 從 GET /me 的 DataResponse({ data: { company: { enc_id, name } } })取公司名。\n * shape 非預期時回空字串 —— login 已驗 key(200),不該因回應格式小變動而失敗;\n * company_name 缺失只讓 whoami 退回顯示 (unknown)。\n */\nfunction extractCompanyName(body: unknown): string {\n\tif (body && typeof body === 'object') {\n\t\tconst data = (body as { data?: unknown }).data;\n\t\tif (data && typeof data === 'object') {\n\t\t\tconst company = (data as { company?: unknown }).company;\n\t\t\tif (company && typeof company === 'object') {\n\t\t\t\tconst name = (company as { name?: unknown }).name;\n\t\t\t\tif (typeof name === 'string') return name;\n\t\t\t}\n\t\t}\n\t}\n\treturn '';\n}\n\nexport function registerEnterpriseLogin(parent: Command): void {\n\tparent\n\t\t.command('login')\n\t\t.description('Validate and save an enterprise API key (prompts securely; pipe stdin in CI)')\n\t\t.action(async (_flags: unknown, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tconst key = await promptSecret(`Paste your API key (${KEY_PREFIX}...): `);\n\t\t\tawait performLogin({ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs }, key);\n\t\t\tprocess.stdout.write(`Logged in. Key ${maskKey(key)} saved to ${getCredentialsPath()}\\n`);\n\t\t\tif (process.platform === 'win32') {\n\t\t\t\tprintWarn(\n\t\t\t\t\t`On Windows file permissions are best-effort. For stricter isolation, prefer the ${API_KEY_ENV_VAR} env var.`,\n\t\t\t\t\tctx.color\n\t\t\t\t);\n\t\t\t}\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { deleteCredentials, getCredentialsPath } from '../../lib/credentials-store';\n\nexport function registerEnterpriseLogout(parent: Command): void {\n\tparent\n\t\t.command('logout')\n\t\t.description('Delete the saved enterprise API key')\n\t\t.action(() => {\n\t\t\tconst deleted = deleteCredentials();\n\t\t\tprocess.stdout.write(\n\t\t\t\tdeleted ? `Logged out. Removed ${getCredentialsPath()}\\n` : 'No saved credentials to remove.\\n'\n\t\t\t);\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { loadCredentials, maskKey, resolveApiKey } from '../../lib/credentials-store';\n\ninterface WhoamiGlobals {\n\tapiKey?: string;\n}\n\nexport function registerEnterpriseWhoami(parent: Command): void {\n\tparent\n\t\t.command('whoami')\n\t\t.description('Show which enterprise key is in effect (offline; reads local state only)')\n\t\t.action((_flags: unknown, command: Command) => {\n\t\t\tconst globals = command.optsWithGlobals() as WhoamiGlobals;\n\t\t\tconst resolved = resolveApiKey(globals.apiKey);\n\t\t\tconst creds = resolved.source === 'file' ? loadCredentials() : null;\n\t\t\tconst lines = [\n\t\t\t\t`key: ${maskKey(resolved.key)}`,\n\t\t\t\t`source: ${resolved.source}`,\n\t\t\t\t`company: ${creds?.company_name || '(unknown)'}`,\n\t\t\t];\n\t\t\tif (creds?.saved_at) lines.push(`saved: ${creds.saved_at}`);\n\t\t\tprocess.stdout.write(lines.join('\\n') + '\\n');\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { asPaginatedBody } from '../../../lib/api-client';\nimport { enterpriseGet } from '../../../lib/enterprise-client';\nimport { resolveApiKey } from '../../../lib/credentials-store';\nimport { resolveContext } from '../../../lib/global-opts';\nimport { CliError, ExitCode } from '../../../lib/errors';\nimport { dim, printJson, printTable } from '../../../lib/output';\nimport { parseFieldsList, pickPaths } from '../../../lib/path-utils';\n\ninterface ListFlags {\n\tpage?: number;\n\tpageSize?: number;\n\tkeyword?: string;\n\tstatus?: string;\n\tfields?: string;\n\tminimal?: boolean;\n}\n\n/**\n * Server 契約(EnterpriseJobsQueryDto.status: number,0=未刊登,1=已刊登)。\n * openapi.yaml 寫的 active|inactive|deleted 是 drift,送字串會 400 —— 一律走這個映射。\n */\nconst STATUS_MAP: Record<string, number> = { published: 1, unpublished: 0 };\n\nconst MINIMAL_LIST_FIELDS = ['enc_id', 'job_title', 'status', 'updated_at'];\n\n/** 欄位對齊 server EnterpriseJobVm(enterprise-job.vm.ts)。 */\ninterface EnterpriseJobItem {\n\tenc_id?: string;\n\tjob_title?: string | null;\n\tcode?: string | null;\n\tstatus?: number;\n\tcreated_at?: string | null;\n\tupdated_at?: string | null;\n\t[k: string]: unknown;\n}\n\nfunction mapStatusFlag(raw: string | undefined): number | undefined {\n\tif (raw === undefined) return undefined;\n\tif (raw in STATUS_MAP) return STATUS_MAP[raw];\n\tthrow new CliError(\n\t\t`Invalid --status \"${raw}\". Allowed: ${Object.keys(STATUS_MAP).join(', ')}`,\n\t\tExitCode.InvalidArgument\n\t);\n}\n\nexport function formatStatus(status: number | undefined): string {\n\tif (status === 1) return 'published';\n\tif (status === 0) return 'unpublished';\n\treturn status === undefined ? '' : String(status);\n}\n\nfunction formatDate(value: string | null | undefined): string {\n\treturn value ? String(value).slice(0, 10) : '';\n}\n\nexport function registerEnterpriseJobsList(parent: Command): void {\n\tparent\n\t\t.command('list')\n\t\t.description('List your company job postings')\n\t\t.option('--page <n>', 'page number (server: currentPage, default 1)', (v) => Number(v))\n\t\t.option('--page-size <n>', 'items per page (server: pageSize, default 10, max 100)', (v) => Number(v))\n\t\t.option('--keyword <kw>', 'filter by job title keyword')\n\t\t.option('--status <state>', 'filter by status: published | unpublished')\n\t\t.option('--fields <list>', 'output selected fields as JSON (comma-separated dotted paths)')\n\t\t.option('--minimal', `output only ${MINIMAL_LIST_FIELDS.join(',')} as JSON`)\n\t\t.action(async (flags: ListFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tif (flags.fields && flags.minimal) {\n\t\t\t\tthrow new CliError('Use either --fields or --minimal, not both', ExitCode.InvalidArgument);\n\t\t\t}\n\t\t\tconst globals = command.optsWithGlobals() as { apiKey?: string };\n\t\t\tconst { key } = resolveApiKey(globals.apiKey);\n\t\t\tconst { body } = await enterpriseGet(\n\t\t\t\t{ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey: key },\n\t\t\t\t'/jobs',\n\t\t\t\t{\n\t\t\t\t\tcurrentPage: flags.page,\n\t\t\t\t\tpageSize: flags.pageSize,\n\t\t\t\t\tkeyword: flags.keyword,\n\t\t\t\t\tstatus: mapStatusFlag(flags.status),\n\t\t\t\t}\n\t\t\t);\n\t\t\tconst paged = asPaginatedBody<EnterpriseJobItem>(body);\n\n\t\t\tconst projection = flags.minimal ? MINIMAL_LIST_FIELDS : flags.fields ? parseFieldsList(flags.fields) : undefined;\n\t\t\tif (projection || ctx.format === 'json') {\n\t\t\t\tprintJson(projection ? { ...paged, data: paged.data.map((row) => pickPaths(row, projection)) } : paged);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tprintTable(\n\t\t\t\tpaged.data,\n\t\t\t\t[\n\t\t\t\t\t{ header: 'ENC_ID', value: (r) => (r.enc_id ?? '').slice(0, 14) },\n\t\t\t\t\t{ header: 'TITLE', value: (r) => r.job_title ?? '', maxWidth: 36 },\n\t\t\t\t\t{ header: 'STATUS', value: (r) => formatStatus(r.status) },\n\t\t\t\t\t{ header: 'CODE', value: (r) => r.code ?? '', maxWidth: 16 },\n\t\t\t\t\t{ header: 'UPDATED', value: (r) => formatDate(r.updated_at), maxWidth: 12 },\n\t\t\t\t],\n\t\t\t\tctx.color\n\t\t\t);\n\t\t\tconst head = `Showing page ${paged.currentPage}/${paged.totalPages} (${paged.data.length} of ${paged.totalCount} jobs).`;\n\t\t\tconst hint =\n\t\t\t\tpaged.totalPages > paged.currentPage\n\t\t\t\t\t? ` Next: wport enterprise jobs list --page ${paged.currentPage + 1}`\n\t\t\t\t\t: '';\n\t\t\tprocess.stdout.write(dim(head + hint, ctx.color) + '\\n');\n\t\t});\n}\n\n// Internal helpers exposed for tests. Not part of the public CLI API.\nexport const __test__ = { mapStatusFlag, formatStatus };\n","import type { Command } from 'commander';\nimport { unwrapDataResponse } from '../../../lib/api-client';\nimport { enterpriseGet } from '../../../lib/enterprise-client';\nimport { resolveApiKey } from '../../../lib/credentials-store';\nimport { resolveContext } from '../../../lib/global-opts';\nimport { CliError, ExitCode } from '../../../lib/errors';\nimport { printJson, sanitizeForTerminal } from '../../../lib/output';\nimport { parseFieldsList, pickPaths } from '../../../lib/path-utils';\nimport { formatStatus } from './list';\n\ninterface ViewFlags {\n\tfields?: string;\n}\n\ninterface EnterpriseJobDetail {\n\tenc_id?: string;\n\tjob_title?: string | null;\n\tcode?: string | null;\n\tstatus?: number;\n\tcreated_at?: string | null;\n\tupdated_at?: string | null;\n\t[k: string]: unknown;\n}\n\nconst DETAIL_FIELDS: ReadonlyArray<string> = ['enc_id', 'job_title', 'code', 'status', 'created_at', 'updated_at'];\n\nfunction renderDetailLines(job: EnterpriseJobDetail): string[] {\n\tconst pad = Math.max(...DETAIL_FIELDS.map((f) => f.length)) + 1;\n\tconst lines: string[] = [];\n\tfor (const field of DETAIL_FIELDS) {\n\t\tconst raw = job[field];\n\t\tif (raw === null || raw === undefined) continue;\n\t\tconst value = field === 'status' ? formatStatus(raw as number) : String(raw);\n\t\tlines.push(`${(field + ':').padEnd(pad + 1)}${sanitizeForTerminal(value)}`);\n\t}\n\treturn lines;\n}\n\nexport function registerEnterpriseJobsView(parent: Command): void {\n\tparent\n\t\t.command('view <enc_id>')\n\t\t.description('View one of your company job postings')\n\t\t.option('--fields <list>', 'output selected fields as JSON (comma-separated dotted paths)')\n\t\t.action(async (encId: string, flags: ViewFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tif (!encId.trim()) {\n\t\t\t\tthrow new CliError('enc_id must not be empty', ExitCode.InvalidArgument);\n\t\t\t}\n\t\t\tconst globals = command.optsWithGlobals() as { apiKey?: string };\n\t\t\tconst { key } = resolveApiKey(globals.apiKey);\n\t\t\tconst { body } = await enterpriseGet(\n\t\t\t\t{ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey: key },\n\t\t\t\t`/jobs/${encodeURIComponent(encId.trim())}`\n\t\t\t);\n\t\t\tconst job = unwrapDataResponse<EnterpriseJobDetail>(body);\n\n\t\t\tif (flags.fields) {\n\t\t\t\tprintJson(pickPaths(job, parseFieldsList(flags.fields)));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (ctx.format === 'json') {\n\t\t\t\tprintJson(job);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tprocess.stdout.write(renderDetailLines(job).join('\\n') + '\\n');\n\t\t});\n}\n\n// Internal helpers exposed for tests. Not part of the public CLI API.\nexport const __test__ = { renderDetailLines };\n","import type { Command } from 'commander';\nimport { randomUUID } from 'node:crypto';\nimport { unwrapDataResponse } from '../../../lib/api-client';\nimport { enterprisePost } from '../../../lib/enterprise-client';\nimport { resolveApiKey } from '../../../lib/credentials-store';\nimport { resolveContext } from '../../../lib/global-opts';\nimport { readJsonObject } from '../../../lib/io-helpers';\nimport { printJson } from '../../../lib/output';\nimport type { WriteCtx } from './write-shared';\n\ninterface CreateFlags {\n\tfile?: string;\n\tidempotencyKey?: string;\n}\n\n/** create/update 回應:後端只回 { enc_id }(enterprise-jobs.controller)。 */\nexport interface CreatedJob {\n\tenc_id?: string;\n\t[k: string]: unknown;\n}\n\n/**\n * `jobs create` 核心:讀 --file/stdin 的 JSON body → POST /jobs(201)→ 回 { enc_id }。\n * body 直送後端驗證(欄位/巢狀 salary·work_area 皆由 server DTO 把關)。\n * idempotencyKey 由呼叫端決定(後端強制帶,缺 → 400)。\n */\nexport async function runJobsCreate(\n\tctx: WriteCtx,\n\tapiKey: string,\n\tsource: string,\n\tidempotencyKey: string\n): Promise<void> {\n\tconst jobBody = readJsonObject(source, { timeoutMs: ctx.timeoutMs });\n\tconst { body } = await enterprisePost(\n\t\t{ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey },\n\t\t'/jobs',\n\t\tjobBody,\n\t\t{ idempotencyKey }\n\t);\n\tconst created = unwrapDataResponse<CreatedJob>(body);\n\tif (ctx.format === 'json') {\n\t\tprintJson(created);\n\t\treturn;\n\t}\n\tprocess.stdout.write(`Created job: ${created.enc_id ?? ''}\\n`);\n}\n\nexport function registerEnterpriseJobsCreate(parent: Command): void {\n\tparent\n\t\t.command('create')\n\t\t.description('Create a job posting from a JSON file (use \"-\" to read stdin)')\n\t\t.requiredOption('--file <path>', 'path to a JSON job body, or \"-\" for stdin')\n\t\t.option('--idempotency-key <key>', 'reuse across retries to avoid duplicate creates (default: a fresh UUID)')\n\t\t.action(async (flags: CreateFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tconst globals = command.optsWithGlobals() as { apiKey?: string };\n\t\t\tconst { key } = resolveApiKey(globals.apiKey);\n\t\t\tawait runJobsCreate(ctx, key, flags.file as string, flags.idempotencyKey ?? randomUUID());\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { randomUUID } from 'node:crypto';\nimport { unwrapDataResponse } from '../../../lib/api-client';\nimport { enterprisePatch } from '../../../lib/enterprise-client';\nimport { resolveApiKey } from '../../../lib/credentials-store';\nimport { resolveContext } from '../../../lib/global-opts';\nimport { readJsonObject } from '../../../lib/io-helpers';\nimport { printJson } from '../../../lib/output';\nimport type { CreatedJob } from './create';\nimport { requireEncId, type WriteCtx } from './write-shared';\n\ninterface UpdateFlags {\n\tfile?: string;\n\tidempotencyKey?: string;\n\tifMatch?: string;\n}\n\n/**\n * `jobs update` 核心:讀 --file/stdin 的 partial JSON → PATCH /jobs/:enc_id(200)。\n * --if-match 帶目標 updated_at → 樂觀鎖(版本不符後端回 409)。\n */\nexport async function runJobsUpdate(\n\tctx: WriteCtx,\n\tapiKey: string,\n\tencId: string,\n\tsource: string,\n\tidempotencyKey: string,\n\tifMatch?: string\n): Promise<void> {\n\tconst trimmed = requireEncId(encId);\n\tconst jobBody = readJsonObject(source, { timeoutMs: ctx.timeoutMs });\n\tconst { body } = await enterprisePatch(\n\t\t{ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey },\n\t\t`/jobs/${encodeURIComponent(trimmed)}`,\n\t\tjobBody,\n\t\t{ idempotencyKey, ifMatch }\n\t);\n\tconst updated = unwrapDataResponse<CreatedJob>(body);\n\tif (ctx.format === 'json') {\n\t\tprintJson(updated);\n\t\treturn;\n\t}\n\tprocess.stdout.write(`Updated job: ${updated.enc_id ?? trimmed}\\n`);\n}\n\nexport function registerEnterpriseJobsUpdate(parent: Command): void {\n\tparent\n\t\t.command('update <enc_id>')\n\t\t.description('Update a job posting from a JSON file (partial; use \"-\" for stdin)')\n\t\t.requiredOption('--file <path>', 'path to a partial JSON job body, or \"-\" for stdin')\n\t\t.option('--if-match <updated_at>', \"optimistic lock: the job's current updated_at (409 if stale)\")\n\t\t.option('--idempotency-key <key>', 'reuse across retries (default: a fresh UUID)')\n\t\t.action(async (encId: string, flags: UpdateFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tconst globals = command.optsWithGlobals() as { apiKey?: string };\n\t\t\tconst { key } = resolveApiKey(globals.apiKey);\n\t\t\tawait runJobsUpdate(ctx, key, encId, flags.file as string, flags.idempotencyKey ?? randomUUID(), flags.ifMatch);\n\t\t});\n}\n","import { CliError, ExitCode } from '../../../lib/errors';\nimport type { OutputFormat } from '../../../lib/output';\n\n/**\n * 企業職缺寫入命令共用的 resolved context 子集。\n * 寫入命令目前不使用 `color`(輸出非表格著色),故不納入。\n */\nexport interface WriteCtx {\n\tbaseUrl: string;\n\tlocale: string;\n\ttimeoutMs: number;\n\tformat: OutputFormat;\n}\n\n/** enc_id 去空白 + 非空檢查(空字串 → exit 2、不發請求)。 */\nexport function requireEncId(encId: string): string {\n\tconst trimmed = encId.trim();\n\tif (!trimmed) throw new CliError('enc_id must not be empty', ExitCode.InvalidArgument);\n\treturn trimmed;\n}\n","import type { Command } from 'commander';\nimport { randomUUID } from 'node:crypto';\nimport { unwrapDataResponse } from '../../../lib/api-client';\nimport { enterpriseDelete, enterprisePatch } from '../../../lib/enterprise-client';\nimport { resolveApiKey } from '../../../lib/credentials-store';\nimport { resolveContext } from '../../../lib/global-opts';\nimport { CliError, ExitCode } from '../../../lib/errors';\nimport { printJson } from '../../../lib/output';\nimport type { CreatedJob } from './create';\nimport { requireEncId, type WriteCtx } from './write-shared';\n\ninterface LifecycleFlags {\n\tidempotencyKey?: string;\n\tconfirm?: boolean;\n}\n\n/** publish / unpublish 共用:PATCH /jobs/:enc_id/{action}(空 body,帶 Idempotency-Key)。 */\nexport async function runJobsTransition(\n\tctx: WriteCtx,\n\tapiKey: string,\n\tencId: string,\n\taction: 'publish' | 'unpublish',\n\tidempotencyKey: string\n): Promise<void> {\n\tconst trimmed = requireEncId(encId);\n\tconst { body } = await enterprisePatch(\n\t\t{ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey },\n\t\t`/jobs/${encodeURIComponent(trimmed)}/${action}`,\n\t\t{},\n\t\t{ idempotencyKey }\n\t);\n\tconst result = unwrapDataResponse<CreatedJob>(body);\n\tif (ctx.format === 'json') {\n\t\tprintJson(result);\n\t\treturn;\n\t}\n\tconst verb = action === 'publish' ? 'Published' : 'Unpublished';\n\tprocess.stdout.write(`${verb} job: ${result.enc_id ?? trimmed}\\n`);\n}\n\n/**\n * `jobs delete` 核心:破壞性寫入 —— 無 `--confirm` 一律本地 exit 2、**不發請求**(PRD §6.2)。\n * 帶 Idempotency-Key(後端強制)。\n */\nexport async function runJobsDelete(\n\tctx: WriteCtx,\n\tapiKey: string,\n\tencId: string,\n\tconfirm: boolean,\n\tidempotencyKey: string\n): Promise<void> {\n\tif (!confirm) {\n\t\tthrow new CliError('Refusing to delete without --confirm (destructive, irreversible)', ExitCode.InvalidArgument);\n\t}\n\tconst trimmed = requireEncId(encId);\n\tawait enterpriseDelete(\n\t\t{ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey },\n\t\t`/jobs/${encodeURIComponent(trimmed)}`,\n\t\t{ idempotencyKey }\n\t);\n\t// DELETE 後端回 `DataResponse(null, ...)`(data 為 null、無 enc_id)→ 不 unwrap/deref(否則\n\t// null.enc_id 在 table 模式下丟 TypeError);用呼叫時的 enc_id 回報刪除結果。\n\tif (ctx.format === 'json') {\n\t\tprintJson({ enc_id: trimmed, deleted: true });\n\t\treturn;\n\t}\n\tprocess.stdout.write(`Deleted job: ${trimmed}\\n`);\n}\n\nexport function registerEnterpriseJobsPublish(parent: Command): void {\n\tparent\n\t\t.command('publish <enc_id>')\n\t\t.description('Publish a job posting')\n\t\t.option('--idempotency-key <key>', 'reuse across retries (default: a fresh UUID)')\n\t\t.action(async (encId: string, flags: LifecycleFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tconst { key } = resolveApiKey((command.optsWithGlobals() as { apiKey?: string }).apiKey);\n\t\t\tawait runJobsTransition(ctx, key, encId, 'publish', flags.idempotencyKey ?? randomUUID());\n\t\t});\n}\n\nexport function registerEnterpriseJobsUnpublish(parent: Command): void {\n\tparent\n\t\t.command('unpublish <enc_id>')\n\t\t.description('Unpublish (take down) a job posting')\n\t\t.option('--idempotency-key <key>', 'reuse across retries (default: a fresh UUID)')\n\t\t.action(async (encId: string, flags: LifecycleFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tconst { key } = resolveApiKey((command.optsWithGlobals() as { apiKey?: string }).apiKey);\n\t\t\tawait runJobsTransition(ctx, key, encId, 'unpublish', flags.idempotencyKey ?? randomUUID());\n\t\t});\n}\n\nexport function registerEnterpriseJobsDelete(parent: Command): void {\n\tparent\n\t\t.command('delete <enc_id>')\n\t\t.description('Delete a job posting (destructive; requires --confirm)')\n\t\t.option('--confirm', 'confirm this destructive, irreversible delete')\n\t\t.option('--idempotency-key <key>', 'reuse across retries (default: a fresh UUID)')\n\t\t.action(async (encId: string, flags: LifecycleFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tconst { key } = resolveApiKey((command.optsWithGlobals() as { apiKey?: string }).apiKey);\n\t\t\tawait runJobsDelete(ctx, key, encId, flags.confirm === true, flags.idempotencyKey ?? randomUUID());\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { randomUUID } from 'node:crypto';\nimport { unwrapDataResponse } from '../../../lib/api-client';\nimport { enterprisePost } from '../../../lib/enterprise-client';\nimport { resolveApiKey } from '../../../lib/credentials-store';\nimport { resolveContext } from '../../../lib/global-opts';\nimport { CliError, ExitCode } from '../../../lib/errors';\nimport { readJsonObject } from '../../../lib/io-helpers';\nimport { printJson, sanitizeForTerminal } from '../../../lib/output';\nimport type { WriteCtx } from './write-shared';\n\ninterface BatchFlags {\n\tfile?: string;\n\tconfirm?: boolean;\n\tidempotencyKey?: string;\n}\n\n/** 對齊後端 207 body:data = { succeeded:[{index,enc_id}], failed:[{index,error_path}] }。 */\nexport interface BatchResult {\n\tsucceeded?: { index: number; enc_id: string }[];\n\tfailed?: { index: number; error_path: string }[];\n}\n\nconst BATCH_MIN = 1;\nconst BATCH_MAX = 10;\n\n/**\n * `jobs batch` 核心:讀 {jobs:[...]}(1..10)→ POST /jobs/batch(207 multi-status)。\n * 破壞性/大量寫入 → 無 `--confirm` 本地 exit 2、不發請求。逐筆獨立成敗;有 failed → exit 3\n * (結果已印出供腳本解析)。帶 Idempotency-Key(後端強制)。\n */\nexport async function runJobsBatch(\n\tctx: WriteCtx,\n\tapiKey: string,\n\tsource: string,\n\tconfirm: boolean,\n\tidempotencyKey: string\n): Promise<void> {\n\tif (!confirm) {\n\t\tthrow new CliError('Refusing to run batch create without --confirm', ExitCode.InvalidArgument);\n\t}\n\tconst payload = readJsonObject(source, { timeoutMs: ctx.timeoutMs });\n\tconst jobs = payload.jobs;\n\tif (!Array.isArray(jobs) || jobs.length < BATCH_MIN || jobs.length > BATCH_MAX) {\n\t\tthrow new CliError(\n\t\t\t`Batch input must be { \"jobs\": [...] } with ${BATCH_MIN} to ${BATCH_MAX} items`,\n\t\t\tExitCode.InvalidArgument\n\t\t);\n\t}\n\tconst { body } = await enterprisePost(\n\t\t{ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey },\n\t\t'/jobs/batch',\n\t\tpayload,\n\t\t{ idempotencyKey }\n\t);\n\tconst result = unwrapDataResponse<BatchResult>(body);\n\tconst succeeded = result.succeeded ?? [];\n\tconst failed = result.failed ?? [];\n\n\tif (ctx.format === 'json') {\n\t\tprintJson(result);\n\t} else {\n\t\tprocess.stdout.write(`Batch: ${succeeded.length} succeeded, ${failed.length} failed (of ${jobs.length}).\\n`);\n\t\tfor (const s of succeeded)\n\t\t\tprocess.stdout.write(` ok [${s.index}] ${sanitizeForTerminal(String(s.enc_id ?? ''))}\\n`);\n\t\tfor (const f of failed)\n\t\t\tprocess.stdout.write(` fail [${f.index}] ${sanitizeForTerminal(String(f.error_path ?? ''))}\\n`);\n\t}\n\n\t// 部分成功也算未全成 → 非 0 exit 讓腳本偵測(結果已印出)。\n\tif (failed.length > 0) {\n\t\tthrow new CliError(`${failed.length} of ${jobs.length} job(s) failed in batch create`, ExitCode.ServerClientError);\n\t}\n}\n\nexport function registerEnterpriseJobsBatch(parent: Command): void {\n\tparent\n\t\t.command('batch')\n\t\t.description('Batch-create up to 10 jobs from a JSON file ({ \"jobs\": [...] }; requires --confirm)')\n\t\t.requiredOption('--file <path>', 'path to a JSON { \"jobs\": [...] } body, or \"-\" for stdin')\n\t\t.option('--confirm', 'confirm this bulk write')\n\t\t.option('--idempotency-key <key>', 'reuse across retries (default: a fresh UUID)')\n\t\t.action(async (flags: BatchFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tconst { key } = resolveApiKey((command.optsWithGlobals() as { apiKey?: string }).apiKey);\n\t\t\tawait runJobsBatch(ctx, key, flags.file as string, flags.confirm === true, flags.idempotencyKey ?? randomUUID());\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { registerEnterpriseJobsList } from './list';\nimport { registerEnterpriseJobsView } from './view';\nimport { registerEnterpriseJobsCreate } from './create';\nimport { registerEnterpriseJobsUpdate } from './update';\nimport {\n\tregisterEnterpriseJobsPublish,\n\tregisterEnterpriseJobsUnpublish,\n\tregisterEnterpriseJobsDelete,\n} from './lifecycle';\nimport { registerEnterpriseJobsBatch } from './batch';\n\nexport function registerEnterpriseJobsCommand(parent: Command): void {\n\tconst jobs = parent.command('jobs').description('Manage your company job postings');\n\tregisterEnterpriseJobsList(jobs);\n\tregisterEnterpriseJobsView(jobs);\n\tregisterEnterpriseJobsCreate(jobs);\n\tregisterEnterpriseJobsUpdate(jobs);\n\tregisterEnterpriseJobsPublish(jobs);\n\tregisterEnterpriseJobsUnpublish(jobs);\n\tregisterEnterpriseJobsDelete(jobs);\n\tregisterEnterpriseJobsBatch(jobs);\n}\n","import type { Command } from 'commander';\nimport { unwrapDataArray } from '../../../lib/api-client';\nimport { enterpriseGet } from '../../../lib/enterprise-client';\nimport { resolveApiKey } from '../../../lib/credentials-store';\nimport { resolveContext } from '../../../lib/global-opts';\nimport { dim, printJson, printTable, type OutputFormat } from '../../../lib/output';\n\n/** 欄位對齊 server EnterpriseKeyVm(enterprise-key.vm.ts,pm_41 KEY-M-1)。明文不在此。 */\nexport interface EnterpriseKeyItem {\n\tenc_id?: string;\n\tname?: string | null;\n\tkey_prefix?: string;\n\tkey_last4?: string | null;\n\tscopes?: string[];\n\tstatus?: 'active' | 'expired' | 'revoked' | string;\n\texpires_at?: string | null;\n\tlast_used_at?: string | null;\n\t[k: string]: unknown;\n}\n\nfunction formatDate(value: string | null | undefined): string {\n\treturn value ? String(value).slice(0, 10) : '';\n}\n\nfunction formatScopes(scopes: string[] | undefined): string {\n\treturn Array.isArray(scopes) ? scopes.join(',') : '';\n}\n\n/**\n * `keys list` 核心:驗 key → GET /keys → 輸出。與 commander 註冊分離,方便測試\n * (同 login.performLogin 模式)。GET /keys 回 DataResponse(非分頁),data 是陣列。\n */\nexport async function runKeysList(\n\tctx: { baseUrl: string; locale: string; timeoutMs: number; format: OutputFormat; color: boolean },\n\tapiKey: string\n): Promise<void> {\n\tconst { body } = await enterpriseGet(\n\t\t{ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey },\n\t\t'/keys'\n\t);\n\tconst keys = unwrapDataArray<EnterpriseKeyItem>(body);\n\n\tif (ctx.format === 'json') {\n\t\tprintJson(keys);\n\t\treturn;\n\t}\n\n\tprintTable(\n\t\tkeys,\n\t\t[\n\t\t\t{ header: 'ENC_ID', value: (r) => (r.enc_id ?? '').slice(0, 14) },\n\t\t\t{ header: 'NAME', value: (r) => r.name ?? '', maxWidth: 24 },\n\t\t\t{ header: 'LAST4', value: (r) => r.key_last4 ?? '' },\n\t\t\t{ header: 'SCOPES', value: (r) => formatScopes(r.scopes), maxWidth: 28 },\n\t\t\t{ header: 'STATUS', value: (r) => r.status ?? '' },\n\t\t\t{ header: 'EXPIRES', value: (r) => formatDate(r.expires_at), maxWidth: 12 },\n\t\t\t{ header: 'LAST_USED', value: (r) => formatDate(r.last_used_at), maxWidth: 12 },\n\t\t],\n\t\tctx.color\n\t);\n\tconst active = keys.filter((k) => k.status === 'active').length;\n\tprocess.stdout.write(dim(`${keys.length} key(s), ${active} active.`, ctx.color) + '\\n');\n}\n\nexport function registerEnterpriseKeysList(parent: Command): void {\n\tparent\n\t\t.command('list')\n\t\t.description('List your company API keys (masked)')\n\t\t.action(async (_flags: unknown, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tconst globals = command.optsWithGlobals() as { apiKey?: string };\n\t\t\tconst { key } = resolveApiKey(globals.apiKey);\n\t\t\tawait runKeysList(ctx, key);\n\t\t});\n}\n\n// Internal helpers exposed for tests. Not part of the public CLI API.\nexport const __test__ = { formatDate, formatScopes };\n","import type { Command } from 'commander';\nimport { unwrapDataResponse } from '../../../lib/api-client';\nimport { enterprisePost } from '../../../lib/enterprise-client';\nimport { API_KEY_ENV_VAR, maskKey, resolveApiKey } from '../../../lib/credentials-store';\nimport { resolveContext } from '../../../lib/global-opts';\nimport { CliError, ExitCode } from '../../../lib/errors';\nimport { dim, printJson, printWarn, sanitizeForTerminal, type OutputFormat } from '../../../lib/output';\n\n// 對齊 server ENTERPRISE_KEY_EXPIRY_DAYS(enterprise-api-key.constants.ts)。CLI 是獨立套件、\n// 不能 import server code,故在此複製一份;server 端 @IsIn 才是唯一權威,本地只做提前擋。\nconst ENTERPRISE_KEY_EXPIRY_DAYS = [30, 60, 90] as const;\n\ninterface RotateFlags {\n\texpiryDays?: number;\n\treveal?: boolean;\n}\n\n/** 回應對齊 server EnterpriseKeyIssuedVm(enterprise-key.vm.ts,pm_41 KEY-M-2)。 */\nexport interface EnterpriseKeyIssued {\n\tapi_key?: string;\n\tenc_id?: string;\n\tname?: string | null;\n\tscopes?: string[];\n\texpires_at?: string | null;\n\tkey_last4?: string | null;\n\t[k: string]: unknown;\n}\n\n/** --expiry-days 若帶,必須是 30/60/90(server EnterpriseRotateKeyDto @IsIn)。本地先擋,省一次請求。 */\nexport function validateExpiryDays(raw: number | undefined): number | undefined {\n\tif (raw === undefined) return undefined;\n\tif (!(ENTERPRISE_KEY_EXPIRY_DAYS as readonly number[]).includes(raw)) {\n\t\tthrow new CliError(\n\t\t\t`Invalid --expiry-days ${raw}. Allowed: ${ENTERPRISE_KEY_EXPIRY_DAYS.join(', ')}`,\n\t\t\tExitCode.InvalidArgument\n\t\t);\n\t}\n\treturn raw;\n}\n\n/**\n * `keys rotate` 核心:POST /keys/:enc_id/rotate → 回新明文(僅一次)。與 commander 分離便於測試。\n *\n * 注意:呼叫端已 resolveApiKey,**不可**在本地擋過期 key —— rotate 是唯一「拿過期 key\n * 當 Bearer 仍可過」的端點(server EnterpriseApiKeyRotateGuard,pm_41 §3.5)。\n */\nexport async function runKeysRotate(\n\tctx: { baseUrl: string; locale: string; timeoutMs: number; format: OutputFormat; color: boolean },\n\tapiKey: string,\n\tencId: string,\n\tflags: RotateFlags\n): Promise<void> {\n\tconst trimmed = encId.trim();\n\tif (!trimmed) throw new CliError('enc_id must not be empty', ExitCode.InvalidArgument);\n\tconst expiryDays = validateExpiryDays(flags.expiryDays);\n\n\tconst requestBody: Record<string, unknown> = {};\n\tif (expiryDays !== undefined) requestBody.expiry_days = expiryDays;\n\n\tconst { body } = await enterprisePost(\n\t\t{ baseUrl: ctx.baseUrl, locale: ctx.locale, timeoutMs: ctx.timeoutMs, apiKey },\n\t\t`/keys/${encodeURIComponent(trimmed)}/rotate`,\n\t\trequestBody\n\t);\n\tconst issued = unwrapDataResponse<EnterpriseKeyIssued>(body);\n\n\tif (ctx.format === 'json') {\n\t\t// json 模式帶完整明文 api_key(供腳本擷取,PRD §6.7/§12.1)。\n\t\tprintJson(issued);\n\t} else {\n\t\tconst plaintext = issued.api_key ?? '';\n\t\tconst shown = flags.reveal ? plaintext : maskKey(plaintext);\n\t\tconst lines = [\n\t\t\t`New API key: ${sanitizeForTerminal(shown)}`,\n\t\t\t`enc_id: ${sanitizeForTerminal(issued.enc_id ?? '')}`,\n\t\t\t`scopes: ${sanitizeForTerminal((issued.scopes ?? []).join(','))}`,\n\t\t\t`expires_at: ${sanitizeForTerminal(issued.expires_at ?? '')}`,\n\t\t];\n\t\tprocess.stdout.write(lines.join('\\n') + '\\n');\n\t\tif (!flags.reveal) {\n\t\t\tprocess.stdout.write(dim('Re-run with --reveal to print the full key once.', ctx.color) + '\\n');\n\t\t}\n\t}\n\n\t// 舊 key 立即失效(PRD §12.1):務必提醒更新憑證,否則下次呼叫用舊 key 會 401。stderr 不污染 json stdout。\n\tprintWarn(\n\t\t`The previous key is now invalid. Update your ${API_KEY_ENV_VAR} env var / credential store, ` +\n\t\t\t'or run \"wport enterprise login\" with the new key.',\n\t\tctx.color\n\t);\n}\n\nexport function registerEnterpriseKeysRotate(parent: Command): void {\n\tparent\n\t\t.command('rotate <enc_id>')\n\t\t.description('Rotate an API key in place (issues a new key, invalidates the old one)')\n\t\t.option('--expiry-days <n>', 'new key lifetime in days (30 | 60 | 90; default 90)', (v) => Number(v))\n\t\t.option('--reveal', 'print the full new key (default masks all but the last 4 chars)')\n\t\t.action(async (encId: string, flags: RotateFlags, command: Command) => {\n\t\t\tconst ctx = resolveContext(command);\n\t\t\tconst globals = command.optsWithGlobals() as { apiKey?: string };\n\t\t\t// resolveApiKey 只驗格式,不驗到期 —— 過期 key 仍是合法 wpk_live_ 格式,會放行(rotate 需要)。\n\t\t\tconst { key } = resolveApiKey(globals.apiKey);\n\t\t\tawait runKeysRotate(ctx, key, encId, flags);\n\t\t});\n}\n","import type { Command } from 'commander';\nimport { registerEnterpriseKeysList } from './list';\nimport { registerEnterpriseKeysRotate } from './rotate';\n\nexport function registerEnterpriseKeysCommand(parent: Command): void {\n\tconst keys = parent.command('keys').description('List and rotate your company API keys');\n\tregisterEnterpriseKeysList(keys);\n\tregisterEnterpriseKeysRotate(keys);\n}\n","import type { Command } from 'commander';\nimport { registerEnterpriseLogin } from './login';\nimport { registerEnterpriseLogout } from './logout';\nimport { registerEnterpriseWhoami } from './whoami';\nimport { registerEnterpriseJobsCommand } from './jobs';\nimport { registerEnterpriseKeysCommand } from './keys';\n\nexport function registerEnterpriseCommand(program: Command): void {\n\tconst enterprise = program\n\t\t.command('enterprise')\n\t\t.description('Manage your company job postings with an enterprise API key')\n\t\t.option('--api-key <key>', 'one-off API key (prefer \"wport enterprise login\" or the WPORT_API_KEY env var)');\n\tregisterEnterpriseLogin(enterprise);\n\tregisterEnterpriseLogout(enterprise);\n\tregisterEnterpriseWhoami(enterprise);\n\tregisterEnterpriseJobsCommand(enterprise);\n\tregisterEnterpriseKeysCommand(enterprise);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uBAAwB;;;ACAjB,IAAM,WAAW;AAAA,EACvB,SAAS;AAAA,EACT,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,sBAAsB;AAAA,EACtB,eAAe;AAChB;AAIO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAC1B;AAAA,EAET,YAAY,SAAiB,UAAyB;AACrD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EACjB;AACD;AAEO,IAAM,uBAAN,cAAmC,SAAS;AAAA,EAClD,YAAY,SAAiB;AAC5B,UAAM,SAAS,SAAS,eAAe;AACvC,SAAK,OAAO;AAAA,EACb;AACD;AAEO,IAAM,wBAAN,cAAoC,SAAS;AAAA,EAC1C;AAAA,EACA;AAAA,EACT,YAAY,SAAiB,QAAgB,MAAe;AAC3D,UAAM,SAAS,SAAS,iBAAiB;AACzC,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACb;AACD;AAEO,IAAM,eAAN,cAA2B,SAAS;AAAA,EACjC;AAAA,EACT,YAAY,SAAiB,OAAiB;AAC7C,UAAM,SAAS,SAAS,oBAAoB;AAC5C,SAAK,OAAO;AACZ,SAAK,QAAQ;AAAA,EACd;AACD;AAWO,SAAS,WAAW,KAA+B;AACzD,SAAO,eAAe;AACvB;;;AC1DA,wBAAkB;AAClB,wBAAe;AAiBf,IAAM,uBAAuB,IAAI;AAAA,EAChC;AAAA;AAAA,IAEC;AAAA;AAAA,IAEA;AAAA;AAAA;AAAA;AAAA,IAIA;AAAA,EACD,EAAE,KAAK,GAAG;AAAA,EACV;AACD;AAMA,IAAM,uBAAuB,IAAI,OAAO,2CAA2C,GAAG;AAItF,IAA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AAwB,EAClE,OAAO,mBAAmB,+DAA+D,EACzF,OAAO,eAAe,uBAAuB,EAC7C,OAAO,kBAAkB,6BAA6B,EACtD,OAAO,cAAc,sBAAsB,EAC3C,OAAO,kBAAkB,gCAAgC,CAAC,MAAM,OAAO,CAAC,CAAC;AAE3E,oBAAoB,OAAO;AAC3B,sBAAsB,OAAO;AAC7B,sBAAsB,OAAO;AAC7B,0BAA0B,OAAO;AAEjC,QAAQ,aAAa;AAErB,QACE,WAAW,QAAQ,IAAI,EACvB,KAAK,MAAM,QAAQ,KAAK,SAAS,OAAO,CAAC,EACzC,MAAM,CAAC,QAAiB,oBAAoB,GAAG,CAAC;AAElD,SAAS,oBAAoB,KAAqB;AACjD,QAAM,QAAQ,eAAe,KAAK;AAGlC,MAAI,OAAO,OAAO,QAAQ,YAAY,UAAU,KAAK;AACpD,UAAM,eAAe;AACrB,QAAI,aAAa,SAAS,6BAA6B,aAAa,SAAS,qBAAqB;AACjG,cAAQ,KAAK,SAAS,OAAO;AAAA,IAC9B;AAGA,QAAI,aAAa,QAAS,YAAW,aAAa,SAAS,KAAK;AAChE,YAAQ,KAAK,SAAS,eAAe;AAAA,EACtC;AAEA,MAAI,WAAW,GAAG,GAAG;AACpB,eAAW,IAAI,SAAS,KAAK;AAC7B,YAAQ,KAAK,IAAI,QAAQ;AAAA,EAC1B;AAEA,QAAM,kBAAkB,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AACvE,aAAW,iBAAiB,KAAK;AACjC,UAAQ,KAAK,SAAS,oBAAoB;AAC3C;","names":["pc","Table","import_node_fs","createClient","envPaths","paths","import_node_fs","import_picocolors","paths","s","pc","program","import_node_fs","program","import_node_fs","program","import_node_fs","import_node_path","import_env_paths","paths","envPaths","formatDate","import_node_crypto","import_node_crypto","import_node_crypto","formatDate","program"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wport/cli",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "description": "wport CLI — terminal interface to the W101 Talent Search Hub public API",
5
5
  "author": "YAO <yao@wport.me>",
6
6
  "bugs": {