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

@evervault/sdk

Package Overview
Dependencies
Maintainers
7
Versions
105
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@evervault/sdk - npm Package Compare versions

Comparing version 0.4.2 to 0.5.0

44

index.js

@@ -121,16 +121,36 @@ /** @format */

}),
})
.then((res) => {
if (!res.ok) {
throw Errors.mapStatusToError(res.status, 'evervault.set', {
data: toSave,
});
}
return res.json();
})
.then((result) => {
return result;
});
}).then((res) => {
if (!res.ok) {
throw Errors.mapStatusToError(res.status, 'evervault.set', {
data: toSave,
});
}
return res.json();
});
},
unset: async function (field) {
return this.fetch(`${this.urls.api}/data/${this.appId}/${field}`, {
method: 'DELETE',
}).then((res) => {
if (!res.ok) {
throw Errors.mapStatusToError(res.status, 'evervault.unset', {
field,
});
}
return res.json();
});
},
unsetAll: async function () {
return this.fetch(`${this.urls.api}/data/${this.appId}`, {
method: 'DELETE',
}).then((res) => {
if (!res.ok) {
throw Errors.mapStatusToError(res.status, 'evervault.unsetAll');
}
return res.json();
});
},
/**

@@ -137,0 +157,0 @@ * Fetch data stored on behalf of the user from the evervault API

{
"name": "@evervault/sdk",
"version": "0.4.2",
"version": "0.5.0",
"description": "evervault Browser SDK",

@@ -5,0 +5,0 @@ "repository": {

@@ -22,5 +22,11 @@ /** @format */

.filter((key) => ['pass', 'fail'].includes(key));
//if errorMessage exists, the test has failed
const errorMessage = test.querySelector('.error');
//mocha prepends error messages with 'Error: ' which is just bloat, so trim it out
const error = errorMessage ? errorMessage.innerText.substr(7) : undefined;
return {
state: relevantClasses,
title: test.firstChild.innerText.split('\n')[0],
error,
};

@@ -46,3 +52,3 @@ });

true,
`Test failed: ${testElements[i].title}`
testElements[i].error
);

@@ -49,0 +55,0 @@ })

