chapa-cli 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +31 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -332,17 +332,41 @@ function restoreTls(insecure, original) {
332
332
  }
333
333
  }
334
334
  var TLS_ERROR_PATTERNS = [
335
+ // Node.js error codes (uppercase)
335
336
  "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
336
337
  "CERT_HAS_EXPIRED",
337
338
  "DEPTH_ZERO_SELF_SIGNED_CERT",
338
339
  "SELF_SIGNED_CERT_IN_CHAIN",
339
340
  "ERR_TLS_CERT_ALTNAME_INVALID",
340
341
  "CERTIFICATE_VERIFY_FAILED",
341
- "SSL"
342
+ // Human-readable messages (lowercase, as returned by Node.js fetch)
343
+ "self-signed certificate",
344
+ "unable to verify",
345
+ "certificate has expired"
342
346
  ];
343
347
  function isTlsError(message) {
344
348
  return TLS_ERROR_PATTERNS.some((p) => message.includes(p));
345
349
  }
350
+ function getRootErrorMessage(err) {
351
+ let current = err;
352
+ let message = "";
353
+ while (current instanceof Error) {
354
+ message = current.message;
355
+ current = current.cause;
356
+ }
357
+ return message;
358
+ }
359
+ function getFullErrorChain(err) {
360
+ const parts = [];
361
+ let current = err;
362
+ while (current instanceof Error) {
363
+ parts.push(current.message);
364
+ const code = current.code;
365
+ if (code) parts.push(code);
366
+ current = current.cause;
367
+ }
368
+ return parts.join(" | ");
369
+ }
346
370
  async function login(serverUrl, opts = {}) {
347
371
  const { verbose = false, insecure = false } = opts;
348
372
  const originalTlsSetting = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
@@ -387,13 +411,14 @@ Server returned ${res.status}. Retrying...`);
387
411
  console.error(`[poll ${i + 1}] ${data?.status ?? "no status"}`);
388
412
  }
389
413
  } catch (err) {
390
- const errMsg = err.message;
414
+ const rootMsg = getRootErrorMessage(err);
415
+ const fullChain = getFullErrorChain(err);
391
416
  if (verbose) {
392
- console.error(`[poll ${i + 1}] network error: ${errMsg}`);
417
+ console.error(`[poll ${i + 1}] network error: ${rootMsg}`);
393
418
  }
394
- if (!insecure && isTlsError(errMsg)) {
419
+ if (!insecure && isTlsError(fullChain)) {
395
420
  console.error(`
396
- TLS certificate error: ${errMsg}`);
421
+ TLS certificate error: ${rootMsg}`);
397
422
  console.error("This looks like a corporate network with TLS interception.");
398
423
  console.error(" try: chapa login --insecure\n");
399
424
  }
@@ -423,7 +448,7 @@ Logged in as ${data.handle}!`);
423
448
  }
424
449
 
425
450
  // src/index.ts
426
- var VERSION = true ? "0.2.4" : "0.0.0-dev";
451
+ var VERSION = true ? "0.2.6" : "0.0.0-dev";
427
452
  var HELP_TEXT = `chapa-cli v${VERSION}
428
453
 
429
454
  Merge GitHub EMU (Enterprise Managed User) contributions into your Chapa badge.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chapa-cli",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Merge GitHub EMU contributions into your Chapa developer impact badge",
5
5
  "type": "module",
6
6
  "bin": {