msw 2.2.3 → 2.2.5

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 (55) hide show
  1. package/cli/init.js +1 -1
  2. package/lib/browser/index.js +33 -36
  3. package/lib/browser/index.js.map +1 -1
  4. package/lib/browser/index.mjs +33 -36
  5. package/lib/browser/index.mjs.map +1 -1
  6. package/lib/core/{GraphQLHandler-AenIUdwE.d.mts → GraphQLHandler-BumTfgY4.d.mts} +1 -1
  7. package/lib/core/{GraphQLHandler-jOzqbxSK.d.ts → GraphQLHandler-DqVT0Gbq.d.ts} +1 -1
  8. package/lib/core/HttpResponse.d.mts +1 -1
  9. package/lib/core/HttpResponse.d.ts +1 -1
  10. package/lib/core/SetupApi.d.mts +1 -1
  11. package/lib/core/SetupApi.d.ts +1 -1
  12. package/lib/core/getResponse.d.mts +1 -1
  13. package/lib/core/getResponse.d.ts +1 -1
  14. package/lib/core/graphql.d.mts +2 -2
  15. package/lib/core/graphql.d.ts +2 -2
  16. package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
  17. package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
  18. package/lib/core/handlers/HttpHandler.d.mts +1 -1
  19. package/lib/core/handlers/HttpHandler.d.ts +1 -1
  20. package/lib/core/handlers/RequestHandler.d.mts +1 -1
  21. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  22. package/lib/core/http.d.mts +1 -1
  23. package/lib/core/http.d.ts +1 -1
  24. package/lib/core/index.d.mts +2 -2
  25. package/lib/core/index.d.ts +2 -2
  26. package/lib/core/passthrough.d.mts +1 -1
  27. package/lib/core/passthrough.d.ts +1 -1
  28. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  29. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  30. package/lib/core/utils/HttpResponse/decorators.js +4 -1
  31. package/lib/core/utils/HttpResponse/decorators.js.map +1 -1
  32. package/lib/core/utils/HttpResponse/decorators.mjs +4 -1
  33. package/lib/core/utils/HttpResponse/decorators.mjs.map +1 -1
  34. package/lib/core/utils/executeHandlers.d.mts +1 -1
  35. package/lib/core/utils/executeHandlers.d.ts +1 -1
  36. package/lib/core/utils/handleRequest.d.mts +1 -1
  37. package/lib/core/utils/handleRequest.d.ts +1 -1
  38. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
  39. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
  40. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  41. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  42. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  43. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  44. package/lib/iife/index.js +21 -23
  45. package/lib/iife/index.js.map +1 -1
  46. package/lib/mockServiceWorker.js +7 -3
  47. package/package.json +6 -9
  48. package/src/browser/setupWorker/glossary.ts +4 -1
  49. package/src/browser/setupWorker/start/createStartHandler.ts +9 -19
  50. package/src/browser/utils/checkWorkerIntegrity.ts +34 -0
  51. package/src/core/utils/HttpResponse/decorators.ts +8 -4
  52. package/src/mockServiceWorker.js +6 -2
  53. package/src/browser/utils/requestIntegrityCheck.ts +0 -23
  54. /package/lib/core/{HttpResponse-wcp03c7-.d.mts → HttpResponse-C94XLD-W.d.mts} +0 -0
  55. /package/lib/core/{HttpResponse-_514VQ9z.d.ts → HttpResponse-jHZ0p2dL.d.ts} +0 -0
@@ -95,6 +95,9 @@ function isNodeProcess() {
95
95
  return false;
96
96
  }
97
97
 
98
+ // src/browser/setupWorker/start/createStartHandler.ts
99
+ import { devUtils as devUtils7 } from '../core/utils/internal/devUtils.mjs';
100
+
98
101
  // node_modules/.pnpm/@open-draft+until@2.1.0/node_modules/@open-draft/until/lib/index.mjs
99
102
  var until = async (promise) => {
100
103
  try {
@@ -107,9 +110,6 @@ var until = async (promise) => {
107
110
  }
108
111
  };
109
112
 
110
- // src/browser/setupWorker/start/createStartHandler.ts
111
- import { devUtils as devUtils6 } from '../core/utils/internal/devUtils.mjs';
112
-
113
113
  // src/browser/setupWorker/start/utils/getWorkerInstance.ts
114
114
  import { devUtils } from '../core/utils/internal/devUtils.mjs';
115
115
 
@@ -352,18 +352,22 @@ This exception has been gracefully handled as a 500 response, however, it's stro
352
352
  };
