msw 2.11.0 → 2.11.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.
Files changed (78) hide show
  1. package/lib/browser/index.js.map +1 -1
  2. package/lib/browser/index.mjs.map +1 -1
  3. package/lib/core/{HttpResponse-DiuKTgC7.d.mts → HttpResponse-B4YmE-GJ.d.mts} +1 -1
  4. package/lib/core/{HttpResponse-DlQEvD4q.d.ts → HttpResponse-BbwAqLE_.d.ts} +1 -1
  5. package/lib/core/HttpResponse.d.mts +1 -1
  6. package/lib/core/HttpResponse.d.ts +1 -1
  7. package/lib/core/HttpResponse.js.map +1 -1
  8. package/lib/core/HttpResponse.mjs.map +1 -1
  9. package/lib/core/SetupApi.d.mts +1 -1
  10. package/lib/core/SetupApi.d.ts +1 -1
  11. package/lib/core/getResponse.d.mts +1 -1
  12. package/lib/core/getResponse.d.ts +1 -1
  13. package/lib/core/graphql.d.mts +1 -1
  14. package/lib/core/graphql.d.ts +1 -1
  15. package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
  16. package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
  17. package/lib/core/handlers/HttpHandler.d.mts +1 -1
  18. package/lib/core/handlers/HttpHandler.d.ts +1 -1
  19. package/lib/core/handlers/RequestHandler.d.mts +1 -1
  20. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  21. package/lib/core/http.d.mts +1 -1
  22. package/lib/core/http.d.ts +1 -1
  23. package/lib/core/index.d.mts +1 -1
  24. package/lib/core/index.d.ts +1 -1
  25. package/lib/core/passthrough.d.mts +1 -1
  26. package/lib/core/passthrough.d.ts +1 -1
  27. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  28. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  29. package/lib/core/utils/cookieStore.d.mts +10 -2
  30. package/lib/core/utils/cookieStore.d.ts +10 -2
  31. package/lib/core/utils/cookieStore.js +49 -146
  32. package/lib/core/utils/cookieStore.js.map +1 -1
  33. package/lib/core/utils/cookieStore.mjs +53 -136
  34. package/lib/core/utils/cookieStore.mjs.map +1 -1
  35. package/lib/core/utils/executeHandlers.d.mts +1 -1
  36. package/lib/core/utils/executeHandlers.d.ts +1 -1
  37. package/lib/core/utils/handleRequest.d.mts +1 -1
  38. package/lib/core/utils/handleRequest.d.ts +1 -1
  39. package/lib/core/utils/handleRequest.js +1 -1
  40. package/lib/core/utils/handleRequest.js.map +1 -1
  41. package/lib/core/utils/handleRequest.mjs +1 -1
  42. package/lib/core/utils/handleRequest.mjs.map +1 -1
  43. package/lib/core/utils/internal/isHandlerKind.d.mts +1 -1
  44. package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
  45. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
  46. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
  47. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  48. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  49. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  50. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  51. package/lib/core/utils/request/getRequestCookies.js +1 -1
  52. package/lib/core/utils/request/getRequestCookies.js.map +1 -1
  53. package/lib/core/utils/request/getRequestCookies.mjs +1 -1
  54. package/lib/core/utils/request/getRequestCookies.mjs.map +1 -1
  55. package/lib/core/utils/request/storeResponseCookies.d.mts +1 -1
  56. package/lib/core/utils/request/storeResponseCookies.d.ts +1 -1
  57. package/lib/core/utils/request/storeResponseCookies.js +2 -2
  58. package/lib/core/utils/request/storeResponseCookies.js.map +1 -1
  59. package/lib/core/utils/request/storeResponseCookies.mjs +2 -2
  60. package/lib/core/utils/request/storeResponseCookies.mjs.map +1 -1
  61. package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
  62. package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
  63. package/lib/iife/index.js +2589 -12070
  64. package/lib/iife/index.js.map +1 -1
  65. package/lib/mockServiceWorker.js +1 -1
  66. package/lib/node/index.js.map +1 -1
  67. package/lib/node/index.mjs.map +1 -1
  68. package/package.json +4 -4
  69. package/src/browser/setupWorker/setupWorker.ts +1 -1
  70. package/src/core/HttpResponse.ts +3 -3
  71. package/src/core/handlers/GraphQLHandler.test.ts +1 -1
  72. package/src/core/utils/cookieStore.ts +56 -198
  73. package/src/core/utils/handleRequest.ts +1 -1
  74. package/src/core/utils/request/getRequestCookies.ts +1 -1
  75. package/src/core/utils/request/storeResponseCookies.ts +3 -3
  76. package/src/core/utils/request/toPublicUrl.test.ts +1 -1
  77. package/src/core/ws/WebSocketClientManager.test.ts +1 -1
  78. package/src/node/SetupServerApi.ts +1 -1
@@ -300,7 +300,7 @@ declare class HttpResponse<BodyType extends DefaultBodyType> extends FetchRespon
300
300
  *
301
301
  * HttpResponse.arrayBuffer(buffer)
302
302
  */
303
- static arrayBuffer(body?: ArrayBuffer | SharedArrayBuffer, init?: HttpResponseInit): HttpResponse<ArrayBuffer | SharedArrayBuffer>;
303
+ static arrayBuffer<BodyType extends ArrayBuffer | SharedArrayBuffer>(body?: BodyType, init?: HttpResponseInit): HttpResponse<BodyType>;
304
304
  /**
305
305
  * Create a `Response` with a `FormData` body.
306
306
  * @example
@@ -300,7 +300,7 @@ declare class HttpResponse<BodyType extends DefaultBodyType> extends FetchRespon
300
300
  *
301
301
  * HttpResponse.arrayBuffer(buffer)
302
302
  */
