namecheap-ts 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/README.md +37 -0
- package/dist/index.d.mts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +147 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +117 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Namecheap-ts API Wrapper
|
|
2
|
+
|
|
3
|
+
A TypeScript package that provides a simple and intuitive interface to interact with Namecheap API.
|
|
4
|
+
|
|
5
|
+
- **Installation**: You can install the package using npm. Run the following command in your terminal:
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm install namecheap-ts
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- **Usage**: You can use the package to perform various operations such as domain registration, DNS management, SSL certificate management, and more. Here's an example of how to use the package to check whether the domain name is available or not:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import Namecheap, { INamecheapConfig } from "namecheap-ts";
|
|
15
|
+
const config: INamecheapConfig = {
|
|
16
|
+
ApiKey: "api-key",
|
|
17
|
+
ApiUser: "api-user",
|
|
18
|
+
UserName: "user-name",
|
|
19
|
+
ClientIp: "client-ip",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const api = new Namecheap(config, true);
|
|
23
|
+
|
|
24
|
+
const payload = { DomainList: "mezoishere.net" };
|
|
25
|
+
const { data } = await api.call("namecheap.domains.check", payload);
|
|
26
|
+
|
|
27
|
+
const isAvailabe = data[0].DomainCheckResult[0].$.Available;
|
|
28
|
+
console.log(isAvailable);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Remove the second parameter to use the API for production like below:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
const api = new Namecheap(config);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
You can refer to the official Namecheap API documentation for more information on the available methods and parameters. [The documentation is available at ¹](https://www.namecheap.com/support/api/intro/).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
type ICommand = (typeof COMMANDS)[number];
|
|
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 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
type ICommand = (typeof COMMANDS)[number];
|
|
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 };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
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]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __export = (target, all) => {
|
|
26
|
+
for (var name in all)
|
|
27
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
+
};
|
|
29
|
+
var __copyProps = (to, from, except, desc) => {
|
|
30
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
+
for (let key of __getOwnPropNames(from))
|
|
32
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
+
}
|
|
35
|
+
return to;
|
|
36
|
+
};
|
|
37
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/api/api-client.ts","../src/api/errors.ts","../src/namecheap.ts"],"sourcesContent":["export { default } from \"./namecheap\";\r\nexport { INameCheapConfig } 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((res) => {\r\n// fs.writeFile(\"data.json\", JSON.stringify(res, null, 2), \"utf8\", (err) => {\r\n// console.log(err);\r\n// });\r\n// console.log({ res });\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\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(command: ICommand, payload: Record<string, string>) {\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 response = await this.apiClient.get(url);\r\n\r\n return response.data;\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,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__defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/api/api-client.ts
|
|
42
|
+
import axios from "axios";
|
|
43
|
+
import { parseStringPromise } from "xml2js";
|
|
44
|
+
|
|
45
|
+
// src/api/errors.ts
|
|
46
|
+
var XMLParsingError = class extends Error {
|
|
47
|
+
constructor() {
|
|
48
|
+
super("Invalid XML response");
|
|
49
|
+
this.name = "XMLParsingError";
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var ResponseError = class extends Error {
|
|
53
|
+
constructor(message, code) {
|
|
54
|
+
super((code ? `${code}: ` : "") + message);
|
|
55
|
+
this.code = code;
|
|
56
|
+
this.name = "ResponseError";
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/api/api-client.ts
|
|
61
|
+
var APIClient = class {
|
|
62
|
+
constructor(baseURL) {
|
|
63
|
+
this._client = axios.create({ baseURL });
|
|
64
|
+
this._client.interceptors.response.use(this.onResponse);
|
|
65
|
+
}
|
|
66
|
+
get(url) {
|
|
67
|
+
return __async(this, null, function* () {
|
|
68
|
+
return yield this._client.get(url);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
onResponse(response) {
|
|
72
|
+
return __async(this, null, function* () {
|
|
73
|
+
try {
|
|
74
|
+
const result = yield parseStringPromise(response.data);
|
|
75
|
+
if (result.ApiResponse.$.Status === "ERROR") {
|
|
76
|
+
const responseErrors = result.ApiResponse.Errors;
|
|
77
|
+
const code = responseErrors[0].Error[0].$.Number;
|
|
78
|
+
const message = responseErrors[0].Error[0]._;
|
|
79
|
+
throw new ResponseError(message, code);
|
|
80
|
+
}
|
|
81
|
+
response.data = result.ApiResponse.CommandResponse;
|
|
82
|
+
} catch (err) {
|
|
83
|
+
response.status = 400;
|
|
84
|
+
if (err instanceof ResponseError) {
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
87
|
+
throw new XMLParsingError();
|
|
88
|
+
}
|
|
89
|
+
return response;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var api_client_default = APIClient;
|
|
94
|
+
|
|
95
|
+
// src/namecheap.ts
|
|
96
|
+
var NameCheap = class {
|
|
97
|
+
constructor(config, sandbox) {
|
|
98
|
+
this.config = config;
|
|
99
|
+
const baseURL = `https://api${sandbox ? ".sandbox" : ""}.namecheap.com/xml.response`;
|
|
100
|
+
this.apiClient = new api_client_default(baseURL);
|
|
101
|
+
}
|
|
102
|
+
call(command, payload) {
|
|
103
|
+
return __async(this, null, function* () {
|
|
104
|
+
const params = __spreadProps(__spreadValues(__spreadValues({}, this.config), payload), {
|
|
105
|
+
command
|
|
106
|
+
});
|
|
107
|
+
const url = "?" + new URLSearchParams(params).toString();
|
|
108
|
+
const response = yield this.apiClient.get(url);
|
|
109
|
+
return response.data;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var namecheap_default = NameCheap;
|
|
114
|
+
export {
|
|
115
|
+
namecheap_default as default
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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 INameCheapConfig {\r\n ApiUser: string;\r\n ApiKey: string;\r\n UserName: string;\r\n ClientIp: string;\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(command: ICommand, payload: Record<string, string>) {\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 response = await this.apiClient.get(url);\r\n\r\n return response.data;\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;AAA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|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "namecheap-ts",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A simple wrapper for namecheap API",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"start": "tsc --build && node dist/index.js",
|
|
13
|
+
"build": "tsup",
|
|
14
|
+
"test": "jest"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"namecheap",
|
|
18
|
+
"nodejs",
|
|
19
|
+
"typescript",
|
|
20
|
+
"domain registrar"
|
|
21
|
+
],
|
|
22
|
+
"author": "Abdulrahman Kanakri",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"axios": "^1.5.1",
|
|
26
|
+
"xml2js": "^0.6.2"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/jest": "^29.5.5",
|
|
30
|
+
"@types/xml2js": "^0.4.12",
|
|
31
|
+
"jest": "^29.7.0",
|
|
32
|
+
"ts-jest": "^29.1.1",
|
|
33
|
+
"tsup": "^7.2.0",
|
|
34
|
+
"typescript": "^5.2.2"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/abdulrahmanKanakri/namecheap-ts.git"
|
|
39
|
+
}
|
|
40
|
+
}
|