You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@netlify/blobs

Package Overview
Dependencies
Maintainers
20
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@netlify/blobs - npm Package Compare versions

Comparing version

to
1.1.0

3

dist/main.js

@@ -54,2 +54,5 @@ var HTTPMethod;

const res = await this.fetcher(apiURL, { headers, method });
if (res.status !== 200) {
throw new Error(`${method} operation has failed: API returned a ${res.status} response`);
}
const { url } = await res.json();

@@ -56,0 +59,0 @@ return {

@@ -72,2 +72,22 @@ import { version as nodeVersion } from 'process';

});
test('Throws when the API returns a non-200 status code', async () => {
const fetcher = async (...args) => {
const [url, options] = args;
const headers = options?.headers;
expect(options?.method).toBe('get');
if (url === `https://api.netlify.com/api/v1/sites/${siteID}/blobs/${key}?context=production`) {
expect(headers.authorization).toBe(`Bearer ${apiToken}`);
return new Response(null, { status: 401, statusText: 'Unauthorized' });
}
throw new Error(`Unexpected fetch call: ${url}`);
};
const blobs = new Blobs({
authentication: {
token: apiToken,
},
fetcher,
siteID,
});
expect(async () => await blobs.get(key)).rejects.toThrowError('get operation has failed: API returned a 401 response');
});
test('Throws when a pre-signed URL returns a non-200 status code', async () => {

@@ -183,2 +203,22 @@ const fetcher = async (...args) => {

});
test('Throws when the API returns a non-200 status code', async () => {
const fetcher = async (...args) => {
const [url, options] = args;
const headers = options?.headers;
expect(options?.method).toBe('put');
if (url === `https://api.netlify.com/api/v1/sites/${siteID}/blobs/${key}?context=production`) {
expect(headers.authorization).toBe(`Bearer ${apiToken}`);
return new Response(null, { status: 401 });
}
throw new Error(`Unexpected fetch call: ${url}`);
};
const blobs = new Blobs({
authentication: {
token: apiToken,
},
fetcher,
siteID,
});
expect(async () => await blobs.set(key, 'value')).rejects.toThrowError('put operation has failed: API returned a 401 response');
});
});

@@ -212,2 +252,25 @@ describe('delete', () => {

});
test('Throws when the API returns a non-200 status code', async () => {
const fetcher = async (...args) => {
const [url, options] = args;
const headers = options?.headers;
expect(options?.method).toBe('delete');
if (url === `https://api.netlify.com/api/v1/sites/${siteID}/blobs/${key}?context=production`) {
expect(headers.authorization).toBe(`Bearer ${apiToken}`);
return new Response(null, { status: 401 });
}
if (url === signedURL) {
return new Response('Something went wrong', { status: 401 });
}
throw new Error(`Unexpected fetch call: ${url}`);
};
const blobs = new Blobs({
authentication: {
token: apiToken,
},
fetcher,
siteID,
});
expect(async () => await blobs.delete(key)).rejects.toThrowError('delete operation has failed: API returned a 401 response');
});
});

2

package.json
{
"name": "@netlify/blobs",
"version": "1.0.0",
"version": "1.1.0",
"description": "A JavaScript client for the Netlify Blob Store",

@@ -5,0 +5,0 @@ "type": "module",