303
- static arrayBuffer(body?: ArrayBuffer | SharedArrayBuffer, init?: HttpResponseInit): HttpResponse<ArrayBuffer | SharedArrayBuffer>;
303
+ static arrayBuffer<BodyType extends ArrayBuffer | SharedArrayBuffer>(body?: BodyType, init?: HttpResponseInit): HttpResponse<BodyType>;
304
304
  /**
305
305
  * Create a `Response` with a `FormData` body.
306
306
  * @example
@@ -1,5 +1,5 @@
1
1
  import '@mswjs/interceptors';
2
- export { m as DefaultUnsafeFetchResponse, o as HttpResponse, H as HttpResponseInit, S as StrictRequest, n as StrictResponse, l as bodyType } from './HttpResponse-DiuKTgC7.mjs';
2
+ export { m as DefaultUnsafeFetchResponse, o as HttpResponse, H as HttpResponseInit, S as StrictRequest, n as StrictResponse, l as bodyType } from './HttpResponse-B4YmE-GJ.mjs';
3
3
  import './typeUtils.mjs';
4
4
  import './utils/internal/isIterable.mjs';
5
5
  import 'graphql';
@@ -1,5 +1,5 @@
1
1
  import '@mswjs/interceptors';
2
- export { m as DefaultUnsafeFetchResponse, o as HttpResponse, H as HttpResponseInit, S as StrictRequest, n as StrictResponse, l as bodyType } from './HttpResponse-DlQEvD4q.js';
2
+ export { m as DefaultUnsafeFetchResponse, o as HttpResponse, H as HttpResponseInit, S as StrictRequest, n as StrictResponse, l as bodyType } from './HttpResponse-BbwAqLE_.js';
3
3
  import './typeUtils.js';
4
4
  import './utils/internal/isIterable.js';
5
5
  import 'graphql';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/HttpResponse.ts"],"sourcesContent":["import { FetchResponse } from '@mswjs/interceptors'\nimport type { DefaultBodyType, JsonBodyType } from './handlers/RequestHandler'\nimport type { NoInfer } from './typeUtils'\nimport {\n decorateResponse,\n normalizeResponseInit,\n} from './utils/HttpResponse/decorators'\n\nexport interface HttpResponseInit extends ResponseInit {\n type?: ResponseType\n}\n\nexport const bodyType: unique symbol = Symbol('bodyType')\nexport type DefaultUnsafeFetchResponse = Response & {\n [bodyType]?: never\n}\n\nexport interface StrictRequest<BodyType extends JsonBodyType> extends Request {\n json(): Promise<BodyType>\n}\n\n/**\n * Opaque `Response` type that supports strict body type.\n *\n * @deprecated Please use {@link HttpResponse} instead.\n */\nexport type StrictResponse<BodyType extends DefaultBodyType> =\n HttpResponse<BodyType>\n\n/**\n * A drop-in replacement for the standard `Response` class\n * to allow additional features, like mocking the response `Set-Cookie` header.\n *\n * @example\n * new HttpResponse('Hello world', { status: 201 })\n * HttpResponse.json({ name: 'John' })\n * HttpResponse.formData(form)\n *\n * @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}\n */\nexport class HttpResponse<\n BodyType extends DefaultBodyType,\n> extends FetchResponse {\n readonly [bodyType]: BodyType = null as any\n\n constructor(body?: NoInfer<BodyType> | null, init?: HttpResponseInit) {\n const responseInit = normalizeResponseInit(init)\n super(body as BodyInit, responseInit)\n decorateResponse(this, responseInit)\n }\n\n static error(): HttpResponse<any> {\n return super.error() as HttpResponse<any>\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/plain\"` body.\n * @example\n * HttpResponse.text('hello world')\n * HttpResponse.text('Error', { status: 500 })\n */\n static text<BodyType extends string>(\n body?: NoInfer<BodyType> | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/plain')\n }\n\n // Automatically set the \"Content-Length\" response header\n // for non-empty text responses. This enforces consistency and\n // brings mocked responses closer to production.\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n body ? new Blob([body]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/json\"` body.\n * @example\n * HttpResponse.json({ firstName: 'John' })\n * HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })\n */\n static json<BodyType extends JsonBodyType>(\n body?: NoInfer<BodyType> | null | undefined,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'application/json')\n }\n\n /**\n * @note TypeScript is incorrect here.\n * Stringifying undefined will return undefined.\n */\n const responseText = JSON.stringify(body) as string | undefined\n\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n responseText ? new Blob([responseText]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(responseText as BodyType, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/xml\"` body.\n * @example\n * HttpResponse.xml(`<user name=\"John\" />`)\n * HttpResponse.xml(`<article id=\"abc-123\" />`, { status: 201 })\n */\n static xml<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/xml')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/html\"` body.\n * @example\n * HttpResponse.html(`<p class=\"author\">Jane Doe</p>`)\n * HttpResponse.html(`<main id=\"abc-123\">Main text</main>`, { status: 201 })\n */\n static html<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/html')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with an `ArrayBuffer` body.\n * @example\n * const buffer = new ArrayBuffer(3)\n * const view = new Uint8Array(buffer)\n * view.set([1, 2, 3])\n *\n * HttpResponse.arrayBuffer(buffer)\n */\n static arrayBuffer(\n body?: ArrayBuffer | SharedArrayBuffer,\n init?: HttpResponseInit,\n ): HttpResponse<ArrayBuffer | SharedArrayBuffer> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'application/octet-stream')\n }\n\n if (body && !responseInit.headers.has('Content-Length')) {\n responseInit.headers.set('Content-Length', body.byteLength.toString())\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `FormData` body.\n * @example\n * const data = new FormData()\n * data.set('name', 'Alice')\n *\n * HttpResponse.formData(data)\n */\n static formData(\n body?: FormData,\n init?: HttpResponseInit,\n ): HttpResponse<FormData> {\n return new HttpResponse(body, normalizeResponseInit(init))\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;A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,aAAa,cAA0B,YAAY;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,IACL,MACA,MACwB;AACxB,UAAM,mBAAe,yCAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,UAAU;AAAA,IACrD;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KACL,MACA,MACwB;AACxB,UAAM,mBAAe,yCAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,WAAW;AAAA,IACtD;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,OAAO,YACL,MACA,MAC+C;AAC/C,UAAM,mBAAe,yCAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,0BAA0B;AAAA,IACrE;AAEA,QAAI,QAAQ,CAAC,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AACvD,mBAAa,QAAQ,IAAI,kBAAkB,KAAK,WAAW,SAAS,CAAC;AAAA,IACvE;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,SACL,MACA,MACwB;AACxB,WAAO,IAAI,aAAa,UAAM,yCAAsB,IAAI,CAAC;AAAA,EAC3D;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/core/HttpResponse.ts"],"sourcesContent":["import { FetchResponse } from '@mswjs/interceptors'\nimport type { DefaultBodyType, JsonBodyType } from './handlers/RequestHandler'\nimport type { NoInfer } from './typeUtils'\nimport {\n decorateResponse,\n normalizeResponseInit,\n} from './utils/HttpResponse/decorators'\n\nexport interface HttpResponseInit extends ResponseInit {\n type?: ResponseType\n}\n\nexport const bodyType: unique symbol = Symbol('bodyType')\nexport type DefaultUnsafeFetchResponse = Response & {\n [bodyType]?: never\n}\n\nexport interface StrictRequest<BodyType extends JsonBodyType> extends Request {\n json(): Promise<BodyType>\n}\n\n/**\n * Opaque `Response` type that supports strict body type.\n *\n * @deprecated Please use {@link HttpResponse} instead.\n */\nexport type StrictResponse<BodyType extends DefaultBodyType> =\n HttpResponse<BodyType>\n\n/**\n * A drop-in replacement for the standard `Response` class\n * to allow additional features, like mocking the response `Set-Cookie` header.\n *\n * @example\n * new HttpResponse('Hello world', { status: 201 })\n * HttpResponse.json({ name: 'John' })\n * HttpResponse.formData(form)\n *\n * @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}\n */\nexport class HttpResponse<\n BodyType extends DefaultBodyType,\n> extends FetchResponse {\n readonly [bodyType]: BodyType = null as any\n\n constructor(body?: NoInfer<BodyType> | null, init?: HttpResponseInit) {\n const responseInit = normalizeResponseInit(init)\n super(body as BodyInit, responseInit)\n decorateResponse(this, responseInit)\n }\n\n static error(): HttpResponse<any> {\n return super.error() as HttpResponse<any>\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/plain\"` body.\n * @example\n * HttpResponse.text('hello world')\n * HttpResponse.text('Error', { status: 500 })\n */\n static text<BodyType extends string>(\n body?: NoInfer<BodyType> | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/plain')\n }\n\n // Automatically set the \"Content-Length\" response header\n // for non-empty text responses. This enforces consistency and\n // brings mocked responses closer to production.\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n body ? new Blob([body]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/json\"` body.\n * @example\n * HttpResponse.json({ firstName: 'John' })\n * HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })\n */\n static json<BodyType extends JsonBodyType>(\n body?: NoInfer<BodyType> | null | undefined,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'application/json')\n }\n\n /**\n * @note TypeScript is incorrect here.\n * Stringifying undefined will return undefined.\n */\n const responseText = JSON.stringify(body) as string | undefined\n\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n responseText ? new Blob([responseText]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(responseText as BodyType, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/xml\"` body.\n * @example\n * HttpResponse.xml(`<user name=\"John\" />`)\n * HttpResponse.xml(`<article id=\"abc-123\" />`, { status: 201 })\n */\n static xml<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/xml')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/html\"` body.\n * @example\n * HttpResponse.html(`<p class=\"author\">Jane Doe</p>`)\n * HttpResponse.html(`<main id=\"abc-123\">Main text</main>`, { status: 201 })\n */\n static html<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/html')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with an `ArrayBuffer` body.\n * @example\n * const buffer = new ArrayBuffer(3)\n * const view = new Uint8Array(buffer)\n * view.set([1, 2, 3])\n *\n * HttpResponse.arrayBuffer(buffer)\n */\n static arrayBuffer<BodyType extends ArrayBuffer | SharedArrayBuffer>(\n body?: BodyType,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'application/octet-stream')\n }\n\n if (body && !responseInit.headers.has('Content-Length')) {\n responseInit.headers.set('Content-Length', body.byteLength.toString())\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `FormData` body.\n * @example\n * const data = new FormData()\n * data.set('name', 'Alice')\n *\n * HttpResponse.formData(data)\n */\n static formData(\n body?: FormData,\n init?: HttpResponseInit,\n ): HttpResponse<FormData> {\n return new HttpResponse(body, normalizeResponseInit(init))\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA8B;AAG9B,wBAGO;AAMA,MAAM,WAA0B,OAAO,UAAU;AA4BjD,MAAM,qBAEH,kCAAc;AAAA,EACtB,CAAU,QAAQ,IAAc;AAAA,EAEhC,YAAY,MAAiC,MAAyB;AACpE,UAAM,mBAAe,yCAAsB,IAAI;AAC/C,UAAM,MAAkB,YAAY;AACpC,4CAAiB,MAAM,YAAY;AAAA,EACrC;AAAA,EAEA,OAAO,QAA2B;AAChC,WAAO,MAAM,MAAM;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KACL,MACA,MACwB;AACxB,UAAM,mBAAe,yCAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,YAAY;AAAA,IACvD;AAKA,QAAI,CAAC,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AAC/C,mBAAa,QAAQ;AAAA,QACnB;AAAA,QACA,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,yCAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,0BAA0B;AAAA,IACrE;AAEA,QAAI,QAAQ,CAAC,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AACvD,mBAAa,QAAQ,IAAI,kBAAkB,KAAK,WAAW,SAAS,CAAC;AAAA,IACvE;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,SACL,MACA,MACwB;AACxB,WAAO,IAAI,aAAa,UAAM,yCAAsB,IAAI,CAAC;AAAA,EAC3D;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/HttpResponse.ts"],"sourcesContent":["import { FetchResponse } from '@mswjs/interceptors'\nimport type { DefaultBodyType, JsonBodyType } from './handlers/RequestHandler'\nimport type { NoInfer } from './typeUtils'\nimport {\n decorateResponse,\n normalizeResponseInit,\n} from './utils/HttpResponse/decorators'\n\nexport interface HttpResponseInit extends ResponseInit {\n type?: ResponseType\n}\n\nexport const bodyType: unique symbol = Symbol('bodyType')\nexport type DefaultUnsafeFetchResponse = Response & {\n [bodyType]?: never\n}\n\nexport interface StrictRequest<BodyType extends JsonBodyType> extends Request {\n json(): Promise<BodyType>\n}\n\n/**\n * Opaque `Response` type that supports strict body type.\n *\n * @deprecated Please use {@link HttpResponse} instead.\n */\nexport type StrictResponse<BodyType extends DefaultBodyType> =\n HttpResponse<BodyType>\n\n/**\n * A drop-in replacement for the standard `Response` class\n * to allow additional features, like mocking the response `Set-Cookie` header.\n *\n * @example\n * new HttpResponse('Hello world', { status: 201 })\n * HttpResponse.json({ name: 'John' })\n * HttpResponse.formData(form)\n *\n * @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}\n */\nexport class HttpResponse<\n BodyType extends DefaultBodyType,\n> extends FetchResponse {\n readonly [bodyType]: BodyType = null as any\n\n constructor(body?: NoInfer<BodyType> | null, init?: HttpResponseInit) {\n const responseInit = normalizeResponseInit(init)\n super(body as BodyInit, responseInit)\n decorateResponse(this, responseInit)\n }\n\n static error(): HttpResponse<any> {\n return super.error() as HttpResponse<any>\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/plain\"` body.\n * @example\n * HttpResponse.text('hello world')\n * HttpResponse.text('Error', { status: 500 })\n */\n static text<BodyType extends string>(\n body?: NoInfer<BodyType> | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/plain')\n }\n\n // Automatically set the \"Content-Length\" response header\n // for non-empty text responses. This enforces consistency and\n // brings mocked responses closer to production.\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n body ? new Blob([body]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/json\"` body.\n * @example\n * HttpResponse.json({ firstName: 'John' })\n * HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })\n */\n static json<BodyType extends JsonBodyType>(\n body?: NoInfer<BodyType> | null | undefined,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'application/json')\n }\n\n /**\n * @note TypeScript is incorrect here.\n * Stringifying undefined will return undefined.\n */\n const responseText = JSON.stringify(body) as string | undefined\n\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n responseText ? new Blob([responseText]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(responseText as BodyType, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/xml\"` body.\n * @example\n * HttpResponse.xml(`<user name=\"John\" />`)\n * HttpResponse.xml(`<article id=\"abc-123\" />`, { status: 201 })\n */\n static xml<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/xml')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/html\"` body.\n * @example\n * HttpResponse.html(`<p class=\"author\">Jane Doe</p>`)\n * HttpResponse.html(`<main id=\"abc-123\">Main text</main>`, { status: 201 })\n */\n static html<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/html')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with an `ArrayBuffer` body.\n * @example\n * const buffer = new ArrayBuffer(3)\n * const view = new Uint8Array(buffer)\n * view.set([1, 2, 3])\n *\n * HttpResponse.arrayBuffer(buffer)\n */\n static arrayBuffer(\n body?: ArrayBuffer | SharedArrayBuffer,\n init?: HttpResponseInit,\n ): HttpResponse<ArrayBuffer | SharedArrayBuffer> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'application/octet-stream')\n }\n\n if (body && !responseInit.headers.has('Content-Length')) {\n responseInit.headers.set('Content-Length', body.byteLength.toString())\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `FormData` body.\n * @example\n * const data = new FormData()\n * data.set('name', 'Alice')\n *\n * HttpResponse.formData(data)\n */\n static formData(\n body?: FormData,\n init?: HttpResponseInit,\n ): HttpResponse<FormData> {\n return new HttpResponse(body, normalizeResponseInit(init))\n }\n}\n"],"mappings":"AAAA,SAAS,qBAAqB;AAG9B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAMA,MAAM,WAA0B,OA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,MACA,MACwB;AACxB,UAAM,eAAe,sBAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,UAAU;AAAA,IACrD;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KACL,MACA,MACwB;AACxB,UAAM,eAAe,sBAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,WAAW;AAAA,IACtD;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,OAAO,YACL,MACA,MAC+C;AAC/C,UAAM,eAAe,sBAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,0BAA0B;AAAA,IACrE;AAEA,QAAI,QAAQ,CAAC,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AACvD,mBAAa,QAAQ,IAAI,kBAAkB,KAAK,WAAW,SAAS,CAAC;AAAA,IACvE;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,SACL,MACA,MACwB;AACxB,WAAO,IAAI,aAAa,MAAM,sBAAsB,IAAI,CAAC;AAAA,EAC3D;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/core/HttpResponse.ts"],"sourcesContent":["import { FetchResponse } from '@mswjs/interceptors'\nimport type { DefaultBodyType, JsonBodyType } from './handlers/RequestHandler'\nimport type { NoInfer } from './typeUtils'\nimport {\n decorateResponse,\n normalizeResponseInit,\n} from './utils/HttpResponse/decorators'\n\nexport interface HttpResponseInit extends ResponseInit {\n type?: ResponseType\n}\n\nexport const bodyType: unique symbol = Symbol('bodyType')\nexport type DefaultUnsafeFetchResponse = Response & {\n [bodyType]?: never\n}\n\nexport interface StrictRequest<BodyType extends JsonBodyType> extends Request {\n json(): Promise<BodyType>\n}\n\n/**\n * Opaque `Response` type that supports strict body type.\n *\n * @deprecated Please use {@link HttpResponse} instead.\n */\nexport type StrictResponse<BodyType extends DefaultBodyType> =\n HttpResponse<BodyType>\n\n/**\n * A drop-in replacement for the standard `Response` class\n * to allow additional features, like mocking the response `Set-Cookie` header.\n *\n * @example\n * new HttpResponse('Hello world', { status: 201 })\n * HttpResponse.json({ name: 'John' })\n * HttpResponse.formData(form)\n *\n * @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}\n */\nexport class HttpResponse<\n BodyType extends DefaultBodyType,\n> extends FetchResponse {\n readonly [bodyType]: BodyType = null as any\n\n constructor(body?: NoInfer<BodyType> | null, init?: HttpResponseInit) {\n const responseInit = normalizeResponseInit(init)\n super(body as BodyInit, responseInit)\n decorateResponse(this, responseInit)\n }\n\n static error(): HttpResponse<any> {\n return super.error() as HttpResponse<any>\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/plain\"` body.\n * @example\n * HttpResponse.text('hello world')\n * HttpResponse.text('Error', { status: 500 })\n */\n static text<BodyType extends string>(\n body?: NoInfer<BodyType> | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/plain')\n }\n\n // Automatically set the \"Content-Length\" response header\n // for non-empty text responses. This enforces consistency and\n // brings mocked responses closer to production.\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n body ? new Blob([body]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/json\"` body.\n * @example\n * HttpResponse.json({ firstName: 'John' })\n * HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })\n */\n static json<BodyType extends JsonBodyType>(\n body?: NoInfer<BodyType> | null | undefined,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'application/json')\n }\n\n /**\n * @note TypeScript is incorrect here.\n * Stringifying undefined will return undefined.\n */\n const responseText = JSON.stringify(body) as string | undefined\n\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n responseText ? new Blob([responseText]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(responseText as BodyType, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/xml\"` body.\n * @example\n * HttpResponse.xml(`<user name=\"John\" />`)\n * HttpResponse.xml(`<article id=\"abc-123\" />`, { status: 201 })\n */\n static xml<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/xml')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/html\"` body.\n * @example\n * HttpResponse.html(`<p class=\"author\">Jane Doe</p>`)\n * HttpResponse.html(`<main id=\"abc-123\">Main text</main>`, { status: 201 })\n */\n static html<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/html')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with an `ArrayBuffer` body.\n * @example\n * const buffer = new ArrayBuffer(3)\n * const view = new Uint8Array(buffer)\n * view.set([1, 2, 3])\n *\n * HttpResponse.arrayBuffer(buffer)\n */\n static arrayBuffer<BodyType extends ArrayBuffer | SharedArrayBuffer>(\n body?: BodyType,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'application/octet-stream')\n }\n\n if (body && !responseInit.headers.has('Content-Length')) {\n responseInit.headers.set('Content-Length', body.byteLength.toString())\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `FormData` body.\n * @example\n * const data = new FormData()\n * data.set('name', 'Alice')\n *\n * HttpResponse.formData(data)\n */\n static formData(\n body?: FormData,\n init?: HttpResponseInit,\n ): HttpResponse<FormData> {\n return new HttpResponse(body, normalizeResponseInit(init))\n }\n}\n"],"mappings":"AAAA,SAAS,qBAAqB;AAG9B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAMA,MAAM,WAA0B,OAAO,UAAU;AA4BjD,MAAM,qBAEH,cAAc;AAAA,EACtB,CAAU,QAAQ,IAAc;AAAA,EAEhC,YAAY,MAAiC,MAAyB;AACpE,UAAM,eAAe,sBAAsB,IAAI;AAC/C,UAAM,MAAkB,YAAY;AACpC,qBAAiB,MAAM,YAAY;AAAA,EACrC;AAAA,EAEA,OAAO,QAA2B;AAChC,WAAO,MAAM,MAAM;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KACL,MACA,MACwB;AACxB,UAAM,eAAe,sBAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,YAAY;AAAA,IACvD;AAKA,QAAI,CAAC,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AAC/C,mBAAa,QAAQ;AAAA,QACnB;AAAA,QACA,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,SAAS,IAAI;AAAA,MAC5C;AAAA,IACF;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AA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,QAAI,QAAQ,CAAC,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AACvD,mBAAa,QAAQ,IAAI,kBAAkB,KAAK,WAAW,SAAS,CAAC;AAAA,IACvE;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,SACL,MACA,MACwB;AACxB,WAAO,IAAI,aAAa,MAAM,sBAAsB,IAAI,CAAC;AAAA,EAC3D;AACF;","names":[]}
