Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
- run: npm ci

- name: unit test
run: npm test
run: npm test
31 changes: 1 addition & 30 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,7 @@ module.exports = {
// setup ignore list
this._ignore = IGNORE.concat(options.ignore || [])
// setup crypto helper
const trySetup = async () => {
// try saving credentials to a local doc
try {
// first we try to get saved creds from the local doc
const { exportString } = await this.get(LOCAL_ID)
this._crypt = await Crypt.import(password, exportString)
} catch (err) {
// istanbul ignore else
if (err.status === 404) {
// but if the doc doesn't exist, we do first-time setup
this._crypt = new Crypt(password)
const exportString = await this._crypt.export()
try {
await this.put({ _id: LOCAL_ID, exportString })
} catch (err2) {
// istanbul ignore else
if (err2.status === 409) {
// if the doc was created while we were setting up,
// try setting up again to retrieve the saved credentials.
await trySetup()
} else {
throw err2
}
}
} else {
throw err
}
}
}
await trySetup()
this._crypt = new Crypt(password, options.salt ? options.salt : null, options)
// instrument document transforms
this.transform({
incoming: async (doc) => {
Expand Down
Loading