Comparing version 5.0.1-beta to 5.0.2-beta
23
index.js
@@ -117,3 +117,24 @@ 'use strict' | ||
const json = await this._crypt.decrypt(doc.payload) | ||
return JSON.parse(json) | ||
const decrypted = JSON.parse(json) | ||
if ('_rev' in decrypted) { | ||
return decrypted | ||
} else { | ||
// decrypted doc has no rev. there might already be one in the db | ||
// so we have to check for it. | ||
try { | ||
const { _revisions: { ids } } = await this.get(decrypted._id, { revs: true }) | ||
decrypted._rev = `1-${ids[ids.length - 1]}` | ||
} catch (err) { | ||
if (err.name === 'not_found') { | ||
// return the rev-less doc if no rev exists for it | ||
return decrypted | ||
} else { | ||
throw err | ||
} | ||
} | ||
// original doc lacks _rev, so apply it back now that we know it | ||
doc.payload = await this._crypt.encrypt(JSON.stringify(decrypted)) | ||
await this._encrypted.put(doc) | ||
return decrypted | ||
} | ||
} else { | ||
@@ -120,0 +141,0 @@ if (!doc._id) doc._id = uuid() |
{ | ||
"name": "comdb", | ||
"version": "5.0.1-beta", | ||
"version": "5.0.2-beta", | ||
"description": "A PouchDB plugin that transparently encrypts and decrypts its data.", | ||
@@ -42,3 +42,3 @@ "main": "index.js", | ||
"tweetnacl-util": "^0.15.1", | ||
"uuid": "^8.1.0" | ||
"uuid": "^8.3.2" | ||
}, | ||
@@ -54,6 +54,6 @@ "devDependencies": { | ||
"nyc": "^15.1.0", | ||
"pouchdb": "^7.2.2", | ||
"standard": "^16.0.3", | ||
"pouchdb": "^7.3.0", | ||
"standard": "^17.0.0", | ||
"uglify-js": "^3.13.5" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
16667
162
0
Updateduuid@^8.3.2