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