@equinor/fusion-framework-module-http 8.1.0 → 8.1.1
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/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +6 -3
- package/CHANGELOG.md +0 -1299
- package/docs/client-configuration.md +0 -175
- package/docs/observable-patterns.md +0 -103
- package/docs/selectors-and-handlers.md +0 -112
- package/docs/server-sent-events.md +0 -125
- package/docs/testing.md +0 -78
- package/src/configurator.ts +0 -249
- package/src/errors/ClientNotFoundException.ts +0 -9
- package/src/errors/HttpJsonResponseError.ts +0 -32
- package/src/errors/HttpResponseError.ts +0 -21
- package/src/errors/ServerSentEventResponseError.ts +0 -30
- package/src/errors/index.ts +0 -4
- package/src/index.ts +0 -15
- package/src/lib/client/client-msal.ts +0 -80
- package/src/lib/client/client.ts +0 -496
- package/src/lib/client/index.ts +0 -4
- package/src/lib/client/types.ts +0 -244
- package/src/lib/index.ts +0 -3
- package/src/lib/operators/HttpMiddlewareHandler.ts +0 -58
- package/src/lib/operators/HttpRequestHandler.ts +0 -29
- package/src/lib/operators/HttpResponseHandler.ts +0 -11
- package/src/lib/operators/ProcessOperators.ts +0 -113
- package/src/lib/operators/capitalize-request-method-operator.ts +0 -26
- package/src/lib/operators/fetch-request.schemas.ts +0 -104
- package/src/lib/operators/index.ts +0 -9
- package/src/lib/operators/request-operator-header.ts +0 -19
- package/src/lib/operators/request-validation-operator.ts +0 -51
- package/src/lib/operators/sse-map.operator.ts +0 -45
- package/src/lib/operators/types.ts +0 -174
- package/src/lib/selectors/blob-selector.ts +0 -42
- package/src/lib/selectors/create-sse-selector.ts +0 -279
- package/src/lib/selectors/index.ts +0 -11
- package/src/lib/selectors/json-selector.ts +0 -52
- package/src/mock/create-open-api-mock-middleware.ts +0 -40
- package/src/mock/create-router-middleware.ts +0 -158
- package/src/mock/index.ts +0 -26
- package/src/mock/resolve-open-api-mock-response.ts +0 -36
- package/src/module.ts +0 -149
- package/src/provider.ts +0 -225
- package/src/version.ts +0 -2
- package/tests/HttpClient.test.ts +0 -173
- package/tests/HttpMiddlewareHandler.test.ts +0 -58
- package/tests/mock/adapters.test.ts +0 -62
- package/tests/mock/router-middleware.test.ts +0 -135
- package/tests/operators.test.ts +0 -137
- package/tests/sse.selector.test.ts +0 -162
- package/tsconfig.json +0 -18
- package/vitest.config.ts +0 -12
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { ServerSentEventResponseError } from '../src/errors/index.js';
|
|
3
|
-
import { createSseSelector, type ServerSentEvent } from '../src/lib/selectors';
|
|
4
|
-
import { of, lastValueFrom } from 'rxjs';
|
|
5
|
-
import { concatMap, scan } from 'rxjs/operators';
|
|
6
|
-
|
|
7
|
-
// Helper to create a mock Response
|
|
8
|
-
function createMockResponse(
|
|
9
|
-
bodyChunks: (Uint8Array | null)[],
|
|
10
|
-
headers: Record<string, string> = { 'Content-Type': 'text/event-stream' },
|
|
11
|
-
status = 200,
|
|
12
|
-
): Response {
|
|
13
|
-
const body = new ReadableStream({
|
|
14
|
-
start(controller) {
|
|
15
|
-
// feed each chunk to the stream, treating a null chunk as end-of-stream
|
|
16
|
-
for (const chunk of bodyChunks) {
|
|
17
|
-
// a null chunk signals the mock stream should close early
|
|
18
|
-
if (chunk === null) {
|
|
19
|
-
controller.close();
|
|
20
|
-
// nothing left to enqueue once the stream is closed
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
controller.enqueue(chunk);
|
|
24
|
-
}
|
|
25
|
-
controller.close();
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
return new Response(body, { status, headers });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
describe('createSseSelector', () => {
|
|
32
|
-
it('emits parsed events from a valid SSE response', async () => {
|
|
33
|
-
const chunks = [new Uint8Array(new TextEncoder().encode('data: {"key": "value"}\n\n'))];
|
|
34
|
-
const response = createMockResponse(chunks);
|
|
35
|
-
const selector = createSseSelector();
|
|
36
|
-
const events = await lastValueFrom(
|
|
37
|
-
of(response)
|
|
38
|
-
// parse the SSE stream into individual events and collect them into an array
|
|
39
|
-
.pipe(
|
|
40
|
-
concatMap(selector),
|
|
41
|
-
scan((acc, event) => [...acc, event], [] as ServerSentEvent[]),
|
|
42
|
-
),
|
|
43
|
-
);
|
|
44
|
-
expect(events).toEqual([{ data: { key: 'value' } }]);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('throws on non-200 response', () => {
|
|
48
|
-
const response = createMockResponse([], {}, 500);
|
|
49
|
-
const selector = createSseSelector();
|
|
50
|
-
|
|
51
|
-
expect(() => selector(response)).toThrowError(
|
|
52
|
-
new ServerSentEventResponseError('HTTP error! Status: 500', response),
|
|
53
|
-
);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('throws on missing body', () => {
|
|
57
|
-
const response = new Response(null, {
|
|
58
|
-
headers: { 'Content-Type': 'text/event-stream' },
|
|
59
|
-
});
|
|
60
|
-
const selector = createSseSelector();
|
|
61
|
-
|
|
62
|
-
expect(() => selector(response)).toThrowError(
|
|
63
|
-
new ServerSentEventResponseError('Response body is not readable', response),
|
|
64
|
-
);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('throws on invalid Content-Type', () => {
|
|
68
|
-
const response = createMockResponse([], { 'Content-Type': 'application/json' });
|
|
69
|
-
const selector = createSseSelector();
|
|
70
|
-
|
|
71
|
-
expect(() => selector(response)).toThrowError(
|
|
72
|
-
new ServerSentEventResponseError('Response is not a text/event-stream', response),
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('filters events by event type', async () => {
|
|
77
|
-
const chunks = [
|
|
78
|
-
new Uint8Array(new TextEncoder().encode('event: message\ndata: {"key": "value"}\n\n')),
|
|
79
|
-
new Uint8Array(new TextEncoder().encode('event: other\ndata: {"other": "data"}\n\n')),
|
|
80
|
-
];
|
|
81
|
-
const response = createMockResponse(chunks);
|
|
82
|
-
const selector = createSseSelector({ eventFilter: 'message' });
|
|
83
|
-
const events = await lastValueFrom(
|
|
84
|
-
of(response)
|
|
85
|
-
// parse the SSE stream into individual events and collect them into an array
|
|
86
|
-
.pipe(
|
|
87
|
-
concatMap(selector),
|
|
88
|
-
scan((acc, event) => [...acc, event], [] as ServerSentEvent[]),
|
|
89
|
-
),
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
expect(events).toEqual([{ event: 'message', data: { key: 'value' } }]);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('skips heartbeat events when skipHeartbeats is true', async () => {
|
|
96
|
-
const chunks = [
|
|
97
|
-
new Uint8Array(new TextEncoder().encode(':heartbeat\n\n')), // Heartbeat
|
|
98
|
-
new Uint8Array(new TextEncoder().encode('event: heartbeat\n\n')), // Heartbeat
|
|
99
|
-
new Uint8Array(new TextEncoder().encode('event: ping\n\n')), // Heartbeat
|
|
100
|
-
new Uint8Array(new TextEncoder().encode('data: {"key": "value"}\n\n')),
|
|
101
|
-
];
|
|
102
|
-
const response = createMockResponse(chunks);
|
|
103
|
-
const selector = createSseSelector({ skipHeartbeats: true });
|
|
104
|
-
const events = await lastValueFrom(
|
|
105
|
-
of(response)
|
|
106
|
-
// parse the SSE stream into individual events and collect them into an array
|
|
107
|
-
.pipe(
|
|
108
|
-
concatMap(selector),
|
|
109
|
-
scan((acc, event) => [...acc, event], [] as ServerSentEvent[]),
|
|
110
|
-
),
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
expect(events).toEqual([{ data: { key: 'value' } }]);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('retries on retry event with specified delay', async () => {
|
|
117
|
-
const chunks = [
|
|
118
|
-
new Uint8Array(new TextEncoder().encode('data: {"foo": "value1"}\n\n')),
|
|
119
|
-
new Uint8Array(new TextEncoder().encode('retry: 100\n\n')),
|
|
120
|
-
new Uint8Array(new TextEncoder().encode('data: {"bar": "value2"}\n\n')),
|
|
121
|
-
];
|
|
122
|
-
const response = createMockResponse(chunks);
|
|
123
|
-
const selector = createSseSelector();
|
|
124
|
-
|
|
125
|
-
const events = await lastValueFrom(
|
|
126
|
-
of(response)
|
|
127
|
-
// parse the SSE stream into individual events and collect them into an array
|
|
128
|
-
.pipe(
|
|
129
|
-
concatMap(selector),
|
|
130
|
-
scan((acc, event) => [...acc, event], [] as ServerSentEvent[]),
|
|
131
|
-
),
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
expect(events).toEqual([{ data: { foo: 'value1' } }, { data: { bar: 'value2' } }]);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('stops on abort signal', async () => {
|
|
138
|
-
const abortController = new AbortController();
|
|
139
|
-
const chunks = [
|
|
140
|
-
new Uint8Array(new TextEncoder().encode('data: {"key": "value"}\n\n')),
|
|
141
|
-
new Uint8Array(new TextEncoder().encode('retry: 100\n\n')),
|
|
142
|
-
new Uint8Array(new TextEncoder().encode('data: {"next": "event"}\n\n')),
|
|
143
|
-
];
|
|
144
|
-
const response = createMockResponse(chunks);
|
|
145
|
-
const selector = createSseSelector({ abortSignal: abortController.signal });
|
|
146
|
-
const eventsPromise = lastValueFrom(
|
|
147
|
-
of(response)
|
|
148
|
-
// parse the SSE stream into individual events and collect them into an array
|
|
149
|
-
.pipe(
|
|
150
|
-
concatMap(selector),
|
|
151
|
-
scan((acc, event) => [...acc, event], [] as ServerSentEvent[]),
|
|
152
|
-
),
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
156
|
-
abortController.abort();
|
|
157
|
-
|
|
158
|
-
const events = await eventsPromise;
|
|
159
|
-
|
|
160
|
-
expect(events).toEqual([{ data: { key: 'value' } }]);
|
|
161
|
-
});
|
|
162
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "dist/esm",
|
|
5
|
-
"rootDir": "src",
|
|
6
|
-
"declarationDir": "./dist/types"
|
|
7
|
-
},
|
|
8
|
-
"references": [
|
|
9
|
-
{
|
|
10
|
-
"path": "../module"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"path": "../msal"
|
|
14
|
-
}
|
|
15
|
-
],
|
|
16
|
-
"include": ["src/**/*"],
|
|
17
|
-
"exclude": ["node_modules", "lib"]
|
|
18
|
-
}
|
package/vitest.config.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { defineProject } from 'vitest/config';
|
|
2
|
-
|
|
3
|
-
import { name, version } from './package.json' with { type: 'json' };
|
|
4
|
-
|
|
5
|
-
export default defineProject({
|
|
6
|
-
test: {
|
|
7
|
-
// TODO(#5142): remove after __tests__ are deleted!
|
|
8
|
-
include: ['tests/**'],
|
|
9
|
-
name: `${name}@${version}`,
|
|
10
|
-
environment: 'happy-dom',
|
|
11
|
-
},
|
|
12
|
-
});
|