@ipwho/ipwho 1.0.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 +90 -0
- package/dist/index.d.mts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# IPWho TypeScript SDK
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
`ipwho` is an npm-ready TypeScript wrapper around the [IPWho public API](https://ipwho.is/). The client handles API key injection, chooses between `/me` and `/ip/{ip}` automatically, and provides typed helpers (`getLocation`, `getTimezone`, `getConnection`, `getSecurity`) that normalize and narrow the nested payload so you can pull just the information your service needs without re-implementing parsing logic.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
- [Installation](#installation)
|
|
9
|
+
- [Getting Started](#getting-started)
|
|
10
|
+
- [Helper methods](#helper-methods)
|
|
11
|
+
- [Typed responses](#typed-responses)
|
|
12
|
+
- [Forwarding headers](#forwarding-headers)
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install ipwho
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or, if you install via yarn:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
yarn add ipwho
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Getting Started
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { IPWho } from 'ipwho';
|
|
30
|
+
|
|
31
|
+
const client = new IPWho(process.env.IPWHO_API_KEY);
|
|
32
|
+
|
|
33
|
+
// Resolve the caller's IP by default (calls /me)
|
|
34
|
+
const location = await client.getLocation();
|
|
35
|
+
|
|
36
|
+
// Look up another IP
|
|
37
|
+
const armyLocation = await client.getLocation('8.8.8.8');
|
|
38
|
+
|
|
39
|
+
// Use the typed helpers
|
|
40
|
+
const timezone = await client.getTimezone();
|
|
41
|
+
const connection = await client.getConnection();
|
|
42
|
+
const security = await client.getSecurity('1.1.1.1');
|
|
43
|
+
|
|
44
|
+
// Grab raw payloads when needed
|
|
45
|
+
const me = await client.getMe();
|
|
46
|
+
const remote = await client.getIp('1.2.3.4');
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### API key handling
|
|
50
|
+
|
|
51
|
+
- Provide your `apiKey` when constructing the client: `new IPWho('sk_live_XXXX')`.
|
|
52
|
+
- The SDK adds `apiKey` to every request (query param + `X-API-Key` header).
|
|
53
|
+
- Missing keys throw immediately, so you can fail fast in CI.
|
|
54
|
+
|
|
55
|
+
## Helper Methods
|
|
56
|
+
|
|
57
|
+
| Method | Description | Returns |
|
|
58
|
+
| --- | --- | --- |
|
|
59
|
+
| `getLocation(ip?: string)` | Normalized geo data for the requested IP (street-level; defaults to caller). | `GeoLocation` |
|
|
60
|
+
| `getTimezone(ip?: string)` | Timezone metadata, offset, DST, and current time. | `Timezone` |
|
|
61
|
+
| `getConnection(ip?: string)` | ISP connection details (ASN, org, domain, connection type). | `Connection` |
|
|
62
|
+
| `getSecurity(ip?: string)` | VPN/Tor/threat flags and status. | `Security` |
|
|
63
|
+
| `getMe()` | Full raw payload for the caller's IP (identical to `/me`). | `IPWhoData` |
|
|
64
|
+
| `getIp(ip: string)` | Full raw payload for any other IP. | `IPWhoData` |
|
|
65
|
+
|
|
66
|
+
Each helper accepts an optional `ip` parameter. When `ip` is omitted the SDK automatically calls `/me`; when `ip` is provided it calls `/ip/{ip}`.
|
|
67
|
+
|
|
68
|
+
## Typed Responses
|
|
69
|
+
|
|
70
|
+
- `GeoLocation` exports continent, country, coordinates, `dialCode`, and accuracy radius with camel-cased fields that accept both snake_case and camelCase from the API.
|
|
71
|
+
- `Timezone` includes `timeZone`, `abbr`, `offset`, `currentTime`, DST flags, and UTC offset.
|
|
72
|
+
- `Connection`, `Security`, `Currency`, `Flag`, and `UserAgent` wrap nested data (browser/engine/os/device/cpu info, currencies, flags) so you never handle untyped JSON in your application.
|
|
73
|
+
- Refer to `src/types.ts` for the complete interfaces if you need to extend or reconstruct payloads.
|
|
74
|
+
|
|
75
|
+
## Forwarding Headers
|
|
76
|
+
|
|
77
|
+
The SDK no longer injects a `User-Agent` header. When proxying requests (e.g., from a browser) forward relevant headers:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const forwardHeaders = new Headers();
|
|
81
|
+
for (const [key, value] of request.headers) {
|
|
82
|
+
if (['user-agent', 'accept'].includes(key.toLowerCase())) {
|
|
83
|
+
forwardHeaders.set(key, value);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const client = new IPWho(process.env.IPWHO_API_KEY, { headers: forwardHeaders });
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
You can add headers by extending the `fetcher` call if you wrap the client; the SDK focuses on the API key and payload normalization.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface IPWhoResponse {
|
|
2
|
+
success: boolean;
|
|
3
|
+
message?: string;
|
|
4
|
+
data?: any;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare class IPWho {
|
|
9
|
+
private apiKey;
|
|
10
|
+
private baseUrl;
|
|
11
|
+
constructor(apiKey: string);
|
|
12
|
+
private fetcher;
|
|
13
|
+
getIp(ip: string): Promise<IPWhoResponse>;
|
|
14
|
+
getMe(): Promise<IPWhoResponse>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { IPWho, type IPWhoResponse };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface IPWhoResponse {
|
|
2
|
+
success: boolean;
|
|
3
|
+
message?: string;
|
|
4
|
+
data?: any;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare class IPWho {
|
|
9
|
+
private apiKey;
|
|
10
|
+
private baseUrl;
|
|
11
|
+
constructor(apiKey: string);
|
|
12
|
+
private fetcher;
|
|
13
|
+
getIp(ip: string): Promise<IPWhoResponse>;
|
|
14
|
+
getMe(): Promise<IPWhoResponse>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { IPWho, type IPWhoResponse };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var a=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var f=(s,e)=>{for(var r in e)a(s,r,{get:e[r],enumerable:!0})},g=(s,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of h(e))!c.call(s,t)&&t!==r&&a(s,t,{get:()=>e[t],enumerable:!(i=p(e,t))||i.enumerable});return s};var y=s=>g(a({},"__esModule",{value:!0}),s);var u={};f(u,{IPWho:()=>n});module.exports=y(u);var n=class{constructor(e){this.baseUrl="https://api.ipwho.org";if(!e)throw new Error("API Key is required");this.apiKey=e}async fetcher(e){let r=e.includes("?")?"&":"?",i=`${this.baseUrl}${e}${r}apiKey=${this.apiKey}`,o=await(await fetch(i,{headers:{"X-API-Key":this.apiKey,"User-Agent":"ipwho-node-sdk/1.0.0"}})).json();if(!o.success)throw new Error(o.message||"Request failed");return o.data}async getIp(e){return this.fetcher(`/ip/${e}`)}async getMe(){return this.fetcher("/me")}};0&&(module.exports={IPWho});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var r=class{constructor(e){this.baseUrl="https://api.ipwho.org";if(!e)throw new Error("API Key is required");this.apiKey=e}async fetcher(e){let t=e.includes("?")?"&":"?",i=`${this.baseUrl}${e}${t}apiKey=${this.apiKey}`,s=await(await fetch(i,{headers:{"X-API-Key":this.apiKey,"User-Agent":"ipwho-node-sdk/1.0.0"}})).json();if(!s.success)throw new Error(s.message||"Request failed");return s.data}async getIp(e){return this.fetcher(`/ip/${e}`)}async getMe(){return this.fetcher("/me")}};export{r as IPWho};
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ipwho/ipwho",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "SDK for IPWho API",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsup src/index.ts --format cjs,esm --minify --dts",
|
|
9
|
+
"test": "vitest run"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@types/node": "^25.2.1",
|
|
13
|
+
"tsup": "^8.5.1",
|
|
14
|
+
"typescript": "^5.0.0",
|
|
15
|
+
"vitest": "^1.0.0"
|
|
16
|
+
}
|
|
17
|
+
}
|