balena-request
Advanced tools
Comparing version 12.1.0-build-otaviojacobi-does-multipart-form-when-blob-is-present-d4c119a7e7f62c54d12b954846dedf44bd7245dd-1 to 13.0.0-build-drop-support-to-node14-16-c7bdf11c4ce4ea3b885a608d5ce76eeab758d32d-1
@@ -25,4 +25,2 @@ "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; | ||
@@ -320,9 +318,2 @@ /** | ||
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) => { | ||
return Object.values(requestBody !== null && requestBody !== void 0 ? requestBody : {}).some(isBlob); | ||
}; | ||
// This is the actual implementation that hides the internal `retriesRemaining` parameter | ||
@@ -345,31 +336,2 @@ 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.headers.delete('Content-Type'); | ||
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 { | ||
@@ -376,0 +338,0 @@ const requestTime = Date.now(); |
@@ -7,5 +7,5 @@ # Change Log | ||
## 12.1.0 - 2023-10-05 | ||
## 13.0.0 - 2023-10-11 | ||
* Add multi part request support when Blob is present [Otávio Jacobi] | ||
* Drop support for node 14 & 16 [Otávio Jacobi] | ||
@@ -12,0 +12,0 @@ ## 12.0.4 - 2023-08-23 |
@@ -27,4 +27,2 @@ /* | ||
import type { BalenaRequestOptions, BalenaRequestResponse } from './request'; | ||
import * as NodeFormData from 'form-data'; | ||
import { Blob as BufferBlob } from 'buffer'; | ||
@@ -378,13 +376,2 @@ 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) => { | ||
return Object.values(requestBody ?? {}).some(isBlob); | ||
}; | ||
// This is the actual implementation that hides the internal `retriesRemaining` parameter | ||
@@ -413,32 +400,2 @@ | ||
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.headers.delete('Content-Type'); | ||
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 { | ||
@@ -445,0 +402,0 @@ const requestTime = Date.now(); |
{ | ||
"name": "balena-request", | ||
"version": "12.1.0-build-otaviojacobi-does-multipart-form-when-blob-is-present-d4c119a7e7f62c54d12b954846dedf44bd7245dd-1", | ||
"version": "13.0.0-build-drop-support-to-node14-16-c7bdf11c4ce4ea3b885a608d5ce76eeab758d32d-1", | ||
"description": "Balena HTTP client", | ||
@@ -21,3 +21,3 @@ "main": "build/request.js", | ||
"engines": { | ||
"node": ">=14.0.0" | ||
"node": ">=18.0.0" | ||
}, | ||
@@ -44,3 +44,2 @@ "scripts": { | ||
"@types/mocha": "^9.1.1", | ||
"@types/node": "^16.0.0", | ||
"@types/progress-stream": "^2.0.0", | ||
@@ -77,3 +76,2 @@ "@types/qs": "^6.9.3", | ||
"fetch-readablestream": "^0.2.0", | ||
"form-data": "^4.0.0", | ||
"progress-stream": "^2.0.0", | ||
@@ -88,4 +86,4 @@ "qs": "^6.9.4", | ||
"versionist": { | ||
"publishedAt": "2023-10-05T14:50:27.601Z" | ||
"publishedAt": "2023-10-11T17:31:39.709Z" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
9
29
212227
31
4036
- Removedform-data@^4.0.0
- Removedasynckit@0.4.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedform-data@4.0.1(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)