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

@everestate/serverless-router-dynamics

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@everestate/serverless-router-dynamics

Serverless Router plugin to handle Microsoft Dynamics Webhooks

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@everestate/serverless-router-dynamics npm version

Serverless Router plugin to handle Microsoft Dynamics Webhooks

Installation

npm install @everestate/serverless-router @everestate/serverless-router-dynamics --save

Usage

const Router = require('@everestate/serverless-router');
const Dynamics = require('@everestate/serverless-router-dynamics');

const leadService = require('../services/userService');

function dispatch(event) {
  const router = new Router([Dynamics]);

  router.dynamics
    .create('lead', ({ id, entity }) => {
      console.log(`Lead "${id} is created"`);
      return leadService.create(id, entity); // returns promise
    })
    .update('lead', ({ id, entity }) => {
      console.log(`Lead "${id} is updated"`);
      return leadService.update(id, entity); // returns promise
    })
    .delete('lead', ({ id }) => {
      console.log(`Lead "${id} is deleted"`);
      return leadService.delete(id); // returns promise
    })
    .assign('lead', ({ id, entity }) => {
      console.log(`New agent assigned to lead with "id: ${id}"`);
      return leadService.assign(id, entity); // returns promise
    });

  router.mismatch(() => {
    const {
      'x-ms-dynamics-request-name': requestName,
      'x-ms-dynamics-entity-name': entityName,
    } = event.headers;
    return Promise.reject(new Error(`Unknown route: ${requestName} ${entityName}`));
  });

  return router.dispatch(event);
}

function myLambdaHandler(event, context, callback) {
  return dispatch(event)
    .then(result =>
      callback(null, { statusCode: result.code, body: JSON.stringify({ payload: result.payload }) }))
    .catch(error =>
      callback(null, { statusCode: '500', body: JSON.stringify({ message: error.message }) }));
}

By default serveless-router will throw error on route mismatch. It's possible to define custom behaviour on mismatch.

License

MIT

Keywords

FAQs

Package last updated on 28 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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