wkd-checker 1.1.1 → 1.2.1

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/README.md CHANGED
@@ -22,4 +22,10 @@ wkd.getKey(email)
22
22
  .catch(err => {
23
23
  console.error('Error retrieving key:', err);
24
24
  });
25
+ ```
26
+
27
+ or using the CLI:
28
+
29
+ ```bash
30
+ npx wkd-checker test@example.com
25
31
  ```
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ const index_1 = require("./index");
14
+ // ANSI Colors and Styles
15
+ const RESET = "\x1b[0m";
16
+ const BOLD = "\x1b[1m";
17
+ const DIM = "\x1b[2m";
18
+ const RED = "\x1b[31m";
19
+ const GREEN = "\x1b[32m";
20
+ const CYAN = "\x1b[36m";
21
+ // Symbols
22
+ const CHECK_MARK = "\u2713"; // ✓
23
+ const CROSS_MARK = "\u2717"; // ✗
24
+ const formatStatus = (isValid, label) => {
25
+ if (isValid) {
26
+ return `${GREEN}${CHECK_MARK} ${label}${RESET}`;
27
+ }
28
+ return `${RED}${CROSS_MARK} Invalid${RESET}`;
29
+ };
30
+ const formatBoolean = (val) => val ? formatStatus(true, "Valid") : formatStatus(false, "Invalid");
31
+ const printSection = (title, result) => {
32
+ const isWorking = result.valid;
33
+ const titleColor = isWorking ? GREEN : RED;
34
+ const statusLabel = isWorking ? "Working" : "Not Working";
35
+ const statusBadge = isWorking ? `${GREEN} ${statusLabel} ${RESET}` : `${RED} ${statusLabel} ${RESET}`;
36
+ console.log(`\n${BOLD}${title}${RESET} ${statusBadge}`);
37
+ console.log(`${DIM}------------------------------------------------------------${RESET}`);
38
+ console.log(`Policy Available: ${formatBoolean(result.policyAvailable)}`);
39
+ console.log(`Policy CORS Valid: ${formatBoolean(result.policyCorsValid)}`);
40
+ console.log(`\nKey Location: ${CYAN}${result.key_location || 'N/A'}${RESET}`);
41
+ console.log(`\nKey Available: ${formatBoolean(result.key_available)}`);
42
+ console.log(`Key CORS Valid: ${formatBoolean(result.keyCorsValid)}`);
43
+ console.log(`Key Type: ${result.keyTypeValid ? GREEN : RED}${result.keyType}${RESET}`);
44
+ console.log(`Fingerprint: ${BOLD}${result.fingerprint || 'N/A'}${RESET}`);
45
+ console.log(`Email in Key: ${formatBoolean(result.emailInKey)}`);
46
+ };
47
+ function main() {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const args = process.argv.slice(2);
50
+ const jsonOutput = args.includes('--json');
51
+ const cleanArgs = args.filter((arg) => arg !== '--json');
52
+ if (cleanArgs.length !== 1) {
53
+ console.error(`${RED}Error: Please provide exactly one email address.${RESET}`);
54
+ console.log(`Usage: wkd-checker <email> [--json]`);
55
+ process.exit(1);
56
+ }
57
+ const email = cleanArgs[0];
58
+ if (!jsonOutput) {
59
+ console.log(`Checking WKD status for: ${BOLD}${email}${RESET}...`);
60
+ }
61
+ try {
62
+ const results = yield (0, index_1.checkKey)(email);
63
+ const isOverallValid = results.direct.valid || results.advanced.valid;
64
+ if (jsonOutput) {
65
+ console.log(JSON.stringify(results, null, 2));
66
+ process.exit(isOverallValid ? 0 : 1);
67
+ }
68
+ printSection("Direct Method", results.direct);
69
+ printSection("Advanced Method", results.advanced);
70
+ console.log(`\n${BOLD}Overall Status${RESET}`);
71
+ console.log(`${DIM}------------------------------------------------------------${RESET}`);
72
+ console.log(`Valid: ${formatBoolean(isOverallValid)}`);
73
+ process.exit(isOverallValid ? 0 : 1);
74
+ }
75
+ catch (error) {
76
+ if (jsonOutput) {
77
+ console.error(JSON.stringify({ error: error.message || error }));
78
+ process.exit(1);
79
+ }
80
+ console.error(`\n${RED}${CROSS_MARK} Error:${RESET} ${error.message || error}`);
81
+ process.exit(1);
82
+ }
83
+ });
84
+ }
85
+ main();
package/dist/index.js CHANGED
@@ -28,6 +28,7 @@ class WKDError extends Error {
28
28
  }
29
29
  exports.WKDError = WKDError;
30
30
  const EMAIL_REGEX = /^[^@]+@[^@]+\.[^@]+$/;
31
+ const USER_AGENT = "WKD-Checker (+https://www.npmjs.com/package/wkd-checker)";
31
32
  /**
32
33
  * Validates an email address format.
33
34
  * @param {string} email - The email address to validate.
@@ -183,7 +184,7 @@ const getKey = (email) => __awaiter(void 0, void 0, void 0, function* () {
183
184
  const urls = [advancedUrl, directUrl];
184
185
  for (const url of urls) {
185
186
  try {
186
- const response = yield fetch(url);
187
+ const response = yield fetch(url, { headers: { 'User-Agent': USER_AGENT } });
187
188
  if (response.ok) {
188
189
  return new Uint8Array(yield response.arrayBuffer());
189
190
  }
@@ -203,7 +204,7 @@ exports.getKey = getKey;
203
204
  const checkKey = (email) => __awaiter(void 0, void 0, void 0, function* () {
204
205
  const { advancedUrl, directUrl, advancedPolicyUrl, directPolicyUrl } = yield generateWkdUrls(email);
205
206
  const options = {
206
- headers: { "User-Agent": "WKD-Checker (+https://miarecki.eu/posts/web-key-directory-setup/)" }
207
+ headers: { "User-Agent": USER_AGENT }
207
208
  };
208
209
  const [advancedResult, directResult] = yield Promise.all([
209
210
  checkKeyUrl(advancedUrl, advancedPolicyUrl, options, email),
package/package.json CHANGED
@@ -1,10 +1,29 @@
1
1
  {
2
2
  "name": "wkd-checker",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "description": "Web Key Directory library for Node.js. Retreive OpenPGP keys from WKD servers and validate them.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/JonatanMGit/wkd-checker.git"
8
+ },
9
+ "keywords": [
10
+ "wkd",
11
+ "openpgp",
12
+ "pgp",
13
+ "gpg",
14
+ "keyserver"
15
+ ],
16
+ "homepage": "https://miarecki.eu/tools/wkd-checker/",
17
+ "bugs": {
18
+ "url": "https://github.com/JonatanMGit/wkd-checker/issues"
19
+ },
20
+ "bin": {
21
+ "wkd-checker": "dist/cli.js"
22
+ },
5
23
  "author": "Jonatan Miarecki",
6
24
  "license": "MIT",
7
25
  "devDependencies": {
26
+ "@types/node": "^25.0.6",
8
27
  "typescript": "^5.4.2"
9
28
  },
10
29
  "dependencies": {