Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Daniel Cooperman
    @dc00p

    Now use vandium.createInstance.

    Example:

    'use strict';
    
    const vandium = require( 'vandium' );
    
    exports.handler = vandium.createInstance( {
    
                lambdaProxy: true,
                validation: {
    
                    schema: {
    
                        body: {
    
                            firstName: vandium.types.string().min( 1 ).max( 250 ).required(),
    
                            lastName: vandium.types.string().min( 1 ).max( 250 ).required(),
    
                            age: vandium.types.number().min( 0 ).max( 130 ).required()
                        }
                    }
                }
            })
            .handler( function( event /*, context, callback*/ ) {
    
                // log event ?
                // console.log( JSON.stringify( event, null, 2 ) );
    
                // echo body portion
                return Promise.resolve( event.body );
            });

    See: https://github.com/vandium-io/vandium-node/blob/master/examples/lambda-proxy/handler.js

    Mikkel B. Jensen
    @mbejdk_twitter
    Thanks Daniel
    Mikkel B. Jensen
    @mbejdk_twitter
    @dc00p , do you have any suggestions on how to set Access-Control headers using vandium validation with Lambda Proxy? Can one specify the headers when vandium validation reports back?
    Daniel Cooperman
    @dc00p
    'use strict';
    
    const vandium = require( 'vandium' );
    
    exports.handler = vandium.createInstance( {
    
                lambdaProxy: true,
                validation: {
    
                    schema: {
    
                        headers: {
    
                            'Access-Control-...': vandium.types.string().required()
                            ...
                        }
    
                        body: {
    
                            ...
                        }
                    }
                }
            })
            .handler( function( event, context, callback ) {
    
                return {
    
                    headers: {
    
                        headerone: 'results?'
                    },
                    body: {}
                };
            });
    Mikkel B. Jensen
    @mbejdk_twitter

    Thanks @dc00p .

    However I am not able to change the headers on the response from a failed response. Check out the example below:

    'use strict'
    const vandium = require('vandium')
    
    exports.post = vandium.createInstance({
      lambdaProxy: true,
      validation: {
        schema: {
          body: {
            requirednumber: vandium.types.number().min(0).max(10).required()
          }
        }
      }
    })
    .handler(function (event, context, callback) {
    
      return {
    
        headers: {
          'Access-Control-Allow-Credentials': true,
          'Access-Control-Allow-Origin': '*'
        },
        body: {}
      }
    })

    Returns :
    { "statusCode": 422, "headers": {}, "body": "{\"type\":\"ValidationError\",\"message\":\"validation error: child \\\"requirednumber\\\" fails because [\\\"requirednumber\\\" is required]\"}" }
    So vandium basically skips the handler, when the validation fails and therefore does not set the headers?

    Daniel Cooperman
    @dc00p
    Correct
    Steve Schwarz
    @saschwarz
    Hi, I just heard about vandium are there any docs on how to deploy and run on lambda?
    Liz Rosa
    @erosa

    I'm using Vandium to process POST requests from API Gateway. I have a pretty vanilla implementation so far. The handler works as expected without validation, but as soon as I add the validation step, I get this error:

    {
      "type": "ValidationError",
      "message": "\"value\" must be an object"
    }

    My code looks more or less like this:

    const vandium = require('vandium');
    
    exports.handler = vandium.api()
      .protection({mode: 'fail'})
      .GET(event => {
      // ...
      })
      .POST({
        //validate
        body: {
          name: vandium.types.string().max(255).required(),
          id: vandium.types.number()
        }
      },
      (event, context) => {
        return new Promise((resolve, reject) => {
          conn.query('select * from user',
            (error, results, fields) => {
              if (error) {
                reject(error);
              } else {
                resolve(results);
              }
            });
        });
      });

    ...and the sample payload I'm using is {name: "Liz", id: "1234"}. The code does exactly what I want as long as I leave out the validation argument from the .POST() handler. Looks like a Joi error bubbling up through Vandium. Am I missing something here?

    Liz Rosa
    @erosa
    Never mind — my inexperience with Javascript and API programming is showing. Quote your JSON keys.
    Richard kim
    @Rkim01_twitter

    Hi there,

    the exact validation error brought me here (nothing in github issues)

    I'm using Vandium with Serverless Framework.
    According to Serverless Framework, requests templates application/json & application/x-www-form-urlencoded are supported out of the box.
    https://serverless.com/framework/docs/providers/aws/events/apigateway#default-request-templates

    On my vandium POST method handler,
    when i do :

    curl -X POST \
      http://localhost:3000/users \
      -H 'Content-Type: application/json' \
      -d '{ "firstName": "first", "lastName": "last", "age": 1 }'

    it works as expected

    but when i do :

    curl -X POST \
      http://localhost:3000/users \
      -H 'Content-Type: application/x-www-form-urlencoded' \
      -d 'firstName=first&lastName=last&age=1'

    it throws validation errors :

    {
        "type": "ValidationError",
        "message": "\"value\" must be an object"
    }

    here is the handler :

    module.exports.post = vandium.api()
        .callbackWaitsForEmptyEventLoop(false)
        .POST(
            {
                body: {
                    firstName: vandium.types.string().min(1).max(250).required(),
                    lastName: vandium.types.string().min(1).max(250).required(),
                    age: vandium.types.number().min(1).max(130)
                }
            },
            (event) => { ... });

    How could i solve this to support both content-types seamlessly?

    the API Gateway event is respectively showing
    body: '{ "firstName": "AHDOUHAGIUGAI", "lastName": "Dre", "age": 1 }',
    and
    body: 'firstName=test&lastName=azhdaa&age=2',

    Rayat Rahman
    @riotrah
    Not sure I have an answer for that yet - perhaps a PR is needed if no one responds.
    But I DO have another quick question: validating request supports a JOI like syntax - but can I pass a Joi schema directly?
    I'm already defining some isometric models/schemas for certain objects via Joi and it would be easiest to just be able to pass a Joi schema to queryParameters or body etc
    Rayat Rahman
    @riotrah
    It appears that since the current default (and only) validation provider (for the types at least) is joi with some wrappers for emails and uuid, joi schemas should work no?
    Rayat Rahman
    @riotrah
    Hi guys, I'm trying to add FormURLEncoding to the post body but I don't want to rewrite qs parsing code - I don't see any obvious qs parsing dependencies and I've searched thru the codebase trying to find where the querystring parsing for GET requests is done.
    igalmarino
    @igalmarino
    Hi guys, im trying to create a validation using string notation
    Something llke this
    consumerEntryMode: 'string:valid=[KEYENTERED,MANUALLYENTERED,ONFILE],required'
    i want to validate that consumerEntryMode can only be one of the 3 values [KEYENTERED,MANUALLYENTERED,ONFILE]
    but is not working
    a can do it with the object notation
    consumerEntryMode: vandium.types.string().valid('KEYENTERED', 'MANUALLYENTERED', 'ONFILE').required()
    Any idea on how to do this on string notation ?
    Jairo Cisneros
    @jcisneros1_gitlab
    Maybe with pattern vandium.types.string().required().pattern(/\b(?:KEYENTERED|MANUALLYENTERED|ONFILE)\b/),
    Rafay Taher
    @rafaytaher

    Hello I'm a newbie and was wsorking on serverless project where next step is to use vandium, I have installed vandium but now i'm trying to use it in my existing function but I get this error: Failure: Object(...) is not a function.
    below is how i am using it :

    import { vandium } from 'vandium';
    const action = vandium((event, context, cb) => {

    cb(null, getCustomerById(event));

    });
    ......
    export {action}

    Also i'm getting a warning on import statement over vandium "Could not find a declaration file for module 'vandium'."

    Rafay Taher
    @rafaytaher

    ok I got it. I have used following method
    const vandium = require('vandium');
    vandium.generic()
    .handler(event, context, cb) => {

    cb(null, getCustomerById(event));
    });
    generic, as per documentation, is an event type allows you to handle any type of Lambda event from any source.