getmyip-pro 0.1.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Soos Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # getmyip-pro (Node.js)
2
+
3
+ Tiny, dependency-free Node.js client **and CLI** for the [getmyip.pro](https://getmyip.pro) IP geolocation API — privacy-first (no logs, no trackers), with ip-api-compatible JSON.
4
+
5
+ > One plan: free. 60 requests/min, 10,000/day, batch up to 100 IPs — no signup,
6
+ > no key. Hit the ceiling? Email tech@getmyip.pro and we'll raise it for you.
7
+
8
+ [![Test](https://github.com/soos-labs/getmyip-js/actions/workflows/test.yml/badge.svg)](https://github.com/soos-labs/getmyip-js/actions/workflows/test.yml)
9
+ [![npm](https://img.shields.io/npm/v/getmyip-pro)](https://www.npmjs.com/package/getmyip-pro)
10
+ ![License: MIT](https://img.shields.io/badge/license-MIT-blue)
11
+
12
+ ## CLI
13
+
14
+ ```sh
15
+ npm install -g getmyip-pro # или npx getmyip-pro
16
+ ```
17
+
18
+ ```console
19
+ $ getmyip
20
+ IP: 45.82.64.40
21
+ Location: Naaldwijk, Netherlands (NL)
22
+ Network: WorldStream B.V. (AS49981)
23
+ Timezone: Europe/Amsterdam
24
+
25
+ $ getmyip 8.8.8.8
26
+ IP: 8.8.8.8
27
+ Location: United States (US)
28
+ Network: Google LLC (AS15169)
29
+
30
+ $ getmyip --field org 8.8.8.8
31
+ Google LLC
32
+
33
+ $ getmyip --json 8.8.8.8
34
+ {"ip":"8.8.8.8","country":"United States",...}
35
+ ```
36
+
37
+ An API key is optional (the anonymous tier needs none); pass `--key` or set `GETMYIP_API_KEY` for higher limits. Point the CLI at a self-hosted instance with `GETMYIP_BASE_URL`.
38
+
39
+ ## Library
40
+
41
+ ```js
42
+ import { Client } from "getmyip-pro";
43
+
44
+ const c = new Client(); // new Client({ apiKey: "..." }) to raise limits
45
+ const me = await c.me(); // your own IP
46
+ const r = await c.lookup("8.8.8.8"); // any IPv4/IPv6
47
+ const rs = await c.batch(["8.8.8.8", "1.1.1.1"]);
48
+
49
+ console.log(r.country, r.org, r.asn); // United States Google LLC 15169
50
+ ```
51
+
52
+ Errors throw `APIError` with `.status` and `.error` (e.g. `rate_limited` — see [limits](https://getmyip.pro/limits)).
53
+
54
+ No dependencies: built-in `fetch` only. Node 18+.
55
+
56
+ ## Related
57
+
58
+ - Go client/CLI: [soos-labs/getmyip-go](https://github.com/soos-labs/getmyip-go)
59
+ - Python client/CLI: [soos-labs/getmyip-python](https://github.com/soos-labs/getmyip-python)
60
+ - API docs: [docs.getmyip.pro](https://docs.getmyip.pro)
package/cli.js ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ // CLI: `getmyip [--json] [--field name] [--key KEY] [ip]` — как у getmyip-go.
3
+
4
+ import { APIError, Client } from "./index.js";
5
+
6
+ function usage() {
7
+ console.error("usage: getmyip [--json] [--field name] [--key KEY] [ip]");
8
+ process.exit(2);
9
+ }
10
+
11
+ const args = process.argv.slice(2);
12
+ let ip, json = false, field, key = process.env.GETMYIP_API_KEY ?? "";
13
+ for (let i = 0; i < args.length; i++) {
14
+ const a = args[i];
15
+ if (a === "--json" || a === "-json") json = true;
16
+ else if (a === "--field" || a === "-field") field = args[++i] ?? usage();
17
+ else if (a === "--key" || a === "-key") key = args[++i] ?? usage();
18
+ else if (a === "--help" || a === "-h") usage();
19
+ else if (a.startsWith("-")) usage();
20
+ else if (ip === undefined) ip = a;
21
+ else usage();
22
+ }
23
+
24
+ try {
25
+ // GETMYIP_BASE_URL — свой инстанс (self-hosted) или мок в тестах
26
+ const c = new Client({ apiKey: key, baseUrl: process.env.GETMYIP_BASE_URL || undefined });
27
+ const r = ip ? await c.lookup(ip) : await c.me();
28
+ if (field !== undefined) {
29
+ if (!(field in r)) {
30
+ console.error(`getmyip: unknown field '${field}'`);
31
+ process.exit(1);
32
+ }
33
+ console.log(r[field]);
34
+ } else if (json) {
35
+ console.log(JSON.stringify(r));
36
+ } else {
37
+ console.log(`IP: ${r.ip}`);
38
+ const loc = [r.city, r.country].filter(Boolean).join(", ");
39
+ if (loc) console.log(`Location: ${loc} (${r.country_code})`);
40
+ if (r.org) console.log(`Network: ${r.org}${r.asn ? ` (AS${r.asn})` : ""}`);
41
+ if (r.timezone) console.log(`Timezone: ${r.timezone}`);
42
+ }
43
+ } catch (e) {
44
+ console.error(`getmyip: ${e instanceof APIError ? e.error || e.status : e.message}`);
45
+ process.exit(1);
46
+ }
package/index.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ export declare const DEFAULT_BASE_URL: string;
2
+ export declare const VERSION: string;
3
+
4
+ /** A single geolocation lookup response (ip-api-compatible field set). */
5
+ export interface Result {
6
+ ip: string;
7
+ ip_version: number;
8
+ is_private: boolean;
9
+ country_code: string;
10
+ country: string;
11
+ region: string;
12
+ city: string;
13
+ postal: string;
14
+ latitude: number;
15
+ longitude: number;
16
+ timezone: string;
17
+ asn: number;
18
+ org: string;
19
+ hostname?: string;
20
+ /** поля, которых клиент ещё не знает, приходят как есть */
21
+ [extra: string]: unknown;
22
+ }
23
+
24
+ /** Non-200 API response; carries HTTP status and the API's error code. */
25
+ export declare class APIError extends Error {
26
+ status: number;
27
+ error: string;
28
+ constructor(status: number, error?: string);
29
+ }
30
+
31
+ export interface ClientOptions {
32
+ /** Optional — the free anonymous tier needs no key; a key raises rate limits. */
33
+ apiKey?: string;
34
+ baseUrl?: string;
35
+ timeoutMs?: number;
36
+ }
37
+
38
+ /** Talks to the getmyip API. */
39
+ export declare class Client {
40
+ apiKey: string;
41
+ baseUrl: string;
42
+ timeoutMs: number;
43
+ constructor(opts?: ClientOptions);
44
+ /** Geolocation for the caller's own public IP. */
45
+ me(): Promise<Result>;
46
+ /** Geolocation for the given IPv4 or IPv6 address. */
47
+ lookup(ip: string): Promise<Result>;
48
+ /** Look up many addresses in a single request. */
49
+ batch(ips: string[]): Promise<Result[]>;
50
+ }
51
+
52
+ export default Client;
package/index.js ADDED
@@ -0,0 +1,71 @@
1
+ // Tiny, dependency-free Node.js client for the getmyip.pro IP geolocation API —
2
+ // privacy-first (no logs, no trackers), ip-api-compatible JSON.
3
+ // See https://getmyip.pro/docs (API at https://api.getmyip.pro). Node 18+ (fetch).
4
+
5
+ export const DEFAULT_BASE_URL = "https://api.getmyip.pro";
6
+ export const VERSION = "0.1.2";
7
+
8
+ /** Non-200 API response; carries HTTP status and the API's error code. */
9
+ export class APIError extends Error {
10
+ constructor(status, error = "") {
11
+ super(`getmyip: ${error || "unexpected status"} (status ${status})`);
12
+ this.name = "APIError";
13
+ this.status = status;
14
+ this.error = error;
15
+ }
16
+ }
17
+
18
+ /**
19
+ * Talks to the getmyip API. An API key is optional — the free anonymous tier
20
+ * needs none; a key (X-API-Key) raises rate limits.
21
+ */
22
+ export class Client {
23
+ /** @param {{apiKey?: string, baseUrl?: string, timeoutMs?: number}} [opts] */
24
+ constructor({ apiKey = "", baseUrl = DEFAULT_BASE_URL, timeoutMs = 10_000 } = {}) {
25
+ this.apiKey = apiKey;
26
+ this.baseUrl = baseUrl.replace(/\/+$/, "");
27
+ this.timeoutMs = timeoutMs;
28
+ }
29
+
30
+ /** Geolocation for the caller's own public IP. */
31
+ me() {
32
+ return this.#request("GET", "/v1/json");
33
+ }
34
+
35
+ /** Geolocation for the given IPv4 or IPv6 address. */
36
+ lookup(ip) {
37
+ return this.#request("GET", "/v1/" + encodeURIComponent(ip));
38
+ }
39
+
40
+ /** Look up many addresses in a single request. */
41
+ async batch(ips) {
42
+ const out = await this.#request("POST", "/v1/batch", { ips });
43
+ return out.results ?? [];
44
+ }
45
+
46
+ async #request(method, path, body) {
47
+ const headers = {
48
+ Accept: "application/json",
49
+ // дефолтные UA скриптов режутся ботозащитой edge — представляемся собой
50
+ "User-Agent": `getmyip-pro-js/${VERSION}`,
51
+ };
52
+ if (body !== undefined) headers["Content-Type"] = "application/json";
53
+ if (this.apiKey) headers["X-API-Key"] = this.apiKey;
54
+ const res = await fetch(this.baseUrl + path, {
55
+ method,
56
+ headers,
57
+ body: body === undefined ? undefined : JSON.stringify(body),
58
+ signal: AbortSignal.timeout(this.timeoutMs),
59
+ });
60
+ if (!res.ok) {
61
+ let err = "";
62
+ try {
63
+ err = (await res.json()).error ?? "";
64
+ } catch {}
65
+ throw new APIError(res.status, err);
66
+ }
67
+ return res.json();
68
+ }
69
+ }
70
+
71
+ export default Client;
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "getmyip-pro",
3
+ "version": "0.1.2",
4
+ "description": "Tiny, dependency-free Node.js client and CLI for the getmyip.pro IP geolocation API",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "exports": "./index.js",
8
+ "bin": {
9
+ "getmyip": "./cli.js"
10
+ },
11
+ "files": [
12
+ "index.js",
13
+ "index.d.ts",
14
+ "cli.js",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "scripts": {
19
+ "test": "node --test"
20
+ },
21
+ "engines": {
22
+ "node": ">=18"
23
+ },
24
+ "keywords": [
25
+ "ip",
26
+ "geolocation",
27
+ "geoip",
28
+ "asn",
29
+ "ip-api"
30
+ ],
31
+ "author": "Soos Labs",
32
+ "license": "MIT",
33
+ "homepage": "https://getmyip.pro",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/soos-labs/getmyip-js.git"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/soos-labs/getmyip-js/issues"
40
+ },
41
+ "types": "./index.d.ts"
42
+ }