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

@whatwg-node/node-fetch

Package Overview
Dependencies
Maintainers
1
Versions
509
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@whatwg-node/node-fetch - npm Package Compare versions

Comparing version 0.5.9 to 0.5.10-alpha-20240321134843-2ae7764efe55eb7970cab335a048aebb4a6d3b0f

5

cjs/Body.js

@@ -165,4 +165,5 @@ "use strict";

});
bb.on('error', err => {
reject(err);
bb.on('error', (err = 'An error occurred while parsing the form data') => {
const errMessage = err.message || err.toString();
reject(new TypeError(errMessage, err.cause));
});

@@ -169,0 +170,0 @@ _body?.readable.pipe(bb);

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

const Response_js_1 = require("./Response.js");
const URL_js_1 = require("./URL.js");
const utils_js_1 = require("./utils.js");

@@ -40,2 +41,15 @@ const BASE64_SUFFIX = ';base64';

}
function getResponseForBlob(url) {
const blob = URL_js_1.PonyfillURL.getBlobFromURL(url);
if (!blob) {
throw new TypeError('Invalid Blob URL');
}
return new Response_js_1.PonyfillResponse(blob, {
status: 200,
headers: {
'content-type': blob.type,
'content-length': blob.size.toString(),
},
});
}
function isURL(obj) {

@@ -58,2 +72,6 @@ return obj != null && obj.href != null;

}
if (fetchRequest.url.startsWith('blob:')) {
const response = getResponseForBlob(fetchRequest.url);
return (0, utils_js_1.fakePromise)(response);
}
if (globalThis.libcurl) {

@@ -60,0 +78,0 @@ return (0, fetchCurl_js_1.fetchCurl)(fetchRequest);

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

const tslib_1 = require("tslib");
const buffer_1 = require("buffer");
const crypto_1 = require("crypto");
const fast_querystring_1 = tslib_1.__importDefault(require("fast-querystring"));

@@ -53,3 +55,20 @@ const fast_url_parser_1 = tslib_1.__importDefault(require("@kamilkisiela/fast-url-parser"));

}
static createObjectURL(blob) {
const blobUrl = `blob:whatwgnode:${(0, crypto_1.randomUUID)()}`;
this.blobRegistry.set(blobUrl, blob);
return blobUrl;
}
static resolveObjectURL(url) {
if (!this.blobRegistry.has(url)) {
URL.revokeObjectURL(url);
}
else {
this.blobRegistry.delete(url);
}
}
static getBlobFromURL(url) {
return (this.blobRegistry.get(url) || (0, buffer_1.resolveObjectURL)(url));
}
}
exports.PonyfillURL = PonyfillURL;
PonyfillURL.blobRegistry = new Map();

@@ -161,4 +161,5 @@ import { Readable } from 'stream';

});
bb.on('error', err => {
reject(err);
bb.on('error', (err = 'An error occurred while parsing the form data') => {
const errMessage = err.message || err.toString();
reject(new TypeError(errMessage, err.cause));
});

@@ -165,0 +166,0 @@ _body?.readable.pipe(bb);

@@ -7,2 +7,3 @@ import { createReadStream } from 'fs';

import { PonyfillResponse } from './Response.js';
import { PonyfillURL } from './URL.js';
import { fakePromise } from './utils.js';

@@ -37,2 +38,15 @@ const BASE64_SUFFIX = ';base64';

}
function getResponseForBlob(url) {
const blob = PonyfillURL.getBlobFromURL(url);
if (!blob) {
throw new TypeError('Invalid Blob URL');
}
return new PonyfillResponse(blob, {
status: 200,
headers: {
'content-type': blob.type,
'content-length': blob.size.toString(),
},
});
}
function isURL(obj) {

@@ -55,2 +69,6 @@ return obj != null && obj.href != null;

}
if (fetchRequest.url.startsWith('blob:')) {
const response = getResponseForBlob(fetchRequest.url);
return fakePromise(response);
}
if (globalThis.libcurl) {

@@ -57,0 +75,0 @@ return fetchCurl(fetchRequest);

@@ -0,1 +1,3 @@

import { resolveObjectURL } from 'buffer';
import { randomUUID } from 'crypto';
import FastQuerystring from 'fast-querystring';

@@ -48,2 +50,19 @@ import FastUrl from '@kamilkisiela/fast-url-parser';

}
static createObjectURL(blob) {
const blobUrl = `blob:whatwgnode:${randomUUID()}`;
this.blobRegistry.set(blobUrl, blob);
return blobUrl;
}
static resolveObjectURL(url) {
if (!this.blobRegistry.has(url)) {
URL.revokeObjectURL(url);
}
else {
this.blobRegistry.delete(url);
}
}
static getBlobFromURL(url) {
return (this.blobRegistry.get(url) || resolveObjectURL(url));
}
}
PonyfillURL.blobRegistry = new Map();

2

package.json
{
"name": "@whatwg-node/node-fetch",
"version": "0.5.9",
"version": "0.5.10-alpha-20240321134843-2ae7764efe55eb7970cab335a048aebb4a6d3b0f",
"description": "Fetch API implementation for Node",

@@ -5,0 +5,0 @@ "sideEffects": false,

/// <reference types="packages/node-fetch/src/declarations.js" />
import FastUrl from '@kamilkisiela/fast-url-parser';
import { PonyfillBlob } from './Blob.js';
import { PonyfillURLSearchParams } from './URLSearchParams.js';

@@ -15,2 +16,6 @@ export declare class PonyfillURL extends FastUrl implements URL {

toJSON(): string;
private static blobRegistry;
static createObjectURL(blob: Blob): string;
static resolveObjectURL(url: string): void;
static getBlobFromURL(url: string): Blob | PonyfillBlob | undefined;
}

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