@@ -1,5 +1,5 @@
1
1
  import { EventMap, Emitter } from 'strict-event-emitter';
2
- import { R as RequestHandler } from './HttpResponse-DiuKTgC7.mjs';
2
+ import { R as RequestHandler } from './HttpResponse-B4YmE-GJ.mjs';
3
3
  import { LifeCycleEventEmitter } from './sharedOptions.mjs';
4
4
  import { Disposable } from './utils/internal/Disposable.mjs';
5
5
  import { WebSocketHandler } from './handlers/WebSocketHandler.mjs';
@@ -1,5 +1,5 @@
1
1
  import { EventMap, Emitter } from 'strict-event-emitter';
2
- import { R as RequestHandler } from './HttpResponse-DlQEvD4q.js';
2
+ import { R as RequestHandler } from './HttpResponse-BbwAqLE_.js';
3
3
  import { LifeCycleEventEmitter } from './sharedOptions.js';
4
4
  import { Disposable } from './utils/internal/Disposable.js';
5
5
  import { WebSocketHandler } from './handlers/WebSocketHandler.js';
@@ -1,4 +1,4 @@
1
- import { R as RequestHandler, p as ResponseResolutionContext } from './HttpResponse-DiuKTgC7.mjs';
1
+ import { R as RequestHandler, p as ResponseResolutionContext } from './HttpResponse-B4YmE-GJ.mjs';
2
2
  import '@mswjs/interceptors';
