domrobot-client 3.0.2 → 3.1.1
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/.eslintrc +22 -0
- package/README.md +5 -3
- package/lib/domrobot.d.ts +2 -2
- package/lib/domrobot.js +23 -22
- package/lib/domrobot.js.map +1 -1
- package/lib/examples/domaincheck.js +7 -4
- package/lib/examples/domaincheck.js.map +1 -1
- package/lib/index.js +15 -4
- package/lib/index.js.map +1 -1
- package/package.json +14 -14
- package/src/domrobot.ts +25 -23
- package/src/examples/domaincheck.ts +6 -4
- package/tslint.json +0 -9
package/.eslintrc
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parser": "@typescript-eslint/parser",
|
|
3
|
+
"parserOptions": {
|
|
4
|
+
"ecmaVersion": "latest",
|
|
5
|
+
"sourceType": "script"
|
|
6
|
+
},
|
|
7
|
+
"env": {
|
|
8
|
+
"es2021": true,
|
|
9
|
+
"node": true
|
|
10
|
+
},
|
|
11
|
+
"plugins": [
|
|
12
|
+
"@typescript-eslint"
|
|
13
|
+
],
|
|
14
|
+
"extends": [
|
|
15
|
+
"eslint:recommended",
|
|
16
|
+
"prettier"
|
|
17
|
+
],
|
|
18
|
+
"rules": {
|
|
19
|
+
"no-console": 0,
|
|
20
|
+
"no-unused-vars": 0
|
|
21
|
+
}
|
|
22
|
+
}
|
package/README.md
CHANGED
|
@@ -39,8 +39,8 @@ const sharedSecret = ''; // only needed for 2FA.
|
|
|
39
39
|
const domain = 'my-test-domain-' + Math.round(Math.random() * 1e8) + '.com'; // the domain which will be checked.
|
|
40
40
|
|
|
41
41
|
const asyncFunc = async () => {
|
|
42
|
-
// By default
|
|
43
|
-
// we have a constant named API_URL_LIVE in the ApiClient class. Just set
|
|
42
|
+
// By default your ApiClient uses the test api (OT&E). If you want to use the production/live api
|
|
43
|
+
// we have a constant named API_URL_LIVE in the ApiClient class. Just set apiUrl=ApiClient.API_URL_LIVE and you're good.
|
|
44
44
|
const apiClient = new ApiClient(ApiClient.API_URL_OTE, Language.EN, true);
|
|
45
45
|
|
|
46
46
|
const loginResponse = await apiClient.login(username, password, sharedSecret);
|
|
@@ -58,8 +58,10 @@ const asyncFunc = async () => {
|
|
|
58
58
|
|
|
59
59
|
// get the first domain in the result array 'domain'
|
|
60
60
|
const checkedDomain = domainCheckResponse.resData.domain[0];
|
|
61
|
-
if (checkedDomain.avail) {
|
|
61
|
+
if (checkedDomain.avail === 1) {
|
|
62
62
|
console.log(`${domain} is still available!`);
|
|
63
|
+
} else if (checkedDomain.avail === -1) {
|
|
64
|
+
console.log(`Availability of ${domain} could not be checked.`);
|
|
63
65
|
} else {
|
|
64
66
|
console.log(`Unfortunately, ${domain} is already registered.`);
|
|
65
67
|
}
|
package/lib/domrobot.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ export declare class ApiClient {
|
|
|
3
3
|
static readonly API_URL_LIVE = "https://api.domrobot.com/jsonrpc/";
|
|
4
4
|
static readonly API_URL_OTE = "https://api.ote.domrobot.com/jsonrpc/";
|
|
5
5
|
static generateClientTransactionId(): string;
|
|
6
|
-
private apiUrl;
|
|
6
|
+
private readonly apiUrl;
|
|
7
7
|
private language;
|
|
8
8
|
private debugMode;
|
|
9
|
-
private
|
|
9
|
+
private cookie;
|
|
10
10
|
/**
|
|
11
11
|
* @param apiUrl url of the API.
|
|
12
12
|
* @param language default language for future API requests.
|
package/lib/domrobot.js
CHANGED
|
@@ -9,9 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Language = exports.ApiClient = void 0;
|
|
12
13
|
const otplib = require("otplib");
|
|
13
|
-
const request = require("request-promise-native");
|
|
14
14
|
class ApiClient {
|
|
15
|
+
static generateClientTransactionId() {
|
|
16
|
+
return 'DomRobot-' + Math.round(Math.random() * 1000000000);
|
|
17
|
+
}
|
|
15
18
|
/**
|
|
16
19
|
* @param apiUrl url of the API.
|
|
17
20
|
* @param language default language for future API requests.
|
|
@@ -21,10 +24,7 @@ class ApiClient {
|
|
|
21
24
|
this.apiUrl = apiUrl;
|
|
22
25
|
this.language = language;
|
|
23
26
|
this.debugMode = debugMode;
|
|
24
|
-
this.
|
|
25
|
-
}
|
|
26
|
-
static generateClientTransactionId() {
|
|
27
|
-
return 'DomRobot-' + Math.round(Math.random() * 1000000000);
|
|
27
|
+
this.cookie = null;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Makes an API call.
|
|
@@ -46,23 +46,24 @@ class ApiClient {
|
|
|
46
46
|
method: apiMethod,
|
|
47
47
|
params: methodParams,
|
|
48
48
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
headers: {
|
|
49
|
+
const response = yield fetch(this.apiUrl, {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: new Headers({
|
|
53
52
|
'Content-Type': 'application/json',
|
|
53
|
+
Cookie: this.cookie,
|
|
54
54
|
'User-Agent': `DomRobot/${ApiClient.CLIENT_VERSION} (Node ${process.version})`,
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
}),
|
|
56
|
+
body: requestBody,
|
|
57
|
+
});
|
|
58
|
+
if (apiMethod === 'account.login') {
|
|
59
|
+
this.cookie = response.headers.get('set-cookie');
|
|
60
|
+
}
|
|
61
|
+
const data = yield response.json();
|
|
62
|
+
if (this.debugMode) {
|
|
63
|
+
console.info(`Request (${apiMethod}): ${requestBody}`);
|
|
64
|
+
console.info(`Response (${apiMethod}): ${JSON.stringify(data)}`);
|
|
65
|
+
}
|
|
66
|
+
return data;
|
|
66
67
|
});
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
@@ -93,7 +94,7 @@ class ApiClient {
|
|
|
93
94
|
*/
|
|
94
95
|
logout() {
|
|
95
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
return yield this.callApi('account.logout').then(() => (this.
|
|
97
|
+
return yield this.callApi('account.logout').then(() => (this.cookie = null));
|
|
97
98
|
});
|
|
98
99
|
}
|
|
99
100
|
getApiUrl() {
|
|
@@ -124,5 +125,5 @@ var Language;
|
|
|
124
125
|
Language["EN"] = "en";
|
|
125
126
|
Language["DE"] = "de";
|
|
126
127
|
Language["ES"] = "es";
|
|
127
|
-
})(Language
|
|
128
|
+
})(Language || (exports.Language = Language = {}));
|
|
128
129
|
//# sourceMappingURL=domrobot.js.map
|
package/lib/domrobot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domrobot.js","sourceRoot":"","sources":["../src/domrobot.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"domrobot.js","sourceRoot":"","sources":["../src/domrobot.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAiC;AAEjC,MAAa,SAAS;IAMX,MAAM,CAAC,2BAA2B;QACrC,OAAO,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC,CAAC;IAChE,CAAC;IAQD;;;;OAIG;IACH,YAAY,SAAiB,SAAS,CAAC,WAAW,EAAE,WAAmB,QAAQ,CAAC,EAAE,EAAE,YAAqB,KAAK;QAC1G,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAED;;;;;;;OAOG;IACU,OAAO,CAChB,SAAiB,EACjB,eAAoB,EAAE,EACtB,sBAA8B,SAAS,CAAC,2BAA2B,EAAE,EACrE,WAAmB,IAAI,CAAC,Q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Y,GAAG,mCAAmC,CAAC;AACnD,qBAAW,GAAG,uCAAuC,CAAC;AA4HjF;;GAEG;AACH,IAAY,QAIX;AAJD,WAAY,QAAQ;IAChB,qBAAS,CAAA;IACT,qBAAS,CAAA;IACT,qBAAS,CAAA;AACb,CAAC,EAJW,QAAQ,wBAAR,QAAQ,QAInB"}
|
|
@@ -15,8 +15,8 @@ const password = '';
|
|
|
15
15
|
const sharedSecret = ''; // only needed for 2FA.
|
|
16
16
|
const domain = 'my-test-domain-' + Math.round(Math.random() * 1e8) + '.com'; // the domain which will be checked.
|
|
17
17
|
const asyncFunc = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
// By default
|
|
19
|
-
// we have a constant named
|
|
18
|
+
// By default, your ApiClient uses the test api (OT&E). If you want to use the production/live api
|
|
19
|
+
// we have a constant named API_URL_LIVE in the ApiClient class. Just set apiUrl=ApiClient.API_URL_LIVE and you're good.
|
|
20
20
|
const apiClient = new domrobot_1.ApiClient(domrobot_1.ApiClient.API_URL_OTE, domrobot_1.Language.EN, true);
|
|
21
21
|
const loginResponse = yield apiClient.login(username, password, sharedSecret);
|
|
22
22
|
if (loginResponse.code !== 1000) {
|
|
@@ -31,13 +31,16 @@ const asyncFunc = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
31
31
|
}
|
|
32
32
|
// get the first domain in the result array 'domain'
|
|
33
33
|
const checkedDomain = domainCheckResponse.resData.domain[0];
|
|
34
|
-
if (checkedDomain.avail) {
|
|
34
|
+
if (checkedDomain.avail === 1) {
|
|
35
35
|
console.log(`${domain} is still available!`);
|
|
36
36
|
}
|
|
37
|
+
else if (checkedDomain.avail === -1) {
|
|
38
|
+
console.log(`Availability of ${domain} could not be checked.`);
|
|
39
|
+
}
|
|
37
40
|
else {
|
|
38
41
|
console.log(`Unfortunately, ${domain} is already registered.`);
|
|
39
42
|
}
|
|
40
43
|
});
|
|
41
44
|
// call the async function
|
|
42
|
-
asyncFunc();
|
|
45
|
+
asyncFunc().catch(console.error);
|
|
43
46
|
//# sourceMappingURL=domaincheck.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domaincheck.js","sourceRoot":"","sources":["../../src/examples/domaincheck.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,0CAAkD;AAElD,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,YAAY,GAAG,EAAE,CAAC,CAAC,uBAAuB;AAChD,MAAM,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,oCAAoC;AAEjH,MAAM,SAAS,GAAG,GAAS,EAAE;IACzB,
|
|
1
|
+
{"version":3,"file":"domaincheck.js","sourceRoot":"","sources":["../../src/examples/domaincheck.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,0CAAkD;AAElD,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,YAAY,GAAG,EAAE,CAAC,CAAC,uBAAuB;AAChD,MAAM,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,oCAAoC;AAEjH,MAAM,SAAS,GAAG,GAAS,EAAE;IACzB,kGAAkG;IAClG,wHAAwH;IACxH,MAAM,SAAS,GAAG,IAAI,oBAAS,CAAC,oBAAS,CAAC,WAAW,EAAE,mBAAQ,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAE1E,MAAM,aAAa,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC9E,IAAI,aAAa,CAAC,IAAI,KAAK,IAAI,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,0BAA0B,aAAa,CAAC,IAAI,cAAc,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC;KAClG;IAED,sDAAsD;IACtD,uFAAuF;IACvF,MAAM,mBAAmB,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAChF,IAAI,mBAAmB,CAAC,IAAI,KAAK,IAAI,EAAE;QACnC,MAAM,IAAI,KAAK,CAAC;8BACM,mBAAmB,CAAC,IAAI,cAAc,mBAAmB,CAAC,GAAG,EAAE,CAAC,CAAC;KAC1F;IAED,oDAAoD;IACpD,MAAM,aAAa,GAAG,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC5D,IAAI,aAAa,CAAC,KAAK,KAAK,CAAC,EAAE;QAC3B,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,sBAAsB,CAAC,CAAC;KAChD;SAAM,IAAI,aAAa,CAAC,KAAK,KAAK,CAAC,CAAC,EAAE;QACnC,OAAO,CAAC,GAAG,CAAC,mBAAmB,MAAM,wBAAwB,CAAC,CAAC;KAClE;SAAM;QACH,OAAO,CAAC,GAAG,CAAC,kBAAkB,MAAM,yBAAyB,CAAC,CAAC;KAClE;AACL,CAAC,CAAA,CAAC;AAEF,0BAA0B;AAC1B,SAAS,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
17
|
+
__exportStar(require("./domrobot"), exports);
|
|
7
18
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "domrobot-client",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "INWX Domrobot Node.JS Client",
|
|
5
5
|
"author": "INWX Developer <developer@inwx.de> (https://inwx.com)",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -21,24 +21,24 @@
|
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "tsc",
|
|
24
|
-
"format": "prettier --write \"src/**/*.ts\"
|
|
25
|
-
"lint": "
|
|
24
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
25
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
26
26
|
"prepare": "npm run build"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"otplib": "^
|
|
30
|
-
"request": "^2.88.0",
|
|
31
|
-
"request-promise-native": "^1.0.7"
|
|
29
|
+
"otplib": "^12.0.1"
|
|
32
30
|
},
|
|
33
31
|
"devDependencies": {
|
|
34
|
-
"@types/node": "^
|
|
32
|
+
"@types/node": "^20.3.3",
|
|
35
33
|
"@types/otplib": "^7.0.0",
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"prettier": "^
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^5.60.1",
|
|
35
|
+
"browserify": "^17.0.0",
|
|
36
|
+
"eslint": "^8.44.0",
|
|
37
|
+
"eslint-config-prettier": "^8.8.0",
|
|
38
|
+
"prettier": "^2.3.1",
|
|
39
|
+
"typescript": "^5.1.6"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/src/domrobot.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import * as otplib from 'otplib';
|
|
2
|
-
import { CookieJar } from 'request';
|
|
3
|
-
import * as request from 'request-promise-native';
|
|
4
2
|
|
|
5
3
|
export class ApiClient {
|
|
6
4
|
public static readonly CLIENT_VERSION = '3.0.2';
|
|
@@ -12,11 +10,11 @@ export class ApiClient {
|
|
|
12
10
|
return 'DomRobot-' + Math.round(Math.random() * 1000000000);
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
private apiUrl: string;
|
|
13
|
+
private readonly apiUrl: string;
|
|
16
14
|
private language: string;
|
|
17
15
|
private debugMode: boolean;
|
|
18
16
|
|
|
19
|
-
private
|
|
17
|
+
private cookie: string;
|
|
20
18
|
|
|
21
19
|
/**
|
|
22
20
|
* @param apiUrl url of the API.
|
|
@@ -27,7 +25,7 @@ export class ApiClient {
|
|
|
27
25
|
this.apiUrl = apiUrl;
|
|
28
26
|
this.language = language;
|
|
29
27
|
this.debugMode = debugMode;
|
|
30
|
-
this.
|
|
28
|
+
this.cookie = null;
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
/**
|
|
@@ -56,23 +54,27 @@ export class ApiClient {
|
|
|
56
54
|
params: methodParams,
|
|
57
55
|
});
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
.
|
|
57
|
+
const response = await fetch(this.apiUrl, {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
headers: new Headers({
|
|
60
|
+
'Content-Type': 'application/json',
|
|
61
|
+
Cookie: this.cookie,
|
|
62
|
+
'User-Agent': `DomRobot/${ApiClient.CLIENT_VERSION} (Node ${process.version})`,
|
|
63
|
+
}),
|
|
64
|
+
body: requestBody,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if (apiMethod === 'account.login') {
|
|
68
|
+
this.cookie = response.headers.get('set-cookie');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const data = await response.json()
|
|
72
|
+
if (this.debugMode) {
|
|
73
|
+
console.info(`Request (${apiMethod}): ${requestBody}`);
|
|
74
|
+
console.info(`Response (${apiMethod}): ${JSON.stringify(data)}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return data;
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
/**
|
|
@@ -102,7 +104,7 @@ export class ApiClient {
|
|
|
102
104
|
* Performs a logout at the API and destroys the current session.
|
|
103
105
|
*/
|
|
104
106
|
public async logout(): Promise<any> {
|
|
105
|
-
return await this.callApi('account.logout').then(() => (this.
|
|
107
|
+
return await this.callApi('account.logout').then(() => (this.cookie = null));
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
public getApiUrl(): string {
|
|
@@ -6,8 +6,8 @@ const sharedSecret = ''; // only needed for 2FA.
|
|
|
6
6
|
const domain = 'my-test-domain-' + Math.round(Math.random() * 1e8) + '.com'; // the domain which will be checked.
|
|
7
7
|
|
|
8
8
|
const asyncFunc = async () => {
|
|
9
|
-
// By default
|
|
10
|
-
// we have a constant named
|
|
9
|
+
// By default, your ApiClient uses the test api (OT&E). If you want to use the production/live api
|
|
10
|
+
// we have a constant named API_URL_LIVE in the ApiClient class. Just set apiUrl=ApiClient.API_URL_LIVE and you're good.
|
|
11
11
|
const apiClient = new ApiClient(ApiClient.API_URL_OTE, Language.EN, true);
|
|
12
12
|
|
|
13
13
|
const loginResponse = await apiClient.login(username, password, sharedSecret);
|
|
@@ -25,12 +25,14 @@ const asyncFunc = async () => {
|
|
|
25
25
|
|
|
26
26
|
// get the first domain in the result array 'domain'
|
|
27
27
|
const checkedDomain = domainCheckResponse.resData.domain[0];
|
|
28
|
-
if (checkedDomain.avail) {
|
|
28
|
+
if (checkedDomain.avail === 1) {
|
|
29
29
|
console.log(`${domain} is still available!`);
|
|
30
|
+
} else if (checkedDomain.avail === -1) {
|
|
31
|
+
console.log(`Availability of ${domain} could not be checked.`);
|
|
30
32
|
} else {
|
|
31
33
|
console.log(`Unfortunately, ${domain} is already registered.`);
|
|
32
34
|
}
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
// call the async function
|
|
36
|
-
asyncFunc();
|
|
38
|
+
asyncFunc().catch(console.error);
|