namecheap-ts 1.0.0 → 1.0.2
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/api/api-client.d.ts +8 -0
- package/dist/api/api-client.js +51 -0
- package/dist/api/errors.d.ts +7 -0
- package/dist/api/errors.js +18 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +8 -0
- package/dist/commands.d.ts +62 -0
- package/dist/commands.js +73 -0
- package/dist/exceptions/InvalidDomainNameException.d.ts +3 -0
- package/dist/exceptions/InvalidDomainNameException.js +10 -0
- package/dist/exceptions/InvalidTLDException.d.ts +3 -0
- package/dist/exceptions/InvalidTLDException.js +10 -0
- package/dist/exceptions/index.d.ts +1 -0
- package/dist/exceptions/index.js +17 -0
- package/dist/index.d.mts +9 -5
- package/dist/index.d.ts +2 -17
- package/dist/index.js +21 -145
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/index.mjs.map +1 -1
- package/dist/namecheap.d.ts +25 -0
- package/dist/namecheap.js +64 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.js +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const xml2js_1 = require("xml2js");
|
|
17
|
+
const errors_1 = require("./errors");
|
|
18
|
+
class APIClient {
|
|
19
|
+
constructor(baseURL) {
|
|
20
|
+
this._client = axios_1.default.create({ baseURL });
|
|
21
|
+
this._client.interceptors.response.use(this.onResponse);
|
|
22
|
+
}
|
|
23
|
+
get(url) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
return yield this._client.get(url);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
onResponse(response) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
try {
|
|
31
|
+
const result = yield (0, xml2js_1.parseStringPromise)(response.data);
|
|
32
|
+
if (result.ApiResponse.$.Status === "ERROR") {
|
|
33
|
+
const responseErrors = result.ApiResponse.Errors;
|
|
34
|
+
const code = responseErrors[0].Error[0].$.Number;
|
|
35
|
+
const message = responseErrors[0].Error[0]._;
|
|
36
|
+
throw new errors_1.ResponseError(message, code);
|
|
37
|
+
}
|
|
38
|
+
response.data = result.ApiResponse.CommandResponse;
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
response.status = 400;
|
|
42
|
+
if (err instanceof errors_1.ResponseError) {
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
throw new errors_1.XMLParsingError();
|
|
46
|
+
}
|
|
47
|
+
return response;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.default = APIClient;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseError = exports.XMLParsingError = void 0;
|
|
4
|
+
class XMLParsingError extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super("Invalid XML response");
|
|
7
|
+
this.name = "XMLParsingError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.XMLParsingError = XMLParsingError;
|
|
11
|
+
class ResponseError extends Error {
|
|
12
|
+
constructor(message, code) {
|
|
13
|
+
super((code ? `${code}: ` : "") + message);
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.name = "ResponseError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ResponseError = ResponseError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./api-client";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var api_client_1 = require("./api-client");
|
|
8
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(api_client_1).default; } });
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export declare enum Commands {
|
|
2
|
+
DOMAINS_GETLIST = "namecheap.domains.getList",
|
|
3
|
+
DOMAINS_GETCONTACTS = "namecheap.domains.getContacts",
|
|
4
|
+
DOMAINS_CREATE = "namecheap.domains.create",
|
|
5
|
+
DOMAINS_GETTLDLIST = "namecheap.domains.getTldList",
|
|
6
|
+
DOMAINS_SETCONTACTS = "namecheap.domains.setContacts",
|
|
7
|
+
DOMAINS_CHECK = "namecheap.domains.check",
|
|
8
|
+
DOMAINS_REACTIVATE = "namecheap.domains.reactivate",
|
|
9
|
+
DOMAINS_RENEW = "namecheap.domains.renew",
|
|
10
|
+
DOMAINS_GETREGISTRARLOCK = "namecheap.domains.getRegistrarLock",
|
|
11
|
+
DOMAINS_SETREGISTRARLOCK = "namecheap.domains.setRegistrarLock",
|
|
12
|
+
DOMAINS_GETINFO = "namecheap.domains.getInfo",
|
|
13
|
+
DOMAINS_DNS_SETDEFAULT = "namecheap.domains.dns.setDefault",
|
|
14
|
+
DOMAINS_DNS_SETCUSTOM = "namecheap.domains.dns.setCustom",
|
|
15
|
+
DOMAINS_DNS_GETLIST = "namecheap.domains.dns.getList",
|
|
16
|
+
DOMAINS_DNS_GETHOSTS = "namecheap.domains.dns.getHosts",
|
|
17
|
+
DOMAINS_DNS_GETEMAILFORWARDING = "namecheap.domains.dns.getEmailForwarding",
|
|
18
|
+
DOMAINS_DNS_SETEMAILFORWARDING = "namecheap.domains.dns.setEmailForwarding",
|
|
19
|
+
DOMAINS_DNS_SETHOSTS = "namecheap.domains.dns.setHosts",
|
|
20
|
+
DOMAINS_NS_CREATE = "namecheap.domains.ns.create",
|
|
21
|
+
DOMAINS_NS_DELETE = "namecheap.domains.ns.delete",
|
|
22
|
+
DOMAINS_NS_GETINFO = "namecheap.domains.ns.getInfo",
|
|
23
|
+
DOMAINS_NS_UPDATE = "namecheap.domains.ns.update",
|
|
24
|
+
DOMAINS_TRANSFER_CREATE = "namecheap.domains.transfer.create",
|
|
25
|
+
DOMAINS_TRANSFER_GETSTATUS = "namecheap.domains.transfer.getStatus",
|
|
26
|
+
DOMAINS_TRANSFER_UPDATESTATUS = "namecheap.domains.transfer.updateStatus",
|
|
27
|
+
DOMAINS_TRANSFER_GETLIST = "namecheap.domains.transfer.getList",
|
|
28
|
+
SSL_CREATE = "namecheap.ssl.create",
|
|
29
|
+
SSL_GETLIST = "namecheap.ssl.getList",
|
|
30
|
+
SSL_PARSECSR = "namecheap.ssl.parseCSR",
|
|
31
|
+
SSL_GETAPPROVEREMAILLIST = "namecheap.ssl.getApproverEmailList",
|
|
32
|
+
SSL_ACTIVATE = "namecheap.ssl.activate",
|
|
33
|
+
SSL_RESENDAPPROVEREMAIL = "namecheap.ssl.resendApproverEmail",
|
|
34
|
+
SSL_GETINFO = "namecheap.ssl.getInfo",
|
|
35
|
+
SSL_RENEW = "namecheap.ssl.renew",
|
|
36
|
+
SSL_REISSUE = "namecheap.ssl.reissue",
|
|
37
|
+
SSL_RESENDFULFILLMENTEMAIL = "namecheap.ssl.resendfulfillmentemail",
|
|
38
|
+
SSL_PURCHASEMORESANS = "namecheap.ssl.purchasemoresans",
|
|
39
|
+
SSL_REVOKECERTIFICATE = "namecheap.ssl.revokecertificate",
|
|
40
|
+
SSL_EDITDCVMETHOD = "namecheap.ssl.editDCVMethod",
|
|
41
|
+
USERS_GETPRICING = "namecheap.users.getPricing",
|
|
42
|
+
USERS_GETBALANCES = "namecheap.users.getBalances",
|
|
43
|
+
USERS_CHANGEPASSWORD = "namecheap.users.changePassword",
|
|
44
|
+
USERS_UPDATE = "namecheap.users.update",
|
|
45
|
+
USERS_CREATEADDFUNDSREQUEST = "namecheap.users.createaddfundsrequest",
|
|
46
|
+
USERS_GETADDFUNDSSTATUS = "namecheap.users.getAddFundsStatus",
|
|
47
|
+
USERS_CREATE = "namecheap.users.create",
|
|
48
|
+
USERS_LOGIN = "namecheap.users.login",
|
|
49
|
+
USERS_RESETPASSWORD = "namecheap.users.resetPassword",
|
|
50
|
+
USERS_ADDRESS_CREATE = "namecheap.users.address.create",
|
|
51
|
+
USERS_ADDRESS_DELETE = "namecheap.users.address.delete",
|
|
52
|
+
USERS_ADDRESS_GETINFO = "namecheap.users.address.getInfo",
|
|
53
|
+
USERS_ADDRESS_GETLIST = "namecheap.users.address.getList",
|
|
54
|
+
USERS_ADDRESS_SETDEFAULT = "namecheap.users.address.setDefault",
|
|
55
|
+
USERS_ADDRESS_UPDATE = "namecheap.users.address.update",
|
|
56
|
+
WHOISGUARD_CHANGEEMAILADDRESS = "Namecheap.Whoisguard.changeemailaddress",
|
|
57
|
+
WHOISGUARD_ENABLE = "Namecheap.Whoisguard.enable",
|
|
58
|
+
WHOISGUARD_DISABLE = "Namecheap.Whoisguard.disable",
|
|
59
|
+
WHOISGUARD_GETLIST = "Namecheap.Whoisguard.getList",
|
|
60
|
+
WHOISGUARD_RENEW = "Namecheap.Whoisguard.renew"
|
|
61
|
+
}
|
|
62
|
+
export type Command = `${Commands}`;
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Commands = void 0;
|
|
4
|
+
var Commands;
|
|
5
|
+
(function (Commands) {
|
|
6
|
+
// domains
|
|
7
|
+
Commands["DOMAINS_GETLIST"] = "namecheap.domains.getList";
|
|
8
|
+
Commands["DOMAINS_GETCONTACTS"] = "namecheap.domains.getContacts";
|
|
9
|
+
Commands["DOMAINS_CREATE"] = "namecheap.domains.create";
|
|
10
|
+
Commands["DOMAINS_GETTLDLIST"] = "namecheap.domains.getTldList";
|
|
11
|
+
Commands["DOMAINS_SETCONTACTS"] = "namecheap.domains.setContacts";
|
|
12
|
+
Commands["DOMAINS_CHECK"] = "namecheap.domains.check";
|
|
13
|
+
Commands["DOMAINS_REACTIVATE"] = "namecheap.domains.reactivate";
|
|
14
|
+
Commands["DOMAINS_RENEW"] = "namecheap.domains.renew";
|
|
15
|
+
Commands["DOMAINS_GETREGISTRARLOCK"] = "namecheap.domains.getRegistrarLock";
|
|
16
|
+
Commands["DOMAINS_SETREGISTRARLOCK"] = "namecheap.domains.setRegistrarLock";
|
|
17
|
+
Commands["DOMAINS_GETINFO"] = "namecheap.domains.getInfo";
|
|
18
|
+
// domains.dns
|
|
19
|
+
Commands["DOMAINS_DNS_SETDEFAULT"] = "namecheap.domains.dns.setDefault";
|
|
20
|
+
Commands["DOMAINS_DNS_SETCUSTOM"] = "namecheap.domains.dns.setCustom";
|
|
21
|
+
Commands["DOMAINS_DNS_GETLIST"] = "namecheap.domains.dns.getList";
|
|
22
|
+
Commands["DOMAINS_DNS_GETHOSTS"] = "namecheap.domains.dns.getHosts";
|
|
23
|
+
Commands["DOMAINS_DNS_GETEMAILFORWARDING"] = "namecheap.domains.dns.getEmailForwarding";
|
|
24
|
+
Commands["DOMAINS_DNS_SETEMAILFORWARDING"] = "namecheap.domains.dns.setEmailForwarding";
|
|
25
|
+
Commands["DOMAINS_DNS_SETHOSTS"] = "namecheap.domains.dns.setHosts";
|
|
26
|
+
// domains.ns
|
|
27
|
+
Commands["DOMAINS_NS_CREATE"] = "namecheap.domains.ns.create";
|
|
28
|
+
Commands["DOMAINS_NS_DELETE"] = "namecheap.domains.ns.delete";
|
|
29
|
+
Commands["DOMAINS_NS_GETINFO"] = "namecheap.domains.ns.getInfo";
|
|
30
|
+
Commands["DOMAINS_NS_UPDATE"] = "namecheap.domains.ns.update";
|
|
31
|
+
// domains.transfer
|
|
32
|
+
Commands["DOMAINS_TRANSFER_CREATE"] = "namecheap.domains.transfer.create";
|
|
33
|
+
Commands["DOMAINS_TRANSFER_GETSTATUS"] = "namecheap.domains.transfer.getStatus";
|
|
34
|
+
Commands["DOMAINS_TRANSFER_UPDATESTATUS"] = "namecheap.domains.transfer.updateStatus";
|
|
35
|
+
Commands["DOMAINS_TRANSFER_GETLIST"] = "namecheap.domains.transfer.getList";
|
|
36
|
+
// ssl
|
|
37
|
+
Commands["SSL_CREATE"] = "namecheap.ssl.create";
|
|
38
|
+
Commands["SSL_GETLIST"] = "namecheap.ssl.getList";
|
|
39
|
+
Commands["SSL_PARSECSR"] = "namecheap.ssl.parseCSR";
|
|
40
|
+
Commands["SSL_GETAPPROVEREMAILLIST"] = "namecheap.ssl.getApproverEmailList";
|
|
41
|
+
Commands["SSL_ACTIVATE"] = "namecheap.ssl.activate";
|
|
42
|
+
Commands["SSL_RESENDAPPROVEREMAIL"] = "namecheap.ssl.resendApproverEmail";
|
|
43
|
+
Commands["SSL_GETINFO"] = "namecheap.ssl.getInfo";
|
|
44
|
+
Commands["SSL_RENEW"] = "namecheap.ssl.renew";
|
|
45
|
+
Commands["SSL_REISSUE"] = "namecheap.ssl.reissue";
|
|
46
|
+
Commands["SSL_RESENDFULFILLMENTEMAIL"] = "namecheap.ssl.resendfulfillmentemail";
|
|
47
|
+
Commands["SSL_PURCHASEMORESANS"] = "namecheap.ssl.purchasemoresans";
|
|
48
|
+
Commands["SSL_REVOKECERTIFICATE"] = "namecheap.ssl.revokecertificate";
|
|
49
|
+
Commands["SSL_EDITDCVMETHOD"] = "namecheap.ssl.editDCVMethod";
|
|
50
|
+
// users
|
|
51
|
+
Commands["USERS_GETPRICING"] = "namecheap.users.getPricing";
|
|
52
|
+
Commands["USERS_GETBALANCES"] = "namecheap.users.getBalances";
|
|
53
|
+
Commands["USERS_CHANGEPASSWORD"] = "namecheap.users.changePassword";
|
|
54
|
+
Commands["USERS_UPDATE"] = "namecheap.users.update";
|
|
55
|
+
Commands["USERS_CREATEADDFUNDSREQUEST"] = "namecheap.users.createaddfundsrequest";
|
|
56
|
+
Commands["USERS_GETADDFUNDSSTATUS"] = "namecheap.users.getAddFundsStatus";
|
|
57
|
+
Commands["USERS_CREATE"] = "namecheap.users.create";
|
|
58
|
+
Commands["USERS_LOGIN"] = "namecheap.users.login";
|
|
59
|
+
Commands["USERS_RESETPASSWORD"] = "namecheap.users.resetPassword";
|
|
60
|
+
// users.address
|
|
61
|
+
Commands["USERS_ADDRESS_CREATE"] = "namecheap.users.address.create";
|
|
62
|
+
Commands["USERS_ADDRESS_DELETE"] = "namecheap.users.address.delete";
|
|
63
|
+
Commands["USERS_ADDRESS_GETINFO"] = "namecheap.users.address.getInfo";
|
|
64
|
+
Commands["USERS_ADDRESS_GETLIST"] = "namecheap.users.address.getList";
|
|
65
|
+
Commands["USERS_ADDRESS_SETDEFAULT"] = "namecheap.users.address.setDefault";
|
|
66
|
+
Commands["USERS_ADDRESS_UPDATE"] = "namecheap.users.address.update";
|
|
67
|
+
// domainprivacy
|
|
68
|
+
Commands["WHOISGUARD_CHANGEEMAILADDRESS"] = "Namecheap.Whoisguard.changeemailaddress";
|
|
69
|
+
Commands["WHOISGUARD_ENABLE"] = "Namecheap.Whoisguard.enable";
|
|
70
|
+
Commands["WHOISGUARD_DISABLE"] = "Namecheap.Whoisguard.disable";
|
|
71
|
+
Commands["WHOISGUARD_GETLIST"] = "Namecheap.Whoisguard.getList";
|
|
72
|
+
Commands["WHOISGUARD_RENEW"] = "Namecheap.Whoisguard.renew";
|
|
73
|
+
})(Commands || (exports.Commands = Commands = {}));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvalidDomainNameException = void 0;
|
|
4
|
+
class InvalidDomainNameException extends Error {
|
|
5
|
+
constructor(domainName) {
|
|
6
|
+
super(`The provided domain name [${domainName}] is not valid`);
|
|
7
|
+
this.name = "InvalidDomainNameException";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.InvalidDomainNameException = InvalidDomainNameException;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvalidTLDException = void 0;
|
|
4
|
+
class InvalidTLDException extends Error {
|
|
5
|
+
constructor(tld) {
|
|
6
|
+
super(`The provided tld [${tld}] is not valid`);
|
|
7
|
+
this.name = "InvalidTLDException";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.InvalidTLDException = InvalidTLDException;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./InvalidDomainNameException";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./InvalidDomainNameException"), exports);
|
package/dist/index.d.mts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
declare const COMMANDS: readonly ["namecheap.domains.getList", "namecheap.domains.getContacts", "namecheap.domains.create", "namecheap.domains.getTldList", "namecheap.domains.setContacts", "namecheap.domains.check", "namecheap.domains.reactivate", "namecheap.domains.renew", "namecheap.domains.getRegistrarLock", "namecheap.domains.setRegistrarLock", "namecheap.domains.getInfo", "namecheap.domains.dns.setDefault", "namecheap.domains.dns.setCustom", "namecheap.domains.dns.getList", "namecheap.domains.dns.getHosts", "namecheap.domains.dns.getEmailForwarding", "namecheap.domains.dns.setEmailForwarding", "namecheap.domains.dns.setHosts", "namecheap.domains.ns.create", "namecheap.domains.ns.delete", "namecheap.domains.ns.getInfo", "namecheap.domains.ns.update", "namecheap.domains.transfer.create", "namecheap.domains.transfer.getStatus", "namecheap.domains.transfer.updateStatus", "namecheap.domains.transfer.getList", "namecheap.ssl.create", "namecheap.ssl.getList", "namecheap.ssl.parseCSR", "namecheap.ssl.getApproverEmailList", "namecheap.ssl.activate", "namecheap.ssl.resendApproverEmail", "namecheap.ssl.getInfo", "namecheap.ssl.renew", "namecheap.ssl.reissue", "namecheap.ssl.resendfulfillmentemail", "namecheap.ssl.purchasemoresans", "namecheap.ssl.revokecertificate", "namecheap.ssl.editDCVMethod", "namecheap.users.getPricing", "namecheap.users.getBalances", "namecheap.users.changePassword", "namecheap.users.update", "namecheap.users.createaddfundsrequest", "namecheap.users.getAddFundsStatus", "namecheap.users.create", "namecheap.users.login", "namecheap.users.resetPassword", "namecheap.users.address.create", "namecheap.users.address.delete", "namecheap.users.address.getInfo", "namecheap.users.address.getList", "namecheap.users.address.setDefault", "namecheap.users.address.update", "Namecheap.Whoisguard.changeemailaddress", "Namecheap.Whoisguard.enable", "Namecheap.Whoisguard.disable", "Namecheap.Whoisguard.getList", "Namecheap.Whoisguard.renew"];
|
|
2
2
|
type ICommand = (typeof COMMANDS)[number];
|
|
3
3
|
|
|
4
|
-
interface
|
|
4
|
+
interface INamecheapConfig {
|
|
5
5
|
ApiUser: string;
|
|
6
6
|
ApiKey: string;
|
|
7
7
|
UserName: string;
|
|
8
8
|
ClientIp: string;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
interface ICallReponse {
|
|
11
|
+
data: any;
|
|
12
|
+
status: number;
|
|
13
|
+
}
|
|
14
|
+
declare class Namecheap {
|
|
11
15
|
private readonly config;
|
|
12
16
|
private readonly apiClient;
|
|
13
|
-
constructor(config:
|
|
14
|
-
call(command: ICommand, payload: Record<string, string>): Promise<
|
|
17
|
+
constructor(config: INamecheapConfig, sandbox?: boolean);
|
|
18
|
+
call(command: ICommand, payload: Record<string, string>): Promise<ICallReponse>;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
export {
|
|
21
|
+
export { ICallReponse, INamecheapConfig, Namecheap as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
interface INameCheapConfig {
|
|
5
|
-
ApiUser: string;
|
|
6
|
-
ApiKey: string;
|
|
7
|
-
UserName: string;
|
|
8
|
-
ClientIp: string;
|
|
9
|
-
}
|
|
10
|
-
declare class NameCheap {
|
|
11
|
-
private readonly config;
|
|
12
|
-
private readonly apiClient;
|
|
13
|
-
constructor(config: INameCheapConfig, sandbox?: boolean);
|
|
14
|
-
call(command: ICommand, payload: Record<string, string>): Promise<any>;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { INameCheapConfig, NameCheap as default };
|
|
1
|
+
export * from "./namecheap";
|
|
2
|
+
export { default } from "./namecheap";
|
package/dist/index.js
CHANGED
|
@@ -1,147 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
7
|
}
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
39
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
40
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
41
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
-
mod
|
|
44
|
-
));
|
|
45
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
-
var __async = (__this, __arguments, generator) => {
|
|
47
|
-
return new Promise((resolve, reject) => {
|
|
48
|
-
var fulfilled = (value) => {
|
|
49
|
-
try {
|
|
50
|
-
step(generator.next(value));
|
|
51
|
-
} catch (e) {
|
|
52
|
-
reject(e);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
var rejected = (value) => {
|
|
56
|
-
try {
|
|
57
|
-
step(generator.throw(value));
|
|
58
|
-
} catch (e) {
|
|
59
|
-
reject(e);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
63
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// src/index.ts
|
|
68
|
-
var src_exports = {};
|
|
69
|
-
__export(src_exports, {
|
|
70
|
-
default: () => namecheap_default
|
|
71
|
-
});
|
|
72
|
-
module.exports = __toCommonJS(src_exports);
|
|
73
|
-
|
|
74
|
-
// src/api/api-client.ts
|
|
75
|
-
var import_axios = __toESM(require("axios"));
|
|
76
|
-
var import_xml2js = require("xml2js");
|
|
77
|
-
|
|
78
|
-
// src/api/errors.ts
|
|
79
|
-
var XMLParsingError = class extends Error {
|
|
80
|
-
constructor() {
|
|
81
|
-
super("Invalid XML response");
|
|
82
|
-
this.name = "XMLParsingError";
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
var ResponseError = class extends Error {
|
|
86
|
-
constructor(message, code) {
|
|
87
|
-
super((code ? `${code}: ` : "") + message);
|
|
88
|
-
this.code = code;
|
|
89
|
-
this.name = "ResponseError";
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// src/api/api-client.ts
|
|
94
|
-
var APIClient = class {
|
|
95
|
-
constructor(baseURL) {
|
|
96
|
-
this._client = import_axios.default.create({ baseURL });
|
|
97
|
-
this._client.interceptors.response.use(this.onResponse);
|
|
98
|
-
}
|
|
99
|
-
get(url) {
|
|
100
|
-
return __async(this, null, function* () {
|
|
101
|
-
return yield this._client.get(url);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
onResponse(response) {
|
|
105
|
-
return __async(this, null, function* () {
|
|
106
|
-
try {
|
|
107
|
-
const result = yield (0, import_xml2js.parseStringPromise)(response.data);
|
|
108
|
-
if (result.ApiResponse.$.Status === "ERROR") {
|
|
109
|
-
const responseErrors = result.ApiResponse.Errors;
|
|
110
|
-
const code = responseErrors[0].Error[0].$.Number;
|
|
111
|
-
const message = responseErrors[0].Error[0]._;
|
|
112
|
-
throw new ResponseError(message, code);
|
|
113
|
-
}
|
|
114
|
-
response.data = result.ApiResponse.CommandResponse;
|
|
115
|
-
} catch (err) {
|
|
116
|
-
response.status = 400;
|
|
117
|
-
if (err instanceof ResponseError) {
|
|
118
|
-
throw err;
|
|
119
|
-
}
|
|
120
|
-
throw new XMLParsingError();
|
|
121
|
-
}
|
|
122
|
-
return response;
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
var api_client_default = APIClient;
|
|
127
|
-
|
|
128
|
-
// src/namecheap.ts
|
|
129
|
-
var NameCheap = class {
|
|
130
|
-
constructor(config, sandbox) {
|
|
131
|
-
this.config = config;
|
|
132
|
-
const baseURL = `https://api${sandbox ? ".sandbox" : ""}.namecheap.com/xml.response`;
|
|
133
|
-
this.apiClient = new api_client_default(baseURL);
|
|
134
|
-
}
|
|
135
|
-
call(command, payload) {
|
|
136
|
-
return __async(this, null, function* () {
|
|
137
|
-
const params = __spreadProps(__spreadValues(__spreadValues({}, this.config), payload), {
|
|
138
|
-
command
|
|
139
|
-
});
|
|
140
|
-
const url = "?" + new URLSearchParams(params).toString();
|
|
141
|
-
const response = yield this.apiClient.get(url);
|
|
142
|
-
return response.data;
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
var namecheap_default = NameCheap;
|
|
147
|
-
//# sourceMappingURL=index.js.map
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.default = void 0;
|
|
21
|
+
__exportStar(require("./namecheap"), exports);
|
|
22
|
+
var namecheap_1 = require("./namecheap");
|
|
23
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(namecheap_1).default; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/api/api-client.ts","../src/api/errors.ts","../src/namecheap.ts"],"sourcesContent":["export { default
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/api/api-client.ts","../src/api/errors.ts","../src/namecheap.ts"],"sourcesContent":["export { default, INamecheapConfig, ICallReponse } from \"./namecheap\";\r\n\r\n// import fs from \"fs\";\r\n\r\n// import NameCheap from \"./namecheap\";\r\n\r\n// const instance = new NameCheap(\r\n// {\r\n// ApiKey: \"d915adb9b0ac405398def53be001110e\",\r\n// ApiUser: \"Kanakri\",\r\n// UserName: \"Kanakri\",\r\n// ClientIp: \"5.155.10.166\",\r\n// },\r\n// true\r\n// );\r\n\r\n// instance\r\n// .call(\"namecheap.domains.check\", {\r\n// DomainList: \"mezoishere.net\",\r\n// })\r\n// .then(({data}) => {\r\n// fs.writeFile(\"data.json\", JSON.stringify(data, null, 2), \"utf8\", (err) => {\r\n// console.log(err);\r\n// });\r\n// console.log({ data });\r\n// })\r\n// .catch((err) => {\r\n// console.log({ err });\r\n// });\r\n","import axios, { AxiosInstance, AxiosResponse } from \"axios\";\r\nimport { parseStringPromise } from \"xml2js\";\r\nimport { ResponseError, XMLParsingError } from \"./errors\";\r\n\r\nclass APIClient {\r\n private readonly _client: AxiosInstance;\r\n constructor(baseURL: string) {\r\n this._client = axios.create({ baseURL });\r\n this._client.interceptors.response.use(this.onResponse);\r\n }\r\n\r\n async get(url: string) {\r\n return await this._client.get(url);\r\n }\r\n\r\n private async onResponse(response: AxiosResponse): Promise<AxiosResponse> {\r\n try {\r\n const result = await parseStringPromise(response.data);\r\n\r\n if (result.ApiResponse.$.Status === \"ERROR\") {\r\n const responseErrors = result.ApiResponse.Errors;\r\n const code = responseErrors[0].Error[0].$.Number;\r\n const message = responseErrors[0].Error[0]._;\r\n\r\n throw new ResponseError(message, code);\r\n }\r\n\r\n response.data = result.ApiResponse.CommandResponse;\r\n } catch (err) {\r\n response.status = 400;\r\n if (err instanceof ResponseError) {\r\n throw err;\r\n }\r\n\r\n throw new XMLParsingError();\r\n }\r\n\r\n return response;\r\n }\r\n}\r\n\r\nexport default APIClient;\r\n","export class XMLParsingError extends Error {\r\n constructor() {\r\n super(\"Invalid XML response\");\r\n\r\n this.name = \"XMLParsingError\";\r\n }\r\n}\r\n\r\nexport class ResponseError extends Error {\r\n constructor(message: string, readonly code?: number) {\r\n super((code ? `${code}: ` : \"\") + message);\r\n\r\n this.name = \"ResponseError\";\r\n }\r\n}\r\n","import APIClient from \"./api\";\r\nimport { ICommand } from \"./commands\";\r\n\r\nexport interface INamecheapConfig {\r\n ApiUser: string;\r\n ApiKey: string;\r\n UserName: string;\r\n ClientIp: string;\r\n}\r\n\r\nexport interface ICallReponse {\r\n data: any;\r\n status: number;\r\n}\r\n\r\nclass Namecheap {\r\n private readonly apiClient: APIClient;\r\n constructor(private readonly config: INamecheapConfig, sandbox?: boolean) {\r\n const baseURL = `https://api${\r\n sandbox ? \".sandbox\" : \"\"\r\n }.namecheap.com/xml.response`;\r\n this.apiClient = new APIClient(baseURL);\r\n }\r\n\r\n async call(\r\n command: ICommand,\r\n payload: Record<string, string>\r\n ): Promise<ICallReponse> {\r\n const params = {\r\n ...this.config,\r\n ...payload,\r\n command,\r\n };\r\n\r\n const url = \"?\" + new URLSearchParams(params).toString();\r\n\r\n const { data, status } = await this.apiClient.get(url);\r\n\r\n return { data, status };\r\n }\r\n}\r\n\r\nexport default Namecheap;\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAoD;AACpD,oBAAmC;;;ACD5B,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,cAAc;AACZ,UAAM,sBAAsB;AAE5B,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EACvC,YAAY,SAA0B,MAAe;AACnD,WAAO,OAAO,GAAG,IAAI,OAAO,MAAM,OAAO;AADL;AAGpC,SAAK,OAAO;AAAA,EACd;AACF;;;ADVA,IAAM,YAAN,MAAgB;AAAA,EAEd,YAAY,SAAiB;AAC3B,SAAK,UAAU,aAAAA,QAAM,OAAO,EAAE,QAAQ,CAAC;AACvC,SAAK,QAAQ,aAAa,SAAS,IAAI,KAAK,UAAU;AAAA,EACxD;AAAA,EAEM,IAAI,KAAa;AAAA;AACrB,aAAO,MAAM,KAAK,QAAQ,IAAI,GAAG;AAAA,IACnC;AAAA;AAAA,EAEc,WAAW,UAAiD;AAAA;AACxE,UAAI;AACF,cAAM,SAAS,UAAM,kCAAmB,SAAS,IAAI;AAErD,YAAI,OAAO,YAAY,EAAE,WAAW,SAAS;AAC3C,gBAAM,iBAAiB,OAAO,YAAY;AAC1C,gBAAM,OAAO,eAAe,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE;AAC1C,gBAAM,UAAU,eAAe,CAAC,EAAE,MAAM,CAAC,EAAE;AAE3C,gBAAM,IAAI,cAAc,SAAS,IAAI;AAAA,QACvC;AAEA,iBAAS,OAAO,OAAO,YAAY;AAAA,MACrC,SAAS,KAAK;AACZ,iBAAS,SAAS;AAClB,YAAI,eAAe,eAAe;AAChC,gBAAM;AAAA,QACR;AAEA,cAAM,IAAI,gBAAgB;AAAA,MAC5B;AAEA,aAAO;AAAA,IACT;AAAA;AACF;AAEA,IAAO,qBAAQ;;;AE1Bf,IAAM,YAAN,MAAgB;AAAA,EAEd,YAA6B,QAA0B,SAAmB;AAA7C;AAC3B,UAAM,UAAU,cACd,UAAU,aAAa,EACzB;AACA,SAAK,YAAY,IAAI,mBAAU,OAAO;AAAA,EACxC;AAAA,EAEM,KACJ,SACA,SACuB;AAAA;AACvB,YAAM,SAAS,gDACV,KAAK,SACL,UAFU;AAAA,QAGb;AAAA,MACF;AAEA,YAAM,MAAM,MAAM,IAAI,gBAAgB,MAAM,EAAE,SAAS;AAEvD,YAAM,EAAE,MAAM,OAAO,IAAI,MAAM,KAAK,UAAU,IAAI,GAAG;AAErD,aAAO,EAAE,MAAM,OAAO;AAAA,IACxB;AAAA;AACF;AAEA,IAAO,oBAAQ;","names":["axios"]}
|
package/dist/index.mjs
CHANGED
|
@@ -93,7 +93,7 @@ var APIClient = class {
|
|
|
93
93
|
var api_client_default = APIClient;
|
|
94
94
|
|
|
95
95
|
// src/namecheap.ts
|
|
96
|
-
var
|
|
96
|
+
var Namecheap = class {
|
|
97
97
|
constructor(config, sandbox) {
|
|
98
98
|
this.config = config;
|
|
99
99
|
const baseURL = `https://api${sandbox ? ".sandbox" : ""}.namecheap.com/xml.response`;
|
|
@@ -105,12 +105,12 @@ var NameCheap = class {
|
|
|
105
105
|
command
|
|
106
106
|
});
|
|
107
107
|
const url = "?" + new URLSearchParams(params).toString();
|
|
108
|
-
const
|
|
109
|
-
return
|
|
108
|
+
const { data, status } = yield this.apiClient.get(url);
|
|
109
|
+
return { data, status };
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
|
-
var namecheap_default =
|
|
113
|
+
var namecheap_default = Namecheap;
|
|
114
114
|
export {
|
|
115
115
|
namecheap_default as default
|
|
116
116
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api/api-client.ts","../src/api/errors.ts","../src/namecheap.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\r\nimport { parseStringPromise } from \"xml2js\";\r\nimport { ResponseError, XMLParsingError } from \"./errors\";\r\n\r\nclass APIClient {\r\n private readonly _client: AxiosInstance;\r\n constructor(baseURL: string) {\r\n this._client = axios.create({ baseURL });\r\n this._client.interceptors.response.use(this.onResponse);\r\n }\r\n\r\n async get(url: string) {\r\n return await this._client.get(url);\r\n }\r\n\r\n private async onResponse(response: AxiosResponse): Promise<AxiosResponse> {\r\n try {\r\n const result = await parseStringPromise(response.data);\r\n\r\n if (result.ApiResponse.$.Status === \"ERROR\") {\r\n const responseErrors = result.ApiResponse.Errors;\r\n const code = responseErrors[0].Error[0].$.Number;\r\n const message = responseErrors[0].Error[0]._;\r\n\r\n throw new ResponseError(message, code);\r\n }\r\n\r\n response.data = result.ApiResponse.CommandResponse;\r\n } catch (err) {\r\n response.status = 400;\r\n if (err instanceof ResponseError) {\r\n throw err;\r\n }\r\n\r\n throw new XMLParsingError();\r\n }\r\n\r\n return response;\r\n }\r\n}\r\n\r\nexport default APIClient;\r\n","export class XMLParsingError extends Error {\r\n constructor() {\r\n super(\"Invalid XML response\");\r\n\r\n this.name = \"XMLParsingError\";\r\n }\r\n}\r\n\r\nexport class ResponseError extends Error {\r\n constructor(message: string, readonly code?: number) {\r\n super((code ? `${code}: ` : \"\") + message);\r\n\r\n this.name = \"ResponseError\";\r\n }\r\n}\r\n","import APIClient from \"./api\";\r\nimport { ICommand } from \"./commands\";\r\n\r\nexport interface
|
|
1
|
+
{"version":3,"sources":["../src/api/api-client.ts","../src/api/errors.ts","../src/namecheap.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\r\nimport { parseStringPromise } from \"xml2js\";\r\nimport { ResponseError, XMLParsingError } from \"./errors\";\r\n\r\nclass APIClient {\r\n private readonly _client: AxiosInstance;\r\n constructor(baseURL: string) {\r\n this._client = axios.create({ baseURL });\r\n this._client.interceptors.response.use(this.onResponse);\r\n }\r\n\r\n async get(url: string) {\r\n return await this._client.get(url);\r\n }\r\n\r\n private async onResponse(response: AxiosResponse): Promise<AxiosResponse> {\r\n try {\r\n const result = await parseStringPromise(response.data);\r\n\r\n if (result.ApiResponse.$.Status === \"ERROR\") {\r\n const responseErrors = result.ApiResponse.Errors;\r\n const code = responseErrors[0].Error[0].$.Number;\r\n const message = responseErrors[0].Error[0]._;\r\n\r\n throw new ResponseError(message, code);\r\n }\r\n\r\n response.data = result.ApiResponse.CommandResponse;\r\n } catch (err) {\r\n response.status = 400;\r\n if (err instanceof ResponseError) {\r\n throw err;\r\n }\r\n\r\n throw new XMLParsingError();\r\n }\r\n\r\n return response;\r\n }\r\n}\r\n\r\nexport default APIClient;\r\n","export class XMLParsingError extends Error {\r\n constructor() {\r\n super(\"Invalid XML response\");\r\n\r\n this.name = \"XMLParsingError\";\r\n }\r\n}\r\n\r\nexport class ResponseError extends Error {\r\n constructor(message: string, readonly code?: number) {\r\n super((code ? `${code}: ` : \"\") + message);\r\n\r\n this.name = \"ResponseError\";\r\n }\r\n}\r\n","import APIClient from \"./api\";\r\nimport { ICommand } from \"./commands\";\r\n\r\nexport interface INamecheapConfig {\r\n ApiUser: string;\r\n ApiKey: string;\r\n UserName: string;\r\n ClientIp: string;\r\n}\r\n\r\nexport interface ICallReponse {\r\n data: any;\r\n status: number;\r\n}\r\n\r\nclass Namecheap {\r\n private readonly apiClient: APIClient;\r\n constructor(private readonly config: INamecheapConfig, sandbox?: boolean) {\r\n const baseURL = `https://api${\r\n sandbox ? \".sandbox\" : \"\"\r\n }.namecheap.com/xml.response`;\r\n this.apiClient = new APIClient(baseURL);\r\n }\r\n\r\n async call(\r\n command: ICommand,\r\n payload: Record<string, string>\r\n ): Promise<ICallReponse> {\r\n const params = {\r\n ...this.config,\r\n ...payload,\r\n command,\r\n };\r\n\r\n const url = \"?\" + new URLSearchParams(params).toString();\r\n\r\n const { data, status } = await this.apiClient.get(url);\r\n\r\n return { data, status };\r\n }\r\n}\r\n\r\nexport default Namecheap;\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,WAA6C;AACpD,SAAS,0BAA0B;;;ACD5B,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,cAAc;AACZ,UAAM,sBAAsB;AAE5B,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EACvC,YAAY,SAA0B,MAAe;AACnD,WAAO,OAAO,GAAG,IAAI,OAAO,MAAM,OAAO;AADL;AAGpC,SAAK,OAAO;AAAA,EACd;AACF;;;ADVA,IAAM,YAAN,MAAgB;AAAA,EAEd,YAAY,SAAiB;AAC3B,SAAK,UAAU,MAAM,OAAO,EAAE,QAAQ,CAAC;AACvC,SAAK,QAAQ,aAAa,SAAS,IAAI,KAAK,UAAU;AAAA,EACxD;AAAA,EAEM,IAAI,KAAa;AAAA;AACrB,aAAO,MAAM,KAAK,QAAQ,IAAI,GAAG;AAAA,IACnC;AAAA;AAAA,EAEc,WAAW,UAAiD;AAAA;AACxE,UAAI;AACF,cAAM,SAAS,MAAM,mBAAmB,SAAS,IAAI;AAErD,YAAI,OAAO,YAAY,EAAE,WAAW,SAAS;AAC3C,gBAAM,iBAAiB,OAAO,YAAY;AAC1C,gBAAM,OAAO,eAAe,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE;AAC1C,gBAAM,UAAU,eAAe,CAAC,EAAE,MAAM,CAAC,EAAE;AAE3C,gBAAM,IAAI,cAAc,SAAS,IAAI;AAAA,QACvC;AAEA,iBAAS,OAAO,OAAO,YAAY;AAAA,MACrC,SAAS,KAAK;AACZ,iBAAS,SAAS;AAClB,YAAI,eAAe,eAAe;AAChC,gBAAM;AAAA,QACR;AAEA,cAAM,IAAI,gBAAgB;AAAA,MAC5B;AAEA,aAAO;AAAA,IACT;AAAA;AACF;AAEA,IAAO,qBAAQ;;;AE1Bf,IAAM,YAAN,MAAgB;AAAA,EAEd,YAA6B,QAA0B,SAAmB;AAA7C;AAC3B,UAAM,UAAU,cACd,UAAU,aAAa,EACzB;AACA,SAAK,YAAY,IAAI,mBAAU,OAAO;AAAA,EACxC;AAAA,EAEM,KACJ,SACA,SACuB;AAAA;AACvB,YAAM,SAAS,gDACV,KAAK,SACL,UAFU;AAAA,QAGb;AAAA,MACF;AAEA,YAAM,MAAM,MAAM,IAAI,gBAAgB,MAAM,EAAE,SAAS;AAEvD,YAAM,EAAE,MAAM,OAAO,IAAI,MAAM,KAAK,UAAU,IAAI,GAAG;AAErD,aAAO,EAAE,MAAM,OAAO;AAAA,IACxB;AAAA;AACF;AAEA,IAAO,oBAAQ;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Command } from "./commands";
|
|
2
|
+
import { DomainPriceAction } from "./types";
|
|
3
|
+
export interface INamecheapConfig {
|
|
4
|
+
ApiUser: string;
|
|
5
|
+
ApiKey: string;
|
|
6
|
+
UserName: string;
|
|
7
|
+
ClientIp: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IReponse {
|
|
10
|
+
data: any;
|
|
11
|
+
status: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ICheckDomainResponse {
|
|
14
|
+
availabe: boolean;
|
|
15
|
+
premium: boolean;
|
|
16
|
+
}
|
|
17
|
+
declare class Namecheap {
|
|
18
|
+
private readonly config;
|
|
19
|
+
private readonly apiClient;
|
|
20
|
+
constructor(config: INamecheapConfig, sandbox?: boolean);
|
|
21
|
+
call(command: Command, payload: Record<string, string>): Promise<IReponse>;
|
|
22
|
+
checkDomain(domainName: string): Promise<ICheckDomainResponse>;
|
|
23
|
+
getDomainPrice(domainName: string, action: DomainPriceAction): Promise<IReponse>;
|
|
24
|
+
}
|
|
25
|
+
export default Namecheap;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const api_1 = __importDefault(require("./api"));
|
|
16
|
+
const commands_1 = require("./commands");
|
|
17
|
+
const exceptions_1 = require("./exceptions");
|
|
18
|
+
class Namecheap {
|
|
19
|
+
constructor(config, sandbox) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
const baseURL = `https://api${sandbox ? ".sandbox" : ""}.namecheap.com/xml.response`;
|
|
22
|
+
this.apiClient = new api_1.default(baseURL);
|
|
23
|
+
}
|
|
24
|
+
call(command, payload) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const params = Object.assign(Object.assign(Object.assign({}, payload), this.config), { command });
|
|
27
|
+
const url = "?" + new URLSearchParams(params).toString();
|
|
28
|
+
const { data, status } = yield this.apiClient.get(url);
|
|
29
|
+
return { data, status };
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
checkDomain(domainName) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const { data } = yield this.call(commands_1.Commands.DOMAINS_CHECK, {
|
|
35
|
+
DomainList: domainName,
|
|
36
|
+
});
|
|
37
|
+
const isAvailabe = data[0].DomainCheckResult[0].$.Available;
|
|
38
|
+
const isPremium = data[0].DomainCheckResult[0].$.IsPremiumName;
|
|
39
|
+
const response = {
|
|
40
|
+
availabe: isAvailabe === "true",
|
|
41
|
+
premium: isPremium === "true",
|
|
42
|
+
};
|
|
43
|
+
return response;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
getDomainPrice(domainName, action) {
|
|
47
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const [_, tld] = domainName.split(".");
|
|
50
|
+
if (!tld) {
|
|
51
|
+
throw new exceptions_1.InvalidDomainNameException(domainName);
|
|
52
|
+
}
|
|
53
|
+
const { data, status } = yield this.call(commands_1.Commands.USERS_GETPRICING, {
|
|
54
|
+
ProductType: "DOMAIN",
|
|
55
|
+
ProductCategory: "DOMAINS",
|
|
56
|
+
ActionName: action,
|
|
57
|
+
ProductName: tld,
|
|
58
|
+
});
|
|
59
|
+
const pricing = (_h = (_g = (_f = (_e = (_d = (_c = (_b = (_a = data[0].UserGetPricingResult[0]) === null || _a === void 0 ? void 0 : _a.ProductType) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.ProductCategory) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.Product) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.Price) === null || _h === void 0 ? void 0 : _h.map((price) => (Object.assign({}, price.$)));
|
|
60
|
+
return { data: pricing, status };
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.default = Namecheap;
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DomainPriceActions = void 0;
|
|
4
|
+
var DomainPriceActions;
|
|
5
|
+
(function (DomainPriceActions) {
|
|
6
|
+
DomainPriceActions["REGISTER"] = "REGISTER";
|
|
7
|
+
DomainPriceActions["RENEW"] = "RENEW";
|
|
8
|
+
DomainPriceActions["REACTIVATE"] = "REACTIVATE";
|
|
9
|
+
DomainPriceActions["TRANSFER"] = "TRANSFER";
|
|
10
|
+
})(DomainPriceActions || (exports.DomainPriceActions = DomainPriceActions = {}));
|