@sisense/sdk-rest-client 1.13.0 → 1.14.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.
@@ -11,8 +11,8 @@ export declare class HttpClient {
11
11
  readonly env: string;
12
12
  constructor(url: string, auth: Authenticator, env: string);
13
13
  login(): Promise<boolean>;
14
- call<T = unknown>(url: string, config: RequestInit, requestConfig?: HttpClientRequestConfig): Promise<T>;
15
- post<T = unknown>(endpoint: string, data: unknown, options?: RequestInit, abortSignal?: AbortSignal, config?: HttpClientRequestConfig): Promise<T>;
16
- get<T = unknown>(endpoint: string, request?: RequestInit, config?: HttpClientRequestConfig): Promise<T>;
17
- delete<T = void>(endpoint: string, request?: RequestInit, config?: HttpClientRequestConfig): Promise<T>;
14
+ call<T>(url: string, config: RequestInit, requestConfig?: HttpClientRequestConfig): Promise<T | undefined>;
15
+ post<T = unknown>(endpoint: string, data: unknown, options?: RequestInit, abortSignal?: AbortSignal, config?: HttpClientRequestConfig): Promise<T | undefined>;
16
+ get<T = unknown>(endpoint: string, request?: RequestInit, config?: HttpClientRequestConfig): Promise<T | undefined>;
17
+ delete<T = void>(endpoint: string, request?: RequestInit, config?: HttpClientRequestConfig): Promise<T | undefined>;
18
18
  }
@@ -11,6 +11,7 @@ import fetchIntercept from 'fetch-intercept';
11
11
  import { getResponseInterceptor, errorInterceptor } from './interceptors.js';
12
12
  import { SsoAuthenticator } from './sso-authenticator.js';
13
13
  import { addQueryParamsToUrl } from './helpers.js';
14
+ const AUTH_WAIT_MS = 10;
14
15
  export class HttpClient {
15
16
  constructor(url, auth, env) {
16
17
  if (!url.endsWith('/')) {
@@ -36,7 +37,7 @@ export class HttpClient {
36
37
  const retry = () => {
37
38
  // wait if still authenticating
38
39
  if (this.auth.isAuthenticating()) {
39
- setTimeout(retry, 10);
40
+ setTimeout(retry, AUTH_WAIT_MS);
40
41
  return;
41
42
  }
42
43
  void this.call(url, config, requestConfig).then((r) => res(r));
@@ -50,51 +51,41 @@ export class HttpClient {
50
51
  config.credentials = 'include';
51
52
  }
52
53
  this.auth.applyHeader(config.headers);
53
- // used for API usage tracking
54
- const trackedUrl = addQueryParamsToUrl(url, {
55
- trc: this.env,
56
- });
57
- const response = yield fetch((requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.skipTrackingParam) ? url : trackedUrl, config);
54
+ const fetchUrl = (requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.skipTrackingParam)
55
+ ? url
56
+ : addQueryParamsToUrl(url, {
57
+ trc: this.env,
58
+ });
59
+ const response = yield fetch(fetchUrl, config);
58
60
  if (response.status === 204 || // No content
59
61
  response.status === 304 // Not modified
60
62
  ) {
61
- return undefined;
62
- }
63
- try {
64
- return ((requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.returnBlob) ? yield response.blob() : yield response.json());
65
- }
66
- catch (e) {
67
- // some of APIs in Sisense returns 200 with empty body - so it's not possible
68
- // to understand definitely is it empty or not until you will try to parse it
69
- if (e instanceof Error && e.message.includes('Unexpected end of JSON input')) {
70
- return undefined;
71
- }
72
- else {
73
- throw e;
74
- }
63
+ return;
75
64
  }
65
+ return ((requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.returnBlob)
66
+ ? response.blob()
67
+ : response.json().catch((e) => {
68
+ var _a, _b;
69
+ // some of APIs in Sisense returns 200 with empty body - so it's not possible
70
+ // to understand definitely is it empty or not until you will try to parse it
71
+ if (!((_b = (_a = e === null || e === void 0 ? void 0 : e.message) === null || _a === void 0 ? void 0 : _a.includes) === null || _b === void 0 ? void 0 : _b.call(_a, 'Unexpected end of JSON input'))) {
72
+ throw e;
73
+ }
74
+ }));
76
75
  });
77
76
  }
78
77
  // eslint-disable-next-line max-params
79
78
  post(endpoint, data, options = {}, abortSignal, config) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- const request = Object.assign({ method: 'POST', body: ((config === null || config === void 0 ? void 0 : config.nonJSONBody) ? data : JSON.stringify(data)), headers: {
82
- Accept: 'application/json, text/plain, */*',
83
- 'Content-Type': 'application/json;charset=UTF-8',
84
- }, signal: abortSignal }, options);
85
- return this.call(this.url + endpoint, request, config);
86
- });
79
+ const request = Object.assign({ method: 'POST', body: ((config === null || config === void 0 ? void 0 : config.nonJSONBody) ? data : JSON.stringify(data)), headers: {
80
+ Accept: 'application/json, text/plain, */*',
81
+ 'Content-Type': 'application/json;charset=UTF-8',
82
+ }, signal: abortSignal }, options);
83
+ return this.call(this.url + endpoint, request, config);
87
84
  }
88
85
  get(endpoint, request = {}, config) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- request.method = 'GET';
91
- return this.call(this.url + endpoint, request, config);
92
- });
86
+ return this.call(this.url + endpoint, Object.assign(Object.assign({}, request), { method: 'GET' }), config);
93
87
  }
94
88
  delete(endpoint, request = {}, config) {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- request.method = 'DELETE';
97
- return this.call(this.url + endpoint, request, config);
98
- });
89
+ return this.call(this.url + endpoint, Object.assign(Object.assign({}, request), { method: 'DELETE' }), config);
99
90
  }
100
91
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "Sisense",
12
12
  "Compose SDK"
13
13
  ],
14
- "version": "1.13.0",
14
+ "version": "1.14.0",
15
15
  "type": "module",
16
16
  "exports": "./dist/index.js",
17
17
  "main": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  "author": "Sisense",
21
21
  "license": "SEE LICENSE IN LICENSE.md",
22
22
  "dependencies": {
23
- "@sisense/sdk-common": "^1.13.0",
23
+ "@sisense/sdk-common": "^1.14.0",
24
24
  "fetch-intercept": "^2.4.0"
25
25
  },
26
26
  "scripts": {