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

apicco-lib

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apicco-lib - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

2

package.json
{
"name": "apicco-lib",
"version": "1.1.2",
"version": "1.2.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -26,2 +26,3 @@ # Apicco-lib

- [Discovery endpoint](#discovery)
- [Request body formatting](#formatting)
- [Minimal SDK](https://github.com/SokratisVidros/apicco/blob/master/sdk/README.md)

@@ -85,2 +86,10 @@ - [Versionless clients](https://github.com/SokratisVidros/apicco/blob/master/sdk/README.md)

<a name="formatting"></a>
#### Formatting
Apicco can be also used for request body conversions and formatting. Apicco uses [Joi](https://github.com/hapijs/joi). That is, if the validation convert option is on (enabled by default), a string will be converted using the specified modifiers for string.lowercase(), string.uppercase(), string.trim(), and each replacement specified with string.replace().
The converted request body can be accessed at `ctx.request.validatedBody`;
### Action files

@@ -87,0 +96,0 @@

@@ -29,4 +29,6 @@ const Boom = require('boom');

if (ctx.request.body) {
const { error } = joi.validate(ctx.request.body, schema, opts);
const { error, value } = joi.validate(ctx.request.body, schema, opts);
ctx.request.validatedBody = value;
if (!isEmpty(error)) {

@@ -44,2 +46,4 @@ switch (errorCode) {

}
} else {
console.warn('Missing ctx.request.body...');
}

@@ -46,0 +50,0 @@

@@ -7,6 +7,8 @@ /* eslint-env jest */

describe('validate({ schema, joi, joiOptions }) middleware', () => {
function mockCtx() {
function mockCtx(values = {}) {
return {
request: {
body: {}
body: {
...values
}
}

@@ -16,2 +18,21 @@ };

test('sets request.validatedBody on ctx', async () => {
const ctx = mockCtx({ foo: ' BAR ' });
const next = jest.fn();
const schema = {
foo: Joi.string()
.lowercase()
.trim()
};
await validate({
schema,
joi: Joi
})(ctx, next);
expect(ctx.request.validatedBody).toEqual({
foo: 'bar'
});
});
describe('when validation error exists', () => {

@@ -18,0 +39,0 @@ test('throws a 422 boom error including detailed error data', async () => {

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