@equinor/fusion-framework-module-http 7.0.1 → 7.0.3
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 +21 -0
- package/dist/esm/lib/operators/fetch-request.schema.js +5 -2
- package/dist/esm/lib/operators/fetch-request.schema.js.map +1 -1
- package/dist/esm/provider.js +7 -1
- 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/fetch-request.schema.d.ts +4 -4
- package/dist/types/provider.d.ts +2 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -3
- package/src/lib/operators/fetch-request.schema.ts +12 -9
- package/src/provider.ts +9 -1
- package/src/version.ts +1 -1
- package/tests/operators.test.ts +16 -8
|
@@ -4,7 +4,7 @@ import { z } from 'zod';
|
|
|
4
4
|
*
|
|
5
5
|
* @link https://www.rfc-editor.org/rfc/rfc7231#section-4.1
|
|
6
6
|
*/
|
|
7
|
-
export declare const requestMethodCasing: () => z.ZodType<string>;
|
|
7
|
+
export declare const requestMethodCasing: () => z.ZodType<string | undefined>;
|
|
8
8
|
/**
|
|
9
9
|
* Creates a Zod enum schema for HTTP request methods.
|
|
10
10
|
*
|
|
@@ -28,7 +28,7 @@ export declare const requestMethodVerb: () => z.ZodEnum<{
|
|
|
28
28
|
CONNECT: "CONNECT";
|
|
29
29
|
TRACE: "TRACE";
|
|
30
30
|
}>;
|
|
31
|
-
export declare const requestMethod: () => z.
|
|
31
|
+
export declare const requestMethod: () => z.ZodOptional<z.ZodEnum<{
|
|
32
32
|
GET: "GET";
|
|
33
33
|
POST: "POST";
|
|
34
34
|
PUT: "PUT";
|
|
@@ -69,7 +69,7 @@ export declare const requestInitSchema: z.ZodObject<{
|
|
|
69
69
|
headers: z.ZodUnion<[z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>, z.ZodCustom<Headers, Headers>]>;
|
|
70
70
|
integrity: z.ZodOptional<z.ZodString>;
|
|
71
71
|
keepalive: z.ZodOptional<z.ZodBoolean>;
|
|
72
|
-
method: z.ZodOptional<z.
|
|
72
|
+
method: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
|
|
73
73
|
GET: "GET";
|
|
74
74
|
POST: "POST";
|
|
75
75
|
PUT: "PUT";
|
|
@@ -140,7 +140,7 @@ export declare const fetchRequestSchema: z.ZodObject<{
|
|
|
140
140
|
headers: z.ZodUnion<[z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>, z.ZodCustom<Headers, Headers>]>;
|
|
141
141
|
integrity: z.ZodOptional<z.ZodString>;
|
|
142
142
|
keepalive: z.ZodOptional<z.ZodBoolean>;
|
|
143
|
-
method: z.ZodOptional<z.
|
|
143
|
+
method: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
|
|
144
144
|
GET: "GET";
|
|
145
145
|
POST: "POST";
|
|
146
146
|
PUT: "PUT";
|
package/dist/types/provider.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { HttpClient } from './lib/client';
|
|
|
2
2
|
import type { HttpClientOptions, HttpClientRequestInitType, IHttpClientConfigurator } from './configurator';
|
|
3
3
|
import type { IHttpRequestHandler } from './lib/operators';
|
|
4
4
|
import type { IHttpClient } from './lib/client';
|
|
5
|
+
import { BaseModuleProvider } from '@equinor/fusion-framework-module/provider';
|
|
5
6
|
/**
|
|
6
7
|
* Exception thrown when a client cannot be found.
|
|
7
8
|
*
|
|
@@ -46,7 +47,7 @@ export interface IHttpClientProvider<TClient extends IHttpClient = IHttpClient>
|
|
|
46
47
|
* The `HttpClientProvider` class is responsible for managing HTTP client instances and their configuration.
|
|
47
48
|
* It provides methods to check if a client is configured, create new client instances, and create custom client instances.
|
|
48
49
|
*/
|
|
49
|
-
export declare class HttpClientProvider<TClient extends IHttpClient = IHttpClient> implements IHttpClientProvider<TClient> {
|
|
50
|
+
export declare class HttpClientProvider<TClient extends IHttpClient = IHttpClient> extends BaseModuleProvider<IHttpClientConfigurator<TClient>> implements IHttpClientProvider<TClient> {
|
|
50
51
|
protected config: IHttpClientConfigurator<TClient>;
|
|
51
52
|
/**
|
|
52
53
|
* Gets the default HTTP request handler for the HTTP client provider.
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "7.0.
|
|
1
|
+
export declare const version = "7.0.3";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-module-http",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"rxjs": "^7.8.1",
|
|
61
61
|
"zod": "^4.1.8",
|
|
62
|
-
"@equinor/fusion-framework-module": "^5.0.
|
|
63
|
-
"@equinor/fusion-framework-module-msal": "^5.
|
|
62
|
+
"@equinor/fusion-framework-module": "^5.0.4",
|
|
63
|
+
"@equinor/fusion-framework-module-msal": "^5.1.1"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"typescript": "^5.8.2",
|
|
@@ -5,14 +5,17 @@ import { z } from 'zod';
|
|
|
5
5
|
*
|
|
6
6
|
* @link https://www.rfc-editor.org/rfc/rfc7231#section-4.1
|
|
7
7
|
*/
|
|
8
|
-
export const requestMethodCasing = (): z.ZodType<string> => {
|
|
9
|
-
return z
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
export const requestMethodCasing = (): z.ZodType<string | undefined> => {
|
|
9
|
+
return z
|
|
10
|
+
.string()
|
|
11
|
+
.optional()
|
|
12
|
+
.refine((value) => value === undefined || value === value?.toUpperCase(), {
|
|
13
|
+
message: [
|
|
14
|
+
'Provided HTTP method must be in uppercase.',
|
|
15
|
+
'See RFC 7231 Section 4.1 for more information',
|
|
16
|
+
'https://www.rfc-editor.org/rfc/rfc7231#section-4.1',
|
|
17
|
+
].join(' '),
|
|
18
|
+
});
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
/**
|
|
@@ -34,7 +37,7 @@ export const requestMethodVerb = () => {
|
|
|
34
37
|
});
|
|
35
38
|
};
|
|
36
39
|
|
|
37
|
-
export const requestMethod = () =>
|
|
40
|
+
export const requestMethod = () => requestMethodVerb().optional();
|
|
38
41
|
|
|
39
42
|
/**
|
|
40
43
|
* Schema for validating the initialization options of a request.
|
package/src/provider.ts
CHANGED
|
@@ -7,6 +7,8 @@ import type {
|
|
|
7
7
|
|
|
8
8
|
import type { IHttpRequestHandler } from './lib/operators';
|
|
9
9
|
import type { IHttpClient } from './lib/client';
|
|
10
|
+
import { BaseModuleProvider } from '@equinor/fusion-framework-module/provider';
|
|
11
|
+
import { version } from './version';
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Exception thrown when a client cannot be found.
|
|
@@ -75,6 +77,7 @@ const isURL = (url: string) => {
|
|
|
75
77
|
* It provides methods to check if a client is configured, create new client instances, and create custom client instances.
|
|
76
78
|
*/
|
|
77
79
|
export class HttpClientProvider<TClient extends IHttpClient = IHttpClient>
|
|
80
|
+
extends BaseModuleProvider<IHttpClientConfigurator<TClient>>
|
|
78
81
|
implements IHttpClientProvider<TClient>
|
|
79
82
|
{
|
|
80
83
|
/**
|
|
@@ -85,7 +88,12 @@ export class HttpClientProvider<TClient extends IHttpClient = IHttpClient>
|
|
|
85
88
|
return this.config.defaultHttpRequestHandler;
|
|
86
89
|
}
|
|
87
90
|
|
|
88
|
-
constructor(protected config: IHttpClientConfigurator<TClient>) {
|
|
91
|
+
constructor(protected config: IHttpClientConfigurator<TClient>) {
|
|
92
|
+
super({
|
|
93
|
+
version,
|
|
94
|
+
config,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
89
97
|
|
|
90
98
|
/**
|
|
91
99
|
* Checks if a client with the given key is configured in the `HttpClientProvider`.
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '7.0.
|
|
2
|
+
export const version = '7.0.3';
|
package/tests/operators.test.ts
CHANGED
|
@@ -30,9 +30,17 @@ describe('capitalizeRequestMethodOperator', () => {
|
|
|
30
30
|
|
|
31
31
|
const result = executeOperator(operator, { method: 'get' });
|
|
32
32
|
|
|
33
|
-
expect(result).resolves.toMatchObject({ method: 'GET' });
|
|
33
|
+
await expect(result).resolves.toMatchObject({ method: 'GET' });
|
|
34
34
|
expect(consoleWarn).toHaveBeenCalled();
|
|
35
35
|
});
|
|
36
|
+
|
|
37
|
+
it('should handle undefined request method', async () => {
|
|
38
|
+
const operator = capitalizeRequestMethodOperator();
|
|
39
|
+
|
|
40
|
+
const result = executeOperator(operator, { method: undefined });
|
|
41
|
+
|
|
42
|
+
await expect(result).resolves.toMatchObject({ method: undefined });
|
|
43
|
+
});
|
|
36
44
|
});
|
|
37
45
|
|
|
38
46
|
describe('requestValidationOperator', () => {
|
|
@@ -50,7 +58,7 @@ describe('requestValidationOperator', () => {
|
|
|
50
58
|
|
|
51
59
|
const result = executeOperator(operator, mockRequest);
|
|
52
60
|
|
|
53
|
-
expect(result).resolves.toBeUndefined();
|
|
61
|
+
await expect(result).resolves.toBeUndefined();
|
|
54
62
|
});
|
|
55
63
|
|
|
56
64
|
it('should parse valid request parameters', async () => {
|
|
@@ -58,7 +66,7 @@ describe('requestValidationOperator', () => {
|
|
|
58
66
|
|
|
59
67
|
const result = executeOperator(operator, mockRequest);
|
|
60
68
|
|
|
61
|
-
expect(result).resolves.toStrictEqual(mockRequest);
|
|
69
|
+
await expect(result).resolves.toStrictEqual(mockRequest);
|
|
62
70
|
});
|
|
63
71
|
|
|
64
72
|
it('should allow additional properties when strict validation is disabled', async () => {
|
|
@@ -70,8 +78,8 @@ describe('requestValidationOperator', () => {
|
|
|
70
78
|
additionalProperty: 'some-value',
|
|
71
79
|
});
|
|
72
80
|
|
|
73
|
-
expect(result).resolves.toMatchObject(mockRequest);
|
|
74
|
-
expect(result).resolves.toHaveProperty('additionalProperty', 'some-value');
|
|
81
|
+
await expect(result).resolves.toMatchObject(mockRequest);
|
|
82
|
+
await expect(result).resolves.toHaveProperty('additionalProperty', 'some-value');
|
|
75
83
|
});
|
|
76
84
|
|
|
77
85
|
it('should remove additional properties when strict validation is enabled', async () => {
|
|
@@ -84,8 +92,8 @@ describe('requestValidationOperator', () => {
|
|
|
84
92
|
method: 'GET',
|
|
85
93
|
});
|
|
86
94
|
|
|
87
|
-
expect(result).resolves.toStrictEqual(mockRequest);
|
|
88
|
-
expect(result).resolves.not.toHaveProperty('additionalProperty');
|
|
95
|
+
await expect(result).resolves.toStrictEqual(mockRequest);
|
|
96
|
+
await expect(result).resolves.not.toHaveProperty('additionalProperty');
|
|
89
97
|
});
|
|
90
98
|
|
|
91
99
|
it('should throw an error for invalid request parameters', async () => {
|
|
@@ -96,6 +104,6 @@ describe('requestValidationOperator', () => {
|
|
|
96
104
|
method: 'GETS', // invalid method
|
|
97
105
|
});
|
|
98
106
|
|
|
99
|
-
expect(result).rejects.toThrowError('RFC 2615');
|
|
107
|
+
await expect(result).rejects.toThrowError('RFC 2615');
|
|
100
108
|
});
|
|
101
109
|
});
|