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

balena-request

Package Overview
Dependencies
Maintainers
1
Versions
177
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

balena-request - npm Package Compare versions

Comparing version 12.0.3 to 12.1.0-build-otaviojacobi-does-multipart-form-when-blob-is-present-49219e9755546df6cd34c6404af9d88abc559389-1

44

build/utils.js

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

const balena_auth_1 = require("balena-auth");
const NodeFormData = require("form-data");
const buffer_1 = require("buffer");
const IS_BROWSER = typeof window !== 'undefined' && window !== null;

@@ -318,2 +320,16 @@ /**

exports.getBody = getBody;
const isBlob = (value) => {
return ((typeof Blob !== 'undefined' && value instanceof Blob) ||
(typeof buffer_1.Blob !== 'undefined' && value instanceof buffer_1.Blob));
};
const hasBlob = (requestBody) => {
if (requestBody) {
for (const value of Object.values(requestBody)) {
if (isBlob(value)) {
return true;
}
}
}
return false;
};
// This is the actual implementation that hides the internal `retriesRemaining` parameter

@@ -336,2 +352,30 @@ function requestAsync(fetch, options, retriesRemaining) {

}
if (hasBlob(options.body)) {
if (IS_BROWSER) {
const form = new FormData();
for (const [k, v] of Object.entries(options.body)) {
form.append(k, v);
}
opts.body = form;
}
else {
const form = new NodeFormData();
for (const [k, v] of Object.entries(options.body)) {
if (v instanceof buffer_1.Blob) {
form.append(k, Buffer.from(yield v.arrayBuffer()), {
filename: 'upload',
contentType: v.type,
});
}
else {
form.append(k, v);
}
}
for (const [k, v] of Object.entries(form.getHeaders())) {
opts.headers.set(k, v);
}
// @ts-expect-error
opts.body = form;
}
}
try {

@@ -338,0 +382,0 @@ const requestTime = Date.now();

4

CHANGELOG.md

@@ -7,2 +7,6 @@ # Change Log

## 12.1.0 - 2023-08-09
* Add multi part request support when Blob is present [Otávio Jacobi]
## 12.0.3 - 2023-08-09

@@ -9,0 +13,0 @@

@@ -27,2 +27,4 @@ /*

import type { BalenaRequestOptions, BalenaRequestResponse } from './request';
import * as NodeFormData from 'form-data';
import { Blob as BufferBlob } from 'buffer';

@@ -376,2 +378,20 @@ const IS_BROWSER = typeof window !== 'undefined' && window !== null;

const isBlob = (value: any) => {
return (
(typeof Blob !== 'undefined' && value instanceof Blob) ||
(typeof BufferBlob !== 'undefined' && value instanceof BufferBlob)
);
};
const hasBlob = (requestBody?: any) => {
if (requestBody) {
for (const value of Object.values(requestBody)) {
if (isBlob(value)) {
return true;
}
}
}
return false;
};
// This is the actual implementation that hides the internal `retriesRemaining` parameter

@@ -400,2 +420,31 @@

if (hasBlob(options.body)) {
if (IS_BROWSER) {
const form = new FormData();
for (const [k, v] of Object.entries(options.body)) {
form.append(k, v as string | Blob);
}
opts.body = form;
} else {
const form = new NodeFormData();
for (const [k, v] of Object.entries(options.body)) {
if (v instanceof BufferBlob) {
form.append(k, Buffer.from(await v.arrayBuffer()), {
filename: 'upload',
contentType: v.type,
});
} else {
form.append(k, v);
}
}
for (const [k, v] of Object.entries(form.getHeaders())) {
opts.headers.set(k, v);
}
// @ts-expect-error
opts.body = form;
}
}
try {

@@ -402,0 +451,0 @@ const requestTime = Date.now();

6

package.json
{
"name": "balena-request",
"version": "12.0.3",
"version": "12.1.0-build-otaviojacobi-does-multipart-form-when-blob-is-present-49219e9755546df6cd34c6404af9d88abc559389-1",
"description": "Balena HTTP client",

@@ -43,2 +43,3 @@ "main": "build/request.js",

"@types/mocha": "^9.1.1",
"@types/node": "^16.0.0",
"@types/progress-stream": "^2.0.0",

@@ -75,2 +76,3 @@ "@types/qs": "^6.9.3",

"fetch-readablestream": "^0.2.0",
"form-data": "^4.0.0",
"progress-stream": "^2.0.0",

@@ -85,4 +87,4 @@ "qs": "^6.9.4",

"versionist": {
"publishedAt": "2023-08-09T12:12:01.537Z"
"publishedAt": "2023-08-09T17:31:18.645Z"
}
}

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