@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, check Whois and retrieve a coupon code.
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[0], null, 2))
const ip = await NamecheapWeb.LOOKUP_IP()
await nw.whitelistIP(ip, 'example')
await nw.removeWhitelistedIP('example')
} catch ({ message }) {
console.error(message)
}
})()
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 static WHOIS(domain): string
Return WHOIS data for the domain.
import NamecheapWeb from '@rqt/namecheap-web'
(async () => {
try {
const res = await NamecheapWeb.WHOIS('test.org')
console.log(res)
} catch ({ message }) {
console.error(message)
}
})()
Show whois data
Domain Name: TEST.ORG
Registry Domain ID: D380528-LROR
Registrar WHOIS Server: whois.psi-usa.info
Registrar URL: http://www.psi-usa.info
Updated Date: 2018-07-27T01:28:31Z
Creation Date: 1997-07-27T04:00:00Z
Registry Expiry Date: 2019-07-26T04:00:00Z
Registrar Registration Expiration Date:
Registrar: PSI-USA, Inc. dba Domain Robot
Registrar IANA ID: 151
Registrar Abuse Contact Email: domain-abuse@psi-usa.info
Registrar Abuse Contact Phone: +49.94159559482
Reseller:
Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
Registrant Organization: TMT Teleservice GmbH & Co.KG
Registrant State/Province: Bayern
Registrant Country: DE
Name Server: NS0.TMT.DE
Name Server: NS4.TMT.DE
Name Server: NS3.TMT.DE
Name Server: NS2.TMT.DE
Name Server: NS1.TMT.DE
DNSSEC: unsigned
URL of the ICANN Whois Inaccuracy Complaint Form https://www.icann.org/wicf/)
>>> Last update of WHOIS database: 2018-10-06T01:22:28Z
async static COUPON(): string
Returns this month's coupon from the https://www.namecheap.com/promos/coupons/ page.
import NamecheapWeb from '@rqt/namecheap-web'
(async () => {
try {
const res = await NamecheapWeb.COUPON()
console.log(res)
} catch ({ message }) {
console.error(message)
}
})()
ZOMBIETLD
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