@arrowsphere/api-client 3.30.0-rc-jpb.1 → 3.30.0-rc-jpb.4
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/build/AbstractHttpClient.d.ts +20 -0
- package/build/AbstractHttpClient.js +32 -0
- package/build/abstractGraphQLClient.d.ts +8 -4
- package/build/abstractGraphQLClient.js +8 -11
- package/build/abstractRestfulClient.d.ts +1 -12
- package/build/abstractRestfulClient.js +0 -13
- package/build/publicApiClient.js +30 -15
- package/build/publicGraphQLClient.js +6 -1
- package/package.json +2 -1
|
@@ -4,6 +4,7 @@ export declare enum HttpClientSecurity {
|
|
|
4
4
|
TOKEN = "token",
|
|
5
5
|
API_KEY = "apikey"
|
|
6
6
|
}
|
|
7
|
+
export declare type Headers = Record<string, string>;
|
|
7
8
|
export declare abstract class AbstractHttpClient {
|
|
8
9
|
/**
|
|
9
10
|
* Base path for HTTP calls
|
|
@@ -21,6 +22,10 @@ export declare abstract class AbstractHttpClient {
|
|
|
21
22
|
* ArrowSphere API URL
|
|
22
23
|
*/
|
|
23
24
|
protected url: string;
|
|
25
|
+
/**
|
|
26
|
+
* Defines header information for http requests
|
|
27
|
+
*/
|
|
28
|
+
protected headers: Headers;
|
|
24
29
|
/**
|
|
25
30
|
* Http Exceptions Handlers
|
|
26
31
|
*/
|
|
@@ -34,11 +39,26 @@ export declare abstract class AbstractHttpClient {
|
|
|
34
39
|
setToken(token: string): this;
|
|
35
40
|
setUrl(url: string): this;
|
|
36
41
|
setSecurity(security: HttpClientSecurity): this;
|
|
42
|
+
/**
|
|
43
|
+
* Warning: can remove useful headers, prefer use mergeHeaders()
|
|
44
|
+
* @param headers
|
|
45
|
+
*/
|
|
46
|
+
setHeaders(headers: Record<string, string>): this;
|
|
47
|
+
/**
|
|
48
|
+
* Will merge existing headers with those in parameters.
|
|
49
|
+
* If There is key equality, the header passed as parameter has priority.
|
|
50
|
+
* @param headers
|
|
51
|
+
*/
|
|
52
|
+
mergeHeaders(headers: Record<string, string>): this;
|
|
37
53
|
/**
|
|
38
54
|
* Allow to register error/exception handler.
|
|
39
55
|
* Handlers can be developed in another projects as long as they respect the interface HttpExceptionHandler.
|
|
40
56
|
*/
|
|
41
57
|
registerHttpExceptionHandler(handler: HttpExceptionHandler): this;
|
|
58
|
+
/**
|
|
59
|
+
* Allow to set error handlers.
|
|
60
|
+
*/
|
|
61
|
+
setHttpExceptionHandlers(handlers: HttpExceptionHandler[]): this;
|
|
42
62
|
/**
|
|
43
63
|
* Will find appropriate ErrorHandlers and apply them to the error in order of registering.
|
|
44
64
|
*/
|
|
@@ -25,6 +25,10 @@ class AbstractHttpClient {
|
|
|
25
25
|
* ArrowSphere API URL
|
|
26
26
|
*/
|
|
27
27
|
this.url = '';
|
|
28
|
+
/**
|
|
29
|
+
* Defines header information for http requests
|
|
30
|
+
*/
|
|
31
|
+
this.headers = {};
|
|
28
32
|
/**
|
|
29
33
|
* Http Exceptions Handlers
|
|
30
34
|
*/
|
|
@@ -48,6 +52,27 @@ class AbstractHttpClient {
|
|
|
48
52
|
this.security = security;
|
|
49
53
|
return this;
|
|
50
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Warning: can remove useful headers, prefer use mergeHeaders()
|
|
57
|
+
* @param headers
|
|
58
|
+
*/
|
|
59
|
+
setHeaders(headers) {
|
|
60
|
+
this.headers = headers;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Will merge existing headers with those in parameters.
|
|
65
|
+
* If There is key equality, the header passed as parameter has priority.
|
|
66
|
+
* @param headers
|
|
67
|
+
*/
|
|
68
|
+
mergeHeaders(headers) {
|
|
69
|
+
const mergedHeaders = {
|
|
70
|
+
...this.headers,
|
|
71
|
+
...headers,
|
|
72
|
+
};
|
|
73
|
+
this.setHeaders(mergedHeaders);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
51
76
|
/**
|
|
52
77
|
* Allow to register error/exception handler.
|
|
53
78
|
* Handlers can be developed in another projects as long as they respect the interface HttpExceptionHandler.
|
|
@@ -56,6 +81,13 @@ class AbstractHttpClient {
|
|
|
56
81
|
this.httpExceptionHandlers.push(handler);
|
|
57
82
|
return this;
|
|
58
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Allow to set error handlers.
|
|
86
|
+
*/
|
|
87
|
+
setHttpExceptionHandlers(handlers) {
|
|
88
|
+
this.httpExceptionHandlers = handlers;
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
59
91
|
/**
|
|
60
92
|
* Will find appropriate ErrorHandlers and apply them to the error in order of registering.
|
|
61
93
|
*/
|
|
@@ -5,13 +5,17 @@ import { GetProductsType } from './catalog';
|
|
|
5
5
|
import { AbstractHttpClient } from './AbstractHttpClient';
|
|
6
6
|
export declare type GraphQLResponseTypes = GetProductsType;
|
|
7
7
|
export declare abstract class AbstractGraphQLClient extends AbstractHttpClient {
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Must not be called directly.
|
|
10
|
+
* Use getClientInstance() to access it.
|
|
11
|
+
* @protected
|
|
12
|
+
*/
|
|
13
|
+
protected graphQLClient: GraphQLClient;
|
|
9
14
|
protected optionsHeader?: Dom.RequestInit['headers'];
|
|
10
15
|
protected options: Options;
|
|
11
|
-
private
|
|
12
|
-
setOptionsHeader(options: Dom.RequestInit['headers']): this;
|
|
16
|
+
private getClientInstance;
|
|
13
17
|
setOptions(options: Options): this;
|
|
14
18
|
protected post<GraphQLResponseTypes>(query: string): Promise<GraphQLResponseTypes>;
|
|
15
|
-
|
|
19
|
+
private generateUrl;
|
|
16
20
|
protected stringifyQuery(query: any): string;
|
|
17
21
|
}
|
|
@@ -33,24 +33,21 @@ class AbstractGraphQLClient extends AbstractHttpClient_1.AbstractHttpClient {
|
|
|
33
33
|
super(...arguments);
|
|
34
34
|
this.options = {};
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
setOptionsHeader(options) {
|
|
41
|
-
this.optionsHeader = options;
|
|
42
|
-
return this;
|
|
36
|
+
getClientInstance() {
|
|
37
|
+
var _a;
|
|
38
|
+
return ((_a = this.graphQLClient) !== null && _a !== void 0 ? _a : (this.graphQLClient = new graphql_request_1.GraphQLClient(this.generateUrl())));
|
|
43
39
|
}
|
|
44
40
|
setOptions(options) {
|
|
45
41
|
this.options = options;
|
|
46
42
|
return this;
|
|
47
43
|
}
|
|
48
44
|
async post(query) {
|
|
49
|
-
|
|
45
|
+
const headers = {
|
|
50
46
|
authorization: this.token,
|
|
51
|
-
...this.
|
|
52
|
-
}
|
|
53
|
-
|
|
47
|
+
...this.headers,
|
|
48
|
+
};
|
|
49
|
+
this.getClientInstance().setHeaders(headers);
|
|
50
|
+
return await this.getClientInstance().request(query);
|
|
54
51
|
}
|
|
55
52
|
generateUrl() {
|
|
56
53
|
const url = new URL(`${this.options.isAdmin ? path.join('admin', this.basePath) : this.basePath}${this.path}`, this.url);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosResponse } from 'axios';
|
|
2
|
-
import { AbstractHttpClient } from './AbstractHttpClient';
|
|
2
|
+
import { AbstractHttpClient, Headers } from './AbstractHttpClient';
|
|
3
3
|
/**
|
|
4
4
|
* Lists of available query parameters for the API call
|
|
5
5
|
*/
|
|
@@ -25,7 +25,6 @@ export declare type ParametersWithPaginationType = (Parameters & {
|
|
|
25
25
|
[ParameterKeys.PER_PAGE_CAMEL]?: number;
|
|
26
26
|
});
|
|
27
27
|
export declare type Parameters = Record<string, string | string[] | number | number[] | boolean | null | undefined>;
|
|
28
|
-
export declare type Headers = Record<string, string>;
|
|
29
28
|
export declare type Payload = Record<string, unknown> | Array<Payload>;
|
|
30
29
|
export declare type Options = {
|
|
31
30
|
isAdmin?: boolean;
|
|
@@ -59,10 +58,6 @@ export declare abstract class AbstractRestfulClient extends AbstractHttpClient {
|
|
|
59
58
|
* Defines whether the pagination options are camel cased or not
|
|
60
59
|
*/
|
|
61
60
|
protected isCamelPagination: boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Defines header information for axios call
|
|
64
|
-
*/
|
|
65
|
-
protected headers: Headers;
|
|
66
61
|
/**
|
|
67
62
|
* AbstractClient constructor.
|
|
68
63
|
* @returns AbstractRestfulClient
|
|
@@ -91,12 +86,6 @@ export declare abstract class AbstractRestfulClient extends AbstractHttpClient {
|
|
|
91
86
|
* @returns AbstractRestfulClient
|
|
92
87
|
*/
|
|
93
88
|
setPage(page: number): this;
|
|
94
|
-
/**
|
|
95
|
-
* Sets Header Information
|
|
96
|
-
* @param headers - Header axios information
|
|
97
|
-
* @returns AbstractRestfulClient
|
|
98
|
-
*/
|
|
99
|
-
setHeaders(headers: Record<string, string>): this;
|
|
100
89
|
/**
|
|
101
90
|
* Sends a GET request and returns the response
|
|
102
91
|
* @param parameters - Query parameters to send
|
|
@@ -52,10 +52,6 @@ class AbstractRestfulClient extends AbstractHttpClient_1.AbstractHttpClient {
|
|
|
52
52
|
* Defines whether the pagination options are camel cased or not
|
|
53
53
|
*/
|
|
54
54
|
this.isCamelPagination = false;
|
|
55
|
-
/**
|
|
56
|
-
* Defines header information for axios call
|
|
57
|
-
*/
|
|
58
|
-
this.headers = {};
|
|
59
55
|
this.client = axiosSingleton_1.AxiosSingleton.getInstance();
|
|
60
56
|
this.setApiKey((_a = configuration === null || configuration === void 0 ? void 0 : configuration[ParameterKeys.API_KEY]) !== null && _a !== void 0 ? _a : '');
|
|
61
57
|
this.setUrl((_b = configuration === null || configuration === void 0 ? void 0 : configuration[ParameterKeys.URL]) !== null && _b !== void 0 ? _b : '');
|
|
@@ -95,15 +91,6 @@ class AbstractRestfulClient extends AbstractHttpClient_1.AbstractHttpClient {
|
|
|
95
91
|
this.page = page;
|
|
96
92
|
return this;
|
|
97
93
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Sets Header Information
|
|
100
|
-
* @param headers - Header axios information
|
|
101
|
-
* @returns AbstractRestfulClient
|
|
102
|
-
*/
|
|
103
|
-
setHeaders(headers) {
|
|
104
|
-
this.headers = headers;
|
|
105
|
-
return this;
|
|
106
|
-
}
|
|
107
94
|
/**
|
|
108
95
|
* Sends a GET request and returns the response
|
|
109
96
|
* @param parameters - Query parameters to send
|
package/build/publicApiClient.js
CHANGED
|
@@ -31,7 +31,8 @@ class PublicApiClient extends abstractRestfulClient_1.AbstractRestfulClient {
|
|
|
31
31
|
return new customers_1.CustomersClient()
|
|
32
32
|
.setUrl(this.url)
|
|
33
33
|
.setApiKey(this.apiKey)
|
|
34
|
-
.setHeaders(this.headers)
|
|
34
|
+
.setHeaders(this.headers)
|
|
35
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
37
38
|
* Creates a new {@link WhoAmIClient} instance and returns it
|
|
@@ -41,7 +42,8 @@ class PublicApiClient extends abstractRestfulClient_1.AbstractRestfulClient {
|
|
|
41
42
|
return new general_1.WhoAmIClient()
|
|
42
43
|
.setUrl(this.url)
|
|
43
44
|
.setApiKey(this.apiKey)
|
|
44
|
-
.setHeaders(this.headers)
|
|
45
|
+
.setHeaders(this.headers)
|
|
46
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
45
47
|
}
|
|
46
48
|
/**
|
|
47
49
|
* Creates a new {@link LicensesClient} instance and returns it
|
|
@@ -51,7 +53,8 @@ class PublicApiClient extends abstractRestfulClient_1.AbstractRestfulClient {
|
|
|
51
53
|
return new licenses_1.LicensesClient()
|
|
52
54
|
.setUrl(this.url)
|
|
53
55
|
.setApiKey(this.apiKey)
|
|
54
|
-
.setHeaders(this.headers)
|
|
56
|
+
.setHeaders(this.headers)
|
|
57
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
55
58
|
}
|
|
56
59
|
/**
|
|
57
60
|
* Creates a new {@link CheckDomainClient} instance and returns it
|
|
@@ -61,7 +64,8 @@ class PublicApiClient extends abstractRestfulClient_1.AbstractRestfulClient {
|
|
|
61
64
|
return new general_1.CheckDomainClient()
|
|
62
65
|
.setUrl(this.url)
|
|
63
66
|
.setApiKey(this.apiKey)
|
|
64
|
-
.setHeaders(this.headers)
|
|
67
|
+
.setHeaders(this.headers)
|
|
68
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
65
69
|
}
|
|
66
70
|
/**
|
|
67
71
|
* Creates a new {@link SubscriptionsClient} instance and returns it
|
|
@@ -71,7 +75,8 @@ class PublicApiClient extends abstractRestfulClient_1.AbstractRestfulClient {
|
|
|
71
75
|
return new subscriptions_1.SubscriptionsClient()
|
|
72
76
|
.setUrl(this.url)
|
|
73
77
|
.setApiKey(this.apiKey)
|
|
74
|
-
.setHeaders(this.headers)
|
|
78
|
+
.setHeaders(this.headers)
|
|
79
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
75
80
|
}
|
|
76
81
|
/**
|
|
77
82
|
* Creates a new {@link OrdersClient} instance and returns it
|
|
@@ -81,7 +86,8 @@ class PublicApiClient extends abstractRestfulClient_1.AbstractRestfulClient {
|
|
|
81
86
|
return new orders_1.OrdersClient()
|
|
82
87
|
.setUrl(this.url)
|
|
83
88
|
.setApiKey(this.apiKey)
|
|
84
|
-
.setHeaders(this.headers)
|
|
89
|
+
.setHeaders(this.headers)
|
|
90
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
85
91
|
}
|
|
86
92
|
/**
|
|
87
93
|
* Creates a new {@link ContactClient} instance and returns it
|
|
@@ -91,7 +97,8 @@ class PublicApiClient extends abstractRestfulClient_1.AbstractRestfulClient {
|
|
|
91
97
|
return new contact_1.ContactClient()
|
|
92
98
|
.setUrl(this.url)
|
|
93
99
|
.setApiKey(this.apiKey)
|
|
94
|
-
.setHeaders(this.headers)
|
|
100
|
+
.setHeaders(this.headers)
|
|
101
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
95
102
|
}
|
|
96
103
|
/**
|
|
97
104
|
* Creates a new {@link ContactClient} instance and returns it
|
|
@@ -101,49 +108,57 @@ class PublicApiClient extends abstractRestfulClient_1.AbstractRestfulClient {
|
|
|
101
108
|
return new campaign_1.CampaignClient()
|
|
102
109
|
.setUrl(this.url)
|
|
103
110
|
.setApiKey(this.apiKey)
|
|
104
|
-
.setHeaders(this.headers)
|
|
111
|
+
.setHeaders(this.headers)
|
|
112
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
105
113
|
}
|
|
106
114
|
getConsumptionClient() {
|
|
107
115
|
return new consumption_1.ConsumptionClient()
|
|
108
116
|
.setUrl(this.url)
|
|
109
117
|
.setApiKey(this.apiKey)
|
|
110
|
-
.setHeaders(this.headers)
|
|
118
|
+
.setHeaders(this.headers)
|
|
119
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
111
120
|
}
|
|
112
121
|
getSecurityStandardsClient() {
|
|
113
122
|
return new standardsClient_1.StandardsClient()
|
|
114
123
|
.setUrl(this.url)
|
|
115
124
|
.setApiKey(this.apiKey)
|
|
116
|
-
.setHeaders(this.headers)
|
|
125
|
+
.setHeaders(this.headers)
|
|
126
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
117
127
|
}
|
|
118
128
|
getSecurityRegisterClient() {
|
|
119
129
|
return new security_1.RegisterClient()
|
|
120
130
|
.setUrl(this.url)
|
|
121
131
|
.setApiKey(this.apiKey)
|
|
122
|
-
.setHeaders(this.headers)
|
|
132
|
+
.setHeaders(this.headers)
|
|
133
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
123
134
|
}
|
|
124
135
|
getCartClient() {
|
|
125
136
|
return new cartClient_1.CartClient()
|
|
126
137
|
.setUrl(this.url)
|
|
127
138
|
.setApiKey(this.apiKey)
|
|
128
|
-
.setHeaders(this.headers)
|
|
139
|
+
.setHeaders(this.headers)
|
|
140
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
129
141
|
}
|
|
130
142
|
getSupportCenterClient() {
|
|
131
143
|
return new supportCenter_1.SupportCenterClient()
|
|
132
144
|
.setUrl(this.url)
|
|
133
145
|
.setApiKey(this.apiKey)
|
|
134
|
-
.setHeaders(this.headers)
|
|
146
|
+
.setHeaders(this.headers)
|
|
147
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
135
148
|
}
|
|
136
149
|
getCatalogClient() {
|
|
137
150
|
return new catalog_1.CatalogClient()
|
|
138
151
|
.setUrl(this.url)
|
|
139
152
|
.setApiKey(this.apiKey)
|
|
140
|
-
.setHeaders(this.headers)
|
|
153
|
+
.setHeaders(this.headers)
|
|
154
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
141
155
|
}
|
|
142
156
|
getUserClient() {
|
|
143
157
|
return new user_1.UserClient()
|
|
144
158
|
.setUrl(this.url)
|
|
145
159
|
.setApiKey(this.apiKey)
|
|
146
|
-
.setHeaders(this.headers)
|
|
160
|
+
.setHeaders(this.headers)
|
|
161
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
147
162
|
}
|
|
148
163
|
}
|
|
149
164
|
exports.PublicApiClient = PublicApiClient;
|
|
@@ -5,7 +5,12 @@ const catalogGraphQLClient_1 = require("./catalog/catalogGraphQLClient");
|
|
|
5
5
|
const abstractGraphQLClient_1 = require("./abstractGraphQLClient");
|
|
6
6
|
class PublicGraphQLClient extends abstractGraphQLClient_1.AbstractGraphQLClient {
|
|
7
7
|
getCatalogGraphQLClient() {
|
|
8
|
-
return new catalogGraphQLClient_1.CatalogGraphQLClient()
|
|
8
|
+
return new catalogGraphQLClient_1.CatalogGraphQLClient()
|
|
9
|
+
.setUrl(this.url)
|
|
10
|
+
.setToken(this.token)
|
|
11
|
+
.setHeaders(this.headers)
|
|
12
|
+
.setToken(this.token)
|
|
13
|
+
.setHttpExceptionHandlers(this.httpExceptionHandlers);
|
|
9
14
|
}
|
|
10
15
|
}
|
|
11
16
|
exports.PublicGraphQLClient = PublicGraphQLClient;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "git",
|
|
5
5
|
"url": "https://github.com/ArrowSphere/nodejs-api-client.git"
|
|
6
6
|
},
|
|
7
|
-
"version": "3.30.0-rc-jpb.
|
|
7
|
+
"version": "3.30.0-rc-jpb.4",
|
|
8
8
|
"description": "Node.js client for ArrowSphere's public API",
|
|
9
9
|
"main": "build/index.js",
|
|
10
10
|
"types": "build/index.d.ts",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"lint:fix": "eslint ./{src,tests}/**/*.ts --fix && prettier --write ./{src,tests}/**/*.ts",
|
|
17
17
|
"prepare": "npm run clean && npm run build",
|
|
18
18
|
"test": "mocha -r ts-node/register \"tests/**/*.ts\"",
|
|
19
|
+
"test:one": "mocha -r ts-node/register",
|
|
19
20
|
"test:watch": "mocha --watch -r ts-node/register \"tests/**/*.ts\"",
|
|
20
21
|
"test:coverage": "nyc --check-coverage npm run test",
|
|
21
22
|
"test:coverage:report": "nyc report --reporter=text-lcov | coveralls"
|