Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mswjs/interceptors

Package Overview
Dependencies
Maintainers
1
Versions
158
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mswjs/interceptors - npm Package Compare versions

Comparing version 0.16.5 to 0.16.6

1

lib/glossary.d.ts
import type { HeadersObject, Headers } from 'headers-polyfill';
import type { LazyCallback } from './utils/createLazyCallback';
export declare const IS_PATCHED_MODULE: unique symbol;
export declare type RequestCredentials = 'omit' | 'include' | 'same-origin';

@@ -4,0 +5,0 @@ export interface IsomorphicRequest {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IS_PATCHED_MODULE = void 0;
exports.IS_PATCHED_MODULE = Symbol('isPatchedModule');
//# sourceMappingURL=glossary.js.map

7

lib/interceptors/ClientRequest/index.d.ts
/// <reference types="node" />
import http from 'http';
import https from 'https';
import { HttpRequestEventMap } from '../../glossary';
import { HttpRequestEventMap, IS_PATCHED_MODULE } from '../../glossary';
import { Interceptor } from '../../Interceptor';
import { AsyncEventEmitter } from '../../utils/AsyncEventEmitter';
import { Protocol } from './NodeClientRequest';
export declare type MaybePatchedModule<Module> = Module & {
[IS_PATCHED_MODULE]?: boolean;
};
export declare type ClientRequestEmitter = AsyncEventEmitter<HttpRequestEventMap>;
export declare type ClientRequestModules = Map<Protocol, typeof http | typeof https>;
export declare type ClientRequestModules = Map<Protocol, MaybePatchedModule<typeof http> | MaybePatchedModule<typeof https>>;
/**

@@ -11,0 +14,0 @@ * Intercept requests made via the `ClientRequest` class.

@@ -51,2 +51,4 @@ "use strict";

var https_1 = __importDefault(require("https"));
var outvariant_1 = require("outvariant");
var glossary_1 = require("../../glossary");
var Interceptor_1 = require("../../Interceptor");

@@ -73,3 +75,7 @@ var http_get_1 = require("./http.get");

var pureRequest = requestModule.request, pureGet = requestModule.get;
outvariant_1.invariant(!requestModule[glossary_1.IS_PATCHED_MODULE], 'Failed to patch the "%s" module: already patched.', protocol);
this_1.subscriptions.push(function () {
Object.defineProperty(requestModule, glossary_1.IS_PATCHED_MODULE, {
value: undefined,
});
requestModule.request = pureRequest;

@@ -91,2 +97,7 @@ requestModule.get = pureGet;

http_get_1.get(protocol, options);
Object.defineProperty(requestModule, glossary_1.IS_PATCHED_MODULE, {
configurable: true,
enumerable: true,
value: true,
});
log('native "%s" module patched!', protocol);

@@ -93,0 +104,0 @@ };

@@ -1,2 +0,2 @@

import type { HttpRequestEventMap } from '../../glossary';
import { HttpRequestEventMap } from '../../glossary';
import { Interceptor } from '../../Interceptor';

@@ -3,0 +3,0 @@ export declare class FetchInterceptor extends Interceptor<HttpRequestEventMap> {

@@ -83,2 +83,4 @@ "use strict";

var headers_polyfill_1 = require("headers-polyfill");
var outvariant_1 = require("outvariant");
var glossary_1 = require("../../glossary");
var Interceptor_1 = require("../../Interceptor");

@@ -100,2 +102,3 @@ var createLazyCallback_1 = require("../../utils/createLazyCallback");

var pureFetch = globalThis.fetch;
outvariant_1.invariant(!pureFetch[glossary_1.IS_PATCHED_MODULE], 'Failed to patch the "fetch" module: already patched.');
globalThis.fetch = function (input, init) { return __awaiter(_this, void 0, void 0, function () {

@@ -179,3 +182,11 @@ var request, url, method, isomorphicRequest, _a, mockedResponse, isomorphicResponse, response;

}); };
Object.defineProperty(globalThis.fetch, glossary_1.IS_PATCHED_MODULE, {
enumerable: true,
configurable: true,
value: true,
});
this.subscriptions.push(function () {
Object.defineProperty(globalThis.fetch, glossary_1.IS_PATCHED_MODULE, {
value: undefined,
});
globalThis.fetch = pureFetch;

@@ -182,0 +193,0 @@ _this.log('restored native "globalThis.fetch"!', globalThis.fetch.name);

@@ -1,2 +0,2 @@

import type { HttpRequestEventMap, InteractiveIsomorphicRequest } from '../../glossary';
import { HttpRequestEventMap, InteractiveIsomorphicRequest } from '../../glossary';
import { Interceptor } from '../../Interceptor';

@@ -3,0 +3,0 @@ import { AsyncEventEmitter } from '../../utils/AsyncEventEmitter';

@@ -19,2 +19,4 @@ "use strict";

exports.XMLHttpRequestInterceptor = void 0;
var outvariant_1 = require("outvariant");
var glossary_1 = require("../../glossary");
var Interceptor_1 = require("../../Interceptor");

@@ -35,2 +37,3 @@ var XMLHttpRequestOverride_1 = require("./XMLHttpRequestOverride");

var PureXMLHttpRequest = window.XMLHttpRequest;
outvariant_1.invariant(!PureXMLHttpRequest[glossary_1.IS_PATCHED_MODULE], 'Failed to patch the "XMLHttpRequest" module: already patched.');
window.XMLHttpRequest = XMLHttpRequestOverride_1.createXMLHttpRequestOverride({

@@ -42,3 +45,11 @@ XMLHttpRequest: PureXMLHttpRequest,

log('native "XMLHttpRequest" module patched!', window.XMLHttpRequest.name);
Object.defineProperty(window.XMLHttpRequest, glossary_1.IS_PATCHED_MODULE, {
enumerable: true,
configurable: true,
value: true,
});
this.subscriptions.push(function () {
Object.defineProperty(window.XMLHttpRequest, glossary_1.IS_PATCHED_MODULE, {
value: undefined,
});
window.XMLHttpRequest = PureXMLHttpRequest;

@@ -45,0 +56,0 @@ log('native "XMLHttpRequest" module restored!', window.XMLHttpRequest.name);

{
"name": "@mswjs/interceptors",
"description": "Low-level HTTP/HTTPS/XHR/fetch request interception library.",
"version": "0.16.5",
"version": "0.16.6",
"main": "lib/index.js",

@@ -6,0 +6,0 @@ "typings": "lib/index.d.ts",

import type { HeadersObject, Headers } from 'headers-polyfill'
import type { LazyCallback } from './utils/createLazyCallback'
export const IS_PATCHED_MODULE: unique symbol = Symbol('isPatchedModule')
export type RequestCredentials = 'omit' | 'include' | 'same-origin'

@@ -5,0 +7,0 @@

import http from 'http'
import https from 'https'
import { HttpRequestEventMap } from '../../glossary'
import { invariant } from 'outvariant'
import { HttpRequestEventMap, IS_PATCHED_MODULE } from '../../glossary'
import { Interceptor } from '../../Interceptor'

@@ -10,5 +11,12 @@ import { AsyncEventEmitter } from '../../utils/AsyncEventEmitter'

export type MaybePatchedModule<Module> = Module & {
[IS_PATCHED_MODULE]?: boolean
}
export type ClientRequestEmitter = AsyncEventEmitter<HttpRequestEventMap>
export type ClientRequestModules = Map<Protocol, typeof http | typeof https>
export type ClientRequestModules = Map<
Protocol,
MaybePatchedModule<typeof http> | MaybePatchedModule<typeof https>
>

@@ -37,3 +45,13 @@ /**

invariant(
!requestModule[IS_PATCHED_MODULE],
'Failed to patch the "%s" module: already patched.',
protocol
)
this.subscriptions.push(() => {
Object.defineProperty(requestModule, IS_PATCHED_MODULE, {
value: undefined,
})
requestModule.request = pureRequest

@@ -60,2 +78,8 @@ requestModule.get = pureGet

Object.defineProperty(requestModule, IS_PATCHED_MODULE, {
configurable: true,
enumerable: true,
value: true,
})
log('native "%s" module patched!', protocol)

@@ -62,0 +86,0 @@ }

@@ -7,6 +7,8 @@ import {

} from 'headers-polyfill'
import type {
import { invariant } from 'outvariant'
import {
HttpRequestEventMap,
InteractiveIsomorphicRequest,
IsomorphicResponse,
IS_PATCHED_MODULE,
} from '../../glossary'

@@ -35,2 +37,7 @@ import { Interceptor } from '../../Interceptor'

invariant(
!(pureFetch as any)[IS_PATCHED_MODULE],
'Failed to patch the "fetch" module: already patched.'
)
globalThis.fetch = async (input, init) => {

@@ -114,4 +121,15 @@ const request = new Request(input, init)

Object.defineProperty(globalThis.fetch, IS_PATCHED_MODULE, {
enumerable: true,
configurable: true,
value: true,
})
this.subscriptions.push(() => {
Object.defineProperty(globalThis.fetch, IS_PATCHED_MODULE, {
value: undefined,
})
globalThis.fetch = pureFetch
this.log('restored native "globalThis.fetch"!', globalThis.fetch.name)

@@ -118,0 +136,0 @@ })

@@ -1,4 +0,6 @@

import type {
import { invariant } from 'outvariant'
import {
HttpRequestEventMap,
InteractiveIsomorphicRequest,
IS_PATCHED_MODULE,
} from '../../glossary'

@@ -36,2 +38,7 @@ import { Interceptor } from '../../Interceptor'

invariant(
!(PureXMLHttpRequest as any)[IS_PATCHED_MODULE],
'Failed to patch the "XMLHttpRequest" module: already patched.'
)
window.XMLHttpRequest = createXMLHttpRequestOverride({

@@ -45,3 +52,13 @@ XMLHttpRequest: PureXMLHttpRequest,

Object.defineProperty(window.XMLHttpRequest, IS_PATCHED_MODULE, {
enumerable: true,
configurable: true,
value: true,
})
this.subscriptions.push(() => {
Object.defineProperty(window.XMLHttpRequest, IS_PATCHED_MODULE, {
value: undefined,
})
window.XMLHttpRequest = PureXMLHttpRequest

@@ -48,0 +65,0 @@ log(

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc