npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cloudevents-extend-api

v0.0.2

Published

CloudEvents programming model for Extend

Downloads

5

Readme

CloudEvents programming model for Extend by Auth0

This repository provides a webtask middleware that supports a simple programming model for CloudEvents. It can be used by Extend and Auth0 Webtask users to quickly and simply implement CloudEvent consumers and optionally secure it with HTTP basic authentication.

Gettig started

The JavaScript programming model for CloudEvents implemented in this module requires the user to implement a class with methods representing the supported CloudEvents events. At runtime, messages will be dispatched to specific methods of the class based on the eventType context property of the event. The class can implement any number of methods for different eventType values.

The example below shows how to create a CloudEvent handler on Auth0 Webtasks, but it is just as well applicable to Extend deployments.

First, write the webtask script:

cat > cloud-events-handler.js <<EOF
'use strict';
module.exports = ce => {
    ce.on('io.goextend.helloWorld', ctx => {
        console.log("Hello, world event received!", ctx.body);
    });
    // Register for other events here
};
EOF

Ensure you have wt-cli installed and configured (this is typically only done once):

npm install -g wt-cli
npm init

Then, create the webtask using:

wt create cloud-events-handler.js \
  --middleware cloudevents-parser \
  --middleware cloudevents-extend-api

Notice the two middleware parameters. The first one is adding support for parsing application/cloudevents+json requests, which allows accepting CloudEvents messages following the structed content mode of the HTTP binding for CloudEvents. The second middleware adds support for the simple JavaScript programming model above.

You can then take the resulting URL and use it as a consumer of CloudEvents sent over HTTP using the structured content mode. You can test your consumer by making a simple request using curl (substitute your URL in the request below):

curl -v -X POST https://tjanczuk.sandbox.auth0-extend.com/cloud-events-handler \
  -H 'Content-Type: application/cloudevents+json' \
  --data-binary '{"eventType":"io.goextend.helloWorld"}'

Authentication

The cloudevents-extend-api middleware can optionally enforce HTTP Basic authentication. To set it up, specify the username:password pair as the BASIC_AUTH secret when creating your webtask:

wt create cloud-events-handler.js \
  --middleware cloudevents-parser \
  --middleware cloudevents-extend-api \
  --secret BASIC_AUTH=username:password

You must then configure your CloudEvent producer to add HTTP Basic username:password credentials when generating the CloudEvents message. How it is done depends on the specifics of the producer.

The cloudevents-extend-api will reject unauthorized requests with HTTP 403.

Secrets

You can provide your CloudEvent handler code with secrets for communicating with external services (e.g. Slack or Twilio):

wt create cloud-events-handler.js \
  --middleware cloudevents-parser \
  --middleware cloudevents-extend-api \
  --secret TWILIO_KEY=abc \
  --secret SLACK_URL=https://...

These secrets can be accessed within the code in the following way:

'use strict';
module.exports = ce => {
    ce.on('io.goextend.helloWorld', ctx => {
        let twilio_key = ctx.secrets.TWILIO_KEY;
        let slack_url = ctx.secrets.SLACK_URL;
        // ...
    });
};

Extend Editor

You can edit the code of your CloudEvents handler using the Extend Editor by opening up a browser with wt edit cloud-events-handler:

image

Extend Editor provides an embedded experience for developing CloudEvent consumers within SaaS platforms that act as CloudEvent producers. Check out Extend by Auth0 for more.