353
353
  };
354
354
 
355
- // src/browser/utils/requestIntegrityCheck.ts
356
- async function requestIntegrityCheck(context, serviceWorker) {
355
+ // src/browser/utils/checkWorkerIntegrity.ts
356
+ import { devUtils as devUtils5 } from '../core/utils/internal/devUtils.mjs';
357
+ async function checkWorkerIntegrity(context) {
357
358
  context.workerChannel.send("INTEGRITY_CHECK_REQUEST");
358
- const { payload: actualChecksum } = await context.events.once(
359
- "INTEGRITY_CHECK_RESPONSE"
360
- );
361
- if (actualChecksum !== "223d191a56023cd36aa88c802961b911") {
362
- throw new Error(
363
- `Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"223d191a56023cd36aa88c802961b911"}).`
359
+ const { payload } = await context.events.once("INTEGRITY_CHECK_RESPONSE");
360
+ if (payload.checksum !== "5db7e6e8385dc04e017ac4823e0e9b29") {
361
+ devUtils5.warn(
362
+ `The currently registered Service Worker has been generated by a different version of MSW (${payload.packageVersion}) and may not be fully compatible with the installed version.
363
+
364
+ It's recommended you update your worker script by running this command:
365
+
366
+ \u2022 npx msw init <PUBLIC_DIR>
367
+
368
+ You can also automate this process and make the worker script update automatically upon the library installations. Read more: https://mswjs.io/docs/cli/init.`
364
369
  );
365
370
  }
366
- return serviceWorker;
367
371
  }
368
372
 
369
373
  // node_modules/.pnpm/@mswjs+interceptors@0.25.16/node_modules/@mswjs/interceptors/lib/browser/chunk-UJZOJSMP.mjs
@@ -1056,10 +1060,10 @@ function createResponseListener(context) {
1056
1060
  }
1057
1061
 
1058
1062
  // src/browser/setupWorker/start/utils/validateWorkerScope.ts
1059
- import { devUtils as devUtils5 } from '../core/utils/internal/devUtils.mjs';
1063
+ import { devUtils as devUtils6 } from '../core/utils/internal/devUtils.mjs';
1060
1064
  function validateWorkerScope(registration, options) {
1061
1065
  if (!options?.quiet && !location.href.startsWith(registration.scope)) {
1062
- devUtils5.warn(
1066
+ devUtils6.warn(
1063
1067
  `Cannot intercept requests on this page because it's outside of the worker's scope ("${registration.scope}"). If you wish to mock API requests on this page, you must resolve this scope issue.
1064
1068
 
1065
1069
  - (Recommended) Register the worker at the root level ("/") of your application.
@@ -1085,14 +1089,14 @@ var createStartHandler = (context) => {
1085
1089
  );
1086
1090
  const [worker, registration] = instance;
1087
1091
  if (!worker) {
1088
- const missingWorkerMessage = customOptions?.findWorker ? devUtils6.formatMessage(
1092
+ const missingWorkerMessage = customOptions?.findWorker ? devUtils7.formatMessage(
1089
1093
  `Failed to locate the Service Worker registration using a custom "findWorker" predicate.
1090
1094
 
1091
1095
  Please ensure that the custom predicate properly locates the Service Worker registration at "%s".
1092
1096
  More details: https://mswjs.io/docs/api/setup-worker/start#findworker
1093
1097
  `,
1094
1098
  options.serviceWorker.url
1095
- ) : devUtils6.formatMessage(
1099
+ ) : devUtils7.formatMessage(
1096
1100
  `Failed to locate the Service Worker registration.
1097
1101
 
1098
1102
  This most likely means that the worker script URL "%s" cannot resolve against the actual public hostname (%s). This may happen if your application runs behind a proxy, or has a dynamic hostname.
@@ -1111,19 +1115,12 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
1111
1115
  }
1112
1116
  window.clearInterval(context.keepAliveInterval);
1113
1117
  });
1114
- const integrityCheckResult = await until(
1115
- () => requestIntegrityCheck(context, worker)
1116
- );
1117
- if (integrityCheckResult.error) {
1118
- devUtils6.error(`Detected outdated Service Worker: ${integrityCheckResult.error.message}
1119
-
1120
- The mocking is still enabled, but it's highly recommended that you update your Service Worker by running:
1121
-
1122
- $ npx msw init <PUBLIC_DIR>
1123
-
1124
- This is necessary to ensure that the Service Worker is in sync with the library to guarantee its stability.
1125
- If this message still persists after updating, please report an issue: https://github.com/open-draft/msw/issues `);
1126
- }
1118
+ await checkWorkerIntegrity(context).catch((error2) => {
1119
+ devUtils7.error(
1120
+ "Error while checking the worker script integrity. Please report this on GitHub (https://github.com/mswjs/msw/issues), including the original error below."
1121
+ );
1122
+ console.error(error2);
1123
+ });
1127
1124
  context.keepAliveInterval = window.setInterval(
1128
1125
  () => context.workerChannel.send("KEEPALIVE_REQUEST"),
1129
1126
  5e3
@@ -1154,16 +1151,16 @@ If this message still persists after updating, please report an issue: https://g
1154
1151
  };
1155
1152
 
1156
1153
  // src/browser/setupWorker/stop/createStop.ts
1157
- import { devUtils as devUtils8 } from '../core/utils/internal/devUtils.mjs';
1154
+ import { devUtils as devUtils9 } from '../core/utils/internal/devUtils.mjs';
1158
1155
 
1159
1156
  // src/browser/setupWorker/stop/utils/printStopMessage.ts
1160
- import { devUtils as devUtils7 } from '../core/utils/internal/devUtils.mjs';
1157
+ import { devUtils as devUtils8 } from '../core/utils/internal/devUtils.mjs';
1161
1158
  function printStopMessage(args = {}) {
1162
1159
  if (args.quiet) {
1163
1160
  return;
1164
1161
  }
1165
1162
  console.log(
1166
- `%c${devUtils7.formatMessage("Mocking disabled.")}`,
1163
+ `%c${devUtils8.formatMessage("Mocking disabled.")}`,
1167
1164
  "color:orangered;font-weight:bold;"
1168
1165
  );
1169
1166
  }
@@ -1172,7 +1169,7 @@ function printStopMessage(args = {}) {
1172
1169
  var createStop = (context) => {
1173
1170
  return function stop() {
1174
1171
  if (!context.isMockingEnabled) {
1175
- devUtils8.warn(
1172
+ devUtils9.warn(
1176
1173
  'Found a redundant "worker.stop()" call. Note that stopping the worker while mocking already stopped has no effect. Consider removing this "worker.stop()" call.'
1177
1174
  );
1178
1175
  return;
@@ -2263,7 +2260,7 @@ function createFallbackStop(context) {
2263
2260
  }
2264
2261
 
2265
2262
  // src/browser/setupWorker/setupWorker.ts
2266
- import { devUtils as devUtils9 } from '../core/utils/internal/devUtils.mjs';
2263
+ import { devUtils as devUtils10 } from '../core/utils/internal/devUtils.mjs';
2267
2264
  import { SetupApi } from '../core/SetupApi.mjs';
2268
2265
  import { mergeRight as mergeRight2 } from '../core/utils/internal/mergeRight.mjs';
2269
2266
 
@@ -2291,7 +2288,7 @@ var SetupWorkerApi = class extends SetupApi {
2291
2288
  super(...handlers);
2292
2289
  invariant(
2293
2290
  !isNodeProcess(),
2294
- devUtils9.formatMessage(
2291
+ devUtils10.formatMessage(
2295
2292
  "Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for Node.js environment instead."
2296
2293
  )
2297
2294
  );
@@ -2389,7 +2386,7 @@ var SetupWorkerApi = class extends SetupApi {
2389
2386
  }
2390
2387
  async start(options = {}) {
2391
2388
  if (options.waitUntilReady === true) {
2392
- devUtils9.warn(
2389
+ devUtils10.warn(
2393
2390
  'The "waitUntilReady" option has been deprecated. Please remove it from this "worker.start()" call. Follow the recommended Browser integration (https://mswjs.io/docs/integrations/browser) to eliminate any race conditions between the Service Worker registration and any requests made by your application on initial render.'
2394
2391
  );
2395
2392
  }