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

@vercel/node-bridge

Package Overview
Dependencies
Maintainers
155
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vercel/node-bridge - npm Package Compare versions

Comparing version 2.2.2 to 3.0.0

218

helpers.js

@@ -238,3 +238,2 @@ module.exports =

var __webpack_unused_export__;
/*!

@@ -254,4 +253,4 @@ * cookie

exports.Q = parse;
__webpack_unused_export__ = serialize;
exports.parse = parse;
exports.serialize = serialize;

@@ -582,70 +581,8 @@ /**

/***/ 987:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.createServerWithHelpers = exports.sendError = exports.ApiError = void 0;
var http_1 = __webpack_require__(605);
const http_1 = __webpack_require__(605);
function getBodyParser(req, body) {

@@ -657,7 +594,7 @@ return function parseBody() {

// eslint-disable-next-line @typescript-eslint/no-var-requires
var parseContentType = __webpack_require__(534).parse;
var type = parseContentType(req.headers['content-type']).type;
const { parse: parseContentType } = __webpack_require__(534);
const { type } = parseContentType(req.headers['content-type']);
if (type === 'application/json') {
try {
var str = body.toString();
const str = body.toString();
return str ? JSON.parse(str) : {};

@@ -674,3 +611,3 @@ }

// eslint-disable-next-line @typescript-eslint/no-var-requires
var parseQS = __webpack_require__(191).parse;
const { parse: parseQS } = __webpack_require__(191);
// note: querystring.parse does not produce an iterable object

@@ -686,7 +623,6 @@ // https://nodejs.org/api/querystring.html#querystring_querystring_parse_str_sep_eq_options

}
function getQueryParser(_a) {
var _b = _a.url, url = _b === void 0 ? '/' : _b;
function getQueryParser({ url = '/' }) {
return function parseQuery() {
// eslint-disable-next-line @typescript-eslint/no-var-requires
var parseURL = __webpack_require__(835).parse;
const { parse: parseURL } = __webpack_require__(835);
return parseURL(url, true).query;

@@ -697,3 +633,3 @@ };

return function parseCookie() {
var header = req.headers.cookie;
const header = req.headers.cookie;
if (!header) {

@@ -703,3 +639,3 @@ return {};

// eslint-disable-next-line @typescript-eslint/no-var-requires
var parse = __webpack_require__(891)/* .parse */ .Q;
const { parse } = __webpack_require__(891);
return parse(Array.isArray(header) ? header.join(';') : header);

@@ -718,3 +654,3 @@ };

if (typeof statusOrUrl !== 'number' || typeof url !== 'string') {
throw new Error("Invalid redirect arguments. Please use a single argument URL, e.g. res.redirect('/destination') or use a status code and URL, e.g. res.redirect(307, '/destination').");
throw new Error(`Invalid redirect arguments. Please use a single argument URL, e.g. res.redirect('/destination') or use a status code and URL, e.g. res.redirect(307, '/destination').`);
}

@@ -726,4 +662,4 @@ res.writeHead(statusOrUrl, { Location: url }).end();

// eslint-disable-next-line @typescript-eslint/no-var-requires
var _a = __webpack_require__(534), parse = _a.parse, format = _a.format;
var parsed = parse(type);
const { parse, format } = __webpack_require__(534);
const parsed = parse(type);
parsed.parameters.charset = charset;

@@ -735,4 +671,4 @@ return format(parsed);

// eslint-disable-next-line @typescript-eslint/no-var-requires
var etag = __webpack_require__(474);
var buf = !Buffer.isBuffer(body) ? Buffer.from(body, encoding) : body;
const etag = __webpack_require__(474);
const buf = !Buffer.isBuffer(body) ? Buffer.from(body, encoding) : body;
return etag(buf, { weak: true });

@@ -742,4 +678,4 @@ }

function send(req, res, body) {
var chunk = body;
var encoding;
let chunk = body;
let encoding;
switch (typeof chunk) {

@@ -772,3 +708,3 @@ // string defaulting to html

// reflect this in content-type
var type = res.getHeader('content-type');
const type = res.getHeader('content-type');
if (typeof type === 'string') {

@@ -779,3 +715,3 @@ res.setHeader('content-type', setCharset(type, 'utf-8'));

// populate Content-Length
var len;
let len;
if (chunk !== undefined) {

@@ -793,3 +729,3 @@ if (Buffer.isBuffer(chunk)) {

// convert chunk to Buffer and calculate
var buf = Buffer.from(chunk, encoding);
const buf = Buffer.from(chunk, encoding);
len = buf.length;

@@ -808,3 +744,3 @@ chunk = buf;

// populate ETag
var etag;
let etag;
if (!res.getHeader('etag') &&

@@ -838,3 +774,3 @@ len !== undefined &&

function json(req, res, jsonBody) {
var body = JSON.stringify(jsonBody);
const body = JSON.stringify(jsonBody);
// content-type

@@ -846,11 +782,8 @@ if (!res.getHeader('content-type')) {

}
var ApiError = /** @class */ (function (_super) {
__extends(ApiError, _super);
function ApiError(statusCode, message) {
var _this = _super.call(this, message) || this;
_this.statusCode = statusCode;
return _this;
class ApiError extends Error {
constructor(statusCode, message) {
super(message);
this.statusCode = statusCode;
}
return ApiError;
}(Error));
}
exports.ApiError = ApiError;

@@ -864,56 +797,47 @@ function sendError(res, statusCode, message) {

function setLazyProp(req, prop, getter) {
var opts = { configurable: true, enumerable: true };
var optsReset = __assign(__assign({}, opts), { writable: true });
Object.defineProperty(req, prop, __assign(__assign({}, opts), { get: function () {
var value = getter();
const opts = { configurable: true, enumerable: true };
const optsReset = { ...opts, writable: true };
Object.defineProperty(req, prop, {
...opts,
get: () => {
const value = getter();
// we set the property on the object to avoid recalculating it
Object.defineProperty(req, prop, __assign(__assign({}, optsReset), { value: value }));
Object.defineProperty(req, prop, { ...optsReset, value });
return value;
}, set: function (value) {
Object.defineProperty(req, prop, __assign(__assign({}, optsReset), { value: value }));
} }));
},
set: value => {
Object.defineProperty(req, prop, { ...optsReset, value });
},
});
}
function createServerWithHelpers(handler, bridge) {
var _this = this;
var server = new http_1.Server(function (_req, _res) { return __awaiter(_this, void 0, void 0, function () {
var req, res, reqId, event, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
req = _req;
res = _res;
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
reqId = req.headers['x-now-bridge-request-id'];
// don't expose this header to the client
delete req.headers['x-now-bridge-request-id'];
if (typeof reqId !== 'string') {
throw new ApiError(500, 'Internal Server Error');
}
event = bridge.consumeEvent(reqId);
setLazyProp(req, 'cookies', getCookieParser(req));
setLazyProp(req, 'query', getQueryParser(req));
setLazyProp(req, 'body', getBodyParser(req, event.body));
res.status = function (statusCode) { return status(res, statusCode); };
res.redirect = function (statusOrUrl, url) { return redirect(res, statusOrUrl, url); };
res.send = function (body) { return send(req, res, body); };
res.json = function (jsonBody) { return json(req, res, jsonBody); };
return [4 /*yield*/, handler(req, res)];
case 2:
_a.sent();
return [3 /*break*/, 4];
case 3:
err_1 = _a.sent();
if (err_1 instanceof ApiError) {
sendError(res, err_1.statusCode, err_1.message);
}
else {
throw err_1;
}
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
const server = new http_1.Server(async (_req, _res) => {
const req = _req;
const res = _res;
try {
const reqId = req.headers['x-now-bridge-request-id'];
// don't expose this header to the client
delete req.headers['x-now-bridge-request-id'];
if (typeof reqId !== 'string') {
throw new ApiError(500, 'Internal Server Error');
}
});
}); });
const event = bridge.consumeEvent(reqId);
setLazyProp(req, 'cookies', getCookieParser(req));
setLazyProp(req, 'query', getQueryParser(req));
setLazyProp(req, 'body', getBodyParser(req, event.body));
res.status = statusCode => status(res, statusCode);
res.redirect = (statusOrUrl, url) => redirect(res, statusOrUrl, url);
res.send = body => send(req, res, body);
res.json = jsonBody => json(req, res, jsonBody);
await handler(req, res);
}
catch (err) {
if (err instanceof ApiError) {
sendError(res, err.statusCode, err.message);
}
else {
throw err;
}
}
});
return server;

@@ -982,3 +906,3 @@ }

/******/ try {
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ threw = false;

@@ -985,0 +909,0 @@ /******/ } finally {

{
"name": "@vercel/node-bridge",
"version": "2.2.2",
"version": "3.0.0",
"license": "MIT",

@@ -28,3 +28,3 @@ "main": "./index.js",

},
"gitHead": "6e8935883b874d68499283e7a3081a1e2824cbee"
"gitHead": "de0d2fba0b32588726a2799015eaff4e6bb65ffb"
}
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