@equinor/fusion-framework-module-http 6.2.1 → 6.2.2
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 +336 -310
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/lib/client/client-msal.js.map +1 -1
- package/dist/esm/lib/client/client.js.map +1 -1
- package/dist/esm/lib/operators/capitalize-request-method.operator.js +3 -1
- package/dist/esm/lib/operators/capitalize-request-method.operator.js.map +1 -1
- package/dist/esm/lib/operators/fetch-request.schema.js.map +1 -1
- package/dist/esm/lib/operators/http-request-handler.js.map +1 -1
- package/dist/esm/lib/operators/process-operators.js.map +1 -1
- package/dist/esm/lib/operators/request-operator-header.js.map +1 -1
- package/dist/esm/lib/operators/request-validation.operator.js.map +1 -1
- package/dist/esm/lib/selectors/blob-selector.js.map +1 -1
- package/dist/esm/lib/selectors/json-selector.js.map +1 -1
- package/dist/esm/module.js +1 -1
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/provider.js +8 -3
- package/dist/esm/provider.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/lib/operators/process-operators.d.ts +1 -1
- package/dist/types/module.d.ts +3 -3
- package/dist/types/provider.d.ts +10 -3
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -3
- package/src/configurator.ts +115 -116
- package/src/errors.ts +24 -24
- package/src/lib/client/client-msal.ts +34 -34
- package/src/lib/client/client.ts +298 -298
- package/src/lib/client/types.ts +147 -145
- package/src/lib/operators/capitalize-request-method.operator.ts +11 -9
- package/src/lib/operators/fetch-request.schema.ts +70 -73
- package/src/lib/operators/http-request-handler.ts +11 -11
- package/src/lib/operators/process-operators.ts +88 -88
- package/src/lib/operators/request-operator-header.ts +6 -6
- package/src/lib/operators/request-validation.operator.ts +32 -32
- package/src/lib/operators/types.ts +44 -44
- package/src/lib/selectors/blob-selector.ts +24 -24
- package/src/lib/selectors/json-selector.ts +25 -25
- package/src/module.ts +73 -69
- package/src/provider.ts +141 -139
- package/src/version.ts +1 -1
- package/tests/HttpClient.test.ts +37 -37
- package/tests/operators.test.ts +67 -67
- package/vitest.config.ts +6 -6
package/src/module.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { HttpClientMsal } from './lib/client';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
type IHttpClientConfigurator,
|
|
5
|
+
HttpClientConfigurator,
|
|
6
|
+
type HttpClientOptions,
|
|
7
|
+
} from './configurator';
|
|
8
|
+
import { type IHttpClientProvider, HttpClientProvider } from './provider';
|
|
5
9
|
|
|
6
10
|
import type {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
Module,
|
|
12
|
+
ModuleConfigType,
|
|
13
|
+
IModuleConfigurator,
|
|
10
14
|
} from '@equinor/fusion-framework-module';
|
|
11
15
|
|
|
12
|
-
import { MsalModule } from '@equinor/fusion-framework-module-msal';
|
|
16
|
+
import type { MsalModule } from '@equinor/fusion-framework-module-msal';
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* Defines the type for the HTTP module, which includes:
|
|
@@ -29,75 +33,75 @@ export type HttpModule = Module<'http', IHttpClientProvider, IHttpClientConfigur
|
|
|
29
33
|
* - The list of required modules, which includes the `MsalModule`
|
|
30
34
|
*/
|
|
31
35
|
export type HttpMsalModule = Module<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
'http',
|
|
37
|
+
IHttpClientProvider<HttpClientMsal>,
|
|
38
|
+
IHttpClientConfigurator<HttpClientMsal>,
|
|
39
|
+
[MsalModule]
|
|
36
40
|
>;
|
|
37
41
|
|
|
38
42
|
/**
|
|
39
43
|
* HTTP module with MSAL authentication.
|
|
40
44
|
*/
|
|
41
45
|
export const module: HttpMsalModule = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
name: 'http',
|
|
47
|
+
/**
|
|
48
|
+
* Configures the HTTP module with MSAL authentication.
|
|
49
|
+
*
|
|
50
|
+
* This function creates a new `HttpClientConfigurator` instance using the `HttpClientMsal` class.
|
|
51
|
+
* The `HttpClientConfigurator` is responsible for configuring the HTTP client with the necessary options,
|
|
52
|
+
* such as the base URL, request headers, and other settings.
|
|
53
|
+
*
|
|
54
|
+
* @returns A new `HttpClientConfigurator` instance configured for MSAL authentication.
|
|
55
|
+
*/
|
|
56
|
+
configure: () => new HttpClientConfigurator(HttpClientMsal),
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
});
|
|
58
|
+
/**
|
|
59
|
+
* Initializes the HTTP client provider with MSAL authentication.
|
|
60
|
+
*
|
|
61
|
+
* This function is responsible for setting up the default HTTP request handler
|
|
62
|
+
* to acquire an access token from MSAL and attach it to the request headers
|
|
63
|
+
* when the request includes scopes.
|
|
64
|
+
*
|
|
65
|
+
* @param config - The module configuration.
|
|
66
|
+
* @param hasModule - A function to check if a module is available.
|
|
67
|
+
* @param requireInstance - A function to get an instance of a module.
|
|
68
|
+
* @returns A promise that resolves to the HTTP client provider.
|
|
69
|
+
*/
|
|
70
|
+
initialize: async ({
|
|
71
|
+
config,
|
|
72
|
+
hasModule,
|
|
73
|
+
requireInstance,
|
|
74
|
+
}): Promise<HttpClientProvider<HttpClientMsal>> => {
|
|
75
|
+
const httpProvider = new HttpClientProvider(config);
|
|
76
|
+
if (hasModule('auth')) {
|
|
77
|
+
const authProvider = await requireInstance('auth');
|
|
78
|
+
httpProvider.defaultHttpRequestHandler.set('MSAL', async (request) => {
|
|
79
|
+
const { scopes = [] } = request;
|
|
80
|
+
if (scopes.length) {
|
|
81
|
+
/** TODO should be try catch, check caller for handling */
|
|
82
|
+
const token = await authProvider.acquireToken({
|
|
83
|
+
scopes,
|
|
84
|
+
});
|
|
85
|
+
if (token) {
|
|
86
|
+
const headers = new Headers(request.headers);
|
|
87
|
+
headers.set('Authorization', `Bearer ${token.accessToken}`);
|
|
88
|
+
return { ...request, headers };
|
|
89
|
+
}
|
|
88
90
|
}
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return httpProvider;
|
|
94
|
+
},
|
|
91
95
|
};
|
|
92
96
|
|
|
93
97
|
/**
|
|
94
98
|
* Configures the HTTP module with MSAL authentication.
|
|
95
99
|
*/
|
|
96
100
|
export const configureHttp = <TRef = unknown>(
|
|
97
|
-
|
|
101
|
+
configure: (config: ModuleConfigType<HttpMsalModule>, ref?: TRef) => void,
|
|
98
102
|
): IModuleConfigurator<HttpMsalModule, TRef> => ({
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
module,
|
|
104
|
+
configure,
|
|
101
105
|
});
|
|
102
106
|
|
|
103
107
|
/**
|
|
@@ -112,22 +116,22 @@ export const configureHttp = <TRef = unknown>(
|
|
|
112
116
|
* @returns A module configurator that can be used to configure the HTTP module.
|
|
113
117
|
*/
|
|
114
118
|
export const configureHttpClient = <TRef = unknown>(
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
name: string,
|
|
120
|
+
args: HttpClientOptions<HttpClientMsal>,
|
|
117
121
|
): IModuleConfigurator<HttpMsalModule, TRef> => ({
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
module,
|
|
123
|
+
configure: (config: ModuleConfigType<HttpMsalModule>) => {
|
|
124
|
+
config.configureClient(name, args);
|
|
125
|
+
},
|
|
122
126
|
});
|
|
123
127
|
|
|
124
128
|
/**
|
|
125
129
|
* Declares a module named '@equinor/fusion-framework-module' that contains an interface named 'Modules' with a property 'http' of type 'HttpMsalModule'.
|
|
126
130
|
*/
|
|
127
131
|
declare module '@equinor/fusion-framework-module' {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
132
|
+
interface Modules {
|
|
133
|
+
http: HttpMsalModule;
|
|
134
|
+
}
|
|
131
135
|
}
|
|
132
136
|
|
|
133
137
|
export default module;
|
package/src/provider.ts
CHANGED
|
@@ -1,51 +1,55 @@
|
|
|
1
|
-
import { HttpClient } from './lib/client';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { HttpClient } from './lib/client';
|
|
2
|
+
import type {
|
|
3
|
+
HttpClientOptions,
|
|
4
|
+
HttpClientRequestInitType,
|
|
5
|
+
IHttpClientConfigurator,
|
|
6
6
|
} from './configurator';
|
|
7
7
|
|
|
8
8
|
import type { IHttpRequestHandler } from './lib/operators';
|
|
9
9
|
import type { IHttpClient } from './lib/client';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Exception thrown when a client cannot be found.
|
|
13
|
+
*
|
|
14
|
+
* This error is typically used to indicate that a requested client instance
|
|
15
|
+
* does not exist or cannot be located within the current context.
|
|
16
|
+
*
|
|
17
|
+
* @extends {Error}
|
|
18
|
+
*/
|
|
19
|
+
export class ClientNotFoundException extends Error {}
|
|
16
20
|
|
|
17
21
|
export interface IHttpClientProvider<TClient extends IHttpClient = IHttpClient> {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
/**
|
|
23
|
+
* The default HTTP request handler used by the HttpClientProvider.
|
|
24
|
+
* This handler is responsible for executing HTTP requests using the configured HttpClient.
|
|
25
|
+
*/
|
|
26
|
+
readonly defaultHttpRequestHandler: IHttpRequestHandler<HttpClientRequestInitType<TClient>>;
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Checks if a client is configured with the given key.
|
|
30
|
+
* @param key - The key of the client to check.
|
|
31
|
+
* @returns `true` if a client is configured with the given key, `false` otherwise.
|
|
32
|
+
*/
|
|
33
|
+
hasClient(key: string): boolean;
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new HTTP client instance with the specified key.
|
|
37
|
+
* @param key - The key of the HTTP client to create.
|
|
38
|
+
* @returns The created HTTP client instance.
|
|
39
|
+
*/
|
|
40
|
+
createClient(key: string): TClient;
|
|
41
|
+
createClient(key: HttpClientOptions<TClient>): TClient;
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Class cast creation of custom client
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* config.http.configureClient('foobar', (client) => {
|
|
48
|
+
* client.ctor = MyClient;
|
|
49
|
+
* client.uri = 'https://foobar.com';
|
|
50
|
+
* });
|
|
51
|
+
*/
|
|
52
|
+
createCustomClient<T extends HttpClient>(key: string): T;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
/**
|
|
@@ -54,16 +58,16 @@ export interface IHttpClientProvider<TClient extends IHttpClient = IHttpClient>
|
|
|
54
58
|
* @returns `true` if the input string is a valid URL, `false` otherwise.
|
|
55
59
|
*/
|
|
56
60
|
const isURL = (url: string) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
const pattern = new RegExp(
|
|
62
|
+
'^(https?:\\/\\/)?' + // protocol
|
|
63
|
+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|' + // domain name
|
|
64
|
+
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
|
|
65
|
+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
|
66
|
+
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
|
67
|
+
'(\\#[-a-z\\d_]*)?$',
|
|
68
|
+
'i',
|
|
69
|
+
); // fragment locator
|
|
70
|
+
return pattern.test(url);
|
|
67
71
|
};
|
|
68
72
|
|
|
69
73
|
/**
|
|
@@ -71,102 +75,100 @@ const isURL = (url: string) => {
|
|
|
71
75
|
* It provides methods to check if a client is configured, create new client instances, and create custom client instances.
|
|
72
76
|
*/
|
|
73
77
|
export class HttpClientProvider<TClient extends IHttpClient = IHttpClient>
|
|
74
|
-
|
|
78
|
+
implements IHttpClientProvider<TClient>
|
|
75
79
|
{
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Gets the default HTTP request handler for the HTTP client provider.
|
|
82
|
+
* @returns The default HTTP request handler.
|
|
83
|
+
*/
|
|
84
|
+
get defaultHttpRequestHandler(): IHttpRequestHandler<HttpClientRequestInitType<TClient>> {
|
|
85
|
+
return this.config.defaultHttpRequestHandler;
|
|
86
|
+
}
|
|
83
87
|
|
|
84
|
-
|
|
88
|
+
constructor(protected config: IHttpClientConfigurator<TClient>) {}
|
|
85
89
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Checks if a client with the given key is configured in the `HttpClientProvider`.
|
|
92
|
+
* @param key - The key of the HTTP client to check.
|
|
93
|
+
* @returns `true` if a client with the given key is configured, `false` otherwise.
|
|
94
|
+
*/
|
|
95
|
+
public hasClient(key: string): boolean {
|
|
96
|
+
return Object.keys(this.config.clients).includes(key);
|
|
97
|
+
}
|
|
94
98
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Creates a new HTTP client instance with the specified configuration.
|
|
101
|
+
*
|
|
102
|
+
* @param keyOrConfig - The key or configuration object for the HTTP client.
|
|
103
|
+
* @returns The created HTTP client instance.
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* This method resolves the configuration for the HTTP client based on the provided `keyOrConfig` parameter.
|
|
107
|
+
* If a string is provided, it is treated as the key for a pre-configured client in the `HttpClientProvider`.
|
|
108
|
+
* If an `HttpClientOptions` object is provided, it is used as the configuration for the new client instance.
|
|
109
|
+
*
|
|
110
|
+
* The method sets up the HTTP client with the following options:
|
|
111
|
+
* - `baseUri`: The base URI for the HTTP client.
|
|
112
|
+
* - `defaultScopes`: The default scopes to be used for authentication.
|
|
113
|
+
* - `onCreate`: An optional callback function that is called when the client instance is created.
|
|
114
|
+
* - `ctor`: The constructor function for the HTTP client, defaulting to the configured `defaultHttpClientCtor`.
|
|
115
|
+
* - `requestHandler`: The HTTP request handler to be used by the client, defaulting to the `defaultHttpRequestHandler`.
|
|
116
|
+
*
|
|
117
|
+
* The created HTTP client instance is returned.
|
|
118
|
+
*/
|
|
119
|
+
public createClient(keyOrConfig: string | HttpClientOptions<TClient>): TClient {
|
|
120
|
+
const config = this._resolveConfig(keyOrConfig);
|
|
121
|
+
const {
|
|
122
|
+
baseUri,
|
|
123
|
+
defaultScopes = [],
|
|
124
|
+
onCreate,
|
|
125
|
+
ctor = this.config.defaultHttpClientCtor,
|
|
126
|
+
requestHandler = this.defaultHttpRequestHandler,
|
|
127
|
+
} = config as HttpClientOptions<TClient>;
|
|
128
|
+
const options = { requestHandler };
|
|
129
|
+
const instance = new ctor(baseUri || '', options) as TClient;
|
|
130
|
+
Object.assign(instance, { defaultScopes });
|
|
131
|
+
onCreate && onCreate(instance as TClient);
|
|
132
|
+
return instance as TClient;
|
|
133
|
+
}
|
|
130
134
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Creates a new HTTP client instance with the specified configuration.
|
|
137
|
+
*
|
|
138
|
+
* @param key - The key of the pre-configured HTTP client to create.
|
|
139
|
+
* @returns The created HTTP client instance, cast to the specified type `T`.
|
|
140
|
+
*
|
|
141
|
+
* @remarks
|
|
142
|
+
* This method delegates to the `createClient` method, but casts the returned
|
|
143
|
+
* instance to the specified type `T`. This can be useful when you need to
|
|
144
|
+
* work with a specific HTTP client implementation, but the `HttpClientProvider`
|
|
145
|
+
* is configured to use a different implementation.
|
|
146
|
+
*/
|
|
147
|
+
public createCustomClient<T extends HttpClient>(key: string): T {
|
|
148
|
+
return this.createClient(key) as unknown as T;
|
|
149
|
+
}
|
|
146
150
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
return config;
|
|
169
|
-
}
|
|
170
|
-
return keyOrConfig as HttpClientOptions<TClient>;
|
|
151
|
+
/**
|
|
152
|
+
* Resolves the configuration for an HTTP client based on the provided `keyOrConfig` parameter.
|
|
153
|
+
*
|
|
154
|
+
* If a string is provided, it is treated as the key for a pre-configured client in the `HttpClientProvider`.
|
|
155
|
+
* If an `HttpClientOptions` object is provided, it is used as the configuration for the new client instance.
|
|
156
|
+
*
|
|
157
|
+
* @param keyOrConfig - The key or configuration object for the HTTP client.
|
|
158
|
+
* @returns The resolved HTTP client configuration.
|
|
159
|
+
*/
|
|
160
|
+
protected _resolveConfig(
|
|
161
|
+
keyOrConfig: string | HttpClientOptions<TClient>,
|
|
162
|
+
): HttpClientOptions<TClient> {
|
|
163
|
+
if (typeof keyOrConfig === 'string') {
|
|
164
|
+
const config = this.config.clients[keyOrConfig];
|
|
165
|
+
if (!config && isURL(keyOrConfig)) {
|
|
166
|
+
return { baseUri: keyOrConfig };
|
|
167
|
+
} else if (!config) {
|
|
168
|
+
throw new ClientNotFoundException(`No registered http client for key [${keyOrConfig}]`);
|
|
169
|
+
}
|
|
170
|
+
return config;
|
|
171
171
|
}
|
|
172
|
+
return keyOrConfig as HttpClientOptions<TClient>;
|
|
173
|
+
}
|
|
172
174
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '6.2.
|
|
2
|
+
export const version = '6.2.2';
|
package/tests/HttpClient.test.ts
CHANGED
|
@@ -8,41 +8,41 @@ import { lastValueFrom } from 'rxjs';
|
|
|
8
8
|
let provider: HttpClientProvider;
|
|
9
9
|
|
|
10
10
|
describe('HttpClient', () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
const config = new HttpClientConfigurator(HttpClient);
|
|
13
|
+
config.configureClient('foo', 'http://localhost:3000');
|
|
14
|
+
provider = new HttpClientProvider(config);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should create instance', () => {
|
|
18
|
+
const client = provider.createClient('foo');
|
|
19
|
+
expect(client).toBeDefined();
|
|
20
|
+
expect(client.uri).toBe('http://localhost:3000');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should allow providing headers in request', async () => {});
|
|
24
|
+
|
|
25
|
+
it('should not modify configured headers', async () => {
|
|
26
|
+
// create a new client from configuration
|
|
27
|
+
const fooClient = provider.createClient('foo');
|
|
28
|
+
fooClient.requestHandler.setHeader('x-foo', 'bar');
|
|
29
|
+
|
|
30
|
+
// generate a RequestInit object
|
|
31
|
+
const fooRequest = await lastValueFrom(
|
|
32
|
+
fooClient.requestHandler.process({ path: '/api', uri: fooClient.uri }),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect((fooRequest.headers as Headers)?.get('x-foo')).toBe('bar');
|
|
36
|
+
|
|
37
|
+
// create a new client from the same configuration
|
|
38
|
+
const barClient = provider.createClient('foo');
|
|
39
|
+
|
|
40
|
+
// generate a RequestInit object
|
|
41
|
+
const barRequest = await lastValueFrom(
|
|
42
|
+
barClient.requestHandler.process({ path: '/api', uri: barClient.uri }),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
// expect the request header to not been modified
|
|
46
|
+
expect((barRequest.headers as Headers)?.get('x-foo')).toBeUndefined();
|
|
47
|
+
});
|
|
48
48
|
});
|