@bedrock/account-http
Advanced tools
Comparing version 6.0.0 to 7.0.0
# bedrock-account-http ChangeLog | ||
## 7.0.0 - 2023-01-24 | ||
### Added | ||
- Add `post` method for updating accounts. Uses a simple post method that | ||
requires the full account to use to overwrite the existing one (whereby the | ||
`id` must continue to match) and the existing `sequence`. | ||
### Changed | ||
- **BREAKING**: Use `@bedrock/account@9`. This update changes the database | ||
record and layout for accounts in ways that incompatible with any previous | ||
releases. It also removes the `patch` method for updating, replacing it with | ||
simple overwrite + `sequence`. | ||
- **BREAKING**: Changed exposed validator names to remove `bedrock` and use | ||
simple names. | ||
### Removed | ||
- **BREAKING**: Remove `patch` method for updating accounts, replaced with | ||
simple post for account updating. | ||
## 6.0.0 - 2022-04-29 | ||
@@ -4,0 +23,0 @@ |
/*! | ||
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved. | ||
* Copyright (c) 2019-2023 Digital Bazaar, Inc. All rights reserved. | ||
*/ | ||
@@ -7,6 +7,6 @@ import * as bedrock from '@bedrock/core'; | ||
import * as validators from '../schemas/bedrock-account-http.js'; | ||
import {ensureAuthenticated, optionallyAuthenticated} from '@bedrock/passport'; | ||
import {asyncHandler} from '@bedrock/express'; | ||
import boolParser from 'express-query-boolean'; | ||
import {createValidateMiddleware} from '@bedrock/validation'; | ||
import {ensureAuthenticated, optionallyAuthenticated} from '@bedrock/passport'; | ||
import intParser from 'express-query-int'; | ||
@@ -167,6 +167,5 @@ import {v4 as uuid} from 'uuid'; | ||
app.patch( | ||
app.post( | ||
accountPath, | ||
ensureAuthenticated, | ||
intParser(), | ||
createValidateMiddleware({bodySchema: validators.update()}), | ||
@@ -179,8 +178,5 @@ asyncHandler(async (req, res) => { | ||
* @param {Function} next | ||
* @description Patch requests to /:account result in an updated account | ||
* patches need to be in the: | ||
* [json patch format]{@link https://tools.ietf.org/html/rfc6902} | ||
* [we use fast-json]{@link https://www.npmjs.com/package/fast-json-patch} | ||
* for handling json patches. | ||
* The body needs to contains the id, patch, and sequence keys. | ||
* @description Posts to /:account result in an updated account | ||
* The body needs to contains the new account and existing account | ||
* sequence. | ||
*/ | ||
@@ -200,3 +196,4 @@ const {account: id} = req.params; | ||
_checkAccount({req, id}); | ||
const record = await brAccount.get({id}); | ||
const {account, meta} = await brAccount.get({id}); | ||
const record = {account, meta}; | ||
res.json(record); | ||
@@ -203,0 +200,0 @@ })); |
{ | ||
"name": "@bedrock/account-http", | ||
"version": "6.0.0", | ||
"version": "7.0.0", | ||
"type": "module", | ||
@@ -30,6 +30,6 @@ "description": "HTTP API for Bedrock User Accounts", | ||
"express-query-int": "^3.0.0", | ||
"uuid": "^8.3.2" | ||
"uuid": "^9.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@bedrock/account": "^8.0.0", | ||
"@bedrock/account": "^9.0.0", | ||
"@bedrock/core": "^6.0.0", | ||
@@ -44,7 +44,7 @@ "@bedrock/express": "^8.0.0", | ||
"devDependencies": { | ||
"eslint": "^7.32.0", | ||
"eslint-config-digitalbazaar": "^2.8.0", | ||
"eslint-plugin-jsdoc": "^37.9.7", | ||
"jsdoc-to-markdown": "^7.1.1" | ||
"eslint": "^8.32.0", | ||
"eslint-config-digitalbazaar": "^4.2.0", | ||
"eslint-plugin-jsdoc": "^39.6.8", | ||
"jsdoc-to-markdown": "^8.0.0" | ||
} | ||
} |
/*! | ||
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved. | ||
* Copyright (c) 2019-2023 Digital Bazaar, Inc. All rights reserved. | ||
*/ | ||
@@ -8,3 +8,3 @@ import {schemas} from '@bedrock/validation'; | ||
return { | ||
title: 'bedrock-accounts-http account creation post', | ||
title: 'Create Account', | ||
type: 'object', | ||
@@ -21,3 +21,3 @@ required: ['email'], | ||
return { | ||
title: 'bedrock-accounts-http get', | ||
title: 'Get Accounts', | ||
type: 'object', | ||
@@ -46,8 +46,20 @@ required: ['email'], | ||
return { | ||
title: 'bedrock-accounts-http account update', | ||
required: ['patch', 'sequence'], | ||
title: 'Update Account', | ||
required: ['account', 'sequence'], | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
patch: schemas.jsonPatch(), | ||
account: { | ||
title: 'Account', | ||
type: 'object', | ||
required: ['id', 'email'], | ||
additionalProperties: true, | ||
properties: { | ||
id: { | ||
type: 'string', | ||
minLength: 0 | ||
}, | ||
email: schemas.email() | ||
} | ||
}, | ||
sequence: { | ||
@@ -63,3 +75,3 @@ type: 'integer', | ||
return { | ||
title: 'bedrock-accounts-http patch set status', | ||
title: 'Set Account Status', | ||
required: ['status'], | ||
@@ -66,0 +78,0 @@ type: 'object', |
/*! | ||
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved. | ||
* Copyright (c) 2019-2023 Digital Bazaar, Inc. All rights reserved. | ||
*/ | ||
import * as helpers from '../helpers.js'; | ||
import {_deserializeUser} from '@bedrock/passport'; | ||
import {config} from '@bedrock/core'; | ||
@@ -10,3 +11,2 @@ // apisauce is a wrapper around axios that provides improved error handling | ||
import {mockData} from '../mock.data.js'; | ||
import {_deserializeUser} from '@bedrock/passport'; | ||
import {v4 as uuid} from 'uuid'; | ||
@@ -91,3 +91,3 @@ | ||
const result = await api.post('/'); | ||
validationError(result, 'post', /email/i); | ||
validationError(result, 'Create Account', /email/i); | ||
}); | ||
@@ -118,3 +118,3 @@ | ||
result.data.message.should.equal(`A validation error occured in the ` + | ||
`'bedrock-accounts-http account creation post' validator.`); | ||
`'Create Account' validator.`); | ||
result.data.details.httpStatusCode.should.equal(400); | ||
@@ -241,15 +241,16 @@ }); | ||
const result = await api.post(`/${id}/status`); | ||
validationError(result, 'patch', /status/i); | ||
validationError(result, 'Set Account Status', /status/i); | ||
}); | ||
}); | ||
describe('patch /:account', function() { | ||
describe('update /:account', function() { | ||
it('should update an account', async function() { | ||
const {account: {id}} = accounts[emails.updated]; | ||
const {account: existingAccount} = accounts[emails.updated]; | ||
stubPassportStub(emails.updated); | ||
const value = 'updated@tester.org'; | ||
const patch = [{op: 'replace', path: '/email', value}]; | ||
const patchResult = await api.patch(`/${id}`, {sequence: 0, patch}); | ||
patchResult.status.should.equal(204); | ||
const getResult = await api.get(`/${id}`); | ||
const updatedAccount = {...existingAccount, email: value}; | ||
const updateResult = await api.post( | ||
`/${existingAccount.id}`, {sequence: 0, account: updatedAccount}); | ||
updateResult.status.should.equal(204); | ||
const getResult = await api.get(`/${existingAccount.id}`); | ||
getResult.status.should.equal(200); | ||
@@ -266,26 +267,28 @@ const {data} = getResult; | ||
it('should fail if there are no patches', async function() { | ||
it('should fail if no account is in the body', async function() { | ||
const {account: {id}} = accounts['alpha@example.com']; | ||
stubPassportStub(emails.alpha); | ||
const result = await api.patch(`/${id}`, {sequence: 10, patch: []}); | ||
validationError(result, 'update', /items/i); | ||
const result = await api.post(`/${id}`, {sequence: 10}); | ||
validationError(result, 'Update Account', /account/i); | ||
}); | ||
it('should fail if there are extra paramaters', async function() { | ||
const {account: {id}} = accounts['alpha@example.com']; | ||
const {account: existingAccount} = accounts['alpha@example.com']; | ||
stubPassportStub(emails.alpha); | ||
const value = 'fail@extras.org'; | ||
const patch = [{op: 'replace', path: '/email', value}]; | ||
const result = await api | ||
.patch(`/${id}`, {sequence: 10, patch, extra: true}); | ||
validationError(result, 'update', /additional/i); | ||
const updatedAccount = {...existingAccount, email: value}; | ||
const result = await api.post(`/${existingAccount.id}`, { | ||
sequence: 10, account: updatedAccount, extra: true | ||
}); | ||
validationError(result, 'Update Account', /additional/i); | ||
}); | ||
it('should fail if there is no sequence', async function() { | ||
const {account: {id}} = accounts['alpha@example.com']; | ||
const {account: existingAccount} = accounts['alpha@example.com']; | ||
stubPassportStub(emails.alpha); | ||
const value = 'updated@tester.org'; | ||
const patch = [{op: 'replace', path: '/email', value}]; | ||
const result = await api.patch(`/${id}`, {patch}); | ||
validationError(result, 'update', /sequence/i); | ||
const updatedAccount = {...existingAccount, email: value}; | ||
const result = await api.post( | ||
`/${existingAccount.id}`, {account: updatedAccount}); | ||
validationError(result, 'Update Account', /sequence/i); | ||
}); | ||
@@ -297,3 +300,3 @@ }); | ||
const result = await api.get('/'); | ||
validationError(result, 'get', /email/i); | ||
validationError(result, 'Get Accounts', /email/i); | ||
}); | ||
@@ -339,3 +342,3 @@ | ||
const result = await api.get('/', {email}); | ||
validationError(result, 'accounts', /email/i); | ||
validationError(result, 'Get Accounts', /email/i); | ||
}); | ||
@@ -347,3 +350,3 @@ | ||
const result = await api.get('/', {email, extra: true}); | ||
validationError(result, 'accounts', /additional/i); | ||
validationError(result, 'Get Accounts', /additional/i); | ||
}); | ||
@@ -350,0 +353,0 @@ |
@@ -27,3 +27,3 @@ { | ||
"@bedrock/core": "^6.0.0", | ||
"@bedrock/account": "^8.0.0", | ||
"@bedrock/account": "^9.0.0", | ||
"@bedrock/account-http": "file:..", | ||
@@ -30,0 +30,0 @@ "@bedrock/express": "^8.0.0", |
/*! | ||
* Copyright (c) 2016-2022 Digital Bazaar, Inc. All rights reserved. | ||
* Copyright (c) 2016-2023 Digital Bazaar, Inc. All rights reserved. | ||
*/ | ||
import {passport} from '@bedrock/passport'; | ||
import sinon from 'sinon'; | ||
import {passport} from '@bedrock/passport'; | ||
global.passportStub = sinon.stub(passport, 'authenticate'); | ||
@@ -7,0 +7,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38881
722
+ Added@bedrock/account@9.1.0(transitive)
+ Addeduuid@9.0.1(transitive)
- Removeduuid@8.3.2(transitive)
Updateduuid@^9.0.0