/** * 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 { // Make the API request const response = await this.client.request( '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 { // Make the API request const response = await this.client.request( '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 { // Make the API request const response = await this.client.request( '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 { // Make the API request const response = await this.client.request( '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'; } }