msw 0.28.1 → 0.30.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/cli/init.js +14 -6
- package/lib/esm/RequestHandler-deps.js +162 -130
- package/lib/esm/fetch-deps.js +306 -95
- package/lib/esm/graphql-deps.js +26 -19
- package/lib/esm/index-deps.js +2 -2
- package/lib/esm/index.js +5291 -710
- package/lib/esm/index2.js +2 -2
- package/lib/esm/mockServiceWorker.js +4 -3
- package/lib/esm/rest-deps.js +4 -4
- package/lib/esm/xml-deps.js +1 -217
- package/lib/iife/index.js +4 -4
- package/lib/iife/mockServiceWorker.js +4 -3
- package/lib/types/context/body.d.ts +1 -1
- package/lib/types/context/json.d.ts +1 -1
- package/lib/types/context/text.d.ts +1 -1
- package/lib/types/context/xml.d.ts +1 -1
- package/lib/types/handlers/GraphQLHandler.d.ts +4 -2
- package/lib/types/handlers/RequestHandler.d.ts +12 -8
- package/lib/types/handlers/RestHandler.d.ts +2 -2
- package/lib/types/node/glossary.d.ts +2 -1
- package/lib/types/response.d.ts +1 -1
- package/lib/types/setupWorker/glossary.d.ts +21 -16
- package/lib/types/setupWorker/start/createFallbackStart.d.ts +2 -0
- package/lib/types/setupWorker/start/createStartHandler.d.ts +2 -0
- package/lib/types/setupWorker/start/utils/enableMocking.d.ts +5 -0
- package/lib/types/setupWorker/start/utils/prepareStartHandler.d.ts +9 -0
- package/lib/types/setupWorker/start/utils/printStartMessage.d.ts +7 -0
- package/lib/types/setupWorker/start/utils/validateWorkerScope.d.ts +2 -0
- package/lib/types/setupWorker/stop/createFallbackStop.d.ts +2 -0
- package/lib/types/setupWorker/stop/createStop.d.ts +2 -2
- package/lib/types/setupWorker/stop/utils/printStopMessage.d.ts +3 -0
- package/lib/types/sharedOptions.d.ts +3 -2
- package/lib/types/utils/getResponse.d.ts +2 -3
- package/lib/types/utils/handleRequest.d.ts +27 -0
- package/lib/types/utils/internal/isIterable.d.ts +4 -0
- package/lib/types/utils/internal/tryCatch.d.ts +1 -0
- package/lib/types/utils/logging/prepareResponse.d.ts +3 -3
- package/lib/types/utils/request/parseIsomorphicRequest.d.ts +6 -0
- package/lib/types/utils/request/parseWorkerRequest.d.ts +4 -0
- package/lib/types/utils/worker/createFallbackRequestListener.d.ts +3 -0
- package/lib/umd/index.js +27002 -5268
- package/lib/umd/mockServiceWorker.js +4 -3
- package/native/lib/index.js +4374 -4281
- package/node/lib/index.js +1385 -1292
- package/package.json +33 -33
- package/lib/types/setupWorker/start/createStart.d.ts +0 -2
- package/lib/types/setupWorker/start/utils/activateMocking.d.ts +0 -2
package/lib/esm/index2.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { d as delay, f as fetch, e as json,
|
|
2
|
-
export { b as body,
|
|
1
|
+
export { b as cookie, d as delay, f as fetch, e as json, a as set, s as status } from './fetch-deps.js';
|
|
2
|
+
export { b as body, t as text, x as xml } from './xml-deps.js';
|
|
3
3
|
export { d as data, e as errors } from './errors-deps.js';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* Mock Service Worker.
|
|
5
|
+
* Mock Service Worker (0.30.1).
|
|
3
6
|
* @see https://github.com/mswjs/msw
|
|
4
7
|
* - Please do NOT modify this file.
|
|
5
8
|
* - Please do NOT serve this file on production.
|
|
6
9
|
*/
|
|
7
|
-
/* eslint-disable */
|
|
8
|
-
/* tslint:disable */
|
|
9
10
|
|
|
10
11
|
const INTEGRITY_CHECKSUM = '82ef9b96d8393b6da34527d1d6e19187'
|
|
11
12
|
const bypassHeaderName = 'x-msw-bypass'
|
package/lib/esm/rest-deps.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { R as RequestHandler,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { R as RequestHandler, f as getUrlByMask, m as matchRequestUrl, g as getPublicUrlFromRequest, h as prepareRequest, i as prepareResponse, j as getTimestamp, k as getStatusCodeColor } from './RequestHandler-deps.js';
|
|
2
|
+
import { a as set, s as status, b as cookie, e as json, d as delay, f as fetch } from './fetch-deps.js';
|
|
3
|
+
import { b as body, t as text, x as xml } from './xml-deps.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Performs a case-insensitive comparison of two given strings.
|
|
@@ -72,7 +72,7 @@ ${queryParams
|
|
|
72
72
|
return matchRequestUrl(request.url, this.info.mask);
|
|
73
73
|
}
|
|
74
74
|
getPublicRequest(request, parsedResult) {
|
|
75
|
-
return Object.assign(Object.assign({}, request), { params: parsedResult.params });
|
|
75
|
+
return Object.assign(Object.assign({}, request), { params: parsedResult.params || {} });
|
|
76
76
|
}
|
|
77
77
|
predicate(request, parsedResult) {
|
|
78
78
|
return (isStringEqual(this.info.method, request.method) && parsedResult.matches);
|
package/lib/esm/xml-deps.js
CHANGED
|
@@ -1,219 +1,3 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* cookie
|
|
3
|
-
* Copyright(c) 2012-2014 Roman Shtylman
|
|
4
|
-
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
5
|
-
* MIT Licensed
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Module exports.
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
var parse_1 = parse;
|
|
14
|
-
var serialize_1 = serialize;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Module variables.
|
|
18
|
-
* @private
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
var decode = decodeURIComponent;
|
|
22
|
-
var encode = encodeURIComponent;
|
|
23
|
-
var pairSplitRegExp = /; */;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* RegExp to match field-content in RFC 7230 sec 3.2
|
|
27
|
-
*
|
|
28
|
-
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
|
|
29
|
-
* field-vchar = VCHAR / obs-text
|
|
30
|
-
* obs-text = %x80-FF
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Parse a cookie header.
|
|
37
|
-
*
|
|
38
|
-
* Parse the given cookie header string into an object
|
|
39
|
-
* The object has the various cookies as keys(names) => values
|
|
40
|
-
*
|
|
41
|
-
* @param {string} str
|
|
42
|
-
* @param {object} [options]
|
|
43
|
-
* @return {object}
|
|
44
|
-
* @public
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
function parse(str, options) {
|
|
48
|
-
if (typeof str !== 'string') {
|
|
49
|
-
throw new TypeError('argument str must be a string');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
var obj = {};
|
|
53
|
-
var opt = options || {};
|
|
54
|
-
var pairs = str.split(pairSplitRegExp);
|
|
55
|
-
var dec = opt.decode || decode;
|
|
56
|
-
|
|
57
|
-
for (var i = 0; i < pairs.length; i++) {
|
|
58
|
-
var pair = pairs[i];
|
|
59
|
-
var eq_idx = pair.indexOf('=');
|
|
60
|
-
|
|
61
|
-
// skip things that don't look like key=value
|
|
62
|
-
if (eq_idx < 0) {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
var key = pair.substr(0, eq_idx).trim();
|
|
67
|
-
var val = pair.substr(++eq_idx, pair.length).trim();
|
|
68
|
-
|
|
69
|
-
// quoted values
|
|
70
|
-
if ('"' == val[0]) {
|
|
71
|
-
val = val.slice(1, -1);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// only assign once
|
|
75
|
-
if (undefined == obj[key]) {
|
|
76
|
-
obj[key] = tryDecode(val, dec);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return obj;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Serialize data into a cookie header.
|
|
85
|
-
*
|
|
86
|
-
* Serialize the a name value pair into a cookie string suitable for
|
|
87
|
-
* http headers. An optional options object specified cookie parameters.
|
|
88
|
-
*
|
|
89
|
-
* serialize('foo', 'bar', { httpOnly: true })
|
|
90
|
-
* => "foo=bar; httpOnly"
|
|
91
|
-
*
|
|
92
|
-
* @param {string} name
|
|
93
|
-
* @param {string} val
|
|
94
|
-
* @param {object} [options]
|
|
95
|
-
* @return {string}
|
|
96
|
-
* @public
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
function serialize(name, val, options) {
|
|
100
|
-
var opt = options || {};
|
|
101
|
-
var enc = opt.encode || encode;
|
|
102
|
-
|
|
103
|
-
if (typeof enc !== 'function') {
|
|
104
|
-
throw new TypeError('option encode is invalid');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (!fieldContentRegExp.test(name)) {
|
|
108
|
-
throw new TypeError('argument name is invalid');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
var value = enc(val);
|
|
112
|
-
|
|
113
|
-
if (value && !fieldContentRegExp.test(value)) {
|
|
114
|
-
throw new TypeError('argument val is invalid');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
var str = name + '=' + value;
|
|
118
|
-
|
|
119
|
-
if (null != opt.maxAge) {
|
|
120
|
-
var maxAge = opt.maxAge - 0;
|
|
121
|
-
|
|
122
|
-
if (isNaN(maxAge) || !isFinite(maxAge)) {
|
|
123
|
-
throw new TypeError('option maxAge is invalid')
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
str += '; Max-Age=' + Math.floor(maxAge);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (opt.domain) {
|
|
130
|
-
if (!fieldContentRegExp.test(opt.domain)) {
|
|
131
|
-
throw new TypeError('option domain is invalid');
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
str += '; Domain=' + opt.domain;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (opt.path) {
|
|
138
|
-
if (!fieldContentRegExp.test(opt.path)) {
|
|
139
|
-
throw new TypeError('option path is invalid');
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
str += '; Path=' + opt.path;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (opt.expires) {
|
|
146
|
-
if (typeof opt.expires.toUTCString !== 'function') {
|
|
147
|
-
throw new TypeError('option expires is invalid');
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
str += '; Expires=' + opt.expires.toUTCString();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (opt.httpOnly) {
|
|
154
|
-
str += '; HttpOnly';
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (opt.secure) {
|
|
158
|
-
str += '; Secure';
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (opt.sameSite) {
|
|
162
|
-
var sameSite = typeof opt.sameSite === 'string'
|
|
163
|
-
? opt.sameSite.toLowerCase() : opt.sameSite;
|
|
164
|
-
|
|
165
|
-
switch (sameSite) {
|
|
166
|
-
case true:
|
|
167
|
-
str += '; SameSite=Strict';
|
|
168
|
-
break;
|
|
169
|
-
case 'lax':
|
|
170
|
-
str += '; SameSite=Lax';
|
|
171
|
-
break;
|
|
172
|
-
case 'strict':
|
|
173
|
-
str += '; SameSite=Strict';
|
|
174
|
-
break;
|
|
175
|
-
case 'none':
|
|
176
|
-
str += '; SameSite=None';
|
|
177
|
-
break;
|
|
178
|
-
default:
|
|
179
|
-
throw new TypeError('option sameSite is invalid');
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return str;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Try decoding a string using a decoding function.
|
|
188
|
-
*
|
|
189
|
-
* @param {string} str
|
|
190
|
-
* @param {function} decode
|
|
191
|
-
* @private
|
|
192
|
-
*/
|
|
193
|
-
|
|
194
|
-
function tryDecode(str, decode) {
|
|
195
|
-
try {
|
|
196
|
-
return decode(str);
|
|
197
|
-
} catch (e) {
|
|
198
|
-
return str;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Sets a given cookie on the mocked response.
|
|
204
|
-
* @example res(ctx.cookie('name', 'value'))
|
|
205
|
-
*/
|
|
206
|
-
const cookie = (name, value, options) => {
|
|
207
|
-
return (res) => {
|
|
208
|
-
const serializedCookie = serialize_1(name, value, options);
|
|
209
|
-
res.headers.set('Set-Cookie', serializedCookie);
|
|
210
|
-
if (typeof document !== 'undefined') {
|
|
211
|
-
document.cookie = serializedCookie;
|
|
212
|
-
}
|
|
213
|
-
return res;
|
|
214
|
-
};
|
|
215
|
-
};
|
|
216
|
-
|
|
217
1
|
/**
|
|
218
2
|
* Sets a raw response body. Does not append any `Content-Type` headers.
|
|
219
3
|
* @example
|
|
@@ -257,4 +41,4 @@ const xml = (body) => {
|
|
|
257
41
|
};
|
|
258
42
|
};
|
|
259
43
|
|
|
260
|
-
export { body as b,
|
|
44
|
+
export { body as b, text as t, xml as x };
|