3
3
  import './utils/internal/isIterable.mjs';
4
4
  import './typeUtils.mjs';
@@ -1,4 +1,4 @@
1
- import { R as RequestHandler, p as ResponseResolutionContext } from './HttpResponse-DlQEvD4q.js';
1
+ import { R as RequestHandler, p as ResponseResolutionContext } from './HttpResponse-BbwAqLE_.js';
2
2
  import '@mswjs/interceptors';
3
3
  import './utils/internal/isIterable.js';
4
4
  import './typeUtils.js';
@@ -1,5 +1,5 @@
1
1
  import { DocumentNode } from 'graphql';
2
- import { e as GraphQLQuery, f as GraphQLVariables, q as GraphQLHandlerNameSelector, k as GraphQLCustomPredicate, a as ResponseResolver, r as GraphQLResolverExtras, h as GraphQLResponseBody, c as RequestHandlerOptions, G as GraphQLHandler } from './HttpResponse-DiuKTgC7.mjs';
2
+ import { e as GraphQLQuery, f as GraphQLVariables, q as GraphQLHandlerNameSelector, k as GraphQLCustomPredicate, a as ResponseResolver, r as GraphQLResolverExtras, h as GraphQLResponseBody, c as RequestHandlerOptions, G as GraphQLHandler } from './HttpResponse-B4YmE-GJ.mjs';
3
3
  import { Path } from './utils/matching/matchRequestUrl.mjs';
4
4
  import '@mswjs/interceptors';
5
5
  import './utils/internal/isIterable.mjs';
@@ -1,5 +1,5 @@
1
1
  import { DocumentNode } from 'graphql';
2
- import { e as GraphQLQuery, f as GraphQLVariables, q as GraphQLHandlerNameSelector, k as GraphQLCustomPredicate, a as ResponseResolver, r as GraphQLResolverExtras, h as GraphQLResponseBody, c as RequestHandlerOptions, G as GraphQLHandler } from './HttpResponse-DlQEvD4q.js';
2
+ import { e as GraphQLQuery, f as GraphQLVariables, q as GraphQLHandlerNameSelector, k as GraphQLCustomPredicate, a as ResponseResolver, r as GraphQLResolverExtras, h as GraphQLResponseBody, c as RequestHandlerOptions, G as GraphQLHandler } from './HttpResponse-BbwAqLE_.js';
3
3
  import { Path } from './utils/matching/matchRequestUrl.js';
4
4
  import '@mswjs/interceptors';
5
5
  import './utils/internal/isIterable.js';
@@ -1,5 +1,5 @@
1
1
  import 'graphql';
