domrobot-client 3.2.2 → 3.3.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/README.md CHANGED
@@ -1,23 +1,22 @@
1
1
  <p align="center">
2
- <a href="https://www.inwx.com/en/" target="_blank">
3
- <img src="https://images.inwx.com/logos/inwx.png">
2
+ <a href="https://www.inwx.de/en" target="_blank">
3
+ <img src="https://images.inwx.com/logos/inwx_nl.png">
4
4
  </a>
5
5
  </p>
6
6
 
7
- INWX Domrobot Node.js Client
8
- =========
7
+ # INWX Domrobot Node.js Client
8
+
9
9
  You can access all functions of our frontend via our API, which is available via the JSON-RPC protocol and thus can be easily consumed with all programming languages.
10
10
 
11
11
  There is also an OT&E test system, which you can access via [ote.inwx.com](https://ote.inwx.com/en/). Here you will find the known web interface which is using a test database. On the OT&E system no actions will be charged. So you can test as much as you like there.
12
12
 
13
- Documentation
14
- ------
13
+ ## Documentation
14
+
15
15
  You can view a detailed description of the API functions in our documentation. You can find the online documentation [by clicking here](https://www.inwx.de/en/help/apidoc).
16
16
 
17
17
  If you still experience any kind of problems don't hesitate to contact our [support via email](mailto:support@inwx.de).
18
18
 
19
- Installation
20
- -------
19
+ ## Installation
21
20
 
22
21
  The recommended way is via npm:
23
22
 
@@ -27,8 +26,9 @@ npm install --save domrobot-client
27
26
 
28
27
  You can find more information about the package on [npmjs.org](https://www.npmjs.com/package/domrobot-client).
29
28
 
30
- Example
31
- -------
29
+ ## Example
30
+
31
+ The third argument of the `ApiClient` constructor turns on debug mode, which prints each request and response with `console.info`; this output can contain sensitive data.
32
32
 
33
33
  ```typescript
34
34
  import { ApiClient, Language } from 'domrobot-client';
@@ -39,7 +39,7 @@ 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 your ApiClient uses the test api (OT&E). If you want to use the production/live api
42
+ // By default, your ApiClient uses the test api (OT&E). If you want to use the production/live api
43
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
 
@@ -68,10 +68,9 @@ const asyncFunc = async () => {
68
68
  };
69
69
 
70
70
  // call the async function
71
- asyncFunc();
71
+ asyncFunc().catch(console.error);
72
72
  ```
73
73
 
74
- License
75
- ----
74
+ ## License
76
75
 
77
76
  MIT
package/lib/domrobot.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare class ApiClient {
2
- static readonly CLIENT_VERSION = "3.0.2";
2
+ static readonly CLIENT_VERSION = "3.3.1";
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;
@@ -7,21 +7,26 @@ export declare class ApiClient {
7
7
  private language;
8
8
  private debugMode;
9
9
  private cookie;
10
+ private headers;
10
11
  /**
11
12
  * @param apiUrl url of the API.
12
13
  * @param language default language for future API requests.
13
14
  * @param debugMode whether requests and responses should be printed out.
15
+ * @param headers Optional HTTP headers to be included in all API requests.
14
16
  */
15
- constructor(apiUrl?: string, language?: string, debugMode?: boolean);
17
+ constructor(apiUrl?: string, language?: string, debugMode?: boolean, headers?: Record<string, any>);
16
18
  /**
17
19
  * Makes an API call.
18
20
  *
19
21
  * @param apiMethod The name of the method called in the API.
20
22
  * @param methodParams An object of parameters added to the request.
21
- * @param clientTransactionId Id sent with every request to distinguish your api requests in case you need support.
22
- * @param language Language for the API request. Default is value of field language.
23
- * @param cacheOption HTTP cache options
24
- * @param nextjsOptions Next.js options
23
+ * @param clientTransactionId Id to distinguish your api requests in case you need support. It is sent only if
24
+ * methodParams already has the key `clTRID`, and it then replaces that value.
25
+ * @param language Language for the API request. Default is value of field language. It is sent only if
26
+ * methodParams already has the key `lang`, and it then replaces that value.
27
+ * @param cacheOption HTTP cache option of fetch. `only-if-cached` needs `mode: 'same-origin'`.
28
+ * @param nextjsOptions Next.js options, spread over the fetch options. Each key replaces the value of the client.
29
+ * A `headers` key replaces all default headers.
25
30
  */
26
31
  callApi(apiMethod: string, methodParams?: any, clientTransactionId?: string, language?: string, cacheOption?: 'no-store' | 'reload' | 'no-cache' | 'force-cache' | 'only-if-cached' | 'default', nextjsOptions?: object): Promise<any>;
27
32
  /**
@@ -43,6 +48,8 @@ export declare class ApiClient {
43
48
  setDebugMode(value: boolean): void;
44
49
  getCookie(): string;
45
50
  setCookie(cookie: string): void;
51
+ setHeaders(headers: Record<string, any>): void;
52
+ getHeaders(): Record<string, any>;
46
53
  }
47
54
  /**
48
55
  * The API response-message language.
package/lib/domrobot.js CHANGED
@@ -19,25 +19,31 @@ class ApiClient {
19
19
  * @param apiUrl url of the API.
20
20
  * @param language default language for future API requests.
21
21
  * @param debugMode whether requests and responses should be printed out.
22
+ * @param headers Optional HTTP headers to be included in all API requests.
22
23
  */
23
- constructor(apiUrl = ApiClient.API_URL_OTE, language = Language.EN, debugMode = false) {
24
+ constructor(apiUrl = ApiClient.API_URL_OTE, language = Language.EN, debugMode = false, headers = {}) {
24
25
  this.apiUrl = apiUrl;
25
26
  this.language = language;
26
27
  this.debugMode = debugMode;
27
28
  this.cookie = null;
29
+ this.headers = headers;
28
30
  }
29
31
  /**
30
32
  * Makes an API call.
31
33
  *
32
34
  * @param apiMethod The name of the method called in the API.
33
35
  * @param methodParams An object of parameters added to the request.
34
- * @param clientTransactionId Id sent with every request to distinguish your api requests in case you need support.
35
- * @param language Language for the API request. Default is value of field language.
36
- * @param cacheOption HTTP cache options
37
- * @param nextjsOptions Next.js options
36
+ * @param clientTransactionId Id to distinguish your api requests in case you need support. It is sent only if
37
+ * methodParams already has the key `clTRID`, and it then replaces that value.
38
+ * @param language Language for the API request. Default is value of field language. It is sent only if
39
+ * methodParams already has the key `lang`, and it then replaces that value.
40
+ * @param cacheOption HTTP cache option of fetch. `only-if-cached` needs `mode: 'same-origin'`.
41
+ * @param nextjsOptions Next.js options, spread over the fetch options. Each key replaces the value of the client.
42
+ * A `headers` key replaces all default headers.
38
43
  */
39
44
  callApi(apiMethod_1) {
40
45
  return __awaiter(this, arguments, void 0, function* (apiMethod, methodParams = {}, clientTransactionId = ApiClient.generateClientTransactionId(), language = this.language, cacheOption, nextjsOptions) {
46
+ var _a;
41
47
  if ('clTRID' in methodParams && clientTransactionId !== null) {
42
48
  methodParams.clTRID = clientTransactionId;
43
49
  }
@@ -50,11 +56,7 @@ class ApiClient {
50
56
  });
51
57
  let fetchOption = {
52
58
  method: 'POST',
53
- headers: new Headers({
54
- 'Content-Type': 'application/json',
55
- Cookie: this.cookie,
56
- 'User-Agent': `DomRobot/${ApiClient.CLIENT_VERSION} (Node ${process.version})`,
57
- }),
59
+ headers: new Headers(Object.assign(Object.assign(Object.assign({ 'Content-Type': 'application/json' }, (this.cookie != null ? { Cookie: this.cookie } : {})), { 'User-Agent': `DomRobot/${ApiClient.CLIENT_VERSION} (Node ${process.version})` }), ((_a = this.headers) !== null && _a !== void 0 ? _a : {}))),
58
60
  body: requestBody,
59
61
  cache: cacheOption !== null && cacheOption !== void 0 ? cacheOption : 'default',
60
62
  };
@@ -65,9 +67,16 @@ class ApiClient {
65
67
  if (apiMethod === 'account.login') {
66
68
  this.cookie = response.headers.get('set-cookie');
67
69
  }
68
- const data = yield response.json();
70
+ const data = yield response.json().catch((error) => {
71
+ if (error instanceof SyntaxError) {
72
+ // The ES6 lib of the compiler has no constructor with options.
73
+ throw Object.assign(new SyntaxError(`Response of ${apiMethod} is not JSON (HTTP ${response.status} ${response.statusText})`), { cause: error });
74
+ }
75
+ throw error;
76
+ });
69
77
  if (this.debugMode) {
70
- console.info(`Request (${apiMethod}): ${requestBody}`);
78
+ const printedRequest = JSON.stringify({ method: apiMethod, params: methodParams }, (key, value) => key === 'pass' || key === 'tan' ? '***' : value);
79
+ console.info(`Request (${apiMethod}): ${printedRequest}`);
71
80
  console.info(`Response (${apiMethod}): ${JSON.stringify(data)}`);
72
81
  }
73
82
  return data;
@@ -125,9 +134,15 @@ class ApiClient {
125
134
  setCookie(cookie) {
126
135
  this.cookie = cookie;
127
136
  }
137
+ setHeaders(headers) {
138
+ this.headers = headers;
139
+ }
140
+ getHeaders() {
141
+ return this.headers;
142
+ }
128
143
  }
129
144
  exports.ApiClient = ApiClient;
130
- ApiClient.CLIENT_VERSION = '3.0.2';
145
+ ApiClient.CLIENT_VERSION = '3.3.1';
131
146
  ApiClient.API_URL_LIVE = 'https://api.domrobot.com/jsonrpc/';
132
147
  ApiClient.API_URL_OTE = 'https://api.ote.domrobot.com/jsonrpc/';
133
148
  /**
@@ -1 +1 @@
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;;;;;;;;;OASG;IACU,OAAO;6DAChB,SAAiB,EACjB,eAAoB,EAAE,EACtB,sBAA8B,SAAS,CAAC,2BAA2B,EAAE,EACrE,WAAmB,IAAI,CAAC,QAAQ,EAChC,WAA+F,EAC/F,aAAsB;YAEtB,IAAI,QAAS,IAAI,YAAY,IAAI,mBAAmB,KAAK,IAAI,EAAE,CAAC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,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAEM,UAAU;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;;AAlLL,8BAmLC;AAlL0B,wBAAc,GAAG,OAAO,CAAC;AAEzB,sBAAY,GAAG,mCAAmC,CAAC;AACnD,qBAAW,GAAG,uCAAuC,CAAC;AAiLjF;;GAEG;AACH,IAAY,QAIX;AAJD,WAAY,QAAQ;IAChB,qBAAS,CAAA;IACT,qBAAS,CAAA;IACT,qBAAS,CAAA;AACb,CAAC,EAJW,QAAQ,wBAAR,QAAQ,QAInB"}
package/package.json CHANGED
@@ -1,45 +1,49 @@
1
1
  {
2
- "name": "domrobot-client",
3
- "version": "3.2.2",
4
- "description": "INWX Domrobot Node.JS Client",
5
- "author": "INWX Developer <developer@inwx.de> (https://inwx.com)",
6
- "main": "lib/index.js",
7
- "types": "lib/index.d.ts",
8
- "repository": {
9
- "type": "git",
10
- "url": "git+https://github.com/inwx/nodejs-client.git"
11
- },
12
- "keywords": [
13
- "INWX",
14
- "API",
15
- "INWX-API",
16
- "Domrobot",
17
- "Client",
18
- "Domrobot-Client",
19
- "Node",
20
- "NodeJS"
21
- ],
22
- "scripts": {
23
- "build": "tsc",
24
- "format": "prettier --write \"src/**/*.ts\"",
25
- "format:check": "prettier --check \"src/**/*.ts\"",
26
- "lint": "eslint \"src/**/*.ts\"",
27
- "prepare": "npm run build"
28
- },
29
- "dependencies": {
30
- "otplib": "^12.0.1"
31
- },
32
- "devDependencies": {
33
- "@types/node": "^22.2.0",
34
- "@types/otplib": "^7.0.0",
35
- "@typescript-eslint/eslint-plugin": "^8.1.0",
36
- "browserify": "^17.0.0",
37
- "eslint": "^8.44.0",
38
- "eslint-config-prettier": "^8.8.0",
39
- "prettier": "^3.3.3",
40
- "typescript": "^5.5.4"
41
- },
42
- "engines": {
43
- "node": ">=18"
44
- }
2
+ "name": "domrobot-client",
3
+ "version": "3.3.1",
4
+ "description": "INWX Domrobot Node.JS Client",
5
+ "author": "INWX Developer <developer@inwx.de> (https://inwx.com)",
6
+ "main": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "files": [
9
+ "lib",
10
+ "src"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/inwx/nodejs-client.git"
15
+ },
16
+ "keywords": [
17
+ "INWX",
18
+ "API",
19
+ "INWX-API",
20
+ "Domrobot",
21
+ "Client",
22
+ "Domrobot-Client",
23
+ "Node",
24
+ "NodeJS"
25
+ ],
26
+ "scripts": {
27
+ "build": "tsc",
28
+ "format": "prettier --write \"src/**/*.ts\"",
29
+ "format:check": "prettier --check \"src/**/*.ts\"",
30
+ "lint": "eslint \"src/**/*.ts\"",
31
+ "prepare": "npm run build",
32
+ "pretest": "npm run build",
33
+ "test": "node --test"
34
+ },
35
+ "dependencies": {
36
+ "otplib": "^12.0.1"
37
+ },
38
+ "devDependencies": {
39
+ "@eslint/js": "^10.0.1",
40
+ "@types/node": "^22.2.0",
41
+ "eslint": "^10.12.0",
42
+ "prettier": "^3.3.3",
43
+ "typescript": "^5.5.4",
44
+ "typescript-eslint": "^8.71.0"
45
+ },
46
+ "engines": {
47
+ "node": ">=18"
48
+ }
45
49
  }
package/src/domrobot.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as otplib from 'otplib';
2
2
 
3
3
  export class ApiClient {
4
- public static readonly CLIENT_VERSION = '3.0.2';
4
+ public static readonly CLIENT_VERSION = '3.3.1';
5
5
 
6
6
  public static readonly API_URL_LIVE = 'https://api.domrobot.com/jsonrpc/';
7
7
  public static readonly API_URL_OTE = 'https://api.ote.domrobot.com/jsonrpc/';
@@ -15,17 +15,25 @@ export class ApiClient {
15
15
  private debugMode: boolean;
16
16
 
17
17
  private cookie: string;
18
+ private headers: Record<string, any>;
18
19
 
19
20
  /**
20
21
  * @param apiUrl url of the API.
21
22
  * @param language default language for future API requests.
22
23
  * @param debugMode whether requests and responses should be printed out.
24
+ * @param headers Optional HTTP headers to be included in all API requests.
23
25
  */
24
- constructor(apiUrl: string = ApiClient.API_URL_OTE, language: string = Language.EN, debugMode: boolean = false) {
26
+ constructor(
27
+ apiUrl: string = ApiClient.API_URL_OTE,
28
+ language: string = Language.EN,
29
+ debugMode: boolean = false,
30
+ headers: Record<string, any> = {},
31
+ ) {
25
32
  this.apiUrl = apiUrl;
26
33
  this.language = language;
27
34
  this.debugMode = debugMode;
28
35
  this.cookie = null;
36
+ this.headers = headers;
29
37
  }
30
38
 
31
39
  /**
@@ -33,10 +41,13 @@ export class ApiClient {
33
41
  *
34
42
  * @param apiMethod The name of the method called in the API.
35
43
  * @param methodParams An object of parameters added to the request.
36
- * @param clientTransactionId Id sent with every request to distinguish your api requests in case you need support.
37
- * @param language Language for the API request. Default is value of field language.
38
- * @param cacheOption HTTP cache options
39
- * @param nextjsOptions Next.js options
44
+ * @param clientTransactionId Id to distinguish your api requests in case you need support. It is sent only if
45
+ * methodParams already has the key `clTRID`, and it then replaces that value.
46
+ * @param language Language for the API request. Default is value of field language. It is sent only if
47
+ * methodParams already has the key `lang`, and it then replaces that value.
48
+ * @param cacheOption HTTP cache option of fetch. `only-if-cached` needs `mode: 'same-origin'`.
49
+ * @param nextjsOptions Next.js options, spread over the fetch options. Each key replaces the value of the client.
50
+ * A `headers` key replaces all default headers.
40
51
  */
41
52
  public async callApi(
42
53
  apiMethod: string,
@@ -62,8 +73,9 @@ export class ApiClient {
62
73
  method: 'POST',
63
74
  headers: new Headers({
64
75
  'Content-Type': 'application/json',
65
- Cookie: this.cookie,
76
+ ...(this.cookie != null ? { Cookie: this.cookie } : {}),
66
77
  'User-Agent': `DomRobot/${ApiClient.CLIENT_VERSION} (Node ${process.version})`,
78
+ ...(this.headers ?? {}),
67
79
  }),
68
80
  body: requestBody,
69
81
  cache: cacheOption ?? 'default',
@@ -79,9 +91,23 @@ export class ApiClient {
79
91
  this.cookie = response.headers.get('set-cookie');
80
92
  }
81
93
 
82
- const data = await response.json();
94
+ const data = await response.json().catch((error) => {
95
+ if (error instanceof SyntaxError) {
96
+ // The ES6 lib of the compiler has no constructor with options.
97
+ throw Object.assign(
98
+ new SyntaxError(
99
+ `Response of ${apiMethod} is not JSON (HTTP ${response.status} ${response.statusText})`,
100
+ ),
101
+ { cause: error },
102
+ );
103
+ }
104
+ throw error;
105
+ });
83
106
  if (this.debugMode) {
84
- console.info(`Request (${apiMethod}): ${requestBody}`);
107
+ const printedRequest = JSON.stringify({ method: apiMethod, params: methodParams }, (key, value) =>
108
+ key === 'pass' || key === 'tan' ? '***' : value,
109
+ );
110
+ console.info(`Request (${apiMethod}): ${printedRequest}`);
85
111
  console.info(`Response (${apiMethod}): ${JSON.stringify(data)}`);
86
112
  }
87
113
 
@@ -145,6 +171,14 @@ export class ApiClient {
145
171
  public setCookie(cookie: string) {
146
172
  this.cookie = cookie;
147
173
  }
174
+
175
+ public setHeaders(headers: Record<string, any>) {
176
+ this.headers = headers;
177
+ }
178
+
179
+ public getHeaders(): Record<string, any> {
180
+ return this.headers;
181
+ }
148
182
  }
149
183
 
150
184
  /**
package/.eslintrc DELETED
@@ -1,22 +0,0 @@
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
- }
@@ -1,20 +0,0 @@
1
- name: format-lint.yaml
2
-
3
- on:
4
- pull_request:
5
- branches:
6
- - master
7
-
8
- jobs:
9
- format:
10
- runs-on: ubuntu-latest
11
- steps:
12
- - uses: actions/checkout@v4
13
- - uses: actions/setup-node@v4
14
- with:
15
- node-version: '20'
16
- - run: npm ci
17
- - name: Prettier check
18
- run: npm run format:check
19
- - name: Lint the code
20
- run: npm run lint
@@ -1,22 +0,0 @@
1
- name: Publish Package to npmjs
2
-
3
- on:
4
- release:
5
- types: [published]
6
-
7
- jobs:
8
- build:
9
- runs-on: ubuntu-latest
10
- permissions:
11
- contents: read
12
- id-token: write
13
- steps:
14
- - uses: actions/checkout@v4
15
- - uses: actions/setup-node@v4
16
- with:
17
- node-version: '20.x'
18
- registry-url: 'https://registry.npmjs.org'
19
- - run: npm ci
20
- - run: npm publish --provenance --access public
21
- env:
22
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/.prettierrc DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "printWidth": 120,
3
- "trailingComma": "all",
4
- "singleQuote": true,
5
- "tabWidth": 4
6
- }
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "none",
4
- "target": "es6",
5
- "moduleResolution": "node",
6
- "sourceMap": true,
7
- "allowSyntheticDefaultImports": true,
8
- "declaration": true,
9
- "outDir": "./lib"
10
- },
11
- "include": ["src"],
12
- "exclude": [
13
- "node_modules",
14
- "examples"
15
- ]
16
- }