🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

nock

Package Overview
Dependencies
Maintainers
4
Versions
466
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nock - npm Package Compare versions

Comparing version
15.0.0-beta.9
to
15.0.0-beta.10
+62
lib/stringify.js
'use strict'
/**
* @see https://github.com/moll/json-stringify-safe/blob/02cfafd45f06d076ac4bf0dd28be6738a07a72f9/stringify.js
* @license
* The ISC License
*
* Copyright (c) Isaac Z. Schlueter and Contributors
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @param {*} obj
* @returns {string}
*/
function stringify(obj) {
return JSON.stringify(obj, safeReplacer())
}
/**
* @param {Array<*>} stack
* @param {Array<string>} keys
* @param {*} value
* @returns {string}
*/
function cycleReplacer(stack, keys, value) {
if (stack[0] === value) return '[Circular ~]'
return `[Circular ~.${keys.slice(0, stack.indexOf(value)).join('.')}]`
}
/**
* @param {Array<*>} [stack]
* @param {Array<string>} [keys]
* @returns {(key: string, value: *) => *} */
function safeReplacer(stack = [], keys = []) {
return function (key, value) {
if (stack.length > 0) {
const thisPos = stack.indexOf(this)
~thisPos ? stack.splice(thisPos + 1) : stack.push(this)
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key)
if (~stack.indexOf(value)) {
value = cycleReplacer(stack, keys, value)
}
} else {
stack.push(value)
}
return value
}
}
module.exports = stringify
+2
-2

@@ -20,3 +20,3 @@ 'use strict'

const { Scope, load, loadDefs, define } = require('./lib/scope')
const { getDecompressedGetBody } = require('./lib/utils/node')
const { getGetRequestBody } = require('./lib/utils/node')

@@ -47,3 +47,3 @@ module.exports = (basePath, options) => new Scope(basePath, options)

back,
getDecompressedGetBody,
getGetRequestBody,
})

@@ -50,0 +50,0 @@

'use strict'
const fs = require('node:fs')
const stringify = require('json-stringify-safe')
const querystring = require('node:querystring')
const { URL, URLSearchParams } = require('node:url')
const stringify = require('./stringify')
const common = require('./common')

@@ -9,0 +9,0 @@ const { remove } = require('./intercept')

@@ -10,3 +10,3 @@ 'use strict'

const { getClientRequestBodyStream } = require('@mswjs/interceptors/utils/node')
const { setDecompressedGetBody } = require('../utils/node')
const { setGetRequestBody } = require('../utils/node')

@@ -49,3 +49,3 @@ const interceptor = new BatchInterceptor({

if (requestBodyBuffer.byteLength > 0 && request.method === 'GET') {
setDecompressedGetBody(decompressedRequest, requestBodyBuffer)
setGetRequestBody(decompressedRequest, requestBodyBuffer)
}

@@ -52,0 +52,0 @@

@@ -247,3 +247,3 @@ 'use strict'

if (typeof value === 'function') {
rawHeaders[i][1] = await value(decompressedRequest)
rawHeaders[i][1] = await value(decompressedRequest, body)
}

@@ -250,0 +250,0 @@ }

'use strict'
const { Readable } = require('node:stream')
const kDecompressedGetBody = Symbol('kDecompressedGetBody')
const kGetRequestBody = Symbol('kGetRequestBody')
/**
* @param {Request} request
* @returns {ArrayBuffer}
* @returns {Readable}
* Returns the request body stream of the given request.

@@ -15,7 +15,7 @@ * @note This is only relevant in the context of `http.ClientRequest`.

*/
function getDecompressedGetBody(request) {
function getGetRequestBody(request) {
if (request.method !== 'GET') {
throw new Error('The request method must be GET')
}
return Readable.from(Reflect.get(request, kDecompressedGetBody))
return Readable.from(Reflect.get(request, kGetRequestBody))
}

@@ -27,9 +27,9 @@

*/
function setDecompressedGetBody(request, body) {
Reflect.set(request, kDecompressedGetBody, Buffer.from(body))
function setGetRequestBody(request, body) {
Reflect.set(request, kGetRequestBody, Buffer.from(body))
}
module.exports = {
getDecompressedGetBody,
setDecompressedGetBody,
getGetRequestBody,
setGetRequestBody,
}

@@ -10,3 +10,3 @@ {

],
"version": "15.0.0-beta.9",
"version": "15.0.0-beta.10",
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",

@@ -26,4 +26,3 @@ "repository": {

"dependencies": {
"@mswjs/interceptors": "^0.41.2",
"json-stringify-safe": "^5.0.1"
"@mswjs/interceptors": "^0.41.2"
},

@@ -30,0 +29,0 @@ "devDependencies": {

@@ -77,3 +77,6 @@ // TypeScript Version: 5.0

type ReplyHeaderFunction = (req: Request) => Promise<string | string[]>
type ReplyHeaderFunction = (
req: Request,
body?: string | Buffer,
) => string | string[] | Promise<string | string[]>
type ReplyHeaderValue = string | string[] | ReplyHeaderFunction

@@ -235,3 +238,3 @@ type ReplyHeaders =

*/
function getDecompressedGetBody(request: Request): Promise<Readable>
function getGetRequestBody(request: Request): Promise<Readable>

@@ -238,0 +241,0 @@ interface Options {