2
- export { k as GraphQLCustomPredicate, E as GraphQLCustomPredicateResult, G as GraphQLHandler, B as GraphQLHandlerInfo, q as GraphQLHandlerNameSelector, i as GraphQLJsonRequestBody, j as GraphQLOperationType, F as GraphQLPredicate, e as GraphQLQuery, g as GraphQLRequestBody, C as GraphQLRequestParsedResult, r as GraphQLResolverExtras, h as GraphQLResponseBody, f as GraphQLVariables, I as isDocumentNode } from '../HttpResponse-DiuKTgC7.mjs';
2
+ export { k as GraphQLCustomPredicate, E as GraphQLCustomPredicateResult, G as GraphQLHandler, B as GraphQLHandlerInfo, q as GraphQLHandlerNameSelector, i as GraphQLJsonRequestBody, j as GraphQLOperationType, F as GraphQLPredicate, e as GraphQLQuery, g as GraphQLRequestBody, C as GraphQLRequestParsedResult, r as GraphQLResolverExtras, h as GraphQLResponseBody, f as GraphQLVariables, I as isDocumentNode } from '../HttpResponse-B4YmE-GJ.mjs';
3
3
  import '../utils/matching/matchRequestUrl.mjs';
4
4
  import '@mswjs/interceptors';
5
5
  import '../utils/internal/isIterable.mjs';
@@ -1,5 +1,5 @@
1
1
  import 'graphql';
2
- export { k as GraphQLCustomPredicate, E as GraphQLCustomPredicateResult, G as GraphQLHandler, B as GraphQLHandlerInfo, q as GraphQLHandlerNameSelector, i as GraphQLJsonRequestBody, j as GraphQLOperationType, F as GraphQLPredicate, e as GraphQLQuery, g as GraphQLRequestBody, C as GraphQLRequestParsedResult, r as GraphQLResolverExtras, h as GraphQLResponseBody, f as GraphQLVariables, I as isDocumentNode } from '../HttpResponse-DlQEvD4q.js';
2
+ export { k as GraphQLCustomPredicate, E as GraphQLCustomPredicateResult, G as GraphQLHandler, B as GraphQLHandlerInfo, q as GraphQLHandlerNameSelector, i as GraphQLJsonRequestBody, j as GraphQLOperationType, F as GraphQLPredicate, e as GraphQLQuery, g as GraphQLRequestBody, C as GraphQLRequestParsedResult, r as GraphQLResolverExtras, h as GraphQLResponseBody, f as GraphQLVariables, I as isDocumentNode } from '../HttpResponse-BbwAqLE_.js';
3
3
  import '../utils/matching/matchRequestUrl.js';
4
4
  import '@mswjs/interceptors';
5
5
  import '../utils/internal/isIterable.js';
@@ -1,4 +1,4 @@
1
- import { R as RequestHandler, s as RequestHandlerDefaultInfo, a as ResponseResolver, c as RequestHandlerOptions, p as ResponseResolutionContext } from '../HttpResponse-DiuKTgC7.mjs';
1
+ import { R as RequestHandler, s as RequestHandlerDefaultInfo, a as ResponseResolver, c as RequestHandlerOptions, p as ResponseResolutionContext } from '../HttpResponse-B4YmE-GJ.mjs';
2
2
  import { PathParams, Path, Match } from '../utils/matching/matchRequestUrl.mjs';
3
3
  import '@mswjs/interceptors';
4
4
  import '../utils/internal/isIterable.mjs';
@@ -1,4 +1,4 @@
1
- import { R as RequestHandler, s as RequestHandlerDefaultInfo, a as ResponseResolver, c as RequestHandlerOptions, p as ResponseResolutionContext } from '../HttpResponse-DlQEvD4q.js';
1
+ import { R as RequestHandler, s as RequestHandlerDefaultInfo, a as ResponseResolver, c as RequestHandlerOptions, p as ResponseResolutionContext } from '../HttpResponse-BbwAqLE_.js';
2
2
  import { PathParams, Path, Match } from '../utils/matching/matchRequestUrl.js';
3
3
  import '@mswjs/interceptors';
4
4
  import '../utils/internal/isIterable.js';
@@ -1,5 +1,5 @@
1
1
  import '../utils/internal/isIterable.mjs';
2
- export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, J as JsonBodyType, M as MaybeAsyncResponseResolverReturnType, R as RequestHandler, N as RequestHandlerArgs, s as RequestHandlerDefaultInfo, O as RequestHandlerExecutionResult, K as RequestHandlerInternalInfo, c as RequestHandlerOptions, a as ResponseResolver, L as ResponseResolverInfo, b as ResponseResolverReturnType } from '../HttpResponse-DiuKTgC7.mjs';
2
+ export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, J as JsonBodyType, M as MaybeAsyncResponseResolverReturnType, R as RequestHandler, N as RequestHandlerArgs, s as RequestHandlerDefaultInfo, O as RequestHandlerExecutionResult, K as RequestHandlerInternalInfo, c as RequestHandlerOptions, a as ResponseResolver, L as ResponseResolverInfo, b as ResponseResolverReturnType } from '../HttpResponse-B4YmE-GJ.mjs';
3
3
  import '../typeUtils.mjs';
4
4
  import '@mswjs/interceptors';
5
5
  import 'graphql';
@@ -1,5 +1,5 @@
1
1
  import '../utils/internal/isIterable.js';
2
- export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, J as JsonBodyType, M as MaybeAsyncResponseResolverReturnType, R as RequestHandler, N as RequestHandlerArgs, s as RequestHandlerDefaultInfo, O as RequestHandlerExecutionResult, K as RequestHandlerInternalInfo, c as RequestHandlerOptions, a as ResponseResolver, L as ResponseResolverInfo, b as ResponseResolverReturnType } from '../HttpResponse-DlQEvD4q.js';
2
+ export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, J as JsonBodyType, M as MaybeAsyncResponseResolverReturnType, R as RequestHandler, N as RequestHandlerArgs, s as RequestHandlerDefaultInfo, O as RequestHandlerExecutionResult, K as RequestHandlerInternalInfo, c as RequestHandlerOptions, a as ResponseResolver, L as ResponseResolverInfo, b as ResponseResolverReturnType } from '../HttpResponse-BbwAqLE_.js';
3
3
  import '../typeUtils.js';
4
4
  import '@mswjs/interceptors';
5
5
  import 'graphql';
@@ -1,4 +1,4 @@
1
- import { D as DefaultBodyType, a as ResponseResolver, c as RequestHandlerOptions } from './HttpResponse-DiuKTgC7.mjs';
1
+ import { D as DefaultBodyType, a as ResponseResolver, c as RequestHandlerOptions } from './HttpResponse-B4YmE-GJ.mjs';
2
2
  import { HttpRequestPredicate, HttpRequestResolverExtras, HttpHandler } from './handlers/HttpHandler.mjs';
3
3
  import { PathParams } from './utils/matching/matchRequestUrl.mjs';
4
4
  import '@mswjs/interceptors';
@@ -1,4 +1,4 @@
1
- import { D as DefaultBodyType, a as ResponseResolver, c as RequestHandlerOptions } from './HttpResponse-DlQEvD4q.js';
1
+ import { D as DefaultBodyType, a as ResponseResolver, c as RequestHandlerOptions } from './HttpResponse-BbwAqLE_.js';
2
2
  import { HttpRequestPredicate, HttpRequestResolverExtras, HttpHandler } from './handlers/HttpHandler.js';
3
3
  import { PathParams } from './utils/matching/matchRequestUrl.js';
4
4
  import '@mswjs/interceptors';
@@ -1,5 +1,5 @@
1
1
  export { SetupApi } from './SetupApi.mjs';
2
- export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, m as DefaultUnsafeFetchResponse, k as GraphQLCustomPredicate, G as GraphQLHandler, i as GraphQLJsonRequestBody, j as GraphQLOperationType, e as GraphQLQuery, g as GraphQLRequestBody, h as GraphQLResponseBody, f as GraphQLVariables, o as HttpResponse, H as HttpResponseInit, J as JsonBodyType, P as ParsedGraphQLRequest, R as RequestHandler, c as RequestHandlerOptions, a as ResponseResolver, b as ResponseResolverReturnType, S as StrictRequest, n as StrictResponse, l as bodyType } from './HttpResponse-DiuKTgC7.mjs';
2
+ export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, m as DefaultUnsafeFetchResponse, k as GraphQLCustomPredicate, G as GraphQLHandler, i as GraphQLJsonRequestBody, j as GraphQLOperationType, e as GraphQLQuery, g as GraphQLRequestBody, h as GraphQLResponseBody, f as GraphQLVariables, o as HttpResponse, H as HttpResponseInit, J as JsonBodyType, P as ParsedGraphQLRequest, R as RequestHandler, c as RequestHandlerOptions, a as ResponseResolver, b as ResponseResolverReturnType, S as StrictRequest, n as StrictResponse, l as bodyType } from './HttpResponse-B4YmE-GJ.mjs';
3
3
  export { HttpRequestHandler, HttpResponseResolver, http } from './http.mjs';
