@kelvininc/web-client-sdk 7.13.2 → 7.21.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/CHANGELOG.md +105 -0
- package/README.md +35 -2
- package/dist/cjs/adapters/http/config.d.ts +1 -0
- package/dist/cjs/adapters/http/config.js +5 -0
- package/dist/cjs/adapters/http/config.js.map +1 -0
- package/dist/cjs/adapters/http/http-adapter.d.ts +9 -0
- package/dist/cjs/adapters/http/http-adapter.helper.d.ts +6 -0
- package/dist/cjs/adapters/http/http-adapter.helper.js +75 -0
- package/dist/cjs/adapters/http/http-adapter.helper.js.map +1 -0
- package/dist/cjs/adapters/http/http-adapter.js +54 -0
- package/dist/cjs/adapters/http/http-adapter.js.map +1 -0
- package/dist/cjs/adapters/http/index.d.ts +1 -0
- package/dist/cjs/adapters/http/index.js +5 -0
- package/dist/cjs/adapters/http/index.js.map +1 -0
- package/dist/cjs/adapters/http/types.d.ts +11 -0
- package/dist/cjs/adapters/http/types.js +3 -0
- package/dist/cjs/adapters/http/types.js.map +1 -0
- package/dist/cjs/classes/index.d.ts +1 -0
- package/dist/cjs/classes/index.js +5 -0
- package/dist/cjs/classes/index.js.map +1 -0
- package/dist/cjs/classes/request-abort-controller.d.ts +8 -0
- package/dist/cjs/classes/request-abort-controller.js +22 -0
- package/dist/cjs/classes/request-abort-controller.js.map +1 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/kelvin-web-sdk.js +3 -3
- package/dist/cjs/kelvin-web-sdk.js.map +1 -1
- package/dist/cjs/models.d.ts +1 -0
- package/dist/cjs/models.js +5 -0
- package/dist/cjs/models.js.map +1 -0
- package/dist/esm/adapters/http/config.d.ts +1 -0
- package/dist/esm/adapters/http/config.js +2 -0
- package/dist/esm/adapters/http/config.js.map +1 -0
- package/dist/esm/adapters/http/http-adapter.d.ts +9 -0
- package/dist/esm/adapters/http/http-adapter.helper.d.ts +6 -0
- package/dist/esm/adapters/http/http-adapter.helper.js +68 -0
- package/dist/esm/adapters/http/http-adapter.helper.js.map +1 -0
- package/dist/esm/adapters/http/http-adapter.js +50 -0
- package/dist/esm/adapters/http/http-adapter.js.map +1 -0
- package/dist/esm/adapters/http/index.d.ts +1 -0
- package/dist/esm/adapters/http/index.js +2 -0
- package/dist/esm/adapters/http/index.js.map +1 -0
- package/dist/esm/adapters/http/types.d.ts +11 -0
- package/dist/esm/adapters/http/types.js +2 -0
- package/dist/esm/adapters/http/types.js.map +1 -0
- package/dist/esm/classes/index.d.ts +1 -0
- package/dist/esm/classes/index.js +2 -0
- package/dist/esm/classes/index.js.map +1 -0
- package/dist/esm/classes/request-abort-controller.d.ts +8 -0
- package/dist/esm/classes/request-abort-controller.js +18 -0
- package/dist/esm/classes/request-abort-controller.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/kelvin-web-sdk.js +1 -1
- package/dist/esm/kelvin-web-sdk.js.map +1 -1
- package/dist/esm/models.d.ts +1 -0
- package/dist/esm/models.js +2 -0
- package/dist/esm/models.js.map +1 -0
- package/package.json +30 -8
- package/dist/cjs/adapters/http-adapter.d.ts +0 -10
- package/dist/cjs/adapters/http-adapter.js +0 -99
- package/dist/cjs/adapters/http-adapter.js.map +0 -1
- package/dist/esm/adapters/http-adapter.d.ts +0 -10
- package/dist/esm/adapters/http-adapter.js +0 -94
- package/dist/esm/adapters/http-adapter.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,111 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [7.21.0](https://bitbucket.org/kelvininc/kelvinjs/compare/v7.20.0...v7.21.0) (2023-09-26)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **model-exports:** export kelvin models in separate path [KMAPS-1195] ([ce04514](https://bitbucket.org/kelvininc/kelvinjs/commits/ce0451483f46bddd52067808ef4e82d5c7811822))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [7.20.0](https://bitbucket.org/kelvininc/kelvinjs/compare/v7.19.1...v7.20.0) (2023-09-01)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **kelvin-node-sdk:** adds support to native fetch [KMAPS-1193] ([42ab78d](https://bitbucket.org/kelvininc/kelvinjs/commits/42ab78d7ed9cda127fce0f9990c14026502f62d2))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## [7.19.1](https://bitbucket.org/kelvininc/kelvinjs/compare/v7.19.0...v7.19.1) (2023-08-01)
|
|
29
|
+
|
|
30
|
+
**Note:** Version bump only for package @kelvininc/web-client-sdk
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# [7.19.0](https://bitbucket.org/kelvininc/kelvinjs/compare/v7.18.0...v7.19.0) (2023-07-21)
|
|
37
|
+
|
|
38
|
+
**Note:** Version bump only for package @kelvininc/web-client-sdk
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# [7.18.0](https://bitbucket.org/kelvininc/kelvinjs/compare/v7.17.0...v7.18.0) (2023-07-04)
|
|
45
|
+
|
|
46
|
+
**Note:** Version bump only for package @kelvininc/web-client-sdk
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# [7.17.0](https://bitbucket.org/kelvininc/kelvinjs/compare/v7.16.0...v7.17.0) (2023-05-17)
|
|
53
|
+
|
|
54
|
+
**Note:** Version bump only for package @kelvininc/web-client-sdk
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# [7.16.0](https://bitbucket.org/kelvininc/kelvinjs/compare/v7.15.2...v7.16.0) (2023-04-04)
|
|
61
|
+
|
|
62
|
+
**Note:** Version bump only for package @kelvininc/web-client-sdk
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## [7.15.2](https://bitbucket.org/kelvininc/kelvinjs/compare/v7.15.1...v7.15.2) (2023-03-14)
|
|
69
|
+
|
|
70
|
+
**Note:** Version bump only for package @kelvininc/web-client-sdk
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## [7.15.1](https://bitbucket.org/kelvininc/kelvinjs/compare/v7.15.0...v7.15.1) (2023-03-06)
|
|
77
|
+
|
|
78
|
+
**Note:** Version bump only for package @kelvininc/web-client-sdk
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# [7.15.0](https://bitbucket.org/kelvininc/kelvinjs/compare/v7.14.1...v7.15.0) (2023-02-13)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Features
|
|
88
|
+
|
|
89
|
+
* **kelvin-web-sdk:** add controls to abort request manually or when stream closes [KMAPS-752] ([31f2cda](https://bitbucket.org/kelvininc/kelvinjs/commits/31f2cdac88d9a4097a89c7d85df17668375a71b4))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
## [7.14.1](https://bitbucket.org/kelvininc/kelvinjs/compare/v7.14.0...v7.14.1) (2023-01-25)
|
|
96
|
+
|
|
97
|
+
**Note:** Version bump only for package @kelvininc/web-client-sdk
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
# [7.14.0](https://bitbucket.org/kelvininc/kelvinjs/compare/v7.13.2...v7.14.0) (2023-01-09)
|
|
104
|
+
|
|
105
|
+
**Note:** Version bump only for package @kelvininc/web-client-sdk
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
6
111
|
## [7.13.2](https://bitbucket.org/kelvininc/kelvinjs/compare/v7.13.1...v7.13.2) (2022-11-24)
|
|
7
112
|
|
|
8
113
|
**Note:** Version bump only for package @kelvininc/web-client-sdk
|
package/README.md
CHANGED
|
@@ -6,8 +6,8 @@ Kelvin SDK Client provides a simple way to integrate our Authentication, Service
|
|
|
6
6
|
|
|
7
7
|
To run our SDK inside your project you need to support the following versions:
|
|
8
8
|
|
|
9
|
-
- Rxjs: 6.6.X
|
|
10
|
-
- Axios:
|
|
9
|
+
- Rxjs: ~6.6.X
|
|
10
|
+
- Axios: >=1.0.0
|
|
11
11
|
- Optionally, keycloak-js to handle the authentication
|
|
12
12
|
|
|
13
13
|
## Installation
|
|
@@ -71,6 +71,39 @@ ACPService.listACP({ pageSize: 20 }).toPromise()
|
|
|
71
71
|
.then(acpList => doSomething(acpList));
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Abort Requests
|
|
77
|
+
|
|
78
|
+
This library uses axios as HTTP Client to communicate with the server-side. Since we encapsulate the request into an observable, we have two options to abort a request:
|
|
79
|
+
|
|
80
|
+
1. Unsubscribe from the `Subscription`
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
const sub = ACPService.listACP({ pageSize: 20 })
|
|
84
|
+
.subscribe(acpList => doSomething(acpList));
|
|
85
|
+
|
|
86
|
+
sub.unsubcribe();
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
2. Abort the request using `KvRequestAbortController`. To use this approach it's necessary to declare the class and pass it through the request options as `requestController`. After the request is built in the SDK we can access the `cancel` option from the class.
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
const requestController = new KvRequestAbortController();
|
|
93
|
+
|
|
94
|
+
await ACPService.listACP(
|
|
95
|
+
{ pageSize: 20 },
|
|
96
|
+
{ requestController } as IKvWebHttpRequestOptions
|
|
97
|
+
)
|
|
98
|
+
.toPromise()
|
|
99
|
+
.then(acpList => doSomething(acpList));
|
|
100
|
+
|
|
101
|
+
// To cancel the request
|
|
102
|
+
requestController.cancel();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
74
107
|
## Kelvin SDK Client API Documentation
|
|
75
108
|
|
|
76
109
|
You can find the full Client API reference [**here**](https://docs.kelvininc.com/api/clients/javascript/reference/index.html).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const AXIOS_ABORT_ERROR_CODE = "ERR_CANCELED";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../src/adapters/http/config.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG,cAAc,CAAC","sourcesContent":["export const AXIOS_ABORT_ERROR_CODE = 'ERR_CANCELED';\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IKvHttpAdapter, IKvHttpResponse } from '@kelvininc/js-client-sdk';
|
|
2
|
+
import { AxiosInstance } from 'axios';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
import { IKvWebHttpRequest } from './types';
|
|
5
|
+
export declare class HttpAdapter implements IKvHttpAdapter {
|
|
6
|
+
private httpClient;
|
|
7
|
+
constructor(httpClient: AxiosInstance);
|
|
8
|
+
request(requestPayload: IKvWebHttpRequest): Observable<IKvHttpResponse>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IKvHttpResponse } from '@kelvininc/js-client-sdk';
|
|
2
|
+
import { AxiosError, AxiosRequestConfig, AxiosResponse, CanceledError } from 'axios';
|
|
3
|
+
import { IKvWebHttpRequest } from './types';
|
|
4
|
+
export declare const handleRequest: (response: AxiosResponse, config: IKvWebHttpRequest) => IKvHttpResponse;
|
|
5
|
+
export declare const handleError: (err: AxiosError | CanceledError<unknown>, config: IKvWebHttpRequest) => IKvHttpResponse;
|
|
6
|
+
export declare const buildAxiosRequestConfig: (request: IKvWebHttpRequest, controller: AbortController) => AxiosRequestConfig;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildAxiosRequestConfig = exports.handleError = exports.handleRequest = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const js_client_sdk_1 = require("@kelvininc/js-client-sdk");
|
|
6
|
+
const config_1 = require("./config");
|
|
7
|
+
const qs_1 = tslib_1.__importDefault(require("qs"));
|
|
8
|
+
const handleRequest = (response, config) => {
|
|
9
|
+
const { data, status, statusText, headers } = response;
|
|
10
|
+
const isChunked = config.mediaType === js_client_sdk_1.EKvHttpMediaType.jsonStream;
|
|
11
|
+
let bodyParsed = data;
|
|
12
|
+
/**
|
|
13
|
+
* typeof bodyParsed == 'string' fixes a bug when the stream
|
|
14
|
+
* comes with only one array the axios framework parses it automatically
|
|
15
|
+
*/
|
|
16
|
+
if (isChunked && typeof bodyParsed === 'string') {
|
|
17
|
+
try {
|
|
18
|
+
bodyParsed = bodyParsed
|
|
19
|
+
? JSON.parse(data.replace(/\]\n\[/g, ','))
|
|
20
|
+
: [];
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
console.error('Error during parsing chunk data', error);
|
|
24
|
+
bodyParsed = [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
type: js_client_sdk_1.EKvHttpResponseType.Response,
|
|
29
|
+
body: bodyParsed,
|
|
30
|
+
status,
|
|
31
|
+
statusText,
|
|
32
|
+
headers,
|
|
33
|
+
config,
|
|
34
|
+
httpResponse: response
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.handleRequest = handleRequest;
|
|
38
|
+
const handleError = (err, config) => {
|
|
39
|
+
var _a;
|
|
40
|
+
const status = err.code === config_1.AXIOS_ABORT_ERROR_CODE
|
|
41
|
+
? js_client_sdk_1.EKvHttpStatusCode.CLI_CLOSED_REQUEST
|
|
42
|
+
: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status;
|
|
43
|
+
return {
|
|
44
|
+
status,
|
|
45
|
+
config,
|
|
46
|
+
type: js_client_sdk_1.EKvHttpResponseType.Response,
|
|
47
|
+
statusText: err.message,
|
|
48
|
+
httpResponse: err.response
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
exports.handleError = handleError;
|
|
52
|
+
const buildAxiosRequestConfig = (request, controller) => {
|
|
53
|
+
const { method, url, data, headers, params, mediaType } = request;
|
|
54
|
+
const responseType = (0, js_client_sdk_1.getResponseType)(mediaType);
|
|
55
|
+
if (data instanceof FormData) {
|
|
56
|
+
headers['Content-Type'] = 'multipart/form-data';
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
method,
|
|
60
|
+
url,
|
|
61
|
+
headers,
|
|
62
|
+
data,
|
|
63
|
+
responseType,
|
|
64
|
+
params,
|
|
65
|
+
signal: controller.signal,
|
|
66
|
+
paramsSerializer: {
|
|
67
|
+
serialize: (paramsToSerialize) => qs_1.default.stringify(paramsToSerialize, {
|
|
68
|
+
arrayFormat: 'comma'
|
|
69
|
+
}),
|
|
70
|
+
indexes: null
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
exports.buildAxiosRequestConfig = buildAxiosRequestConfig;
|
|
75
|
+
//# sourceMappingURL=http-adapter.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-adapter.helper.js","sourceRoot":"","sources":["../../../../src/adapters/http/http-adapter.helper.ts"],"names":[],"mappings":";;;;AAAA,4DAMkC;AAOlC,qCAAkD;AAElD,oDAAoB;AAEb,MAAM,aAAa,GAAG,CAC5B,QAAuB,EACvB,MAAyB,EACP,EAAE;IACpB,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IACvD,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,KAAK,gCAAgB,CAAC,UAAU,CAAC;IACnE,IAAI,UAAU,GAAG,IAAI,CAAC;IAEtB;;;OAGG;IACH,IAAI,SAAS,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;QAChD,IAAI;YACH,UAAU,GAAG,UAAU;gBACtB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;gBAC1C,CAAC,CAAC,EAAE,CAAC;SACN;QAAC,OAAO,KAAK,EAAE;YACf,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;YACxD,UAAU,GAAG,EAAE,CAAC;SAChB;KACD;IAED,OAAO;QACN,IAAI,EAAE,mCAAmB,CAAC,QAAQ;QAClC,IAAI,EAAE,UAAU;QAChB,MAAM;QACN,UAAU;QACV,OAAO;QACP,MAAM;QACN,YAAY,EAAE,QAAQ;KACtB,CAAC;AACH,CAAC,CAAC;AAhCW,QAAA,aAAa,iBAgCxB;AAEK,MAAM,WAAW,GAAG,CAC1B,GAAwC,EACxC,MAAyB,EACP,EAAE;;IACpB,MAAM,MAAM,GACX,GAAG,CAAC,IAAI,KAAK,+BAAsB;QAClC,CAAC,CAAC,iCAAiB,CAAC,kBAAkB;QACtC,CAAC,CAAC,MAAA,GAAG,CAAC,QAAQ,0CAAE,MAAM,CAAC;IAEzB,OAAO;QACN,MAAM;QACN,MAAM;QACN,IAAI,EAAE,mCAAmB,CAAC,QAAQ;QAClC,UAAU,EAAE,GAAG,CAAC,OAAO;QACvB,YAAY,EAAE,GAAG,CAAC,QAAQ;KAC1B,CAAC;AACH,CAAC,CAAC;AAhBW,QAAA,WAAW,eAgBtB;AAEK,MAAM,uBAAuB,GAAG,CACtC,OAA0B,EAC1B,UAA2B,EACN,EAAE;IACvB,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAClE,MAAM,YAAY,GAAG,IAAA,+BAAe,EAAC,SAAS,CAAC,CAAC;IAEhD,IAAI,IAAI,YAAY,QAAQ,EAAE;QAC7B,OAAO,CAAC,cAAc,CAAC,GAAG,qBAAqB,CAAC;KAChD;IAED,OAAO;QACN,MAAM;QACN,GAAG;QACH,OAAO;QACP,IAAI;QACJ,YAAY;QACZ,MAAM;QACN,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,gBAAgB,EAAE;YACjB,SAAS,EAAE,CAAC,iBAA0C,EAAE,EAAE,CACzD,YAAE,CAAC,SAAS,CAAC,iBAAiB,EAAE;gBAC/B,WAAW,EAAE,OAAO;aACpB,CAAC;YACH,OAAO,EAAE,IAAI;SACb;KACD,CAAC;AACH,CAAC,CAAC;AA3BW,QAAA,uBAAuB,2BA2BlC","sourcesContent":["import {\n\tEKvHttpMediaType,\n\tEKvHttpResponseType,\n\tEKvHttpStatusCode,\n\tgetResponseType,\n\tIKvHttpResponse\n} from '@kelvininc/js-client-sdk';\nimport {\n\tAxiosError,\n\tAxiosRequestConfig,\n\tAxiosResponse,\n\tCanceledError\n} from 'axios';\nimport { AXIOS_ABORT_ERROR_CODE } from './config';\nimport { IKvWebHttpRequest } from './types';\nimport qs from 'qs';\n\nexport const handleRequest = (\n\tresponse: AxiosResponse,\n\tconfig: IKvWebHttpRequest\n): IKvHttpResponse => {\n\tconst { data, status, statusText, headers } = response;\n\tconst isChunked = config.mediaType === EKvHttpMediaType.jsonStream;\n\tlet bodyParsed = data;\n\n\t/**\n\t * typeof bodyParsed == 'string' fixes a bug when the stream\n\t * comes with only one array the axios framework parses it automatically\n\t */\n\tif (isChunked && typeof bodyParsed === 'string') {\n\t\ttry {\n\t\t\tbodyParsed = bodyParsed\n\t\t\t\t? JSON.parse(data.replace(/\\]\\n\\[/g, ','))\n\t\t\t\t: [];\n\t\t} catch (error) {\n\t\t\tconsole.error('Error during parsing chunk data', error);\n\t\t\tbodyParsed = [];\n\t\t}\n\t}\n\n\treturn {\n\t\ttype: EKvHttpResponseType.Response,\n\t\tbody: bodyParsed,\n\t\tstatus,\n\t\tstatusText,\n\t\theaders,\n\t\tconfig,\n\t\thttpResponse: response\n\t};\n};\n\nexport const handleError = (\n\terr: AxiosError | CanceledError<unknown>,\n\tconfig: IKvWebHttpRequest\n): IKvHttpResponse => {\n\tconst status =\n\t\terr.code === AXIOS_ABORT_ERROR_CODE\n\t\t\t? EKvHttpStatusCode.CLI_CLOSED_REQUEST\n\t\t\t: err.response?.status;\n\n\treturn {\n\t\tstatus,\n\t\tconfig,\n\t\ttype: EKvHttpResponseType.Response,\n\t\tstatusText: err.message,\n\t\thttpResponse: err.response\n\t};\n};\n\nexport const buildAxiosRequestConfig = (\n\trequest: IKvWebHttpRequest,\n\tcontroller: AbortController\n): AxiosRequestConfig => {\n\tconst { method, url, data, headers, params, mediaType } = request;\n\tconst responseType = getResponseType(mediaType);\n\n\tif (data instanceof FormData) {\n\t\theaders['Content-Type'] = 'multipart/form-data';\n\t}\n\n\treturn {\n\t\tmethod,\n\t\turl,\n\t\theaders,\n\t\tdata,\n\t\tresponseType,\n\t\tparams,\n\t\tsignal: controller.signal,\n\t\tparamsSerializer: {\n\t\t\tserialize: (paramsToSerialize: Record<string, unknown>) =>\n\t\t\t\tqs.stringify(paramsToSerialize, {\n\t\t\t\t\tarrayFormat: 'comma'\n\t\t\t\t}),\n\t\t\tindexes: null\n\t\t}\n\t};\n};\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpAdapter = void 0;
|
|
4
|
+
const js_client_sdk_1 = require("@kelvininc/js-client-sdk");
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
const operators_1 = require("rxjs/operators");
|
|
7
|
+
const http_adapter_helper_1 = require("./http-adapter.helper");
|
|
8
|
+
class HttpAdapter {
|
|
9
|
+
constructor(httpClient) {
|
|
10
|
+
this.httpClient = httpClient;
|
|
11
|
+
}
|
|
12
|
+
request(requestPayload) {
|
|
13
|
+
var _a, _b, _c;
|
|
14
|
+
const requestInstance$ = new rxjs_1.Subject();
|
|
15
|
+
const controller = new AbortController();
|
|
16
|
+
let axiosRequestConfig = (0, http_adapter_helper_1.buildAxiosRequestConfig)(requestPayload, controller);
|
|
17
|
+
if ((_a = requestPayload.options) === null || _a === void 0 ? void 0 : _a.reportProgress) {
|
|
18
|
+
axiosRequestConfig = Object.assign(Object.assign({}, axiosRequestConfig), { onDownloadProgress: (progress) => {
|
|
19
|
+
requestInstance$.next({
|
|
20
|
+
type: js_client_sdk_1.EKvHttpResponseType.DownloadProgress,
|
|
21
|
+
httpResponse: progress,
|
|
22
|
+
config: requestPayload
|
|
23
|
+
});
|
|
24
|
+
}, onUploadProgress: (progress) => {
|
|
25
|
+
requestInstance$.next({
|
|
26
|
+
type: js_client_sdk_1.EKvHttpResponseType.UploadProgress,
|
|
27
|
+
httpResponse: progress,
|
|
28
|
+
config: requestPayload
|
|
29
|
+
});
|
|
30
|
+
} });
|
|
31
|
+
}
|
|
32
|
+
(_c = (_b = requestPayload.options) === null || _b === void 0 ? void 0 : _b.requestController) === null || _c === void 0 ? void 0 : _c.setAbortController(controller);
|
|
33
|
+
this.httpClient
|
|
34
|
+
.request(axiosRequestConfig)
|
|
35
|
+
.then((response) => {
|
|
36
|
+
requestInstance$.next((0, http_adapter_helper_1.handleRequest)(response, requestPayload));
|
|
37
|
+
requestInstance$.complete();
|
|
38
|
+
})
|
|
39
|
+
.catch((error) => {
|
|
40
|
+
requestInstance$.error((0, http_adapter_helper_1.handleError)(error, requestPayload));
|
|
41
|
+
});
|
|
42
|
+
return requestInstance$.pipe((0, operators_1.finalize)(() => {
|
|
43
|
+
/**
|
|
44
|
+
* When the subscription is closed by the client before
|
|
45
|
+
* request completes abort the axios request.
|
|
46
|
+
*/
|
|
47
|
+
if (!requestInstance$.isStopped) {
|
|
48
|
+
controller.abort(js_client_sdk_1.EKvHttpStatusCode.CLI_CLOSED_REQUEST);
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.HttpAdapter = HttpAdapter;
|
|
54
|
+
//# sourceMappingURL=http-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-adapter.js","sourceRoot":"","sources":["../../../../src/adapters/http/http-adapter.ts"],"names":[],"mappings":";;;AAAA,4DAKkC;AAElC,+BAA2C;AAC3C,8CAA0C;AAE1C,+DAI+B;AAE/B,MAAa,WAAW;IACvB,YAAoB,UAAyB;QAAzB,eAAU,GAAV,UAAU,CAAe;IAAG,CAAC;IAEjD,OAAO,CAAC,cAAiC;;QACxC,MAAM,gBAAgB,GAAG,IAAI,cAAO,EAAmB,CAAC;QACxD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,IAAI,kBAAkB,GAAuB,IAAA,6CAAuB,EACnE,cAAc,EACd,UAAU,CACV,CAAC;QAEF,IAAI,MAAA,cAAc,CAAC,OAAO,0CAAE,cAAc,EAAE;YAC3C,kBAAkB,mCACd,kBAAkB,KACrB,kBAAkB,EAAE,CAAC,QAAQ,EAAE,EAAE;oBAChC,gBAAgB,CAAC,IAAI,CAAC;wBACrB,IAAI,EAAE,mCAAmB,CAAC,gBAAgB;wBAC1C,YAAY,EAAE,QAAQ;wBACtB,MAAM,EAAE,cAAc;qBACtB,CAAC,CAAC;gBACJ,CAAC,EACD,gBAAgB,EAAE,CAAC,QAAQ,EAAE,EAAE;oBAC9B,gBAAgB,CAAC,IAAI,CAAC;wBACrB,IAAI,EAAE,mCAAmB,CAAC,cAAc;wBACxC,YAAY,EAAE,QAAQ;wBACtB,MAAM,EAAE,cAAc;qBACtB,CAAC,CAAC;gBACJ,CAAC,GACD,CAAC;SACF;QAED,MAAA,MAAA,cAAc,CAAC,OAAO,0CAAE,iBAAiB,0CAAE,kBAAkB,CAC5D,UAAU,CACV,CAAC;QAEF,IAAI,CAAC,UAAU;aACb,OAAO,CAAC,kBAAkB,CAAC;aAC3B,IAAI,CAAC,CAAC,QAAuB,EAAE,EAAE;YACjC,gBAAgB,CAAC,IAAI,CAAC,IAAA,mCAAa,EAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;YAC/D,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAC7B,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAChB,gBAAgB,CAAC,KAAK,CAAC,IAAA,iCAAW,EAAC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;QAEJ,OAAO,gBAAgB,CAAC,IAAI,CAC3B,IAAA,oBAAQ,EAAC,GAAG,EAAE;YACb;;;eAGG;YACH,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE;gBAChC,UAAU,CAAC,KAAK,CAAC,iCAAiB,CAAC,kBAAkB,CAAC,CAAC;aACvD;QACF,CAAC,CAAC,CACF,CAAC;IACH,CAAC;CACD;AAzDD,kCAyDC","sourcesContent":["import {\n\tEKvHttpResponseType,\n\tEKvHttpStatusCode,\n\tIKvHttpAdapter,\n\tIKvHttpResponse\n} from '@kelvininc/js-client-sdk';\nimport { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';\nimport { Observable, Subject } from 'rxjs';\nimport { finalize } from 'rxjs/operators';\nimport { IKvWebHttpRequest } from './types';\nimport {\n\tbuildAxiosRequestConfig,\n\thandleError,\n\thandleRequest\n} from './http-adapter.helper';\n\nexport class HttpAdapter implements IKvHttpAdapter {\n\tconstructor(private httpClient: AxiosInstance) {}\n\n\trequest(requestPayload: IKvWebHttpRequest): Observable<IKvHttpResponse> {\n\t\tconst requestInstance$ = new Subject<IKvHttpResponse>();\n\t\tconst controller = new AbortController();\n\t\tlet axiosRequestConfig: AxiosRequestConfig = buildAxiosRequestConfig(\n\t\t\trequestPayload,\n\t\t\tcontroller\n\t\t);\n\n\t\tif (requestPayload.options?.reportProgress) {\n\t\t\taxiosRequestConfig = {\n\t\t\t\t...axiosRequestConfig,\n\t\t\t\tonDownloadProgress: (progress) => {\n\t\t\t\t\trequestInstance$.next({\n\t\t\t\t\t\ttype: EKvHttpResponseType.DownloadProgress,\n\t\t\t\t\t\thttpResponse: progress,\n\t\t\t\t\t\tconfig: requestPayload\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tonUploadProgress: (progress) => {\n\t\t\t\t\trequestInstance$.next({\n\t\t\t\t\t\ttype: EKvHttpResponseType.UploadProgress,\n\t\t\t\t\t\thttpResponse: progress,\n\t\t\t\t\t\tconfig: requestPayload\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\trequestPayload.options?.requestController?.setAbortController(\n\t\t\tcontroller\n\t\t);\n\n\t\tthis.httpClient\n\t\t\t.request(axiosRequestConfig)\n\t\t\t.then((response: AxiosResponse) => {\n\t\t\t\trequestInstance$.next(handleRequest(response, requestPayload));\n\t\t\t\trequestInstance$.complete();\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\trequestInstance$.error(handleError(error, requestPayload));\n\t\t\t});\n\n\t\treturn requestInstance$.pipe(\n\t\t\tfinalize(() => {\n\t\t\t\t/**\n\t\t\t\t * When the subscription is closed by the client before\n\t\t\t\t * request completes abort the axios request.\n\t\t\t\t */\n\t\t\t\tif (!requestInstance$.isStopped) {\n\t\t\t\t\tcontroller.abort(EKvHttpStatusCode.CLI_CLOSED_REQUEST);\n\t\t\t\t}\n\t\t\t})\n\t\t);\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/adapters/http/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB","sourcesContent":["export * from './types';\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IKvHttpRequest, IKvHttpRequestOptions } from '@kelvininc/js-client-sdk';
|
|
2
|
+
import { KvRequestAbortController } from '../../classes';
|
|
3
|
+
export interface IKvWebHttpRequestOptions extends IKvHttpRequestOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Use this option if you plan to handle manually the request abortion
|
|
6
|
+
*/
|
|
7
|
+
requestController?: KvRequestAbortController;
|
|
8
|
+
}
|
|
9
|
+
export interface IKvWebHttpRequest extends IKvHttpRequest {
|
|
10
|
+
options?: IKvWebHttpRequestOptions;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/adapters/http/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n\tIKvHttpRequest,\n\tIKvHttpRequestOptions\n} from '@kelvininc/js-client-sdk';\n\nimport { KvRequestAbortController } from '../../classes';\n\nexport interface IKvWebHttpRequestOptions extends IKvHttpRequestOptions {\n\t/**\n\t * Use this option if you plan to handle manually the request abortion\n\t */\n\trequestController?: KvRequestAbortController;\n}\n\nexport interface IKvWebHttpRequest extends IKvHttpRequest {\n\toptions?: IKvWebHttpRequestOptions;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './request-abort-controller';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/classes/index.ts"],"names":[],"mappings":";;;AAAA,qEAA2C","sourcesContent":["export * from './request-abort-controller';\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KvRequestAbortController = void 0;
|
|
4
|
+
const js_client_sdk_1 = require("@kelvininc/js-client-sdk");
|
|
5
|
+
const uuid_1 = require("uuid");
|
|
6
|
+
class KvRequestAbortController {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.requestId = (0, uuid_1.v4)();
|
|
9
|
+
}
|
|
10
|
+
getId() {
|
|
11
|
+
return this.requestId;
|
|
12
|
+
}
|
|
13
|
+
setAbortController(controller) {
|
|
14
|
+
this.abortController = controller;
|
|
15
|
+
}
|
|
16
|
+
cancel() {
|
|
17
|
+
var _a;
|
|
18
|
+
(_a = this.abortController) === null || _a === void 0 ? void 0 : _a.abort(js_client_sdk_1.EKvHttpStatusCode.CLI_CLOSED_REQUEST);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.KvRequestAbortController = KvRequestAbortController;
|
|
22
|
+
//# sourceMappingURL=request-abort-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-abort-controller.js","sourceRoot":"","sources":["../../../src/classes/request-abort-controller.ts"],"names":[],"mappings":";;;AAAA,4DAA6D;AAC7D,+BAAkC;AAElC,MAAa,wBAAwB;IAIpC;QACC,IAAI,CAAC,SAAS,GAAG,IAAA,SAAI,GAAE,CAAC;IACzB,CAAC;IAED,KAAK;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED,kBAAkB,CAAC,UAA2B;QAC7C,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC;IACnC,CAAC;IAED,MAAM;;QACL,MAAA,IAAI,CAAC,eAAe,0CAAE,KAAK,CAAC,iCAAiB,CAAC,kBAAkB,CAAC,CAAC;IACnE,CAAC;CACD;AAnBD,4DAmBC","sourcesContent":["import { EKvHttpStatusCode } from '@kelvininc/js-client-sdk';\nimport { v4 as uuid } from 'uuid';\n\nexport class KvRequestAbortController {\n\tprivate requestId: string;\n\tprivate abortController: AbortController;\n\n\tconstructor() {\n\t\tthis.requestId = uuid();\n\t}\n\n\tgetId() {\n\t\treturn this.requestId;\n\t}\n\n\tsetAbortController(controller: AbortController) {\n\t\tthis.abortController = controller;\n\t}\n\n\tcancel() {\n\t\tthis.abortController?.abort(EKvHttpStatusCode.CLI_CLOSED_REQUEST);\n\t}\n}\n"]}
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -3,5 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const kelvin_web_sdk_1 = require("./kelvin-web-sdk");
|
|
5
5
|
tslib_1.__exportStar(require("@kelvininc/js-client-sdk"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./adapters/http"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./classes"), exports);
|
|
6
8
|
exports.default = kelvin_web_sdk_1.KelvinSDK;
|
|
7
9
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAA6C;AAC7C,mEAAyC;AACzC,kBAAe,0BAAS,CAAC","sourcesContent":["import { KelvinSDK } from './kelvin-web-sdk';\nexport * from '@kelvininc/js-client-sdk';\nexport default KelvinSDK;\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAA6C;AAC7C,mEAAyC;AACzC,0DAAgC;AAChC,oDAA0B;AAC1B,kBAAe,0BAAS,CAAC","sourcesContent":["import { KelvinSDK } from './kelvin-web-sdk';\nexport * from '@kelvininc/js-client-sdk';\nexport * from './adapters/http';\nexport * from './classes';\nexport default KelvinSDK;\n"]}
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.KelvinSDK = void 0;
|
|
4
4
|
const js_client_sdk_1 = require("@kelvininc/js-client-sdk");
|
|
5
|
-
const http_adapter_1 = require("./adapters/http-adapter");
|
|
5
|
+
const http_adapter_1 = require("./adapters/http/http-adapter");
|
|
6
6
|
const storage_adapter_1 = require("./adapters/storage-adapter");
|
|
7
7
|
class KelvinSDK {
|
|
8
8
|
static initialize(configuration, httpClient) {
|
|
9
|
-
js_client_sdk_1.init(Object.assign(Object.assign({}, configuration), { httpAdapter: new http_adapter_1.HttpAdapter(httpClient), storageAdapter: new storage_adapter_1.StorageAdapter() }));
|
|
9
|
+
(0, js_client_sdk_1.init)(Object.assign(Object.assign({}, configuration), { httpAdapter: new http_adapter_1.HttpAdapter(httpClient), storageAdapter: new storage_adapter_1.StorageAdapter() }));
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Change the session parameters without an initialization
|
|
13
13
|
* @param sessionConfig session configuration data
|
|
14
14
|
*/
|
|
15
15
|
static setSessionConfiguration(sessionConfig) {
|
|
16
|
-
js_client_sdk_1.setSession(sessionConfig);
|
|
16
|
+
(0, js_client_sdk_1.setSession)(sessionConfig);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.KelvinSDK = KelvinSDK;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kelvin-web-sdk.js","sourceRoot":"","sources":["../../src/kelvin-web-sdk.ts"],"names":[],"mappings":";;;AAAA,4DAKkC;AAElC
|
|
1
|
+
{"version":3,"file":"kelvin-web-sdk.js","sourceRoot":"","sources":["../../src/kelvin-web-sdk.ts"],"names":[],"mappings":";;;AAAA,4DAKkC;AAElC,+DAA2D;AAC3D,gEAA4D;AAE5D,MAAa,SAAS;IACrB,MAAM,CAAC,UAAU,CAChB,aAAmC,EACnC,UAAyB;QAEzB,IAAA,oBAAc,kCACV,aAAa,KAChB,WAAW,EAAE,IAAI,0BAAW,CAAC,UAAU,CAAC,EACxC,cAAc,EAAE,IAAI,gCAAc,EAAE,IACnC,CAAC;IACJ,CAAC;IAED;;;OAGG;IAEH,MAAM,CAAC,uBAAuB,CAAC,aAA6B;QAC3D,IAAA,0BAAU,EAAC,aAAa,CAAC,CAAC;IAC3B,CAAC;CACD;AApBD,8BAoBC","sourcesContent":["import {\n\tIKvEnvironmentConfig,\n\tISessionConfig,\n\tsetSession,\n\tinit as initKelvinCore\n} from '@kelvininc/js-client-sdk';\nimport { AxiosInstance } from 'axios';\nimport { HttpAdapter } from './adapters/http/http-adapter';\nimport { StorageAdapter } from './adapters/storage-adapter';\n\nexport class KelvinSDK {\n\tstatic initialize(\n\t\tconfiguration: IKvEnvironmentConfig,\n\t\thttpClient: AxiosInstance\n\t) {\n\t\tinitKelvinCore({\n\t\t\t...configuration,\n\t\t\thttpAdapter: new HttpAdapter(httpClient),\n\t\t\tstorageAdapter: new StorageAdapter()\n\t\t});\n\t}\n\n\t/**\n\t * Change the session parameters without an initialization\n\t * @param sessionConfig session configuration data\n\t */\n\n\tstatic setSessionConfiguration(sessionConfig: ISessionConfig) {\n\t\tsetSession(sessionConfig);\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@kelvininc/js-client-sdk/models';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":";;;AAAA,0EAAgD","sourcesContent":["export * from '@kelvininc/js-client-sdk/models';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const AXIOS_ABORT_ERROR_CODE = "ERR_CANCELED";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../src/adapters/http/config.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,cAAc,CAAC","sourcesContent":["export const AXIOS_ABORT_ERROR_CODE = 'ERR_CANCELED';\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IKvHttpAdapter, IKvHttpResponse } from '@kelvininc/js-client-sdk';
|
|
2
|
+
import { AxiosInstance } from 'axios';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
import { IKvWebHttpRequest } from './types';
|
|
5
|
+
export declare class HttpAdapter implements IKvHttpAdapter {
|
|
6
|
+
private httpClient;
|
|
7
|
+
constructor(httpClient: AxiosInstance);
|
|
8
|
+
request(requestPayload: IKvWebHttpRequest): Observable<IKvHttpResponse>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IKvHttpResponse } from '@kelvininc/js-client-sdk';
|
|
2
|
+
import { AxiosError, AxiosRequestConfig, AxiosResponse, CanceledError } from 'axios';
|
|
3
|
+
import { IKvWebHttpRequest } from './types';
|
|
4
|
+
export declare const handleRequest: (response: AxiosResponse, config: IKvWebHttpRequest) => IKvHttpResponse;
|
|
5
|
+
export declare const handleError: (err: AxiosError | CanceledError<unknown>, config: IKvWebHttpRequest) => IKvHttpResponse;
|
|
6
|
+
export declare const buildAxiosRequestConfig: (request: IKvWebHttpRequest, controller: AbortController) => AxiosRequestConfig;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { EKvHttpMediaType, EKvHttpResponseType, EKvHttpStatusCode, getResponseType } from '@kelvininc/js-client-sdk';
|
|
2
|
+
import { AXIOS_ABORT_ERROR_CODE } from './config';
|
|
3
|
+
import qs from 'qs';
|
|
4
|
+
export const handleRequest = (response, config) => {
|
|
5
|
+
const { data, status, statusText, headers } = response;
|
|
6
|
+
const isChunked = config.mediaType === EKvHttpMediaType.jsonStream;
|
|
7
|
+
let bodyParsed = data;
|
|
8
|
+
/**
|
|
9
|
+
* typeof bodyParsed == 'string' fixes a bug when the stream
|
|
10
|
+
* comes with only one array the axios framework parses it automatically
|
|
11
|
+
*/
|
|
12
|
+
if (isChunked && typeof bodyParsed === 'string') {
|
|
13
|
+
try {
|
|
14
|
+
bodyParsed = bodyParsed
|
|
15
|
+
? JSON.parse(data.replace(/\]\n\[/g, ','))
|
|
16
|
+
: [];
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
console.error('Error during parsing chunk data', error);
|
|
20
|
+
bodyParsed = [];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
type: EKvHttpResponseType.Response,
|
|
25
|
+
body: bodyParsed,
|
|
26
|
+
status,
|
|
27
|
+
statusText,
|
|
28
|
+
headers,
|
|
29
|
+
config,
|
|
30
|
+
httpResponse: response
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export const handleError = (err, config) => {
|
|
34
|
+
var _a;
|
|
35
|
+
const status = err.code === AXIOS_ABORT_ERROR_CODE
|
|
36
|
+
? EKvHttpStatusCode.CLI_CLOSED_REQUEST
|
|
37
|
+
: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status;
|
|
38
|
+
return {
|
|
39
|
+
status,
|
|
40
|
+
config,
|
|
41
|
+
type: EKvHttpResponseType.Response,
|
|
42
|
+
statusText: err.message,
|
|
43
|
+
httpResponse: err.response
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export const buildAxiosRequestConfig = (request, controller) => {
|
|
47
|
+
const { method, url, data, headers, params, mediaType } = request;
|
|
48
|
+
const responseType = getResponseType(mediaType);
|
|
49
|
+
if (data instanceof FormData) {
|
|
50
|
+
headers['Content-Type'] = 'multipart/form-data';
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
method,
|
|
54
|
+
url,
|
|
55
|
+
headers,
|
|
56
|
+
data,
|
|
57
|
+
responseType,
|
|
58
|
+
params,
|
|
59
|
+
signal: controller.signal,
|
|
60
|
+
paramsSerializer: {
|
|
61
|
+
serialize: (paramsToSerialize) => qs.stringify(paramsToSerialize, {
|
|
62
|
+
arrayFormat: 'comma'
|
|
63
|
+
}),
|
|
64
|
+
indexes: null
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=http-adapter.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-adapter.helper.js","sourceRoot":"","sources":["../../../../src/adapters/http/http-adapter.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EAEf,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,CAAC,MAAM,aAAa,GAAG,CAC5B,QAAuB,EACvB,MAAyB,EACP,EAAE;IACpB,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IACvD,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,KAAK,gBAAgB,CAAC,UAAU,CAAC;IACnE,IAAI,UAAU,GAAG,IAAI,CAAC;IAEtB;;;OAGG;IACH,IAAI,SAAS,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;QAChD,IAAI;YACH,UAAU,GAAG,UAAU;gBACtB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;gBAC1C,CAAC,CAAC,EAAE,CAAC;SACN;QAAC,OAAO,KAAK,EAAE;YACf,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;YACxD,UAAU,GAAG,EAAE,CAAC;SAChB;KACD;IAED,OAAO;QACN,IAAI,EAAE,mBAAmB,CAAC,QAAQ;QAClC,IAAI,EAAE,UAAU;QAChB,MAAM;QACN,UAAU;QACV,OAAO;QACP,MAAM;QACN,YAAY,EAAE,QAAQ;KACtB,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAC1B,GAAwC,EACxC,MAAyB,EACP,EAAE;;IACpB,MAAM,MAAM,GACX,GAAG,CAAC,IAAI,KAAK,sBAAsB;QAClC,CAAC,CAAC,iBAAiB,CAAC,kBAAkB;QACtC,CAAC,CAAC,MAAA,GAAG,CAAC,QAAQ,0CAAE,MAAM,CAAC;IAEzB,OAAO;QACN,MAAM;QACN,MAAM;QACN,IAAI,EAAE,mBAAmB,CAAC,QAAQ;QAClC,UAAU,EAAE,GAAG,CAAC,OAAO;QACvB,YAAY,EAAE,GAAG,CAAC,QAAQ;KAC1B,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACtC,OAA0B,EAC1B,UAA2B,EACN,EAAE;IACvB,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAClE,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IAEhD,IAAI,IAAI,YAAY,QAAQ,EAAE;QAC7B,OAAO,CAAC,cAAc,CAAC,GAAG,qBAAqB,CAAC;KAChD;IAED,OAAO;QACN,MAAM;QACN,GAAG;QACH,OAAO;QACP,IAAI;QACJ,YAAY;QACZ,MAAM;QACN,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,gBAAgB,EAAE;YACjB,SAAS,EAAE,CAAC,iBAA0C,EAAE,EAAE,CACzD,EAAE,CAAC,SAAS,CAAC,iBAAiB,EAAE;gBAC/B,WAAW,EAAE,OAAO;aACpB,CAAC;YACH,OAAO,EAAE,IAAI;SACb;KACD,CAAC;AACH,CAAC,CAAC","sourcesContent":["import {\n\tEKvHttpMediaType,\n\tEKvHttpResponseType,\n\tEKvHttpStatusCode,\n\tgetResponseType,\n\tIKvHttpResponse\n} from '@kelvininc/js-client-sdk';\nimport {\n\tAxiosError,\n\tAxiosRequestConfig,\n\tAxiosResponse,\n\tCanceledError\n} from 'axios';\nimport { AXIOS_ABORT_ERROR_CODE } from './config';\nimport { IKvWebHttpRequest } from './types';\nimport qs from 'qs';\n\nexport const handleRequest = (\n\tresponse: AxiosResponse,\n\tconfig: IKvWebHttpRequest\n): IKvHttpResponse => {\n\tconst { data, status, statusText, headers } = response;\n\tconst isChunked = config.mediaType === EKvHttpMediaType.jsonStream;\n\tlet bodyParsed = data;\n\n\t/**\n\t * typeof bodyParsed == 'string' fixes a bug when the stream\n\t * comes with only one array the axios framework parses it automatically\n\t */\n\tif (isChunked && typeof bodyParsed === 'string') {\n\t\ttry {\n\t\t\tbodyParsed = bodyParsed\n\t\t\t\t? JSON.parse(data.replace(/\\]\\n\\[/g, ','))\n\t\t\t\t: [];\n\t\t} catch (error) {\n\t\t\tconsole.error('Error during parsing chunk data', error);\n\t\t\tbodyParsed = [];\n\t\t}\n\t}\n\n\treturn {\n\t\ttype: EKvHttpResponseType.Response,\n\t\tbody: bodyParsed,\n\t\tstatus,\n\t\tstatusText,\n\t\theaders,\n\t\tconfig,\n\t\thttpResponse: response\n\t};\n};\n\nexport const handleError = (\n\terr: AxiosError | CanceledError<unknown>,\n\tconfig: IKvWebHttpRequest\n): IKvHttpResponse => {\n\tconst status =\n\t\terr.code === AXIOS_ABORT_ERROR_CODE\n\t\t\t? EKvHttpStatusCode.CLI_CLOSED_REQUEST\n\t\t\t: err.response?.status;\n\n\treturn {\n\t\tstatus,\n\t\tconfig,\n\t\ttype: EKvHttpResponseType.Response,\n\t\tstatusText: err.message,\n\t\thttpResponse: err.response\n\t};\n};\n\nexport const buildAxiosRequestConfig = (\n\trequest: IKvWebHttpRequest,\n\tcontroller: AbortController\n): AxiosRequestConfig => {\n\tconst { method, url, data, headers, params, mediaType } = request;\n\tconst responseType = getResponseType(mediaType);\n\n\tif (data instanceof FormData) {\n\t\theaders['Content-Type'] = 'multipart/form-data';\n\t}\n\n\treturn {\n\t\tmethod,\n\t\turl,\n\t\theaders,\n\t\tdata,\n\t\tresponseType,\n\t\tparams,\n\t\tsignal: controller.signal,\n\t\tparamsSerializer: {\n\t\t\tserialize: (paramsToSerialize: Record<string, unknown>) =>\n\t\t\t\tqs.stringify(paramsToSerialize, {\n\t\t\t\t\tarrayFormat: 'comma'\n\t\t\t\t}),\n\t\t\tindexes: null\n\t\t}\n\t};\n};\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { EKvHttpResponseType, EKvHttpStatusCode } from '@kelvininc/js-client-sdk';
|
|
2
|
+
import { Subject } from 'rxjs';
|
|
3
|
+
import { finalize } from 'rxjs/operators';
|
|
4
|
+
import { buildAxiosRequestConfig, handleError, handleRequest } from './http-adapter.helper';
|
|
5
|
+
export class HttpAdapter {
|
|
6
|
+
constructor(httpClient) {
|
|
7
|
+
this.httpClient = httpClient;
|
|
8
|
+
}
|
|
9
|
+
request(requestPayload) {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
const requestInstance$ = new Subject();
|
|
12
|
+
const controller = new AbortController();
|
|
13
|
+
let axiosRequestConfig = buildAxiosRequestConfig(requestPayload, controller);
|
|
14
|
+
if ((_a = requestPayload.options) === null || _a === void 0 ? void 0 : _a.reportProgress) {
|
|
15
|
+
axiosRequestConfig = Object.assign(Object.assign({}, axiosRequestConfig), { onDownloadProgress: (progress) => {
|
|
16
|
+
requestInstance$.next({
|
|
17
|
+
type: EKvHttpResponseType.DownloadProgress,
|
|
18
|
+
httpResponse: progress,
|
|
19
|
+
config: requestPayload
|
|
20
|
+
});
|
|
21
|
+
}, onUploadProgress: (progress) => {
|
|
22
|
+
requestInstance$.next({
|
|
23
|
+
type: EKvHttpResponseType.UploadProgress,
|
|
24
|
+
httpResponse: progress,
|
|
25
|
+
config: requestPayload
|
|
26
|
+
});
|
|
27
|
+
} });
|
|
28
|
+
}
|
|
29
|
+
(_c = (_b = requestPayload.options) === null || _b === void 0 ? void 0 : _b.requestController) === null || _c === void 0 ? void 0 : _c.setAbortController(controller);
|
|
30
|
+
this.httpClient
|
|
31
|
+
.request(axiosRequestConfig)
|
|
32
|
+
.then((response) => {
|
|
33
|
+
requestInstance$.next(handleRequest(response, requestPayload));
|
|
34
|
+
requestInstance$.complete();
|
|
35
|
+
})
|
|
36
|
+
.catch((error) => {
|
|
37
|
+
requestInstance$.error(handleError(error, requestPayload));
|
|
38
|
+
});
|
|
39
|
+
return requestInstance$.pipe(finalize(() => {
|
|
40
|
+
/**
|
|
41
|
+
* When the subscription is closed by the client before
|
|
42
|
+
* request completes abort the axios request.
|
|
43
|
+
*/
|
|
44
|
+
if (!requestInstance$.isStopped) {
|
|
45
|
+
controller.abort(EKvHttpStatusCode.CLI_CLOSED_REQUEST);
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=http-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-adapter.js","sourceRoot":"","sources":["../../../../src/adapters/http/http-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,mBAAmB,EACnB,iBAAiB,EAGjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAc,OAAO,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EACN,uBAAuB,EACvB,WAAW,EACX,aAAa,EACb,MAAM,uBAAuB,CAAC;AAE/B,MAAM,OAAO,WAAW;IACvB,YAAoB,UAAyB;QAAzB,eAAU,GAAV,UAAU,CAAe;IAAG,CAAC;IAEjD,OAAO,CAAC,cAAiC;;QACxC,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAAmB,CAAC;QACxD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,IAAI,kBAAkB,GAAuB,uBAAuB,CACnE,cAAc,EACd,UAAU,CACV,CAAC;QAEF,IAAI,MAAA,cAAc,CAAC,OAAO,0CAAE,cAAc,EAAE;YAC3C,kBAAkB,mCACd,kBAAkB,KACrB,kBAAkB,EAAE,CAAC,QAAQ,EAAE,EAAE;oBAChC,gBAAgB,CAAC,IAAI,CAAC;wBACrB,IAAI,EAAE,mBAAmB,CAAC,gBAAgB;wBAC1C,YAAY,EAAE,QAAQ;wBACtB,MAAM,EAAE,cAAc;qBACtB,CAAC,CAAC;gBACJ,CAAC,EACD,gBAAgB,EAAE,CAAC,QAAQ,EAAE,EAAE;oBAC9B,gBAAgB,CAAC,IAAI,CAAC;wBACrB,IAAI,EAAE,mBAAmB,CAAC,cAAc;wBACxC,YAAY,EAAE,QAAQ;wBACtB,MAAM,EAAE,cAAc;qBACtB,CAAC,CAAC;gBACJ,CAAC,GACD,CAAC;SACF;QAED,MAAA,MAAA,cAAc,CAAC,OAAO,0CAAE,iBAAiB,0CAAE,kBAAkB,CAC5D,UAAU,CACV,CAAC;QAEF,IAAI,CAAC,UAAU;aACb,OAAO,CAAC,kBAAkB,CAAC;aAC3B,IAAI,CAAC,CAAC,QAAuB,EAAE,EAAE;YACjC,gBAAgB,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;YAC/D,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAC7B,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAChB,gBAAgB,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;QAEJ,OAAO,gBAAgB,CAAC,IAAI,CAC3B,QAAQ,CAAC,GAAG,EAAE;YACb;;;eAGG;YACH,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE;gBAChC,UAAU,CAAC,KAAK,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;aACvD;QACF,CAAC,CAAC,CACF,CAAC;IACH,CAAC;CACD","sourcesContent":["import {\n\tEKvHttpResponseType,\n\tEKvHttpStatusCode,\n\tIKvHttpAdapter,\n\tIKvHttpResponse\n} from '@kelvininc/js-client-sdk';\nimport { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';\nimport { Observable, Subject } from 'rxjs';\nimport { finalize } from 'rxjs/operators';\nimport { IKvWebHttpRequest } from './types';\nimport {\n\tbuildAxiosRequestConfig,\n\thandleError,\n\thandleRequest\n} from './http-adapter.helper';\n\nexport class HttpAdapter implements IKvHttpAdapter {\n\tconstructor(private httpClient: AxiosInstance) {}\n\n\trequest(requestPayload: IKvWebHttpRequest): Observable<IKvHttpResponse> {\n\t\tconst requestInstance$ = new Subject<IKvHttpResponse>();\n\t\tconst controller = new AbortController();\n\t\tlet axiosRequestConfig: AxiosRequestConfig = buildAxiosRequestConfig(\n\t\t\trequestPayload,\n\t\t\tcontroller\n\t\t);\n\n\t\tif (requestPayload.options?.reportProgress) {\n\t\t\taxiosRequestConfig = {\n\t\t\t\t...axiosRequestConfig,\n\t\t\t\tonDownloadProgress: (progress) => {\n\t\t\t\t\trequestInstance$.next({\n\t\t\t\t\t\ttype: EKvHttpResponseType.DownloadProgress,\n\t\t\t\t\t\thttpResponse: progress,\n\t\t\t\t\t\tconfig: requestPayload\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tonUploadProgress: (progress) => {\n\t\t\t\t\trequestInstance$.next({\n\t\t\t\t\t\ttype: EKvHttpResponseType.UploadProgress,\n\t\t\t\t\t\thttpResponse: progress,\n\t\t\t\t\t\tconfig: requestPayload\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\trequestPayload.options?.requestController?.setAbortController(\n\t\t\tcontroller\n\t\t);\n\n\t\tthis.httpClient\n\t\t\t.request(axiosRequestConfig)\n\t\t\t.then((response: AxiosResponse) => {\n\t\t\t\trequestInstance$.next(handleRequest(response, requestPayload));\n\t\t\t\trequestInstance$.complete();\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\trequestInstance$.error(handleError(error, requestPayload));\n\t\t\t});\n\n\t\treturn requestInstance$.pipe(\n\t\t\tfinalize(() => {\n\t\t\t\t/**\n\t\t\t\t * When the subscription is closed by the client before\n\t\t\t\t * request completes abort the axios request.\n\t\t\t\t */\n\t\t\t\tif (!requestInstance$.isStopped) {\n\t\t\t\t\tcontroller.abort(EKvHttpStatusCode.CLI_CLOSED_REQUEST);\n\t\t\t\t}\n\t\t\t})\n\t\t);\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/adapters/http/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC","sourcesContent":["export * from './types';\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IKvHttpRequest, IKvHttpRequestOptions } from '@kelvininc/js-client-sdk';
|
|
2
|
+
import { KvRequestAbortController } from '../../classes';
|
|
3
|
+
export interface IKvWebHttpRequestOptions extends IKvHttpRequestOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Use this option if you plan to handle manually the request abortion
|
|
6
|
+
*/
|
|
7
|
+
requestController?: KvRequestAbortController;
|
|
8
|
+
}
|
|
9
|
+
export interface IKvWebHttpRequest extends IKvHttpRequest {
|
|
10
|
+
options?: IKvWebHttpRequestOptions;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/adapters/http/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n\tIKvHttpRequest,\n\tIKvHttpRequestOptions\n} from '@kelvininc/js-client-sdk';\n\nimport { KvRequestAbortController } from '../../classes';\n\nexport interface IKvWebHttpRequestOptions extends IKvHttpRequestOptions {\n\t/**\n\t * Use this option if you plan to handle manually the request abortion\n\t */\n\trequestController?: KvRequestAbortController;\n}\n\nexport interface IKvWebHttpRequest extends IKvHttpRequest {\n\toptions?: IKvWebHttpRequestOptions;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './request-abort-controller';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/classes/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC","sourcesContent":["export * from './request-abort-controller';\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EKvHttpStatusCode } from '@kelvininc/js-client-sdk';
|
|
2
|
+
import { v4 as uuid } from 'uuid';
|
|
3
|
+
export class KvRequestAbortController {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.requestId = uuid();
|
|
6
|
+
}
|
|
7
|
+
getId() {
|
|
8
|
+
return this.requestId;
|
|
9
|
+
}
|
|
10
|
+
setAbortController(controller) {
|
|
11
|
+
this.abortController = controller;
|
|
12
|
+
}
|
|
13
|
+
cancel() {
|
|
14
|
+
var _a;
|
|
15
|
+
(_a = this.abortController) === null || _a === void 0 ? void 0 : _a.abort(EKvHttpStatusCode.CLI_CLOSED_REQUEST);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=request-abort-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-abort-controller.js","sourceRoot":"","sources":["../../../src/classes/request-abort-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,MAAM,OAAO,wBAAwB;IAIpC;QACC,IAAI,CAAC,SAAS,GAAG,IAAI,EAAE,CAAC;IACzB,CAAC;IAED,KAAK;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED,kBAAkB,CAAC,UAA2B;QAC7C,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC;IACnC,CAAC;IAED,MAAM;;QACL,MAAA,IAAI,CAAC,eAAe,0CAAE,KAAK,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;IACnE,CAAC;CACD","sourcesContent":["import { EKvHttpStatusCode } from '@kelvininc/js-client-sdk';\nimport { v4 as uuid } from 'uuid';\n\nexport class KvRequestAbortController {\n\tprivate requestId: string;\n\tprivate abortController: AbortController;\n\n\tconstructor() {\n\t\tthis.requestId = uuid();\n\t}\n\n\tgetId() {\n\t\treturn this.requestId;\n\t}\n\n\tsetAbortController(controller: AbortController) {\n\t\tthis.abortController = controller;\n\t}\n\n\tcancel() {\n\t\tthis.abortController?.abort(EKvHttpStatusCode.CLI_CLOSED_REQUEST);\n\t}\n}\n"]}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,eAAe,SAAS,CAAC","sourcesContent":["import { KelvinSDK } from './kelvin-web-sdk';\nexport * from '@kelvininc/js-client-sdk';\nexport default KelvinSDK;\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,eAAe,SAAS,CAAC","sourcesContent":["import { KelvinSDK } from './kelvin-web-sdk';\nexport * from '@kelvininc/js-client-sdk';\nexport * from './adapters/http';\nexport * from './classes';\nexport default KelvinSDK;\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setSession, init as initKelvinCore } from '@kelvininc/js-client-sdk';
|
|
2
|
-
import { HttpAdapter } from './adapters/http-adapter';
|
|
2
|
+
import { HttpAdapter } from './adapters/http/http-adapter';
|
|
3
3
|
import { StorageAdapter } from './adapters/storage-adapter';
|
|
4
4
|
export class KelvinSDK {
|
|
5
5
|
static initialize(configuration, httpClient) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kelvin-web-sdk.js","sourceRoot":"","sources":["../../src/kelvin-web-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,UAAU,EACV,IAAI,IAAI,cAAc,EACtB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"kelvin-web-sdk.js","sourceRoot":"","sources":["../../src/kelvin-web-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,UAAU,EACV,IAAI,IAAI,cAAc,EACtB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,MAAM,OAAO,SAAS;IACrB,MAAM,CAAC,UAAU,CAChB,aAAmC,EACnC,UAAyB;QAEzB,cAAc,iCACV,aAAa,KAChB,WAAW,EAAE,IAAI,WAAW,CAAC,UAAU,CAAC,EACxC,cAAc,EAAE,IAAI,cAAc,EAAE,IACnC,CAAC;IACJ,CAAC;IAED;;;OAGG;IAEH,MAAM,CAAC,uBAAuB,CAAC,aAA6B;QAC3D,UAAU,CAAC,aAAa,CAAC,CAAC;IAC3B,CAAC;CACD","sourcesContent":["import {\n\tIKvEnvironmentConfig,\n\tISessionConfig,\n\tsetSession,\n\tinit as initKelvinCore\n} from '@kelvininc/js-client-sdk';\nimport { AxiosInstance } from 'axios';\nimport { HttpAdapter } from './adapters/http/http-adapter';\nimport { StorageAdapter } from './adapters/storage-adapter';\n\nexport class KelvinSDK {\n\tstatic initialize(\n\t\tconfiguration: IKvEnvironmentConfig,\n\t\thttpClient: AxiosInstance\n\t) {\n\t\tinitKelvinCore({\n\t\t\t...configuration,\n\t\t\thttpAdapter: new HttpAdapter(httpClient),\n\t\t\tstorageAdapter: new StorageAdapter()\n\t\t});\n\t}\n\n\t/**\n\t * Change the session parameters without an initialization\n\t * @param sessionConfig session configuration data\n\t */\n\n\tstatic setSessionConfiguration(sessionConfig: ISessionConfig) {\n\t\tsetSession(sessionConfig);\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@kelvininc/js-client-sdk/models';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC","sourcesContent":["export * from '@kelvininc/js-client-sdk/models';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kelvininc/web-client-sdk",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.21.0",
|
|
4
4
|
"description": "Kelvin SDK Client for modern frontend Javascript frameworks, like Vue or React",
|
|
5
5
|
"homepage": "https://docs.kelvininc.com",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"kelvin vue/react client"
|
|
11
11
|
],
|
|
12
12
|
"author": {
|
|
13
|
-
"name": "
|
|
13
|
+
"name": "Kelvin Inc.",
|
|
14
14
|
"email": "support@kelvininc.com",
|
|
15
15
|
"url": "https://kelvininc.com"
|
|
16
16
|
},
|
|
@@ -20,6 +20,18 @@
|
|
|
20
20
|
},
|
|
21
21
|
"main": "dist/cjs/index.js",
|
|
22
22
|
"module": "dist/esm/index.js",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"require": "./dist/cjs/index.js",
|
|
26
|
+
"import": "./dist/esm/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./models": {
|
|
30
|
+
"require": "./dist/cjs/models.js",
|
|
31
|
+
"import": "./dist/esm/models.js",
|
|
32
|
+
"types": "./dist/esm/models.d.ts"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
23
35
|
"files": [
|
|
24
36
|
"dist"
|
|
25
37
|
],
|
|
@@ -28,22 +40,32 @@
|
|
|
28
40
|
"build:webpack": "rm -rf dist && webpack",
|
|
29
41
|
"lint:fix": "tslint -p tsconfig.json --fix",
|
|
30
42
|
"tslint": "tslint",
|
|
31
|
-
"build": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json"
|
|
43
|
+
"build": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json",
|
|
44
|
+
"build:watch": "tsc -p tsconfig.json --watch",
|
|
45
|
+
"test": "jest -c jest.config.js --no-cache",
|
|
46
|
+
"test:watch": "jest -c jest.config.js --watch",
|
|
47
|
+
"test:coverage": "jest -c jest.config.js --coverage"
|
|
32
48
|
},
|
|
33
49
|
"dependencies": {
|
|
34
|
-
"@kelvininc/js-client-sdk": "^7.
|
|
35
|
-
"qs": "6.10.3"
|
|
50
|
+
"@kelvininc/js-client-sdk": "^7.21.0",
|
|
51
|
+
"qs": "6.10.3",
|
|
52
|
+
"uuid": "9.0.0"
|
|
36
53
|
},
|
|
37
54
|
"devDependencies": {
|
|
38
55
|
"@types/axios": "^0.14.0",
|
|
56
|
+
"@types/jest": "^29.2.5",
|
|
57
|
+
"axios": "~1.2.2",
|
|
58
|
+
"jest": "^29.3.1",
|
|
59
|
+
"jest-environment-jsdom": "^29.3.1",
|
|
39
60
|
"rxjs": "~6.6.7",
|
|
61
|
+
"ts-jest": "29.0.4",
|
|
40
62
|
"tslint": "^6.1.3",
|
|
41
63
|
"tslint-defocus": "^2.0.6",
|
|
42
|
-
"typescript": "^4.
|
|
64
|
+
"typescript": "^4.6.4"
|
|
43
65
|
},
|
|
44
66
|
"peerDependencies": {
|
|
45
|
-
"axios": "
|
|
67
|
+
"axios": ">=1.0.0",
|
|
46
68
|
"rxjs": "~6.6.7"
|
|
47
69
|
},
|
|
48
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "fbe0f93f29d4f423b20574095f83ed8b527fee39"
|
|
49
71
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { IKvHttpAdapter, IKvHttpRequest, IKvHttpResponse } from '@kelvininc/js-client-sdk';
|
|
2
|
-
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
|
3
|
-
import { Observable } from 'rxjs';
|
|
4
|
-
export declare class HttpAdapter implements IKvHttpAdapter {
|
|
5
|
-
private httpClient;
|
|
6
|
-
constructor(httpClient: AxiosInstance);
|
|
7
|
-
request(requestPayload: IKvHttpRequest): Observable<IKvHttpResponse>;
|
|
8
|
-
handleError(err: AxiosError, config: IKvHttpRequest): IKvHttpResponse | AxiosError;
|
|
9
|
-
handleRequest(response: AxiosResponse, isChunked: boolean, config: IKvHttpRequest): IKvHttpResponse;
|
|
10
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpAdapter = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const js_client_sdk_1 = require("@kelvininc/js-client-sdk");
|
|
6
|
-
const rxjs_1 = require("rxjs");
|
|
7
|
-
const qs_1 = tslib_1.__importDefault(require("qs"));
|
|
8
|
-
class HttpAdapter {
|
|
9
|
-
constructor(httpClient) {
|
|
10
|
-
this.httpClient = httpClient;
|
|
11
|
-
}
|
|
12
|
-
request(requestPayload) {
|
|
13
|
-
var _a;
|
|
14
|
-
const { method, url, data, headers, params, mediaType } = requestPayload;
|
|
15
|
-
const isChunked = mediaType === js_client_sdk_1.EKvHttpMediaType.jsonStream;
|
|
16
|
-
const responseType = js_client_sdk_1.getResponseType(mediaType);
|
|
17
|
-
if (data instanceof FormData) {
|
|
18
|
-
headers['Content-Type'] = 'multipart/form-data';
|
|
19
|
-
}
|
|
20
|
-
let mappedRequestPayload = {
|
|
21
|
-
method,
|
|
22
|
-
url,
|
|
23
|
-
headers,
|
|
24
|
-
data,
|
|
25
|
-
responseType,
|
|
26
|
-
params,
|
|
27
|
-
paramsSerializer: (paramsToSerialize) => {
|
|
28
|
-
return qs_1.default.stringify(paramsToSerialize, { arrayFormat: 'comma' });
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const requestInstance$ = new rxjs_1.Subject();
|
|
32
|
-
if ((_a = requestPayload.options) === null || _a === void 0 ? void 0 : _a.reportProgress) {
|
|
33
|
-
mappedRequestPayload = Object.assign(Object.assign({}, mappedRequestPayload), { onDownloadProgress: (progress) => {
|
|
34
|
-
requestInstance$.next({
|
|
35
|
-
httpResponse: progress,
|
|
36
|
-
type: js_client_sdk_1.EKvHttpResponseType.DownloadProgress,
|
|
37
|
-
config: requestPayload
|
|
38
|
-
});
|
|
39
|
-
}, onUploadProgress: (progress) => {
|
|
40
|
-
requestInstance$.next({
|
|
41
|
-
httpResponse: progress,
|
|
42
|
-
type: js_client_sdk_1.EKvHttpResponseType.UploadProgress,
|
|
43
|
-
config: requestPayload
|
|
44
|
-
});
|
|
45
|
-
} });
|
|
46
|
-
}
|
|
47
|
-
this.httpClient.request(mappedRequestPayload)
|
|
48
|
-
.then((response) => {
|
|
49
|
-
requestInstance$.next(this.handleRequest(response, isChunked, requestPayload));
|
|
50
|
-
requestInstance$.complete();
|
|
51
|
-
})
|
|
52
|
-
.catch((error) => {
|
|
53
|
-
requestInstance$.error(this.handleError(error, requestPayload));
|
|
54
|
-
});
|
|
55
|
-
return requestInstance$;
|
|
56
|
-
}
|
|
57
|
-
handleError(err, config) {
|
|
58
|
-
var _a, _b;
|
|
59
|
-
const error = err
|
|
60
|
-
? {
|
|
61
|
-
type: js_client_sdk_1.EKvHttpResponseType.Response,
|
|
62
|
-
status: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
|
|
63
|
-
statusText: err.message,
|
|
64
|
-
headers: (_b = err.response) === null || _b === void 0 ? void 0 : _b.headers,
|
|
65
|
-
config,
|
|
66
|
-
httpResponse: err.response
|
|
67
|
-
}
|
|
68
|
-
: err;
|
|
69
|
-
return error;
|
|
70
|
-
}
|
|
71
|
-
handleRequest(response, isChunked, config) {
|
|
72
|
-
const { data, status, statusText, headers } = response;
|
|
73
|
-
let bodyParsed = data;
|
|
74
|
-
/**
|
|
75
|
-
* typeof bodyParsed == 'string' fixes a bug when the stream
|
|
76
|
-
* comes with only one array the axios framework parses it automatically
|
|
77
|
-
*/
|
|
78
|
-
if (isChunked && typeof bodyParsed === 'string') {
|
|
79
|
-
try {
|
|
80
|
-
bodyParsed = bodyParsed ? JSON.parse(data.replace(/\]\n\[/g, ',')) : [];
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
console.error('Error during parsing chunk data', error);
|
|
84
|
-
bodyParsed = [];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
type: js_client_sdk_1.EKvHttpResponseType.Response,
|
|
89
|
-
body: bodyParsed,
|
|
90
|
-
status,
|
|
91
|
-
statusText,
|
|
92
|
-
headers,
|
|
93
|
-
config,
|
|
94
|
-
httpResponse: event
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.HttpAdapter = HttpAdapter;
|
|
99
|
-
//# sourceMappingURL=http-adapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-adapter.js","sourceRoot":"","sources":["../../../src/adapters/http-adapter.ts"],"names":[],"mappings":"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","sourcesContent":["import { EKvHttpMediaType, EKvHttpResponseType, getResponseType, IKvHttpAdapter, IKvHttpRequest, IKvHttpResponse } from '@kelvininc/js-client-sdk';\nimport { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';\nimport { Observable, Subject } from 'rxjs';\nimport qs from 'qs';\n\nexport class HttpAdapter implements IKvHttpAdapter {\n\n\tconstructor(private httpClient: AxiosInstance) { }\n\n\trequest(requestPayload: IKvHttpRequest): Observable<IKvHttpResponse> {\n\t\tconst { method, url, data, headers, params, mediaType } = requestPayload;\n\t\tconst isChunked = mediaType === EKvHttpMediaType.jsonStream;\n\t\tconst responseType = getResponseType(mediaType);\n\n\t\tif (data instanceof FormData) {\n\t\t\theaders['Content-Type'] = 'multipart/form-data';\n\t\t}\n\n\t\tlet mappedRequestPayload: AxiosRequestConfig = {\n\t\t\tmethod,\n\t\t\turl,\n\t\t\theaders,\n\t\t\tdata,\n\t\t\tresponseType,\n\t\t\tparams,\n\t\t\tparamsSerializer: (paramsToSerialize) => {\n\t\t\t\treturn qs.stringify(paramsToSerialize, { arrayFormat: 'comma' });\n\t\t\t}\n\t\t};\n\n\t\tconst requestInstance$ = new Subject<IKvHttpResponse>();\n\t\tif (requestPayload.options?.reportProgress) {\n\t\t\tmappedRequestPayload = {\n\t\t\t\t...mappedRequestPayload,\n\t\t\t\tonDownloadProgress: (progress) => {\n\t\t\t\t\trequestInstance$.next({\n\t\t\t\t\t\thttpResponse: progress,\n\t\t\t\t\t\ttype: EKvHttpResponseType.DownloadProgress,\n\t\t\t\t\t\tconfig: requestPayload\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tonUploadProgress: (progress) => {\n\t\t\t\t\trequestInstance$.next({\n\t\t\t\t\t\thttpResponse: progress,\n\t\t\t\t\t\ttype: EKvHttpResponseType.UploadProgress,\n\t\t\t\t\t\tconfig: requestPayload\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\tthis.httpClient.request(mappedRequestPayload)\n\t\t\t.then((response: AxiosResponse) => {\n\t\t\t\trequestInstance$.next(this.handleRequest(response, isChunked, requestPayload));\n\t\t\t\trequestInstance$.complete();\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\trequestInstance$.error(this.handleError(error, requestPayload));\n\t\t\t});\n\t\treturn requestInstance$;\n\t}\n\n\thandleError(err: AxiosError, config: IKvHttpRequest): IKvHttpResponse | AxiosError {\n\t\tconst error = err\n\t\t\t? {\n\t\t\t\ttype: EKvHttpResponseType.Response,\n\t\t\t\tstatus: err.response?.status,\n\t\t\t\tstatusText: err.message,\n\t\t\t\theaders: err.response?.headers,\n\t\t\t\tconfig,\n\t\t\t\thttpResponse: err.response\n\t\t\t}\n\t\t\t: err;\n\n\t\treturn error;\n\t}\n\n\thandleRequest(response: AxiosResponse, isChunked: boolean, config: IKvHttpRequest): IKvHttpResponse {\n\t\tconst { data, status, statusText, headers } = response;\n\t\tlet bodyParsed = data;\n\t\t/**\n\t\t * typeof bodyParsed == 'string' fixes a bug when the stream\n\t\t * comes with only one array the axios framework parses it automatically\n\t\t */\n\t\tif (isChunked && typeof bodyParsed === 'string') {\n\t\t\ttry {\n\t\t\t\tbodyParsed = bodyParsed ? JSON.parse(data.replace(/\\]\\n\\[/g, ',')) : [];\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error during parsing chunk data', error);\n\t\t\t\tbodyParsed = [];\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\ttype: EKvHttpResponseType.Response,\n\t\t\tbody: bodyParsed,\n\t\t\tstatus,\n\t\t\tstatusText,\n\t\t\theaders,\n\t\t\tconfig,\n\t\t\thttpResponse: event\n\t\t};\n\t}\n}\n"]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { IKvHttpAdapter, IKvHttpRequest, IKvHttpResponse } from '@kelvininc/js-client-sdk';
|
|
2
|
-
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
|
3
|
-
import { Observable } from 'rxjs';
|
|
4
|
-
export declare class HttpAdapter implements IKvHttpAdapter {
|
|
5
|
-
private httpClient;
|
|
6
|
-
constructor(httpClient: AxiosInstance);
|
|
7
|
-
request(requestPayload: IKvHttpRequest): Observable<IKvHttpResponse>;
|
|
8
|
-
handleError(err: AxiosError, config: IKvHttpRequest): IKvHttpResponse | AxiosError;
|
|
9
|
-
handleRequest(response: AxiosResponse, isChunked: boolean, config: IKvHttpRequest): IKvHttpResponse;
|
|
10
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { EKvHttpMediaType, EKvHttpResponseType, getResponseType } from '@kelvininc/js-client-sdk';
|
|
2
|
-
import { Subject } from 'rxjs';
|
|
3
|
-
import qs from 'qs';
|
|
4
|
-
export class HttpAdapter {
|
|
5
|
-
constructor(httpClient) {
|
|
6
|
-
this.httpClient = httpClient;
|
|
7
|
-
}
|
|
8
|
-
request(requestPayload) {
|
|
9
|
-
var _a;
|
|
10
|
-
const { method, url, data, headers, params, mediaType } = requestPayload;
|
|
11
|
-
const isChunked = mediaType === EKvHttpMediaType.jsonStream;
|
|
12
|
-
const responseType = getResponseType(mediaType);
|
|
13
|
-
if (data instanceof FormData) {
|
|
14
|
-
headers['Content-Type'] = 'multipart/form-data';
|
|
15
|
-
}
|
|
16
|
-
let mappedRequestPayload = {
|
|
17
|
-
method,
|
|
18
|
-
url,
|
|
19
|
-
headers,
|
|
20
|
-
data,
|
|
21
|
-
responseType,
|
|
22
|
-
params,
|
|
23
|
-
paramsSerializer: (paramsToSerialize) => {
|
|
24
|
-
return qs.stringify(paramsToSerialize, { arrayFormat: 'comma' });
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const requestInstance$ = new Subject();
|
|
28
|
-
if ((_a = requestPayload.options) === null || _a === void 0 ? void 0 : _a.reportProgress) {
|
|
29
|
-
mappedRequestPayload = Object.assign(Object.assign({}, mappedRequestPayload), { onDownloadProgress: (progress) => {
|
|
30
|
-
requestInstance$.next({
|
|
31
|
-
httpResponse: progress,
|
|
32
|
-
type: EKvHttpResponseType.DownloadProgress,
|
|
33
|
-
config: requestPayload
|
|
34
|
-
});
|
|
35
|
-
}, onUploadProgress: (progress) => {
|
|
36
|
-
requestInstance$.next({
|
|
37
|
-
httpResponse: progress,
|
|
38
|
-
type: EKvHttpResponseType.UploadProgress,
|
|
39
|
-
config: requestPayload
|
|
40
|
-
});
|
|
41
|
-
} });
|
|
42
|
-
}
|
|
43
|
-
this.httpClient.request(mappedRequestPayload)
|
|
44
|
-
.then((response) => {
|
|
45
|
-
requestInstance$.next(this.handleRequest(response, isChunked, requestPayload));
|
|
46
|
-
requestInstance$.complete();
|
|
47
|
-
})
|
|
48
|
-
.catch((error) => {
|
|
49
|
-
requestInstance$.error(this.handleError(error, requestPayload));
|
|
50
|
-
});
|
|
51
|
-
return requestInstance$;
|
|
52
|
-
}
|
|
53
|
-
handleError(err, config) {
|
|
54
|
-
var _a, _b;
|
|
55
|
-
const error = err
|
|
56
|
-
? {
|
|
57
|
-
type: EKvHttpResponseType.Response,
|
|
58
|
-
status: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
|
|
59
|
-
statusText: err.message,
|
|
60
|
-
headers: (_b = err.response) === null || _b === void 0 ? void 0 : _b.headers,
|
|
61
|
-
config,
|
|
62
|
-
httpResponse: err.response
|
|
63
|
-
}
|
|
64
|
-
: err;
|
|
65
|
-
return error;
|
|
66
|
-
}
|
|
67
|
-
handleRequest(response, isChunked, config) {
|
|
68
|
-
const { data, status, statusText, headers } = response;
|
|
69
|
-
let bodyParsed = data;
|
|
70
|
-
/**
|
|
71
|
-
* typeof bodyParsed == 'string' fixes a bug when the stream
|
|
72
|
-
* comes with only one array the axios framework parses it automatically
|
|
73
|
-
*/
|
|
74
|
-
if (isChunked && typeof bodyParsed === 'string') {
|
|
75
|
-
try {
|
|
76
|
-
bodyParsed = bodyParsed ? JSON.parse(data.replace(/\]\n\[/g, ',')) : [];
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
console.error('Error during parsing chunk data', error);
|
|
80
|
-
bodyParsed = [];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
type: EKvHttpResponseType.Response,
|
|
85
|
-
body: bodyParsed,
|
|
86
|
-
status,
|
|
87
|
-
statusText,
|
|
88
|
-
headers,
|
|
89
|
-
config,
|
|
90
|
-
httpResponse: event
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=http-adapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-adapter.js","sourceRoot":"","sources":["../../../src/adapters/http-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,eAAe,EAAmD,MAAM,0BAA0B,CAAC;AAEnJ,OAAO,EAAc,OAAO,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,OAAO,WAAW;IAEvB,YAAoB,UAAyB;QAAzB,eAAU,GAAV,UAAU,CAAe;IAAI,CAAC;IAElD,OAAO,CAAC,cAA8B;;QACrC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,cAAc,CAAC;QACzE,MAAM,SAAS,GAAG,SAAS,KAAK,gBAAgB,CAAC,UAAU,CAAC;QAC5D,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QAEhD,IAAI,IAAI,YAAY,QAAQ,EAAE;YAC7B,OAAO,CAAC,cAAc,CAAC,GAAG,qBAAqB,CAAC;SAChD;QAED,IAAI,oBAAoB,GAAuB;YAC9C,MAAM;YACN,GAAG;YACH,OAAO;YACP,IAAI;YACJ,YAAY;YACZ,MAAM;YACN,gBAAgB,EAAE,CAAC,iBAAiB,EAAE,EAAE;gBACvC,OAAO,EAAE,CAAC,SAAS,CAAC,iBAAiB,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC;YAClE,CAAC;SACD,CAAC;QAEF,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAAmB,CAAC;QACxD,UAAI,cAAc,CAAC,OAAO,0CAAE,cAAc,EAAE;YAC3C,oBAAoB,mCAChB,oBAAoB,KACvB,kBAAkB,EAAE,CAAC,QAAQ,EAAE,EAAE;oBAChC,gBAAgB,CAAC,IAAI,CAAC;wBACrB,YAAY,EAAE,QAAQ;wBACtB,IAAI,EAAE,mBAAmB,CAAC,gBAAgB;wBAC1C,MAAM,EAAE,cAAc;qBACtB,CAAC,CAAC;gBACJ,CAAC,EACD,gBAAgB,EAAE,CAAC,QAAQ,EAAE,EAAE;oBAC9B,gBAAgB,CAAC,IAAI,CAAC;wBACrB,YAAY,EAAE,QAAQ;wBACtB,IAAI,EAAE,mBAAmB,CAAC,cAAc;wBACxC,MAAM,EAAE,cAAc;qBACtB,CAAC,CAAC;gBACJ,CAAC,GACD,CAAC;SACF;QAED,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,oBAAoB,CAAC;aAC3C,IAAI,CAAC,CAAC,QAAuB,EAAE,EAAE;YACjC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;YAC/E,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAC7B,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAChB,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;QACJ,OAAO,gBAAgB,CAAC;IACzB,CAAC;IAED,WAAW,CAAC,GAAe,EAAE,MAAsB;;QAClD,MAAM,KAAK,GAAG,GAAG;YAChB,CAAC,CAAC;gBACD,IAAI,EAAE,mBAAmB,CAAC,QAAQ;gBAClC,MAAM,QAAE,GAAG,CAAC,QAAQ,0CAAE,MAAM;gBAC5B,UAAU,EAAE,GAAG,CAAC,OAAO;gBACvB,OAAO,QAAE,GAAG,CAAC,QAAQ,0CAAE,OAAO;gBAC9B,MAAM;gBACN,YAAY,EAAE,GAAG,CAAC,QAAQ;aAC1B;YACD,CAAC,CAAC,GAAG,CAAC;QAEP,OAAO,KAAK,CAAC;IACd,CAAC;IAED,aAAa,CAAC,QAAuB,EAAE,SAAkB,EAAE,MAAsB;QAChF,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;QACvD,IAAI,UAAU,GAAG,IAAI,CAAC;QACtB;;;WAGG;QACH,IAAI,SAAS,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YAChD,IAAI;gBACH,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;aACxE;YAAC,OAAO,KAAK,EAAE;gBACf,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;gBACxD,UAAU,GAAG,EAAE,CAAC;aAChB;SACD;QAED,OAAO;YACN,IAAI,EAAE,mBAAmB,CAAC,QAAQ;YAClC,IAAI,EAAE,UAAU;YAChB,MAAM;YACN,UAAU;YACV,OAAO;YACP,MAAM;YACN,YAAY,EAAE,KAAK;SACnB,CAAC;IACH,CAAC;CACD","sourcesContent":["import { EKvHttpMediaType, EKvHttpResponseType, getResponseType, IKvHttpAdapter, IKvHttpRequest, IKvHttpResponse } from '@kelvininc/js-client-sdk';\nimport { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';\nimport { Observable, Subject } from 'rxjs';\nimport qs from 'qs';\n\nexport class HttpAdapter implements IKvHttpAdapter {\n\n\tconstructor(private httpClient: AxiosInstance) { }\n\n\trequest(requestPayload: IKvHttpRequest): Observable<IKvHttpResponse> {\n\t\tconst { method, url, data, headers, params, mediaType } = requestPayload;\n\t\tconst isChunked = mediaType === EKvHttpMediaType.jsonStream;\n\t\tconst responseType = getResponseType(mediaType);\n\n\t\tif (data instanceof FormData) {\n\t\t\theaders['Content-Type'] = 'multipart/form-data';\n\t\t}\n\n\t\tlet mappedRequestPayload: AxiosRequestConfig = {\n\t\t\tmethod,\n\t\t\turl,\n\t\t\theaders,\n\t\t\tdata,\n\t\t\tresponseType,\n\t\t\tparams,\n\t\t\tparamsSerializer: (paramsToSerialize) => {\n\t\t\t\treturn qs.stringify(paramsToSerialize, { arrayFormat: 'comma' });\n\t\t\t}\n\t\t};\n\n\t\tconst requestInstance$ = new Subject<IKvHttpResponse>();\n\t\tif (requestPayload.options?.reportProgress) {\n\t\t\tmappedRequestPayload = {\n\t\t\t\t...mappedRequestPayload,\n\t\t\t\tonDownloadProgress: (progress) => {\n\t\t\t\t\trequestInstance$.next({\n\t\t\t\t\t\thttpResponse: progress,\n\t\t\t\t\t\ttype: EKvHttpResponseType.DownloadProgress,\n\t\t\t\t\t\tconfig: requestPayload\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tonUploadProgress: (progress) => {\n\t\t\t\t\trequestInstance$.next({\n\t\t\t\t\t\thttpResponse: progress,\n\t\t\t\t\t\ttype: EKvHttpResponseType.UploadProgress,\n\t\t\t\t\t\tconfig: requestPayload\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\tthis.httpClient.request(mappedRequestPayload)\n\t\t\t.then((response: AxiosResponse) => {\n\t\t\t\trequestInstance$.next(this.handleRequest(response, isChunked, requestPayload));\n\t\t\t\trequestInstance$.complete();\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\trequestInstance$.error(this.handleError(error, requestPayload));\n\t\t\t});\n\t\treturn requestInstance$;\n\t}\n\n\thandleError(err: AxiosError, config: IKvHttpRequest): IKvHttpResponse | AxiosError {\n\t\tconst error = err\n\t\t\t? {\n\t\t\t\ttype: EKvHttpResponseType.Response,\n\t\t\t\tstatus: err.response?.status,\n\t\t\t\tstatusText: err.message,\n\t\t\t\theaders: err.response?.headers,\n\t\t\t\tconfig,\n\t\t\t\thttpResponse: err.response\n\t\t\t}\n\t\t\t: err;\n\n\t\treturn error;\n\t}\n\n\thandleRequest(response: AxiosResponse, isChunked: boolean, config: IKvHttpRequest): IKvHttpResponse {\n\t\tconst { data, status, statusText, headers } = response;\n\t\tlet bodyParsed = data;\n\t\t/**\n\t\t * typeof bodyParsed == 'string' fixes a bug when the stream\n\t\t * comes with only one array the axios framework parses it automatically\n\t\t */\n\t\tif (isChunked && typeof bodyParsed === 'string') {\n\t\t\ttry {\n\t\t\t\tbodyParsed = bodyParsed ? JSON.parse(data.replace(/\\]\\n\\[/g, ',')) : [];\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error during parsing chunk data', error);\n\t\t\t\tbodyParsed = [];\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\ttype: EKvHttpResponseType.Response,\n\t\t\tbody: bodyParsed,\n\t\t\tstatus,\n\t\t\tstatusText,\n\t\t\theaders,\n\t\t\tconfig,\n\t\t\thttpResponse: event\n\t\t};\n\t}\n}\n"]}
|