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.2 to 12.1.0-build-otaviojacobi-does-multipart-form-when-blob-is-present-c55aae989843200f9a73b9e5a84c42643c31767d-1

39

build/utils.js

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

const token_1 = require("balena-auth/build/token");
const NodeFormData = require("form-data");
const IS_BROWSER = typeof window !== 'undefined' && window !== null;

@@ -318,2 +319,12 @@ /**

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

@@ -336,2 +347,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 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 +377,0 @@ const requestTime = Date.now();

4

CHANGELOG.md

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

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

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

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

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

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

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

@@ -400,2 +412,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 Blob) {
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 +443,0 @@ const requestTime = Date.now();

5

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

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

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

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

"versionist": {
"publishedAt": "2023-07-25T15:47:53.133Z"
"publishedAt": "2023-08-08T01:55:13.858Z"
}
}

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