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

@bedrock/account

Package Overview
Dependencies
Maintainers
5
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bedrock/account - npm Package Compare versions

Comparing version 8.0.0 to 8.1.0

5

CHANGELOG.md
# bedrock-account ChangeLog
## 8.1.0 - 2022-12-11
### Added
- Add optional `explain` flag to `get()`.
## 8.0.0 - 2022-04-29

@@ -4,0 +9,0 @@

19

lib/index.js

@@ -176,6 +176,10 @@ /*!

* @param {string} [options.email] - The email of the account to retrieve.
* @param {boolean} [options.explain=false] - An optional explain boolean.
*
* @returns {Promise} Resolves to `{account, meta}`.
* @returns {Promise | ExplainObject} - Returns a Promise that resolves to
* the account record (`{account, meta}`) or an ExplainObject if
* `explain=true`.
*/
export async function get({id, email} = {}) {
export async function get({id, email, explain} = {}) {
assert.optionalString(id, 'id');

@@ -195,4 +199,13 @@ assert.optionalString(email, 'email');

const record = await database.collections.account.findOne(
query, {projection: {_id: 0, account: 1, meta: 1}});
const projection = {_id: 0, account: 1, meta: 1};
const collection = database.collections.account;
if(explain) {
// 'find().limit(1)' is used here because 'findOne()' doesn't return a
// cursor which allows the use of the explain function.
const cursor = await collection.find(query, {projection}).limit(1);
return cursor.explain('executionStats');
}
const record = await collection.findOne(query, {projection});
if(!record) {

@@ -199,0 +212,0 @@ throw new BedrockError(

2

package.json
{
"name": "@bedrock/account",
"version": "8.0.0",
"version": "8.1.0",
"type": "module",

@@ -5,0 +5,0 @@ "description": "User accounts for Bedrock applications",

@@ -131,2 +131,32 @@ /*!

});
describe('Indexes', async () => {
let accountId;
// NOTE: the accounts collection is getting erased before each test
// this allows for the creation of tokens using the same account info
beforeEach(async () => {
await helpers.prepareDatabase(mockData);
accountId = mockData.accounts['alpha@example.com'].account.id;
});
it(`is properly indexed for 'id'`, async () => {
const {
executionStats
} = await brAccount.get({id: accountId, explain: true});
executionStats.nReturned.should.equal(1);
executionStats.totalKeysExamined.should.equal(1);
executionStats.totalDocsExamined.should.equal(1);
executionStats.executionStages.inputStage.inputStage.inputStage.stage
.should.equal('IXSCAN');
});
it(`is properly indexed for 'account.email'`, async () => {
const {
executionStats
} = await brAccount.get({email: 'alpha@example.com', explain: true});
executionStats.nReturned.should.equal(1);
executionStats.totalKeysExamined.should.equal(1);
executionStats.totalDocsExamined.should.equal(1);
executionStats.executionStages.inputStage.inputStage.inputStage.stage
.should.equal('IXSCAN');
});
});
}); // end get API

@@ -133,0 +163,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