domrobot-client 3.3.0 → 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,6 +1,6 @@
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
 
@@ -28,6 +28,8 @@ You can find more information about the package on [npmjs.org](https://www.npmjs
28
28
 
29
29
  ## Example
30
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
+
31
33
  ```typescript
32
34
  import { ApiClient, Language } from 'domrobot-client';
33
35
 
@@ -37,7 +39,7 @@ const sharedSecret = ''; // only needed for 2FA.
37
39
  const domain = 'my-test-domain-' + Math.round(Math.random() * 1e8) + '.com'; // the domain which will be checked.
38
40
 
39
41
  const asyncFunc = async () => {
40
- // 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
41
43
  // we have a constant named API_URL_LIVE in the ApiClient class. Just set apiUrl=ApiClient.API_URL_LIVE and you're good.
42
44
  const apiClient = new ApiClient(ApiClient.API_URL_OTE, Language.EN, true);
43
45
 
@@ -66,7 +68,7 @@ const asyncFunc = async () => {
66
68
  };
67
69
 
68
70
  // call the async function
69
- asyncFunc();
71
+ asyncFunc().catch(console.error);
70
72
  ```
71
73
 
72
74
  ## License
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;
@@ -20,10 +20,13 @@ export declare class ApiClient {
20
20
  *
21
21
  * @param apiMethod The name of the method called in the API.
22
22
  * @param methodParams An object of parameters added to the request.
23
- * @param clientTransactionId Id sent with every request to distinguish your api requests in case you need support.
24
- * @param language Language for the API request. Default is value of field language.
25
- * @param cacheOption HTTP cache options
26
- * @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.
27
30
  */
28
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>;
29
32
  /**
package/lib/domrobot.js CHANGED
@@ -33,10 +33,13 @@ class ApiClient {
33
33
  *
34
34
  * @param apiMethod The name of the method called in the API.
35
35
  * @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
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.
40
43
  */
41
44
  callApi(apiMethod_1) {
42
45
  return __awaiter(this, arguments, void 0, function* (apiMethod, methodParams = {}, clientTransactionId = ApiClient.generateClientTransactionId(), language = this.language, cacheOption, nextjsOptions) {
@@ -53,7 +56,7 @@ class ApiClient {
53
56
  });
54
57
  let fetchOption = {
55
58
  method: 'POST',
56
- headers: new Headers(Object.assign({ 'Content-Type': 'application/json', Cookie: this.cookie, 'User-Agent': `DomRobot/${ApiClient.CLIENT_VERSION} (Node ${process.version})` }, ((_a = this.headers) !== null && _a !== void 0 ? _a : {}))),
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 : {}))),
57
60
  body: requestBody,
58
61
  cache: cacheOption !== null && cacheOption !== void 0 ? cacheOption : 'default',
59
62
  };
@@ -64,9 +67,16 @@ class ApiClient {
64
67
  if (apiMethod === 'account.login') {
65
68
  this.cookie = response.headers.get('set-cookie');
66
69
  }
67
- 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
+ });
68
77
  if (this.debugMode) {
69
- 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}`);
70
80
  console.info(`Response (${apiMethod}): ${JSON.stringify(data)}`);
71
81
  }
72
82
  return data;
@@ -132,7 +142,7 @@ class ApiClient {
132
142
  }
133
143
  }
134
144
  exports.ApiClient = ApiClient;
135
- ApiClient.CLIENT_VERSION = '3.0.2';
145
+ ApiClient.CLIENT_VERSION = '3.3.1';
136
146
  ApiClient.API_URL_LIVE = 'https://api.domrobot.com/jsonrpc/';
137
147
  ApiClient.API_URL_OTE = 'https://api.ote.domrobot.com/jsonrpc/';
138
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;IASD;;;;;OAKG;IACH,YACI,SAAiB,SAAS,CAAC,WAAW,EACtC,WAAmB,QAAQ,CAAC,EAAE,EAC9B,YAAqB,KAAK,EAC1B,UAA+B,EAAE;QAEjC,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;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,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;gBAC5D,YAAY,CAAC,MAAM,GAAG,mBAAmB,CAAC;YAC9C,CAAC;YACD,IAAI,MAAO,IAAI,YAAY,EAAE,CAAC;gBAC1B,YAAY,CAAC,IAAI,GAAG,QAAQ,CAAC;YACjC,CAAC;YAED,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC;gBAC/B,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE,YAAY;aACvB,CAAC,CAAC;Y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;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,10 +1,14 @@
1
1
  {
2
2
  "name": "domrobot-client",
3
- "version": "3.3.0",
3
+ "version": "3.3.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",
7
7
  "types": "lib/index.d.ts",
8
+ "files": [
9
+ "lib",
10
+ "src"
11
+ ],
8
12
  "repository": {
9
13
  "type": "git",
10
14
  "url": "git+https://github.com/inwx/nodejs-client.git"
@@ -24,20 +28,20 @@
24
28
  "format": "prettier --write \"src/**/*.ts\"",
25
29
  "format:check": "prettier --check \"src/**/*.ts\"",
26
30
  "lint": "eslint \"src/**/*.ts\"",
27
- "prepare": "npm run build"
31
+ "prepare": "npm run build",
32
+ "pretest": "npm run build",
33
+ "test": "node --test"
28
34
  },
29
35
  "dependencies": {
30
36
  "otplib": "^12.0.1"
31
37
  },
32
38
  "devDependencies": {
39
+ "@eslint/js": "^10.0.1",
33
40
  "@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",
41
+ "eslint": "^10.12.0",
39
42
  "prettier": "^3.3.3",
40
- "typescript": "^5.5.4"
43
+ "typescript": "^5.5.4",
44
+ "typescript-eslint": "^8.71.0"
41
45
  },
42
46
  "engines": {
43
47
  "node": ">=18"
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/';
@@ -41,10 +41,13 @@ export class ApiClient {
41
41
  *
42
42
  * @param apiMethod The name of the method called in the API.
43
43
  * @param methodParams An object of parameters added to the request.
44
- * @param clientTransactionId Id sent with every request to distinguish your api requests in case you need support.
45
- * @param language Language for the API request. Default is value of field language.
46
- * @param cacheOption HTTP cache options
47
- * @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.
48
51
  */
49
52
  public async callApi(
50
53
  apiMethod: string,
@@ -70,7 +73,7 @@ export class ApiClient {
70
73
  method: 'POST',
71
74
  headers: new Headers({
72
75
  'Content-Type': 'application/json',
73
- Cookie: this.cookie,
76
+ ...(this.cookie != null ? { Cookie: this.cookie } : {}),
74
77
  'User-Agent': `DomRobot/${ApiClient.CLIENT_VERSION} (Node ${process.version})`,
75
78
  ...(this.headers ?? {}),
76
79
  }),
@@ -88,9 +91,23 @@ export class ApiClient {
88
91
  this.cookie = response.headers.get('set-cookie');
89
92
  }
90
93
 
91
- 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
+ });
92
106
  if (this.debugMode) {
93
- 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}`);
94
111
  console.info(`Response (${apiMethod}): ${JSON.stringify(data)}`);
95
112
  }
96
113
 
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,13 +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": ["node_modules", "examples"]
13
- }