chapa-cli 0.2.5 → 0.2.7

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 +16 -22
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -323,22 +323,18 @@ var MAX_POLL_ATTEMPTS = 150;
323
323
  function sleep(ms) {
324
324
  return new Promise((resolve) => setTimeout(resolve, ms));
325
325
  }
326
- function restoreTls(insecure, original) {
327
- if (!insecure) return;
328
- if (original === void 0) {
329
- delete process.env.NODE_TLS_REJECT_UNAUTHORIZED;
330
- } else {
331
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = original;
332
- }
333
- }
334
326
  var TLS_ERROR_PATTERNS = [
327
+ // Node.js error codes (uppercase)
335
328
  "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
336
329
  "CERT_HAS_EXPIRED",
337
330
  "DEPTH_ZERO_SELF_SIGNED_CERT",
338
331
  "SELF_SIGNED_CERT_IN_CHAIN",
339
332
  "ERR_TLS_CERT_ALTNAME_INVALID",
340
333
  "CERTIFICATE_VERIFY_FAILED",
341
- "SSL"
334
+ // Human-readable messages (lowercase, as returned by Node.js fetch)
335
+ "self-signed certificate",
336
+ "unable to verify",
337
+ "certificate has expired"
342
338
  ];
343
339
  function isTlsError(message) {
344
340
  return TLS_ERROR_PATTERNS.some((p) => message.includes(p));
@@ -353,22 +349,18 @@ function getRootErrorMessage(err) {
353
349
  return message;
354
350
  }
355
351
  function getFullErrorChain(err) {
356
- const messages = [];
352
+ const parts = [];
357
353
  let current = err;
358
354
  while (current instanceof Error) {
359
- messages.push(current.message);
355
+ parts.push(current.message);
356
+ const code = current.code;
357
+ if (code) parts.push(code);
360
358
  current = current.cause;
361
359
  }
362
- return messages.join(" | ");
360
+ return parts.join(" | ");
363
361
  }
364
362
  async function login(serverUrl, opts = {}) {
365
363
  const { verbose = false, insecure = false } = opts;
366
- const originalTlsSetting = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
367
- if (insecure) {
368
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
369
- console.warn("\n\u26A0 TLS certificate verification disabled (--insecure).");
370
- console.warn(" Use only on corporate networks with TLS interception.\n");
371
- }
372
364
  const baseUrl = serverUrl.replace(/\/+$/, "");
373
365
  const sessionId = randomUUID();
374
366
  const authorizeUrl = `${baseUrl}/cli/authorize?session=${sessionId}`;
@@ -427,22 +419,19 @@ TLS certificate error: ${rootMsg}`);
427
419
  console.log(`
428
420
  Logged in as ${data.handle}!`);
429
421
  console.log("Credentials saved to ~/.chapa/credentials.json");
430
- restoreTls(insecure, originalTlsSetting);
431
422
  return;
432
423
  }
433
424
  if (data?.status === "expired") {
434
- restoreTls(insecure, originalTlsSetting);
435
425
  console.error("\nSession expired. Please try again.");
436
426
  process.exit(1);
437
427
  }
438
428
  }
439
- restoreTls(insecure, originalTlsSetting);
440
429
  console.error("\nTimed out waiting for approval. Please try again.");
441
430
  process.exit(1);
442
431
  }
443
432
 
444
433
  // src/index.ts
445
- var VERSION = true ? "0.2.5" : "0.0.0-dev";
434
+ var VERSION = true ? "0.2.7" : "0.0.0-dev";
446
435
  var HELP_TEXT = `chapa-cli v${VERSION}
447
436
 
448
437
  Merge GitHub EMU (Enterprise Managed User) contributions into your Chapa badge.
@@ -473,6 +462,11 @@ async function main() {
473
462
  console.log(HELP_TEXT);
474
463
  process.exit(0);
475
464
  }
465
+ if (args.insecure) {
466
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
467
+ console.warn("\n\u26A0 TLS certificate verification disabled (--insecure).");
468
+ console.warn(" Use only on corporate networks with TLS interception.\n");
469
+ }
476
470
  if (args.command === "login") {
477
471
  await login(args.server, { verbose: args.verbose, insecure: args.insecure });
478
472
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chapa-cli",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Merge GitHub EMU contributions into your Chapa developer impact badge",
5
5
  "type": "module",
6
6
  "bin": {