@sisense/sdk-rest-client 0.11.3 → 0.12.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/dist/http-client.d.ts +4 -4
- package/dist/http-client.js +21 -5
- package/dist/sso-authenticator.js +1 -1
- package/package.json +1 -1
package/dist/http-client.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ export declare class HttpClient {
|
|
|
6
6
|
readonly env: string;
|
|
7
7
|
constructor(url: string, auth: Authenticator, env: string);
|
|
8
8
|
login(): Promise<boolean>;
|
|
9
|
-
call(url: string, config: RequestInit): Promise<
|
|
10
|
-
post<T>(endpoint: string, data: unknown, options?: RequestInit, abortSignal?: AbortSignal): Promise<T>;
|
|
11
|
-
get<T>(endpoint: string, request?: RequestInit): Promise<T>;
|
|
12
|
-
delete(endpoint: string, request?: RequestInit): Promise<
|
|
9
|
+
call<T = unknown>(url: string, config: RequestInit): Promise<T>;
|
|
10
|
+
post<T = unknown>(endpoint: string, data: unknown, options?: RequestInit, abortSignal?: AbortSignal): Promise<T>;
|
|
11
|
+
get<T = unknown>(endpoint: string, request?: RequestInit): Promise<T>;
|
|
12
|
+
delete<T = void>(endpoint: string, request?: RequestInit): Promise<T>;
|
|
13
13
|
}
|
package/dist/http-client.js
CHANGED
|
@@ -67,7 +67,25 @@ export class HttpClient {
|
|
|
67
67
|
const trackedUrl = addQueryParamsToUrl(url, {
|
|
68
68
|
trc: this.env,
|
|
69
69
|
});
|
|
70
|
-
|
|
70
|
+
const response = yield fetch(trackedUrl, config);
|
|
71
|
+
if (response.status === 204 || // No content
|
|
72
|
+
response.status === 304 // Not modified
|
|
73
|
+
) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
return (yield response.json());
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
// some of APIs in Sisense returns 200 with empty body - so it's not possible
|
|
81
|
+
// to understand definitely is it empty or not until you will try to parse it
|
|
82
|
+
if (e instanceof Error && e.message.includes('Unexpected end of JSON input')) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
throw e;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
71
89
|
});
|
|
72
90
|
}
|
|
73
91
|
// eslint-disable-next-line max-params
|
|
@@ -77,15 +95,13 @@ export class HttpClient {
|
|
|
77
95
|
Accept: 'application/json, text/plain, */*',
|
|
78
96
|
'Content-Type': 'application/json;charset=UTF-8',
|
|
79
97
|
}, signal: abortSignal }, options);
|
|
80
|
-
|
|
81
|
-
return res.json();
|
|
98
|
+
return this.call(this.url + endpoint, request);
|
|
82
99
|
});
|
|
83
100
|
}
|
|
84
101
|
get(endpoint, request = {}) {
|
|
85
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
103
|
request.method = 'GET';
|
|
87
|
-
|
|
88
|
-
return res.json();
|
|
104
|
+
return this.call(this.url + endpoint, request);
|
|
89
105
|
});
|
|
90
106
|
}
|
|
91
107
|
delete(endpoint, request = {}) {
|
|
@@ -29,7 +29,7 @@ export class SsoAuthenticator {
|
|
|
29
29
|
authenticate() {
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
31
|
this._authenticating = true;
|
|
32
|
-
const fetchUrl = `${this.url}
|
|
32
|
+
const fetchUrl = `${this.url}${!this.url.endsWith('/') ? '/' : ''}api/auth/isauth`;
|
|
33
33
|
return fetch(fetchUrl, {
|
|
34
34
|
headers: { Internal: 'true' },
|
|
35
35
|
credentials: 'include',
|