msw 2.3.1 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/{GraphQLHandler-Dq_WRbKe.d.mts → GraphQLHandler-L3AUWt2v.d.mts} +1 -1
- package/lib/core/{GraphQLHandler-COiPfZ8k.d.ts → GraphQLHandler-UgnlXhlx.d.ts} +1 -1
- package/lib/core/{HttpResponse-B07UKAkU.d.ts → HttpResponse-B58aIqZM.d.ts} +6 -5
- package/lib/core/{HttpResponse-C7niBMwb.d.mts → HttpResponse-fnOXxh4-.d.mts} +6 -5
- package/lib/core/HttpResponse.d.mts +2 -1
- package/lib/core/HttpResponse.d.ts +2 -1
- package/lib/core/SetupApi.d.mts +2 -1
- package/lib/core/SetupApi.d.ts +2 -1
- package/lib/core/getResponse.d.mts +2 -1
- package/lib/core/getResponse.d.ts +2 -1
- package/lib/core/graphql.d.mts +3 -2
- package/lib/core/graphql.d.ts +3 -2
- package/lib/core/handlers/GraphQLHandler.d.mts +3 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +3 -2
- package/lib/core/handlers/HttpHandler.d.mts +2 -1
- package/lib/core/handlers/HttpHandler.d.ts +2 -1
- package/lib/core/handlers/RequestHandler.d.mts +2 -1
- package/lib/core/handlers/RequestHandler.d.ts +2 -1
- package/lib/core/handlers/RequestHandler.js +18 -25
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs +21 -26
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/http.d.mts +2 -1
- package/lib/core/http.d.ts +2 -1
- package/lib/core/index.d.mts +3 -2
- package/lib/core/index.d.ts +3 -2
- package/lib/core/passthrough.d.mts +2 -1
- package/lib/core/passthrough.d.ts +2 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +4 -2
- package/lib/core/utils/HttpResponse/decorators.d.ts +4 -2
- package/lib/core/utils/HttpResponse/decorators.js +16 -6
- package/lib/core/utils/HttpResponse/decorators.js.map +1 -1
- package/lib/core/utils/HttpResponse/decorators.mjs +16 -6
- package/lib/core/utils/HttpResponse/decorators.mjs.map +1 -1
- package/lib/core/utils/cookieStore.d.mts +5 -0
- package/lib/core/utils/cookieStore.d.ts +5 -0
- package/lib/core/utils/cookieStore.js +176 -0
- package/lib/core/utils/cookieStore.js.map +1 -0
- package/lib/core/utils/cookieStore.mjs +146 -0
- package/lib/core/utils/cookieStore.mjs.map +1 -0
- package/lib/core/utils/executeHandlers.d.mts +2 -1
- package/lib/core/utils/executeHandlers.d.ts +2 -1
- package/lib/core/utils/handleRequest.d.mts +2 -1
- package/lib/core/utils/handleRequest.d.ts +2 -1
- package/lib/core/utils/handleRequest.js +2 -2
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs +2 -2
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/core/utils/internal/isIterable.d.mts +16 -2
- package/lib/core/utils/internal/isIterable.d.ts +16 -2
- package/lib/core/utils/internal/isIterable.js +1 -1
- package/lib/core/utils/internal/isIterable.js.map +1 -1
- package/lib/core/utils/internal/isIterable.mjs +1 -1
- package/lib/core/utils/internal/isIterable.mjs.map +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +3 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +3 -2
- package/lib/core/utils/internal/parseMultipartData.d.mts +2 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +2 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +2 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +2 -1
- package/lib/core/utils/request/getRequestCookies.d.mts +1 -6
- package/lib/core/utils/request/getRequestCookies.d.ts +1 -6
- package/lib/core/utils/request/getRequestCookies.js +22 -20
- package/lib/core/utils/request/getRequestCookies.js.map +1 -1
- package/lib/core/utils/request/getRequestCookies.mjs +22 -20
- package/lib/core/utils/request/getRequestCookies.mjs.map +1 -1
- package/lib/core/utils/request/storeResponseCookies.d.mts +3 -0
- package/lib/core/utils/request/storeResponseCookies.d.ts +3 -0
- package/lib/core/utils/request/{readResponseCookies.js → storeResponseCookies.js} +12 -9
- package/lib/core/utils/request/storeResponseCookies.js.map +1 -0
- package/lib/core/utils/request/storeResponseCookies.mjs +12 -0
- package/lib/core/utils/request/storeResponseCookies.mjs.map +1 -0
- package/lib/iife/index.js +12204 -345
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +7 -7
- package/src/core/handlers/RequestHandler.ts +51 -44
- package/src/core/utils/HttpResponse/decorators.ts +32 -16
- package/src/core/utils/cookieStore.ts +212 -0
- package/src/core/utils/handleRequest.ts +3 -3
- package/src/core/utils/internal/isIterable.ts +22 -2
- package/src/core/utils/request/getRequestCookies.ts +32 -35
- package/src/core/utils/request/storeResponseCookies.ts +17 -0
- package/lib/core/utils/request/readResponseCookies.d.mts +0 -3
- package/lib/core/utils/request/readResponseCookies.d.ts +0 -3
- package/lib/core/utils/request/readResponseCookies.js.map +0 -1
- package/lib/core/utils/request/readResponseCookies.mjs +0 -9
- package/lib/core/utils/request/readResponseCookies.mjs.map +0 -1
- package/src/core/utils/request/getRequestCookies.node.test.ts +0 -29
- package/src/core/utils/request/getRequestCookies.test.ts +0 -64
- package/src/core/utils/request/readResponseCookies.ts +0 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/utils/handleRequest.ts"],"sourcesContent":["import { until } from '@open-draft/until'\nimport { Emitter } from 'strict-event-emitter'\nimport { RequestHandler } from '../handlers/RequestHandler'\nimport { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'\nimport { RequiredDeep } from '../typeUtils'\nimport { HandlersExecutionResult, executeHandlers } from './executeHandlers'\nimport { onUnhandledRequest } from './request/onUnhandledRequest'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/handleRequest.ts"],"sourcesContent":["import { until } from '@open-draft/until'\nimport { Emitter } from 'strict-event-emitter'\nimport { RequestHandler } from '../handlers/RequestHandler'\nimport { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'\nimport { RequiredDeep } from '../typeUtils'\nimport { HandlersExecutionResult, executeHandlers } from './executeHandlers'\nimport { onUnhandledRequest } from './request/onUnhandledRequest'\nimport { storeResponseCookies } from './request/storeResponseCookies'\n\nexport interface HandleRequestOptions {\n /**\n * `resolutionContext` is not part of the general public api\n * but is exposed to aid in creating extensions like\n * `@mswjs/http-middleware`.\n */\n resolutionContext?: {\n /**\n * A base url to use when resolving relative urls.\n * @note This is primarily used by the `@mswjs/http-middleware`\n * to resolve relative urls in the context of the running server\n */\n baseUrl?: string\n }\n\n /**\n * Transforms a `MockedResponse` instance returned from a handler\n * to a response instance supported by the lower tooling (i.e. interceptors).\n */\n transformResponse?(response: Response): Response\n\n /**\n * Invoked whenever a request is performed as-is.\n */\n onPassthroughResponse?(request: Request): void\n\n /**\n * Invoked when the mocked response is ready to be sent.\n */\n onMockedResponse?(\n response: Response,\n handler: RequiredDeep<HandlersExecutionResult>,\n ): void\n}\n\nexport async function handleRequest(\n request: Request,\n requestId: string,\n handlers: Array<RequestHandler>,\n options: RequiredDeep<SharedOptions>,\n emitter: Emitter<LifeCycleEventsMap>,\n handleRequestOptions?: HandleRequestOptions,\n): Promise<Response | undefined> {\n emitter.emit('request:start', { request, requestId })\n\n // Perform bypassed requests (i.e. wrapped in \"bypass()\") as-is.\n if (request.headers.get('x-msw-intention') === 'bypass') {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Resolve a mocked response from the list of request handlers.\n const lookupResult = await until(() => {\n return executeHandlers({\n request,\n requestId,\n handlers,\n resolutionContext: handleRequestOptions?.resolutionContext,\n })\n })\n\n if (lookupResult.error) {\n // Allow developers to react to unhandled exceptions in request handlers.\n emitter.emit('unhandledException', {\n error: lookupResult.error,\n request,\n requestId,\n })\n throw lookupResult.error\n }\n\n // If the handler lookup returned nothing, no request handler was found\n // matching this request. Report the request as unhandled.\n if (!lookupResult.data) {\n await onUnhandledRequest(request, options.onUnhandledRequest)\n emitter.emit('request:unhandled', { request, requestId })\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n const { response } = lookupResult.data\n\n // When the handled request returned no mocked response, warn the developer,\n // as it may be an oversight on their part. Perform the request as-is.\n if (!response) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Perform the request as-is when the developer explicitly returned \"req.passthrough()\".\n // This produces no warning as the request was handled.\n if (\n response.status === 302 &&\n response.headers.get('x-msw-intention') === 'passthrough'\n ) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Store all the received response cookies in the cookie jar.\n storeResponseCookies(request, response)\n\n emitter.emit('request:match', { request, requestId })\n\n const requiredLookupResult =\n lookupResult.data as RequiredDeep<HandlersExecutionResult>\n\n const transformedResponse =\n handleRequestOptions?.transformResponse?.(response) ||\n (response as any as Response)\n\n handleRequestOptions?.onMockedResponse?.(\n transformedResponse,\n requiredLookupResult,\n )\n\n emitter.emit('request:end', { request, requestId })\n\n return transformedResponse\n}\n"],"mappings":"AAAA,SAAS,aAAa;AAKtB,SAAkC,uBAAuB;AACzD,SAAS,0BAA0B;AACnC,SAAS,4BAA4B;AAqCrC,eAAsB,cACpB,SACA,WACA,UACA,SACA,SACA,sBAC+B;AAC/B,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAGpD,MAAI,QAAQ,QAAQ,IAAI,iBAAiB,MAAM,UAAU;AACvD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,QAAM,eAAe,MAAM,MAAM,MAAM;AACrC,WAAO,gBAAgB;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB,sBAAsB;AAAA,IAC3C,CAAC;AAAA,EACH,CAAC;AAED,MAAI,aAAa,OAAO;AAEtB,YAAQ,KAAK,sBAAsB;AAAA,MACjC,OAAO,aAAa;AAAA,MACpB;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,aAAa;AAAA,EACrB;AAIA,MAAI,CAAC,aAAa,MAAM;AACtB,UAAM,mBAAmB,SAAS,QAAQ,kBAAkB;AAC5D,YAAQ,KAAK,qBAAqB,EAAE,SAAS,UAAU,CAAC;AACxD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAEA,QAAM,EAAE,SAAS,IAAI,aAAa;AAIlC,MAAI,CAAC,UAAU;AACb,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAIA,MACE,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,iBAAiB,MAAM,eAC5C;AACA,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,uBAAqB,SAAS,QAAQ;AAEtC,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAEpD,QAAM,uBACJ,aAAa;AAEf,QAAM,sBACJ,sBAAsB,oBAAoB,QAAQ,KACjD;AAEH,wBAAsB;AAAA,IACpB;AAAA,IACA;AAAA,EACF;AAEA,UAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAElD,SAAO;AACT;","names":[]}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the same as TypeScript's `Iterable`, but with all three type parameters.
|
|
3
|
+
* @todo Remove once TypeScript 5.6 is the minimum.
|
|
4
|
+
*/
|
|
5
|
+
interface Iterable<T, TReturn, TNext> {
|
|
6
|
+
[Symbol.iterator](): Iterator<T, TReturn, TNext>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* This is the same as TypeScript's `AsyncIterable`, but with all three type parameters.
|
|
10
|
+
* @todo Remove once TypeScript 5.6 is the minimum.
|
|
11
|
+
*/
|
|
12
|
+
interface AsyncIterable<T, TReturn, TNext> {
|
|
13
|
+
[Symbol.asyncIterator](): AsyncIterator<T, TReturn, TNext>;
|
|
14
|
+
}
|
|
1
15
|
/**
|
|
2
16
|
* Determines if the given function is an iterator.
|
|
3
17
|
*/
|
|
4
|
-
declare function isIterable<IteratorType>(fn: any): fn is
|
|
18
|
+
declare function isIterable<IteratorType>(fn: any): fn is Iterable<IteratorType, IteratorType, IteratorType> | AsyncIterable<IteratorType, IteratorType, IteratorType>;
|
|
5
19
|
|
|
6
|
-
export { isIterable };
|
|
20
|
+
export { type AsyncIterable, type Iterable, isIterable };
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the same as TypeScript's `Iterable`, but with all three type parameters.
|
|
3
|
+
* @todo Remove once TypeScript 5.6 is the minimum.
|
|
4
|
+
*/
|
|
5
|
+
interface Iterable<T, TReturn, TNext> {
|
|
6
|
+
[Symbol.iterator](): Iterator<T, TReturn, TNext>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* This is the same as TypeScript's `AsyncIterable`, but with all three type parameters.
|
|
10
|
+
* @todo Remove once TypeScript 5.6 is the minimum.
|
|
11
|
+
*/
|
|
12
|
+
interface AsyncIterable<T, TReturn, TNext> {
|
|
13
|
+
[Symbol.asyncIterator](): AsyncIterator<T, TReturn, TNext>;
|
|
14
|
+
}
|
|
1
15
|
/**
|
|
2
16
|
* Determines if the given function is an iterator.
|
|
3
17
|
*/
|
|
4
|
-
declare function isIterable<IteratorType>(fn: any): fn is
|
|
18
|
+
declare function isIterable<IteratorType>(fn: any): fn is Iterable<IteratorType, IteratorType, IteratorType> | AsyncIterable<IteratorType, IteratorType, IteratorType>;
|
|
5
19
|
|
|
6
|
-
export { isIterable };
|
|
20
|
+
export { type AsyncIterable, type Iterable, isIterable };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/internal/isIterable.ts"],"sourcesContent":["/**\n * Determines if the given function is an iterator.\n */\nexport function isIterable<IteratorType>(\n fn: any,\n): fn is
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/internal/isIterable.ts"],"sourcesContent":["/**\n * This is the same as TypeScript's `Iterable`, but with all three type parameters.\n * @todo Remove once TypeScript 5.6 is the minimum.\n */\nexport interface Iterable<T, TReturn, TNext> {\n [Symbol.iterator](): Iterator<T, TReturn, TNext>\n}\n\n/**\n * This is the same as TypeScript's `AsyncIterable`, but with all three type parameters.\n * @todo Remove once TypeScript 5.6 is the minimum.\n */\nexport interface AsyncIterable<T, TReturn, TNext> {\n [Symbol.asyncIterator](): AsyncIterator<T, TReturn, TNext>\n}\n\n/**\n * Determines if the given function is an iterator.\n */\nexport function isIterable<IteratorType>(\n fn: any,\n): fn is\n | Iterable<IteratorType, IteratorType, IteratorType>\n | AsyncIterable<IteratorType, IteratorType, IteratorType> {\n if (!fn) {\n return false\n }\n\n return (\n Reflect.has(fn, Symbol.iterator) || Reflect.has(fn, Symbol.asyncIterator)\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBO,SAAS,WACd,IAG0D;AAC1D,MAAI,CAAC,IAAI;AACP,WAAO;AAAA,EACT;AAEA,SACE,QAAQ,IAAI,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,IAAI,OAAO,aAAa;AAE5E;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/internal/isIterable.ts"],"sourcesContent":["/**\n * Determines if the given function is an iterator.\n */\nexport function isIterable<IteratorType>(\n fn: any,\n): fn is
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/internal/isIterable.ts"],"sourcesContent":["/**\n * This is the same as TypeScript's `Iterable`, but with all three type parameters.\n * @todo Remove once TypeScript 5.6 is the minimum.\n */\nexport interface Iterable<T, TReturn, TNext> {\n [Symbol.iterator](): Iterator<T, TReturn, TNext>\n}\n\n/**\n * This is the same as TypeScript's `AsyncIterable`, but with all three type parameters.\n * @todo Remove once TypeScript 5.6 is the minimum.\n */\nexport interface AsyncIterable<T, TReturn, TNext> {\n [Symbol.asyncIterator](): AsyncIterator<T, TReturn, TNext>\n}\n\n/**\n * Determines if the given function is an iterator.\n */\nexport function isIterable<IteratorType>(\n fn: any,\n): fn is\n | Iterable<IteratorType, IteratorType, IteratorType>\n | AsyncIterable<IteratorType, IteratorType, IteratorType> {\n if (!fn) {\n return false\n }\n\n return (\n Reflect.has(fn, Symbol.iterator) || Reflect.has(fn, Symbol.asyncIterator)\n )\n}\n"],"mappings":"AAmBO,SAAS,WACd,IAG0D;AAC1D,MAAI,CAAC,IAAI;AACP,WAAO;AAAA,EACT;AAEA,SACE,QAAQ,IAAI,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,IAAI,OAAO,aAAa;AAE5E;","names":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-
|
|
3
|
-
import '../../HttpResponse-
|
|
2
|
+
export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-L3AUWt2v.mjs';
|
|
3
|
+
import '../../HttpResponse-fnOXxh4-.mjs';
|
|
4
|
+
import './isIterable.mjs';
|
|
4
5
|
import '../../typeUtils.mjs';
|
|
5
6
|
import '../matching/matchRequestUrl.mjs';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-
|
|
3
|
-
import '../../HttpResponse-
|
|
2
|
+
export { j as GraphQLMultipartRequestBody, i as GraphQLParsedOperationsMap, h as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, k as parseGraphQLRequest } from '../../GraphQLHandler-UgnlXhlx.js';
|
|
3
|
+
import '../../HttpResponse-B58aIqZM.js';
|
|
4
|
+
import './isIterable.js';
|
|
4
5
|
import '../../typeUtils.js';
|
|
5
6
|
import '../matching/matchRequestUrl.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-
|
|
1
|
+
import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-fnOXxh4-.mjs';
|
|
2
|
+
import './isIterable.mjs';
|
|
2
3
|
import '../../typeUtils.mjs';
|
|
3
4
|
|
|
4
5
|
declare function use(currentHandlers: Array<RequestHandler>, ...handlers: Array<RequestHandler>): void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-
|
|
1
|
+
import { R as RequestHandler, g as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-B58aIqZM.js';
|
|
2
|
+
import './isIterable.js';
|
|
2
3
|
import '../../typeUtils.js';
|
|
3
4
|
|
|
4
5
|
declare function use(currentHandlers: Array<RequestHandler>, ...handlers: Array<RequestHandler>): void;
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/** @todo Rename this to "getDocumentCookies" */
|
|
2
|
-
/**
|
|
3
|
-
* Returns relevant document cookies based on the request `credentials` option.
|
|
4
|
-
*/
|
|
5
|
-
declare function getRequestCookies(request: Request): Record<string, string>;
|
|
6
1
|
declare function getAllRequestCookies(request: Request): Record<string, string>;
|
|
7
2
|
|
|
8
|
-
export { getAllRequestCookies
|
|
3
|
+
export { getAllRequestCookies };
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/** @todo Rename this to "getDocumentCookies" */
|
|
2
|
-
/**
|
|
3
|
-
* Returns relevant document cookies based on the request `credentials` option.
|
|
4
|
-
*/
|
|
5
|
-
declare function getRequestCookies(request: Request): Record<string, string>;
|
|
6
1
|
declare function getAllRequestCookies(request: Request): Record<string, string>;
|
|
7
2
|
|
|
8
|
-
export { getAllRequestCookies
|
|
3
|
+
export { getAllRequestCookies };
|
|
@@ -28,23 +28,22 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var getRequestCookies_exports = {};
|
|
30
30
|
__export(getRequestCookies_exports, {
|
|
31
|
-
getAllRequestCookies: () => getAllRequestCookies
|
|
32
|
-
getRequestCookies: () => getRequestCookies
|
|
31
|
+
getAllRequestCookies: () => getAllRequestCookies
|
|
33
32
|
});
|
|
34
33
|
module.exports = __toCommonJS(getRequestCookies_exports);
|
|
35
34
|
var import_cookie = __toESM(require("@bundled-es-modules/cookie"));
|
|
36
|
-
var
|
|
35
|
+
var import_cookieStore = require("../cookieStore.js");
|
|
37
36
|
function getAllDocumentCookies() {
|
|
38
37
|
return import_cookie.default.parse(document.cookie);
|
|
39
38
|
}
|
|
40
|
-
function
|
|
39
|
+
function getDocumentCookies(request) {
|
|
41
40
|
if (typeof document === "undefined" || typeof location === "undefined") {
|
|
42
41
|
return {};
|
|
43
42
|
}
|
|
44
43
|
switch (request.credentials) {
|
|
45
44
|
case "same-origin": {
|
|
46
|
-
const
|
|
47
|
-
return location.origin ===
|
|
45
|
+
const requestUrl = new URL(request.url);
|
|
46
|
+
return location.origin === requestUrl.origin ? getAllDocumentCookies() : {};
|
|
48
47
|
}
|
|
49
48
|
case "include": {
|
|
50
49
|
return getAllDocumentCookies();
|
|
@@ -55,22 +54,25 @@ function getRequestCookies(request) {
|
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
function getAllRequestCookies(request) {
|
|
58
|
-
const
|
|
59
|
-
const cookiesFromHeaders =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
const requestCookieHeader = request.headers.get("cookie");
|
|
58
|
+
const cookiesFromHeaders = requestCookieHeader ? import_cookie.default.parse(requestCookieHeader) : {};
|
|
59
|
+
const cookiesFromDocument = getDocumentCookies(request);
|
|
60
|
+
for (const name in cookiesFromDocument) {
|
|
61
|
+
request.headers.append(
|
|
62
|
+
"cookie",
|
|
63
|
+
import_cookie.default.serialize(name, cookiesFromDocument[name])
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
const cookiesFromStore = import_cookieStore.cookieStore.getCookiesSync(request.url);
|
|
67
|
+
const storedCookiesObject = Object.fromEntries(
|
|
68
|
+
cookiesFromStore.map((cookie) => [cookie.key, cookie.value])
|
|
69
|
+
);
|
|
70
|
+
for (const cookie of cookiesFromStore) {
|
|
71
|
+
request.headers.append("cookie", cookie.toString());
|
|
71
72
|
}
|
|
72
73
|
return {
|
|
73
|
-
...
|
|
74
|
+
...cookiesFromDocument,
|
|
75
|
+
...storedCookiesObject,
|
|
74
76
|
...cookiesFromHeaders
|
|
75
77
|
};
|
|
76
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/request/getRequestCookies.ts"],"sourcesContent":["import cookieUtils from '@bundled-es-modules/cookie'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/getRequestCookies.ts"],"sourcesContent":["import cookieUtils from '@bundled-es-modules/cookie'\nimport { cookieStore } from '../cookieStore'\n\nfunction getAllDocumentCookies() {\n return cookieUtils.parse(document.cookie)\n}\n\nfunction getDocumentCookies(request: Request): Record<string, string> {\n if (typeof document === 'undefined' || typeof location === 'undefined') {\n return {}\n }\n\n switch (request.credentials) {\n case 'same-origin': {\n const requestUrl = new URL(request.url)\n\n // Return document cookies only when requested a resource\n // from the same origin as the current document.\n return location.origin === requestUrl.origin\n ? getAllDocumentCookies()\n : {}\n }\n\n case 'include': {\n // Return all document cookies.\n return getAllDocumentCookies()\n }\n\n default: {\n return {}\n }\n }\n}\n\nexport function getAllRequestCookies(request: Request): Record<string, string> {\n /**\n * @note While the \"cookie\" header is a forbidden header field\n * in the browser, you can read it in Node.js. We need to respect\n * it for mocking in Node.js.\n */\n const requestCookieHeader = request.headers.get('cookie')\n const cookiesFromHeaders = requestCookieHeader\n ? cookieUtils.parse(requestCookieHeader)\n : {}\n\n const cookiesFromDocument = getDocumentCookies(request)\n\n // Forward the document cookies to the request headers.\n for (const name in cookiesFromDocument) {\n request.headers.append(\n 'cookie',\n cookieUtils.serialize(name, cookiesFromDocument[name]),\n )\n }\n\n const cookiesFromStore = cookieStore.getCookiesSync(request.url)\n const storedCookiesObject = Object.fromEntries(\n cookiesFromStore.map((cookie) => [cookie.key, cookie.value]),\n )\n\n // Forward the raw stored cookies to request headers\n // so they contain metadata like \"expires\", \"secure\", etc.\n for (const cookie of cookiesFromStore) {\n request.headers.append('cookie', cookie.toString())\n }\n\n return {\n ...cookiesFromDocument,\n ...storedCookiesObject,\n ...cookiesFromHeaders,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAwB;AACxB,yBAA4B;AAE5B,SAAS,wBAAwB;AAC/B,SAAO,cAAAA,QAAY,MAAM,SAAS,MAAM;AAC1C;AAEA,SAAS,mBAAmB,SAA0C;AACpE,MAAI,OAAO,aAAa,eAAe,OAAO,aAAa,aAAa;AACtE,WAAO,CAAC;AAAA,EACV;AAEA,UAAQ,QAAQ,aAAa;AAAA,IAC3B,KAAK,eAAe;AAClB,YAAM,aAAa,IAAI,IAAI,QAAQ,GAAG;AAItC,aAAO,SAAS,WAAW,WAAW,SAClC,sBAAsB,IACtB,CAAC;AAAA,IACP;AAAA,IAEA,KAAK,WAAW;AAEd,aAAO,sBAAsB;AAAA,IAC/B;AAAA,IAEA,SAAS;AACP,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,SAA0C;AAM7E,QAAM,sBAAsB,QAAQ,QAAQ,IAAI,QAAQ;AACxD,QAAM,qBAAqB,sBACvB,cAAAA,QAAY,MAAM,mBAAmB,IACrC,CAAC;AAEL,QAAM,sBAAsB,mBAAmB,OAAO;AAGtD,aAAW,QAAQ,qBAAqB;AACtC,YAAQ,QAAQ;AAAA,MACd;AAAA,MACA,cAAAA,QAAY,UAAU,MAAM,oBAAoB,IAAI,CAAC;AAAA,IACvD;AAAA,EACF;AAEA,QAAM,mBAAmB,+BAAY,eAAe,QAAQ,GAAG;AAC/D,QAAM,sBAAsB,OAAO;AAAA,IACjC,iBAAiB,IAAI,CAAC,WAAW,CAAC,OAAO,KAAK,OAAO,KAAK,CAAC;AAAA,EAC7D;AAIA,aAAW,UAAU,kBAAkB;AACrC,YAAQ,QAAQ,OAAO,UAAU,OAAO,SAAS,CAAC;AAAA,EACpD;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;","names":["cookieUtils"]}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import cookieUtils from "@bundled-es-modules/cookie";
|
|
2
|
-
import {
|
|
2
|
+
import { cookieStore } from '../cookieStore.mjs';
|
|
3
3
|
function getAllDocumentCookies() {
|
|
4
4
|
return cookieUtils.parse(document.cookie);
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function getDocumentCookies(request) {
|
|
7
7
|
if (typeof document === "undefined" || typeof location === "undefined") {
|
|
8
8
|
return {};
|
|
9
9
|
}
|
|
10
10
|
switch (request.credentials) {
|
|
11
11
|
case "same-origin": {
|
|
12
|
-
const
|
|
13
|
-
return location.origin ===
|
|
12
|
+
const requestUrl = new URL(request.url);
|
|
13
|
+
return location.origin === requestUrl.origin ? getAllDocumentCookies() : {};
|
|
14
14
|
}
|
|
15
15
|
case "include": {
|
|
16
16
|
return getAllDocumentCookies();
|
|
@@ -21,27 +21,29 @@ function getRequestCookies(request) {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
function getAllRequestCookies(request) {
|
|
24
|
-
const
|
|
25
|
-
const cookiesFromHeaders =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
const requestCookieHeader = request.headers.get("cookie");
|
|
25
|
+
const cookiesFromHeaders = requestCookieHeader ? cookieUtils.parse(requestCookieHeader) : {};
|
|
26
|
+
const cookiesFromDocument = getDocumentCookies(request);
|
|
27
|
+
for (const name in cookiesFromDocument) {
|
|
28
|
+
request.headers.append(
|
|
29
|
+
"cookie",
|
|
30
|
+
cookieUtils.serialize(name, cookiesFromDocument[name])
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
const cookiesFromStore = cookieStore.getCookiesSync(request.url);
|
|
34
|
+
const storedCookiesObject = Object.fromEntries(
|
|
35
|
+
cookiesFromStore.map((cookie) => [cookie.key, cookie.value])
|
|
36
|
+
);
|
|
37
|
+
for (const cookie of cookiesFromStore) {
|
|
38
|
+
request.headers.append("cookie", cookie.toString());
|
|
37
39
|
}
|
|
38
40
|
return {
|
|
39
|
-
...
|
|
41
|
+
...cookiesFromDocument,
|
|
42
|
+
...storedCookiesObject,
|
|
40
43
|
...cookiesFromHeaders
|
|
41
44
|
};
|
|
42
45
|
}
|
|
43
46
|
export {
|
|
44
|
-
getAllRequestCookies
|
|
45
|
-
getRequestCookies
|
|
47
|
+
getAllRequestCookies
|
|
46
48
|
};
|
|
47
49
|
//# sourceMappingURL=getRequestCookies.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/request/getRequestCookies.ts"],"sourcesContent":["import cookieUtils from '@bundled-es-modules/cookie'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/getRequestCookies.ts"],"sourcesContent":["import cookieUtils from '@bundled-es-modules/cookie'\nimport { cookieStore } from '../cookieStore'\n\nfunction getAllDocumentCookies() {\n return cookieUtils.parse(document.cookie)\n}\n\nfunction getDocumentCookies(request: Request): Record<string, string> {\n if (typeof document === 'undefined' || typeof location === 'undefined') {\n return {}\n }\n\n switch (request.credentials) {\n case 'same-origin': {\n const requestUrl = new URL(request.url)\n\n // Return document cookies only when requested a resource\n // from the same origin as the current document.\n return location.origin === requestUrl.origin\n ? getAllDocumentCookies()\n : {}\n }\n\n case 'include': {\n // Return all document cookies.\n return getAllDocumentCookies()\n }\n\n default: {\n return {}\n }\n }\n}\n\nexport function getAllRequestCookies(request: Request): Record<string, string> {\n /**\n * @note While the \"cookie\" header is a forbidden header field\n * in the browser, you can read it in Node.js. We need to respect\n * it for mocking in Node.js.\n */\n const requestCookieHeader = request.headers.get('cookie')\n const cookiesFromHeaders = requestCookieHeader\n ? cookieUtils.parse(requestCookieHeader)\n : {}\n\n const cookiesFromDocument = getDocumentCookies(request)\n\n // Forward the document cookies to the request headers.\n for (const name in cookiesFromDocument) {\n request.headers.append(\n 'cookie',\n cookieUtils.serialize(name, cookiesFromDocument[name]),\n )\n }\n\n const cookiesFromStore = cookieStore.getCookiesSync(request.url)\n const storedCookiesObject = Object.fromEntries(\n cookiesFromStore.map((cookie) => [cookie.key, cookie.value]),\n )\n\n // Forward the raw stored cookies to request headers\n // so they contain metadata like \"expires\", \"secure\", etc.\n for (const cookie of cookiesFromStore) {\n request.headers.append('cookie', cookie.toString())\n }\n\n return {\n ...cookiesFromDocument,\n ...storedCookiesObject,\n ...cookiesFromHeaders,\n }\n}\n"],"mappings":"AAAA,OAAO,iBAAiB;AACxB,SAAS,mBAAmB;AAE5B,SAAS,wBAAwB;AAC/B,SAAO,YAAY,MAAM,SAAS,MAAM;AAC1C;AAEA,SAAS,mBAAmB,SAA0C;AACpE,MAAI,OAAO,aAAa,eAAe,OAAO,aAAa,aAAa;AACtE,WAAO,CAAC;AAAA,EACV;AAEA,UAAQ,QAAQ,aAAa;AAAA,IAC3B,KAAK,eAAe;AAClB,YAAM,aAAa,IAAI,IAAI,QAAQ,GAAG;AAItC,aAAO,SAAS,WAAW,WAAW,SAClC,sBAAsB,IACtB,CAAC;AAAA,IACP;AAAA,IAEA,KAAK,WAAW;AAEd,aAAO,sBAAsB;AAAA,IAC/B;AAAA,IAEA,SAAS;AACP,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,SAA0C;AAM7E,QAAM,sBAAsB,QAAQ,QAAQ,IAAI,QAAQ;AACxD,QAAM,qBAAqB,sBACvB,YAAY,MAAM,mBAAmB,IACrC,CAAC;AAEL,QAAM,sBAAsB,mBAAmB,OAAO;AAGtD,aAAW,QAAQ,qBAAqB;AACtC,YAAQ,QAAQ;AAAA,MACd;AAAA,MACA,YAAY,UAAU,MAAM,oBAAoB,IAAI,CAAC;AAAA,IACvD;AAAA,EACF;AAEA,QAAM,mBAAmB,YAAY,eAAe,QAAQ,GAAG;AAC/D,QAAM,sBAAsB,OAAO;AAAA,IACjC,iBAAiB,IAAI,CAAC,WAAW,CAAC,OAAO,KAAK,OAAO,KAAK,CAAC;AAAA,EAC7D;AAIA,aAAW,UAAU,kBAAkB;AACrC,YAAQ,QAAQ,OAAO,UAAU,OAAO,SAAS,CAAC;AAAA,EACpD;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;","names":[]}
|
|
@@ -16,14 +16,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var storeResponseCookies_exports = {};
|
|
20
|
+
__export(storeResponseCookies_exports, {
|
|
21
|
+
storeResponseCookies: () => storeResponseCookies
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
module.exports = __toCommonJS(storeResponseCookies_exports);
|
|
24
|
+
var import_cookieStore = require("../cookieStore.js");
|
|
25
|
+
var import_decorators = require("../HttpResponse/decorators.js");
|
|
26
|
+
function storeResponseCookies(request, response) {
|
|
27
|
+
const responseCookies = Reflect.get(response, import_decorators.kSetCookie);
|
|
28
|
+
if (responseCookies) {
|
|
29
|
+
import_cookieStore.cookieStore.setCookie(responseCookies, request.url);
|
|
30
|
+
}
|
|
28
31
|
}
|
|
29
|
-
//# sourceMappingURL=
|
|
32
|
+
//# sourceMappingURL=storeResponseCookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/storeResponseCookies.ts"],"sourcesContent":["import { cookieStore } from '../cookieStore'\nimport { kSetCookie } from '../HttpResponse/decorators'\n\nexport function storeResponseCookies(\n request: Request,\n response: Response,\n): void {\n // Grab the raw \"Set-Cookie\" response header provided\n // in the HeadersInit for this mocked response.\n const responseCookies = Reflect.get(response, kSetCookie) as\n | string\n | undefined\n\n if (responseCookies) {\n cookieStore.setCookie(responseCookies, request.url)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA4B;AAC5B,wBAA2B;AAEpB,SAAS,qBACd,SACA,UACM;AAGN,QAAM,kBAAkB,QAAQ,IAAI,UAAU,4BAAU;AAIxD,MAAI,iBAAiB;AACnB,mCAAY,UAAU,iBAAiB,QAAQ,GAAG;AAAA,EACpD;AACF;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { cookieStore } from '../cookieStore.mjs';
|
|
2
|
+
import { kSetCookie } from '../HttpResponse/decorators.mjs';
|
|
3
|
+
function storeResponseCookies(request, response) {
|
|
4
|
+
const responseCookies = Reflect.get(response, kSetCookie);
|
|
5
|
+
if (responseCookies) {
|
|
6
|
+
cookieStore.setCookie(responseCookies, request.url);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
storeResponseCookies
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=storeResponseCookies.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/storeResponseCookies.ts"],"sourcesContent":["import { cookieStore } from '../cookieStore'\nimport { kSetCookie } from '../HttpResponse/decorators'\n\nexport function storeResponseCookies(\n request: Request,\n response: Response,\n): void {\n // Grab the raw \"Set-Cookie\" response header provided\n // in the HeadersInit for this mocked response.\n const responseCookies = Reflect.get(response, kSetCookie) as\n | string\n | undefined\n\n if (responseCookies) {\n cookieStore.setCookie(responseCookies, request.url)\n }\n}\n"],"mappings":"AAAA,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAEpB,SAAS,qBACd,SACA,UACM;AAGN,QAAM,kBAAkB,QAAQ,IAAI,UAAU,UAAU;AAIxD,MAAI,iBAAiB;AACnB,gBAAY,UAAU,iBAAiB,QAAQ,GAAG;AAAA,EACpD;AACF;","names":[]}
|