msw 2.3.3 → 2.3.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.
- package/README.md +5 -0
- package/lib/core/HttpResponse.js +1 -1
- package/lib/core/HttpResponse.js.map +1 -1
- package/lib/core/HttpResponse.mjs +1 -1
- package/lib/core/HttpResponse.mjs.map +1 -1
- package/lib/core/utils/cookieStore.js +0 -1
- package/lib/core/utils/cookieStore.js.map +1 -1
- package/lib/core/utils/cookieStore.mjs +0 -1
- package/lib/core/utils/cookieStore.mjs.map +1 -1
- package/lib/iife/index.js +1 -2
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +1 -1
- package/src/core/HttpResponse.ts +1 -1
- package/src/core/utils/cookieStore.ts +0 -2
package/README.md
CHANGED
|
@@ -240,6 +240,11 @@ Mock Service Worker is trusted by hundreds of thousands of engineers around the
|
|
|
240
240
|
<img src="media/sponsors/replay.svg" alt="Replay" height="64" />
|
|
241
241
|
</a>
|
|
242
242
|
</td>
|
|
243
|
+
<td>
|
|
244
|
+
<a href="https://codemod.com/" target="_blank">
|
|
245
|
+
<img src="media/sponsors/codemod.svg" alt="Codemod" height="64" width="128" />
|
|
246
|
+
</a>
|
|
247
|
+
</td>
|
|
243
248
|
</tr>
|
|
244
249
|
</table>
|
|
245
250
|
|
package/lib/core/HttpResponse.js
CHANGED
|
@@ -94,7 +94,7 @@ class HttpResponse extends Response {
|
|
|
94
94
|
*/
|
|
95
95
|
static arrayBuffer(body, init) {
|
|
96
96
|
const responseInit = (0, import_decorators.normalizeResponseInit)(init);
|
|
97
|
-
if (body) {
|
|
97
|
+
if (body && !responseInit.headers.has("Content-Length")) {
|
|
98
98
|
responseInit.headers.set("Content-Length", body.byteLength.toString());
|
|
99
99
|
}
|
|
100
100
|
return new HttpResponse(body, responseInit);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/HttpResponse.ts"],"sourcesContent":["import 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\ndeclare const bodyType: unique symbol\n\nexport interface StrictRequest<BodyType extends DefaultBodyType>\n extends Request {\n json(): Promise<BodyType>\n}\n\n/**\n * Opaque `Response` type that supports strict body type.\n */\nexport interface StrictResponse<BodyType extends DefaultBodyType>\n extends Response {\n readonly [bodyType]: BodyType\n}\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 extends Response {\n constructor(body?: BodyInit | null, init?: HttpResponseInit) {\n const responseInit = normalizeResponseInit(init)\n super(body, responseInit)\n decorateResponse(this, responseInit)\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 ): StrictResponse<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) as StrictResponse<BodyType>\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,\n init?: HttpResponseInit,\n ): StrictResponse<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(\n responseText,\n responseInit,\n ) as StrictResponse<BodyType>\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 ): Response {\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 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(body?: ArrayBuffer, init?: HttpResponseInit): Response {\n const responseInit = normalizeResponseInit(init)\n\n if (body) {\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(body?: FormData, init?: HttpResponseInit): Response {\n return new HttpResponse(body, normalizeResponseInit(init))\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,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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;AAAA;AAAA;AAAA,EAWA,OAAO,YAAY,MAAoB,MAAmC;AACxE,UAAM,mBAAe,yCAAsB,IAAI;AAE/C,QAAI,
|
|
1
|
+
{"version":3,"sources":["../../src/core/HttpResponse.ts"],"sourcesContent":["import 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\ndeclare const bodyType: unique symbol\n\nexport interface StrictRequest<BodyType extends DefaultBodyType>\n extends Request {\n json(): Promise<BodyType>\n}\n\n/**\n * Opaque `Response` type that supports strict body type.\n */\nexport interface StrictResponse<BodyType extends DefaultBodyType>\n extends Response {\n readonly [bodyType]: BodyType\n}\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 extends Response {\n constructor(body?: BodyInit | null, init?: HttpResponseInit) {\n const responseInit = normalizeResponseInit(init)\n super(body, responseInit)\n decorateResponse(this, responseInit)\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 ): StrictResponse<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) as StrictResponse<BodyType>\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,\n init?: HttpResponseInit,\n ): StrictResponse<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(\n responseText,\n responseInit,\n ) as StrictResponse<BodyType>\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 ): Response {\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 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(body?: ArrayBuffer, init?: HttpResponseInit): Response {\n const responseInit = normalizeResponseInit(init)\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(body?: FormData, init?: HttpResponseInit): Response {\n return new HttpResponse(body, normalizeResponseInit(init))\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,wBAGO;AAgCA,MAAM,qBAAqB,SAAS;AAAA,EACzC,YAAY,MAAwB,MAAyB;AAC3D,UAAM,mBAAe,yCAAsB,IAAI;AAC/C,UAAM,MAAM,YAAY;AACxB,4CAAiB,MAAM,YAAY;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KACL,MACA,MAC0B;AAC1B,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,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,SAAS,IAAI;AAAA,MAC5C;AAAA,IACF;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KACL,MACA,MAC0B;AAC1B,UAAM,mBAAe,yCAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,kBAAkB;AAAA,IAC7D;AAMA,UAAM,eAAe,KAAK,UAAU,IAAI;AAExC,QAAI,CAAC,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AAC/C,mBAAa,QAAQ;AAAA,QACnB;AAAA,QACA,eAAe,IAAI,KAAK,CAAC,YAAY,CAAC,EAAE,KAAK,SAAS,IAAI;AAAA,MAC5D;AAAA,IACF;AAEA,WAAO,IAAI;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,IACL,MACA,MACU;AACV,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;AAAA;AAAA;AAAA,EAWA,OAAO,YAAY,MAAoB,MAAmC;AACxE,UAAM,mBAAe,yCAAsB,IAAI;AAE/C,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,SAAS,MAAiB,MAAmC;AAClE,WAAO,IAAI,aAAa,UAAM,yCAAsB,IAAI,CAAC;AAAA,EAC3D;AACF;","names":[]}
|
|
@@ -74,7 +74,7 @@ class HttpResponse extends Response {
|
|
|
74
74
|
*/
|
|
75
75
|
static arrayBuffer(body, init) {
|
|
76
76
|
const responseInit = normalizeResponseInit(init);
|
|
77
|
-
if (body) {
|
|
77
|
+
if (body && !responseInit.headers.has("Content-Length")) {
|
|
78
78
|
responseInit.headers.set("Content-Length", body.byteLength.toString());
|
|
79
79
|
}
|
|
80
80
|
return new HttpResponse(body, responseInit);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/HttpResponse.ts"],"sourcesContent":["import 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\ndeclare const bodyType: unique symbol\n\nexport interface StrictRequest<BodyType extends DefaultBodyType>\n extends Request {\n json(): Promise<BodyType>\n}\n\n/**\n * Opaque `Response` type that supports strict body type.\n */\nexport interface StrictResponse<BodyType extends DefaultBodyType>\n extends Response {\n readonly [bodyType]: BodyType\n}\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 extends Response {\n constructor(body?: BodyInit | null, init?: HttpResponseInit) {\n const responseInit = normalizeResponseInit(init)\n super(body, responseInit)\n decorateResponse(this, responseInit)\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 ): StrictResponse<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) as StrictResponse<BodyType>\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,\n init?: HttpResponseInit,\n ): StrictResponse<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(\n responseText,\n responseInit,\n ) as StrictResponse<BodyType>\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 ): Response {\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 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(body?: ArrayBuffer, init?: HttpResponseInit): Response {\n const responseInit = normalizeResponseInit(init)\n\n if (body) {\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(body?: FormData, init?: HttpResponseInit): Response {\n return new HttpResponse(body, normalizeResponseInit(init))\n }\n}\n"],"mappings":"AAEA;AA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AAC,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;AAAA;AAAA;AAAA,EAWA,OAAO,YAAY,MAAoB,MAAmC;AACxE,UAAM,eAAe,sBAAsB,IAAI;AAE/C,QAAI,
|
|
1
|
+
{"version":3,"sources":["../../src/core/HttpResponse.ts"],"sourcesContent":["import 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\ndeclare const bodyType: unique symbol\n\nexport interface StrictRequest<BodyType extends DefaultBodyType>\n extends Request {\n json(): Promise<BodyType>\n}\n\n/**\n * Opaque `Response` type that supports strict body type.\n */\nexport interface StrictResponse<BodyType extends DefaultBodyType>\n extends Response {\n readonly [bodyType]: BodyType\n}\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 extends Response {\n constructor(body?: BodyInit | null, init?: HttpResponseInit) {\n const responseInit = normalizeResponseInit(init)\n super(body, responseInit)\n decorateResponse(this, responseInit)\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 ): StrictResponse<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) as StrictResponse<BodyType>\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,\n init?: HttpResponseInit,\n ): StrictResponse<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(\n responseText,\n responseInit,\n ) as StrictResponse<BodyType>\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 ): Response {\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 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(body?: ArrayBuffer, init?: HttpResponseInit): Response {\n const responseInit = normalizeResponseInit(init)\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(body?: FormData, init?: HttpResponseInit): Response {\n return new HttpResponse(body, normalizeResponseInit(init))\n }\n}\n"],"mappings":"AAEA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAgCA,MAAM,qBAAqB,SAAS;AAAA,EACzC,YAAY,MAAwB,MAAyB;AAC3D,UAAM,eAAe,sBAAsB,IAAI;AAC/C,UAAM,MAAM,YAAY;AACxB,qBAAiB,MAAM,YAAY;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KACL,MACA,MAC0B;AAC1B,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;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KACL,MACA,MAC0B;AAC1B,UAAM,eAAe,sBAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,kBAAkB;AAAA,IAC7D;AAMA,UAAM,eAAe,KAAK,UAAU,IAAI;AAExC,QAAI,CAAC,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AAC/C,mBAAa,QAAQ;AAAA,QACnB;AAAA,QACA,eAAe,IAAI,KAAK,CAAC,YAAY,CAAC,EAAE,KAAK,SAAS,IAAI;AAAA,MAC5D;AAAA,IACF;AAEA,WAAO,IAAI;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,IACL,MACA,MACU;AACV,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;AAAA;AAAA;AAAA,EAWA,OAAO,YAAY,MAAoB,MAAmC;AACxE,UAAM,eAAe,sBAAsB,IAAI;AAE/C,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,SAAS,MAAiB,MAAmC;AAClE,WAAO,IAAI,aAAa,MAAM,sBAAsB,IAAI,CAAC;AAAA,EAC3D;AACF;","names":[]}
|
|
@@ -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 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 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
|
|
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 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 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,IAC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,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 +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 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 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
|
|
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 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 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,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,OAAO,iBAEA;AAEP,MAAM,EAAE,QAAQ,WAAW,OAAO,mBAAmB,aAAa,UAAU,IAC1E;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,YAAMA,SAAQ,KAAK,SAAS;AAC5B,YAAM,UAAU,KAAK,sBAAsBA,QAAO,EAAE,QAAQ,MAAM,IAAI,CAAC;AACvE,eAAS,MAAM,QAAQ,CAAC,KAAK,IAAI;AAAA,IACnC,SAAS,OAAO;AACd,UAAI,iBAAiB,OAAO;AAC1B,iBAAS,OAAO,IAAI;AAAA,MACtB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,YAC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,QAAQ,OAAO,CAAC,WAAW,CAAC,gBAAgB,SAAS,MAAM,CAAC;AAAA,EACrE;AACF;AAEA,MAAM,QAAQ,cAAc,IACxB,IAAI,kBAAkB,IACtB,IAAI,sBAAsB;AAEvB,MAAM,cAAc,IAAI,UAAU,KAAK;","names":["store"]}
|
package/lib/iife/index.js
CHANGED
|
@@ -13887,7 +13887,6 @@ var MockServiceWorker = (() => {
|
|
|
13887
13887
|
}
|
|
13888
13888
|
result.push(cookie);
|
|
13889
13889
|
}
|
|
13890
|
-
console.log("filter result:", { cookies, matches, result });
|
|
13891
13890
|
return result;
|
|
13892
13891
|
}
|
|
13893
13892
|
deleteCookiesFromList(cookies, matches) {
|
|
@@ -17582,7 +17581,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`;
|
|
|
17582
17581
|
*/
|
|
17583
17582
|
static arrayBuffer(body, init) {
|
|
17584
17583
|
const responseInit = normalizeResponseInit(init);
|
|
17585
|
-
if (body) {
|
|
17584
|
+
if (body && !responseInit.headers.has("Content-Length")) {
|
|
17586
17585
|
responseInit.headers.set("Content-Length", body.byteLength.toString());
|
|
17587
17586
|
}
|
|
17588
17587
|
return new _HttpResponse(body, responseInit);
|