Coder Social home page Coder Social logo

zenginehq / zn-backend-webhooks Goto Github PK

View Code? Open in Web Editor NEW
0.0 11.0 2.0 485 KB

Helper module for working with Webhooks in Zengine backend plugins.

Home Page: https://zenginehq.github.io/zn-backend-webhooks/

License: MIT License

JavaScript 100.00%

zn-backend-webhooks's Introduction

Backend Webhooks

Helper module for working with Webhooks in Zengine backend Plugins.

Coverage Status Build Status npm version

Installation

npm i @zenginehq/backend-webhooks --save

Usage

var $webhook = require('@zenginehq/backend-webhooks');
var $firebase = require('@zenginehq/backend-firebase');
var $api = require('@zenginehq/backend-http');

var workspaceId; // from eventData
var activity; // from eventData

// Load settings from firebase.
$firebase.load(workspaceId).then(function (settings) {
  if (!$webhook.validateSecret(settings, eventData.request)) {
    return eventData.response.status(403).send('Invalid Webhook Key');
  }

  // Load activity.
  return $api.getActivity(activity.id).then(function (fullActivity) {
    if ($webhook.activityToFolder(fullActivity, settings.submittedFolder)) {
      // Do something.
    }
    
    // You can also make sure the activity didn't come from a specific folder.
    if (!$webhook.activityFromFolder(fullActivity, settings.submittedFolder)) {
    	// Do something else.
    	// $api.moveToFolder(approcvedfolder);
    }
  });
});

Methods

validateSecret(settings, request)

Returns whether the webhook id and secret match what's stored in settings.

Out of the box expects the id to be stored in settings.webhookId and the key in settings.webhookKey.

You can customize this by calling $webhook.setIdField('myIdField) and $webhook.setKeyField('myKeyField').

activityToFolder(activity, toFolder)

Returns whether the given activity is a move to the specified folder (ie: record moved from a folder into this one)

activityFromFolder(activity, toFolder)

Returns whether the given activity is a move from the specified folder (ie: record moved from this folder this another one)

API Docs

Full documentation

zn-backend-webhooks's People

Contributors

tehpsalmist avatar

Watchers

Ted Kulp avatar Anthony Putignano avatar Everton Yoshitani avatar James Cloos avatar David McNelis avatar A Park(s) avatar  avatar Juan Scarton avatar  avatar Joe avatar  avatar

zn-backend-webhooks's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.