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

hoodie-plugin-store-crypto

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hoodie-plugin-store-crypto - npm Package Compare versions

Comparing version 2.2.2 to 2.2.3

lib/utils/doc-lock.js

12

lib/find.js

@@ -6,3 +6,2 @@ 'use strict'

var PouchDBErrors = require('pouchdb-errors')
var toId = require('@hoodie/store-client/lib/utils/to-id')

@@ -12,2 +11,3 @@ var decryptOne = require('./helpers/decrypt-one')

var isEncryptedObject = require('./utils/is-encrypted-object')
var toIdWithPrefix = require('./utils/to-id-with-prefix')

@@ -98,12 +98,2 @@ module.exports = find

function toIdWithPrefix (prefix, objectOrId) {
var id = toId(objectOrId)
if (prefix && id.substr(0, prefix.length) !== prefix) {
id = prefix + id
}
return id
}
function addPrefix (prefix, objectOrId) {

@@ -110,0 +100,0 @@ if (prefix == null || objectOrId == null) return objectOrId

@@ -11,2 +11,3 @@ 'use strict'

var remove = require('./remove')
var docLock = require('./utils/doc-lock')

@@ -27,2 +28,3 @@ module.exports = removeAll

var key = state.key
var locked = null

@@ -36,3 +38,5 @@ if (key == null || key.length < 32) {

.then(function (docs) {
var encryped = docs.map(function (doc) {
locked = docLock(docs)
var encrypted = docs.map(function (doc) {
doc._deleted = true

@@ -44,3 +48,3 @@ addTimestamps(doc)

return Promise.all(encryped)
return Promise.all(encrypted)
})

@@ -52,4 +56,4 @@

.then(function (result) {
var decryped = result.map(function (oneResult, index) {
if (!oneResult.ok) return Promise.resolve(oneResult) // error
var decrypted = result.map(function (oneResult, index) {
if (!oneResult.ok) return oneResult // error

@@ -61,6 +65,13 @@ var encryptDoc = encrypted[index]

return Promise.all(decryped)
return Promise.all(decrypted)
})
.then(function (results) {
locked.unlock()
return results
})
.catch(function (error) {
locked.unlock()
if (error.message === 'database is destroyed') { // workaround for #42

@@ -67,0 +78,0 @@ var deleted = encrypted.map(function (doc) {

@@ -11,2 +11,3 @@ 'use strict'

var updateObject = require('./utils/update-object')
var lockDocs = require('./utils/doc-lock')

@@ -34,2 +35,4 @@ module.exports = remove

var locked = lockDocs(prefix, objectsOrIds)
return find(store, state, prefix, objectsOrIds)

@@ -96,2 +99,13 @@

})
.then(
function (arg) {
locked.unlock()
return arg
},
function (err) {
locked.unlock()
throw err
}
)
}

@@ -13,2 +13,3 @@ 'use strict'

var isEncryptedObject = require('./utils/is-encrypted-object')
var docLock = require('./utils/doc-lock')

@@ -30,2 +31,3 @@ module.exports = updateAll

var key = state.key
var locked = null

@@ -122,3 +124,8 @@ if (key == null || key.length < 32) {

.then(function (objects) {
return encryptMany(key, null, objects)
locked = docLock(null, objects)
var objectsToEncrypt = objects.map(function (object, index) {
var error = locked.failed[index]
return error != null ? error : object
})
return encryptMany(key, null, objectsToEncrypt)
})

@@ -139,5 +146,12 @@

.then(function (objects) {
return decryptMany(key, objects)
})
.then(
function (objects) {
locked.unlock()
return decryptMany(key, objects)
},
function (err) {
locked.unlock()
throw err
}
)
}

@@ -5,6 +5,6 @@ 'use strict'

var PouchDBErrors = require('pouchdb-errors')
var toId = require('@hoodie/store-client/lib/utils/to-id')
var add = require('./add')
var update = require('./update')
var toId = require('./utils/to-id')

@@ -14,3 +14,3 @@ module.exports = updateOrAdd

/**
* updates existing object and encryptes, or creates otherwise.
* updates existing object and encrypts, or creates otherwise.
*

@@ -55,3 +55,3 @@ * @param {Object} store instance of a hoodie client store

if (object instanceof Error && object.status !== 404) {
return Promise.resolve(object)
return object
}

@@ -63,3 +63,3 @@

.catch(function (error) {
return Promise.resolve(error)
return error
})

@@ -66,0 +66,0 @@ }

@@ -10,2 +10,3 @@ 'use strict'

var updateObject = require('./utils/update-object')
var lockDocs = require('./utils/doc-lock')

@@ -33,2 +34,4 @@ module.exports = update

var locked = lockDocs(prefix, objectsOrIds)
return find(store, state, prefix, objectsOrIds)

@@ -50,2 +53,13 @@

})
.then(
function (arg) {
locked.unlock()
return arg
},
function (err) {
locked.unlock()
throw err
}
)
}

@@ -69,3 +83,3 @@

var mapped = oldObjects.map(function (old, index) {
if (old instanceof Error) return Promise.resolve(old)
if (old instanceof Error) return old

@@ -75,3 +89,3 @@ return updateObject(objectsOrIds[index], old, change, key, false)

.then(function (updated) {
if (updated instanceof Error) return Promise.resolve(updated)
if (updated instanceof Error) return updated

@@ -78,0 +92,0 @@ return store.update(updated._id, function updater (object) {

{
"name": "hoodie-plugin-store-crypto",
"version": "2.2.2",
"version": "2.2.3",
"description": "End-to-end crypto plugin for the Hoodie client store.",

@@ -48,7 +48,7 @@ "main": "index.js",

"devDependencies": {
"hoodie": "^28.2.8",
"hoodie": "^28.2.9",
"pouchdb-adapter-memory": "^7.1.1",
"pouchdb-core": "^7.1.1",
"pouchdb-replication": "^7.1.1",
"standard": "^14.0.0",
"standard": "^14.3.1",
"tap-spec": "^5.0.0",

@@ -55,0 +55,0 @@ "tape": "^4.11.0",

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