@mswjs/interceptors 0.16.4 → 0.17.0
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/README.md +177 -56
- package/lib/InteractiveIsomorphicRequest.d.ts +7 -0
- package/lib/InteractiveIsomorphicRequest.js +37 -0
- package/lib/InteractiveIsomorphicRequest.js.map +1 -0
- package/lib/IsomorphicRequest.d.ts +24 -0
- package/lib/IsomorphicRequest.js +107 -0
- package/lib/IsomorphicRequest.js.map +1 -0
- package/lib/RemoteHttpInterceptor.d.ts +1 -1
- package/lib/RemoteHttpInterceptor.js +12 -8
- package/lib/RemoteHttpInterceptor.js.map +1 -1
- package/lib/glossary.d.ts +3 -17
- package/lib/glossary.js +2 -0
- package/lib/glossary.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/interceptors/ClientRequest/NodeClientRequest.js +29 -57
- package/lib/interceptors/ClientRequest/NodeClientRequest.js.map +1 -1
- package/lib/interceptors/ClientRequest/index.d.ts +5 -2
- package/lib/interceptors/ClientRequest/index.js +11 -0
- package/lib/interceptors/ClientRequest/index.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.d.ts +1 -2
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js +19 -27
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/index.d.ts +2 -1
- package/lib/interceptors/XMLHttpRequest/index.js +11 -0
- package/lib/interceptors/XMLHttpRequest/index.js.map +1 -1
- package/lib/interceptors/fetch/index.d.ts +1 -1
- package/lib/interceptors/fetch/index.js +33 -25
- package/lib/interceptors/fetch/index.js.map +1 -1
- package/lib/utils/bufferUtils.d.ts +3 -0
- package/lib/utils/bufferUtils.js +20 -0
- package/lib/utils/bufferUtils.js.map +1 -0
- package/package.json +5 -2
- package/src/InteractiveIsomorphicRequest.ts +24 -0
- package/src/IsomorphicRequest.test.ts +108 -0
- package/src/IsomorphicRequest.ts +86 -0
- package/src/RemoteHttpInterceptor.ts +18 -18
- package/src/glossary.ts +4 -19
- package/src/index.ts +2 -0
- package/src/interceptors/ClientRequest/NodeClientRequest.test.ts +2 -8
- package/src/interceptors/ClientRequest/NodeClientRequest.ts +33 -69
- package/src/interceptors/ClientRequest/index.ts +26 -2
- package/src/interceptors/ClientRequest/utils/getIncomingMessageBody.ts +4 -4
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestOverride.ts +21 -23
- package/src/interceptors/XMLHttpRequest/index.ts +18 -4
- package/src/interceptors/fetch/index.ts +47 -20
- package/src/utils/bufferUtils.test.ts +20 -0
- package/src/utils/bufferUtils.ts +19 -0
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Low-level HTTP/HTTPS/XHR/fetch request interception library.
|
|
|
10
10
|
- `https.get`/`https.request`
|
|
11
11
|
- `XMLHttpRequest`
|
|
12
12
|
- `fetch`
|
|
13
|
-
- Any third-party libraries that use the modules above (i.e. `request`, `node-fetch`, `supertest`, etc.)
|
|
13
|
+
- Any third-party libraries that use the modules above (i.e. `axios`, `request`, `node-fetch`, `supertest`, etc.)
|
|
14
14
|
|
|
15
15
|
## Motivation
|
|
16
16
|
|
|
@@ -96,30 +96,195 @@ You can respond to an isomorphic request using an _isomorphic response_. In a si
|
|
|
96
96
|
npm install @mswjs/interceptors
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
##
|
|
99
|
+
## Interceptors
|
|
100
|
+
|
|
101
|
+
To use this library you need to choose one or multiple interceptors to apply. There are different interceptors exported by this library to spy on respective request-issuing modules:
|
|
102
|
+
|
|
103
|
+
- `ClientRequestInterceptor` to spy on `http.ClientRequest` (`http.get`/`http.request`);
|
|
104
|
+
- `XMLHttpRequestInterceptor` to spy on `XMLHttpRequest`;
|
|
105
|
+
- `FetchInterceptor` to spy on `fetch`.
|
|
106
|
+
|
|
107
|
+
Use an interceptor by constructing it and attaching request/response listeners:
|
|
100
108
|
|
|
101
|
-
|
|
109
|
+
```js
|
|
110
|
+
import { ClientRequestInterceptor } from '@mswjs/interceptors/lib/interceptors/ClientRequest'
|
|
111
|
+
|
|
112
|
+
const interceptor = new ClientRequestInterceptor()
|
|
113
|
+
|
|
114
|
+
// Listen to any "http.ClientRequest" being dispatched,
|
|
115
|
+
// and log its method and full URL.
|
|
116
|
+
interceptor.on('request', (request) => {
|
|
117
|
+
console.log(request.method, request.url.href)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
// Listen to any responses sent to "http.ClientRequest".
|
|
121
|
+
// Note that this listener is read-only and cannot affect responses.
|
|
122
|
+
interceptor.on('response', (response, request) => {
|
|
123
|
+
console.log(
|
|
124
|
+
'response to %s %s was:',
|
|
125
|
+
request.method,
|
|
126
|
+
request.url.href,
|
|
127
|
+
response
|
|
128
|
+
)
|
|
129
|
+
})
|
|
130
|
+
```
|
|
102
131
|
|
|
103
|
-
|
|
132
|
+
All HTTP request interceptors implement the same events:
|
|
104
133
|
|
|
105
|
-
- `
|
|
106
|
-
- `
|
|
107
|
-
- `FetchInterceptor`
|
|
134
|
+
- `request`, emitted whenever a request has been dispatched;
|
|
135
|
+
- `response`, emitted whenever any request receives a response.
|
|
108
136
|
|
|
109
|
-
|
|
137
|
+
### Using multiple interceptors
|
|
110
138
|
|
|
111
|
-
|
|
139
|
+
You can combine multiple interceptors to capture requests from different request-issuing modules at once.
|
|
112
140
|
|
|
113
141
|
```js
|
|
142
|
+
import { BatchInterceptor } from '@mswjs/interceptors'
|
|
114
143
|
import { ClientRequestInterceptor } from '@mswjs/interceptors/lib/interceptors/ClientRequest'
|
|
144
|
+
import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/lib/interceptors/XMLHttpRequest'
|
|
115
145
|
|
|
116
|
-
const interceptor =
|
|
146
|
+
const interceptor = BatchInterceptor({
|
|
147
|
+
name: 'my-interceptor',
|
|
148
|
+
interceptors: [ClientRequestInterceptor, XMLHttpRequestInterceptor],
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
// This "request" listener will be called on both
|
|
152
|
+
// "http.ClientRequest" and "XMLHttpRequest" being dispatched.
|
|
153
|
+
interceptor.on('request', listener)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
> Note that you can use [pre-defined presets](#presets) that cover all the request sources for a given environment type.
|
|
157
|
+
|
|
158
|
+
## Presets
|
|
159
|
+
|
|
160
|
+
When using [`BatchInterceptor`](#batchinterceptor), you can provide a pre-defined preset to its "interceptors" option to capture all request for that environment.
|
|
161
|
+
|
|
162
|
+
### Node.js preset
|
|
163
|
+
|
|
164
|
+
This preset combines `ClientRequestInterceptor`, `XMLHttpRequestInterceptor` and is meant to be used in Node.js.
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
import { BatchInterceptor } from '@mswjs/interceptors'
|
|
168
|
+
import nodeInterceptors from '@mswjs/interceptors/lib/presets/node'
|
|
169
|
+
|
|
170
|
+
const interceptor = BatchInterceptor({
|
|
171
|
+
name: 'my-interceptor',
|
|
172
|
+
interceptors: nodeInterceptors,
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
interceptor.on('request', listener)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Browser preset
|
|
179
|
+
|
|
180
|
+
This preset combines `XMLHttpRequestInterceptor` and `FetchInterceptor` and is meant to be used in a browser.
|
|
181
|
+
|
|
182
|
+
```js
|
|
183
|
+
import { BatchInterceptor } from '@mswjs/interceptors'
|
|
184
|
+
import browserInterceptors from '@mswjs/interceptors/lib/presets/browser'
|
|
185
|
+
|
|
186
|
+
const interceptor = BatchInterceptor({
|
|
187
|
+
name: 'my-interceptor',
|
|
188
|
+
interceptors: browserInterceptors,
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
interceptor.on('request', listener)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Introspecting requests
|
|
195
|
+
|
|
196
|
+
All HTTP request interceptors emit a "request" event. In the listener to this event, they expose an isomorphic `request` instance—a normalized representation of the captured request.
|
|
197
|
+
|
|
198
|
+
> There are many ways to describe a request in Node.js, that's why this library exposes you a custom request instance that abstracts those details away from you, making request listeners uniform.
|
|
199
|
+
|
|
200
|
+
```js
|
|
201
|
+
interceptor.on('reqest', (request) => {})
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The exposed `request` partially implements Fetch API [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) specification, containing the following properties and methods:
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
interface IsomorphicRequest {
|
|
208
|
+
id: string
|
|
209
|
+
url: URL
|
|
210
|
+
method: string
|
|
211
|
+
headers: Headers
|
|
212
|
+
credentials: 'omit' | 'same-origin' | 'include'
|
|
213
|
+
bodyUsed: boolean
|
|
214
|
+
clone(): IsomorphicRequest
|
|
215
|
+
arrayBuffer(): Promise<ArrayBuffer>
|
|
216
|
+
text(): Promise<string>
|
|
217
|
+
json(): Promise<Record<string, unknown>>
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
For example, this is how you would read a JSON request body:
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
interceptor.on('request', async (request) => {
|
|
225
|
+
const json = await request.json()
|
|
226
|
+
})
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Mocking responses
|
|
230
|
+
|
|
231
|
+
Although this library can be used purely for request introspection purposes, you can also affect request resolution by responding to any intercepted request within the "request" event.
|
|
232
|
+
|
|
233
|
+
Use the `request.respondWith()` method to respond to a request with a mocked response:
|
|
234
|
+
|
|
235
|
+
```js
|
|
117
236
|
interceptor.on('request', (request) => {
|
|
118
|
-
|
|
119
|
-
|
|
237
|
+
request.respondWith({
|
|
238
|
+
status: 200,
|
|
239
|
+
statusText: 'OK',
|
|
240
|
+
headers: {
|
|
241
|
+
'Content-Type': 'application/json',
|
|
242
|
+
},
|
|
243
|
+
body: JSON.stringify({
|
|
244
|
+
firstName: 'John',
|
|
245
|
+
lastName: 'Maverick',
|
|
246
|
+
}),
|
|
247
|
+
})
|
|
120
248
|
})
|
|
121
249
|
```
|
|
122
250
|
|
|
251
|
+
Note that a single request _can only be handled once_. You may want to introduce conditional logic, like routing, in your request listener but it's generally advised to use a higher-level library like [Mock Service Worker](https://github.com/mswjs/msw) that does request matching for you.
|
|
252
|
+
|
|
253
|
+
Requests must be responded to within the same tick as the request listener. This means you cannot respond to a request using `setTimeout`, as this will delegate the callback to the next tick. If you wish to introduce asynchronous side-effects in the listener, consider making it an `async` function, awaiting any side-effects you need.
|
|
254
|
+
|
|
255
|
+
```js
|
|
256
|
+
// Respond to all requests with a 500 response
|
|
257
|
+
// delayed by 500ms.
|
|
258
|
+
interceptor.on('request', async (request) => {
|
|
259
|
+
await sleep(500)
|
|
260
|
+
request.respondWith({ status: 500 })
|
|
261
|
+
})
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## API
|
|
265
|
+
|
|
266
|
+
### `Interceptor`
|
|
267
|
+
|
|
268
|
+
A generic class implemented by all interceptors. You do not interact with this class directly.
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
class Interceptor {
|
|
272
|
+
// Applies the interceptor, enabling the interception of requests
|
|
273
|
+
// in the current process.
|
|
274
|
+
apply(): void
|
|
275
|
+
|
|
276
|
+
// Listens to the public interceptor events.
|
|
277
|
+
// For HTTP requests, these are "request' and "response" events.
|
|
278
|
+
on(event, listener): void
|
|
279
|
+
|
|
280
|
+
// Cleans up any side-effects introduced by the interceptor
|
|
281
|
+
// and disables the interception of requests.
|
|
282
|
+
dispose(): void
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
**For public consumption, use [interceptors](#interceptors) instead**.
|
|
287
|
+
|
|
123
288
|
### `BatchInterceptor`
|
|
124
289
|
|
|
125
290
|
Applies multiple request interceptors at the same time.
|
|
@@ -187,50 +352,6 @@ resolver.on('request', (request) => {
|
|
|
187
352
|
})
|
|
188
353
|
```
|
|
189
354
|
|
|
190
|
-
### Methods
|
|
191
|
-
|
|
192
|
-
#### `apply`
|
|
193
|
-
|
|
194
|
-
Applies interceptor, enabling the interception of requests in the current process.
|
|
195
|
-
|
|
196
|
-
```js
|
|
197
|
-
interceptor.apply()
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
The same interceptor can be applied multiple times. If that happens, each subsequent interceptor instance will reusing a single running instance instead of applying itself repeatedly. Each interceptor instance should still be disposed individually.
|
|
201
|
-
|
|
202
|
-
#### `on`
|
|
203
|
-
|
|
204
|
-
Listens to the interceptor events.
|
|
205
|
-
|
|
206
|
-
Each interceptor decides what event map to implement. Currently, all exported interceptors implement an HTTP request event map that consists of the following events:
|
|
207
|
-
|
|
208
|
-
- `request`, signals when a new request happens;
|
|
209
|
-
- `response`, signals when a response was sent.
|
|
210
|
-
|
|
211
|
-
```js
|
|
212
|
-
interceptor.on('request', (request) => {
|
|
213
|
-
console.log('[%s] %s', request.method, request.url.toString())
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
interceptor.on('response', (request, response) => {
|
|
217
|
-
console.log(
|
|
218
|
-
'Received response to [%s] %s:',
|
|
219
|
-
request.method,
|
|
220
|
-
request.url.href,
|
|
221
|
-
response
|
|
222
|
-
)
|
|
223
|
-
})
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
#### `dispose`
|
|
227
|
-
|
|
228
|
-
Disposes of the applied interceptor. This cleans up all the side-effects introduced by the interceptor (i.e. restores augmented modules).
|
|
229
|
-
|
|
230
|
-
```js
|
|
231
|
-
interceptor.dispose()
|
|
232
|
-
```
|
|
233
|
-
|
|
234
355
|
## Special mention
|
|
235
356
|
|
|
236
357
|
The following libraries were used as an inspiration to write this low-level API:
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MockedResponse } from './glossary';
|
|
2
|
+
import { IsomorphicRequest } from './IsomorphicRequest';
|
|
3
|
+
import { LazyCallback } from './utils/createLazyCallback';
|
|
4
|
+
export declare class InteractiveIsomorphicRequest extends IsomorphicRequest {
|
|
5
|
+
respondWith: LazyCallback<(response: MockedResponse) => void>;
|
|
6
|
+
constructor(request: IsomorphicRequest);
|
|
7
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.InteractiveIsomorphicRequest = void 0;
|
|
19
|
+
var outvariant_1 = require("outvariant");
|
|
20
|
+
var IsomorphicRequest_1 = require("./IsomorphicRequest");
|
|
21
|
+
var createLazyCallback_1 = require("./utils/createLazyCallback");
|
|
22
|
+
var InteractiveIsomorphicRequest = /** @class */ (function (_super) {
|
|
23
|
+
__extends(InteractiveIsomorphicRequest, _super);
|
|
24
|
+
function InteractiveIsomorphicRequest(request) {
|
|
25
|
+
var _this = _super.call(this, request) || this;
|
|
26
|
+
_this.respondWith = createLazyCallback_1.createLazyCallback({
|
|
27
|
+
maxCalls: 1,
|
|
28
|
+
maxCallsCallback: function () {
|
|
29
|
+
outvariant_1.invariant(false, 'Failed to respond to "%s %s" request: the "request" event has already been responded to.', _this.method, _this.url.href);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
return _this;
|
|
33
|
+
}
|
|
34
|
+
return InteractiveIsomorphicRequest;
|
|
35
|
+
}(IsomorphicRequest_1.IsomorphicRequest));
|
|
36
|
+
exports.InteractiveIsomorphicRequest = InteractiveIsomorphicRequest;
|
|
37
|
+
//# sourceMappingURL=InteractiveIsomorphicRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InteractiveIsomorphicRequest.js","sourceRoot":"","sources":["../src/InteractiveIsomorphicRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,yCAAsC;AAEtC,yDAAuD;AACvD,iEAA6E;AAE7E;IAAkD,gDAAiB;IAGjE,sCAAY,OAA0B;QAAtC,YACE,kBAAM,OAAO,CAAC,SAaf;QAXC,KAAI,CAAC,WAAW,GAAG,uCAAkB,CAAC;YACpC,QAAQ,EAAE,CAAC;YACX,gBAAgB,EAAE;gBAChB,sBAAS,CACP,KAAK,EACL,0FAA0F,EAC1F,KAAI,CAAC,MAAM,EACX,KAAI,CAAC,GAAG,CAAC,IAAI,CACd,CAAA;YACH,CAAC;SACF,CAAC,CAAA;;IACJ,CAAC;IACH,mCAAC;AAAD,CAAC,AAlBD,CAAkD,qCAAiB,GAkBlE;AAlBY,oEAA4B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Headers } from 'headers-polyfill/lib';
|
|
2
|
+
export interface RequestInit {
|
|
3
|
+
method?: string;
|
|
4
|
+
headers?: Record<string, string | string[]> | Headers;
|
|
5
|
+
credentials?: RequestCredentials;
|
|
6
|
+
body?: ArrayBuffer;
|
|
7
|
+
}
|
|
8
|
+
export declare class IsomorphicRequest {
|
|
9
|
+
id: string;
|
|
10
|
+
readonly url: URL;
|
|
11
|
+
readonly method: string;
|
|
12
|
+
readonly headers: Headers;
|
|
13
|
+
readonly credentials: RequestCredentials;
|
|
14
|
+
private readonly body;
|
|
15
|
+
private _bodyUsed;
|
|
16
|
+
constructor(url: URL);
|
|
17
|
+
constructor(url: URL, init: RequestInit);
|
|
18
|
+
constructor(request: IsomorphicRequest);
|
|
19
|
+
get bodyUsed(): boolean;
|
|
20
|
+
text(): Promise<string>;
|
|
21
|
+
json<T = any>(): Promise<T>;
|
|
22
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
23
|
+
clone(): IsomorphicRequest;
|
|
24
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.IsomorphicRequest = void 0;
|
|
40
|
+
var lib_1 = require("headers-polyfill/lib");
|
|
41
|
+
var outvariant_1 = require("outvariant");
|
|
42
|
+
var bufferUtils_1 = require("./utils/bufferUtils");
|
|
43
|
+
var uuid_1 = require("./utils/uuid");
|
|
44
|
+
var IsomorphicRequest = /** @class */ (function () {
|
|
45
|
+
function IsomorphicRequest(input, init) {
|
|
46
|
+
if (init === void 0) { init = {}; }
|
|
47
|
+
var defaultBody = new ArrayBuffer(0);
|
|
48
|
+
this._bodyUsed = false;
|
|
49
|
+
if (input instanceof IsomorphicRequest) {
|
|
50
|
+
this.id = input.id;
|
|
51
|
+
this.url = input.url;
|
|
52
|
+
this.method = input.method;
|
|
53
|
+
this.headers = input.headers;
|
|
54
|
+
this.credentials = input.credentials;
|
|
55
|
+
this.body = input.body || defaultBody;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.id = uuid_1.uuidv4();
|
|
59
|
+
this.url = input;
|
|
60
|
+
this.method = init.method || 'GET';
|
|
61
|
+
this.headers = new lib_1.Headers(init.headers);
|
|
62
|
+
this.credentials = init.credentials || 'same-origin';
|
|
63
|
+
this.body = init.body || defaultBody;
|
|
64
|
+
}
|
|
65
|
+
Object.defineProperty(IsomorphicRequest.prototype, "bodyUsed", {
|
|
66
|
+
get: function () {
|
|
67
|
+
return this._bodyUsed;
|
|
68
|
+
},
|
|
69
|
+
enumerable: false,
|
|
70
|
+
configurable: true
|
|
71
|
+
});
|
|
72
|
+
IsomorphicRequest.prototype.text = function () {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
outvariant_1.invariant(!this.bodyUsed, 'Failed to execute "text" on "IsomorphicRequest": body buffer already read');
|
|
76
|
+
this._bodyUsed = true;
|
|
77
|
+
return [2 /*return*/, bufferUtils_1.decodeBuffer(this.body)];
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
IsomorphicRequest.prototype.json = function () {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
+
var text;
|
|
84
|
+
return __generator(this, function (_a) {
|
|
85
|
+
outvariant_1.invariant(!this.bodyUsed, 'Failed to execute "json" on "IsomorphicRequest": body buffer already read');
|
|
86
|
+
this._bodyUsed = true;
|
|
87
|
+
text = bufferUtils_1.decodeBuffer(this.body);
|
|
88
|
+
return [2 /*return*/, JSON.parse(text)];
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
IsomorphicRequest.prototype.arrayBuffer = function () {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
94
|
+
return __generator(this, function (_a) {
|
|
95
|
+
outvariant_1.invariant(!this.bodyUsed, 'Failed to execute "arrayBuffer" on "IsomorphicRequest": body buffer already read');
|
|
96
|
+
this._bodyUsed = true;
|
|
97
|
+
return [2 /*return*/, this.body];
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
IsomorphicRequest.prototype.clone = function () {
|
|
102
|
+
return new IsomorphicRequest(this);
|
|
103
|
+
};
|
|
104
|
+
return IsomorphicRequest;
|
|
105
|
+
}());
|
|
106
|
+
exports.IsomorphicRequest = IsomorphicRequest;
|
|
107
|
+
//# sourceMappingURL=IsomorphicRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IsomorphicRequest.js","sourceRoot":"","sources":["../src/IsomorphicRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8C;AAC9C,yCAAsC;AACtC,mDAAkD;AAClD,qCAAqC;AASrC;IAaE,2BAAY,KAA8B,EAAE,IAAsB;QAAtB,qBAAA,EAAA,SAAsB;QAChE,IAAM,WAAW,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAA;QACtC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAA;QAEtB,IAAI,KAAK,YAAY,iBAAiB,EAAE;YACtC,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAA;YAClB,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAA;YACpB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;YAC1B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAA;YAC5B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW,CAAA;YACpC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,WAAW,CAAA;YACrC,OAAM;SACP;QAED,IAAI,CAAC,EAAE,GAAG,aAAM,EAAE,CAAA;QAClB,IAAI,CAAC,GAAG,GAAG,KA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ildProcess } from 'child_process';
|
|
3
|
-
import
|
|
3
|
+
import { HttpRequestEventMap } from './glossary';
|
|
4
4
|
import { Interceptor } from './Interceptor';
|
|
5
5
|
import { BatchInterceptor } from './BatchInterceptor';
|
|
6
6
|
import { ClientRequestInterceptor } from './interceptors/ClientRequest';
|
|
@@ -84,8 +84,10 @@ var Interceptor_1 = require("./Interceptor");
|
|
|
84
84
|
var BatchInterceptor_1 = require("./BatchInterceptor");
|
|
85
85
|
var ClientRequest_1 = require("./interceptors/ClientRequest");
|
|
86
86
|
var XMLHttpRequest_1 = require("./interceptors/XMLHttpRequest");
|
|
87
|
-
var createLazyCallback_1 = require("./utils/createLazyCallback");
|
|
88
87
|
var toIsoResponse_1 = require("./utils/toIsoResponse");
|
|
88
|
+
var IsomorphicRequest_1 = require("./IsomorphicRequest");
|
|
89
|
+
var bufferFrom_1 = require("./interceptors/XMLHttpRequest/utils/bufferFrom");
|
|
90
|
+
var InteractiveIsomorphicRequest_1 = require("./InteractiveIsomorphicRequest");
|
|
89
91
|
var RemoteHttpInterceptor = /** @class */ (function (_super) {
|
|
90
92
|
__extends(RemoteHttpInterceptor, _super);
|
|
91
93
|
function RemoteHttpInterceptor() {
|
|
@@ -124,7 +126,7 @@ var RemoteHttpInterceptor = /** @class */ (function (_super) {
|
|
|
124
126
|
}
|
|
125
127
|
};
|
|
126
128
|
});
|
|
127
|
-
// Listen for the mocked
|
|
129
|
+
// Listen for the mocked response message from the parent.
|
|
128
130
|
this.log('add "message" listener to the parent process', handleParentMessage);
|
|
129
131
|
process.addListener('message', handleParentMessage);
|
|
130
132
|
return [2 /*return*/, responsePromise];
|
|
@@ -159,7 +161,7 @@ var RemoteHttpResolver = /** @class */ (function (_super) {
|
|
|
159
161
|
var _this = this;
|
|
160
162
|
var log = this.log.extend('setup');
|
|
161
163
|
var handleChildMessage = function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
162
|
-
var _a, serializedRequest, isomorphicRequest, interactiveIsomorphicRequest, _b, mockedResponse, serializedResponse;
|
|
164
|
+
var _a, serializedRequest, requestJson, body, isomorphicRequest, interactiveIsomorphicRequest, _b, mockedResponse, serializedResponse;
|
|
163
165
|
var _this = this;
|
|
164
166
|
return __generator(this, function (_c) {
|
|
165
167
|
switch (_c.label) {
|
|
@@ -173,9 +175,11 @@ var RemoteHttpResolver = /** @class */ (function (_super) {
|
|
|
173
175
|
if (!serializedRequest) {
|
|
174
176
|
return [2 /*return*/];
|
|
175
177
|
}
|
|
176
|
-
|
|
177
|
-
log('parsed intercepted request',
|
|
178
|
-
|
|
178
|
+
requestJson = JSON.parse(serializedRequest, requestReviver);
|
|
179
|
+
log('parsed intercepted request', requestJson);
|
|
180
|
+
body = bufferFrom_1.bufferFrom(requestJson.body);
|
|
181
|
+
isomorphicRequest = new IsomorphicRequest_1.IsomorphicRequest(requestJson.url, __assign(__assign({}, requestJson), { body: body.buffer }));
|
|
182
|
+
interactiveIsomorphicRequest = new InteractiveIsomorphicRequest_1.InteractiveIsomorphicRequest(isomorphicRequest);
|
|
179
183
|
this.emitter.emit('request', interactiveIsomorphicRequest);
|
|
180
184
|
return [4 /*yield*/, this.emitter.untilIdle('request', function (_a) {
|
|
181
185
|
var _b = __read(_a.args, 1), request = _b[0];
|
|
@@ -188,12 +192,12 @@ var RemoteHttpResolver = /** @class */ (function (_super) {
|
|
|
188
192
|
_b = __read.apply(void 0, [_c.sent(), 1]), mockedResponse = _b[0];
|
|
189
193
|
log('event.respondWith called with:', mockedResponse);
|
|
190
194
|
serializedResponse = JSON.stringify(mockedResponse);
|
|
191
|
-
this.process.send("response:" +
|
|
195
|
+
this.process.send("response:" + requestJson.id + ":" + serializedResponse, function (error) {
|
|
192
196
|
if (error) {
|
|
193
197
|
return;
|
|
194
198
|
}
|
|
195
199
|
if (mockedResponse) {
|
|
196
|
-
// Emit an
|
|
200
|
+
// Emit an optimistic "response" event at this point,
|
|
197
201
|
// not to rely on the back-and-forth signaling for the sake of the event.
|
|
198
202
|
_this.emitter.emit('response', isomorphicRequest, toIsoResponse_1.toIsoResponse(mockedResponse));
|
|
199
203
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteHttpInterceptor.js","sourceRoot":"","sources":["../src/RemoteHttpInterceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qDAA0C;
|
|
1
|
+
{"version":3,"file":"RemoteHttpInterceptor.js","sourceRoot":"","sources":["../src/RemoteHttpInterceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qDAA0C;AAE1C,6CAA2C;AAC3C,uDAAqD;AACrD,8DAAuE;AACvE,gEAAyE;AACzE,uDAAqD;AACrD,yDAAuD;AACvD,6EAA2E;AAC3E,+EAA6E;AAE7E;IAA2C,yCAE1C;IACC;eACE,kBAAM;YACJ,IAAI,EAAE,oBAAoB;YAC1B,YAAY,EAAE;gBACZ,IAAI,wCAAwB,EAAE;gBAC9B,IAAI,0CAAyB,EAAE;aAChC;SACF,CAAC;IACJ,CAAC;IAES,qCAAK,GAAf;QAAA,iBA+CC;QA9CC,iBAAM,KAAK,WAAE,CAAA;QAEb,IAAI,mBAA2C,CAAA;QAE/C,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,UAAO,OAAO;;;;gBAGzB,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;gBAEjD,IAAI,CAAC,GAAG,CAAC,uCAAuC,EAAE,iBAAiB,CAAC,CAAA;gBACpE,MAAA,OAAO,CAAC,IAAI,+CAAZ,OAAO,EAAQ,aAAW,iBAAmB,CAAC,CAAA;gBAExC,eAAe,GAAG,IAAI,OAAO,CAAO,UAAC,OAAO;oBAChD,mBAAmB,GAAG,UAAC,OAAO;wBAC5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AAc,CAAC,CAAA;IACjD,CAAC;IAnFM,yBAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAA;IAoF3C,yBAAC;CAAA,AArFD,CAAwC,yBAAW,GAqFlD;AArFY,gDAAkB"}
|
package/lib/glossary.d.ts
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
import type { HeadersObject, Headers } from 'headers-polyfill';
|
|
2
|
-
import type {
|
|
2
|
+
import type { InteractiveIsomorphicRequest } from './InteractiveIsomorphicRequest';
|
|
3
|
+
import type { IsomorphicRequest } from './IsomorphicRequest';
|
|
4
|
+
export declare const IS_PATCHED_MODULE: unique symbol;
|
|
3
5
|
export declare type RequestCredentials = 'omit' | 'include' | 'same-origin';
|
|
4
|
-
export interface IsomorphicRequest {
|
|
5
|
-
id: string;
|
|
6
|
-
url: URL;
|
|
7
|
-
method: string;
|
|
8
|
-
headers: Headers;
|
|
9
|
-
/**
|
|
10
|
-
* The value of the request client's "credentials" option
|
|
11
|
-
* or a compatible alternative (i.e. `withCredentials` for `XMLHttpRequest`).
|
|
12
|
-
* Always equals to "omit" in Node.js.
|
|
13
|
-
*/
|
|
14
|
-
credentials: RequestCredentials;
|
|
15
|
-
body?: string;
|
|
16
|
-
}
|
|
17
|
-
export interface InteractiveIsomorphicRequest extends IsomorphicRequest {
|
|
18
|
-
respondWith: LazyCallback<(mockedResponse: MockedResponse) => void>;
|
|
19
|
-
}
|
|
20
6
|
export interface IsomorphicResponse {
|
|
21
7
|
status: number;
|
|
22
8
|
statusText: string;
|
package/lib/glossary.js
CHANGED
package/lib/glossary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glossary.js","sourceRoot":"","sources":["../src/glossary.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"glossary.js","sourceRoot":"","sources":["../src/glossary.ts"],"names":[],"mappings":";;;AAIa,QAAA,iBAAiB,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAA"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -14,6 +14,8 @@ exports.getCleanUrl = void 0;
|
|
|
14
14
|
__exportStar(require("./glossary"), exports);
|
|
15
15
|
__exportStar(require("./Interceptor"), exports);
|
|
16
16
|
__exportStar(require("./BatchInterceptor"), exports);
|
|
17
|
+
__exportStar(require("./IsomorphicRequest"), exports);
|
|
18
|
+
__exportStar(require("./InteractiveIsomorphicRequest"), exports);
|
|
17
19
|
/* Utils */
|
|
18
20
|
var getCleanUrl_1 = require("./utils/getCleanUrl");
|
|
19
21
|
Object.defineProperty(exports, "getCleanUrl", { enumerable: true, get: function () { return getCleanUrl_1.getCleanUrl; } });
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,gDAA6B;AAC7B,qDAAkC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,gDAA6B;AAC7B,qDAAkC;AAClC,sDAAmC;AACnC,iEAA8C;AAE9C,WAAW;AACX,mDAAiD;AAAxC,0GAAA,WAAW,OAAA"}
|