initial
This commit is contained in:
100
ts/config.ts
Normal file
100
ts/config.ts
Normal file
@ -0,0 +1,100 @@
|
||||
/**
|
||||
* Namecheap API Client - Configuration
|
||||
*/
|
||||
import type { INamecheapAuth } from './types.js';
|
||||
|
||||
export class NamecheapConfig implements INamecheapAuth {
|
||||
// Required authentication properties
|
||||
apiUser: string;
|
||||
apiKey: string;
|
||||
userName: string;
|
||||
clientIp: string;
|
||||
|
||||
// API endpoint configuration
|
||||
baseUrl: string = 'https://api.namecheap.com/xml.response';
|
||||
|
||||
// Whether to use sandbox environment (for testing)
|
||||
useSandbox: boolean = false;
|
||||
|
||||
// Default request timeout in milliseconds
|
||||
timeout: number = 30000;
|
||||
|
||||
/**
|
||||
* Create a new Namecheap API configuration
|
||||
*/
|
||||
constructor(config: INamecheapAuth) {
|
||||
this.apiUser = config.apiUser;
|
||||
this.apiKey = config.apiKey;
|
||||
this.userName = config.userName || config.apiUser; // Default userName to apiUser if not provided
|
||||
this.clientIp = config.clientIp;
|
||||
|
||||
this.validateConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate configuration parameters
|
||||
* @throws Error if configuration is invalid
|
||||
*/
|
||||
private validateConfig(): void {
|
||||
if (!this.apiUser) {
|
||||
throw new Error('Namecheap API User is required');
|
||||
}
|
||||
|
||||
if (!this.apiKey) {
|
||||
throw new Error('Namecheap API Key is required');
|
||||
}
|
||||
|
||||
if (!this.userName) {
|
||||
throw new Error('Namecheap User Name is required');
|
||||
}
|
||||
|
||||
if (!this.clientIp) {
|
||||
throw new Error('Client IP address is required');
|
||||
}
|
||||
|
||||
// Validate IP address format
|
||||
const ipRegex = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
|
||||
if (!ipRegex.test(this.clientIp)) {
|
||||
throw new Error('Invalid IP address format');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable sandbox mode for testing
|
||||
*/
|
||||
enableSandbox(): void {
|
||||
this.useSandbox = true;
|
||||
this.baseUrl = 'https://api.sandbox.namecheap.com/xml.response';
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable sandbox mode
|
||||
*/
|
||||
disableSandbox(): void {
|
||||
this.useSandbox = false;
|
||||
this.baseUrl = 'https://api.namecheap.com/xml.response';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set request timeout
|
||||
* @param ms Timeout in milliseconds
|
||||
*/
|
||||
setTimeout(ms: number): void {
|
||||
this.timeout = ms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get base parameters that should be included in every API request
|
||||
* @param command API command to execute
|
||||
* @returns Base parameters object
|
||||
*/
|
||||
getBaseParams(command: string): Record<string, string | number> {
|
||||
return {
|
||||
ApiUser: this.apiUser,
|
||||
ApiKey: this.apiKey,
|
||||
UserName: this.userName,
|
||||
ClientIp: this.clientIp,
|
||||
Command: command
|
||||
};
|
||||
}
|
||||
}
|
245
ts/domains-dns.ts
Normal file
245
ts/domains-dns.ts
Normal file
@ -0,0 +1,245 @@
|
||||
/**
|
||||
* Namecheap API Client - Domains DNS Module
|
||||
*/
|
||||
import { HttpClient } from './http-client.js';
|
||||
import type {
|
||||
IDnsDomainHostsResponse,
|
||||
IDnsHost,
|
||||
IDnsSetHostsResponse,
|
||||
IDnsSetCustomResponse,
|
||||
IDnsGetEmailForwardingResponse,
|
||||
IDnsSetEmailForwardingResponse,
|
||||
IDnsGetListResponse,
|
||||
IDnsRecord
|
||||
} from './types.js';
|
||||
|
||||
export class DomainsDns {
|
||||
private client: HttpClient;
|
||||
|
||||
/**
|
||||
* Create a new Domains DNS API handler
|
||||
* @param client HTTP client instance
|
||||
*/
|
||||
constructor(client: HttpClient) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of DNS hosts for a domain
|
||||
* @param domainName Domain name to get hosts for
|
||||
* @param sld Second-level domain (optional)
|
||||
* @param tld Top-level domain (optional)
|
||||
* @returns Array of DNS host records
|
||||
*/
|
||||
async getHosts(domainName: string, sld?: string, tld?: string): Promise<IDnsHost[]> {
|
||||
// Prepare the request parameters
|
||||
const params: Record<string, string> = {};
|
||||
|
||||
// If SLD and TLD are provided, use them instead of DomainName
|
||||
if (sld && tld) {
|
||||
params.SLD = sld;
|
||||
params.TLD = tld;
|
||||
} else {
|
||||
params.DomainName = domainName;
|
||||
}
|
||||
|
||||
// Make the API request
|
||||
const response = await this.client.request<IDnsDomainHostsResponse>(
|
||||
'namecheap.domains.dns.getHosts',
|
||||
params
|
||||
);
|
||||
|
||||
// Extract host records from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const hosts = commandResponse.DomainDNSGetHostsResult[0].host || [];
|
||||
|
||||
// Convert the parsed XML structure to a more usable format
|
||||
return hosts.map(host => ({
|
||||
id: parseInt(host.$.HostId, 10),
|
||||
name: host.$.Name,
|
||||
type: host.$.Type,
|
||||
address: host.$.Address,
|
||||
mxPref: host.$.MXPref ? parseInt(host.$.MXPref, 10) : 0,
|
||||
ttl: parseInt(host.$.TTL, 10),
|
||||
isActive: host.$.IsActive?.toLowerCase() === 'true',
|
||||
isDDNSEnabled: host.$.IsDDNSEnabled?.toLowerCase() === 'true'
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set DNS host records for a domain
|
||||
* @param domainName Domain name to set hosts for
|
||||
* @param hosts Array of host records to set
|
||||
* @param sld Second-level domain (optional)
|
||||
* @param tld Top-level domain (optional)
|
||||
* @returns Success status
|
||||
*/
|
||||
async setHosts(
|
||||
domainName: string,
|
||||
hosts: Array<{
|
||||
hostName: string;
|
||||
recordType: 'A' | 'AAAA' | 'CNAME' | 'MX' | 'TXT' | 'URL' | 'FRAME' | 'NS';
|
||||
address: string;
|
||||
mxPref?: number;
|
||||
ttl?: number;
|
||||
}>,
|
||||
sld?: string,
|
||||
tld?: string
|
||||
): Promise<boolean> {
|
||||
// Prepare the request parameters
|
||||
const params: Record<string, string | number> = {};
|
||||
|
||||
// If SLD and TLD are provided, use them instead of DomainName
|
||||
if (sld && tld) {
|
||||
params.SLD = sld;
|
||||
params.TLD = tld;
|
||||
} else {
|
||||
params.DomainName = domainName;
|
||||
}
|
||||
|
||||
// Add host records to the parameters
|
||||
hosts.forEach((host, index) => {
|
||||
params[`HostName${index + 1}`] = host.hostName;
|
||||
params[`RecordType${index + 1}`] = host.recordType;
|
||||
params[`Address${index + 1}`] = host.address;
|
||||
|
||||
if (host.mxPref !== undefined) {
|
||||
params[`MXPref${index + 1}`] = host.mxPref;
|
||||
}
|
||||
|
||||
if (host.ttl !== undefined) {
|
||||
params[`TTL${index + 1}`] = host.ttl;
|
||||
}
|
||||
});
|
||||
|
||||
// Make the API request
|
||||
const response = await this.client.request<IDnsSetHostsResponse>(
|
||||
'namecheap.domains.dns.setHosts',
|
||||
params
|
||||
);
|
||||
|
||||
// Check if the operation was successful
|
||||
return response.ApiResponse.$.Status === 'OK';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom nameservers for a domain
|
||||
* @param domainName Domain name to set nameservers for
|
||||
* @param nameservers Array of nameserver hostnames
|
||||
* @param sld Second-level domain (optional)
|
||||
* @param tld Top-level domain (optional)
|
||||
* @returns Success status
|
||||
*/
|
||||
async setCustom(
|
||||
domainName: string,
|
||||
nameservers: string[],
|
||||
sld?: string,
|
||||
tld?: string
|
||||
): Promise<boolean> {
|
||||
// Prepare the request parameters
|
||||
const params: Record<string, string> = {};
|
||||
|
||||
// If SLD and TLD are provided, use them instead of DomainName
|
||||
if (sld && tld) {
|
||||
params.SLD = sld;
|
||||
params.TLD = tld;
|
||||
} else {
|
||||
params.DomainName = domainName;
|
||||
}
|
||||
|
||||
// Add nameservers to the parameters
|
||||
params.Nameservers = nameservers.join(',');
|
||||
|
||||
// Make the API request
|
||||
const response = await this.client.request<IDnsSetCustomResponse>(
|
||||
'namecheap.domains.dns.setCustom',
|
||||
params
|
||||
);
|
||||
|
||||
// Check if the operation was successful
|
||||
return response.ApiResponse.$.Status === 'OK';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email forwarding settings for a domain
|
||||
* @param domainName Domain name to get email forwarding for
|
||||
* @returns Email forwarding settings
|
||||
*/
|
||||
async getEmailForwarding(domainName: string): Promise<Array<{
|
||||
from: string;
|
||||
to: string;
|
||||
}>> {
|
||||
// Make the API request
|
||||
const response = await this.client.request<IDnsGetEmailForwardingResponse>(
|
||||
'namecheap.domains.dns.getEmailForwarding',
|
||||
{ DomainName: domainName }
|
||||
);
|
||||
|
||||
// Extract email forwarding settings from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const forwardings = commandResponse.DomainDNSGetEmailForwardingResult[0].forward || [];
|
||||
|
||||
// Convert the parsed XML structure to a more usable format
|
||||
return forwardings.map(forward => ({
|
||||
from: forward.$.from,
|
||||
to: forward.$.to
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email forwarding settings for a domain
|
||||
* @param domainName Domain name to set email forwarding for
|
||||
* @param forwardings Array of email forwarding settings
|
||||
* @returns Success status
|
||||
*/
|
||||
async setEmailForwarding(
|
||||
domainName: string,
|
||||
forwardings: Array<{
|
||||
from: string;
|
||||
to: string;
|
||||
}>
|
||||
): Promise<boolean> {
|
||||
// Prepare the request parameters
|
||||
const params: Record<string, string> = {
|
||||
DomainName: domainName
|
||||
};
|
||||
|
||||
// Add email forwarding settings to the parameters
|
||||
forwardings.forEach((forward, index) => {
|
||||
params[`MailBox${index + 1}`] = forward.from;
|
||||
params[`ForwardTo${index + 1}`] = forward.to;
|
||||
});
|
||||
|
||||
// Make the API request
|
||||
const response = await this.client.request<IDnsSetEmailForwardingResponse>(
|
||||
'namecheap.domains.dns.setEmailForwarding',
|
||||
params
|
||||
);
|
||||
|
||||
// Check if the operation was successful
|
||||
return response.ApiResponse.$.Status === 'OK';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of DNS servers for a domain
|
||||
* @param sld Second-level domain
|
||||
* @param tld Top-level domain
|
||||
* @returns Array of DNS server names
|
||||
*/
|
||||
async getList(sld: string, tld: string): Promise<string[]> {
|
||||
// Make the API request
|
||||
const response = await this.client.request<IDnsGetListResponse>(
|
||||
'namecheap.domains.dns.getList',
|
||||
{
|
||||
SLD: sld,
|
||||
TLD: tld
|
||||
}
|
||||
);
|
||||
|
||||
// Extract DNS server list from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const dnsServers = commandResponse.DomainDNSGetListResult[0].Nameserver || [];
|
||||
|
||||
return dnsServers;
|
||||
}
|
||||
}
|
130
ts/domains-ns.ts
Normal file
130
ts/domains-ns.ts
Normal file
@ -0,0 +1,130 @@
|
||||
/**
|
||||
* Namecheap API Client - Domains Nameservers Module
|
||||
*/
|
||||
import { HttpClient } from './http-client.js';
|
||||
import type {
|
||||
INsCreateResponse,
|
||||
INsDeleteResponse,
|
||||
INsGetInfoResponse,
|
||||
INsUpdateResponse,
|
||||
INsInfo
|
||||
} from './types.js';
|
||||
|
||||
export class DomainsNs {
|
||||
private client: HttpClient;
|
||||
|
||||
/**
|
||||
* Create a new Domains Nameservers API handler
|
||||
* @param client HTTP client instance
|
||||
*/
|
||||
constructor(client: HttpClient) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new nameserver
|
||||
* @param sld Second-level domain
|
||||
* @param tld Top-level domain
|
||||
* @param nameserver Nameserver hostname
|
||||
* @param ip Nameserver IP address
|
||||
* @returns Success status
|
||||
*/
|
||||
async create(sld: string, tld: string, nameserver: string, ip: string): Promise<boolean> {
|
||||
// Make the API request
|
||||
const response = await this.client.request<INsCreateResponse>(
|
||||
'namecheap.domains.ns.create',
|
||||
{
|
||||
SLD: sld,
|
||||
TLD: tld,
|
||||
Nameserver: nameserver,
|
||||
IP: ip
|
||||
}
|
||||
);
|
||||
|
||||
// Check if the operation was successful
|
||||
return response.ApiResponse.$.Status === 'OK';
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a nameserver
|
||||
* @param sld Second-level domain
|
||||
* @param tld Top-level domain
|
||||
* @param nameserver Nameserver hostname
|
||||
* @returns Success status
|
||||
*/
|
||||
async delete(sld: string, tld: string, nameserver: string): Promise<boolean> {
|
||||
// Make the API request
|
||||
const response = await this.client.request<INsDeleteResponse>(
|
||||
'namecheap.domains.ns.delete',
|
||||
{
|
||||
SLD: sld,
|
||||
TLD: tld,
|
||||
Nameserver: nameserver
|
||||
}
|
||||
);
|
||||
|
||||
// Check if the operation was successful
|
||||
return response.ApiResponse.$.Status === 'OK';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about a nameserver
|
||||
* @param sld Second-level domain
|
||||
* @param tld Top-level domain
|
||||
* @param nameserver Nameserver hostname
|
||||
* @returns Nameserver information
|
||||
*/
|
||||
async getInfo(sld: string, tld: string, nameserver: string): Promise<INsInfo> {
|
||||
// Make the API request
|
||||
const response = await this.client.request<INsGetInfoResponse>(
|
||||
'namecheap.domains.ns.getInfo',
|
||||
{
|
||||
SLD: sld,
|
||||
TLD: tld,
|
||||
Nameserver: nameserver
|
||||
}
|
||||
);
|
||||
|
||||
// Extract nameserver information from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const nsInfo = commandResponse.DomainNSInfoResult[0].$;
|
||||
|
||||
return {
|
||||
nameserver: nsInfo.Nameserver,
|
||||
ip: nsInfo.IP,
|
||||
statuses: nsInfo.Statuses?.split(',') || []
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a nameserver's IP address
|
||||
* @param sld Second-level domain
|
||||
* @param tld Top-level domain
|
||||
* @param nameserver Nameserver hostname
|
||||
* @param oldIp Old IP address
|
||||
* @param newIp New IP address
|
||||
* @returns Success status
|
||||
*/
|
||||
async update(
|
||||
sld: string,
|
||||
tld: string,
|
||||
nameserver: string,
|
||||
oldIp: string,
|
||||
newIp: string
|
||||
): Promise<boolean> {
|
||||
// Make the API request
|
||||
const response = await this.client.request<INsUpdateResponse>(
|
||||
'namecheap.domains.ns.update',
|
||||
{
|
||||
SLD: sld,
|
||||
TLD: tld,
|
||||
Nameserver: nameserver,
|
||||
OldIP: oldIp,
|
||||
IP: newIp
|
||||
}
|
||||
);
|
||||
|
||||
// Check if the operation was successful
|
||||
return response.ApiResponse.$.Status === 'OK';
|
||||
}
|
||||
}
|
261
ts/domains-transfer.ts
Normal file
261
ts/domains-transfer.ts
Normal file
@ -0,0 +1,261 @@
|
||||
/**
|
||||
* Namecheap API Client - Domains Transfer Module
|
||||
*/
|
||||
import { HttpClient } from './http-client.js';
|
||||
import type {
|
||||
ITransferGetListResponse,
|
||||
ITransferGetStatusResponse,
|
||||
ITransferCreateResponse,
|
||||
ITransferUpdateStatusResponse,
|
||||
ITransferGetInfoResponse,
|
||||
ITransferInfo,
|
||||
ITransferStatusInfo
|
||||
} from './types.js';
|
||||
|
||||
export class DomainsTransfer {
|
||||
private client: HttpClient;
|
||||
|
||||
/**
|
||||
* Create a new Domains Transfer API handler
|
||||
* @param client HTTP client instance
|
||||
*/
|
||||
constructor(client: HttpClient) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of domain transfers
|
||||
* @param page Page number
|
||||
* @param pageSize Number of items per page
|
||||
* @param listType Type of transfers to list
|
||||
* @returns List of domain transfers
|
||||
*/
|
||||
async getList(
|
||||
page: number = 1,
|
||||
pageSize: number = 20,
|
||||
listType: 'ALL' | 'INPROGRESS' | 'COMPLETED' | 'FAILED' = 'ALL'
|
||||
): Promise<{
|
||||
transfers: ITransferInfo[];
|
||||
paging: {
|
||||
totalItems: number;
|
||||
currentPage: number;
|
||||
pageSize: number;
|
||||
};
|
||||
}> {
|
||||
// Make the API request
|
||||
const response = await this.client.request<ITransferGetListResponse>(
|
||||
'namecheap.domains.transfer.getList',
|
||||
{
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
ListType: listType
|
||||
}
|
||||
);
|
||||
|
||||
// Extract transfer information from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const transferList = commandResponse.TransferGetListResult[0];
|
||||
const paging = commandResponse.Paging[0];
|
||||
|
||||
// Convert the parsed XML structure to a more usable format
|
||||
const transfers = (transferList.Transfer || []).map(transfer => ({
|
||||
id: parseInt(transfer.$.ID, 10),
|
||||
domainName: transfer.$.DomainName,
|
||||
status: transfer.$.Status,
|
||||
statusDescription: transfer.$.StatusDescription,
|
||||
date: transfer.$.Date,
|
||||
lockTransferDate: transfer.$.LockTransferDate || null,
|
||||
transferOrderDetailId: parseInt(transfer.$.TransferOrderDetailID || '0', 10),
|
||||
isLocked: transfer.$.IsLocked?.toLowerCase() === 'true',
|
||||
authInfo: transfer.$.AuthInfo || null
|
||||
}));
|
||||
|
||||
// Convert paging information
|
||||
const pagingInfo = paging ? {
|
||||
totalItems: parseInt(paging.TotalItems[0], 10),
|
||||
currentPage: parseInt(paging.CurrentPage[0], 10),
|
||||
pageSize: parseInt(paging.PageSize[0], 10)
|
||||
} : {
|
||||
totalItems: transfers.length,
|
||||
currentPage: 1,
|
||||
pageSize: transfers.length
|
||||
};
|
||||
|
||||
return {
|
||||
transfers,
|
||||
paging: pagingInfo
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status of a domain transfer
|
||||
* @param transferId Transfer ID
|
||||
* @returns Transfer status information
|
||||
*/
|
||||
async getStatus(transferId: number): Promise<ITransferStatusInfo> {
|
||||
// Make the API request
|
||||
const response = await this.client.request<ITransferGetStatusResponse>(
|
||||
'namecheap.domains.transfer.getStatus',
|
||||
{ TransferID: transferId }
|
||||
);
|
||||
|
||||
// Extract status information from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const statusInfo = commandResponse.TransferGetStatusResult[0].$;
|
||||
|
||||
return {
|
||||
id: parseInt(statusInfo.TransferID, 10),
|
||||
status: statusInfo.Status,
|
||||
statusDescription: statusInfo.StatusDescription,
|
||||
domainName: statusInfo.DomainName,
|
||||
date: statusInfo.Date,
|
||||
lockTransferDate: statusInfo.LockTransferDate || null,
|
||||
transferOrderDetailId: parseInt(statusInfo.TransferOrderDetailID || '0', 10),
|
||||
isLocked: statusInfo.IsLocked?.toLowerCase() === 'true',
|
||||
authInfo: statusInfo.AuthInfo || null
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new domain transfer
|
||||
* @param domainName Domain name to transfer
|
||||
* @param years Number of years to renew for
|
||||
* @param authCode Authorization code from current registrar
|
||||
* @param options Additional options
|
||||
* @returns Transfer creation result
|
||||
*/
|
||||
async create(
|
||||
domainName: string,
|
||||
years: number,
|
||||
authCode: string,
|
||||
options?: {
|
||||
promotionCode?: string;
|
||||
addFreeWhoisguard?: boolean;
|
||||
whoisguardEnable?: boolean;
|
||||
idnCode?: string;
|
||||
premiumPrice?: number;
|
||||
eapFee?: number;
|
||||
}
|
||||
): Promise<{
|
||||
transferId: number;
|
||||
transferOrderId: number;
|
||||
isSuccess: boolean;
|
||||
transferStatus: string;
|
||||
statusDescription: string;
|
||||
chargedAmount: number;
|
||||
}> {
|
||||
// Prepare the request parameters
|
||||
const params: Record<string, string | number | boolean> = {
|
||||
DomainName: domainName,
|
||||
Years: years,
|
||||
EPPCode: authCode
|
||||
};
|
||||
|
||||
// Add optional parameters
|
||||
if (options) {
|
||||
if (options.promotionCode) {
|
||||
params.PromotionCode = options.promotionCode;
|
||||
}
|
||||
|
||||
if (options.addFreeWhoisguard !== undefined) {
|
||||
params.AddFreeWhoisguard = options.addFreeWhoisguard;
|
||||
}
|
||||
|
||||
if (options.whoisguardEnable !== undefined) {
|
||||
params.WGEnable = options.whoisguardEnable;
|
||||
}
|
||||
|
||||
if (options.idnCode) {
|
||||
params.IdnCode = options.idnCode;
|
||||
}
|
||||
|
||||
if (options.premiumPrice !== undefined) {
|
||||
params.PremiumPrice = options.premiumPrice;
|
||||
}
|
||||
|
||||
if (options.eapFee !== undefined) {
|
||||
params.EapFee = options.eapFee;
|
||||
}
|
||||
}
|
||||
|
||||
// Make the API request
|
||||
const response = await this.client.request<ITransferCreateResponse>(
|
||||
'namecheap.domains.transfer.create',
|
||||
params
|
||||
);
|
||||
|
||||
// Extract creation information from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const result = commandResponse.DomainTransferCreateResult[0].$;
|
||||
|
||||
return {
|
||||
transferId: parseInt(result.TransferID, 10),
|
||||
transferOrderId: parseInt(result.OrderID, 10),
|
||||
isSuccess: result.IsSuccess?.toLowerCase() === 'true',
|
||||
transferStatus: result.Status,
|
||||
statusDescription: result.StatusDescription,
|
||||
chargedAmount: parseFloat(result.ChargedAmount)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the status of a domain transfer
|
||||
* @param transferId Transfer ID
|
||||
* @param resubmit Whether to resubmit the transfer
|
||||
* @returns Success status
|
||||
*/
|
||||
async updateStatus(transferId: number, resubmit: boolean): Promise<boolean> {
|
||||
// Make the API request
|
||||
const response = await this.client.request<ITransferUpdateStatusResponse>(
|
||||
'namecheap.domains.transfer.updateStatus',
|
||||
{
|
||||
TransferID: transferId,
|
||||
Resubmit: resubmit
|
||||
}
|
||||
);
|
||||
|
||||
// Check if the operation was successful
|
||||
return response.ApiResponse.$.Status === 'OK';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get detailed information about a domain transfer
|
||||
* @param transferId Transfer ID
|
||||
* @returns Detailed transfer information
|
||||
*/
|
||||
async getInfo(transferId: number): Promise<{
|
||||
transferId: number;
|
||||
domainName: string;
|
||||
status: string;
|
||||
statusDescription: string;
|
||||
authInfo: string;
|
||||
date: string;
|
||||
whoisguardStatus: string;
|
||||
orderDate: string;
|
||||
orderId: number;
|
||||
transferOrderDetailId: number;
|
||||
}> {
|
||||
// Make the API request
|
||||
const response = await this.client.request<ITransferGetInfoResponse>(
|
||||
'namecheap.domains.transfer.getInfo',
|
||||
{ TransferID: transferId }
|
||||
);
|
||||
|
||||
// Extract detailed information from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const info = commandResponse.TransferGetInfoResult[0].$;
|
||||
|
||||
return {
|
||||
transferId: parseInt(info.TransferID, 10),
|
||||
domainName: info.DomainName,
|
||||
status: info.Status,
|
||||
statusDescription: info.StatusDescription,
|
||||
authInfo: info.AuthInfo || '',
|
||||
date: info.Date,
|
||||
whoisguardStatus: info.WhoisguardStatus || '',
|
||||
orderDate: info.OrderDate,
|
||||
orderId: parseInt(info.OrderID, 10),
|
||||
transferOrderDetailId: parseInt(info.TransferOrderDetailID, 10)
|
||||
};
|
||||
}
|
||||
}
|
577
ts/domains.ts
Normal file
577
ts/domains.ts
Normal file
@ -0,0 +1,577 @@
|
||||
/**
|
||||
* Namecheap API Client - Domains Module
|
||||
*/
|
||||
import { HttpClient } from './http-client.js';
|
||||
import type {
|
||||
IDomainsGetListParams,
|
||||
IDomainsGetListResponse,
|
||||
IDomainInfo,
|
||||
IDomainCheckResponse,
|
||||
IDomainCheckResult,
|
||||
IDomainAvailability,
|
||||
IDomainCreateParams,
|
||||
IDomainCreateResponse,
|
||||
IDomainGetInfoResponse,
|
||||
IDomainInfoResult,
|
||||
IDomainContacts,
|
||||
IDomainGetContactsResponse,
|
||||
IDomainSetContactsParams,
|
||||
IDomainRenewResponse,
|
||||
IDomainRenewResult,
|
||||
IRegistrarLockResponse,
|
||||
IDomainTldListResponse,
|
||||
IContactInfo
|
||||
} from './types.js';
|
||||
|
||||
export class Domains {
|
||||
private client: HttpClient;
|
||||
|
||||
/**
|
||||
* Create a new Domains API handler
|
||||
* @param client HTTP client instance
|
||||
*/
|
||||
constructor(client: HttpClient) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of domains in the Namecheap account
|
||||
* @param params Optional parameters for filtering and pagination
|
||||
* @returns Array of domain information objects
|
||||
*/
|
||||
async getList(params: IDomainsGetListParams = {}): Promise<{
|
||||
domains: IDomainInfo[];
|
||||
paging: {
|
||||
totalItems: number;
|
||||
currentPage: number;
|
||||
pageSize: number;
|
||||
};
|
||||
}> {
|
||||
// Convert parameters to the format expected by the API
|
||||
const requestParams: Record<string, string | number | boolean> = {};
|
||||
|
||||
// Add optional parameters if provided
|
||||
if (params.Page !== undefined) {
|
||||
requestParams.Page = params.Page;
|
||||
}
|
||||
|
||||
if (params.PageSize !== undefined) {
|
||||
requestParams.PageSize = params.PageSize;
|
||||
}
|
||||
|
||||
if (params.SortBy !== undefined) {
|
||||
requestParams.SortBy = params.SortBy;
|
||||
}
|
||||
|
||||
if (params.ListType !== undefined) {
|
||||
requestParams.ListType = params.ListType;
|
||||
}
|
||||
|
||||
if (params.SearchTerm !== undefined) {
|
||||
requestParams.SearchTerm = params.SearchTerm;
|
||||
}
|
||||
|
||||
// Make the API request
|
||||
const response = await this.client.request<IDomainsGetListResponse>(
|
||||
'namecheap.domains.getList',
|
||||
requestParams
|
||||
);
|
||||
|
||||
// Extract domain information from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const domainListResult = commandResponse.DomainGetListResult[0];
|
||||
const paging = commandResponse.Paging[0];
|
||||
|
||||
// Convert the parsed XML structure to a more usable format
|
||||
const domains = (domainListResult.Domain || []).map(domain => {
|
||||
const domainInfo: IDomainInfo = {
|
||||
...domain.$,
|
||||
// Convert string boolean values to actual booleans
|
||||
IsExpired: String(domain.$.IsExpired).toLowerCase() === 'true',
|
||||
IsLocked: String(domain.$.IsLocked).toLowerCase() === 'true',
|
||||
AutoRenew: String(domain.$.AutoRenew).toLowerCase() === 'true',
|
||||
IsPremium: String(domain.$.IsPremium).toLowerCase() === 'true',
|
||||
IsOurDNS: String(domain.$.IsOurDNS).toLowerCase() === 'true',
|
||||
// Join nameservers array with commas if it exists
|
||||
Nameservers: Array.isArray(domain.Nameservers) && domain.Nameservers.length > 0 ?
|
||||
domain.Nameservers[0] : ''
|
||||
};
|
||||
|
||||
return domainInfo;
|
||||
});
|
||||
|
||||
// Convert paging information
|
||||
const pagingInfo = paging ? {
|
||||
totalItems: parseInt(paging.TotalItems[0], 10),
|
||||
currentPage: parseInt(paging.CurrentPage[0], 10),
|
||||
pageSize: parseInt(paging.PageSize[0], 10)
|
||||
} : {
|
||||
totalItems: domains.length,
|
||||
currentPage: 1,
|
||||
pageSize: domains.length
|
||||
};
|
||||
|
||||
return {
|
||||
domains,
|
||||
paging: pagingInfo
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if domains are available for registration
|
||||
* @param domainNames Domain name(s) to check (single string or array of strings)
|
||||
* @returns Domain availability information
|
||||
*/
|
||||
async check(domainNames: string | string[]): Promise<IDomainAvailability[]> {
|
||||
// Convert single domain to array if needed
|
||||
const domains = Array.isArray(domainNames) ? domainNames : [domainNames];
|
||||
|
||||
// Join domains with comma for the API request
|
||||
const domainList = domains.join(',');
|
||||
|
||||
// Make the API request
|
||||
const response = await this.client.request<IDomainCheckResponse>(
|
||||
'namecheap.domains.check',
|
||||
{ DomainList: domainList }
|
||||
);
|
||||
|
||||
// Parse the response to determine availability
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const results: IDomainCheckResult[] = Array.isArray(commandResponse.DomainCheckResult)
|
||||
? commandResponse.DomainCheckResult
|
||||
: [commandResponse.DomainCheckResult];
|
||||
|
||||
// Convert the results to a more usable format
|
||||
return results.map(result => ({
|
||||
domain: result.$.Domain,
|
||||
available: String(result.$.Available).toLowerCase() === 'true',
|
||||
errorNo: parseInt(result.$.ErrorNo || '0', 10),
|
||||
description: result.$.Description || '',
|
||||
isPremium: String(result.$.IsPremiumName).toLowerCase() === 'true',
|
||||
premiumRegistrationPrice: parseFloat(result.$.PremiumRegistrationPrice || '0'),
|
||||
premiumRenewalPrice: parseFloat(result.$.PremiumRenewalPrice || '0'),
|
||||
premiumRestorePrice: parseFloat(result.$.PremiumRestorePrice || '0'),
|
||||
premiumTransferPrice: parseFloat(result.$.PremiumTransferPrice || '0'),
|
||||
icannFee: parseFloat(result.$.IcannFee || '0'),
|
||||
eapFee: parseFloat(result.$.EapFee || '0')
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get detailed information about a specific domain
|
||||
* @param domainName Domain name to get information for
|
||||
* @param hostName Optional host name for hosted domains
|
||||
* @returns Detailed domain information
|
||||
*/
|
||||
async getInfo(domainName: string, hostName?: string): Promise<IDomainInfoResult> {
|
||||
const params: Record<string, string> = { DomainName: domainName };
|
||||
|
||||
if (hostName) {
|
||||
params.HostName = hostName;
|
||||
}
|
||||
|
||||
// Make the API request
|
||||
const response = await this.client.request<IDomainGetInfoResponse>(
|
||||
'namecheap.domains.getInfo',
|
||||
params
|
||||
);
|
||||
|
||||
// Extract domain information from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const domainInfo = commandResponse.DomainGetInfoResult[0];
|
||||
|
||||
// Convert string boolean values to actual booleans
|
||||
const result: IDomainInfoResult = {
|
||||
status: domainInfo.$.Status,
|
||||
id: parseInt(domainInfo.$.ID, 10),
|
||||
domainName: domainInfo.$.DomainName,
|
||||
ownerName: domainInfo.$.OwnerName,
|
||||
isOwner: String(domainInfo.$.IsOwner).toLowerCase() === 'true',
|
||||
isPremium: String(domainInfo.$.IsPremium).toLowerCase() === 'true',
|
||||
createdDate: domainInfo.DomainDetails?.[0]?.CreatedDate?.[0] || '',
|
||||
expiredDate: domainInfo.DomainDetails?.[0]?.ExpiredDate?.[0] || '',
|
||||
whoisGuard: {
|
||||
enabled: domainInfo.Whoisguard?.[0]?.$.Enabled?.toLowerCase() === 'true' || false,
|
||||
id: domainInfo.Whoisguard?.[0]?.ID?.[0] ? parseInt(domainInfo.Whoisguard[0].ID[0], 10) : 0,
|
||||
expiredDate: domainInfo.Whoisguard?.[0]?.ExpiredDate?.[0] || ''
|
||||
},
|
||||
dnsProvider: domainInfo.DnsDetails?.[0]?.$.ProviderType || '',
|
||||
modificationRights: {
|
||||
all: domainInfo.Modificationrights?.[0]?.$.All?.toLowerCase() === 'true' || false
|
||||
}
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get contact information for a domain
|
||||
* @param domainName Domain name to get contacts for
|
||||
* @returns Domain contact information
|
||||
* @throws Error if the domain name is invalid or the API request fails
|
||||
*/
|
||||
async getContacts(domainName: string): Promise<IDomainContacts> {
|
||||
if (!domainName) {
|
||||
throw new Error('Domain name is required');
|
||||
}
|
||||
|
||||
try {
|
||||
// Make the API request
|
||||
const response = await this.client.request<IDomainGetContactsResponse>(
|
||||
'namecheap.domains.getContacts',
|
||||
{ DomainName: domainName }
|
||||
);
|
||||
|
||||
// Check for API errors
|
||||
if (response.ApiResponse.$.Status !== 'OK') {
|
||||
const errors = response.ApiResponse.Errors;
|
||||
if (Array.isArray(errors) && errors.length > 0) {
|
||||
const error = errors[0] as { Error?: string[] };
|
||||
if (error.Error && error.Error.length > 0) {
|
||||
throw new Error(`API Error: ${error.Error.join(', ')}`);
|
||||
}
|
||||
}
|
||||
throw new Error('Failed to get domain contacts');
|
||||
}
|
||||
|
||||
// Extract contact information from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const contacts = commandResponse.DomainContactsResult[0];
|
||||
|
||||
// Convert the parsed XML structure to a more usable format
|
||||
return {
|
||||
registrant: this.parseContact(contacts.Registrant?.[0]),
|
||||
tech: this.parseContact(contacts.Tech?.[0]),
|
||||
admin: this.parseContact(contacts.Admin?.[0]),
|
||||
auxBilling: this.parseContact(contacts.AuxBilling?.[0])
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
throw error;
|
||||
}
|
||||
throw new Error(`Failed to get domain contacts: ${String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set contact information for a domain
|
||||
* @param domainName Domain name to set contacts for
|
||||
* @param contacts Contact information to set
|
||||
* @returns Success status
|
||||
* @throws Error if the domain name is invalid, contacts are missing, or the API request fails
|
||||
*/
|
||||
async setContacts(domainName: string, contacts: IDomainSetContactsParams): Promise<boolean> {
|
||||
// Validate inputs
|
||||
if (!domainName) {
|
||||
throw new Error('Domain name is required');
|
||||
}
|
||||
|
||||
if (!contacts || Object.keys(contacts).length === 0) {
|
||||
throw new Error('Contact information is required');
|
||||
}
|
||||
|
||||
// Ensure at least one contact type is provided
|
||||
if (!contacts.registrant && !contacts.tech && !contacts.admin && !contacts.auxBilling) {
|
||||
throw new Error('At least one contact type (registrant, tech, admin, or auxBilling) is required');
|
||||
}
|
||||
|
||||
try {
|
||||
// Prepare the request parameters
|
||||
const params: Record<string, string> = {
|
||||
DomainName: domainName,
|
||||
...this.flattenContacts(contacts)
|
||||
};
|
||||
|
||||
// Make the API request
|
||||
const response = await this.client.request(
|
||||
'namecheap.domains.setContacts',
|
||||
params
|
||||
);
|
||||
|
||||
// Check for API errors
|
||||
if (response.ApiResponse.$.Status !== 'OK') {
|
||||
const errors = response.ApiResponse.Errors;
|
||||
if (Array.isArray(errors) && errors.length > 0) {
|
||||
const error = errors[0] as { Error?: string[] };
|
||||
if (error.Error && error.Error.length > 0) {
|
||||
throw new Error(`API Error: ${error.Error.join(', ')}`);
|
||||
}
|
||||
}
|
||||
throw new Error('Failed to set domain contacts');
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
throw error;
|
||||
}
|
||||
throw new Error(`Failed to set domain contacts: ${String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new domain
|
||||
* @param params Domain registration parameters
|
||||
* @returns Registration result
|
||||
*/
|
||||
async create(params: IDomainCreateParams): Promise<{
|
||||
domain: string;
|
||||
registered: boolean;
|
||||
chargedAmount: number;
|
||||
transactionId: number;
|
||||
orderId: number;
|
||||
}> {
|
||||
// Prepare the request parameters
|
||||
const requestParams: Record<string, string | number | boolean> = {
|
||||
DomainName: params.domainName,
|
||||
Years: params.years,
|
||||
...this.flattenContacts(params.contacts)
|
||||
};
|
||||
|
||||
// Add nameservers if provided
|
||||
if (params.nameservers && params.nameservers.length > 0) {
|
||||
requestParams.Nameservers = params.nameservers.join(',');
|
||||
}
|
||||
|
||||
// Add additional parameters
|
||||
if (params.addFreeWhoisguard !== undefined) {
|
||||
requestParams.AddFreeWhoisguard = params.addFreeWhoisguard;
|
||||
}
|
||||
|
||||
if (params.whoisguardPrivacy !== undefined) {
|
||||
requestParams.WGEnabled = params.whoisguardPrivacy;
|
||||
}
|
||||
|
||||
if (params.premiumPrice !== undefined) {
|
||||
requestParams.PremiumPrice = params.premiumPrice;
|
||||
}
|
||||
|
||||
// Make the API request
|
||||
const response = await this.client.request<IDomainCreateResponse>(
|
||||
'namecheap.domains.create',
|
||||
requestParams
|
||||
);
|
||||
|
||||
// Extract registration information from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const domainCreateResult = commandResponse.DomainCreateResult[0];
|
||||
|
||||
return {
|
||||
domain: domainCreateResult.$.Domain,
|
||||
registered: String(domainCreateResult.$.Registered).toLowerCase() === 'true',
|
||||
chargedAmount: parseFloat(domainCreateResult.$.ChargedAmount),
|
||||
transactionId: parseInt(domainCreateResult.$.TransactionID, 10),
|
||||
orderId: parseInt(domainCreateResult.$.OrderID, 10)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew a domain registration
|
||||
* @param domainName Domain name to renew
|
||||
* @param years Number of years to renew for
|
||||
* @param premiumPrice Optional premium price for premium domains
|
||||
* @returns Renewal result
|
||||
*/
|
||||
async renew(domainName: string, years: number, premiumPrice?: number): Promise<IDomainRenewResult> {
|
||||
// Prepare the request parameters
|
||||
const params: Record<string, string | number | boolean> = {
|
||||
DomainName: domainName,
|
||||
Years: years
|
||||
};
|
||||
|
||||
if (premiumPrice !== undefined) {
|
||||
params.PremiumPrice = premiumPrice;
|
||||
}
|
||||
|
||||
// Make the API request
|
||||
const response = await this.client.request<IDomainRenewResponse>(
|
||||
'namecheap.domains.renew',
|
||||
params
|
||||
);
|
||||
|
||||
// Extract renewal information from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const renewResult = commandResponse.DomainRenewResult[0].$;
|
||||
|
||||
return {
|
||||
domainName: renewResult.DomainName,
|
||||
domainId: parseInt(renewResult.DomainID, 10),
|
||||
renewed: String(renewResult.Renewed).toLowerCase() === 'true',
|
||||
chargedAmount: parseFloat(renewResult.ChargedAmount),
|
||||
transactionId: parseInt(renewResult.TransactionID, 10),
|
||||
orderId: parseInt(renewResult.OrderID, 10),
|
||||
expireDate: renewResult.DomainDetails?.ExpiredDate || ''
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Reactivate an expired domain
|
||||
* @param domainName Domain name to reactivate
|
||||
* @returns Reactivation result
|
||||
*/
|
||||
async reactivate(domainName: string): Promise<{
|
||||
domain: string;
|
||||
reactivated: boolean;
|
||||
chargedAmount: number;
|
||||
orderId: number;
|
||||
transactionId: number;
|
||||
}> {
|
||||
// Make the API request
|
||||
const response = await this.client.request(
|
||||
'namecheap.domains.reactivate',
|
||||
{ DomainName: domainName }
|
||||
);
|
||||
|
||||
// Extract reactivation information from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const reactivateResult = commandResponse.DomainReactivateResult[0].$;
|
||||
|
||||
return {
|
||||
domain: reactivateResult.Domain,
|
||||
reactivated: String(reactivateResult.IsSuccess).toLowerCase() === 'true',
|
||||
chargedAmount: parseFloat(reactivateResult.ChargedAmount),
|
||||
orderId: parseInt(reactivateResult.OrderID, 10),
|
||||
transactionId: parseInt(reactivateResult.TransactionID, 10)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the registrar lock status for a domain
|
||||
* @param domainName Domain name to check
|
||||
* @returns Lock status
|
||||
*/
|
||||
async getRegistrarLock(domainName: string): Promise<boolean> {
|
||||
// Make the API request
|
||||
const response = await this.client.request<IRegistrarLockResponse>(
|
||||
'namecheap.domains.getRegistrarLock',
|
||||
{ DomainName: domainName }
|
||||
);
|
||||
|
||||
// Extract lock status from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const lockStatus = commandResponse.DomainGetRegistrarLockResult[0];
|
||||
|
||||
return String(lockStatus.$.RegistrarLockStatus).toLowerCase() === 'true';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the registrar lock status for a domain
|
||||
* @param domainName Domain name to update
|
||||
* @param lockStatus New lock status (true to lock, false to unlock)
|
||||
* @returns Success status
|
||||
*/
|
||||
async setRegistrarLock(domainName: string, lockStatus: boolean): Promise<boolean> {
|
||||
// Make the API request
|
||||
const response = await this.client.request(
|
||||
'namecheap.domains.setRegistrarLock',
|
||||
{
|
||||
DomainName: domainName,
|
||||
LockAction: lockStatus ? 'LOCK' : 'UNLOCK'
|
||||
}
|
||||
);
|
||||
|
||||
// Check if the operation was successful
|
||||
return response.ApiResponse.$.Status === 'OK';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of available TLDs
|
||||
* @returns List of TLDs
|
||||
*/
|
||||
async getTldList(): Promise<string[]> {
|
||||
// Make the API request
|
||||
const response = await this.client.request<IDomainTldListResponse>(
|
||||
'namecheap.domains.getTldList'
|
||||
);
|
||||
|
||||
// Extract TLD list from the response
|
||||
const commandResponse = response.ApiResponse.CommandResponse[0];
|
||||
const tlds = commandResponse.Tlds[0].Tld || [];
|
||||
|
||||
return tlds.map(tld => tld.$.Name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to parse contact information
|
||||
* @param contactData Contact data from API response
|
||||
* @returns Parsed contact information
|
||||
*/
|
||||
private parseContact(contactData: any): IContactInfo {
|
||||
if (!contactData) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const contact: IContactInfo = {};
|
||||
|
||||
// Map all contact fields
|
||||
Object.keys(contactData).forEach(key => {
|
||||
if (Array.isArray(contactData[key]) && contactData[key].length > 0) {
|
||||
// Use type assertion to handle dynamic property assignment
|
||||
(contact as any)[key] = contactData[key][0];
|
||||
}
|
||||
});
|
||||
|
||||
return contact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to flatten contact information for API requests
|
||||
* @param contacts Contact information object
|
||||
* @returns Flattened contact parameters
|
||||
*/
|
||||
private flattenContacts(contacts: IDomainSetContactsParams): Record<string, string> {
|
||||
const params: Record<string, string> = {};
|
||||
|
||||
// Process each contact type
|
||||
['Registrant', 'Tech', 'Admin', 'AuxBilling'].forEach(type => {
|
||||
const contactType = type.toLowerCase() as keyof typeof contacts;
|
||||
const contactInfo = contacts[contactType];
|
||||
|
||||
if (contactInfo) {
|
||||
// Ensure all required fields are present
|
||||
this.validateContactInfo(contactInfo, type);
|
||||
|
||||
// Add each field to the params with the appropriate prefix
|
||||
Object.entries(contactInfo).forEach(([field, value]) => {
|
||||
if (value !== undefined && value !== null) {
|
||||
params[`${type}${field}`] = String(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate contact information to ensure required fields are present
|
||||
* @param contactInfo Contact information to validate
|
||||
* @param contactType Type of contact (Registrant, Tech, Admin, AuxBilling)
|
||||
* @throws Error if required fields are missing
|
||||
*/
|
||||
private validateContactInfo(contactInfo: IContactInfo, contactType: string): void {
|
||||
// Required fields for all contact types
|
||||
const requiredFields = [
|
||||
'FirstName',
|
||||
'LastName',
|
||||
'Address1',
|
||||
'City',
|
||||
'StateProvince',
|
||||
'PostalCode',
|
||||
'Country',
|
||||
'Phone',
|
||||
'EmailAddress'
|
||||
];
|
||||
|
||||
// Check for missing required fields
|
||||
const missingFields = requiredFields.filter(field => {
|
||||
return !contactInfo[field as keyof IContactInfo];
|
||||
});
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
throw new Error(
|
||||
`Missing required fields for ${contactType} contact: ${missingFields.join(', ')}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
158
ts/http-client.ts
Normal file
158
ts/http-client.ts
Normal file
@ -0,0 +1,158 @@
|
||||
/**
|
||||
* Namecheap API Client - HTTP Client
|
||||
*/
|
||||
import axios from 'axios';
|
||||
import type { AxiosInstance, AxiosResponse } from 'axios';
|
||||
import { parseStringPromise } from 'xml2js';
|
||||
import { NamecheapConfig } from './config.js';
|
||||
import type { IApiResponse, IErrorResponse } from './types.js';
|
||||
|
||||
export class HttpClient {
|
||||
private client: AxiosInstance;
|
||||
private config: NamecheapConfig;
|
||||
|
||||
/**
|
||||
* Create a new HTTP client for Namecheap API
|
||||
* @param config Namecheap API configuration
|
||||
*/
|
||||
constructor(config: NamecheapConfig) {
|
||||
this.config = config;
|
||||
|
||||
// Initialize axios instance with default config
|
||||
this.client = axios.create({
|
||||
baseURL: config.baseUrl,
|
||||
timeout: config.timeout,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Accept': 'application/xml'
|
||||
}
|
||||
});
|
||||
|
||||
// Add response interceptor for global error handling
|
||||
this.client.interceptors.response.use(
|
||||
response => response,
|
||||
error => this.handleAxiosError(error)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a request to the Namecheap API
|
||||
* @param command API command to execute
|
||||
* @param params Additional parameters
|
||||
* @returns Parsed API response
|
||||
*/
|
||||
async request<T extends IApiResponse>(
|
||||
command: string,
|
||||
params: Record<string, string | number | boolean> = {}
|
||||
): Promise<T> {
|
||||
try {
|
||||
// Get base parameters that all requests need
|
||||
const baseParams = this.config.getBaseParams(command);
|
||||
|
||||
// Merge base params with additional params
|
||||
const requestParams = {
|
||||
...baseParams,
|
||||
...params
|
||||
};
|
||||
|
||||
// Send request to the API
|
||||
const response = await this.client.get('', {
|
||||
params: requestParams
|
||||
});
|
||||
|
||||
// Parse XML response to JavaScript object
|
||||
const parsedResponse = await this.parseXmlResponse<T>(response);
|
||||
|
||||
// Check for API errors
|
||||
this.checkApiErrors(parsedResponse);
|
||||
|
||||
return parsedResponse;
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
throw error;
|
||||
} else {
|
||||
throw new Error('Unknown error occurred');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse XML response to JavaScript object
|
||||
* @param response Axios response object
|
||||
* @returns Parsed response
|
||||
*/
|
||||
private async parseXmlResponse<T>(response: AxiosResponse): Promise<T> {
|
||||
try {
|
||||
const xmlData = response.data;
|
||||
|
||||
// Parse XML to JavaScript object with some options for better formatting
|
||||
const result = await parseStringPromise(xmlData, {
|
||||
explicitArray: true,
|
||||
explicitRoot: true,
|
||||
mergeAttrs: false,
|
||||
attrkey: '$'
|
||||
});
|
||||
|
||||
return result as T;
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to parse XML response: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for API errors in the response
|
||||
* @param response Parsed API response
|
||||
* @throws Error if API returned an error
|
||||
*/
|
||||
private checkApiErrors(response: IApiResponse): void {
|
||||
// Check if response status is ERROR
|
||||
if (response.ApiResponse.$.Status === 'ERROR') {
|
||||
const errors = response.ApiResponse.Errors[0];
|
||||
|
||||
if (errors && 'Error' in errors) {
|
||||
const errorMessages = errors.Error;
|
||||
throw new Error(`Namecheap API Error: ${errorMessages.join(', ')}`);
|
||||
} else {
|
||||
throw new Error('Namecheap API returned an error without details');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle axios errors
|
||||
* @param error Axios error object
|
||||
* @throws Formatted error
|
||||
*/
|
||||
private handleAxiosError(error: any): never {
|
||||
let errorResponse: IErrorResponse = {
|
||||
message: 'Request to Namecheap API failed'
|
||||
};
|
||||
|
||||
if (error.response) {
|
||||
// Server responded with a status code outside of 2xx range
|
||||
errorResponse.message = `Namecheap API request failed with status ${error.response.status}`;
|
||||
|
||||
// Try to parse error response if it's XML
|
||||
if (error.response.data && typeof error.response.data === 'string') {
|
||||
try {
|
||||
const xmlError = error.response.data;
|
||||
errorResponse.message = `API Error: ${xmlError}`;
|
||||
} catch (parseError) {
|
||||
// Couldn't parse error response, use default message
|
||||
}
|
||||
}
|
||||
} else if (error.request) {
|
||||
// Request was made but no response received
|
||||
errorResponse.message = 'No response received from Namecheap API';
|
||||
|
||||
if (error.code === 'ECONNABORTED') {
|
||||
errorResponse.message = `Request timed out after ${this.config.timeout}ms`;
|
||||
}
|
||||
} else {
|
||||
// Error setting up the request
|
||||
errorResponse.message = error.message || 'Error setting up the request';
|
||||
}
|
||||
|
||||
throw new Error(errorResponse.message);
|
||||
}
|
||||
}
|
102
ts/index.ts
Normal file
102
ts/index.ts
Normal file
@ -0,0 +1,102 @@
|
||||
/**
|
||||
* Namecheap API Client - Main Entry Point
|
||||
*/
|
||||
import { NamecheapConfig } from './config.js';
|
||||
import { HttpClient } from './http-client.js';
|
||||
import { Domains } from './domains.js';
|
||||
import { DomainsDns } from './domains-dns.js';
|
||||
import { DomainsNs } from './domains-ns.js';
|
||||
import { DomainsTransfer } from './domains-transfer.js';
|
||||
import type { INamecheapAuth } from './types.js';
|
||||
|
||||
// Re-export types for library consumers
|
||||
export * from './types.js';
|
||||
export { NamecheapConfig } from './config.js';
|
||||
export { Domains } from './domains.js';
|
||||
export { DomainsDns } from './domains-dns.js';
|
||||
export { DomainsNs } from './domains-ns.js';
|
||||
export { DomainsTransfer } from './domains-transfer.js';
|
||||
|
||||
/**
|
||||
* Main Namecheap API client class
|
||||
*/
|
||||
export class NamecheapClient {
|
||||
private config: NamecheapConfig;
|
||||
private httpClient: HttpClient;
|
||||
|
||||
/**
|
||||
* Domains API module
|
||||
*/
|
||||
public domains: Domains;
|
||||
|
||||
/**
|
||||
* Domains DNS API module
|
||||
*/
|
||||
public dns: DomainsDns;
|
||||
|
||||
/**
|
||||
* Domains Nameservers API module
|
||||
*/
|
||||
public ns: DomainsNs;
|
||||
|
||||
/**
|
||||
* Domains Transfer API module
|
||||
*/
|
||||
public transfer: DomainsTransfer;
|
||||
|
||||
/**
|
||||
* Create a new Namecheap API client
|
||||
* @param auth Authentication details
|
||||
* @param useSandbox Whether to use the sandbox environment (default: false)
|
||||
*/
|
||||
constructor(auth: INamecheapAuth, useSandbox: boolean = false) {
|
||||
// Initialize configuration
|
||||
this.config = new NamecheapConfig(auth);
|
||||
|
||||
// Set sandbox mode if requested
|
||||
if (useSandbox) {
|
||||
this.config.enableSandbox();
|
||||
}
|
||||
|
||||
// Create HTTP client
|
||||
this.httpClient = new HttpClient(this.config);
|
||||
|
||||
// Initialize API modules
|
||||
this.domains = new Domains(this.httpClient);
|
||||
this.dns = new DomainsDns(this.httpClient);
|
||||
this.ns = new DomainsNs(this.httpClient);
|
||||
this.transfer = new DomainsTransfer(this.httpClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable sandbox mode for testing
|
||||
*/
|
||||
enableSandbox(): void {
|
||||
this.config.enableSandbox();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable sandbox mode
|
||||
*/
|
||||
disableSandbox(): void {
|
||||
this.config.disableSandbox();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set request timeout
|
||||
* @param ms Timeout in milliseconds
|
||||
*/
|
||||
setTimeout(ms: number): void {
|
||||
this.config.setTimeout(ms);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Namecheap API client instance
|
||||
* @param auth Authentication details
|
||||
* @param useSandbox Whether to use the sandbox environment
|
||||
* @returns Namecheap API client
|
||||
*/
|
||||
export function createClient(auth: INamecheapAuth, useSandbox: boolean = false): NamecheapClient {
|
||||
return new NamecheapClient(auth, useSandbox);
|
||||
}
|
5
ts/paths.ts
Normal file
5
ts/paths.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import * as plugins from './plugins.js';
|
||||
export const packageDir = plugins.path.join(
|
||||
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||
'../',
|
||||
);
|
9
ts/plugins.ts
Normal file
9
ts/plugins.ts
Normal file
@ -0,0 +1,9 @@
|
||||
// native scope
|
||||
import * as path from 'path';
|
||||
|
||||
export { path };
|
||||
|
||||
// @push.rocks scope
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
|
||||
export { smartpath };
|
948
ts/types.ts
Normal file
948
ts/types.ts
Normal file
@ -0,0 +1,948 @@
|
||||
/**
|
||||
* Namecheap API Client - Type Definitions
|
||||
*/
|
||||
|
||||
// Base interface for API authentication
|
||||
export interface INamecheapAuth {
|
||||
apiUser: string;
|
||||
apiKey: string;
|
||||
userName: string;
|
||||
clientIp: string;
|
||||
}
|
||||
|
||||
// Base parameters that all API calls require
|
||||
export interface TBaseParams {
|
||||
ApiUser: string;
|
||||
ApiKey: string;
|
||||
UserName: string;
|
||||
ClientIp: string;
|
||||
Command: string;
|
||||
}
|
||||
|
||||
// Response status types
|
||||
export type TApiResponseStatus = 'OK' | 'ERROR';
|
||||
|
||||
// Base API response structure
|
||||
export interface IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
[key: string]: any;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Domain List Parameters
|
||||
export interface IDomainsGetListParams {
|
||||
Page?: number;
|
||||
PageSize?: number;
|
||||
SortBy?: 'NAME' | 'NAME_DESC' | 'EXPIREDATE' | 'EXPIREDATE_DESC' | 'CREATEDATE' | 'CREATEDATE_DESC';
|
||||
ListType?: 'ALL' | 'EXPIRING' | 'EXPIRED';
|
||||
SearchTerm?: string;
|
||||
}
|
||||
|
||||
// Domain information returned from getList
|
||||
export interface IDomainInfo {
|
||||
ID: string;
|
||||
Name: string;
|
||||
User: string;
|
||||
Created: string;
|
||||
Expires: string;
|
||||
IsExpired: boolean;
|
||||
IsLocked: boolean;
|
||||
AutoRenew: boolean;
|
||||
WhoisGuard: 'ENABLED' | 'DISABLED' | 'NOTPRESENT';
|
||||
IsPremium: boolean;
|
||||
IsOurDNS: boolean;
|
||||
Nameservers: string;
|
||||
}
|
||||
|
||||
// GetList response
|
||||
export interface IDomainsGetListResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainGetListResult: Array<{
|
||||
Domain: Array<{
|
||||
$: IDomainInfo;
|
||||
Nameservers: string[];
|
||||
}>;
|
||||
}>;
|
||||
Paging: Array<{
|
||||
TotalItems: string[];
|
||||
CurrentPage: string[];
|
||||
PageSize: string[];
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Domain Check Response
|
||||
export interface IDomainCheckResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainCheckResult: IDomainCheckResult | IDomainCheckResult[];
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Domain Check Result
|
||||
export interface IDomainCheckResult {
|
||||
$: {
|
||||
Domain: string;
|
||||
Available: string;
|
||||
ErrorNo: string;
|
||||
Description: string;
|
||||
IsPremiumName: string;
|
||||
PremiumRegistrationPrice: string;
|
||||
PremiumRenewalPrice: string;
|
||||
PremiumRestorePrice: string;
|
||||
PremiumTransferPrice: string;
|
||||
IcannFee: string;
|
||||
EapFee: string;
|
||||
};
|
||||
}
|
||||
|
||||
// Domain Availability (processed result)
|
||||
export interface IDomainAvailability {
|
||||
domain: string;
|
||||
available: boolean;
|
||||
errorNo: number;
|
||||
description: string;
|
||||
isPremium: boolean;
|
||||
premiumRegistrationPrice: number;
|
||||
premiumRenewalPrice: number;
|
||||
premiumRestorePrice: number;
|
||||
premiumTransferPrice: number;
|
||||
icannFee: number;
|
||||
eapFee: number;
|
||||
}
|
||||
|
||||
// Domain Get Info Response
|
||||
export interface IDomainGetInfoResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainGetInfoResult: Array<{
|
||||
$: {
|
||||
Status: string;
|
||||
ID: string;
|
||||
DomainName: string;
|
||||
OwnerName: string;
|
||||
IsOwner: string;
|
||||
IsPremium: string;
|
||||
};
|
||||
DomainDetails?: Array<{
|
||||
CreatedDate: string[];
|
||||
ExpiredDate: string[];
|
||||
}>;
|
||||
LockDetails?: any[];
|
||||
Whoisguard?: Array<{
|
||||
$: {
|
||||
Enabled: string;
|
||||
};
|
||||
ID: string[];
|
||||
ExpiredDate: string[];
|
||||
}>;
|
||||
DnsDetails?: Array<{
|
||||
$: {
|
||||
ProviderType: string;
|
||||
};
|
||||
}>;
|
||||
Modificationrights?: Array<{
|
||||
$: {
|
||||
All: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Domain Info Result (processed)
|
||||
export interface IDomainInfoResult {
|
||||
status: string;
|
||||
id: number;
|
||||
domainName: string;
|
||||
ownerName: string;
|
||||
isOwner: boolean;
|
||||
isPremium: boolean;
|
||||
createdDate: string;
|
||||
expiredDate: string;
|
||||
whoisGuard: {
|
||||
enabled: boolean;
|
||||
id: number;
|
||||
expiredDate: string;
|
||||
};
|
||||
dnsProvider: string;
|
||||
modificationRights: {
|
||||
all: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
// Domain Get Contacts Response
|
||||
export interface IDomainGetContactsResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainContactsResult: Array<{
|
||||
Registrant?: Array<Record<string, string[]>>;
|
||||
Tech?: Array<Record<string, string[]>>;
|
||||
Admin?: Array<Record<string, string[]>>;
|
||||
AuxBilling?: Array<Record<string, string[]>>;
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Contact information structure
|
||||
export interface IContactInfo {
|
||||
FirstName?: string;
|
||||
LastName?: string;
|
||||
Address1?: string;
|
||||
Address2?: string;
|
||||
City?: string;
|
||||
StateProvince?: string;
|
||||
StateProvinceChoice?: string;
|
||||
PostalCode?: string;
|
||||
Country?: string;
|
||||
Phone?: string;
|
||||
PhoneExt?: string;
|
||||
Fax?: string;
|
||||
EmailAddress?: string;
|
||||
OrganizationName?: string;
|
||||
JobTitle?: string;
|
||||
}
|
||||
|
||||
// Domain Contacts
|
||||
export interface IDomainContacts {
|
||||
registrant: IContactInfo;
|
||||
tech: IContactInfo;
|
||||
admin: IContactInfo;
|
||||
auxBilling: IContactInfo;
|
||||
}
|
||||
|
||||
// Domain Set Contacts Parameters
|
||||
export interface IDomainSetContactsParams {
|
||||
registrant?: IContactInfo;
|
||||
tech?: IContactInfo;
|
||||
admin?: IContactInfo;
|
||||
auxBilling?: IContactInfo;
|
||||
}
|
||||
|
||||
// Domain Create Parameters
|
||||
export interface IDomainCreateParams {
|
||||
domainName: string;
|
||||
years: number;
|
||||
contacts: IDomainSetContactsParams;
|
||||
nameservers?: string[];
|
||||
addFreeWhoisguard?: boolean;
|
||||
whoisguardPrivacy?: boolean;
|
||||
premiumPrice?: number;
|
||||
}
|
||||
|
||||
// Domain Create Response
|
||||
export interface IDomainCreateResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainCreateResult: Array<{
|
||||
$: {
|
||||
Domain: string;
|
||||
Registered: string;
|
||||
ChargedAmount: string;
|
||||
TransactionID: string;
|
||||
OrderID: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Domain Renew Parameters
|
||||
export interface IDomainRenewParams {
|
||||
DomainName: string;
|
||||
Years: number;
|
||||
PremiumPrice?: number;
|
||||
}
|
||||
|
||||
// Domain Renew Response
|
||||
export interface IDomainRenewResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainRenewResult: Array<{
|
||||
$: {
|
||||
DomainName: string;
|
||||
DomainID: string;
|
||||
Renewed: string;
|
||||
ChargedAmount: string;
|
||||
TransactionID: string;
|
||||
OrderID: string;
|
||||
DomainDetails?: {
|
||||
ExpiredDate: string;
|
||||
};
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Domain Renew Result (processed)
|
||||
export interface IDomainRenewResult {
|
||||
domainName: string;
|
||||
domainId: number;
|
||||
renewed: boolean;
|
||||
chargedAmount: number;
|
||||
transactionId: number;
|
||||
orderId: number;
|
||||
expireDate: string;
|
||||
}
|
||||
|
||||
// Registrar Lock Response
|
||||
export interface IRegistrarLockResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainGetRegistrarLockResult: Array<{
|
||||
$: {
|
||||
RegistrarLockStatus: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Domain TLD List Response
|
||||
export interface IDomainTldListResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
Tlds: Array<{
|
||||
Tld: Array<{
|
||||
$: {
|
||||
Name: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// DNS Host Record
|
||||
export interface IDnsHost {
|
||||
id: number;
|
||||
name: string;
|
||||
type: string;
|
||||
address: string;
|
||||
mxPref: number;
|
||||
ttl: number;
|
||||
isActive: boolean;
|
||||
isDDNSEnabled: boolean;
|
||||
}
|
||||
|
||||
// DNS Record
|
||||
export interface IDnsRecord {
|
||||
name: string;
|
||||
type: string;
|
||||
address: string;
|
||||
mxPref?: number;
|
||||
ttl?: number;
|
||||
}
|
||||
|
||||
// DNS Get Hosts Response
|
||||
export interface IDnsDomainHostsResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainDNSGetHostsResult: Array<{
|
||||
$: {
|
||||
Domain: string;
|
||||
IsUsingOurDNS: string;
|
||||
};
|
||||
host: Array<{
|
||||
$: {
|
||||
HostId: string;
|
||||
Name: string;
|
||||
Type: string;
|
||||
Address: string;
|
||||
MXPref?: string;
|
||||
TTL: string;
|
||||
IsActive?: string;
|
||||
IsDDNSEnabled?: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// DNS Set Hosts Response
|
||||
export interface IDnsSetHostsResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainDNSSetHostsResult: Array<{
|
||||
$: {
|
||||
Domain: string;
|
||||
IsSuccess: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// DNS Set Custom Response
|
||||
export interface IDnsSetCustomResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainDNSSetCustomResult: Array<{
|
||||
$: {
|
||||
Domain: string;
|
||||
Updated: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// DNS Get Email Forwarding Response
|
||||
export interface IDnsGetEmailForwardingResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainDNSGetEmailForwardingResult: Array<{
|
||||
$: {
|
||||
Domain: string;
|
||||
};
|
||||
forward: Array<{
|
||||
$: {
|
||||
from: string;
|
||||
to: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// DNS Set Email Forwarding Response
|
||||
export interface IDnsSetEmailForwardingResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainDNSSetEmailForwardingResult: Array<{
|
||||
$: {
|
||||
Domain: string;
|
||||
IsSuccess: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// DNS Get List Response
|
||||
export interface IDnsGetListResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainDNSGetListResult: Array<{
|
||||
Nameserver: string[];
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Transfer Info
|
||||
export interface ITransferInfo {
|
||||
id: number;
|
||||
domainName: string;
|
||||
status: string;
|
||||
statusDescription: string;
|
||||
date: string;
|
||||
lockTransferDate: string | null;
|
||||
transferOrderDetailId: number;
|
||||
isLocked: boolean;
|
||||
authInfo: string | null;
|
||||
}
|
||||
|
||||
// Transfer Status Info
|
||||
export interface ITransferStatusInfo extends ITransferInfo {}
|
||||
|
||||
// Transfer Get List Response
|
||||
export interface ITransferGetListResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
TransferGetListResult: Array<{
|
||||
Transfer: Array<{
|
||||
$: {
|
||||
ID: string;
|
||||
DomainName: string;
|
||||
Status: string;
|
||||
StatusDescription: string;
|
||||
Date: string;
|
||||
LockTransferDate?: string;
|
||||
TransferOrderDetailID?: string;
|
||||
IsLocked?: string;
|
||||
AuthInfo?: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Paging: Array<{
|
||||
TotalItems: string[];
|
||||
CurrentPage: string[];
|
||||
PageSize: string[];
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Transfer Get Status Response
|
||||
export interface ITransferGetStatusResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
TransferGetStatusResult: Array<{
|
||||
$: {
|
||||
TransferID: string;
|
||||
Status: string;
|
||||
StatusDescription: string;
|
||||
DomainName: string;
|
||||
Date: string;
|
||||
LockTransferDate?: string;
|
||||
TransferOrderDetailID?: string;
|
||||
IsLocked?: string;
|
||||
AuthInfo?: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Transfer Create Response
|
||||
export interface ITransferCreateResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainTransferCreateResult: Array<{
|
||||
$: {
|
||||
TransferID: string;
|
||||
OrderID: string;
|
||||
IsSuccess?: string;
|
||||
Status: string;
|
||||
StatusDescription: string;
|
||||
ChargedAmount: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Transfer Update Status Response
|
||||
export interface ITransferUpdateStatusResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
TransferUpdateStatusResult: Array<{
|
||||
$: {
|
||||
Domain: string;
|
||||
Updated: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Transfer Get Info Response
|
||||
export interface ITransferGetInfoResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
TransferGetInfoResult: Array<{
|
||||
$: {
|
||||
TransferID: string;
|
||||
DomainName: string;
|
||||
Status: string;
|
||||
StatusDescription: string;
|
||||
AuthInfo?: string;
|
||||
Date: string;
|
||||
WhoisguardStatus?: string;
|
||||
OrderDate: string;
|
||||
OrderID: string;
|
||||
TransferOrderDetailID: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Nameserver Info
|
||||
export interface INsInfo {
|
||||
nameserver: string;
|
||||
ip: string;
|
||||
statuses: string[];
|
||||
}
|
||||
|
||||
// Nameserver Create Response
|
||||
export interface INsCreateResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainNSCreateResult: Array<{
|
||||
$: {
|
||||
Domain: string;
|
||||
Nameserver: string;
|
||||
IP: string;
|
||||
IsSuccess: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Nameserver Delete Response
|
||||
export interface INsDeleteResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainNSDeleteResult: Array<{
|
||||
$: {
|
||||
Domain: string;
|
||||
Nameserver: string;
|
||||
IsSuccess: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Nameserver Get Info Response
|
||||
export interface INsGetInfoResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainNSInfoResult: Array<{
|
||||
$: {
|
||||
Nameserver: string;
|
||||
IP: string;
|
||||
Statuses?: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Nameserver Update Response
|
||||
export interface INsUpdateResponse extends IApiResponse {
|
||||
ApiResponse: {
|
||||
$: {
|
||||
Status: TApiResponseStatus;
|
||||
xmlns: string;
|
||||
};
|
||||
Errors: Array<{ Error: string[] }> | [{}];
|
||||
Warnings: Array<{ Warning: string[] }> | [{}];
|
||||
RequestedCommand: string[];
|
||||
CommandResponse: Array<{
|
||||
$: {
|
||||
Type: string;
|
||||
};
|
||||
DomainNSUpdateResult: Array<{
|
||||
$: {
|
||||
Domain: string;
|
||||
Nameserver: string;
|
||||
OldIP: string;
|
||||
IP: string;
|
||||
IsSuccess: string;
|
||||
};
|
||||
}>;
|
||||
}>;
|
||||
Server: string[];
|
||||
GMTTimeDifference: string[];
|
||||
ExecutionTime: string[];
|
||||
};
|
||||
}
|
||||
|
||||
// Error response
|
||||
export interface IErrorResponse {
|
||||
message: string;
|
||||
errors?: string[];
|
||||
}
|
Reference in New Issue
Block a user