4
4
  export { HttpCustomPredicate, HttpHandler, HttpMethods, HttpRequestParsedResult, RequestQuery } from './handlers/HttpHandler.mjs';
5
5
  export { GraphQLRequestHandler, GraphQLResponseResolver, graphql } from './graphql.mjs';
@@ -1,5 +1,5 @@
1
1
  export { SetupApi } from './SetupApi.js';
2
- export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, m as DefaultUnsafeFetchResponse, k as GraphQLCustomPredicate, G as GraphQLHandler, i as GraphQLJsonRequestBody, j as GraphQLOperationType, e as GraphQLQuery, g as GraphQLRequestBody, h as GraphQLResponseBody, f as GraphQLVariables, o as HttpResponse, H as HttpResponseInit, J as JsonBodyType, P as ParsedGraphQLRequest, R as RequestHandler, c as RequestHandlerOptions, a as ResponseResolver, b as ResponseResolverReturnType, S as StrictRequest, n as StrictResponse, l as bodyType } from './HttpResponse-DlQEvD4q.js';
2
+ export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, m as DefaultUnsafeFetchResponse, k as GraphQLCustomPredicate, G as GraphQLHandler, i as GraphQLJsonRequestBody, j as GraphQLOperationType, e as GraphQLQuery, g as GraphQLRequestBody, h as GraphQLResponseBody, f as GraphQLVariables, o as HttpResponse, H as HttpResponseInit, J as JsonBodyType, P as ParsedGraphQLRequest, R as RequestHandler, c as RequestHandlerOptions, a as ResponseResolver, b as ResponseResolverReturnType, S as StrictRequest, n as StrictResponse, l as bodyType } from './HttpResponse-BbwAqLE_.js';
3
3
  export { HttpRequestHandler, HttpResponseResolver, http } from './http.js';
4
4
  export { HttpCustomPredicate, HttpHandler, HttpMethods, HttpRequestParsedResult, RequestQuery } from './handlers/HttpHandler.js';
5
5
  export { GraphQLRequestHandler, GraphQLResponseResolver, graphql } from './graphql.js';
@@ -1,4 +1,4 @@
1
- import { o as HttpResponse } from './HttpResponse-DiuKTgC7.mjs';
1
+ import { o as HttpResponse } from './HttpResponse-B4YmE-GJ.mjs';
2
2
  import '@mswjs/interceptors';
3
3
  import './utils/internal/isIterable.mjs';
4
4
  import './typeUtils.mjs';
@@ -1,4 +1,4 @@
1
- import { o as HttpResponse } from './HttpResponse-DlQEvD4q.js';
1
+ import { o as HttpResponse } from './HttpResponse-BbwAqLE_.js';
2
2
  import '@mswjs/interceptors';
3
3
  import './utils/internal/isIterable.js';
4
4
  import './typeUtils.js';
@@ -1,4 +1,4 @@
1
- import { H as HttpResponseInit } from '../../HttpResponse-DiuKTgC7.mjs';
1
+ import { H as HttpResponseInit } from '../../HttpResponse-B4YmE-GJ.mjs';
2
2
  import '@mswjs/interceptors';
3
3
  import '../internal/isIterable.mjs';
4
4
  import '../../typeUtils.mjs';
@@ -1,4 +1,4 @@
1
- import { H as HttpResponseInit } from '../../HttpResponse-DlQEvD4q.js';
1
+ import { H as HttpResponseInit } from '../../HttpResponse-BbwAqLE_.js';
2
2
  import '@mswjs/interceptors';
3
3
  import '../internal/isIterable.js';
4
4
  import '../../typeUtils.js';
@@ -1,5 +1,13 @@
1
- import toughCookie from '@bundled-es-modules/tough-cookie';
1
+ import { Cookie } from 'tough-cookie';
2
2
 
3
- declare const cookieStore: toughCookie.CookieJar;
3
+ declare class CookieStore {
4
+ #private;
5
+ constructor();
6
+ getCookies(url: string): Array<Cookie>;
7
+ setCookie(cookieName: string, url: string): Promise<void>;
8
+ private getCookieStoreIndex;
9
+ private persist;
10
+ }
11
+ declare const cookieStore: CookieStore;
4
12
 
5
13
  export { cookieStore };
@@ -1,5 +1,13 @@
1
- import toughCookie from '@bundled-es-modules/tough-cookie';
1
+ import { Cookie } from 'tough-cookie';
2
2
 
3
- declare const cookieStore: toughCookie.CookieJar;
3
+ declare class CookieStore {
4
+ #private;
5
+ constructor();
6
+ getCookies(url: string): Array<Cookie>;
7
+ setCookie(cookieName: string, url: string): Promise<void>;
8
+ private getCookieStoreIndex;
9
+ private persist;
10
+ }
11
+ declare const cookieStore: CookieStore;
4
12
 
5
13
  export { cookieStore };
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,171 +15,76 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var cookieStore_exports = {};
30
20
  __export(cookieStore_exports, {
31
21
  cookieStore: () => cookieStore
32
22
  });
33
23
  module.exports = __toCommonJS(cookieStore_exports);
34
- var import_outvariant = require("outvariant");
35
24
  var import_is_node_process = require("is-node-process");
