@kontent-ai/core-sdk 10.2.0 → 10.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +14 -14
- package/LICENSE.md +9 -9
- package/README.md +30 -30
- package/dist/cjs/sdk-info.generated.js +1 -1
- package/dist/es6/sdk-info.generated.js +1 -1
- package/dist/esnext/sdk-info.generated.js +1 -1
- package/dist/umd/kontent-core.umd.js +229 -205
- package/dist/umd/kontent-core.umd.js.map +1 -1
- package/dist/umd/kontent-core.umd.min.js +1 -1
- package/dist/umd/kontent-core.umd.min.js.map +1 -1
- package/dist/umd/report.json +1 -1
- package/dist/umd/report.min.json +1 -1
- package/dist/umd/stats.json +446 -446
- package/dist/umd/stats.min.json +438 -438
- package/lib/helpers/header.helper.ts +23 -23
- package/lib/helpers/headers-helper.ts +15 -15
- package/lib/helpers/index.ts +4 -4
- package/lib/helpers/retry-helper.ts +204 -204
- package/lib/helpers/url.helper.ts +26 -26
- package/lib/http/http.debugger.ts +21 -21
- package/lib/http/http.functions.ts +312 -312
- package/lib/http/http.models.ts +83 -83
- package/lib/http/http.service.ts +91 -91
- package/lib/http/ihttp.service.ts +20 -20
- package/lib/http/index.ts +6 -6
- package/lib/http/test-http.service.ts +70 -70
- package/lib/index.ts +4 -4
- package/lib/models/index.ts +3 -3
- package/lib/models/isdk-info.ts +15 -15
- package/lib/models/parameters.ts +25 -25
- package/lib/models/url.models.ts +3 -3
- package/lib/sdk-info.generated.ts +1 -1
- package/package.json +88 -88
package/lib/http/http.models.ts
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { ResponseType } from 'axios';
|
|
2
|
-
|
|
3
|
-
export interface IResponseRetryStrategyResult {
|
|
4
|
-
options: IRetryStrategyOptions;
|
|
5
|
-
retryAttempts: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface IResponse<TRawData> {
|
|
9
|
-
data: TRawData;
|
|
10
|
-
headers: IHeader[];
|
|
11
|
-
rawResponse: any;
|
|
12
|
-
status: number;
|
|
13
|
-
retryStrategy: IResponseRetryStrategyResult;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface IRetryStrategyOptions {
|
|
17
|
-
/**
|
|
18
|
-
* back-off interval between retries
|
|
19
|
-
*/
|
|
20
|
-
deltaBackoffMs?: number;
|
|
21
|
-
/**
|
|
22
|
-
* Maximum allowed number of attempts
|
|
23
|
-
*/
|
|
24
|
-
maxAttempts?: number;
|
|
25
|
-
/**
|
|
26
|
-
* Indicates if jitter is added to retry
|
|
27
|
-
*/
|
|
28
|
-
addJitter?: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Determines if error can be retried. There are errors that are never retried
|
|
31
|
-
* such as when request is cancelled or the response status is 404 and so on...
|
|
32
|
-
*/
|
|
33
|
-
canRetryError?: (error: any) => boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface IHttpQueryCall {
|
|
37
|
-
url: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface IHttpPostQueryCall extends IHttpQueryCall {
|
|
41
|
-
body: any;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface IHttpPutQueryCall extends IHttpQueryCall {
|
|
45
|
-
body: any;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface IHttpPatchQueryCall extends IHttpQueryCall {
|
|
49
|
-
body: any;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface IHttpDeleteQueryCall extends IHttpQueryCall {}
|
|
53
|
-
|
|
54
|
-
export interface IHttpGetQueryCall extends IHttpQueryCall {}
|
|
55
|
-
|
|
56
|
-
export interface IHttpCancelRequestToken<TCancelToken> {
|
|
57
|
-
token: TCancelToken;
|
|
58
|
-
cancel: (cancelMessage?: string) => void;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface IHttpQueryOptions<TCancelToken> {
|
|
62
|
-
/**
|
|
63
|
-
* retry strategy
|
|
64
|
-
*/
|
|
65
|
-
retryStrategy?: IRetryStrategyOptions;
|
|
66
|
-
/**
|
|
67
|
-
* Request headers
|
|
68
|
-
*/
|
|
69
|
-
headers?: IHeader[];
|
|
70
|
-
/**
|
|
71
|
-
* Response type
|
|
72
|
-
*/
|
|
73
|
-
responseType?: ResponseType;
|
|
74
|
-
/**
|
|
75
|
-
* Cancel token
|
|
76
|
-
*/
|
|
77
|
-
cancelToken?: IHttpCancelRequestToken<TCancelToken>;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export interface IHeader {
|
|
81
|
-
header: string;
|
|
82
|
-
value: string;
|
|
83
|
-
}
|
|
1
|
+
import { ResponseType } from 'axios';
|
|
2
|
+
|
|
3
|
+
export interface IResponseRetryStrategyResult {
|
|
4
|
+
options: IRetryStrategyOptions;
|
|
5
|
+
retryAttempts: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface IResponse<TRawData> {
|
|
9
|
+
data: TRawData;
|
|
10
|
+
headers: IHeader[];
|
|
11
|
+
rawResponse: any;
|
|
12
|
+
status: number;
|
|
13
|
+
retryStrategy: IResponseRetryStrategyResult;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface IRetryStrategyOptions {
|
|
17
|
+
/**
|
|
18
|
+
* back-off interval between retries
|
|
19
|
+
*/
|
|
20
|
+
deltaBackoffMs?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Maximum allowed number of attempts
|
|
23
|
+
*/
|
|
24
|
+
maxAttempts?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Indicates if jitter is added to retry
|
|
27
|
+
*/
|
|
28
|
+
addJitter?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Determines if error can be retried. There are errors that are never retried
|
|
31
|
+
* such as when request is cancelled or the response status is 404 and so on...
|
|
32
|
+
*/
|
|
33
|
+
canRetryError?: (error: any) => boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface IHttpQueryCall {
|
|
37
|
+
url: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface IHttpPostQueryCall extends IHttpQueryCall {
|
|
41
|
+
body: any;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface IHttpPutQueryCall extends IHttpQueryCall {
|
|
45
|
+
body: any;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface IHttpPatchQueryCall extends IHttpQueryCall {
|
|
49
|
+
body: any;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface IHttpDeleteQueryCall extends IHttpQueryCall {}
|
|
53
|
+
|
|
54
|
+
export interface IHttpGetQueryCall extends IHttpQueryCall {}
|
|
55
|
+
|
|
56
|
+
export interface IHttpCancelRequestToken<TCancelToken> {
|
|
57
|
+
token: TCancelToken;
|
|
58
|
+
cancel: (cancelMessage?: string) => void;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface IHttpQueryOptions<TCancelToken> {
|
|
62
|
+
/**
|
|
63
|
+
* retry strategy
|
|
64
|
+
*/
|
|
65
|
+
retryStrategy?: IRetryStrategyOptions;
|
|
66
|
+
/**
|
|
67
|
+
* Request headers
|
|
68
|
+
*/
|
|
69
|
+
headers?: IHeader[];
|
|
70
|
+
/**
|
|
71
|
+
* Response type
|
|
72
|
+
*/
|
|
73
|
+
responseType?: ResponseType;
|
|
74
|
+
/**
|
|
75
|
+
* Cancel token
|
|
76
|
+
*/
|
|
77
|
+
cancelToken?: IHttpCancelRequestToken<TCancelToken>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface IHeader {
|
|
81
|
+
header: string;
|
|
82
|
+
value: string;
|
|
83
|
+
}
|
package/lib/http/http.service.ts
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import axios, { AxiosInstance, AxiosRequestConfig, CancelToken } from 'axios';
|
|
2
|
-
|
|
3
|
-
import * as HttpFunctions from './http.functions';
|
|
4
|
-
import { IHttpFunctionsConfig } from './http.functions';
|
|
5
|
-
import {
|
|
6
|
-
IResponse,
|
|
7
|
-
IHttpDeleteQueryCall,
|
|
8
|
-
IHttpGetQueryCall,
|
|
9
|
-
IHttpPatchQueryCall,
|
|
10
|
-
IHttpPostQueryCall,
|
|
11
|
-
IHttpPutQueryCall,
|
|
12
|
-
IHttpQueryOptions,
|
|
13
|
-
IHttpCancelRequestToken
|
|
14
|
-
} from './http.models';
|
|
15
|
-
import { IHttpService } from './ihttp.service';
|
|
16
|
-
|
|
17
|
-
export class HttpService implements IHttpService<CancelToken> {
|
|
18
|
-
private readonly axiosInstance: AxiosInstance;
|
|
19
|
-
|
|
20
|
-
private readonly functionsConfig: IHttpFunctionsConfig;
|
|
21
|
-
|
|
22
|
-
constructor(
|
|
23
|
-
private opts?: {
|
|
24
|
-
axiosRequestConfig?: AxiosRequestConfig;
|
|
25
|
-
logErrorsToConsole?: boolean;
|
|
26
|
-
}
|
|
27
|
-
) {
|
|
28
|
-
this.axiosInstance = axios.create(opts?.axiosRequestConfig);
|
|
29
|
-
this.functionsConfig = this.getFunctionsConfig();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async getAsync<TRawData>(
|
|
33
|
-
call: IHttpGetQueryCall,
|
|
34
|
-
options?: IHttpQueryOptions<CancelToken>
|
|
35
|
-
): Promise<IResponse<TRawData>> {
|
|
36
|
-
return await HttpFunctions.getWithRetryAsync<TRawData>(this.axiosInstance, call, this.functionsConfig, options);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async postAsync<TRawData>(
|
|
40
|
-
call: IHttpPostQueryCall,
|
|
41
|
-
options?: IHttpQueryOptions<CancelToken>
|
|
42
|
-
): Promise<IResponse<TRawData>> {
|
|
43
|
-
return await HttpFunctions.postWithRetryAsync<TRawData>(
|
|
44
|
-
this.axiosInstance,
|
|
45
|
-
call,
|
|
46
|
-
this.functionsConfig,
|
|
47
|
-
options
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async putAsync<TRawData>(
|
|
52
|
-
call: IHttpPutQueryCall,
|
|
53
|
-
options?: IHttpQueryOptions<CancelToken>
|
|
54
|
-
): Promise<IResponse<TRawData>> {
|
|
55
|
-
return await HttpFunctions.putWithRetryAsync<TRawData>(this.axiosInstance, call, this.functionsConfig, options);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async patchAsync<TRawData>(
|
|
59
|
-
call: IHttpPatchQueryCall,
|
|
60
|
-
options?: IHttpQueryOptions<CancelToken>
|
|
61
|
-
): Promise<IResponse<TRawData>> {
|
|
62
|
-
return await HttpFunctions.patchWithRetryAsync<TRawData>(
|
|
63
|
-
this.axiosInstance,
|
|
64
|
-
call,
|
|
65
|
-
this.functionsConfig,
|
|
66
|
-
options
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async deleteAsync<TRawData>(
|
|
71
|
-
call: IHttpDeleteQueryCall,
|
|
72
|
-
options?: IHttpQueryOptions<CancelToken>
|
|
73
|
-
): Promise<IResponse<TRawData>> {
|
|
74
|
-
return await HttpFunctions.deleteWithRetryAsync<TRawData>(
|
|
75
|
-
this.axiosInstance,
|
|
76
|
-
call,
|
|
77
|
-
this.functionsConfig,
|
|
78
|
-
options
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
createCancelToken(): IHttpCancelRequestToken<CancelToken> {
|
|
83
|
-
return HttpFunctions.createCancelToken();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private getFunctionsConfig(): IHttpFunctionsConfig {
|
|
87
|
-
return {
|
|
88
|
-
logErrorsToConsole: this.opts?.logErrorsToConsole ?? true
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
1
|
+
import axios, { AxiosInstance, AxiosRequestConfig, CancelToken } from 'axios';
|
|
2
|
+
|
|
3
|
+
import * as HttpFunctions from './http.functions';
|
|
4
|
+
import { IHttpFunctionsConfig } from './http.functions';
|
|
5
|
+
import {
|
|
6
|
+
IResponse,
|
|
7
|
+
IHttpDeleteQueryCall,
|
|
8
|
+
IHttpGetQueryCall,
|
|
9
|
+
IHttpPatchQueryCall,
|
|
10
|
+
IHttpPostQueryCall,
|
|
11
|
+
IHttpPutQueryCall,
|
|
12
|
+
IHttpQueryOptions,
|
|
13
|
+
IHttpCancelRequestToken
|
|
14
|
+
} from './http.models';
|
|
15
|
+
import { IHttpService } from './ihttp.service';
|
|
16
|
+
|
|
17
|
+
export class HttpService implements IHttpService<CancelToken> {
|
|
18
|
+
private readonly axiosInstance: AxiosInstance;
|
|
19
|
+
|
|
20
|
+
private readonly functionsConfig: IHttpFunctionsConfig;
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
private opts?: {
|
|
24
|
+
axiosRequestConfig?: AxiosRequestConfig;
|
|
25
|
+
logErrorsToConsole?: boolean;
|
|
26
|
+
}
|
|
27
|
+
) {
|
|
28
|
+
this.axiosInstance = axios.create(opts?.axiosRequestConfig);
|
|
29
|
+
this.functionsConfig = this.getFunctionsConfig();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async getAsync<TRawData>(
|
|
33
|
+
call: IHttpGetQueryCall,
|
|
34
|
+
options?: IHttpQueryOptions<CancelToken>
|
|
35
|
+
): Promise<IResponse<TRawData>> {
|
|
36
|
+
return await HttpFunctions.getWithRetryAsync<TRawData>(this.axiosInstance, call, this.functionsConfig, options);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async postAsync<TRawData>(
|
|
40
|
+
call: IHttpPostQueryCall,
|
|
41
|
+
options?: IHttpQueryOptions<CancelToken>
|
|
42
|
+
): Promise<IResponse<TRawData>> {
|
|
43
|
+
return await HttpFunctions.postWithRetryAsync<TRawData>(
|
|
44
|
+
this.axiosInstance,
|
|
45
|
+
call,
|
|
46
|
+
this.functionsConfig,
|
|
47
|
+
options
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async putAsync<TRawData>(
|
|
52
|
+
call: IHttpPutQueryCall,
|
|
53
|
+
options?: IHttpQueryOptions<CancelToken>
|
|
54
|
+
): Promise<IResponse<TRawData>> {
|
|
55
|
+
return await HttpFunctions.putWithRetryAsync<TRawData>(this.axiosInstance, call, this.functionsConfig, options);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async patchAsync<TRawData>(
|
|
59
|
+
call: IHttpPatchQueryCall,
|
|
60
|
+
options?: IHttpQueryOptions<CancelToken>
|
|
61
|
+
): Promise<IResponse<TRawData>> {
|
|
62
|
+
return await HttpFunctions.patchWithRetryAsync<TRawData>(
|
|
63
|
+
this.axiosInstance,
|
|
64
|
+
call,
|
|
65
|
+
this.functionsConfig,
|
|
66
|
+
options
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async deleteAsync<TRawData>(
|
|
71
|
+
call: IHttpDeleteQueryCall,
|
|
72
|
+
options?: IHttpQueryOptions<CancelToken>
|
|
73
|
+
): Promise<IResponse<TRawData>> {
|
|
74
|
+
return await HttpFunctions.deleteWithRetryAsync<TRawData>(
|
|
75
|
+
this.axiosInstance,
|
|
76
|
+
call,
|
|
77
|
+
this.functionsConfig,
|
|
78
|
+
options
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
createCancelToken(): IHttpCancelRequestToken<CancelToken> {
|
|
83
|
+
return HttpFunctions.createCancelToken();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private getFunctionsConfig(): IHttpFunctionsConfig {
|
|
87
|
+
return {
|
|
88
|
+
logErrorsToConsole: this.opts?.logErrorsToConsole ?? true
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IResponse,
|
|
3
|
-
IHttpDeleteQueryCall,
|
|
4
|
-
IHttpGetQueryCall,
|
|
5
|
-
IHttpPostQueryCall,
|
|
6
|
-
IHttpPutQueryCall,
|
|
7
|
-
IHttpQueryOptions,
|
|
8
|
-
IHttpPatchQueryCall,
|
|
9
|
-
IHttpCancelRequestToken,
|
|
10
|
-
} from './http.models';
|
|
11
|
-
|
|
12
|
-
export interface IHttpService<TCancelToken> {
|
|
13
|
-
getAsync<TRawData>(call: IHttpGetQueryCall, options?: IHttpQueryOptions<TCancelToken>): Promise<IResponse<TRawData>>;
|
|
14
|
-
postAsync<TRawData>(call: IHttpPostQueryCall, options?: IHttpQueryOptions<TCancelToken>): Promise<IResponse<TRawData>>;
|
|
15
|
-
putAsync<TRawData>(call: IHttpPutQueryCall, options?: IHttpQueryOptions<TCancelToken>): Promise<IResponse<TRawData>>;
|
|
16
|
-
patchAsync<TRawData>(call: IHttpPatchQueryCall, options?: IHttpQueryOptions<TCancelToken>): Promise<IResponse<TRawData>>;
|
|
17
|
-
deleteAsync<TRawData>(call: IHttpDeleteQueryCall, options?: IHttpQueryOptions<TCancelToken>): Promise<IResponse<TRawData>>;
|
|
18
|
-
|
|
19
|
-
createCancelToken(): IHttpCancelRequestToken<TCancelToken>;
|
|
20
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
IResponse,
|
|
3
|
+
IHttpDeleteQueryCall,
|
|
4
|
+
IHttpGetQueryCall,
|
|
5
|
+
IHttpPostQueryCall,
|
|
6
|
+
IHttpPutQueryCall,
|
|
7
|
+
IHttpQueryOptions,
|
|
8
|
+
IHttpPatchQueryCall,
|
|
9
|
+
IHttpCancelRequestToken,
|
|
10
|
+
} from './http.models';
|
|
11
|
+
|
|
12
|
+
export interface IHttpService<TCancelToken> {
|
|
13
|
+
getAsync<TRawData>(call: IHttpGetQueryCall, options?: IHttpQueryOptions<TCancelToken>): Promise<IResponse<TRawData>>;
|
|
14
|
+
postAsync<TRawData>(call: IHttpPostQueryCall, options?: IHttpQueryOptions<TCancelToken>): Promise<IResponse<TRawData>>;
|
|
15
|
+
putAsync<TRawData>(call: IHttpPutQueryCall, options?: IHttpQueryOptions<TCancelToken>): Promise<IResponse<TRawData>>;
|
|
16
|
+
patchAsync<TRawData>(call: IHttpPatchQueryCall, options?: IHttpQueryOptions<TCancelToken>): Promise<IResponse<TRawData>>;
|
|
17
|
+
deleteAsync<TRawData>(call: IHttpDeleteQueryCall, options?: IHttpQueryOptions<TCancelToken>): Promise<IResponse<TRawData>>;
|
|
18
|
+
|
|
19
|
+
createCancelToken(): IHttpCancelRequestToken<TCancelToken>;
|
|
20
|
+
}
|
package/lib/http/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './ihttp.service';
|
|
2
|
-
export * from './http.service';
|
|
3
|
-
export * from './http.models';
|
|
4
|
-
export * from './http.functions';
|
|
5
|
-
export * from './http.debugger';
|
|
6
|
-
export * from './test-http.service';
|
|
1
|
+
export * from './ihttp.service';
|
|
2
|
+
export * from './http.service';
|
|
3
|
+
export * from './http.models';
|
|
4
|
+
export * from './http.functions';
|
|
5
|
+
export * from './http.debugger';
|
|
6
|
+
export * from './test-http.service';
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IResponse,
|
|
3
|
-
IHttpDeleteQueryCall,
|
|
4
|
-
IHttpGetQueryCall,
|
|
5
|
-
IHttpPatchQueryCall,
|
|
6
|
-
IHttpPostQueryCall,
|
|
7
|
-
IHttpPutQueryCall,
|
|
8
|
-
IHttpQueryOptions,
|
|
9
|
-
IHttpCancelRequestToken
|
|
10
|
-
} from './http.models';
|
|
11
|
-
import { IHttpService } from './ihttp.service';
|
|
12
|
-
|
|
13
|
-
export class TestHttpService implements IHttpService<undefined> {
|
|
14
|
-
public response?: IResponse<any> = undefined;
|
|
15
|
-
public error?: any = undefined;
|
|
16
|
-
|
|
17
|
-
constructor(config: { response?: IResponse<any>; error?: any }) {
|
|
18
|
-
Object.assign(this, config);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getAsync<TRawData>(call: IHttpGetQueryCall, options?: IHttpQueryOptions<undefined>): Promise<IResponse<TRawData>> {
|
|
22
|
-
return this.resolveTestCall();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
postAsync<TRawData>(
|
|
26
|
-
call: IHttpPostQueryCall,
|
|
27
|
-
options?: IHttpQueryOptions<undefined>
|
|
28
|
-
): Promise<IResponse<TRawData>> {
|
|
29
|
-
return this.resolveTestCall();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
putAsync<TRawData>(call: IHttpPutQueryCall, options?: IHttpQueryOptions<undefined>): Promise<IResponse<TRawData>> {
|
|
33
|
-
return this.resolveTestCall();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
patchAsync<TRawData>(
|
|
37
|
-
call: IHttpPatchQueryCall,
|
|
38
|
-
options?: IHttpQueryOptions<undefined>
|
|
39
|
-
): Promise<IResponse<TRawData>> {
|
|
40
|
-
return this.resolveTestCall();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
deleteAsync<TRawData>(
|
|
44
|
-
call: IHttpDeleteQueryCall,
|
|
45
|
-
options?: IHttpQueryOptions<undefined>
|
|
46
|
-
): Promise<IResponse<TRawData>> {
|
|
47
|
-
return this.resolveTestCall();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
createCancelToken(): IHttpCancelRequestToken<undefined> {
|
|
51
|
-
return {
|
|
52
|
-
cancel: () => {},
|
|
53
|
-
token: undefined
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private resolveTestCall(): Promise<IResponse<any>> {
|
|
58
|
-
const promise = new Promise<IResponse<any>>((resolve, reject) => {
|
|
59
|
-
if (this.response) {
|
|
60
|
-
resolve(this.response);
|
|
61
|
-
}
|
|
62
|
-
if (this.error) {
|
|
63
|
-
reject(this.error);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
throw Error(`Missing test data`);
|
|
67
|
-
});
|
|
68
|
-
return promise;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
IResponse,
|
|
3
|
+
IHttpDeleteQueryCall,
|
|
4
|
+
IHttpGetQueryCall,
|
|
5
|
+
IHttpPatchQueryCall,
|
|
6
|
+
IHttpPostQueryCall,
|
|
7
|
+
IHttpPutQueryCall,
|
|
8
|
+
IHttpQueryOptions,
|
|
9
|
+
IHttpCancelRequestToken
|
|
10
|
+
} from './http.models';
|
|
11
|
+
import { IHttpService } from './ihttp.service';
|
|
12
|
+
|
|
13
|
+
export class TestHttpService implements IHttpService<undefined> {
|
|
14
|
+
public response?: IResponse<any> = undefined;
|
|
15
|
+
public error?: any = undefined;
|
|
16
|
+
|
|
17
|
+
constructor(config: { response?: IResponse<any>; error?: any }) {
|
|
18
|
+
Object.assign(this, config);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getAsync<TRawData>(call: IHttpGetQueryCall, options?: IHttpQueryOptions<undefined>): Promise<IResponse<TRawData>> {
|
|
22
|
+
return this.resolveTestCall();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
postAsync<TRawData>(
|
|
26
|
+
call: IHttpPostQueryCall,
|
|
27
|
+
options?: IHttpQueryOptions<undefined>
|
|
28
|
+
): Promise<IResponse<TRawData>> {
|
|
29
|
+
return this.resolveTestCall();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
putAsync<TRawData>(call: IHttpPutQueryCall, options?: IHttpQueryOptions<undefined>): Promise<IResponse<TRawData>> {
|
|
33
|
+
return this.resolveTestCall();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
patchAsync<TRawData>(
|
|
37
|
+
call: IHttpPatchQueryCall,
|
|
38
|
+
options?: IHttpQueryOptions<undefined>
|
|
39
|
+
): Promise<IResponse<TRawData>> {
|
|
40
|
+
return this.resolveTestCall();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
deleteAsync<TRawData>(
|
|
44
|
+
call: IHttpDeleteQueryCall,
|
|
45
|
+
options?: IHttpQueryOptions<undefined>
|
|
46
|
+
): Promise<IResponse<TRawData>> {
|
|
47
|
+
return this.resolveTestCall();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
createCancelToken(): IHttpCancelRequestToken<undefined> {
|
|
51
|
+
return {
|
|
52
|
+
cancel: () => {},
|
|
53
|
+
token: undefined
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private resolveTestCall(): Promise<IResponse<any>> {
|
|
58
|
+
const promise = new Promise<IResponse<any>>((resolve, reject) => {
|
|
59
|
+
if (this.response) {
|
|
60
|
+
resolve(this.response);
|
|
61
|
+
}
|
|
62
|
+
if (this.error) {
|
|
63
|
+
reject(this.error);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
throw Error(`Missing test data`);
|
|
67
|
+
});
|
|
68
|
+
return promise;
|
|
69
|
+
}
|
|
70
|
+
}
|
package/lib/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Public API */
|
|
2
|
-
export * from './helpers';
|
|
3
|
-
export * from './models';
|
|
4
|
-
export * from './http';
|
|
1
|
+
/* Public API */
|
|
2
|
+
export * from './helpers';
|
|
3
|
+
export * from './models';
|
|
4
|
+
export * from './http';
|
package/lib/models/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './url.models';
|
|
2
|
-
export * from './isdk-info';
|
|
3
|
-
export * from './parameters';
|
|
1
|
+
export * from './url.models';
|
|
2
|
+
export * from './isdk-info';
|
|
3
|
+
export * from './parameters';
|
package/lib/models/isdk-info.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export interface ISDKInfo {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Name of SDK
|
|
5
|
-
*/
|
|
6
|
-
name: string;
|
|
7
|
-
/**
|
|
8
|
-
* Version SDK
|
|
9
|
-
*/
|
|
10
|
-
version: string;
|
|
11
|
-
/**
|
|
12
|
-
* Host of SDK
|
|
13
|
-
*/
|
|
14
|
-
host: string;
|
|
15
|
-
}
|
|
1
|
+
export interface ISDKInfo {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Name of SDK
|
|
5
|
+
*/
|
|
6
|
+
name: string;
|
|
7
|
+
/**
|
|
8
|
+
* Version SDK
|
|
9
|
+
*/
|
|
10
|
+
version: string;
|
|
11
|
+
/**
|
|
12
|
+
* Host of SDK
|
|
13
|
+
*/
|
|
14
|
+
host: string;
|
|
15
|
+
}
|
package/lib/models/parameters.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { IQueryParameter } from './url.models';
|
|
2
|
-
|
|
3
|
-
export namespace Parameters {
|
|
4
|
-
export class CustomParameter implements IQueryParameter {
|
|
5
|
-
/**
|
|
6
|
-
* Custom parameter
|
|
7
|
-
* @constructor
|
|
8
|
-
* @param {string} name - Name of the parameter
|
|
9
|
-
* @param {string} value - Value of the parameter
|
|
10
|
-
*/
|
|
11
|
-
constructor(public name: string, public value: string) {
|
|
12
|
-
if (!name) {
|
|
13
|
-
throw Error(`Name of the custom parameter is not specified`);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public getParam(): string {
|
|
18
|
-
return this.name;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public getParamValue(): string {
|
|
22
|
-
return this.value;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
1
|
+
import { IQueryParameter } from './url.models';
|
|
2
|
+
|
|
3
|
+
export namespace Parameters {
|
|
4
|
+
export class CustomParameter implements IQueryParameter {
|
|
5
|
+
/**
|
|
6
|
+
* Custom parameter
|
|
7
|
+
* @constructor
|
|
8
|
+
* @param {string} name - Name of the parameter
|
|
9
|
+
* @param {string} value - Value of the parameter
|
|
10
|
+
*/
|
|
11
|
+
constructor(public name: string, public value: string) {
|
|
12
|
+
if (!name) {
|
|
13
|
+
throw Error(`Name of the custom parameter is not specified`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public getParam(): string {
|
|
18
|
+
return this.name;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public getParamValue(): string {
|
|
22
|
+
return this.value;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
package/lib/models/url.models.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export interface IQueryParameter {
|
|
2
|
-
getParam(): string;
|
|
3
|
-
}
|
|
1
|
+
export interface IQueryParameter {
|
|
2
|
+
getParam(): string;
|
|
3
|
+
}
|