@equinor/fusion-framework-module-http 8.0.3 → 8.0.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/CHANGELOG.md +19 -0
- package/dist/esm/configurator.js +7 -1
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/errors/ClientNotFoundException.js +10 -0
- package/dist/esm/errors/ClientNotFoundException.js.map +1 -0
- package/dist/esm/errors/HttpJsonResponseError.js +26 -0
- package/dist/esm/errors/HttpJsonResponseError.js.map +1 -0
- package/dist/esm/errors/HttpResponseError.js +19 -0
- package/dist/esm/errors/HttpResponseError.js.map +1 -0
- package/dist/esm/errors/ServerSentEventResponseError.js +25 -0
- package/dist/esm/errors/ServerSentEventResponseError.js.map +1 -0
- package/dist/esm/errors/index.js +5 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/client/client-msal.js +1 -0
- package/dist/esm/lib/client/client-msal.js.map +1 -1
- package/dist/esm/lib/client/client.js +40 -4
- package/dist/esm/lib/client/client.js.map +1 -1
- package/dist/esm/lib/operators/{http-request-handler.js → HttpRequestHandler.js} +3 -3
- package/dist/esm/lib/operators/HttpRequestHandler.js.map +1 -0
- package/dist/esm/lib/operators/{http-response-handler.js → HttpResponseHandler.js} +2 -2
- package/dist/esm/lib/operators/HttpResponseHandler.js.map +1 -0
- package/dist/esm/lib/operators/{process-operators.js → ProcessOperators.js} +4 -1
- package/dist/esm/lib/operators/ProcessOperators.js.map +1 -0
- package/dist/esm/lib/operators/{capitalize-request-method.operator.js → capitalize-request-method-operator.js} +4 -2
- package/dist/esm/lib/operators/capitalize-request-method-operator.js.map +1 -0
- package/dist/esm/lib/operators/{fetch-request.schema.js → fetch-request.schemas.js} +1 -1
- package/dist/esm/lib/operators/fetch-request.schemas.js.map +1 -0
- package/dist/esm/lib/operators/index.js +6 -6
- package/dist/esm/lib/operators/index.js.map +1 -1
- package/dist/esm/lib/operators/{request-validation.operator.js → request-validation-operator.js} +3 -2
- package/dist/esm/lib/operators/{request-validation.operator.js.map → request-validation-operator.js.map} +1 -1
- package/dist/esm/lib/operators/{sse.operator.js → sse-map.operator.js} +5 -3
- package/dist/esm/lib/operators/sse-map.operator.js.map +1 -0
- package/dist/esm/lib/selectors/blob-selector.js +3 -2
- package/dist/esm/lib/selectors/blob-selector.js.map +1 -1
- package/dist/esm/lib/selectors/{sse-selector.js → create-sse-selector.js} +20 -5
- package/dist/esm/lib/selectors/create-sse-selector.js.map +1 -0
- package/dist/esm/lib/selectors/index.js +1 -1
- package/dist/esm/lib/selectors/index.js.map +1 -1
- package/dist/esm/lib/selectors/json-selector.js +1 -1
- package/dist/esm/lib/selectors/json-selector.js.map +1 -1
- package/dist/esm/module.js +4 -1
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/provider.js +14 -8
- package/dist/esm/provider.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/configurator.d.ts +5 -1
- package/dist/types/errors/ClientNotFoundException.d.ts +9 -0
- package/dist/types/errors/HttpJsonResponseError.d.ts +23 -0
- package/dist/types/errors/HttpResponseError.d.ts +15 -0
- package/dist/types/errors/ServerSentEventResponseError.d.ts +23 -0
- package/dist/types/errors/index.d.ts +4 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/lib/client/client-msal.d.ts +1 -0
- package/dist/types/lib/client/client.d.ts +33 -3
- package/dist/types/lib/operators/{http-request-handler.d.ts → HttpRequestHandler.d.ts} +1 -1
- package/dist/types/lib/operators/{http-response-handler.d.ts → HttpResponseHandler.d.ts} +1 -1
- package/dist/types/lib/operators/index.d.ts +6 -6
- package/dist/types/lib/operators/{sse.operator.d.ts → sse-map.operator.d.ts} +1 -1
- package/dist/types/lib/selectors/index.d.ts +2 -2
- package/dist/types/provider.d.ts +7 -8
- package/dist/types/version.d.ts +1 -1
- package/package.json +7 -7
- package/src/configurator.ts +7 -1
- package/src/errors/ClientNotFoundException.ts +9 -0
- package/src/errors/HttpJsonResponseError.ts +31 -0
- package/src/errors/HttpResponseError.ts +21 -0
- package/src/errors/ServerSentEventResponseError.ts +30 -0
- package/src/errors/index.ts +4 -0
- package/src/index.ts +2 -1
- package/src/lib/client/client-msal.ts +1 -0
- package/src/lib/client/client.ts +40 -4
- package/src/lib/operators/{http-request-handler.ts → HttpRequestHandler.ts} +2 -2
- package/src/lib/operators/{http-response-handler.ts → HttpResponseHandler.ts} +1 -1
- package/src/lib/operators/{process-operators.ts → ProcessOperators.ts} +3 -0
- package/src/lib/operators/{capitalize-request-method.operator.ts → capitalize-request-method-operator.ts} +3 -1
- package/src/lib/operators/index.ts +6 -6
- package/src/lib/operators/{request-validation.operator.ts → request-validation-operator.ts} +2 -1
- package/src/lib/operators/{sse.operator.ts → sse-map.operator.ts} +2 -1
- package/src/lib/operators/types.ts +1 -0
- package/src/lib/selectors/blob-selector.ts +3 -2
- package/src/lib/selectors/{sse-selector.ts → create-sse-selector.ts} +34 -17
- package/src/lib/selectors/index.ts +2 -2
- package/src/lib/selectors/json-selector.ts +1 -1
- package/src/module.ts +4 -1
- package/src/provider.ts +14 -8
- package/src/version.ts +1 -1
- package/tests/HttpClient.test.ts +2 -2
- package/tests/operators.test.ts +5 -1
- package/tests/sse.selector.test.ts +34 -21
- package/vitest.config.ts +1 -1
- package/dist/esm/errors.js +0 -58
- package/dist/esm/errors.js.map +0 -1
- package/dist/esm/lib/operators/capitalize-request-method.operator.js.map +0 -1
- package/dist/esm/lib/operators/fetch-request.schema.js.map +0 -1
- package/dist/esm/lib/operators/http-request-handler.js.map +0 -1
- package/dist/esm/lib/operators/http-response-handler.js.map +0 -1
- package/dist/esm/lib/operators/process-operators.js.map +0 -1
- package/dist/esm/lib/operators/sse.operator.js.map +0 -1
- package/dist/esm/lib/selectors/sse-selector.js.map +0 -1
- package/dist/types/errors.d.ts +0 -51
- package/src/errors.ts +0 -69
- package/dist/types/lib/operators/{process-operators.d.ts → ProcessOperators.d.ts} +0 -0
- package/dist/types/lib/operators/{capitalize-request-method.operator.d.ts → capitalize-request-method-operator.d.ts} +0 -0
- package/dist/types/lib/operators/{fetch-request.schema.d.ts → fetch-request.schemas.d.ts} +26 -26
- /package/dist/types/lib/operators/{request-validation.operator.d.ts → request-validation-operator.d.ts} +0 -0
- /package/dist/types/lib/selectors/{sse-selector.d.ts → create-sse-selector.d.ts} +0 -0
- /package/src/lib/operators/{fetch-request.schema.ts → fetch-request.schemas.ts} +0 -0
|
@@ -117,7 +117,11 @@ export interface IHttpClientConfigurator<TClient extends IHttpClient = IHttpClie
|
|
|
117
117
|
/** @inheritdoc */
|
|
118
118
|
export declare class HttpClientConfigurator<TClient extends IHttpClient> implements IHttpClientConfigurator<TClient> {
|
|
119
119
|
protected _clients: Record<string, HttpClientOptions<TClient>>;
|
|
120
|
-
/**
|
|
120
|
+
/**
|
|
121
|
+
* Gets a shallow clone of all named client configurations.
|
|
122
|
+
*
|
|
123
|
+
* @returns A shallow clone of the named client configurations.
|
|
124
|
+
*/
|
|
121
125
|
get clients(): Record<string, HttpClientOptions<TClient>>;
|
|
122
126
|
/** Default constructor used when a client configuration does not provide `ctor`. */
|
|
123
127
|
readonly defaultHttpClientCtor: HttpClientConstructor<TClient>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when `createClient(name)` is called with an unknown client key.
|
|
3
|
+
*
|
|
4
|
+
* This is only used when the provided string is neither a registered client name
|
|
5
|
+
* nor an absolute `http:` or `https:` URL.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ClientNotFoundException extends Error {
|
|
8
|
+
}
|
|
9
|
+
export default ClientNotFoundException;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HttpResponseError } from './HttpResponseError.js';
|
|
2
|
+
/**
|
|
3
|
+
* Represents an error that occurs when handling a JSON response in an HTTP request.
|
|
4
|
+
* Extends the base `HttpResponseError` class.
|
|
5
|
+
*
|
|
6
|
+
* @template TType - The type of the data associated with the error.
|
|
7
|
+
* @template TResponse - The type of the HTTP response.
|
|
8
|
+
*/
|
|
9
|
+
export declare class HttpJsonResponseError<TType = unknown, TResponse = Response> extends HttpResponseError<TResponse> {
|
|
10
|
+
static Name: string;
|
|
11
|
+
readonly data?: TType;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new instance of `HttpJsonResponseError`.
|
|
14
|
+
*
|
|
15
|
+
* @param message - The error message.
|
|
16
|
+
* @param response - The HTTP response associated with the error.
|
|
17
|
+
* @param options - Additional options for the error, including the associated data.
|
|
18
|
+
*/
|
|
19
|
+
constructor(message: string, response: TResponse, options?: ErrorOptions & {
|
|
20
|
+
data?: TType;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export default HttpJsonResponseError;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an error that occurs when handling an HTTP response.
|
|
3
|
+
* @template TResponse The type of the HTTP response.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HttpResponseError<TResponse = Response> extends Error {
|
|
6
|
+
readonly response: TResponse;
|
|
7
|
+
static Name: string;
|
|
8
|
+
/**
|
|
9
|
+
* @param message - The error message.
|
|
10
|
+
* @param response - The HTTP response associated with the error.
|
|
11
|
+
* @param options - Additional error options.
|
|
12
|
+
*/
|
|
13
|
+
constructor(message: string, response: TResponse, options?: ErrorOptions);
|
|
14
|
+
}
|
|
15
|
+
export default HttpResponseError;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HttpResponseError } from './HttpResponseError.js';
|
|
2
|
+
/**
|
|
3
|
+
* Represents an error that occurs when handling a server-sent event (SSE) HTTP response.
|
|
4
|
+
*
|
|
5
|
+
* @template TType - The type of additional data associated with the error.
|
|
6
|
+
* @template TResponse - The type of the HTTP response object.
|
|
7
|
+
*
|
|
8
|
+
* @extends HttpResponseError<TResponse>
|
|
9
|
+
*/
|
|
10
|
+
export declare class ServerSentEventResponseError<TType = unknown, TResponse = Response> extends HttpResponseError<TResponse> {
|
|
11
|
+
static Name: string;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new instance of the error.
|
|
14
|
+
*
|
|
15
|
+
* @param message - The error message describing the cause of the error.
|
|
16
|
+
* @param response - The HTTP response associated with the error.
|
|
17
|
+
* @param options - Optional error options, which may include additional data of type `TType`.
|
|
18
|
+
*/
|
|
19
|
+
constructor(message: string, response: TResponse, options?: ErrorOptions & {
|
|
20
|
+
data?: TType;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export default ServerSentEventResponseError;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
export * from './configurator';
|
|
6
6
|
export * from './provider';
|
|
7
7
|
export * from './module';
|
|
8
|
-
export * from './errors';
|
|
8
|
+
export * as Errors from './errors/index.js';
|
|
9
|
+
export * from './errors/index.js';
|
|
9
10
|
export type { IHttpClient, FetchResponse } from './lib/client';
|
|
10
11
|
export { default } from './module';
|
|
@@ -46,6 +46,7 @@ export declare class HttpClientMsal<TRequest extends MsalFetchRequest = MsalFetc
|
|
|
46
46
|
*
|
|
47
47
|
* @overrides HttpClient.fetch$
|
|
48
48
|
*
|
|
49
|
+
* @template T - The expected response type.
|
|
49
50
|
* @param path - The path to the resource to fetch.
|
|
50
51
|
* @param init - An optional `MsalFetchRequestInit` object that can include the `scopes` property.
|
|
51
52
|
* @returns An `Observable` that emits the fetched resource.
|
|
@@ -2,7 +2,7 @@ import { Subject } from 'rxjs';
|
|
|
2
2
|
import type { Observable, ObservableInput } from 'rxjs';
|
|
3
3
|
import type { IHttpRequestHandler, IHttpResponseHandler } from '../operators';
|
|
4
4
|
import type { BlobResult, FetchRequest, FetchRequestInit, FetchResponse, IHttpClient, JsonRequest, StreamResponse } from './types';
|
|
5
|
-
import { type ServerSentEvent, type SseSelectorOptions } from '../selectors/sse-selector';
|
|
5
|
+
import { type ServerSentEvent, type SseSelectorOptions } from '../selectors/create-sse-selector';
|
|
6
6
|
/**
|
|
7
7
|
* Configuration options for creating an `HttpClient` instance.
|
|
8
8
|
*
|
|
@@ -45,12 +45,19 @@ export declare class HttpClient<TRequest extends FetchRequest = FetchRequest, TR
|
|
|
45
45
|
protected _abort$: Subject<void>;
|
|
46
46
|
/**
|
|
47
47
|
* A stream of requests that are about to be executed.
|
|
48
|
+
* @returns An `Observable` that emits each request before it is executed.
|
|
48
49
|
*/
|
|
49
50
|
get request$(): Observable<TRequest>;
|
|
50
51
|
/**
|
|
51
52
|
* A stream of responses that have been received.
|
|
53
|
+
* @returns An `Observable` that emits each response as it is received.
|
|
52
54
|
*/
|
|
53
55
|
get response$(): Observable<TResponse>;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new `HttpClient`.
|
|
58
|
+
* @param uri - The base URI used to resolve relative request paths.
|
|
59
|
+
* @param options - Optional request and response handlers.
|
|
60
|
+
*/
|
|
54
61
|
constructor(uri: string, options?: Partial<HttpClientCreateOptions<TRequest, TResponse>>);
|
|
55
62
|
/**
|
|
56
63
|
* Internal method called by child classes to perform initialization logic in the constructor.
|
|
@@ -62,6 +69,7 @@ export declare class HttpClient<TRequest extends FetchRequest = FetchRequest, TR
|
|
|
62
69
|
/**
|
|
63
70
|
* Fetches data from the specified path and returns a stream response.
|
|
64
71
|
*
|
|
72
|
+
* @template T - The expected shape of the fetched data.
|
|
65
73
|
* @param path - The path to fetch data from.
|
|
66
74
|
* @param args - Optional request initialization options, including a custom selector function.
|
|
67
75
|
* @returns A stream response containing the fetched data.
|
|
@@ -70,16 +78,24 @@ export declare class HttpClient<TRequest extends FetchRequest = FetchRequest, TR
|
|
|
70
78
|
/**
|
|
71
79
|
* Fetches data from the specified path and returns a Promise containing the fetched data.
|
|
72
80
|
*
|
|
81
|
+
* @template T - The expected shape of the fetched data.
|
|
73
82
|
* @param path - The path to fetch data from.
|
|
74
83
|
* @param args - Optional request initialization options, including a custom selector function.
|
|
75
84
|
* @returns A Promise containing the fetched data.
|
|
76
85
|
*/
|
|
77
86
|
fetch<T = TResponse>(path: string, args?: FetchRequestInit<T, TRequest, TResponse>): Promise<T>;
|
|
78
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* @deprecated Use {@link fetch} instead.
|
|
89
|
+
* @template T - The expected shape of the fetched data.
|
|
90
|
+
* @param path - The path to fetch data from.
|
|
91
|
+
* @param args - Optional request initialization options, including a custom selector function.
|
|
92
|
+
* @returns A Promise containing the fetched data.
|
|
93
|
+
*/
|
|
79
94
|
fetchAsync<T = TResponse>(path: string, args?: FetchRequestInit<T, TRequest, TResponse>): Promise<T>;
|
|
80
95
|
/**
|
|
81
96
|
* Fetches data from the specified path and returns a stream response containing the data in JSON format.
|
|
82
97
|
*
|
|
98
|
+
* @template T - The expected shape of the parsed JSON data.
|
|
83
99
|
* @param path - The path to fetch the data from.
|
|
84
100
|
* @param args - Optional request initialization options, including a custom selector function and request body.
|
|
85
101
|
* - `body`: The request body, which will be automatically serialized to JSON if it's an object.
|
|
@@ -91,6 +107,7 @@ export declare class HttpClient<TRequest extends FetchRequest = FetchRequest, TR
|
|
|
91
107
|
/**
|
|
92
108
|
* Fetches data from the specified path and returns a Promise containing the fetched data in JSON format.
|
|
93
109
|
*
|
|
110
|
+
* @template T - The expected shape of the parsed JSON data.
|
|
94
111
|
* @param path - The path to fetch the data from.
|
|
95
112
|
* @param args - Optional request initialization options, including a custom selector function and request body.
|
|
96
113
|
* - `body`: The request body, which will be automatically serialized to JSON if it's an object.
|
|
@@ -102,6 +119,7 @@ export declare class HttpClient<TRequest extends FetchRequest = FetchRequest, TR
|
|
|
102
119
|
/**
|
|
103
120
|
* Fetches a blob resource from the specified path and returns a stream response.
|
|
104
121
|
*
|
|
122
|
+
* @template T - The expected shape of the fetched blob data.
|
|
105
123
|
* @param path - The path to the blob resource.
|
|
106
124
|
* @param args - Optional request initialization options, including a custom selector function.
|
|
107
125
|
* @returns A stream response containing the fetched blob data.
|
|
@@ -110,6 +128,7 @@ export declare class HttpClient<TRequest extends FetchRequest = FetchRequest, TR
|
|
|
110
128
|
/**
|
|
111
129
|
* Fetches a blob from the specified path and returns a Promise that resolves to the blob result.
|
|
112
130
|
*
|
|
131
|
+
* @template T - The expected shape of the fetched blob data.
|
|
113
132
|
* @param path - The path to fetch the blob from.
|
|
114
133
|
* @param args - Optional arguments for the fetch request, including request body, headers, and response type.
|
|
115
134
|
* @returns A Promise that resolves to the blob result.
|
|
@@ -138,11 +157,19 @@ export declare class HttpClient<TRequest extends FetchRequest = FetchRequest, TR
|
|
|
138
157
|
* });
|
|
139
158
|
*/
|
|
140
159
|
sse$<T = unknown>(path: string, args?: FetchRequestInit<ServerSentEvent<T>, TRequest, TResponse> | null, options?: Omit<SseSelectorOptions<T>, 'abortSignal'>): StreamResponse<ServerSentEvent<T>>;
|
|
141
|
-
/**
|
|
160
|
+
/**
|
|
161
|
+
* @deprecated Use {@link json} instead.
|
|
162
|
+
* @template T - The expected shape of the parsed JSON data.
|
|
163
|
+
* @param path - The path to fetch the data from.
|
|
164
|
+
* @param args - Optional request initialization options, including a custom selector function and request body.
|
|
165
|
+
* @returns A Promise containing the fetched data in JSON format.
|
|
166
|
+
*/
|
|
142
167
|
jsonAsync<T = unknown>(path: string, args?: FetchRequestInit<T, JsonRequest<TRequest>, TResponse>): Promise<T>;
|
|
143
168
|
/**
|
|
144
169
|
* Executes an HTTP request using the specified method and path.
|
|
145
170
|
*
|
|
171
|
+
* @template T - The expected shape of the result.
|
|
172
|
+
* @template TMethod - The name of the `IHttpClient` method to invoke.
|
|
146
173
|
* @param method - The HTTP method to use for the request, such as 'fetch', 'json', or 'blob'.
|
|
147
174
|
* @param path - The path to the resource to fetch.
|
|
148
175
|
* @param init - Optional request initialization options, including request body, headers, and response type.
|
|
@@ -158,10 +185,13 @@ export declare class HttpClient<TRequest extends FetchRequest = FetchRequest, TR
|
|
|
158
185
|
/**
|
|
159
186
|
* Fetches data from the specified path and returns an Observable that emits the response.
|
|
160
187
|
*
|
|
188
|
+
* @template T - The expected shape of the emitted data.
|
|
161
189
|
* @param path - The path to fetch the data from.
|
|
162
190
|
* @param args - Optional arguments for the fetch request, including a response selector function, request body, headers, and response type.
|
|
163
191
|
* @returns {Observable<T>} An Observable that emits the response data.
|
|
164
192
|
*
|
|
193
|
+
* @throws {HttpResponseError} When the optional `selector` throws while transforming the response.
|
|
194
|
+
*
|
|
165
195
|
* This method handles the following steps:
|
|
166
196
|
* 1. Resolves the full URL by combining the base URI and the provided path.
|
|
167
197
|
* 2. Prepares the request by passing it through the `requestHandler.process()` method.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProcessOperators } from './
|
|
1
|
+
import { ProcessOperators } from './ProcessOperators';
|
|
2
2
|
/**
|
|
3
3
|
* The `HttpResponseHandler` class extends the `ProcessOperators` class and is responsible for handling HTTP responses.
|
|
4
4
|
* It provides a common interface for processing HTTP responses, allowing for consistent error handling and response transformation.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { HttpRequestHandler } from './
|
|
2
|
-
export { HttpResponseHandler } from './
|
|
3
|
-
export { ProcessOperators } from './
|
|
4
|
-
export { capitalizeRequestMethodOperator } from './capitalize-request-method
|
|
5
|
-
export { requestValidationOperator } from './request-validation
|
|
6
|
-
export { sseMap } from './sse.operator';
|
|
1
|
+
export { HttpRequestHandler } from './HttpRequestHandler';
|
|
2
|
+
export { HttpResponseHandler } from './HttpResponseHandler';
|
|
3
|
+
export { ProcessOperators } from './ProcessOperators';
|
|
4
|
+
export { capitalizeRequestMethodOperator } from './capitalize-request-method-operator';
|
|
5
|
+
export { requestValidationOperator } from './request-validation-operator';
|
|
6
|
+
export { sseMap } from './sse-map.operator';
|
|
7
7
|
export * from './types';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OperatorFunction } from 'rxjs';
|
|
2
|
-
import { type ServerSentEvent, type SseSelectorOptions } from '../selectors/sse-selector';
|
|
2
|
+
import { type ServerSentEvent, type SseSelectorOptions } from '../selectors/create-sse-selector';
|
|
3
3
|
/**
|
|
4
4
|
* An operator function for handling Server-Sent Events (SSE) in an RxJS pipeline.
|
|
5
5
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { jsonSelector } from './json-selector';
|
|
2
2
|
export { blobSelector } from './blob-selector';
|
|
3
|
-
export { createSseSelector } from './sse-selector';
|
|
3
|
+
export { createSseSelector } from './create-sse-selector';
|
|
4
4
|
export type { ResponseSelector } from '../client/types';
|
|
5
|
-
export type { DataParser, ServerSentEvent, SseSelector, SseSelectorOptions, } from './sse-selector';
|
|
5
|
+
export type { DataParser, ServerSentEvent, SseSelector, SseSelectorOptions, } from './create-sse-selector';
|
package/dist/types/provider.d.ts
CHANGED
|
@@ -3,14 +3,6 @@ import type { HttpClientOptions, HttpClientRequestInitType, IHttpClientConfigura
|
|
|
3
3
|
import type { IHttpRequestHandler } from './lib/operators';
|
|
4
4
|
import type { IHttpClient } from './lib/client';
|
|
5
5
|
import { BaseModuleProvider } from '@equinor/fusion-framework-module/provider';
|
|
6
|
-
/**
|
|
7
|
-
* Thrown when `createClient(name)` is called with an unknown client key.
|
|
8
|
-
*
|
|
9
|
-
* This is only used when the provided string is neither a registered client name
|
|
10
|
-
* nor an absolute `http:` or `https:` URL.
|
|
11
|
-
*/
|
|
12
|
-
export declare class ClientNotFoundException extends Error {
|
|
13
|
-
}
|
|
14
6
|
/**
|
|
15
7
|
* Creates fresh HTTP client instances from named or ad-hoc configuration.
|
|
16
8
|
*
|
|
@@ -62,6 +54,10 @@ export declare class HttpClientProvider<TClient extends IHttpClient = IHttpClien
|
|
|
62
54
|
* @returns The default HTTP request handler.
|
|
63
55
|
*/
|
|
64
56
|
get defaultHttpRequestHandler(): IHttpRequestHandler<HttpClientRequestInitType<TClient>>;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new `HttpClientProvider`.
|
|
59
|
+
* @param config - The configurator providing client definitions and defaults.
|
|
60
|
+
*/
|
|
65
61
|
constructor(config: IHttpClientConfigurator<TClient>);
|
|
66
62
|
/**
|
|
67
63
|
* Checks if a client with the given key is configured in the `HttpClientProvider`.
|
|
@@ -89,6 +85,7 @@ export declare class HttpClientProvider<TClient extends IHttpClient = IHttpClien
|
|
|
89
85
|
/**
|
|
90
86
|
* Creates a client instance and returns it as the requested custom client type.
|
|
91
87
|
*
|
|
88
|
+
* @template T - The custom `HttpClient` implementation type to cast the created instance to.
|
|
92
89
|
* @param key - The key of the pre-configured HTTP client to create.
|
|
93
90
|
* @returns The created HTTP client instance, cast to the specified type `T`.
|
|
94
91
|
*
|
|
@@ -108,6 +105,8 @@ export declare class HttpClientProvider<TClient extends IHttpClient = IHttpClien
|
|
|
108
105
|
*
|
|
109
106
|
* @param keyOrConfig - The key or configuration object for the HTTP client.
|
|
110
107
|
* @returns The resolved HTTP client configuration.
|
|
108
|
+
* @throws {ClientNotFoundException} When `keyOrConfig` is a string that is neither a registered
|
|
109
|
+
* client key nor a URL-like value.
|
|
111
110
|
*/
|
|
112
111
|
protected _resolveConfig(keyOrConfig: string | HttpClientOptions<TClient>): HttpClientOptions<TClient>;
|
|
113
112
|
}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "8.0.
|
|
1
|
+
export declare const version = "8.0.4";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-module-http",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"types": "./dist/types/lib/selectors/index.d.ts"
|
|
23
23
|
},
|
|
24
24
|
"./errors": {
|
|
25
|
-
"import": "./dist/esm/errors.js",
|
|
26
|
-
"types": "./dist/types/errors.d.ts"
|
|
25
|
+
"import": "./dist/esm/errors/index.js",
|
|
26
|
+
"types": "./dist/types/errors/index.d.ts"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"typesVersions": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dist/types/lib/selectors/index.d.ts"
|
|
42
42
|
],
|
|
43
43
|
"errors": [
|
|
44
|
-
"dist/types/errors.d.ts"
|
|
44
|
+
"dist/types/errors/index.d.ts"
|
|
45
45
|
]
|
|
46
46
|
}
|
|
47
47
|
},
|
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"rxjs": "^7.8.1",
|
|
61
61
|
"zod": "^4.4.3",
|
|
62
|
-
"@equinor/fusion-framework-module": "^6.1.
|
|
63
|
-
"@equinor/fusion-framework-module-msal": "^10.0.
|
|
62
|
+
"@equinor/fusion-framework-module": "^6.1.1",
|
|
63
|
+
"@equinor/fusion-framework-module-msal": "^10.0.2"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"typescript": "^
|
|
66
|
+
"typescript": "^7.0.2",
|
|
67
67
|
"vitest": "^4.1.0"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
package/src/configurator.ts
CHANGED
|
@@ -155,7 +155,11 @@ export class HttpClientConfigurator<TClient extends IHttpClient>
|
|
|
155
155
|
{
|
|
156
156
|
protected _clients: Record<string, HttpClientOptions<TClient>> = {};
|
|
157
157
|
|
|
158
|
-
/**
|
|
158
|
+
/**
|
|
159
|
+
* Gets a shallow clone of all named client configurations.
|
|
160
|
+
*
|
|
161
|
+
* @returns A shallow clone of the named client configurations.
|
|
162
|
+
*/
|
|
159
163
|
public get clients(): Record<string, HttpClientOptions<TClient>> {
|
|
160
164
|
return { ...this._clients };
|
|
161
165
|
}
|
|
@@ -191,6 +195,8 @@ export class HttpClientConfigurator<TClient extends IHttpClient>
|
|
|
191
195
|
): HttpClientConfigurator<TClient> {
|
|
192
196
|
const argFn = typeof args === 'string' ? ({ baseUri: args } as HttpClientOptions<T>) : args;
|
|
193
197
|
const options = typeof argFn === 'function' ? { onCreate: argFn } : argFn;
|
|
198
|
+
// `options` is `HttpClientOptions<T>` (this call's generic), but `_clients` is keyed by the
|
|
199
|
+
// configurator's own `TClient` — callers are expected to keep the two in sync.
|
|
194
200
|
this._clients[name] = {
|
|
195
201
|
...this._clients[name],
|
|
196
202
|
...(options as unknown as HttpClientOptions<TClient>),
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when `createClient(name)` is called with an unknown client key.
|
|
3
|
+
*
|
|
4
|
+
* This is only used when the provided string is neither a registered client name
|
|
5
|
+
* nor an absolute `http:` or `https:` URL.
|
|
6
|
+
*/
|
|
7
|
+
export class ClientNotFoundException extends Error {}
|
|
8
|
+
|
|
9
|
+
export default ClientNotFoundException;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { HttpResponseError } from './HttpResponseError.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents an error that occurs when handling a JSON response in an HTTP request.
|
|
5
|
+
* Extends the base `HttpResponseError` class.
|
|
6
|
+
*
|
|
7
|
+
* @template TType - The type of the data associated with the error.
|
|
8
|
+
* @template TResponse - The type of the HTTP response.
|
|
9
|
+
*/
|
|
10
|
+
export class HttpJsonResponseError<
|
|
11
|
+
TType = unknown,
|
|
12
|
+
TResponse = Response,
|
|
13
|
+
> extends HttpResponseError<TResponse> {
|
|
14
|
+
static Name = 'HttpJsonResponseError';
|
|
15
|
+
public readonly data?: TType;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new instance of `HttpJsonResponseError`.
|
|
19
|
+
*
|
|
20
|
+
* @param message - The error message.
|
|
21
|
+
* @param response - The HTTP response associated with the error.
|
|
22
|
+
* @param options - Additional options for the error, including the associated data.
|
|
23
|
+
*/
|
|
24
|
+
constructor(message: string, response: TResponse, options?: ErrorOptions & { data?: TType }) {
|
|
25
|
+
super(message, response, options);
|
|
26
|
+
this.name = HttpJsonResponseError.Name;
|
|
27
|
+
this.data = options?.data;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default HttpJsonResponseError;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an error that occurs when handling an HTTP response.
|
|
3
|
+
* @template TResponse The type of the HTTP response.
|
|
4
|
+
*/
|
|
5
|
+
export class HttpResponseError<TResponse = Response> extends Error {
|
|
6
|
+
static Name = 'HttpResponseError';
|
|
7
|
+
/**
|
|
8
|
+
* @param message - The error message.
|
|
9
|
+
* @param response - The HTTP response associated with the error.
|
|
10
|
+
* @param options - Additional error options.
|
|
11
|
+
*/
|
|
12
|
+
constructor(
|
|
13
|
+
message: string,
|
|
14
|
+
public readonly response: TResponse,
|
|
15
|
+
options?: ErrorOptions,
|
|
16
|
+
) {
|
|
17
|
+
super(message, options);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default HttpResponseError;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HttpResponseError } from './HttpResponseError.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents an error that occurs when handling a server-sent event (SSE) HTTP response.
|
|
5
|
+
*
|
|
6
|
+
* @template TType - The type of additional data associated with the error.
|
|
7
|
+
* @template TResponse - The type of the HTTP response object.
|
|
8
|
+
*
|
|
9
|
+
* @extends HttpResponseError<TResponse>
|
|
10
|
+
*/
|
|
11
|
+
export class ServerSentEventResponseError<
|
|
12
|
+
TType = unknown,
|
|
13
|
+
TResponse = Response,
|
|
14
|
+
> extends HttpResponseError<TResponse> {
|
|
15
|
+
static Name = 'ServerSentEventResponseError';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new instance of the error.
|
|
19
|
+
*
|
|
20
|
+
* @param message - The error message describing the cause of the error.
|
|
21
|
+
* @param response - The HTTP response associated with the error.
|
|
22
|
+
* @param options - Optional error options, which may include additional data of type `TType`.
|
|
23
|
+
*/
|
|
24
|
+
constructor(message: string, response: TResponse, options?: ErrorOptions & { data?: TType }) {
|
|
25
|
+
super(message, response, options);
|
|
26
|
+
this.name = ServerSentEventResponseError.Name;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default ServerSentEventResponseError;
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,8 @@ export * from './configurator';
|
|
|
7
7
|
export * from './provider';
|
|
8
8
|
export * from './module';
|
|
9
9
|
|
|
10
|
-
export * from './errors';
|
|
10
|
+
export * as Errors from './errors/index.js';
|
|
11
|
+
export * from './errors/index.js';
|
|
11
12
|
|
|
12
13
|
export type { IHttpClient, FetchResponse } from './lib/client';
|
|
13
14
|
|
|
@@ -55,6 +55,7 @@ export class HttpClientMsal<
|
|
|
55
55
|
*
|
|
56
56
|
* @overrides HttpClient.fetch$
|
|
57
57
|
*
|
|
58
|
+
* @template T - The expected response type.
|
|
58
59
|
* @param path - The path to the resource to fetch.
|
|
59
60
|
* @param init - An optional `MsalFetchRequestInit` object that can include the `scopes` property.
|
|
60
61
|
* @returns An `Observable` that emits the fetched resource.
|