msw 0.21.3 → 0.22.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.
Files changed (49) hide show
  1. package/README.md +3 -9
  2. package/lib/esm/errors-deps.js +6 -7
  3. package/lib/esm/fetch-deps.js +44 -22
  4. package/lib/esm/{matchRequestUrl-deps.js → getCallFrame-deps.js} +32 -5
  5. package/lib/esm/graphql.js +601 -465
  6. package/lib/esm/index.js +56 -50
  7. package/lib/esm/mockServiceWorker.js +16 -10
  8. package/lib/esm/rest-deps.js +10 -1
  9. package/lib/esm/rest.js +1 -1
  10. package/lib/types/context/errors.d.ts +3 -3
  11. package/lib/types/context/json.d.ts +5 -1
  12. package/lib/types/index.d.ts +3 -2
  13. package/lib/types/native/index.d.ts +1 -7
  14. package/lib/types/node/createSetupServer.d.ts +2 -23
  15. package/{node/node/createSetupServer.d.ts → lib/types/node/glossary.d.ts} +12 -13
  16. package/lib/types/node/index.d.ts +1 -0
  17. package/lib/types/node/setupServer.d.ts +1 -7
  18. package/lib/types/response.d.ts +7 -2
  19. package/lib/types/rest.d.ts +60 -30
  20. package/lib/types/setupWorker/glossary.d.ts +22 -0
  21. package/lib/types/setupWorker/setupWorker.d.ts +1 -19
  22. package/lib/types/utils/handlers/requestHandler.d.ts +13 -1
  23. package/lib/types/utils/internal/getCallFrame.d.ts +4 -0
  24. package/lib/types/utils/internal/isObject.d.ts +4 -0
  25. package/lib/types/utils/internal/mergeRight.d.ts +1 -1
  26. package/lib/types/utils/request/onUnhandledRequest.d.ts +1 -1
  27. package/lib/umd/index.js +720 -519
  28. package/lib/umd/mockServiceWorker.js +16 -10
  29. package/native/index.js +2017 -125
  30. package/node/index.js +2017 -125
  31. package/package.json +34 -32
  32. package/lib/types/LiveStorage.d.ts +0 -17
  33. package/node/context/delay.d.ts +0 -11
  34. package/node/context/fetch.d.ts +0 -8
  35. package/node/context/set.d.ts +0 -2
  36. package/node/context/status.d.ts +0 -2
  37. package/node/node/index.d.ts +0 -5
  38. package/node/node/setupServer.d.ts +0 -7
  39. package/node/response.d.ts +0 -25
  40. package/node/utils/NetworkError.d.ts +0 -3
  41. package/node/utils/getResponse.d.ts +0 -14
  42. package/node/utils/handlers/requestHandler.d.ts +0 -74
  43. package/node/utils/handlers/requestHandlerUtils.d.ts +0 -4
  44. package/node/utils/internal/compose.d.ts +0 -5
  45. package/node/utils/internal/isNodeProcess.d.ts +0 -5
  46. package/node/utils/internal/jsonParse.d.ts +0 -5
  47. package/node/utils/request/getPublicUrlFromRequest.d.ts +0 -6
  48. package/node/utils/request/onUnhandledRequest.d.ts +0 -5
  49. package/node/utils/request/parseBody.d.ts +0 -5
@@ -7,7 +7,7 @@
7
7
  /* eslint-disable */
8
8
  /* tslint:disable */
9
9
 
10
- const INTEGRITY_CHECKSUM = 'd1e0e502f550d40a34bee90822e4bf98'
10
+ const INTEGRITY_CHECKSUM = '65d33ca82955e1c5928aed19d1bdf3f9'
11
11
  const bypassHeaderName = 'x-msw-bypass'
12
12
 
13
13
  let clients = {}
@@ -74,11 +74,22 @@ self.addEventListener('message', async function (event) {
74
74
  }
75
75
  })
76
76
 
77
- self.addEventListener('fetch', async function (event) {
77
+ self.addEventListener('fetch', function (event) {
78
78
  const { clientId, request } = event
79
79
  const requestClone = request.clone()
80
80
  const getOriginalResponse = () => fetch(requestClone)
81
81
 
82
+ // Bypass navigation requests.
83
+ if (request.mode === 'navigate') {
84
+ return
85
+ }
86
+
87
+ // Bypass mocking if the current client isn't present in the internal clients map
88
+ // (i.e. has the mocking disabled).
89
+ if (!clients[clientId]) {
90
+ return
91
+ }
92
+
82
93
  // Opening the DevTools triggers the "only-if-cached" request
83
94
  // that cannot be handled by the worker. Bypass such requests.
84
95
  if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
@@ -89,20 +100,15 @@ self.addEventListener('fetch', async function (event) {
89
100
  new Promise(async (resolve, reject) => {
90
101
  const client = await event.target.clients.get(clientId)
91
102
 
92
- if (
93
- // Bypass mocking when no clients active
94
- !client ||
95
- // Bypass mocking if the current client has mocking disabled
96
- !clients[clientId] ||
97
- // Bypass mocking for navigation requests
98
- request.mode === 'navigate'
99
- ) {
103
+ // Bypass mocking when the request client is not active.
104
+ if (!client) {
100
105
  return resolve(getOriginalResponse())
101
106
  }
102
107
 
103
108
  // Bypass requests with the explicit bypass header
104
109
  if (requestClone.headers.get(bypassHeaderName) === 'true') {
105
110
  const modifiedHeaders = serializeHeaders(requestClone.headers)
111
+
106
112
  // Remove the bypass header to comply with the CORS preflight check
107
113
  delete modifiedHeaders[bypassHeaderName]
108
114