36
- var import_tough_cookie = __toESM(require("@bundled-es-modules/tough-cookie"), 1);
37
- const { Cookie, CookieJar, Store, MemoryCookieStore, domainMatch, pathMatch } = import_tough_cookie.default;
38
- class WebStorageCookieStore extends Store {
39
- storage;
40
- storageKey;
25
+ var import_outvariant = require("outvariant");
26
+ var import_tough_cookie = require("tough-cookie");
27
+ var import_jsonParse = require("./internal/jsonParse");
28
+ class CookieStore {
29
+ #storageKey = "__msw-cookie-store__";
30
+ #jar;
31
+ #memoryStore;
41
32
  constructor() {
42
- super();
43
- (0, import_outvariant.invariant)(
44
- typeof localStorage !== "undefined",
45
- "Failed to create a WebStorageCookieStore: `localStorage` is not available in this environment. This is likely an issue with MSW. Please report it on GitHub: https://github.com/mswjs/msw/issues"
46
- );
47
- this.synchronous = true;
48
- this.storage = localStorage;
49
- this.storageKey = "__msw-cookie-store__";
50
- }
51
- findCookie(domain, path, key, callback) {
52
- try {
53
- const store2 = this.getStore();
54
- const cookies = this.filterCookiesFromList(store2, { domain, path, key });
55
- callback(null, cookies[0] || null);
56
- } catch (error) {
57
- if (error instanceof Error) {
58
- callback(error, null);
59
- }
33
+ if (!(0, import_is_node_process.isNodeProcess)()) {
34
+ (0, import_outvariant.invariant)(
35
+ typeof localStorage !== "undefined",
36
+ "Failed to create a CookieStore: `localStorage` is not available in this environment. This is likely an issue with your environment, which has been detected as browser (or browser-like) environment and must implement global browser APIs correctly."
37
+ );
60
38
  }
39
+ this.#memoryStore = new import_tough_cookie.MemoryCookieStore();
40
+ this.#memoryStore.idx = this.getCookieStoreIndex();
41
+ this.#jar = new import_tough_cookie.CookieJar(this.#memoryStore);
61
42
  }
62
- findCookies(domain, path, allowSpecialUseDomain, callback) {
63
- if (!domain) {
64
- callback(null, []);
65
- return;
66
- }
67
- try {
68
- const store2 = this.getStore();
69
- const results = this.filterCookiesFromList(store2, {
70
- domain,
71
- path
72
- });
73
- callback(null, results);
74
- } catch (error) {
75
- if (error instanceof Error) {
76
- callback(error, []);
77
- }
78
- }
43
+ getCookies(url) {
44
+ return this.#jar.getCookiesSync(url);
79
45
  }
80
- putCookie(cookie, callback) {
81
- try {
82
- if (cookie.maxAge === 0) {
83
- return;
84
- }
85
- const store2 = this.getStore();
86
- store2.push(cookie);
87
- this.updateStore(store2);
88
- } catch (error) {
89
- if (error instanceof Error) {
90
- callback(error);
91
- }
92
- }
46
+ async setCookie(cookieName, url) {
47
+ await this.#jar.setCookie(cookieName, url);
48
+ this.persist();
93
49
  }
94
- updateCookie(oldCookie, newCookie, callback) {
95
- if (newCookie.maxAge === 0) {
96
- this.removeCookie(
97
- newCookie.domain || "",
98
- newCookie.path || "",
99
- newCookie.key,
100
- callback
101
- );
102
- return;
50
+ getCookieStoreIndex() {
51
+ if (typeof localStorage === "undefined") {
52
+ return {};
103
53
  }
104
- this.putCookie(newCookie, callback);
105
- }
106
- removeCookie(domain, path, key, callback) {
107
- try {
108
- const store2 = this.getStore();
109
- const nextStore = this.deleteCookiesFromList(store2, { domain, path, key });
110
- this.updateStore(nextStore);
111
- callback(null);
112
- } catch (error) {
113
- if (error instanceof Error) {
114
- callback(error);
115
- }
54
+ const cookiesString = localStorage.getItem(this.#storageKey);
55
+ if (cookiesString == null) {
56
+ return {};
116
57
  }
117
- }
118
- removeCookies(domain, path, callback) {
119
- try {
120
- const store2 = this.getStore();
121
- const nextStore = this.deleteCookiesFromList(store2, { domain, path });
122
- this.updateStore(nextStore);
123
- callback(null);
124
- } catch (error) {
125
- if (error instanceof Error) {
126
- callback(error);
127
- }
58
+ const rawCookies = (0, import_jsonParse.jsonParse)(cookiesString);
59
+ if (rawCookies == null) {
60
+ return {};
128
61
  }
129
- }
130
- getAllCookies(callback) {
131
- try {
132
- callback(null, this.getStore());
133
- } catch (error) {
134
- if (error instanceof Error) {
135
- callback(error, []);
62
+ const cookies = {};
63
+ for (const rawCookie of rawCookies) {
64
+ const cookie = import_tough_cookie.Cookie.fromJSON(rawCookie);
65
+ if (cookie != null && cookie.domain != null && cookie.path != null) {
66
+ cookies[cookie.domain] ||= {};
67
+ cookies[cookie.domain][cookie.path] ||= {};
68
+ cookies[cookie.domain][cookie.path][cookie.key] = cookie;
136
69
  }
137
70
  }
71
+ return cookies;
138
72
  }
139
- getStore() {
140
- try {
141
- const json = this.storage.getItem(this.storageKey);
142
- if (json == null) {
143
- return [];
144
- }
145
- const rawCookies = JSON.parse(json);
146
- const cookies = [];
147
- for (const rawCookie of rawCookies) {
148
- const cookie = Cookie.fromJSON(rawCookie);
149
- if (cookie != null) {
150
- cookies.push(cookie);
151
- }
152
- }
153
- return cookies;
154
- } catch {
155
- return [];
73
+ persist() {
74
+ if (typeof localStorage === "undefined") {
75
+ return;
156
76
  }
157
- }
158
- updateStore(nextStore) {
159
- this.storage.setItem(
160
- this.storageKey,
161
- JSON.stringify(nextStore.map((cookie) => cookie.toJSON()))
162
- );
163
- }
164
- filterCookiesFromList(cookies, matches) {
165
- const result = [];
166
- for (const cookie of cookies) {
167
- if (matches.domain && !domainMatch(matches.domain, cookie.domain || "")) {
168
- continue;
169
- }
170
- if (matches.path && !pathMatch(matches.path, cookie.path || "")) {
171
- continue;
172
- }
173
- if (matches.key && cookie.key !== matches.key) {
174
- continue;
77
+ const data = [];
78
+ const { idx } = this.#memoryStore;
79
+ for (const domain in idx) {
80
+ for (const path in idx[domain]) {
81
+ for (const key in idx[domain][path]) {
82
+ data.push(idx[domain][path][key].toJSON());
83
+ }
175
84
  }
176
- result.push(cookie);
177
85
  }
178
- return result;
179
- }
180
- deleteCookiesFromList(cookies, matches) {
181
- const matchingCookies = this.filterCookiesFromList(cookies, matches);
182
- return cookies.filter((cookie) => !matchingCookies.includes(cookie));
86
+ localStorage.setItem(this.#storageKey, JSON.stringify(data));
183
87
  }
184
88
  }
185
- const store = (0, import_is_node_process.isNodeProcess)() ? new MemoryCookieStore() : new WebStorageCookieStore();
186
- const cookieStore = new CookieJar(store);
89
+ const cookieStore = new CookieStore();
187
90
  //# sourceMappingURL=cookieStore.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/utils/cookieStore.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { isNodeProcess } from 'is-node-process'\nimport toughCookie, {\n type Cookie as CookieInstance,\n} from '@bundled-es-modules/tough-cookie'\n\nconst { Cookie, CookieJar, Store, MemoryCookieStore, domainMatch, pathMatch } =\n toughCookie\n\n/**\n * Custom cookie store that uses the Web Storage API.\n * @see https://github.com/expo/tough-cookie-web-storage-store\n */\nclass WebStorageCookieStore extends Store {\n private storage: Storage\n private storageKey: string\n\n constructor() {\n super()\n\n invariant(\n typeof localStorage !== 'undefined',\n 'Failed to create a WebStorageCookieStore: `localStorage` is not available in this environment. This is likely an issue with MSW. Please report it on GitHub: https://github.com/mswjs/msw/issues',\n )\n\n this.synchronous = true\n this.storage = localStorage\n this.storageKey = '__msw-cookie-store__'\n }\n\n findCookie(\n domain: string,\n path: string,\n key: string,\n callback: (error: Error | null, cookie: CookieInstance | null) => void,\n ): void {\n try {\n const store = this.getStore()\n const cookies = this.filterCookiesFromList(store, { domain, path, key })\n callback(null, cookies[0] || null)\n } catch (error) {\n if (error instanceof Error) {\n callback(error, null)\n }\n }\n }\n\n findCookies(\n domain: string,\n path: string,\n allowSpecialUseDomain: boolean,\n callback: (error: Error | null, cookie: Array<CookieInstance>) => void,\n ): void {\n if (!domain) {\n callback(null, [])\n return\n }\n\n try {\n const store = this.getStore()\n const results = this.filterCookiesFromList(store, {\n domain,\n path,\n })\n callback(null, results)\n } catch (error) {\n if (error instanceof Error) {\n callback(error, [])\n }\n }\n }\n\n putCookie(\n cookie: CookieInstance,\n callback: (error: Error | null) => void,\n ): void {\n try {\n // Never set cookies with `maxAge` of `0`.\n if (cookie.maxAge === 0) {\n return\n }\n\n const store = this.getStore()\n store.push(cookie)\n this.updateStore(store)\n } catch (error) {\n if (error instanceof Error) {\n callback(error)\n }\n }\n }\n\n updateCookie(\n oldCookie: CookieInstance,\n newCookie: CookieInstance,\n callback: (error: Error | null) => void,\n ): void {\n /**\n * If updating a cookie with `maxAge` of `0`, remove it from the store.\n * Otherwise, two cookie entries will be created.\n * @see https://github.com/mswjs/msw/issues/2272\n */\n if (newCookie.maxAge === 0) {\n this.removeCookie(\n newCookie.domain || '',\n newCookie.path || '',\n newCookie.key,\n callback,\n )\n return\n }\n\n this.putCookie(newCookie, callback)\n }\n\n removeCookie(\n domain: string,\n path: string,\n key: string,\n callback: (error: Error | null) => void,\n ): void {\n try {\n const store = this.getStore()\n const nextStore = this.deleteCookiesFromList(store, { domain, path, key })\n this.updateStore(nextStore)\n callback(null)\n } catch (error) {\n if (error instanceof Error) {\n callback(error)\n }\n }\n }\n\n removeCookies(\n domain: string,\n path: string,\n callback: (error: Error | null) => void,\n ): void {\n try {\n const store = this.getStore()\n const nextStore = this.deleteCookiesFromList(store, { domain, path })\n this.updateStore(nextStore)\n callback(null)\n } catch (error) {\n if (error instanceof Error) {\n callback(error)\n }\n }\n }\n\n getAllCookies(\n callback: (error: Error | null, cookie: Array<CookieInstance>) => void,\n ): void {\n try {\n callback(null, this.getStore())\n } catch (error) {\n if (error instanceof Error) {\n callback(error, [])\n }\n }\n }\n\n private getStore(): Array<CookieInstance> {\n try {\n const json = this.storage.getItem(this.storageKey)\n\n if (json == null) {\n return []\n }\n\n const rawCookies = JSON.parse(json) as Array<Record<string, any>>\n const cookies: Array<CookieInstance> = []\n for (const rawCookie of rawCookies) {\n const cookie = Cookie.fromJSON(rawCookie)\n if (cookie != null) {\n cookies.push(cookie)\n }\n }\n return cookies\n } catch {\n return []\n }\n }\n\n private updateStore(nextStore: Array<CookieInstance>) {\n this.storage.setItem(\n this.storageKey,\n JSON.stringify(nextStore.map((cookie) => cookie.toJSON())),\n )\n }\n\n private filterCookiesFromList(\n cookies: Array<CookieInstance>,\n matches: { domain?: string; path?: string; key?: string },\n ): Array<CookieInstance> {\n const result: Array<CookieInstance> = []\n\n for (const cookie of cookies) {\n if (matches.domain && !domainMatch(matches.domain, cookie.domain || '')) {\n continue\n }\n\n if (matches.path && !pathMatch(matches.path, cookie.path || '')) {\n continue\n }\n\n if (matches.key && cookie.key !== matches.key) {\n continue\n }\n\n result.push(cookie)\n }\n\n return result\n }\n\n private deleteCookiesFromList(\n cookies: Array<CookieInstance>,\n matches: { domain?: string; path?: string; key?: string },\n ) {\n const matchingCookies = this.filterCookiesFromList(cookies, matches)\n return cookies.filter((cookie) => !matchingCookies.includes(cookie))\n }\n}\n\nconst store = isNodeProcess()\n ? new MemoryCookieStore()\n : new WebStorageCookieStore()\n\nexport const cookieStore = new CookieJar(store)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA0B;AAC1B,6BAA8B;AAC9B,0BAEO;AAEP,MAAM,EAAE,QAAQ,WAAW,OAAO,mBAAmB,aAAa,UAAU,IAC1E,oBAAAA;AAMF,MAAM,8BAA8B,MAAM;AAAA,EAChC;AAAA,EACA;AAAA,EAER,cAAc;AACZ,UAAM;AAEN;AAAA,MACE,OAAO,iBAAiB;AAAA,MACxB;AAAA,IACF;AAEA,SAAK,cAAc;AACnB,SAAK,UAAU;AACf,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,WACE,QACA,MACA,KACA,UACM;AACN,QAAI;AACF,YAAMC,SAAQ,KAAK,SAAS;AAC5B,YAAM,UAAU,KAAK,sBAAsBA,QAAO,EAAE,Q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AQ,UAAU,CAAC,YAAY,QAAQ,QAAQ,OAAO,UAAU,EAAE,GAAG;AACvE;AAAA,MACF;AAEA,UAAI,QAAQ,QAAQ,CAAC,UAAU,QAAQ,MAAM,OAAO,QAAQ,EAAE,GAAG;AAC/D;AAAA,MACF;AAEA,UAAI,QAAQ,OAAO,OAAO,QAAQ,QAAQ,KAAK;AAC7C;AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAEA,WAAO;AAAA,EACT;AAAA,EAEQ,sBACN,SACA,SACA;AACA,UAAM,kBAAkB,KAAK,sBAAsB,SAAS,OAAO;AACnE,WAAO,QAAQ,OAAO,CAAC,WAAW,CAAC,gBAAgB,SAAS,MAAM,CAAC;AAAA,EACrE;AACF;AAEA,MAAM,YAAQ,sCAAc,IACxB,IAAI,kBAAkB,IACtB,IAAI,sBAAsB;AAEvB,MAAM,cAAc,IAAI,UAAU,KAAK;","names":["toughCookie","store"]}
1
+ {"version":3,"sources":["../../../src/core/utils/cookieStore.ts"],"sourcesContent":["import { isNodeProcess } from 'is-node-process'\nimport { invariant } from 'outvariant'\nimport {\n Cookie,\n CookieJar,\n MemoryCookieStore,\n type MemoryCookieStoreIndex,\n} from 'tough-cookie'\nimport { jsonParse } from './internal/jsonParse'\n\nclass CookieStore {\n #storageKey = '__msw-cookie-store__'\n #jar: CookieJar\n #memoryStore: MemoryCookieStore\n\n constructor() {\n if (!isNodeProcess()) {\n invariant(\n typeof localStorage !== 'undefined',\n 'Failed to create a CookieStore: `localStorage` is not available in this environment. This is likely an issue with your environment, which has been detected as browser (or browser-like) environment and must implement global browser APIs correctly.',\n )\n }\n\n this.#memoryStore = new MemoryCookieStore()\n this.#memoryStore.idx = this.getCookieStoreIndex()\n this.#jar = new CookieJar(this.#memoryStore)\n }\n\n public getCookies(url: string): Array<Cookie> {\n return this.#jar.getCookiesSync(url)\n }\n\n public async setCookie(cookieName: string, url: string): Promise<void> {\n await this.#jar.setCookie(cookieName, url)\n this.persist()\n }\n\n private getCookieStoreIndex(): MemoryCookieStoreIndex {\n if (typeof localStorage === 'undefined') {\n return {}\n }\n\n const cookiesString = localStorage.getItem(this.#storageKey)\n if (cookiesString == null) {\n return {}\n }\n\n const rawCookies = jsonParse<Array<Record<string, unknown>>>(cookiesString)\n if (rawCookies == null) {\n return {}\n }\n\n const cookies: MemoryCookieStoreIndex = {}\n\n for (const rawCookie of rawCookies) {\n const cookie = Cookie.fromJSON(rawCookie)\n\n if (cookie != null && cookie.domain != null && cookie.path != null) {\n cookies[cookie.domain] ||= {}\n cookies[cookie.domain][cookie.path] ||= {}\n cookies[cookie.domain][cookie.path][cookie.key] = cookie\n }\n }\n\n return cookies\n }\n\n private persist(): void {\n if (typeof localStorage === 'undefined') {\n return\n }\n\n const data = []\n const { idx } = this.#memoryStore\n\n for (const domain in idx) {\n for (const path in idx[domain]) {\n for (const key in idx[domain][path]) {\n data.push(idx[domain][path][key].toJSON())\n }\n }\n }\n\n localStorage.setItem(this.#storageKey, JSON.stringify(data))\n }\n}\n\nexport const cookieStore = new CookieStore()\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAA8B;AAC9B,wBAA0B;AAC1B,0BAKO;AACP,uBAA0B;AAE1B,MAAM,YAAY;AAAA,EAChB,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EAEA,cAAc;AACZ,QAAI,KAAC,sCAAc,GAAG;AACpB;AAAA,QACE,OAAO,iBAAiB;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAEA,SAAK,eAAe,IAAI,sCAAkB;AAC1C,SAAK,aAAa,MAAM,KAAK,oBAAoB;AACjD,SAAK,OAAO,IAAI,8BAAU,KAAK,YAAY;AAAA,EAC7C;AAAA,EAEO,WAAW,KAA4B;AAC5C,WAAO,KAAK,KAAK,eAAe,GAAG;AAAA,EACrC;AAAA,EAEA,MAAa,UAAU,YAAoB,KAA4B;AACrE,UAAM,KAAK,KAAK,UAAU,YAAY,GAAG;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