@fwgapps/namecheap 0.5.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,1661 @@
1
- "use strict";var U=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var K=(r,e)=>{for(var s in e)U(r,s,{get:e[s],enumerable:!0})},W=(r,e,s,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of V(e))!q.call(r,o)&&o!==s&&U(r,o,{get:()=>e[o],enumerable:!(a=X(e,o))||a.enumerable});return r};var _=r=>W(U({},"__esModule",{value:!0}),r);var me={};K(me,{DomainDnsTag:()=>ce,DomainListSortBy:()=>J,DomainListType:()=>b,DomainTransferListType:()=>k,DomainTransferSortBy:()=>v,EmailType:()=>j,GetAddFundsStatus:()=>pe,IdnCode:()=>Y,LockAction:()=>x,RecordType:()=>z,SSLListSortBy:()=>ee,SSLListType:()=>Q,SSLType:()=>Z,UserActionName:()=>ae,UserListFindBy:()=>oe,UserPaymentType:()=>ne,UserProductCategory:()=>te,UserProductName:()=>re,UserProductType:()=>se,WhoIsListType:()=>ie,default:()=>C});module.exports=_(me);var F=require("fast-xml-parser"),h=require("change-case-all");var g=r=>{if(Array.isArray(r))return r.map(g).filter(e=>e!=null&&e!=="");if(typeof r=="object"&&r!==null){let e=Object.keys(r);if(e.length===2&&e.includes("#text")&&e.some(s=>s!=="#text"&&r[s]===!0))return r["#text"];if(e.length===2&&e.some(s=>r[s]===!0)){let s=e.find(a=>r[a]!==!0);return g(r[s])}return Object.keys(r).reduce((s,a)=>{let o=a==="#text"?"value":a,n=g(r[a]);return n!=null&&n!==""&&(s[o]=n),s},{})}return r};var O=r=>`https://${r?"api.sandbox.namecheap.com":"api.namecheap.com"}/xml.response`,B=r=>r.status==="ERROR"||Object.hasOwnProperty.call(r,"errors"),y=(r,e="",s=!0)=>{let a=[];return Object.entries(r).forEach(([o,n])=>{let i=(0,h.pascalCase)(`${e} ${o}`);typeof n=="object"&&n!==null&&!Array.isArray(n)?a.push(...y(n,i)):typeof n=="object"&&n!==null&&Array.isArray(n)?n.forEach((m,p)=>{s?a.push([`${i}[${p+1}]`,String(m)]):a.push([`${i}${p+1}`,String(m)])}):n!=null&&a.push([i,String(n)])}),a},$=["apiResponse.commandResponse.tlds.tld","apiResponse.commandResponse.tlds.tld.categories","apiResponse.commandResponse.domainGetListResult.domain","apiResponse.commandResponse.domainCheckResult","apiResponse.commandResponse.userGetPricingResult.productType.productCategory","apiResponse.commandResponse.userGetPricingResult.productType.productCategory.product","apiResponse.commandResponse.userGetPricingResult.productType.productCategory.product.price","apiResponse.commandResponse.whoisguardGetListResult.whoisguardGetListResult.whoisguard","apiResponse.commandResponse.domainDnsGetEmailForwardingResult.forward","apiResponse.commandResponse.domainDnsSetHostsResult"],H=new F.XMLParser({allowBooleanAttributes:!0,attributeNamePrefix:"",ignoreAttributes:!1,processEntities:!0,parseTagValue:!0,parseAttributeValue:!0,trimValues:!0,isArray:(r,e)=>$.includes(e),transformTagName:r=>(0,h.camelCase)(r),transformAttributeName:r=>(0,h.camelCase)(r)});async function t(r,e,s={}){let{apiUser:a,apiKey:o,apiUrl:n,username:i,clientIp:m}=r,p=new URL(n);p.searchParams.append("ApiUser",a),p.searchParams.append("ApiKey",o),p.searchParams.append("UserName",i),p.searchParams.append("ClientIp",m),p.searchParams.append("Command",e),y(s).forEach(([l,G])=>{p.searchParams.append(l,G)});let c=await fetch(p.toString());if(!c.ok)throw new Error(`Error in API Namecheap: ${c.statusText}`);let d=await c.text(),f=H.parse(d),u=g(f.apiResponse);if(B(u)){let l=u.errors;throw{code:l.number||-1,message:l.value||"Unknown Error"}}return u}async function S(r,e,s={},a={}){let{apiUser:o,apiKey:n,apiUrl:i,username:m,clientIp:p}=r,c=new URL(i);c.searchParams.append("ApiUser",o),c.searchParams.append("ApiKey",n),c.searchParams.append("UserName",m),c.searchParams.append("ClientIp",p),c.searchParams.append("Command",e);let d=[];y(s).forEach(([R,M])=>{c.searchParams.append(R,M)}),y(a,"",!1).forEach(([R,M])=>{d.push({Key:R,Value:M})});let f={request:{RequestValues:d}},u=await fetch(c.toString(),{method:"POST",body:JSON.stringify(f)});if(!u.ok)throw new Error(`Error in API Namecheap: ${u.statusText}`);let l=await u.text(),G=H.parse(l),I=g(G.apiResponse);if(B(I)){let R=I.errors;throw{code:R.number,message:R.value}}return I}var z={A:"A",AAAA:"AAAA",ALIAS:"ALIAS",CAA:"CAA",CNAME:"CNAME",MX:"MX",MXE:"MXE",NS:"NS",TXT:"TXT",URL:"URL",URL301:"URL301",FRAME:"FRAME"},j={MXE:"MXE",MX:"MX",FWD:"FWD",OX:"OX"},x={Lock:"LOCK",Unlock:"UNLOCK"},b={All:"ALL",Expiring:"EXPIRING",Expired:"EXPIRED"},J={NameAsc:"NAME",NameDesc:"NAME_DESC",ExpireDateAsc:"EXPIREDATE",ExpireDateDesc:"EXPIREDATE_DESC",CreateDateAsc:"CREATEDATE",CreateDateDesc:"CREATEDATE_DESC"},Y={AFR:"afr",ALB:"alb",ARA:"ara",ARG:"arg",ARM:"arm",ASM:"asm",AST:"ast",AVE:"ave",AWA:"awa",AZE:"aze",BAK:"bak",BAL:"bal",BAN:"ban",BAQ:"baq",BAS:"bas",BEL:"bel",BEN:"ben",BHO:"bho",BOS:"bos",BUL:"bul",BUR:"bur",CAR:"car",CAT:"cat",CHE:"che",CHI:"chi",CHV:"chv",COP:"cop",COS:"cos",CZE:"cze",DAN:"dan",DIV:"div",DOI:"doi",DUT:"dut",ENG:"eng",EST:"est",FAO:"fao",FIJ:"fij",FIN:"fin",FRE:"fre",FRY:"fry",GEO:"geo",GER:"ger",GLA:"gla",GLE:"gle",GON:"gon",GRE:"gre",GUJ:"guj",HEB:"heb",HIN:"hin",HUN:"hun",INC:"inc",IND:"ind",INH:"inh",ISL:"isl",ITA:"ita",JAV:"jav",JPN:"jpn",KAS:"kas",KAZ:"kaz",KHM:"khm",KIR:"kir",KOR:"kor",KUR:"kur",LAO:"lao",LAV:"lav",LIT:"lit",LTZ:"ltz",MAL:"mal",MKD:"mkd",MLT:"mlt",MOL:"mol",MON:"mon",MRI:"mri",MSA:"msa",NEP:"nep",NOR:"nor",ORI:"ori",OSS:"oss",PAN:"pan",PER:"per",POL:"pol",POR:"por",PUS:"pus",RAJ:"raj",RUM:"rum",RUS:"rus",SAN:"san",SCR:"scr",SIN:"sin",SLO:"slo",SLV:"slv",SMO:"smo",SND:"snd",SOM:"som",SPA:"spa",SRD:"srd",SRP:"srp",SWA:"swa",SWE:"swe",SYR:"syr",TAM:"tam",TEL:"tel",TGK:"tgk",THA:"tha",TIB:"tib",TUR:"tur",UKR:"ukr",URD:"urd",UZB:"uzb",VIE:"vie",WEL:"wel",YID:"yid"},k={All:"ALL",InProgress:"INPROGRESS",Cancelled:"CANCELLED",Completed:"COMPLETED"},v={DomainName:"DOMAINNAME",DomainNameDesc:"DOMAINNAME_DESC",TransferDate:"TRANSFERDATE",TransferDateDesc:"TRANSFERDATE_DESC",StatusDate:"STATUSDATE",StatusDateDesc:"STATUSDATE_DESC"},Z={PositiveSSL:"PositiveSSL",EssentialSSL:"EssentialSSL",InstantSSL:"InstantSSL",InstantSSLPro:"InstantSSL Pro",PremiumSSL:"PremiumSSL",EVSSL:"EV SSL",PositiveSSLWildcard:"PositiveSSL Wildcard",EssentialSSLWildcard:"EssentialSSL Wildcard",PremiumSSLWildcard:"PremiumSSL Wildcard",PositiveSSLMultiDomain:"PositiveSSL Multi Domain",MultiDomainSSL:"Multi Domain SSL",UnifiedCommunications:"Unified Communications",EVMultiDomainSSL:"EV Multi Domain SSL"},Q={ALL:"ALL",Processing:"Processing",EmailSent:"EmailSent",TechnicalProblem:"TechnicalProblem",InProgress:"InProgress",Completed:"Completed",Deactivated:"Deactivated",Active:"Active",Cancelled:"Cancelled",NewPurchase:"NewPurchase",NewRenewal:"NewRenewal"},ee={PurchaseDate:"PURCHASEDATE",PurchaseDateDesc:"PURCHASEDATE_DESC",SSLType:"SSLTYPE",SSLTypeDesc:"SSLTYPE_DESC",ExpireDateTime:"EXPIREDATETIME",ExpireDateTimeDesc:"EXPIREDATETIME_DESC",Hostname:"Host_Name",HostnameDesc:"Host_Name_DESC"},se={Domain:"DOMAIN",SslCertificate:"SSLCERTIFICATE"},te={Domains:"DOMAINS",Comodo:"COMODO"},ae={Register:"REGISTER",Renew:"RENEW",Reactivate:"REACTIVATE",Transfer:"TRANSFER",Purchase:"PURCHASE"},re={COM:"COM",InstantSsl:"INSTANTSSL"},ne={CreditCard:"Creditcard"},oe={EmailAddress:"EMAILADDRESS",DomainName:"DOMAINNAME",Username:"USERNAME"},ie={All:"ALL",Alloted:"ALLOTED",Free:"FREE",Discard:"DISCARD"},pe={Created:"CREATED",Submitted:"SUBMITTED",Completed:"COMPLETED",Failed:"FAILED",Expired:"EXPIRED"},ce={Issue:"issue",IssueWild:"issuewild",IODEF:"iodef"};var P=class{constructor(e){this.config=e}async getList(e={listType:b.All,page:1,pageSize:20}){let s=await t(this.config,"namecheap.domains.getList",e);return{data:s.commandResponse.domainGetListResult,paging:s.commandResponse.paging}}async getContacts(e){return(await t(this.config,"namecheap.domains.getContacts",{domainName:e})).commandResponse.domainContactsResult}async create(e,s){return(await t(this.config,"namecheap.domains.create",{...s,domainName:e})).commandResponse.domainCreateResult}async getTldList(){return(await t(this.config,"namecheap.domains.getTldList")).commandResponse.tlds}async setContacts(e,s){return(await t(this.config,"namecheap.domains.setContacts",{...s,domainName:e})).commandResponse.domainSetContactResult}async check(e){return(await t(this.config,"namecheap.domains.check",{domainList:e.join()})).commandResponse.domainCheckResult}async reactivate(e,s={}){return(await t(this.config,"namecheap.domains.reactivate",{...s,domainName:e})).commandResponse.domainReactivateResult}async renew(e,s){return(await t(this.config,"namecheap.domains.renew",{...s,domainName:e})).commandResponse.domainRenewResult}async getRegistrarLock(e){return(await t(this.config,"namecheap.domains.getRegistrarLock",{domainName:e})).commandResponse.domainGetRegistrarLockResult}async setRegistrarLock(e,s={lockAction:x.Lock}){return(await t(this.config,"namecheap.domains.setRegistrarLock",{...s,domainName:e})).commandResponse.domainSetRegistrarLockResult}async getInfo(e,s){return(await t(this.config,"namecheap.domains.getInfo",{domainName:e,hostName:s})).commandResponse.domainGetInfoResult}};var L=class{constructor(e){this.config=e}async setDefault(e,s){return(await t(this.config,"namecheap.domains.dns.setDefault",{sld:e,tld:s})).commandResponse.domainDnsSetDefaultResult}async setCustom(e,s,a){return(await t(this.config,"namecheap.domains.dns.setCustom",{sld:e,tld:s,nameservers:a})).commandResponse.domainDNSSetCustomResult}async getList(e,s){return(await t(this.config,"namecheap.domains.dns.getList",{sld:e,tld:s})).commandResponse.domainDnsGetListResult}async getHosts(e,s){return(await t(this.config,"namecheap.domains.dns.getHosts",{sld:e,tld:s})).commandResponse.domainDnsGetHostsResult}async getEmailForwarding(e){return(await t(this.config,"namecheap.domains.dns.getEmailForwarding",{domainName:e})).commandResponse.domainDnsGetEmailForwardingResult}async setEmailForwarding(e,s){return(await t(this.config,"namecheap.domains.dns.setEmailForwarding",{...s,domainName:e})).commandResponse.domainDnsSetEmailForwardingResult}async setHosts(e,s,a){let{hosts:o}=a,n=o.reduce((m,p,c)=>(Object.entries(p).forEach(([d,f])=>{m[d][c]=f}),m),{hostname:[],ttl:[],address:[],mxpref:[],recordType:[]}),i;return o.length>10?i=await S(this.config,"namecheap.domains.dns.setHosts",{SLD:e,TLD:s},{...n,tag:a.tag,flag:a.flag,emailType:a.emailType}):i=await t(this.config,"namecheap.domains.dns.setHosts",{...n,sld:e,tld:s,tag:a.tag,flag:a.flag,emailType:a.emailType}),i.commandResponse.domainDnsSetHostsResult}};var A=class{constructor(e){this.config=e}async create(e,s,a,o){return(await t(this.config,"namecheap.domains.ns.create",{sld:e,tld:s,nameserver:a,ip:o})).commandResponse.domainNsCreateResult}async delete(e,s,a){return(await t(this.config,"namecheap.domains.ns.delete",{sld:e,tld:s,nameserver:a})).commandResponse.domainNsDeleteResult}async getInfo(e,s,a){return(await t(this.config,"namecheap.domains.ns.getInfo",{sld:e,tld:s,nameserver:a})).commandResponse.domainNsInfoResult}async update(e,s,a,o,n){return(await t(this.config,"namecheap.domains.ns.update",{sld:e,tld:s,nameserver:a,ip:o,oldIp:n})).commandResponse.domainNsUpdateResult}};var D=class{constructor(e){this.config=e}async create(e,s){return(await t(this.config,"namecheap.domains.transfer.create",{domainName:e,...s})).commandResponse.domainTransferCreateResult}async getStatus(e){return(await t(this.config,"namecheap.domains.transfer.getStatus",{transferID:e})).commandResponse.domainTransferGetStatusResult}async updateStatus(e,s){return(await t(this.config,"namecheap.domains.transfer.updateStatus",{transferID:e,resubmit:s})).commandResponse.domainTransferUpdateStatusResult}async getList(e={listType:k.All,page:1,pageSize:10,sortBy:v.DomainName}){let s=await t(this.config,"namecheap.domains.transfer.getList",e);return{data:s.commandResponse.transferGetListResult,paging:s.commandResponse.paging}}};var E=class{constructor(e){this.config=e}async create(e){return(await t(this.config,"namecheap.ssl.create",e)).commandResponse.sslCreateResult}async getList(e){return(await t(this.config,"namecheap.ssl.getList",e)).commandResponse.sslListResult}async parseCSR(e,s){return(await S(this.config,"namecheap.ssl.parseCSR",{csr:e,certificateType:s})).commandResponse.sslParseCsrResult}async getApproverEmailList(e,s){return(await t(this.config,"namecheap.ssl.getApproverEmailList",{domainName:e,certificateType:s})).commandResponse.getApproverEmailListResult}async activate(e,s){return(await t(this.config,"namecheap.ssl.activate",{certificateId:e,...s})).commandResponse.sslActivateResult}async resendApproverEmail(e){return(await t(this.config,"namecheap.ssl.resendApproverEmail",{certificateId:e})).commandResponse.sslResendApproverEmailResult}async getInfo(e){return(await t(this.config,"namecheap.ssl.getInfo",{certificateId:e})).commandResponse.sslGetInfoResult}async renew(e,s){return(await t(this.config,"namecheap.ssl.renew",{certificateId:e,...s})).commandResponse.sslRenewResult}async reissue(e,s){return(await t(this.config,"namecheap.ssl.reissue",{certificateId:e,...s})).commandResponse.sslActivateResult}async resendFulfillmentEmail(e){return(await t(this.config,"namecheap.ssl.resendfulfillmentemail",{certificateId:e})).commandResponse.sslResendFulfillmentEmailResult}async purchaseMoreSANS(e,s){return(await t(this.config,"namecheap.ssl.purchasemoresans",{certificateId:e,numberOfSANSToAdd:s})).commandResponse.sslPurchaseMoreSansResult}async revokeCertificate(e,s){return(await t(this.config,"namecheap.ssl.revokecertificate",{certificateId:e,certificateType:s})).commandResponse.revokeCertificateResult}async editDCVMethod(e,s){return(await t(this.config,"namecheap.ssl.editDCVMethod",{certificateId:e,...s})).commandResponse.sslEditDcvMethodResult}};var T=class{constructor(e){this.config=e}async getPricing(e){return(await t(this.config,"namecheap.users.getPricing",e)).commandResponse.userGetPricingResult}async getBalances(){return(await t(this.config,"namecheap.users.getBalances")).commandResponse.userGetBalancesResult}async changePassword(e,s){return(await t(this.config,"namecheap.users.changePassword",{oldPassword:e,newPassword:s})).commandResponse.userChangePasswordResult}async update(e){return(await t(this.config,"namecheap.users.update",e)).commandResponse.userUpdateResult}async createAddFundsRequest(e,s){return(await t(this.config,"namecheap.users.createaddfundsrequest",{...s,username:e})).commandResponse.createaddfundsrequestresult}async getAddFundsStatus(e){return(await t(this.config,"namecheap.users.getAddFundsStatus",{tokenId:e})).commandResponse.getAddFundsStatusResult}async create(e){return(await t(this.config,"namecheap.users.create",e)).commandResponse.userCreateResult}async login(e){return(await t(this.config,"namecheap.users.login",{password:e})).commandResponse.userLoginResult}async resetPassword(e){return(await t(this.config,"namecheap.users.resetPassword",e)).commandResponse.userResetPasswordResult}};var w=class{constructor(e){this.config=e}async create(e){return(await t(this.config,"namecheap.users.address.create",e)).commandResponse.addressCreateResult}async delete(e){return(await t(this.config,"namecheap.users.address.delete",{addressId:e})).commandResponse.addressDeleteResult}async getInfo(e){return(await t(this.config,"namecheap.users.address.getInfo",{addressId:e})).commandResponse.getAddressInfoResult}async getList(){return(await t(this.config,"namecheap.users.address.getList")).commandResponse.addressGetListResult}async setDefault(e){return(await t(this.config,"namecheap.users.address.setDefault",{addressId:e})).commandResponse.addressSetDefaultResult}async update(e,s){return(await t(this.config,"namecheap.users.address.update",{...s,addressId:e})).commandResponse.addressUpdateResult}};var N=class{constructor(e){this.config=e}async changeEmailAddress(e){return(await t(this.config,"namecheap.whoisguard.changeemailaddress",{whoIsGuardId:e})).commandResponse.whoisguardChangeEmailAddressResult}async enable(e,s){return(await t(this.config,"namecheap.whoisguard.enable",{whoIsGuardId:e,forwardedToEmail:s})).commandResponse.whoisguardEnableResult}async disable(e){return(await t(this.config,"namecheap.whoisguard.disable",{whoIsGuardId:e})).commandResponse.whoisguardDisableResult}async getList(e){let s=await t(this.config,"namecheap.whoisguard.getList",e);return{data:s.commandResponse.whoisguardGetListResult,paging:s.commandResponse.paging}}async renew(e,s,a){return(await t(this.config,"namecheap.whoisguard.renew",{whoIsGuardId:e,year:s,promotionCode:a})).commandResponse.whoisguardRenewResult}};var C=class{get domainPrivacy(){return this.whoIsGuard}constructor(e){let{apiUser:s,apiKey:a,username:o,clientIp:n,sandbox:i}=e;this.apiUser=s,this.apiKey=a,this.username=o||s,this.clientIp=n,this.apiUrl=O(i),this.domains=new P(this.getConfig()),this.domainsDns=new L(this.getConfig()),this.domainsNs=new A(this.getConfig()),this.domainsTransfer=new D(this.getConfig()),this.ssl=new E(this.getConfig()),this.users=new T(this.getConfig()),this.usersAddress=new w(this.getConfig()),this.whoIsGuard=new N(this.getConfig())}getConfig(){return{apiUser:this.apiUser,apiKey:this.apiKey,username:this.username,clientIp:this.clientIp,apiUrl:this.apiUrl}}};0&&(module.exports={DomainDnsTag,DomainListSortBy,DomainListType,DomainTransferListType,DomainTransferSortBy,EmailType,GetAddFundsStatus,IdnCode,LockAction,RecordType,SSLListSortBy,SSLListType,SSLType,UserActionName,UserListFindBy,UserPaymentType,UserProductCategory,UserProductName,UserProductType,WhoIsListType});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Namecheap: () => Namecheap,
24
+ NamecheapError: () => NamecheapError,
25
+ NamecheapHttpError: () => NamecheapHttpError,
26
+ NamecheapParseError: () => NamecheapParseError,
27
+ createTransport: () => createTransport,
28
+ default: () => index_default,
29
+ dnsCommands: () => dnsCommands,
30
+ dnsGetEmailForwarding: () => getEmailForwarding,
31
+ dnsGetHosts: () => getHosts,
32
+ dnsGetList: () => getList,
33
+ dnsSetCustom: () => setCustom,
34
+ dnsSetDefault: () => setDefault,
35
+ dnsSetEmailForwarding: () => setEmailForwarding,
36
+ dnsSetHosts: () => setHosts,
37
+ domainsCheck: () => check,
38
+ domainsCommands: () => domainsCommands,
39
+ domainsCreate: () => create,
40
+ domainsGetContacts: () => getContacts,
41
+ domainsGetInfo: () => getInfo,
42
+ domainsGetList: () => getList2,
43
+ domainsGetRegistrarLock: () => getRegistrarLock,
44
+ domainsGetTldList: () => getTldList,
45
+ domainsReactivate: () => reactivate,
46
+ domainsRenew: () => renew,
47
+ domainsSetContacts: () => setContacts,
48
+ domainsSetRegistrarLock: () => setRegistrarLock,
49
+ nsCommands: () => nsCommands,
50
+ nsCreate: () => create2,
51
+ nsDelete: () => deleteNs,
52
+ nsGetInfo: () => getInfo2,
53
+ nsUpdate: () => update,
54
+ run: () => run,
55
+ sslActivate: () => activate,
56
+ sslCommands: () => sslCommands,
57
+ sslCreate: () => create3,
58
+ sslEditDCVMethod: () => editDCVMethod,
59
+ sslGetApproverEmailList: () => getApproverEmailList,
60
+ sslGetInfo: () => getInfo3,
61
+ sslGetList: () => getList3,
62
+ sslParseCSR: () => parseCSR,
63
+ sslPurchaseMoreSans: () => purchaseMoreSans,
64
+ sslReissue: () => reissue,
65
+ sslRenew: () => renew2,
66
+ sslResendApproverEmail: () => resendApproverEmail,
67
+ sslResendFulfillmentEmail: () => resendFulfillmentEmail,
68
+ sslRevokeCertificate: () => revokeCertificate,
69
+ transferCommands: () => transferCommands,
70
+ transferCreate: () => create4,
71
+ transferGetList: () => getList4,
72
+ transferGetStatus: () => getStatus,
73
+ transferUpdateStatus: () => updateStatus,
74
+ usersAddressCommands: () => usersAddressCommands,
75
+ usersAddressCreate: () => create6,
76
+ usersAddressDelete: () => deleteAddress,
77
+ usersAddressGetInfo: () => getInfo4,
78
+ usersAddressGetList: () => getList5,
79
+ usersAddressSetDefault: () => setDefault2,
80
+ usersAddressUpdate: () => update3,
81
+ usersChangePassword: () => changePassword,
82
+ usersCommands: () => usersCommands,
83
+ usersCreate: () => create5,
84
+ usersCreateAddFundsRequest: () => createAddFundsRequest,
85
+ usersGetAddFundsStatus: () => getAddFundsStatus,
86
+ usersGetBalances: () => getBalances,
87
+ usersGetPricing: () => getPricing,
88
+ usersLogin: () => login,
89
+ usersResetPassword: () => resetPassword,
90
+ usersUpdate: () => update2,
91
+ whoisGuardChangeEmailAddress: () => changeEmailAddress,
92
+ whoisGuardCommands: () => whoisGuardCommands,
93
+ whoisGuardDisable: () => disable,
94
+ whoisGuardEnable: () => enable,
95
+ whoisGuardGetList: () => getList6,
96
+ whoisGuardRenew: () => renew3
97
+ });
98
+ module.exports = __toCommonJS(index_exports);
99
+
100
+ // src/core/errors.ts
101
+ var NamecheapError = class extends Error {
102
+ code;
103
+ errors;
104
+ constructor(errors) {
105
+ const first = errors[0];
106
+ super(
107
+ first === void 0 ? "Unknown Namecheap error" : first.message.trim() === "" ? `Namecheap error ${first.code}` : first.message
108
+ );
109
+ this.name = "NamecheapError";
110
+ this.code = first?.code ?? -1;
111
+ this.errors = errors;
112
+ }
113
+ };
114
+ var NamecheapHttpError = class extends Error {
115
+ status;
116
+ statusText;
117
+ constructor(message, init) {
118
+ super(message, init?.cause === void 0 ? void 0 : { cause: init.cause });
119
+ this.name = "NamecheapHttpError";
120
+ this.status = init?.status;
121
+ this.statusText = init?.statusText ?? "";
122
+ }
123
+ };
124
+ var NamecheapParseError = class extends Error {
125
+ constructor(message, init) {
126
+ super(message, init?.cause === void 0 ? void 0 : { cause: init.cause });
127
+ this.name = "NamecheapParseError";
128
+ }
129
+ };
130
+
131
+ // src/core/serialize.ts
132
+ var ACRONYMS = [
133
+ "SLD",
134
+ "TLD",
135
+ "IP",
136
+ "ID",
137
+ "DNS",
138
+ "WG",
139
+ "MX",
140
+ "TTL",
141
+ "EPP",
142
+ "CSR",
143
+ "DCV",
144
+ "SSL"
145
+ ];
146
+ var hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
147
+ function splitWords(key) {
148
+ return key.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/[\s_]+/).filter((word) => word.length > 0);
149
+ }
150
+ function toWord(word) {
151
+ const upper = word.toUpperCase();
152
+ if (ACRONYMS.includes(upper)) return upper;
153
+ return word.charAt(0).toUpperCase() + word.slice(1);
154
+ }
155
+ function toParamName(key) {
156
+ return splitWords(key).map(toWord).join("");
157
+ }
158
+ function isPlainObject(value) {
159
+ if (typeof value !== "object" || value === null) return false;
160
+ const proto = Object.getPrototypeOf(value);
161
+ return proto === Object.prototype || proto === null;
162
+ }
163
+ function isObject(value) {
164
+ return typeof value === "object" && value !== null;
165
+ }
166
+ function serializeParams(params, opts = {}) {
167
+ const arrayStyle = opts.arrayStyle ?? "bracket";
168
+ const keys = opts.keys ?? {};
169
+ const out = [];
170
+ const walk = (obj, path, prefix) => {
171
+ for (const [key, value] of Object.entries(obj)) {
172
+ if (value === void 0 || value === null) continue;
173
+ const keyPath = [...path, key];
174
+ const dotted = keyPath.join(".");
175
+ const name = (hasOwn(keys, dotted) ? keys[dotted] : void 0) ?? prefix + toParamName(key);
176
+ if (Array.isArray(value)) {
177
+ if (value.some((item) => isPlainObject(item))) {
178
+ value.forEach((item, position) => {
179
+ if (item === void 0 || item === null) {
180
+ throw new TypeError(
181
+ `Array parameter "${dotted}" cannot contain null or undefined records`
182
+ );
183
+ }
184
+ if (!isPlainObject(item)) {
185
+ throw new TypeError(`Array parameter "${dotted}" cannot mix objects and scalars`);
186
+ }
187
+ for (const [field, fieldValue] of Object.entries(item)) {
188
+ if (fieldValue === void 0 || fieldValue === null) continue;
189
+ if (isObject(fieldValue)) {
190
+ throw new TypeError(
191
+ `Array parameter "${dotted}" field "${field}" must be a scalar value`
192
+ );
193
+ }
194
+ out.push([`${toParamName(field)}${position + 1}`, String(fieldValue)]);
195
+ }
196
+ });
197
+ continue;
198
+ }
199
+ let index = 0;
200
+ for (const item of value) {
201
+ if (item === void 0 || item === null) continue;
202
+ if (isObject(item)) {
203
+ throw new TypeError(
204
+ `Array parameter "${dotted}" cannot contain nested arrays or non-plain objects`
205
+ );
206
+ }
207
+ index += 1;
208
+ out.push([
209
+ arrayStyle === "bracket" ? `${name}[${index}]` : `${name}${index}`,
210
+ String(item)
211
+ ]);
212
+ }
213
+ } else if (isObject(value)) {
214
+ walk(value, keyPath, name);
215
+ } else {
216
+ out.push([name, String(value)]);
217
+ }
218
+ }
219
+ };
220
+ walk(params, [], "");
221
+ return out;
222
+ }
223
+
224
+ // src/core/define.ts
225
+ var RESERVED_NAMES = /* @__PURE__ */ new Set(["apiuser", "apikey", "username", "clientip", "command"]);
226
+ function defineCommand(def) {
227
+ return def;
228
+ }
229
+ async function run(command, send, ...args) {
230
+ const params = args[0] ?? {};
231
+ command.validate?.(params);
232
+ const options = {};
233
+ if (command.arrayStyle !== void 0) options.arrayStyle = command.arrayStyle;
234
+ if (command.keys !== void 0) options.keys = command.keys;
235
+ const serialized = serializeParams(params, options);
236
+ for (const [name] of serialized) {
237
+ if (RESERVED_NAMES.has(name.toLowerCase())) {
238
+ throw new TypeError(`Parameter "${name}" is reserved: the client sets it itself`);
239
+ }
240
+ }
241
+ const el = await send({ command: command.name, params: serialized });
242
+ try {
243
+ return command.parse(el);
244
+ } catch (error) {
245
+ if (error instanceof NamecheapParseError) {
246
+ throw new NamecheapParseError(
247
+ `${command.name}: Namecheap reported success but the response could not be read; the action may have been performed, verify before retrying`,
248
+ { cause: error }
249
+ );
250
+ }
251
+ throw error;
252
+ }
253
+ }
254
+ function group(commands, send) {
255
+ const out = {};
256
+ for (const [key, command] of Object.entries(commands)) {
257
+ out[key] = (params) => run(command, send, params);
258
+ }
259
+ return out;
260
+ }
261
+
262
+ // src/core/fields.ts
263
+ function optionalField(key, value) {
264
+ return value === void 0 ? {} : { [key]: value };
265
+ }
266
+ function firstLenientNumber(el, ...names) {
267
+ for (const name of names) {
268
+ if (el.optionalString(name) !== void 0) return el.lenientNumber(name);
269
+ }
270
+ return void 0;
271
+ }
272
+
273
+ // src/commands/dns.ts
274
+ var setDefault = /* @__PURE__ */ defineCommand({
275
+ name: "namecheap.domains.dns.setDefault",
276
+ parse: (cr) => {
277
+ const result = cr.one("DomainDNSSetDefaultResult");
278
+ return { domain: result.string("Domain"), updated: result.boolean("Updated") };
279
+ }
280
+ });
281
+ var setCustom = /* @__PURE__ */ defineCommand({
282
+ name: "namecheap.domains.dns.setCustom",
283
+ parse: (cr) => {
284
+ const result = cr.one("DomainDNSSetCustomResult");
285
+ return { domain: result.string("Domain"), updated: result.boolean("Updated") };
286
+ }
287
+ });
288
+ var getList = /* @__PURE__ */ defineCommand({
289
+ name: "namecheap.domains.dns.getList",
290
+ parse: (cr) => {
291
+ const result = cr.one("DomainDNSGetListResult");
292
+ return {
293
+ domain: result.string("Domain"),
294
+ isUsingOurDNS: result.boolean("IsUsingOurDNS"),
295
+ ...optionalField("isPremiumDNS", result.optionalBoolean("IsPremiumDNS")),
296
+ ...optionalField("isUsingFreeDNS", result.optionalBoolean("IsUsingFreeDNS")),
297
+ nameservers: result.all("Nameserver").map((ns) => ns.text())
298
+ };
299
+ }
300
+ });
301
+ function parseHost(host) {
302
+ return {
303
+ hostId: host.number("HostId"),
304
+ name: host.string("Name"),
305
+ type: host.string("Type"),
306
+ address: host.string("Address"),
307
+ mxPref: host.number("MXPref"),
308
+ ttl: host.number("TTL"),
309
+ ...optionalField("associatedAppTitle", host.optionalString("AssociatedAppTitle")),
310
+ ...optionalField("friendlyName", host.optionalString("FriendlyName")),
311
+ ...optionalField("isActive", host.optionalBoolean("IsActive")),
312
+ ...optionalField("isDDNSEnabled", host.optionalBoolean("IsDDNSEnabled"))
313
+ };
314
+ }
315
+ var getHosts = /* @__PURE__ */ defineCommand({
316
+ name: "namecheap.domains.dns.getHosts",
317
+ parse: (cr) => {
318
+ const result = cr.one("DomainDNSGetHostsResult");
319
+ return {
320
+ domain: result.string("Domain"),
321
+ ...optionalField("emailType", result.optionalString("EmailType")),
322
+ isUsingOurDNS: result.boolean("IsUsingOurDNS"),
323
+ hosts: result.all("host").map(parseHost)
324
+ };
325
+ }
326
+ });
327
+ var getEmailForwarding = /* @__PURE__ */ defineCommand({
328
+ name: "namecheap.domains.dns.getEmailForwarding",
329
+ parse: (cr) => {
330
+ const result = cr.one("DomainEmailForwardingResult");
331
+ return {
332
+ domain: result.string("Domain"),
333
+ forwards: result.all("Forward").map((forward) => ({
334
+ mailbox: forward.string("mailbox"),
335
+ ...optionalField("forwardTo", forward.optionalString("ForwardTo"))
336
+ }))
337
+ };
338
+ }
339
+ });
340
+ var setEmailForwarding = /* @__PURE__ */ defineCommand({
341
+ name: "namecheap.domains.dns.setEmailForwarding",
342
+ parse: (cr) => {
343
+ const result = cr.one("DomainEmailForwardingResult");
344
+ return { domain: result.string("Domain"), isSuccess: result.boolean("IsSuccess") };
345
+ }
346
+ });
347
+ var setHosts = /* @__PURE__ */ defineCommand({
348
+ name: "namecheap.domains.dns.setHosts",
349
+ validate: (params) => {
350
+ if (!params.hosts?.some((host) => host !== void 0 && host !== null)) {
351
+ throw new TypeError(
352
+ "dns.setHosts requires at least one host record: it replaces the whole zone, so an empty list would delete every record"
353
+ );
354
+ }
355
+ },
356
+ parse: (cr) => {
357
+ const result = cr.one("DomainDNSSetHostsResult");
358
+ return {
359
+ domain: result.string("Domain"),
360
+ ...optionalField("emailType", result.optionalString("EmailType")),
361
+ isSuccess: result.boolean("IsSuccess")
362
+ };
363
+ }
364
+ });
365
+ var dnsCommands = {
366
+ setDefault,
367
+ setCustom,
368
+ getList,
369
+ getHosts,
370
+ getEmailForwarding,
371
+ setEmailForwarding,
372
+ setHosts
373
+ };
374
+
375
+ // src/core/paging.ts
376
+ function parsePaging(el) {
377
+ return {
378
+ totalItems: el.one("TotalItems").numberText(),
379
+ currentPage: el.one("CurrentPage").numberText(),
380
+ pageSize: el.one("PageSize").numberText()
381
+ };
382
+ }
383
+
384
+ // src/commands/domains.ts
385
+ function parseListItem(domain) {
386
+ return {
387
+ id: domain.number("ID"),
388
+ name: domain.string("Name"),
389
+ user: domain.string("User"),
390
+ created: domain.string("Created"),
391
+ expires: domain.string("Expires"),
392
+ isExpired: domain.boolean("IsExpired"),
393
+ isLocked: domain.boolean("IsLocked"),
394
+ autoRenew: domain.boolean("AutoRenew"),
395
+ whoisGuard: domain.string("WhoisGuard"),
396
+ isPremium: domain.boolean("IsPremium"),
397
+ isOurDNS: domain.boolean("IsOurDNS")
398
+ };
399
+ }
400
+ var getList2 = /* @__PURE__ */ defineCommand({
401
+ name: "namecheap.domains.getList",
402
+ parse: (cr) => ({
403
+ domains: (cr.optional("DomainGetListResult")?.all("Domain") ?? []).map(parseListItem),
404
+ paging: parsePaging(cr.one("Paging"))
405
+ })
406
+ });
407
+ var check = /* @__PURE__ */ defineCommand({
408
+ name: "namecheap.domains.check",
409
+ parse: (cr) => cr.all("DomainCheckResult").map((item) => ({
410
+ domain: item.string("Domain"),
411
+ available: item.boolean("Available"),
412
+ ...optionalField("errorNo", item.optionalNumber("ErrorNo")),
413
+ ...optionalField("description", item.optionalString("Description")),
414
+ isPremiumName: item.boolean("IsPremiumName"),
415
+ premiumRegistrationPrice: item.number("PremiumRegistrationPrice"),
416
+ premiumRenewalPrice: item.number("PremiumRenewalPrice"),
417
+ premiumRestorePrice: item.number("PremiumRestorePrice"),
418
+ premiumTransferPrice: item.number("PremiumTransferPrice"),
419
+ icannFee: item.number("IcannFee"),
420
+ eapFee: item.number("EapFee")
421
+ }))
422
+ });
423
+ var getRegistrarLock = /* @__PURE__ */ defineCommand({
424
+ name: "namecheap.domains.getRegistrarLock",
425
+ parse: (cr) => {
426
+ const result = cr.one("DomainGetRegistrarLockResult");
427
+ return {
428
+ domain: result.string("Domain"),
429
+ registrarLockStatus: result.boolean("RegistrarLockStatus")
430
+ };
431
+ }
432
+ });
433
+ var setRegistrarLock = /* @__PURE__ */ defineCommand({
434
+ name: "namecheap.domains.setRegistrarLock",
435
+ parse: (cr) => {
436
+ const result = cr.one("DomainSetRegistrarLockResult");
437
+ return { domain: result.string("Domain"), isSuccess: result.boolean("IsSuccess") };
438
+ }
439
+ });
440
+ var reactivate = /* @__PURE__ */ defineCommand({
441
+ name: "namecheap.domains.reactivate",
442
+ parse: (cr) => {
443
+ const result = cr.one("DomainReactivateResult");
444
+ return {
445
+ domain: result.string("Domain"),
446
+ isSuccess: result.boolean("IsSuccess"),
447
+ chargedAmount: result.number("ChargedAmount"),
448
+ orderID: result.number("OrderID"),
449
+ transactionID: result.number("TransactionID")
450
+ };
451
+ }
452
+ });
453
+ var renew = /* @__PURE__ */ defineCommand({
454
+ name: "namecheap.domains.renew",
455
+ parse: (cr) => {
456
+ const result = cr.one("DomainRenewResult");
457
+ const details = result.one("DomainDetails");
458
+ return {
459
+ domainName: result.string("DomainName"),
460
+ domainID: result.number("DomainID"),
461
+ renew: result.boolean("Renew"),
462
+ chargedAmount: result.number("ChargedAmount"),
463
+ orderID: result.number("OrderID"),
464
+ transactionID: result.number("TransactionID"),
465
+ domainDetails: {
466
+ expiredDate: details.one("ExpiredDate").text(),
467
+ numYears: details.one("NumYears").numberText()
468
+ }
469
+ };
470
+ }
471
+ });
472
+ var setContacts = /* @__PURE__ */ defineCommand({
473
+ name: "namecheap.domains.setContacts",
474
+ parse: (cr) => {
475
+ const result = cr.one("DomainSetContactResult");
476
+ return { domain: result.string("Domain"), isSuccess: result.boolean("IsSuccess") };
477
+ }
478
+ });
479
+ var create = /* @__PURE__ */ defineCommand({
480
+ name: "namecheap.domains.create",
481
+ parse: (cr) => {
482
+ const result = cr.one("DomainCreateResult");
483
+ return {
484
+ domain: result.string("Domain"),
485
+ registered: result.boolean("Registered"),
486
+ chargedAmount: result.number("ChargedAmount"),
487
+ domainID: result.number("DomainID"),
488
+ orderID: result.number("OrderID"),
489
+ transactionID: result.number("TransactionID"),
490
+ ...optionalField("whoisguardEnable", result.lenientBoolean("WhoisguardEnable")),
491
+ ...optionalField("nonRealTimeDomain", result.lenientBoolean("NonRealTimeDomain"))
492
+ };
493
+ }
494
+ });
495
+ var getTldList = /* @__PURE__ */ defineCommand({
496
+ name: "namecheap.domains.getTldList",
497
+ parse: (cr) => (cr.optional("Tlds")?.all("Tld") ?? []).map((tld) => ({
498
+ name: tld.string("Name"),
499
+ nonRealTimeDomain: tld.boolean("NonRealTimeDomain"),
500
+ minRegisterYears: tld.number("MinRegisterYears"),
501
+ maxRegisterYears: tld.number("MaxRegisterYears"),
502
+ minRenewYears: tld.number("MinRenewYears"),
503
+ maxRenewYears: tld.number("MaxRenewYears"),
504
+ minTransferYears: tld.number("MinTransferYears"),
505
+ maxTransferYears: tld.number("MaxTransferYears"),
506
+ isApiRegisterable: tld.boolean("IsApiRegisterable"),
507
+ isApiRenewable: tld.boolean("IsApiRenewable"),
508
+ isApiTransferable: tld.boolean("IsApiTransferable"),
509
+ isEppRequired: tld.boolean("IsEppRequired"),
510
+ description: tld.text()
511
+ }))
512
+ });
513
+ function parseContact(contact) {
514
+ const text = (name) => contact.optionalText(name);
515
+ return {
516
+ ...optionalField("organizationName", text("OrganizationName")),
517
+ ...optionalField("jobTitle", text("JobTitle")),
518
+ ...optionalField("firstName", text("FirstName")),
519
+ ...optionalField("lastName", text("LastName")),
520
+ ...optionalField("address1", text("Address1")),
521
+ ...optionalField("address2", text("Address2")),
522
+ ...optionalField("city", text("City")),
523
+ ...optionalField("stateProvince", text("StateProvince")),
524
+ ...optionalField("postalCode", text("PostalCode")),
525
+ ...optionalField("country", text("Country")),
526
+ ...optionalField("phone", text("Phone")),
527
+ ...optionalField("emailAddress", text("EmailAddress"))
528
+ };
529
+ }
530
+ var getContacts = /* @__PURE__ */ defineCommand({
531
+ name: "namecheap.domains.getContacts",
532
+ parse: (cr) => {
533
+ const result = cr.one("DomainContactsResult");
534
+ const contact = (name) => {
535
+ const found = result.optional(name);
536
+ return found === void 0 ? void 0 : parseContact(found);
537
+ };
538
+ return {
539
+ domain: result.string("Domain"),
540
+ domainnameid: result.number("domainnameid"),
541
+ readonly: result.boolean("Readonly"),
542
+ ...optionalField("registrant", contact("Registrant")),
543
+ ...optionalField("tech", contact("Tech")),
544
+ ...optionalField("admin", contact("Admin")),
545
+ ...optionalField("auxBilling", contact("AuxBilling"))
546
+ };
547
+ }
548
+ });
549
+ function parseWhoisguard(whoisguard) {
550
+ const emailDetails = whoisguard.optional("EmailDetails");
551
+ return {
552
+ enabled: whoisguard.string("Enabled"),
553
+ id: whoisguard.one("ID").numberText(),
554
+ ...optionalField("expiredDate", whoisguard.optionalText("ExpiredDate")),
555
+ ...optionalField(
556
+ "emailDetails",
557
+ emailDetails === void 0 ? void 0 : {
558
+ whoisGuardEmail: emailDetails.string("WhoisGuardEmail"),
559
+ forwardedTo: emailDetails.string("ForwardedTo"),
560
+ lastAutoEmailChangeDate: emailDetails.string("LastAutoEmailChangeDate"),
561
+ autoEmailChangeFrequencyDays: emailDetails.number("AutoEmailChangeFrequencyDays")
562
+ }
563
+ )
564
+ };
565
+ }
566
+ var getInfo = /* @__PURE__ */ defineCommand({
567
+ name: "namecheap.domains.getInfo",
568
+ parse: (cr) => {
569
+ const result = cr.one("DomainGetInfoResult");
570
+ const details = result.one("DomainDetails");
571
+ const premiumDns = result.one("PremiumDnsSubscription");
572
+ const dns = result.one("DnsDetails");
573
+ const rights = result.one("Modificationrights");
574
+ return {
575
+ ...optionalField("status", result.optionalString("Status")),
576
+ id: result.number("ID"),
577
+ domainName: result.string("DomainName"),
578
+ ownerName: result.string("OwnerName"),
579
+ isOwner: result.boolean("IsOwner"),
580
+ isPremium: result.boolean("IsPremium"),
581
+ domainDetails: {
582
+ ...optionalField("createdDate", details.optionalText("CreatedDate")),
583
+ ...optionalField("expiredDate", details.optionalText("ExpiredDate")),
584
+ numYears: details.one("NumYears").numberText()
585
+ },
586
+ whoisguard: parseWhoisguard(result.one("Whoisguard")),
587
+ premiumDnsSubscription: {
588
+ useAutoRenew: premiumDns.one("UseAutoRenew").booleanText(),
589
+ subscriptionId: premiumDns.one("SubscriptionId").numberText(),
590
+ createdDate: premiumDns.one("CreatedDate").text(),
591
+ expirationDate: premiumDns.one("ExpirationDate").text(),
592
+ isActive: premiumDns.one("IsActive").booleanText()
593
+ },
594
+ dnsDetails: {
595
+ providerType: dns.string("ProviderType"),
596
+ isUsingOurDNS: dns.boolean("IsUsingOurDNS"),
597
+ hostCount: dns.number("HostCount"),
598
+ emailType: dns.string("EmailType"),
599
+ dynamicDNSStatus: dns.boolean("DynamicDNSStatus"),
600
+ isFailover: dns.boolean("IsFailover"),
601
+ nameservers: dns.all("Nameserver").map((nameserver) => nameserver.text())
602
+ },
603
+ modificationrights: {
604
+ ...optionalField("all", rights.optionalBoolean("All")),
605
+ rights: rights.all("Rights").map((right) => ({
606
+ type: right.string("Type"),
607
+ value: right.text()
608
+ }))
609
+ }
610
+ };
611
+ }
612
+ });
613
+ var domainsCommands = {
614
+ getList: getList2,
615
+ check,
616
+ getRegistrarLock,
617
+ setRegistrarLock,
618
+ reactivate,
619
+ renew,
620
+ setContacts,
621
+ create,
622
+ getTldList,
623
+ getContacts,
624
+ getInfo
625
+ };
626
+
627
+ // src/commands/ns.ts
628
+ var create2 = /* @__PURE__ */ defineCommand({
629
+ name: "namecheap.domains.ns.create",
630
+ parse: (cr) => {
631
+ const result = cr.one("DomainNSCreateResult");
632
+ return {
633
+ domain: result.string("Domain"),
634
+ nameserver: result.string("Nameserver"),
635
+ ip: result.string("IP"),
636
+ isSuccess: result.boolean("IsSuccess")
637
+ };
638
+ }
639
+ });
640
+ var deleteNs = /* @__PURE__ */ defineCommand({
641
+ name: "namecheap.domains.ns.delete",
642
+ parse: (cr) => {
643
+ const result = cr.one("DomainNSDeleteResult");
644
+ return {
645
+ domain: result.string("Domain"),
646
+ nameserver: result.string("Nameserver"),
647
+ isSuccess: result.boolean("IsSuccess")
648
+ };
649
+ }
650
+ });
651
+ var getInfo2 = /* @__PURE__ */ defineCommand({
652
+ name: "namecheap.domains.ns.getInfo",
653
+ parse: (cr) => {
654
+ const result = cr.one("DomainNSInfoResult");
655
+ const statuses = result.optional("NameserverStatuses");
656
+ return {
657
+ domain: result.string("Domain"),
658
+ nameserver: result.string("Nameserver"),
659
+ ip: result.string("IP"),
660
+ ...optionalField(
661
+ "nameserverStatuses",
662
+ statuses?.all("Status").map((status) => status.text())
663
+ )
664
+ };
665
+ }
666
+ });
667
+ var update = /* @__PURE__ */ defineCommand({
668
+ name: "namecheap.domains.ns.update",
669
+ parse: (cr) => {
670
+ const result = cr.one("DomainNSUpdateResult");
671
+ return {
672
+ domain: result.string("Domain"),
673
+ nameserver: result.string("Nameserver"),
674
+ isSuccess: result.boolean("IsSuccess")
675
+ };
676
+ }
677
+ });
678
+ var nsCommands = { create: create2, delete: deleteNs, getInfo: getInfo2, update };
679
+
680
+ // src/commands/ssl.ts
681
+ var create3 = /* @__PURE__ */ defineCommand({
682
+ name: "namecheap.ssl.create",
683
+ keys: { sansToAdd: "SANStoADD" },
684
+ parse: (cr) => {
685
+ const wrapper = cr.optional("SSLCreateResult") ?? cr.children()[0];
686
+ if (wrapper === void 0) return {};
687
+ const nested = wrapper.optional("SSLCertificate");
688
+ const sources = nested === void 0 ? [wrapper] : [wrapper, nested];
689
+ const pick = (read) => sources.map(read).find((value) => value !== void 0);
690
+ return {
691
+ ...optionalField("isSuccess", wrapper.lenientBoolean("IsSuccess")),
692
+ ...optionalField("orderID", firstLenientNumber(wrapper, "OrderID", "OrderId")),
693
+ ...optionalField(
694
+ "transactionID",
695
+ firstLenientNumber(wrapper, "TransactionID", "TransactionId")
696
+ ),
697
+ ...optionalField("chargedAmount", wrapper.lenientNumber("ChargedAmount")),
698
+ ...optionalField(
699
+ "certificateID",
700
+ pick((el) => el.lenientNumber("CertificateID"))
701
+ ),
702
+ ...optionalField(
703
+ "created",
704
+ pick((el) => el.optionalString("Created"))
705
+ ),
706
+ ...optionalField(
707
+ "sslType",
708
+ pick((el) => el.optionalString("SSLType"))
709
+ ),
710
+ ...optionalField(
711
+ "status",
712
+ pick((el) => el.optionalString("Status"))
713
+ )
714
+ };
715
+ }
716
+ });
717
+ function parseListItem2(ssl) {
718
+ return {
719
+ certificateID: ssl.number("CertificateID"),
720
+ hostName: ssl.string("HostName"),
721
+ sslType: ssl.string("SSLType"),
722
+ purchaseDate: ssl.string("PurchaseDate"),
723
+ expireDate: ssl.string("ExpireDate"),
724
+ ...optionalField("status", ssl.optionalString("Status"))
725
+ };
726
+ }
727
+ var getList3 = /* @__PURE__ */ defineCommand({
728
+ name: "namecheap.ssl.getList",
729
+ parse: (cr) => ({
730
+ certificates: (cr.optional("SSLListResult")?.all("SSL") ?? []).map(parseListItem2),
731
+ paging: parsePaging(cr.one("Paging"))
732
+ })
733
+ });
734
+ var parseCSR = /* @__PURE__ */ defineCommand({
735
+ name: "namecheap.ssl.parseCSR",
736
+ keys: { csr: "csr" },
737
+ parse: (cr) => {
738
+ const details = cr.one("SSLParseCSRResult").one("CSRDetails");
739
+ return {
740
+ commonName: details.one("CommonName").text(),
741
+ domainName: details.one("DomainName").text(),
742
+ country: details.one("Country").text(),
743
+ organisationUnit: details.one("OrganisationUnit").text(),
744
+ organisation: details.one("Organisation").text(),
745
+ state: details.one("State").text(),
746
+ locality: details.one("Locality").text(),
747
+ email: details.one("Email").text()
748
+ };
749
+ }
750
+ });
751
+ function emails(result, group2) {
752
+ return (result.optional(group2)?.all("email") ?? []).map((email) => email.text());
753
+ }
754
+ var getApproverEmailList = /* @__PURE__ */ defineCommand({
755
+ name: "namecheap.ssl.getApproverEmailList",
756
+ parse: (cr) => {
757
+ const result = cr.one("GetApproverEmailListResult");
758
+ return {
759
+ domainEmails: emails(result, "Domainemails"),
760
+ genericEmails: emails(result, "Genericemails"),
761
+ manualEmails: emails(result, "Manualemails")
762
+ };
763
+ }
764
+ });
765
+ function parseHttpDcValidation(result) {
766
+ const validation = result.optional("HttpDCValidation");
767
+ if (validation === void 0) return void 0;
768
+ return {
769
+ valueAvailable: validation.boolean("ValueAvailable"),
770
+ ...optionalField("fileName", validation.optionalText("FileName")),
771
+ ...optionalField("fileContent", validation.optionalText("FileContent"))
772
+ };
773
+ }
774
+ function parseActivation(result) {
775
+ return {
776
+ id: result.number("ID"),
777
+ isSuccess: result.boolean("IsSuccess"),
778
+ ...optionalField("httpDCValidation", parseHttpDcValidation(result))
779
+ };
780
+ }
781
+ var activate = /* @__PURE__ */ defineCommand({
782
+ name: "namecheap.ssl.activate",
783
+ parse: (cr) => parseActivation(cr.one("SSLActivateResult"))
784
+ });
785
+ function parseResend(result) {
786
+ return { id: result.number("ID"), isSuccess: result.boolean("IsSuccess") };
787
+ }
788
+ var resendApproverEmail = /* @__PURE__ */ defineCommand({
789
+ name: "namecheap.ssl.resendApproverEmail",
790
+ parse: (cr) => parseResend(cr.one("SSLResendApproverEmailResult"))
791
+ });
792
+ var reissue = /* @__PURE__ */ defineCommand({
793
+ name: "namecheap.ssl.reissue",
794
+ parse: (cr) => parseActivation(cr.one("SSLReissueResult"))
795
+ });
796
+ var resendFulfillmentEmail = /* @__PURE__ */ defineCommand({
797
+ name: "namecheap.ssl.resendfulfillmentemail",
798
+ parse: (cr) => parseResend(cr.one("SSLResendFulfillmentEmailResult"))
799
+ });
800
+ var editDCVMethod = /* @__PURE__ */ defineCommand(
801
+ {
802
+ name: "namecheap.ssl.editDCVMethod",
803
+ parse: (cr) => parseActivation(cr.one("SSLEditDCVMethodResult"))
804
+ }
805
+ );
806
+ var getInfo3 = /* @__PURE__ */ defineCommand({
807
+ name: "namecheap.ssl.getInfo",
808
+ keys: { returnCertificate: "Returncertificate", returnType: "Returntype" },
809
+ parse: (cr) => {
810
+ const result = cr.one("SSLGetInfoResult");
811
+ return {
812
+ certificateID: result.number("CertificateID"),
813
+ status: result.string("Status"),
814
+ ...optionalField("type", result.optionalString("Type")),
815
+ ...optionalField("commonName", result.optionalString("CommonName")),
816
+ ...optionalField("provider", result.optionalString("Provider")),
817
+ ...optionalField("issuedOn", result.optionalString("IssuedOn")),
818
+ ...optionalField("expires", result.optionalString("Expires"))
819
+ };
820
+ }
821
+ });
822
+ var renew2 = /* @__PURE__ */ defineCommand({
823
+ name: "namecheap.ssl.renew",
824
+ parse: (cr) => {
825
+ const result = cr.optional("SSLRenewResult") ?? cr.children()[0];
826
+ if (result === void 0) return {};
827
+ return {
828
+ ...optionalField("certificateID", result.lenientNumber("CertificateID")),
829
+ ...optionalField("years", result.lenientNumber("Years")),
830
+ ...optionalField("orderID", firstLenientNumber(result, "OrderID", "OrderId")),
831
+ ...optionalField(
832
+ "transactionID",
833
+ firstLenientNumber(result, "TransactionID", "TransactionId")
834
+ ),
835
+ ...optionalField("chargedAmount", result.lenientNumber("ChargedAmount"))
836
+ };
837
+ }
838
+ });
839
+ var purchaseMoreSans = /* @__PURE__ */ defineCommand({
840
+ name: "namecheap.ssl.purchasemoresans",
841
+ keys: { numberOfSansToAdd: "NumberOfSANSToAdd" },
842
+ parse: (cr) => {
843
+ const result = cr.optional("SSLPurchaseMoreSansResult") ?? cr.children()[0];
844
+ if (result === void 0) return {};
845
+ return {
846
+ ...optionalField("isSuccess", result.lenientBoolean("IsSuccess")),
847
+ ...optionalField("orderID", firstLenientNumber(result, "OrderID", "OrderId")),
848
+ ...optionalField(
849
+ "transactionID",
850
+ firstLenientNumber(result, "TransactionID", "TransactionId")
851
+ ),
852
+ ...optionalField("chargedAmount", result.lenientNumber("ChargedAmount")),
853
+ ...optionalField("certificateID", result.lenientNumber("CertificateID")),
854
+ ...optionalField("sslType", result.optionalString("SSLType")),
855
+ ...optionalField("sansCount", result.lenientNumber("SANSCount"))
856
+ };
857
+ }
858
+ });
859
+ var revokeCertificate = /* @__PURE__ */ defineCommand({
860
+ name: "namecheap.ssl.revokecertificate",
861
+ parse: (cr) => {
862
+ const result = cr.one("SSLRevokeCertificateResult");
863
+ return {
864
+ isSuccess: result.boolean("IsSuccess"),
865
+ certificateID: result.number("CertificateID")
866
+ };
867
+ }
868
+ });
869
+ var sslCommands = {
870
+ create: create3,
871
+ getList: getList3,
872
+ parseCSR,
873
+ getApproverEmailList,
874
+ activate,
875
+ resendApproverEmail,
876
+ reissue,
877
+ resendFulfillmentEmail,
878
+ editDCVMethod,
879
+ getInfo: getInfo3,
880
+ renew: renew2,
881
+ purchaseMoreSans,
882
+ revokeCertificate
883
+ };
884
+
885
+ // src/commands/transfer.ts
886
+ var create4 = /* @__PURE__ */ defineCommand({
887
+ name: "namecheap.domains.transfer.create",
888
+ keys: { wgEnable: "WGenable" },
889
+ parse: (cr) => {
890
+ const result = cr.one("DomainTransferCreateResult");
891
+ return {
892
+ domainName: result.string("DomainName"),
893
+ transferID: result.number("TransferID"),
894
+ statusID: result.number("StatusID"),
895
+ orderID: result.number("OrderID"),
896
+ transactionID: result.number("TransactionID"),
897
+ chargedAmount: result.number("ChargedAmount")
898
+ };
899
+ }
900
+ });
901
+ var getStatus = /* @__PURE__ */ defineCommand({
902
+ name: "namecheap.domains.transfer.getStatus",
903
+ parse: (cr) => {
904
+ const result = cr.one("DomainTransferGetStatusResult");
905
+ return {
906
+ transferID: result.number("TransferID"),
907
+ statusID: result.number("StatusID"),
908
+ status: result.string("Status")
909
+ };
910
+ }
911
+ });
912
+ var updateStatus = /* @__PURE__ */ defineCommand({
913
+ name: "namecheap.domains.transfer.updateStatus",
914
+ parse: (cr) => {
915
+ const result = cr.one("DomainTransferUpdateStatusResult");
916
+ return {
917
+ transferID: result.number("TransferID"),
918
+ resubmit: result.boolean("Resubmit")
919
+ };
920
+ }
921
+ });
922
+ function parseListItem3(transfer) {
923
+ return {
924
+ transferID: transfer.number("TransferID"),
925
+ domainName: transfer.string("DomainName"),
926
+ user: transfer.string("User"),
927
+ transferDate: transfer.string("TransferDate"),
928
+ orderID: transfer.number("OrderID"),
929
+ statusID: transfer.number("StatusID"),
930
+ status: transfer.string("Status")
931
+ };
932
+ }
933
+ var getList4 = /* @__PURE__ */ defineCommand({
934
+ name: "namecheap.domains.transfer.getList",
935
+ parse: (cr) => ({
936
+ transfers: (cr.optional("TransferGetListResult")?.all("Transfer") ?? []).map(parseListItem3),
937
+ paging: parsePaging(cr.one("Paging"))
938
+ })
939
+ });
940
+ var transferCommands = { create: create4, getStatus, updateStatus, getList: getList4 };
941
+
942
+ // src/commands/users.ts
943
+ var getBalances = /* @__PURE__ */ defineCommand({
944
+ name: "namecheap.users.getBalances",
945
+ parse: (cr) => {
946
+ const result = cr.one("UserGetBalancesResult");
947
+ return {
948
+ currency: result.string("Currency"),
949
+ availableBalance: result.string("AvailableBalance"),
950
+ accountBalance: result.string("AccountBalance"),
951
+ earnedAmount: result.string("EarnedAmount"),
952
+ withdrawableAmount: result.string("WithdrawableAmount"),
953
+ fundsRequiredForAutoRenew: result.string("FundsRequiredForAutoRenew")
954
+ };
955
+ }
956
+ });
957
+ var getPricing = /* @__PURE__ */ defineCommand({
958
+ name: "namecheap.users.getPricing",
959
+ parse: (cr) => ({
960
+ productTypes: cr.one("UserGetPricingResult").all("ProductType").map((type) => ({
961
+ name: type.string("Name"),
962
+ productCategories: type.all("ProductCategory").map((category) => ({
963
+ name: category.string("Name"),
964
+ products: category.all("Product").map((product) => ({
965
+ name: product.string("Name"),
966
+ prices: product.all("Price").map((price) => ({
967
+ duration: price.number("Duration"),
968
+ durationType: price.string("DurationType"),
969
+ price: price.string("Price"),
970
+ regularPrice: price.string("RegularPrice"),
971
+ yourPrice: price.string("YourPrice"),
972
+ currency: price.string("Currency"),
973
+ ...optionalField("pricingType", price.optionalString("PricingType")),
974
+ ...optionalField("regularPriceType", price.optionalString("RegularPriceType")),
975
+ ...optionalField("yourPriceType", price.optionalString("YourPriceType")),
976
+ ...optionalField("promotionPrice", price.optionalString("PromotionPrice"))
977
+ }))
978
+ }))
979
+ }))
980
+ }))
981
+ })
982
+ });
983
+ var changePassword = /* @__PURE__ */ defineCommand({
984
+ name: "namecheap.users.changePassword",
985
+ parse: (cr) => {
986
+ const result = cr.one("UserChangePasswordResult");
987
+ return { success: result.boolean("Success"), userID: result.number("UserID") };
988
+ }
989
+ });
990
+ var update2 = /* @__PURE__ */ defineCommand({
991
+ name: "namecheap.users.update",
992
+ parse: (cr) => ({ success: cr.one("UserUpdateResult").boolean("Success") })
993
+ });
994
+ var createAddFundsRequest = /* @__PURE__ */ defineCommand({
995
+ name: "namecheap.users.createaddfundsrequest",
996
+ parse: (cr) => {
997
+ const result = cr.one("CreateAddFundsRequestResult");
998
+ return {
999
+ tokenID: result.string("TokenID"),
1000
+ redirectURL: result.string("RedirectURL"),
1001
+ returnURL: result.string("ReturnURL")
1002
+ };
1003
+ }
1004
+ });
1005
+ var getAddFundsStatus = /* @__PURE__ */ defineCommand({
1006
+ name: "namecheap.users.getAddFundsStatus",
1007
+ keys: { tokenId: "TokenId" },
1008
+ parse: (cr) => {
1009
+ const result = cr.one("GetAddFundsStatusResult");
1010
+ return {
1011
+ transactionID: result.number("TransactionID"),
1012
+ amount: result.string("Amount"),
1013
+ status: result.string("Status")
1014
+ };
1015
+ }
1016
+ });
1017
+ var create5 = /* @__PURE__ */ defineCommand({
1018
+ name: "namecheap.users.create",
1019
+ parse: (cr) => cr.children()[0]?.attributes() ?? {}
1020
+ });
1021
+ var login = /* @__PURE__ */ defineCommand({
1022
+ name: "namecheap.users.login",
1023
+ parse: (cr) => {
1024
+ const result = cr.children()[0];
1025
+ return {
1026
+ ...optionalField("username", result?.optionalString("Username")),
1027
+ ...optionalField("loginSuccess", result?.lenientBoolean("LoginSuccess"))
1028
+ };
1029
+ }
1030
+ });
1031
+ var resetPassword = /* @__PURE__ */ defineCommand({
1032
+ name: "namecheap.users.resetPassword",
1033
+ keys: { urlPattern: "URLPattern" },
1034
+ parse: (cr) => ({
1035
+ ...optionalField("success", cr.children()[0]?.lenientBoolean("Success"))
1036
+ })
1037
+ });
1038
+ var usersCommands = {
1039
+ getBalances,
1040
+ getPricing,
1041
+ changePassword,
1042
+ update: update2,
1043
+ createAddFundsRequest,
1044
+ getAddFundsStatus,
1045
+ create: create5,
1046
+ login,
1047
+ resetPassword
1048
+ };
1049
+
1050
+ // src/commands/users-address.ts
1051
+ var create6 = /* @__PURE__ */ defineCommand({
1052
+ name: "namecheap.users.address.create",
1053
+ parse: (cr) => {
1054
+ const result = cr.one("AddressCreateResult");
1055
+ return {
1056
+ success: result.boolean("Success"),
1057
+ addressId: result.number("AddressId"),
1058
+ addressName: result.string("AddressName")
1059
+ };
1060
+ }
1061
+ });
1062
+ var deleteAddress = /* @__PURE__ */ defineCommand({
1063
+ name: "namecheap.users.address.delete",
1064
+ keys: { addressId: "AddressId" },
1065
+ parse: (cr) => {
1066
+ const result = cr.one("AddressDeleteResult");
1067
+ return {
1068
+ success: result.boolean("Success"),
1069
+ profileId: result.number("ProfileId"),
1070
+ ...optionalField("username", result.optionalString("Username"))
1071
+ };
1072
+ }
1073
+ });
1074
+ var getInfo4 = /* @__PURE__ */ defineCommand(
1075
+ {
1076
+ name: "namecheap.users.address.getInfo",
1077
+ keys: { addressId: "AddressId" },
1078
+ parse: (cr) => {
1079
+ const result = cr.one("GetAddressInfoResult");
1080
+ return {
1081
+ addressId: result.one("AddressId").numberText(),
1082
+ userName: result.one("UserName").text(),
1083
+ addressName: result.one("AddressName").text(),
1084
+ defaultYN: result.one("Default_YN").booleanText(),
1085
+ firstName: result.one("FirstName").text(),
1086
+ lastName: result.one("LastName").text(),
1087
+ ...optionalField("jobTitle", result.optionalText("JobTitle")),
1088
+ ...optionalField("organization", result.optionalText("Organization")),
1089
+ address1: result.one("Address1").text(),
1090
+ ...optionalField("address2", result.optionalText("Address2")),
1091
+ city: result.one("City").text(),
1092
+ stateProvince: result.one("StateProvince").text(),
1093
+ stateProvinceChoice: result.one("StateProvinceChoice").text(),
1094
+ zip: result.one("Zip").text(),
1095
+ country: result.one("Country").text(),
1096
+ phone: result.one("Phone").text(),
1097
+ ...optionalField("phoneExt", result.optionalText("PhoneExt")),
1098
+ ...optionalField("fax", result.optionalText("Fax")),
1099
+ emailAddress: result.one("EmailAddress").text()
1100
+ };
1101
+ }
1102
+ }
1103
+ );
1104
+ var getList5 = /* @__PURE__ */ defineCommand({
1105
+ name: "namecheap.users.address.getList",
1106
+ parse: (cr) => (cr.optional("AddressGetListResult")?.all("List") ?? []).map((item) => ({
1107
+ addressId: item.number("AddressId"),
1108
+ addressName: item.string("AddressName"),
1109
+ isDefault: item.boolean("IsDefault")
1110
+ }))
1111
+ });
1112
+ var setDefault2 = /* @__PURE__ */ defineCommand({
1113
+ name: "namecheap.users.address.setDefault",
1114
+ keys: { addressId: "AddressId" },
1115
+ parse: (cr) => {
1116
+ const result = cr.one("AddressSetDefaultResult");
1117
+ return { success: result.boolean("Success"), addressId: result.number("AddressId") };
1118
+ }
1119
+ });
1120
+ var update3 = /* @__PURE__ */ defineCommand({
1121
+ name: "namecheap.users.address.update",
1122
+ keys: { addressId: "AddressId" },
1123
+ parse: (cr) => {
1124
+ const result = cr.one("AddressUpdateResult");
1125
+ return {
1126
+ success: result.boolean("Success"),
1127
+ addressId: result.number("AddressId"),
1128
+ addressName: result.string("AddressName")
1129
+ };
1130
+ }
1131
+ });
1132
+ var usersAddressCommands = {
1133
+ create: create6,
1134
+ delete: deleteAddress,
1135
+ getInfo: getInfo4,
1136
+ getList: getList5,
1137
+ setDefault: setDefault2,
1138
+ update: update3
1139
+ };
1140
+
1141
+ // src/commands/whoisguard.ts
1142
+ var changeEmailAddress = /* @__PURE__ */ defineCommand({
1143
+ name: "namecheap.whoisguard.changeemailaddress",
1144
+ parse: (cr) => {
1145
+ const result = cr.one("WhoisguardChangeEmailAddressResult");
1146
+ return {
1147
+ id: result.number("ID"),
1148
+ isSuccess: result.boolean("IsSuccess"),
1149
+ wgEmail: result.string("WGEmail"),
1150
+ wgOldEmail: result.string("WGOldEmail")
1151
+ };
1152
+ }
1153
+ });
1154
+ var enable = /* @__PURE__ */ defineCommand({
1155
+ name: "namecheap.whoisguard.enable",
1156
+ parse: (cr) => {
1157
+ const result = cr.one("WhoisguardEnableResult");
1158
+ return {
1159
+ domainName: result.string("DomainName"),
1160
+ isSuccess: result.boolean("IsSuccess")
1161
+ };
1162
+ }
1163
+ });
1164
+ var disable = /* @__PURE__ */ defineCommand({
1165
+ name: "namecheap.whoisguard.disable",
1166
+ parse: (cr) => {
1167
+ const result = cr.one("WhoisguardDisableResult");
1168
+ return {
1169
+ domainName: result.string("DomainName"),
1170
+ isSuccess: result.boolean("IsSuccess")
1171
+ };
1172
+ }
1173
+ });
1174
+ function parseListItem4(item) {
1175
+ return {
1176
+ id: item.number("ID"),
1177
+ domainName: item.string("DomainName"),
1178
+ created: item.string("Created"),
1179
+ expires: item.string("Expires"),
1180
+ status: item.string("Status")
1181
+ };
1182
+ }
1183
+ var getList6 = /* @__PURE__ */ defineCommand({
1184
+ name: "namecheap.whoisguard.getlist",
1185
+ parse: (cr) => ({
1186
+ whoisguards: (cr.optional("WhoisguardGetListResult")?.all("Whoisguard") ?? []).map(
1187
+ parseListItem4
1188
+ ),
1189
+ paging: parsePaging(cr.one("Paging"))
1190
+ })
1191
+ });
1192
+ var renew3 = /* @__PURE__ */ defineCommand({
1193
+ name: "namecheap.whoisguard.renew",
1194
+ parse: (cr) => {
1195
+ const result = cr.children()[0];
1196
+ return {
1197
+ ...optionalField(
1198
+ "whoisguardID",
1199
+ result && firstLenientNumber(result, "WhoisguardID", "WhoisguardId")
1200
+ ),
1201
+ ...optionalField("years", result?.lenientNumber("Years")),
1202
+ ...optionalField("renew", result?.lenientBoolean("Renew")),
1203
+ ...optionalField("orderID", result && firstLenientNumber(result, "OrderID", "OrderId")),
1204
+ ...optionalField(
1205
+ "transactionID",
1206
+ result && firstLenientNumber(result, "TransactionID", "TransactionId")
1207
+ ),
1208
+ ...optionalField("chargedAmount", result?.lenientNumber("ChargedAmount"))
1209
+ };
1210
+ }
1211
+ });
1212
+ var whoisGuardCommands = { changeEmailAddress, enable, disable, getList: getList6, renew: renew3 };
1213
+
1214
+ // src/core/element.ts
1215
+ var PLAIN_DECIMAL = /^[+-]?\d+(\.\d+)?$/;
1216
+ var El = class _El {
1217
+ constructor(node) {
1218
+ this.node = node;
1219
+ this.name = node.name;
1220
+ }
1221
+ node;
1222
+ name;
1223
+ text() {
1224
+ return this.node.text;
1225
+ }
1226
+ all(name) {
1227
+ return this.node.children.filter((child) => child.name === name).map((child) => new _El(child));
1228
+ }
1229
+ /** All direct child elements in document order, whatever their names. */
1230
+ children() {
1231
+ return this.node.children.map((child) => new _El(child));
1232
+ }
1233
+ /** Text of the first child element called `name`, or `undefined` when there is none. */
1234
+ optionalText(name) {
1235
+ return this.optional(name)?.text();
1236
+ }
1237
+ one(name) {
1238
+ const found = this.optional(name);
1239
+ if (found === void 0) {
1240
+ throw new NamecheapParseError(`${this.name}: missing element "${name}"`);
1241
+ }
1242
+ return found;
1243
+ }
1244
+ optional(name) {
1245
+ const child = this.node.children.find((candidate) => candidate.name === name);
1246
+ return child === void 0 ? void 0 : new _El(child);
1247
+ }
1248
+ string(attr) {
1249
+ const value = this.optionalString(attr);
1250
+ if (value === void 0) {
1251
+ throw new NamecheapParseError(`${this.name}: missing attribute "${attr}"`);
1252
+ }
1253
+ return value;
1254
+ }
1255
+ optionalString(attr) {
1256
+ return Object.hasOwn(this.node.attrs, attr) ? this.node.attrs[attr] : void 0;
1257
+ }
1258
+ number(attr) {
1259
+ return this.parseNumber(attr, this.string(attr));
1260
+ }
1261
+ optionalNumber(attr) {
1262
+ const value = this.optionalString(attr);
1263
+ return value === void 0 ? void 0 : this.parseNumber(attr, value);
1264
+ }
1265
+ boolean(attr) {
1266
+ return this.parseBoolean(attr, this.string(attr));
1267
+ }
1268
+ optionalBoolean(attr) {
1269
+ const value = this.optionalString(attr);
1270
+ return value === void 0 ? void 0 : this.parseBoolean(attr, value);
1271
+ }
1272
+ /**
1273
+ * Never throws: the plain decimal value of an attribute, or `undefined` when it is
1274
+ * absent or not acceptable. For undocumented responses of billed or account-changing
1275
+ * commands, where a parse failure after the action succeeded would invite a retry.
1276
+ */
1277
+ lenientNumber(attr) {
1278
+ const value = this.optionalString(attr);
1279
+ if (value === void 0 || !PLAIN_DECIMAL.test(value)) return void 0;
1280
+ const parsed = Number(value);
1281
+ return Number.isFinite(parsed) ? parsed : void 0;
1282
+ }
1283
+ /** Never throws: `true`/`false` (any case), or `undefined` when absent or anything else. */
1284
+ lenientBoolean(attr) {
1285
+ const lower = this.optionalString(attr)?.toLowerCase();
1286
+ if (lower === "true") return true;
1287
+ if (lower === "false") return false;
1288
+ return void 0;
1289
+ }
1290
+ /** Element text as a plain decimal number (for numeric child elements). */
1291
+ numberText() {
1292
+ return this.parseNumber(`text`, this.text(), `${this.name}: text is not a number`);
1293
+ }
1294
+ /** Element text as `true`/`false` (for boolean child elements). */
1295
+ booleanText() {
1296
+ return this.parseBoolean(`text`, this.text(), `${this.name}: text is not a boolean`);
1297
+ }
1298
+ attributes() {
1299
+ return { ...this.node.attrs };
1300
+ }
1301
+ parseNumber(attr, value, message) {
1302
+ const parsed = PLAIN_DECIMAL.test(value) ? Number(value) : Number.NaN;
1303
+ if (!Number.isFinite(parsed)) {
1304
+ throw new NamecheapParseError(message ?? `${this.name}: attribute "${attr}" is not a number`);
1305
+ }
1306
+ return parsed;
1307
+ }
1308
+ parseBoolean(attr, value, message) {
1309
+ const lower = value.toLowerCase();
1310
+ if (lower === "true") return true;
1311
+ if (lower === "false") return false;
1312
+ throw new NamecheapParseError(message ?? `${this.name}: attribute "${attr}" is not a boolean`);
1313
+ }
1314
+ };
1315
+
1316
+ // src/core/xml.ts
1317
+ var NAMED_ENTITIES = {
1318
+ amp: "&",
1319
+ lt: "<",
1320
+ gt: ">",
1321
+ quot: '"',
1322
+ apos: "'"
1323
+ };
1324
+ var NAME_START = /[A-Za-z_:]/;
1325
+ var NAME_CHAR = /[A-Za-z0-9_:.-]/;
1326
+ function fail(message, position) {
1327
+ throw new NamecheapParseError(`Invalid XML at position ${position}: ${message}`);
1328
+ }
1329
+ function isSpace(ch) {
1330
+ return ch === " " || ch === " " || ch === "\n" || ch === "\r";
1331
+ }
1332
+ function decodeEntities(raw, position) {
1333
+ if (!raw.includes("&")) return raw;
1334
+ let out = "";
1335
+ let i = 0;
1336
+ while (i < raw.length) {
1337
+ const amp = raw.indexOf("&", i);
1338
+ if (amp === -1) {
1339
+ out += raw.slice(i);
1340
+ break;
1341
+ }
1342
+ out += raw.slice(i, amp);
1343
+ const semi = raw.indexOf(";", amp);
1344
+ if (semi === -1) fail("unterminated entity", position + amp);
1345
+ const body = raw.slice(amp + 1, semi);
1346
+ let decoded;
1347
+ if (body.startsWith("#x") || body.startsWith("#X")) {
1348
+ decoded = codePoint(body.slice(2), 16);
1349
+ } else if (body.startsWith("#")) {
1350
+ decoded = codePoint(body.slice(1), 10);
1351
+ } else {
1352
+ decoded = Object.hasOwn(NAMED_ENTITIES, body) ? NAMED_ENTITIES[body] : void 0;
1353
+ }
1354
+ if (decoded === void 0) {
1355
+ const shown = body.length > 32 ? `${body.slice(0, 32)}\u2026` : body;
1356
+ fail(`unknown entity &${shown};`, position + amp);
1357
+ }
1358
+ out += decoded;
1359
+ i = semi + 1;
1360
+ }
1361
+ return out;
1362
+ }
1363
+ function codePoint(digits, radix) {
1364
+ const pattern = radix === 10 ? /^[0-9]{1,7}$/ : /^[0-9A-Fa-f]{1,6}$/;
1365
+ if (!pattern.test(digits)) return void 0;
1366
+ const value = Number.parseInt(digits, radix);
1367
+ if (value > 1114111 || value >= 55296 && value <= 57343) return void 0;
1368
+ return String.fromCodePoint(value);
1369
+ }
1370
+ function parseXml(input) {
1371
+ const length = input.length;
1372
+ let pos = 0;
1373
+ let root;
1374
+ const stack = [];
1375
+ const skipSpace = () => {
1376
+ while (pos < length && isSpace(input[pos])) pos++;
1377
+ };
1378
+ const readName = () => {
1379
+ const start = pos;
1380
+ if (pos >= length || !NAME_START.test(input[pos])) fail("expected a name", pos);
1381
+ pos++;
1382
+ while (pos < length && NAME_CHAR.test(input[pos])) pos++;
1383
+ return input.slice(start, pos);
1384
+ };
1385
+ const skipUntil = (terminator, what) => {
1386
+ const end = input.indexOf(terminator, pos);
1387
+ if (end === -1) fail(`unterminated ${what}`, pos);
1388
+ pos = end + terminator.length;
1389
+ };
1390
+ const readAttributes = (attrs) => {
1391
+ for (; ; ) {
1392
+ const before = pos;
1393
+ skipSpace();
1394
+ const ch = input[pos];
1395
+ if (ch === void 0) fail("unterminated start tag", pos);
1396
+ if (ch === ">") {
1397
+ pos++;
1398
+ return false;
1399
+ }
1400
+ if (ch === "/") {
1401
+ if (input[pos + 1] !== ">") fail("expected '>' after '/'", pos);
1402
+ pos += 2;
1403
+ return true;
1404
+ }
1405
+ if (pos === before) fail("expected whitespace before attribute", pos);
1406
+ const name = readName();
1407
+ skipSpace();
1408
+ if (input[pos] !== "=") fail(`attribute ${name} has no value`, pos);
1409
+ pos++;
1410
+ skipSpace();
1411
+ const quote = input[pos];
1412
+ if (quote !== '"' && quote !== "'") fail(`attribute ${name} value is not quoted`, pos);
1413
+ pos++;
1414
+ const end = input.indexOf(quote, pos);
1415
+ if (end === -1) fail("unterminated attribute value", pos);
1416
+ const raw = input.slice(pos, end);
1417
+ if (raw.includes("<")) fail("'<' in attribute value", pos);
1418
+ if (Object.hasOwn(attrs, name)) fail(`duplicate attribute ${name}`, pos);
1419
+ attrs[name] = decodeEntities(raw, pos);
1420
+ pos = end + 1;
1421
+ }
1422
+ };
1423
+ const closeElement = (builder) => {
1424
+ const node = {
1425
+ name: builder.name,
1426
+ attrs: builder.attrs,
1427
+ text: builder.text.trim(),
1428
+ children: builder.children
1429
+ };
1430
+ const parent = stack[stack.length - 1];
1431
+ if (parent) parent.children.push(node);
1432
+ else root = node;
1433
+ };
1434
+ while (pos < length) {
1435
+ const current = stack[stack.length - 1];
1436
+ if (input[pos] !== "<") {
1437
+ const next = input.indexOf("<", pos);
1438
+ const end = next === -1 ? length : next;
1439
+ const raw = input.slice(pos, end);
1440
+ if (current) {
1441
+ current.text += decodeEntities(raw, pos);
1442
+ } else if (raw.trim() !== "") {
1443
+ fail("text outside the root element", pos);
1444
+ }
1445
+ pos = end;
1446
+ continue;
1447
+ }
1448
+ if (input.startsWith("<!--", pos)) {
1449
+ pos += 4;
1450
+ skipUntil("-->", "comment");
1451
+ } else if (input.startsWith("<![CDATA[", pos)) {
1452
+ if (!current) fail("CDATA outside the root element", pos);
1453
+ pos += 9;
1454
+ const end = input.indexOf("]]>", pos);
1455
+ if (end === -1) fail("unterminated CDATA section", pos);
1456
+ current.text += input.slice(pos, end);
1457
+ pos = end + 3;
1458
+ } else if (input.startsWith("<?", pos)) {
1459
+ pos += 2;
1460
+ skipUntil("?>", "processing instruction");
1461
+ } else if (input.startsWith("<!", pos)) {
1462
+ fail("DTD and entity declarations are not supported", pos);
1463
+ } else if (input.startsWith("</", pos)) {
1464
+ pos += 2;
1465
+ const name = readName();
1466
+ skipSpace();
1467
+ if (input[pos] !== ">") fail("expected '>' in end tag", pos);
1468
+ pos++;
1469
+ if (!current) fail(`unexpected end tag </${name}>`, pos);
1470
+ if (current.name !== name) {
1471
+ fail(`end tag </${name}> does not match <${current.name}>`, pos);
1472
+ }
1473
+ stack.pop();
1474
+ closeElement(current);
1475
+ } else {
1476
+ if (!current && root) fail("more than one root element", pos);
1477
+ pos++;
1478
+ const builder = { name: readName(), attrs: {}, text: "", children: [] };
1479
+ const selfClosing = readAttributes(builder.attrs);
1480
+ if (selfClosing) closeElement(builder);
1481
+ else stack.push(builder);
1482
+ }
1483
+ }
1484
+ if (stack.length > 0) fail(`unclosed element <${stack[stack.length - 1]?.name}>`, pos);
1485
+ if (!root) fail("no root element", pos);
1486
+ return root;
1487
+ }
1488
+
1489
+ // src/core/envelope.ts
1490
+ var INTEGER = /^-?\d+$/;
1491
+ function toErrorItem(error) {
1492
+ const number = error.optionalString("Number")?.trim();
1493
+ return {
1494
+ code: number !== void 0 && INTEGER.test(number) ? Number(number) : -1,
1495
+ message: error.text().trim()
1496
+ };
1497
+ }
1498
+ function readEnvelope(xml) {
1499
+ const root = new El(parseXml(xml));
1500
+ if (root.name !== "ApiResponse") {
1501
+ throw new NamecheapParseError(`Unexpected response root element "${root.name}"`);
1502
+ }
1503
+ const errors = root.optional("Errors")?.all("Error") ?? [];
1504
+ if (root.optionalString("Status") === "ERROR" || errors.length > 0) {
1505
+ throw new NamecheapError(errors.map(toErrorItem));
1506
+ }
1507
+ const command = root.optional("CommandResponse");
1508
+ if (command === void 0) {
1509
+ throw new NamecheapParseError("Response has no CommandResponse element");
1510
+ }
1511
+ return command;
1512
+ }
1513
+
1514
+ // src/core/transport.ts
1515
+ var PRODUCTION_URL = "https://api.namecheap.com/xml.response";
1516
+ var SANDBOX_URL = "https://api.sandbox.namecheap.com/xml.response";
1517
+ function createTransport(config) {
1518
+ if (config.sandbox !== void 0 && typeof config.sandbox !== "boolean") {
1519
+ throw new TypeError("NamecheapConfig.sandbox must be a boolean");
1520
+ }
1521
+ const url = config.sandbox === true ? SANDBOX_URL : PRODUCTION_URL;
1522
+ const fetchImpl = config.fetch ?? globalThis.fetch;
1523
+ return async ({ command, params }) => {
1524
+ const body = new URLSearchParams();
1525
+ body.append("ApiUser", config.apiUser);
1526
+ body.append("ApiKey", config.apiKey);
1527
+ body.append("UserName", config.userName ?? config.apiUser);
1528
+ body.append("ClientIp", config.clientIp);
1529
+ body.append("Command", command);
1530
+ for (const [name, value] of params) body.append(name, value);
1531
+ const init = {
1532
+ method: "POST",
1533
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
1534
+ body: body.toString(),
1535
+ redirect: "error"
1536
+ };
1537
+ if (config.timeoutMs !== void 0) init.signal = AbortSignal.timeout(config.timeoutMs);
1538
+ let response;
1539
+ try {
1540
+ response = await fetchImpl(url, init);
1541
+ } catch (cause) {
1542
+ throw new NamecheapHttpError("Request to Namecheap failed", { cause });
1543
+ }
1544
+ if (!response.ok) {
1545
+ throw new NamecheapHttpError(`Namecheap responded with HTTP ${response.status}`, {
1546
+ status: response.status,
1547
+ statusText: response.statusText
1548
+ });
1549
+ }
1550
+ let text;
1551
+ try {
1552
+ text = await response.text();
1553
+ } catch (cause) {
1554
+ throw new NamecheapHttpError("Request to Namecheap failed", { cause });
1555
+ }
1556
+ return readEnvelope(text);
1557
+ };
1558
+ }
1559
+
1560
+ // src/client.ts
1561
+ var Namecheap = class {
1562
+ domains;
1563
+ dns;
1564
+ ns;
1565
+ transfer;
1566
+ ssl;
1567
+ users;
1568
+ usersAddress;
1569
+ whoisGuard;
1570
+ constructor(config) {
1571
+ const send = createTransport(config);
1572
+ this.domains = group(domainsCommands, send);
1573
+ this.dns = group(dnsCommands, send);
1574
+ this.ns = group(nsCommands, send);
1575
+ this.transfer = group(transferCommands, send);
1576
+ this.ssl = group(sslCommands, send);
1577
+ this.users = group(usersCommands, send);
1578
+ this.usersAddress = group(usersAddressCommands, send);
1579
+ this.whoisGuard = group(whoisGuardCommands, send);
1580
+ }
1581
+ };
1582
+
1583
+ // src/index.ts
1584
+ var index_default = Namecheap;
1585
+ // Annotate the CommonJS export names for ESM import in node:
1586
+ 0 && (module.exports = {
1587
+ Namecheap,
1588
+ NamecheapError,
1589
+ NamecheapHttpError,
1590
+ NamecheapParseError,
1591
+ createTransport,
1592
+ dnsCommands,
1593
+ dnsGetEmailForwarding,
1594
+ dnsGetHosts,
1595
+ dnsGetList,
1596
+ dnsSetCustom,
1597
+ dnsSetDefault,
1598
+ dnsSetEmailForwarding,
1599
+ dnsSetHosts,
1600
+ domainsCheck,
1601
+ domainsCommands,
1602
+ domainsCreate,
1603
+ domainsGetContacts,
1604
+ domainsGetInfo,
1605
+ domainsGetList,
1606
+ domainsGetRegistrarLock,
1607
+ domainsGetTldList,
1608
+ domainsReactivate,
1609
+ domainsRenew,
1610
+ domainsSetContacts,
1611
+ domainsSetRegistrarLock,
1612
+ nsCommands,
1613
+ nsCreate,
1614
+ nsDelete,
1615
+ nsGetInfo,
1616
+ nsUpdate,
1617
+ run,
1618
+ sslActivate,
1619
+ sslCommands,
1620
+ sslCreate,
1621
+ sslEditDCVMethod,
1622
+ sslGetApproverEmailList,
1623
+ sslGetInfo,
1624
+ sslGetList,
1625
+ sslParseCSR,
1626
+ sslPurchaseMoreSans,
1627
+ sslReissue,
1628
+ sslRenew,
1629
+ sslResendApproverEmail,
1630
+ sslResendFulfillmentEmail,
1631
+ sslRevokeCertificate,
1632
+ transferCommands,
1633
+ transferCreate,
1634
+ transferGetList,
1635
+ transferGetStatus,
1636
+ transferUpdateStatus,
1637
+ usersAddressCommands,
1638
+ usersAddressCreate,
1639
+ usersAddressDelete,
1640
+ usersAddressGetInfo,
1641
+ usersAddressGetList,
1642
+ usersAddressSetDefault,
1643
+ usersAddressUpdate,
1644
+ usersChangePassword,
1645
+ usersCommands,
1646
+ usersCreate,
1647
+ usersCreateAddFundsRequest,
1648
+ usersGetAddFundsStatus,
1649
+ usersGetBalances,
1650
+ usersGetPricing,
1651
+ usersLogin,
1652
+ usersResetPassword,
1653
+ usersUpdate,
1654
+ whoisGuardChangeEmailAddress,
1655
+ whoisGuardCommands,
1656
+ whoisGuardDisable,
1657
+ whoisGuardEnable,
1658
+ whoisGuardGetList,
1659
+ whoisGuardRenew
1660
+ });
2
1661
  //# sourceMappingURL=index.cjs.map