@datasentry/cli 1.0.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/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # DataSentry CLI
2
+
3
+ High-performance IP intelligence from your terminal. Look up geolocation, threat scores, and API usage.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g @datasentry/cli
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```bash
14
+ # Authenticate
15
+ datasentry auth <your_api_key>
16
+
17
+ # Lookup your own IP
18
+ datasentry lookup
19
+
20
+ # Lookup a specific IP
21
+ datasentry lookup 8.8.8.8
22
+
23
+ # Output JSON
24
+ datasentry lookup 8.8.8.8 --json
25
+
26
+ # Check API usage
27
+ datasentry usage
28
+ ```
29
+
30
+ ## Commands
31
+
32
+ | Command | Description |
33
+ |---------|-------------|
34
+ | `datasentry auth [key]` | Save your API key locally |
35
+ | `datasentry lookup [ip]` | Geolocation and threat intelligence |
36
+ | `datasentry usage` | Check remaining API credits |
37
+ | `datasentry bulk <file>` | Batch IP lookups (coming soon) |
38
+ | `datasentry logout` | Clear local credentials |
39
+
40
+ ## Configuration
41
+
42
+ Set your API key via environment variable instead of `auth`:
43
+
44
+ ```bash
45
+ export DATASENTRY_API_KEY="your_key_here"
46
+ ```
47
+
48
+ ## License
49
+
50
+ Proprietary. See [LICENSE](../LICENSE) for details.
package/dist/client.js ADDED
@@ -0,0 +1,27 @@
1
+ import axios from "axios";
2
+ export class DataSentryClient {
3
+ client;
4
+ constructor(apiKey, baseUrl = "https://api.datasentry.site") {
5
+ this.client = axios.create({
6
+ baseURL: baseUrl,
7
+ headers: {
8
+ "x-api-key": apiKey,
9
+ "User-Agent": "DataSentry-CLI/1.0.0",
10
+ },
11
+ });
12
+ }
13
+ async lookup(ip) {
14
+ const response = await this.client.get("/v1/lookup", {
15
+ params: ip ? { ip } : {},
16
+ });
17
+ return response.data;
18
+ }
19
+ async usage() {
20
+ const response = await this.client.get("/v1/usage");
21
+ return response.data;
22
+ }
23
+ async bulk(ips) {
24
+ const response = await this.client.post("/v1/bulk", { ips });
25
+ return response.data;
26
+ }
27
+ }
package/dist/index.js ADDED
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import chalk from "chalk";
4
+ import ora from "ora";
5
+ import Table from "cli-table3";
6
+ import Conf from "conf";
7
+ import { DataSentryClient } from "./client.js";
8
+ const config = new Conf({ projectName: "datasentry" });
9
+ const program = new Command();
10
+ const BANNER = `
11
+ ██████╗ █████╗ ████████╗ █████╗ ███████╗███████╗███╗ ██╗████████╗██████╗ ██╗ ██╗
12
+ ██╔══██╗██╔══██╗╚══██╔══╝██╔══██╗ ██╔════╝██╔════╝████╗ ██║╚══██╔══╝██╔══██╗╚██╗ ██╔╝
13
+ ██║ ██║███████║ ██║ ███████║ ███████╗█████╗ ██╔██╗ ██║ ██║ ██████╔╝ ╚████╔╝
14
+ ██║ ██║██╔══██║ ██║ ██╔══██║ ╚════██║██╔══╝ ██║╚██╗██║ ██║ ██╔══██╗ ╚██╔╝
15
+ ██████╔╝██║ ██║ ██║ ██║ ██║ ███████║███████╗██║ ╚████║ ██║ ██║ ██║ ██║
16
+ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
17
+ `;
18
+ function printBanner() {
19
+ console.log(chalk.white(BANNER));
20
+ }
21
+ program
22
+ .name("datasentry")
23
+ .description("DataSentry CLI - High-performance IP Intelligence & Geolocation")
24
+ .version("1.0.0");
25
+ program
26
+ .command("lookup")
27
+ .description("Lookup geolocation and security insights for an IP address")
28
+ .argument("[ip]", "The IP address to lookup (defaults to your current IP)")
29
+ .option("--json", "Output results in JSON format")
30
+ .option("-u, --base-url <url>", "API base URL (default: https://api.datasentry.site)")
31
+ .action(async (ip, options) => {
32
+ if (!options.json)
33
+ printBanner();
34
+ const apiKey = process.env.DATASENTRY_API_KEY || config.get("apiKey");
35
+ if (!apiKey) {
36
+ console.error(chalk.red("Error: API Key is required. Run 'datasentry auth' or set DATASENTRY_API_KEY."));
37
+ process.exit(1);
38
+ }
39
+ const baseUrl = options.baseUrl || config.get("baseUrl") || process.env.DATASENTRY_BASE_URL || "https://api.datasentry.site";
40
+ const spinner = !options.json ? ora(`Looking up ${ip || "your IP"}...`).start() : null;
41
+ const client = new DataSentryClient(apiKey, baseUrl);
42
+ try {
43
+ const data = await client.lookup(ip);
44
+ spinner?.succeed("Lookup complete.");
45
+ if (options.json) {
46
+ console.log(JSON.stringify(data, null, 2));
47
+ }
48
+ else {
49
+ console.log(`\n${chalk.bold("--- DataSentry Lookup: " + data.ip + " ---")}`);
50
+ console.log(`${chalk.cyan("Location:")} ${data.location.city}, ${data.location.region}, ${data.location.country_name}`);
51
+ console.log(`${chalk.cyan("Security Score:")} ${formatScore(data.security.threat_score)}`);
52
+ console.log(`${chalk.cyan("Risk Level:")} ${data.security.risk_level.toUpperCase()}`);
53
+ console.log(`${chalk.cyan("Timezone:")} ${data.location.timezone}\n`);
54
+ }
55
+ }
56
+ catch (error) {
57
+ spinner?.fail("Lookup failed.");
58
+ console.error(chalk.red(`Error: ${error.response?.data?.detail || error.message}`));
59
+ process.exit(1);
60
+ }
61
+ });
62
+ program
63
+ .command("usage")
64
+ .description("Check your API usage and remaining credits")
65
+ .option("-u, --base-url <url>", "API base URL (default: https://api.datasentry.site)")
66
+ .action(async (options) => {
67
+ printBanner();
68
+ const apiKey = process.env.DATASENTRY_API_KEY || config.get("apiKey");
69
+ if (!apiKey) {
70
+ console.error(chalk.red("Error: API Key is required. Run 'datasentry auth'."));
71
+ process.exit(1);
72
+ }
73
+ const baseUrl = options.baseUrl || config.get("baseUrl") || process.env.DATASENTRY_BASE_URL || "https://api.datasentry.site";
74
+ const spinner = ora("Fetching usage data...").start();
75
+ const client = new DataSentryClient(apiKey, baseUrl);
76
+ try {
77
+ const data = await client.usage();
78
+ spinner.succeed("Usage data retrieved.");
79
+ const table = new Table({
80
+ head: [chalk.cyan("Metric"), chalk.cyan("Value")],
81
+ colWidths: [20, 30],
82
+ });
83
+ table.push(["Credits Used", data.credits_used], ["Credits Remaining", data.credits_remaining], ["Reset Time", new Date(data.reset_time).toLocaleString()]);
84
+ console.log(table.toString());
85
+ }
86
+ catch (error) {
87
+ spinner.fail("Failed to fetch usage data.");
88
+ console.error(chalk.red(`Error: ${error.response?.data?.detail || error.message}`));
89
+ process.exit(1);
90
+ }
91
+ });
92
+ program
93
+ .command("auth")
94
+ .description("Authenticate the CLI with your DataSentry API Key")
95
+ .argument("[key]", "Your DataSentry API Key")
96
+ .option("-u, --base-url <url>", "API base URL (default: https://api.datasentry.site)")
97
+ .action((key, options) => {
98
+ printBanner();
99
+ if (key) {
100
+ config.set("apiKey", key);
101
+ if (options.baseUrl) {
102
+ config.set("baseUrl", options.baseUrl);
103
+ }
104
+ console.log(chalk.green("Success! API Key saved.\n"));
105
+ console.log(chalk.bold("What's next?"));
106
+ console.log(`- ${chalk.cyan("datasentry lookup")} Check your own IP intelligence`);
107
+ console.log(`- ${chalk.cyan("datasentry lookup <ip>")} Lookup a specific IP address`);
108
+ console.log(`- ${chalk.cyan("datasentry usage")} View your credit balance`);
109
+ console.log(`- ${chalk.cyan("datasentry logout")} Clear local credentials\n`);
110
+ }
111
+ else {
112
+ console.log(chalk.yellow("\nTo authenticate, please get your API key from https://datasentry.site/dashboard\n"));
113
+ console.log(`Run ${chalk.bold("datasentry auth <your_key>")} to save it.\n`);
114
+ console.log(chalk.bold("Available Features & Commands:"));
115
+ console.log(`• ${chalk.white("IP Geolocation")} ${chalk.cyan("datasentry lookup [ip]")}`);
116
+ console.log(`• ${chalk.white("Threat Intelligence")} ${chalk.cyan("datasentry lookup")}`);
117
+ console.log(`• ${chalk.white("Bulk IP Analysis")} ${chalk.cyan("datasentry bulk <file>")}`);
118
+ console.log(`• ${chalk.white("Quota Management")} ${chalk.cyan("datasentry usage")}`);
119
+ console.log(`• ${chalk.white("JSON Export")} ${chalk.cyan("datasentry lookup --json")}\n`);
120
+ }
121
+ });
122
+ program
123
+ .command("bulk")
124
+ .description("Perform batch IP lookups from a file")
125
+ .argument("<file>", "Path to a text or CSV file containing IPs")
126
+ .action(async (file) => {
127
+ printBanner();
128
+ console.log(chalk.yellow(`\nBulk lookup for ${file} is currently being optimized.`));
129
+ console.log(chalk.white("This feature will be available in the next minor release.\n"));
130
+ });
131
+ program
132
+ .command("logout")
133
+ .description("Clear local credentials")
134
+ .action(() => {
135
+ printBanner();
136
+ config.delete("apiKey");
137
+ config.delete("baseUrl");
138
+ console.log(chalk.green("Logged out successfully. Local credentials cleared."));
139
+ });
140
+ function formatScore(score) {
141
+ if (score <= 20)
142
+ return chalk.green(score);
143
+ if (score <= 60)
144
+ return chalk.yellow(score);
145
+ return chalk.red(score);
146
+ }
147
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@datasentry/cli",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "description": "High-performance IP intelligence CLI tool for geolocation and threat scoring.",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "datasentry": "dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "keywords": [
16
+ "ip",
17
+ "geolocation",
18
+ "cli",
19
+ "threat-intelligence",
20
+ "security",
21
+ "datasentry"
22
+ ],
23
+ "author": "DataSentry Team",
24
+ "license": "SEE LICENSE IN LICENSE",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/datasentry/DataSentry.Site.git",
28
+ "directory": "cli"
29
+ },
30
+ "homepage": "https://datasentry.site",
31
+ "bugs": {
32
+ "url": "https://github.com/datasentry/DataSentry.Site/issues"
33
+ },
34
+ "engines": {
35
+ "node": ">=18"
36
+ },
37
+ "dependencies": {
38
+ "axios": "^1.15.2",
39
+ "chalk": "^5.4.1",
40
+ "cli-progress": "^3.12.0",
41
+ "cli-table3": "^0.6.5",
42
+ "commander": "^13.1.0",
43
+ "conf": "^12.0.0",
44
+ "ora": "^8.1.1"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^25.6.0",
48
+ "typescript": "^6.0.3",
49
+ "vitest": "^4.1.5"
50
+ },
51
+ "scripts": {
52
+ "build": "tsc",
53
+ "test": "npm run build && vitest run",
54
+ "start": "node dist/index.js"
55
+ }
56
+ }