domrobot-client 3.1.1 → 3.2.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/lib/domrobot.d.ts +4 -1
- package/lib/domrobot.js +13 -3
- package/lib/domrobot.js.map +1 -1
- package/package.json +1 -1
- package/src/domrobot.ts +17 -2
package/lib/domrobot.d.ts
CHANGED
|
@@ -20,8 +20,10 @@ export declare class ApiClient {
|
|
|
20
20
|
* @param methodParams An object of parameters added to the request.
|
|
21
21
|
* @param clientTransactionId Id sent with every request to distinguish your api requests in case you need support.
|
|
22
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
25
|
*/
|
|
24
|
-
callApi(apiMethod: string, methodParams?: any, clientTransactionId?: string, language?: string): Promise<any>;
|
|
26
|
+
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>;
|
|
25
27
|
/**
|
|
26
28
|
* Performs a login at the API and saves the session for following API calls.
|
|
27
29
|
*
|
|
@@ -39,6 +41,7 @@ export declare class ApiClient {
|
|
|
39
41
|
setLanguage(value: string): void;
|
|
40
42
|
isDebugMode(): boolean;
|
|
41
43
|
setDebugMode(value: boolean): void;
|
|
44
|
+
getCookie(): string;
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
44
47
|
* The API response-message language.
|
package/lib/domrobot.js
CHANGED
|
@@ -33,8 +33,10 @@ class ApiClient {
|
|
|
33
33
|
* @param methodParams An object of parameters added to the request.
|
|
34
34
|
* @param clientTransactionId Id sent with every request to distinguish your api requests in case you need support.
|
|
35
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
38
|
*/
|
|
37
|
-
callApi(apiMethod, methodParams = {}, clientTransactionId = ApiClient.generateClientTransactionId(), language = this.language) {
|
|
39
|
+
callApi(apiMethod, methodParams = {}, clientTransactionId = ApiClient.generateClientTransactionId(), language = this.language, cacheOption, nextjsOptions) {
|
|
38
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
41
|
if ('clTRID' in methodParams && clientTransactionId !== null) {
|
|
40
42
|
methodParams.clTRID = clientTransactionId;
|
|
@@ -46,7 +48,7 @@ class ApiClient {
|
|
|
46
48
|
method: apiMethod,
|
|
47
49
|
params: methodParams,
|
|
48
50
|
});
|
|
49
|
-
|
|
51
|
+
let fetchOption = {
|
|
50
52
|
method: 'POST',
|
|
51
53
|
headers: new Headers({
|
|
52
54
|
'Content-Type': 'application/json',
|
|
@@ -54,7 +56,12 @@ class ApiClient {
|
|
|
54
56
|
'User-Agent': `DomRobot/${ApiClient.CLIENT_VERSION} (Node ${process.version})`,
|
|
55
57
|
}),
|
|
56
58
|
body: requestBody,
|
|
57
|
-
|
|
59
|
+
cache: cacheOption !== null && cacheOption !== void 0 ? cacheOption : "default",
|
|
60
|
+
};
|
|
61
|
+
if (nextjsOptions !== undefined) {
|
|
62
|
+
fetchOption = Object.assign(Object.assign({}, fetchOption), nextjsOptions);
|
|
63
|
+
}
|
|
64
|
+
const response = yield fetch(this.apiUrl, fetchOption);
|
|
58
65
|
if (apiMethod === 'account.login') {
|
|
59
66
|
this.cookie = response.headers.get('set-cookie');
|
|
60
67
|
}
|
|
@@ -112,6 +119,9 @@ class ApiClient {
|
|
|
112
119
|
setDebugMode(value) {
|
|
113
120
|
this.debugMode = value;
|
|
114
121
|
}
|
|
122
|
+
getCookie() {
|
|
123
|
+
return this.cookie;
|
|
124
|
+
}
|
|
115
125
|
}
|
|
116
126
|
exports.ApiClient = ApiClient;
|
|
117
127
|
ApiClient.CLIENT_VERSION = '3.0.2';
|
package/lib/domrobot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domrobot.js","sourceRoot":"","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,SAAS,CAAC;IAC1B,CAAC;IAEM,YAAY,CAAC,KAAc;QAC9B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IAC3B,CAAC;IAEM,SAAS;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;;AA5IL,8BA6IC;AA5I0B,wBAAc,GAAG,OAAO,CAAC;AAEzB,sBAAY,GAAG,mCAAmC,CAAC;AACnD,qBAAW,GAAG,uCAAuC,CAAC;AA2IjF;;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
package/src/domrobot.ts
CHANGED
|
@@ -35,12 +35,16 @@ export class ApiClient {
|
|
|
35
35
|
* @param methodParams An object of parameters added to the request.
|
|
36
36
|
* @param clientTransactionId Id sent with every request to distinguish your api requests in case you need support.
|
|
37
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
|
|
38
40
|
*/
|
|
39
41
|
public async callApi(
|
|
40
42
|
apiMethod: string,
|
|
41
43
|
methodParams: any = {},
|
|
42
44
|
clientTransactionId: string = ApiClient.generateClientTransactionId(),
|
|
43
45
|
language: string = this.language,
|
|
46
|
+
cacheOption?: "no-store" | "reload" | "no-cache" | "force-cache" | "only-if-cached" | "default",
|
|
47
|
+
nextjsOptions?: object
|
|
44
48
|
): Promise<any> {
|
|
45
49
|
if ('clTRID'! in methodParams && clientTransactionId !== null) {
|
|
46
50
|
methodParams.clTRID = clientTransactionId;
|
|
@@ -54,7 +58,7 @@ export class ApiClient {
|
|
|
54
58
|
params: methodParams,
|
|
55
59
|
});
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
let fetchOption = {
|
|
58
62
|
method: 'POST',
|
|
59
63
|
headers: new Headers({
|
|
60
64
|
'Content-Type': 'application/json',
|
|
@@ -62,7 +66,14 @@ export class ApiClient {
|
|
|
62
66
|
'User-Agent': `DomRobot/${ApiClient.CLIENT_VERSION} (Node ${process.version})`,
|
|
63
67
|
}),
|
|
64
68
|
body: requestBody,
|
|
65
|
-
|
|
69
|
+
cache: cacheOption ?? "default",
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
if (nextjsOptions !== undefined) {
|
|
73
|
+
fetchOption = {...fetchOption, ...nextjsOptions};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const response = await fetch(this.apiUrl, fetchOption);
|
|
66
77
|
|
|
67
78
|
if (apiMethod === 'account.login') {
|
|
68
79
|
this.cookie = response.headers.get('set-cookie');
|
|
@@ -126,6 +137,10 @@ export class ApiClient {
|
|
|
126
137
|
public setDebugMode(value: boolean) {
|
|
127
138
|
this.debugMode = value;
|
|
128
139
|
}
|
|
140
|
+
|
|
141
|
+
public getCookie(): string {
|
|
142
|
+
return this.cookie;
|
|
143
|
+
}
|
|
129
144
|
}
|
|
130
145
|
|
|
131
146
|
/**
|