@ip2geo/sdk
v0.0.3
Published
Programmatically convert IP's into GEO location data.
Maintainers
Keywords
Readme
Intro to the Npm Package
This package provides a lightweight, type-safe way to integrate Ip2Geo. Blazingly fast and works with Node, Bun, and Deno out of the box.
Installing
npm i @ip2geo/sdk@latestInitializing
import { Init } from '@ip2geo/sdk'
import { Env } from '@/data'
await Init(Env.IP2GEO_API_KEY)Client-Side Usage (Public Keys)
You can use the SDK directly in the browser with public keys. Public keys are tied to a specific domain and don't need to be kept secret.
- Go to your dashboard and navigate to Websites
- Add your domain (e.g.
myapp.com) — a public key (i2g_pk_...) will be generated - Use the public key in your frontend code:
import { Init, ConvertIP } from '@ip2geo/sdk'
await Init('i2g_pk_your_public_key_here')
const result = await ConvertIP({ ip: '8.8.8.8' })The public key only works from the allowed domain. Requests from other origins will be rejected. Usage is tracked per website in your dashboard.
Using
import { ConvertIP, ConvertIPs } from '@ip2geo/sdk'
const convertedIp = await ConvertIP({
ip: '8.8.8.8'
})
const convertedIps = await ConvertIPs({
ips: [
'8.8.8.8',
'1.1.1.1',
'9.9.9.9',
'64.6.64.6'
]
})
// {
// success: boolean
// code: number
// message: string
// data: Ip | null
// _req: {
// reqId: string | null
// resTime: number
// }
// }
// {
// message: string
// code: number
// sucess: boolean
// data: [
// {
// ip: string
// conversion: Ip | null
// }
// ],
// _req: {
// reqId: string | null
// resTime: number
// }
// }