@rqt/namecheap-web
@rqt/namecheap-web
is an API to namecheap.com
via the web interface, with an ability to log in using 2-factor Auth and check Whois.
The web API is currently used in the Expensive package to authenticate and white-list IP addresses. This is useful for dynamic-IP holders. Because the API implemented with gzip
compression, the amount of traffic is minimized as well, helping to save data on mobile networks.
yarn add -E @rqt/namecheap-web
Table Of Contents
API
The package is available by importing its default class:
import NamecheapWeb from '@rqt/namecheap-web'
constructor(
options?: Options,
): NamecheapWeb
Create a new instance of the NamecheapWeb class. The sandbox
version can be specified in the options. To remember the session cookies on the local filesystem, the readSession
parameter can be passed. On the production version, the session expires after 20 minutes, but can be renewed after 10 minutes of using an existing session.
Options
: Options for the web client.
Name | Type | Description | Default |
---|
sandbox | boolean | Whether to use the sandbox version. | false |
readSession | boolean | Read and store the cookies for the session from the local file. | false |
sessionFile | string | If reading session, indicates the file where to store cookies. | .namecheap-web.json |
import NamecheapWeb from '@rqt/namecheap-web'
import bosom from 'bosom'
(async () => {
try {
const { username, password } = await bosom('.auth-sandbox.json')
const nw = new NamecheapWeb({
sandbox: true,
readSession: true,
})
await nw.auth(username, password)
const ips = await nw.getWhitelistedIPList()
console.log(JSON.stringify(ips, null, 2))
const ip = await NamecheapWeb.LOOKUP_IP()
await nw.whitelistIP(ip, 'example')
await nw.removeWhitelistedIP('example')
} catch ({ message }) {
console.error(message)
}
})()
[
{
"Name": "expensive 2018-7-23 18-13-04",
"IpAddress": "2.219.56.166",
"ModifyDate": "2018-07-23T17:13:05.200Z"
},
{
"Name": "82.132.224.85",
"IpAddress": "82.132.224.85",
"ModifyDate": "2018-06-14T10:09:21.750Z"
},
{
"Name": "expensive 2018-6-18 19-38-19",
"IpAddress": "82.132.225.170",
"ModifyDate": "2018-06-18T18:38:20.083Z"
},
{
"Name": "expensive 2018-6-22 19-17-06",
"IpAddress": "82.132.246.100",
"ModifyDate": "2018-06-22T18:17:06.770Z"
},
{
"Name": "expensive 2018-6-22 11-54-37",
"IpAddress": "82.132.247.173",
"ModifyDate": "2018-06-22T10:54:37.913Z"
}
]
async auth(
username: string,
password: string,
phone?: string,
): void
Authenticate the app and obtain the cookies. If 2-factor authentication is enabled, it will also be carried out. The phone
argument can be passed which is the last 3 digits of the phone used to receive the confirmation text. If it is not passed, a question will be asked via the CLI. The code should be then entered in the CLI as well.
async static LOOKUP_IP(): string
Get the public IP address using https://api.ipify.org.
async getWhitelistedIPList(
username: string,
password: string,
phone?: string,
): WhitelistedIP[]
Get a list of white-listed IP addresses which can make API calls. The maximum of 20 IP addresses is allowed.
WhitelistedIP
: A white-listed IP which can be used for API calls.
Name | Type | Description |
---|
Name* | string | The name of the IP. |
IpAddress* | string | The IP address. |
ModifyDate* | Date | The modification date. |
async whitelistIP(
ip: string,
name?: string,
): void
Add an IP address to the white-listed IPs. If name is not given, it is automatically generated as rqt {date}
async removeWhitelistedIP(
name: string,
): void
Remove the IP from the white-listed IPs by its name.
Copyright
(c) Rqt 2018