@@ -483,2 +483,8 @@ /** @format */

);
chai.assert(
fetchStub.calledWith(
sinon.match(new RegExp(`\/data\/${appId}$`)),
sinon.match.has('method', 'POST')
)
);
evervault.decrypt(result.data).then((decrypted) => {

@@ -496,17 +502,18 @@ chai.assert.deepEqual(

it('should let a user get all stored data', function (done) {
fetchStub.callsFake(() => {
return Promise.resolve(
getMockApiResponse(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify(mockDB)
fetchStub.resolves(
getMockApiResponse(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify(mockDB)
)
);
evervault.get().then((result) => {
chai.assert(fetchStub.calledOnce, 'Fetch was not called once');
chai.assert(
fetchStub.calledWith(
sinon.match(new RegExp(`\/data\/${appId}\/$`)),
sinon.match.has('method', 'GET')
)
);
});
evervault.get().then((result) => {
chai.assert.equal(
fetchStub.calledOnce,
true,
'Fetch was not called once'
);
chai.assert.deepEqual(

@@ -522,13 +529,19 @@ result,

it('should let a user get specfic stored data', function (done) {
fetchStub.callsFake(() => {
return Promise.resolve(
getMockApiResponse(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({ foo: mockDB.foo })
const field = 'foo';
fetchStub.resolves(
getMockApiResponse(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({ [field]: mockDB[field] })
)
);
evervault.get(field).then((result) => {
chai.assert(fetchStub.calledOnce, "Fetch wasn't called");
chai.assert(
fetchStub.calledWith(
sinon.match(new RegExp(`\/data\/${appId}\/${field}$`)),
sinon.match.has('method', 'GET')
)
);
});
evervault.get('foo').then((result) => {
chai.assert(result.foo === testData.foo);
chai.assert(result[field] === testData[field]);
done();

@@ -538,32 +551,108 @@ });

it('should throw an evervault data not found error when requesting non existent data', function (done) {
fetchStub.callsFake(() => {
return Promise.resolve(getMockApiResponse(404));
});
evervault.get('foo').catch((err) => {
it('should throw an evervault data not found error when requesting non existent data', function () {
fetchStub.resolves(getMockApiResponse(404));
const field = 'foo';
return evervault.get(field).catch((err) => {
chai.assert(
fetchStub.calledWith(
sinon.match(new RegExp(`\/data\/${appId}/${field}$`)),
sinon.match.has('method', 'GET')
)
);
chai.assert(err instanceof evervault.errors.DataNotFound);
done();
});
});
it('should throw an evervault unauthorized error when requesting without valid credentials', function (done) {
fetchStub.callsFake(() => {
return Promise.resolve(getMockApiResponse(401));
});
evervault.get('foo').catch((err) => {
it('should throw an evervault unauthorized error when requesting without valid credentials', function () {
fetchStub.resolves(getMockApiResponse(401));
const field = 'foo';
return evervault.get(field).catch((err) => {
chai.assert(
fetchStub.calledWith(
sinon.match(new RegExp(`\/data\/${appId}/${field}$`)),
sinon.match.has('method', 'GET')
)
);
chai.assert(err instanceof evervault.errors.Unauthorized);
done();
});
});
it('should throw an evervault bad request error when attempting to save invalid data', function (done) {
it('should throw an evervault bad request error when attempting to save invalid data', function () {
fetchStub.callsFake(() => {
return Promise.resolve(getMockApiResponse(400));
});
evervault.set('foo').catch((err) => {
return evervault.set('foo').catch((err) => {
chai.assert(fetchStub.calledOnce, true, 'fetch was not called');
chai.assert(
fetchStub.calledWith(
sinon.match(new RegExp(`\/data\/${appId}$`)),
sinon.match.has('method', 'POST')
)
);
chai.assert(err instanceof evervault.errors.BadRequest);
done();
});
});
it('should throw an evervault data not found error when unsetting non existent data', function () {
fetchStub.resolves(getMockApiResponse(404));
const field = 'non-existent';
return evervault.unset(field).catch((err) => {
chai.assert(fetchStub.calledOnce, true, 'fetch was not called');
chai.assert(
fetchStub.calledWith(
sinon.match(new RegExp(`\/data\/${appId}/${field}$`)),
sinon.match.has('method', 'DELETE')
),
'The request to the api had the wrong method'
);
chai.assert(err instanceof evervault.errors.DataNotFound);
});
});
it('should throw an evervault data not found error when unsetting all data before it has been set', function () {
fetchStub.resolves(getMockApiResponse(404));
return evervault.unsetAll().catch((err) => {
chai.assert(fetchStub.calledOnce, true, 'fetch was not called');
chai.assert(
fetchStub.calledWith(
sinon.match(new RegExp(`\/data\/${appId}$`)),
sinon.match.has('method', 'DELETE')
),
'The request to the api had the wrong method'
);
chai.assert(err instanceof evervault.errors.DataNotFound);
});
});
it('should return the updated data after unsetting a field', function () {
const apiResponse = getMockApiResponse(200, {}, JSON.stringify(testData));
fetchStub.resolves(apiResponse);
const field = 'some-data';
return evervault.unset(field).then(() => {
chai.assert(fetchStub.calledOnce, 'Fetch was not called');
chai.assert(
fetchStub.calledWith(
sinon.match(new RegExp(`\/data\/${appId}\/${field}$`)),
sinon.match.has('method', 'DELETE')
),
'The request to the api had the wrong method'
);
});
});
it('should return the updated data after unsetting an entire relation', function () {
const apiResponse = getMockApiResponse(200, {}, JSON.stringify({}));
fetchStub.resolves(apiResponse);
return evervault.unsetAll().then(() => {
chai.assert(fetchStub.calledOnce, 'fetch was not called');
chai.assert(
fetchStub.calledWith(
sinon.match(new RegExp(`\/data\/${appId}$`)),
sinon.match.has('method', 'DELETE')
),
'fetch was not called with the expected url and method'
);
});
});
});
});
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