msw 0.33.0 → 0.34.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 +18 -16
- package/lib/esm/RequestHandler-deps.js +78 -21
- package/lib/esm/graphql-deps.js +39 -17
- package/lib/esm/index.js +3 -3
- package/lib/esm/mockServiceWorker.js +24 -9
- package/lib/esm/rest-deps.js +3 -2
- package/lib/iife/index.js +2 -2
- package/lib/iife/mockServiceWorker.js +24 -9
- package/lib/types/graphql.d.ts +13 -4
- package/lib/types/handlers/GraphQLHandler.d.ts +4 -3
- package/lib/types/handlers/RequestHandler.d.ts +2 -1
- package/lib/types/handlers/RestHandler.d.ts +1 -1
- package/lib/types/setupWorker/glossary.d.ts +5 -3
- package/lib/types/utils/internal/parseGraphQLRequest.d.ts +2 -1
- package/lib/types/utils/logging/getStatusCodeColor.d.ts +6 -1
- package/lib/types/utils/logging/getTimestamp.d.ts +3 -0
- package/lib/types/utils/logging/prepareResponse.d.ts +1 -3
- package/lib/umd/index.js +130 -38
- package/lib/umd/mockServiceWorker.js +24 -9
- package/native/lib/index.js +117 -37
- package/node/lib/index.js +117 -37
- package/package.json +7 -3
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
/* tslint:disable */
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Mock Service Worker (0.
|
|
5
|
+
* Mock Service Worker (0.34.0).
|
|
6
6
|
* @see https://github.com/mswjs/msw
|
|
7
7
|
* - Please do NOT modify this file.
|
|
8
8
|
* - Please do NOT serve this file on production.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const INTEGRITY_CHECKSUM = '
|
|
11
|
+
const INTEGRITY_CHECKSUM = 'f0a916b13c8acc2b526a03a6d26df85f'
|
|
12
12
|
const bypassHeaderName = 'x-msw-bypass'
|
|
13
13
|
const activeClientIds = new Set()
|
|
14
14
|
|
|
@@ -221,13 +221,11 @@ async function getResponse(event, client, requestId) {
|
|
|
221
221
|
|
|
222
222
|
console.error(
|
|
223
223
|
`\
|
|
224
|
-
[MSW]
|
|
224
|
+
[MSW] Uncaught exception in the request handler for "%s %s":
|
|
225
225
|
|
|
226
|
-
${parsedBody.
|
|
227
|
-
(see more detailed error stack trace in the mocked response body)
|
|
226
|
+
${parsedBody.location}
|
|
228
227
|
|
|
229
|
-
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error.
|
|
230
|
-
If you wish to mock an error response, please refer to this guide: https://mswjs.io/docs/recipes/mocking-error-responses\
|
|
228
|
+
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/recipes/mocking-error-responses\
|
|
231
229
|
`,
|
|
232
230
|
request.method,
|
|
233
231
|
request.url,
|
|
@@ -242,6 +240,12 @@ If you wish to mock an error response, please refer to this guide: https://mswjs
|
|
|
242
240
|
|
|
243
241
|
self.addEventListener('fetch', function (event) {
|
|
244
242
|
const { request } = event
|
|
243
|
+
const accept = request.headers.get('accept') || ''
|
|
244
|
+
|
|
245
|
+
// Bypass server-sent events.
|
|
246
|
+
if (accept.includes('text/event-stream')) {
|
|
247
|
+
return
|
|
248
|
+
}
|
|
245
249
|
|
|
246
250
|
// Bypass navigation requests.
|
|
247
251
|
if (request.mode === 'navigate') {
|
|
@@ -265,11 +269,22 @@ self.addEventListener('fetch', function (event) {
|
|
|
265
269
|
|
|
266
270
|
return event.respondWith(
|
|
267
271
|
handleRequest(event, requestId).catch((error) => {
|
|
272
|
+
if (error.name === 'NetworkError') {
|
|
273
|
+
console.warn(
|
|
274
|
+
'[MSW] Successfully emulated a network error for the "%s %s" request.',
|
|
275
|
+
request.method,
|
|
276
|
+
request.url,
|
|
277
|
+
)
|
|
278
|
+
return
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// At this point, any exception indicates an issue with the original request/response.
|
|
268
282
|
console.error(
|
|
269
|
-
|
|
283
|
+
`\
|
|
284
|
+
[MSW] Caught an exception from the "%s %s" request (%s). This is probably not a problem with Mock Service Worker. There is likely an additional logging output above.`,
|
|
270
285
|
request.method,
|
|
271
286
|
request.url,
|
|
272
|
-
error
|
|
287
|
+
`${error.name}: ${error.message}`,
|
|
273
288
|
)
|
|
274
289
|
}),
|
|
275
290
|
)
|
package/lib/types/graphql.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import { DocumentNode } from 'graphql';
|
|
1
2
|
import { Path } from 'node-match-path';
|
|
2
3
|
import { ResponseResolver } from './handlers/RequestHandler';
|
|
3
4
|
import { GraphQLHandler, GraphQLContext, GraphQLRequest, GraphQLVariables, GraphQLHandlerNameSelector } from './handlers/GraphQLHandler';
|
|
5
|
+
export interface TypedDocumentNode<Result = {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}, Variables = {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}> extends DocumentNode {
|
|
10
|
+
__resultType?: Result;
|
|
11
|
+
__variablesType?: Variables;
|
|
12
|
+
}
|
|
4
13
|
declare const standardGraphQLHandlers: {
|
|
5
14
|
/**
|
|
6
15
|
* Captures any GraphQL operation, regardless of its name, under the current scope.
|
|
@@ -19,7 +28,7 @@ declare const standardGraphQLHandlers: {
|
|
|
19
28
|
* })
|
|
20
29
|
* @see {@link https://mswjs.io/docs/api/graphql/query `graphql.query()`}
|
|
21
30
|
*/
|
|
22
|
-
query: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
|
|
31
|
+
query: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query_1, Variables_1>, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
|
|
23
32
|
/**
|
|
24
33
|
* Captures a GraphQL mutation by a given name.
|
|
25
34
|
* @example
|
|
@@ -28,7 +37,7 @@ declare const standardGraphQLHandlers: {
|
|
|
28
37
|
* })
|
|
29
38
|
* @see {@link https://mswjs.io/docs/api/graphql/mutation `graphql.mutation()`}
|
|
30
39
|
*/
|
|
31
|
-
mutation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
|
|
40
|
+
mutation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query_1, Variables_1>, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
|
|
32
41
|
};
|
|
33
42
|
declare function createGraphQLLink(url: Path): typeof standardGraphQLHandlers;
|
|
34
43
|
export declare const graphql: {
|
|
@@ -50,7 +59,7 @@ export declare const graphql: {
|
|
|
50
59
|
* })
|
|
51
60
|
* @see {@link https://mswjs.io/docs/api/graphql/query `graphql.query()`}
|
|
52
61
|
*/
|
|
53
|
-
query: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
|
|
62
|
+
query: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query_1, Variables_1>, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
|
|
54
63
|
/**
|
|
55
64
|
* Captures a GraphQL mutation by a given name.
|
|
56
65
|
* @example
|
|
@@ -59,6 +68,6 @@ export declare const graphql: {
|
|
|
59
68
|
* })
|
|
60
69
|
* @see {@link https://mswjs.io/docs/api/graphql/mutation `graphql.mutation()`}
|
|
61
70
|
*/
|
|
62
|
-
mutation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
|
|
71
|
+
mutation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query_1, Variables_1>, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
|
|
63
72
|
};
|
|
64
73
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OperationTypeNode } from 'graphql';
|
|
1
|
+
import { DocumentNode, OperationTypeNode } from 'graphql';
|
|
2
2
|
import { Path } from 'node-match-path';
|
|
3
3
|
import { SerializedResponse } from '../setupWorker/glossary';
|
|
4
4
|
import { set } from '../context/set';
|
|
@@ -11,7 +11,7 @@ import { cookie } from '../context/cookie';
|
|
|
11
11
|
import { MockedRequest, RequestHandler, ResponseResolver } from './RequestHandler';
|
|
12
12
|
import { ParsedGraphQLRequest, GraphQLMultipartRequestBody } from '../utils/internal/parseGraphQLRequest';
|
|
13
13
|
export declare type ExpectedOperationTypeNode = OperationTypeNode | 'all';
|
|
14
|
-
export declare type GraphQLHandlerNameSelector = RegExp | string;
|
|
14
|
+
export declare type GraphQLHandlerNameSelector = DocumentNode | RegExp | string;
|
|
15
15
|
export declare type GraphQLContext<QueryType> = {
|
|
16
16
|
set: typeof set;
|
|
17
17
|
status: typeof status;
|
|
@@ -35,11 +35,12 @@ export interface GraphQLJsonRequestBody<Variables extends GraphQLVariables> {
|
|
|
35
35
|
export interface GraphQLRequest<Variables extends GraphQLVariables> extends MockedRequest<GraphQLRequestBody<Variables>> {
|
|
36
36
|
variables: Variables;
|
|
37
37
|
}
|
|
38
|
+
export declare function isDocumentNode(value: DocumentNode | any): value is DocumentNode;
|
|
38
39
|
export declare class GraphQLHandler<Request extends GraphQLRequest<any> = GraphQLRequest<any>> extends RequestHandler<GraphQLHandlerInfo, Request, ParsedGraphQLRequest | null, GraphQLRequest<any>> {
|
|
39
40
|
private endpoint;
|
|
40
41
|
constructor(operationType: ExpectedOperationTypeNode, operationName: GraphQLHandlerNameSelector, endpoint: Path, resolver: ResponseResolver<any, any>);
|
|
41
42
|
parse(request: MockedRequest): ParsedGraphQLRequest<GraphQLVariables>;
|
|
42
43
|
protected getPublicRequest(request: Request, parsedResult: ParsedGraphQLRequest): GraphQLRequest<any>;
|
|
43
44
|
predicate(request: MockedRequest, parsedResult: ParsedGraphQLRequest): boolean;
|
|
44
|
-
log(request: Request, response: SerializedResponse
|
|
45
|
+
log(request: Request, response: SerializedResponse, handler: this, parsedRequest: ParsedGraphQLRequest): void;
|
|
45
46
|
}
|
|
@@ -2,6 +2,7 @@ import { Headers } from 'headers-utils';
|
|
|
2
2
|
import { MockedResponse, ResponseComposition } from '../response';
|
|
3
3
|
import { set } from '../context/set';
|
|
4
4
|
import { ResponseResolutionContext } from '../utils/getResponse';
|
|
5
|
+
import { SerializedResponse } from '../setupWorker/glossary';
|
|
5
6
|
export declare const defaultContext: {
|
|
6
7
|
status: (statusCode: number, statusText?: string | undefined) => import("../response").ResponseTransformer<any, any>;
|
|
7
8
|
set: typeof set;
|
|
@@ -65,7 +66,7 @@ export declare abstract class RequestHandler<HandlerInfo extends Record<string,
|
|
|
65
66
|
/**
|
|
66
67
|
* Print out the successfully handled request.
|
|
67
68
|
*/
|
|
68
|
-
abstract log(request: Request, response: any
|
|
69
|
+
abstract log(request: Request, response: SerializedResponse<any>, handler: this, parsedResult: ParsedResult): void;
|
|
69
70
|
/**
|
|
70
71
|
* Parse the captured request to extract additional information from it.
|
|
71
72
|
* Parsed result is then exposed to other methods of this request handler.
|
|
@@ -48,6 +48,6 @@ export declare class RestHandler<RequestType extends MockedRequest<DefaultReques
|
|
|
48
48
|
parse(request: RequestType, resolutionContext?: ResponseResolutionContext): Match;
|
|
49
49
|
protected getPublicRequest(request: RequestType, parsedResult: ParsedRestRequest): RestRequest<any, RequestParams>;
|
|
50
50
|
predicate(request: RequestType, parsedResult: ParsedRestRequest): boolean;
|
|
51
|
-
log(request: RequestType, response: SerializedResponse
|
|
51
|
+
log(request: RequestType, response: SerializedResponse): void;
|
|
52
52
|
}
|
|
53
53
|
export {};
|
|
@@ -2,7 +2,6 @@ import { Path } from 'node-match-path';
|
|
|
2
2
|
import { PartialDeep } from 'type-fest';
|
|
3
3
|
import { FlatHeadersObject } from 'headers-utils';
|
|
4
4
|
import { StrictEventEmitter } from 'strict-event-emitter';
|
|
5
|
-
import { MockedResponse } from '../response';
|
|
6
5
|
import { SharedOptions } from '../sharedOptions';
|
|
7
6
|
import { ServiceWorkerMessage } from '../utils/createBroadcastChannel';
|
|
8
7
|
import { MockedRequest, RequestHandler } from '../handlers/RequestHandler';
|
|
@@ -115,9 +114,12 @@ export interface StartOptions extends SharedOptions {
|
|
|
115
114
|
*/
|
|
116
115
|
findWorker: FindWorker;
|
|
117
116
|
}
|
|
118
|
-
export
|
|
117
|
+
export interface SerializedResponse<BodyType = any> {
|
|
118
|
+
status: number;
|
|
119
|
+
statusText: string;
|
|
119
120
|
headers: FlatHeadersObject;
|
|
120
|
-
|
|
121
|
+
body: BodyType;
|
|
122
|
+
}
|
|
121
123
|
export declare type StartReturnType = Promise<ServiceWorkerRegistration | undefined>;
|
|
122
124
|
export declare type StartHandler = (options: StartOptions, initialOptions: PartialDeep<StartOptions>) => StartReturnType;
|
|
123
125
|
export declare type StopHandler = () => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OperationTypeNode } from 'graphql';
|
|
1
|
+
import { DocumentNode, OperationTypeNode } from 'graphql';
|
|
2
2
|
import { GraphQLVariables } from '../../handlers/GraphQLHandler';
|
|
3
3
|
import { MockedRequest } from '../../handlers/RequestHandler';
|
|
4
4
|
export interface ParsedGraphQLQuery {
|
|
@@ -8,6 +8,7 @@ export interface ParsedGraphQLQuery {
|
|
|
8
8
|
export declare type ParsedGraphQLRequest<VariablesType extends GraphQLVariables = GraphQLVariables> = (ParsedGraphQLQuery & {
|
|
9
9
|
variables?: VariablesType;
|
|
10
10
|
}) | undefined;
|
|
11
|
+
export declare function parseDocumentNode(node: DocumentNode): ParsedGraphQLQuery;
|
|
11
12
|
export declare type GraphQLParsedOperationsMap = Record<string, string[]>;
|
|
12
13
|
export declare type GraphQLMultipartRequestBody = {
|
|
13
14
|
operations: string;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
export declare enum StatusCodeColor {
|
|
2
|
+
Success = "#69AB32",
|
|
3
|
+
Warning = "#F0BB4B",
|
|
4
|
+
Danger = "#E95F5D"
|
|
5
|
+
}
|
|
1
6
|
/**
|
|
2
7
|
* Returns a HEX color for a given response status code number.
|
|
3
8
|
*/
|
|
4
|
-
export declare function getStatusCodeColor(status: number):
|
|
9
|
+
export declare function getStatusCodeColor(status: number): StatusCodeColor;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { SerializedResponse } from '../../setupWorker/glossary';
|
|
2
2
|
/**
|
|
3
|
-
* Formats a mocked response for introspection in browser's console.
|
|
3
|
+
* Formats a mocked response for introspection in the browser's console.
|
|
4
4
|
*/
|
|
5
5
|
export declare function prepareResponse(res: SerializedResponse<any>): {
|
|
6
6
|
body: string | Record<string, any> | undefined;
|
|
7
7
|
status: number;
|
|
8
8
|
statusText: string;
|
|
9
|
-
once: boolean;
|
|
10
|
-
delay?: number | undefined;
|
|
11
9
|
headers: import("headers-utils").FlatHeadersObject;
|
|
12
10
|
};
|
package/lib/umd/index.js
CHANGED
|
@@ -1754,6 +1754,65 @@
|
|
|
1754
1754
|
|
|
1755
1755
|
var invariant$3 = {};
|
|
1756
1756
|
|
|
1757
|
+
var format$1 = {};
|
|
1758
|
+
|
|
1759
|
+
Object.defineProperty(format$1, "__esModule", { value: true });
|
|
1760
|
+
format$1.format = void 0;
|
|
1761
|
+
var POSITIONALS_EXP = /(%?)(%([sdjo]))/g;
|
|
1762
|
+
function serializePositional(positional, flag) {
|
|
1763
|
+
switch (flag) {
|
|
1764
|
+
// Strings.
|
|
1765
|
+
case 's':
|
|
1766
|
+
return positional;
|
|
1767
|
+
// Digits.
|
|
1768
|
+
case 'd':
|
|
1769
|
+
case 'i':
|
|
1770
|
+
return Number(positional);
|
|
1771
|
+
// JSON.
|
|
1772
|
+
case 'j':
|
|
1773
|
+
return JSON.stringify(positional);
|
|
1774
|
+
// Objects.
|
|
1775
|
+
case 'o': {
|
|
1776
|
+
// Preserve stings to prevent extra quotes around them.
|
|
1777
|
+
if (typeof positional === 'string') {
|
|
1778
|
+
return positional;
|
|
1779
|
+
}
|
|
1780
|
+
var json = JSON.stringify(positional);
|
|
1781
|
+
// If the positional isn't serializable, return it as-is.
|
|
1782
|
+
if (json === '{}' || json === '[]' || /^\[object .+?\]$/.test(json)) {
|
|
1783
|
+
return positional;
|
|
1784
|
+
}
|
|
1785
|
+
return json;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
function format(message) {
|
|
1790
|
+
var positionals = [];
|
|
1791
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1792
|
+
positionals[_i - 1] = arguments[_i];
|
|
1793
|
+
}
|
|
1794
|
+
if (positionals.length === 0) {
|
|
1795
|
+
return message;
|
|
1796
|
+
}
|
|
1797
|
+
var positionalIndex = 0;
|
|
1798
|
+
var formattedMessage = message.replace(POSITIONALS_EXP, function (match, isEscaped, _, flag) {
|
|
1799
|
+
var positional = positionals[positionalIndex];
|
|
1800
|
+
var value = serializePositional(positional, flag);
|
|
1801
|
+
if (!isEscaped) {
|
|
1802
|
+
positionalIndex++;
|
|
1803
|
+
return value;
|
|
1804
|
+
}
|
|
1805
|
+
return match;
|
|
1806
|
+
});
|
|
1807
|
+
// Append unresolved positionals to string as-is.
|
|
1808
|
+
if (positionalIndex < positionals.length) {
|
|
1809
|
+
formattedMessage += " " + positionals.slice(positionalIndex).join(' ');
|
|
1810
|
+
}
|
|
1811
|
+
formattedMessage = formattedMessage.replace(/%{2,2}/g, '%');
|
|
1812
|
+
return formattedMessage;
|
|
1813
|
+
}
|
|
1814
|
+
format$1.format = format;
|
|
1815
|
+
|
|
1757
1816
|
var __extends$1 = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
1758
1817
|
var extendStatics = function (d, b) {
|
|
1759
1818
|
extendStatics = Object.setPrototypeOf ||
|
|
@@ -1775,21 +1834,9 @@
|
|
|
1775
1834
|
return to;
|
|
1776
1835
|
};
|
|
1777
1836
|
Object.defineProperty(invariant$3, "__esModule", { value: true });
|
|
1778
|
-
invariant$3.invariant = invariant$3.InvariantError =
|
|
1837
|
+
invariant$3.invariant = invariant$3.InvariantError = void 0;
|
|
1838
|
+
var format_1 = format$1;
|
|
1779
1839
|
var STACK_FRAMES_TO_IGNORE = 2;
|
|
1780
|
-
function interpolate(message) {
|
|
1781
|
-
var positionals = [];
|
|
1782
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1783
|
-
positionals[_i - 1] = arguments[_i];
|
|
1784
|
-
}
|
|
1785
|
-
var index = 0;
|
|
1786
|
-
return message.replace(/%[s|d|o]/g, function (match) {
|
|
1787
|
-
var _a;
|
|
1788
|
-
var value = (_a = positionals[index++]) !== null && _a !== void 0 ? _a : match;
|
|
1789
|
-
return typeof value === 'object' ? JSON.stringify(value) : value;
|
|
1790
|
-
});
|
|
1791
|
-
}
|
|
1792
|
-
invariant$3.interpolate = interpolate;
|
|
1793
1840
|
var InvariantError = /** @class */ (function (_super) {
|
|
1794
1841
|
__extends$1(InvariantError, _super);
|
|
1795
1842
|
function InvariantError(message) {
|
|
@@ -1799,7 +1846,7 @@
|
|
|
1799
1846
|
}
|
|
1800
1847
|
var _this = _super.call(this, message) || this;
|
|
1801
1848
|
_this.name = 'Invariant Violation';
|
|
1802
|
-
_this.message =
|
|
1849
|
+
_this.message = format_1.format.apply(void 0, __spreadArray([message], positionals));
|
|
1803
1850
|
if (_this.stack) {
|
|
1804
1851
|
var prevStack = _this.stack;
|
|
1805
1852
|
_this.stack = prevStack
|
|
@@ -1836,6 +1883,7 @@
|
|
|
1836
1883
|
};
|
|
1837
1884
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1838
1885
|
__exportStar(invariant$3, exports);
|
|
1886
|
+
__exportStar(format$1, exports);
|
|
1839
1887
|
}(lib$2));
|
|
1840
1888
|
|
|
1841
1889
|
const LIBRARY_PREFIX = '[MSW]';
|
|
@@ -1843,7 +1891,7 @@
|
|
|
1843
1891
|
* Formats a given message by appending the library's prefix string.
|
|
1844
1892
|
*/
|
|
1845
1893
|
function formatMessage(message, ...positionals) {
|
|
1846
|
-
const interpolatedMessage = lib$2.
|
|
1894
|
+
const interpolatedMessage = lib$2.format(message, ...positionals);
|
|
1847
1895
|
return `${LIBRARY_PREFIX} ${interpolatedMessage}`;
|
|
1848
1896
|
}
|
|
1849
1897
|
/**
|
|
@@ -22235,17 +22283,20 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
22235
22283
|
: new URL(request.url.pathname, `${request.url.protocol}//${request.url.host}`).href;
|
|
22236
22284
|
};
|
|
22237
22285
|
|
|
22238
|
-
function
|
|
22286
|
+
function parseDocumentNode(node) {
|
|
22239
22287
|
var _a;
|
|
22288
|
+
const operationDef = node.definitions.find((def) => {
|
|
22289
|
+
return def.kind === 'OperationDefinition';
|
|
22290
|
+
});
|
|
22291
|
+
return {
|
|
22292
|
+
operationType: operationDef === null || operationDef === void 0 ? void 0 : operationDef.operation,
|
|
22293
|
+
operationName: (_a = operationDef === null || operationDef === void 0 ? void 0 : operationDef.name) === null || _a === void 0 ? void 0 : _a.value,
|
|
22294
|
+
};
|
|
22295
|
+
}
|
|
22296
|
+
function parseQuery(query) {
|
|
22240
22297
|
try {
|
|
22241
22298
|
const ast = graphql$3.parse(query);
|
|
22242
|
-
|
|
22243
|
-
return def.kind === 'OperationDefinition';
|
|
22244
|
-
});
|
|
22245
|
-
return {
|
|
22246
|
-
operationType: operationDef === null || operationDef === void 0 ? void 0 : operationDef.operation,
|
|
22247
|
-
operationName: (_a = operationDef === null || operationDef === void 0 ? void 0 : operationDef.name) === null || _a === void 0 ? void 0 : _a.value,
|
|
22248
|
-
};
|
|
22299
|
+
return parseDocumentNode(ast);
|
|
22249
22300
|
}
|
|
22250
22301
|
catch (error) {
|
|
22251
22302
|
return error;
|
|
@@ -22325,7 +22376,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
22325
22376
|
const parsedResult = parseQuery(query);
|
|
22326
22377
|
if (parsedResult instanceof Error) {
|
|
22327
22378
|
const requestPublicUrl = getPublicUrlFromRequest(request);
|
|
22328
|
-
throw new Error(devUtils.formatMessage('Failed to intercept a GraphQL request to "%s %s": cannot parse query. See the error message from the parser below.\n\n%
|
|
22379
|
+
throw new Error(devUtils.formatMessage('Failed to intercept a GraphQL request to "%s %s": cannot parse query. See the error message from the parser below.\n\n%s', request.method, requestPublicUrl, parsedResult.message));
|
|
22329
22380
|
}
|
|
22330
22381
|
return {
|
|
22331
22382
|
operationType: parsedResult.operationType,
|
|
@@ -22334,19 +22385,28 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
22334
22385
|
};
|
|
22335
22386
|
}
|
|
22336
22387
|
|
|
22388
|
+
var StatusCodeColor;
|
|
22389
|
+
(function (StatusCodeColor) {
|
|
22390
|
+
StatusCodeColor["Success"] = "#69AB32";
|
|
22391
|
+
StatusCodeColor["Warning"] = "#F0BB4B";
|
|
22392
|
+
StatusCodeColor["Danger"] = "#E95F5D";
|
|
22393
|
+
})(StatusCodeColor || (StatusCodeColor = {}));
|
|
22337
22394
|
/**
|
|
22338
22395
|
* Returns a HEX color for a given response status code number.
|
|
22339
22396
|
*/
|
|
22340
22397
|
function getStatusCodeColor(status) {
|
|
22341
22398
|
if (status < 300) {
|
|
22342
|
-
return
|
|
22399
|
+
return StatusCodeColor.Success;
|
|
22343
22400
|
}
|
|
22344
22401
|
if (status < 400) {
|
|
22345
|
-
return
|
|
22402
|
+
return StatusCodeColor.Warning;
|
|
22346
22403
|
}
|
|
22347
|
-
return
|
|
22404
|
+
return StatusCodeColor.Danger;
|
|
22348
22405
|
}
|
|
22349
22406
|
|
|
22407
|
+
/**
|
|
22408
|
+
* Returns a timestamp string in a "HH:MM:SS" format.
|
|
22409
|
+
*/
|
|
22350
22410
|
function getTimestamp() {
|
|
22351
22411
|
const now = new Date();
|
|
22352
22412
|
return [now.getHours(), now.getMinutes(), now.getSeconds()]
|
|
@@ -22364,7 +22424,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
22364
22424
|
}
|
|
22365
22425
|
|
|
22366
22426
|
/**
|
|
22367
|
-
* Formats a mocked response for introspection in browser's console.
|
|
22427
|
+
* Formats a mocked response for introspection in the browser's console.
|
|
22368
22428
|
*/
|
|
22369
22429
|
function prepareResponse(res) {
|
|
22370
22430
|
const responseHeaders = lib$6.objectToHeaders(res.headers);
|
|
@@ -22727,7 +22787,8 @@ ${queryParams
|
|
|
22727
22787
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
22728
22788
|
const loggedRequest = prepareRequest(request);
|
|
22729
22789
|
const loggedResponse = prepareResponse(response);
|
|
22730
|
-
|
|
22790
|
+
const statusColor = getStatusCodeColor(response.status);
|
|
22791
|
+
console.groupCollapsed(devUtils.formatMessage('%s %s %s (%c%s%c)'), getTimestamp(), request.method, publicUrl, `color:${statusColor}`, `${response.status} ${response.statusText}`, 'color:inherit');
|
|
22731
22792
|
console.log('Request', loggedRequest);
|
|
22732
22793
|
console.log('Handler:', {
|
|
22733
22794
|
mask: this.info.path,
|
|
@@ -22757,16 +22818,33 @@ ${queryParams
|
|
|
22757
22818
|
errors,
|
|
22758
22819
|
cookie,
|
|
22759
22820
|
};
|
|
22821
|
+
function isDocumentNode(value) {
|
|
22822
|
+
if (value == null) {
|
|
22823
|
+
return false;
|
|
22824
|
+
}
|
|
22825
|
+
return typeof value === 'object' && 'kind' in value && 'definitions' in value;
|
|
22826
|
+
}
|
|
22760
22827
|
class GraphQLHandler extends RequestHandler {
|
|
22761
22828
|
constructor(operationType, operationName, endpoint, resolver) {
|
|
22829
|
+
let resolvedOperationName = operationName;
|
|
22830
|
+
if (isDocumentNode(operationName)) {
|
|
22831
|
+
const parsedNode = parseDocumentNode(operationName);
|
|
22832
|
+
if (parsedNode.operationType !== operationType) {
|
|
22833
|
+
throw new Error(`Failed to create a GraphQL handler: provided a DocumentNode with a mismatched operation type (expected "${operationType}", but got "${parsedNode.operationType}").`);
|
|
22834
|
+
}
|
|
22835
|
+
if (!parsedNode.operationName) {
|
|
22836
|
+
throw new Error(`Failed to create a GraphQL handler: provided a DocumentNode with no operation name.`);
|
|
22837
|
+
}
|
|
22838
|
+
resolvedOperationName = parsedNode.operationName;
|
|
22839
|
+
}
|
|
22762
22840
|
const header = operationType === 'all'
|
|
22763
22841
|
? `${operationType} (origin: ${endpoint.toString()})`
|
|
22764
|
-
: `${operationType} ${
|
|
22842
|
+
: `${operationType} ${resolvedOperationName} (origin: ${endpoint.toString()})`;
|
|
22765
22843
|
super({
|
|
22766
22844
|
info: {
|
|
22767
22845
|
header,
|
|
22768
22846
|
operationType,
|
|
22769
|
-
operationName,
|
|
22847
|
+
operationName: resolvedOperationName,
|
|
22770
22848
|
},
|
|
22771
22849
|
ctx: graphqlContext,
|
|
22772
22850
|
resolver,
|
|
@@ -22802,10 +22880,11 @@ Consider naming this operation or using "graphql.operation" request handler to i
|
|
|
22802
22880
|
hasMatchingOperationType &&
|
|
22803
22881
|
hasMatchingOperationName);
|
|
22804
22882
|
}
|
|
22805
|
-
log(request, response) {
|
|
22883
|
+
log(request, response, handler, parsedRequest) {
|
|
22806
22884
|
const loggedRequest = prepareRequest(request);
|
|
22807
22885
|
const loggedResponse = prepareResponse(response);
|
|
22808
|
-
|
|
22886
|
+
const statusColor = getStatusCodeColor(response.status);
|
|
22887
|
+
console.groupCollapsed(devUtils.formatMessage('%s %s (%c%s%c)'), getTimestamp(), `${parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationType} ${parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationName}`, `color:${statusColor}`, `${response.status} ${response.statusText}`, 'color:inherit');
|
|
22809
22888
|
console.log('Request:', loggedRequest);
|
|
22810
22889
|
console.log('Handler:', this);
|
|
22811
22890
|
console.log('Response:', loggedResponse);
|
|
@@ -23050,8 +23129,8 @@ Read more: https://mswjs.io/docs/getting-started/mocks\
|
|
|
23050
23129
|
const { payload: actualChecksum } = yield context.events.once('INTEGRITY_CHECK_RESPONSE');
|
|
23051
23130
|
// Compare the response from the Service Worker and the
|
|
23052
23131
|
// global variable set by Rollup during the build.
|
|
23053
|
-
if (actualChecksum !== "
|
|
23054
|
-
throw new Error(`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"
|
|
23132
|
+
if (actualChecksum !== "f0a916b13c8acc2b526a03a6d26df85f") {
|
|
23133
|
+
throw new Error(`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"f0a916b13c8acc2b526a03a6d26df85f"}).`);
|
|
23055
23134
|
}
|
|
23056
23135
|
return serviceWorker;
|
|
23057
23136
|
});
|
|
@@ -23742,6 +23821,8 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
23742
23821
|
function createDebug(namespace) {
|
|
23743
23822
|
let prevTime;
|
|
23744
23823
|
let enableOverride = null;
|
|
23824
|
+
let namespacesCache;
|
|
23825
|
+
let enabledCache;
|
|
23745
23826
|
|
|
23746
23827
|
function debug(...args) {
|
|
23747
23828
|
// Disabled?
|
|
@@ -23802,7 +23883,17 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
23802
23883
|
Object.defineProperty(debug, 'enabled', {
|
|
23803
23884
|
enumerable: true,
|
|
23804
23885
|
configurable: false,
|
|
23805
|
-
get: () =>
|
|
23886
|
+
get: () => {
|
|
23887
|
+
if (enableOverride !== null) {
|
|
23888
|
+
return enableOverride;
|
|
23889
|
+
}
|
|
23890
|
+
if (namespacesCache !== createDebug.namespaces) {
|
|
23891
|
+
namespacesCache = createDebug.namespaces;
|
|
23892
|
+
enabledCache = createDebug.enabled(namespace);
|
|
23893
|
+
}
|
|
23894
|
+
|
|
23895
|
+
return enabledCache;
|
|
23896
|
+
},
|
|
23806
23897
|
set: v => {
|
|
23807
23898
|
enableOverride = v;
|
|
23808
23899
|
}
|
|
@@ -23831,6 +23922,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
23831
23922
|
*/
|
|
23832
23923
|
function enable(namespaces) {
|
|
23833
23924
|
createDebug.save(namespaces);
|
|
23925
|
+
createDebug.namespaces = namespaces;
|
|
23834
23926
|
|
|
23835
23927
|
createDebug.names = [];
|
|
23836
23928
|
createDebug.skips = [];
|
|
@@ -27229,7 +27321,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
27229
27321
|
debug('received original response', _this.status, _this.statusText);
|
|
27230
27322
|
debug('original response body:', _this.response);
|
|
27231
27323
|
var responseHeaders = originalRequest_1.getAllResponseHeaders();
|
|
27232
|
-
debug('original response headers', responseHeaders);
|
|
27324
|
+
debug('original response headers:\n', responseHeaders);
|
|
27233
27325
|
_this._responseHeaders = headers_utils_1.stringToHeaders(responseHeaders);
|
|
27234
27326
|
debug('original response headers (normalized)', _this._responseHeaders);
|
|
27235
27327
|
debug('original response finished');
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
/* tslint:disable */
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Mock Service Worker (0.
|
|
5
|
+
* Mock Service Worker (0.34.0).
|
|
6
6
|
* @see https://github.com/mswjs/msw
|
|
7
7
|
* - Please do NOT modify this file.
|
|
8
8
|
* - Please do NOT serve this file on production.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const INTEGRITY_CHECKSUM = '
|
|
11
|
+
const INTEGRITY_CHECKSUM = 'f0a916b13c8acc2b526a03a6d26df85f'
|
|
12
12
|
const bypassHeaderName = 'x-msw-bypass'
|
|
13
13
|
const activeClientIds = new Set()
|
|
14
14
|
|
|
@@ -221,13 +221,11 @@ async function getResponse(event, client, requestId) {
|
|
|
221
221
|
|
|
222
222
|
console.error(
|
|
223
223
|
`\
|
|
224
|
-
[MSW]
|
|
224
|
+
[MSW] Uncaught exception in the request handler for "%s %s":
|
|
225
225
|
|
|
226
|
-
${parsedBody.
|
|
227
|
-
(see more detailed error stack trace in the mocked response body)
|
|
226
|
+
${parsedBody.location}
|
|
228
227
|
|
|
229
|
-
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error.
|
|
230
|
-
If you wish to mock an error response, please refer to this guide: https://mswjs.io/docs/recipes/mocking-error-responses\
|
|
228
|
+
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/recipes/mocking-error-responses\
|
|
231
229
|
`,
|
|
232
230
|
request.method,
|
|
233
231
|
request.url,
|
|
@@ -242,6 +240,12 @@ If you wish to mock an error response, please refer to this guide: https://mswjs
|
|
|
242
240
|
|
|
243
241
|
self.addEventListener('fetch', function (event) {
|
|
244
242
|
const { request } = event
|
|
243
|
+
const accept = request.headers.get('accept') || ''
|
|
244
|
+
|
|
245
|
+
// Bypass server-sent events.
|
|
246
|
+
if (accept.includes('text/event-stream')) {
|
|
247
|
+
return
|
|
248
|
+
}
|
|
245
249
|
|
|
246
250
|
// Bypass navigation requests.
|
|
247
251
|
if (request.mode === 'navigate') {
|
|
@@ -265,11 +269,22 @@ self.addEventListener('fetch', function (event) {
|
|
|
265
269
|
|
|
266
270
|
return event.respondWith(
|
|
267
271
|
handleRequest(event, requestId).catch((error) => {
|
|
272
|
+
if (error.name === 'NetworkError') {
|
|
273
|
+
console.warn(
|
|
274
|
+
'[MSW] Successfully emulated a network error for the "%s %s" request.',
|
|
275
|
+
request.method,
|
|
276
|
+
request.url,
|
|
277
|
+
)
|
|
278
|
+
return
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// At this point, any exception indicates an issue with the original request/response.
|
|
268
282
|
console.error(
|
|
269
|
-
|
|
283
|
+
`\
|
|
284
|
+
[MSW] Caught an exception from the "%s %s" request (%s). This is probably not a problem with Mock Service Worker. There is likely an additional logging output above.`,
|
|
270
285
|
request.method,
|
|
271
286
|
request.url,
|
|
272
|
-
error
|
|
287
|
+
`${error.name}: ${error.message}`,
|
|
273
288
|
)
|
|
274
289
|
}),
|
|
275
290
|
)
|