Giter Site home page Giter Site logo

dweigmann2 / typedwebhook.tools Goto Github PK

View Code? Open in Web Editor NEW

This project forked from inngest/typedwebhook.tools

0.0 0.0 0.0 8.11 MB

A webhook testing tool for checking payloads, with automatic type generation

Home Page: https://typedwebhook.tools/

License: GNU General Public License v3.0

Shell 0.28% JavaScript 27.36% TypeScript 17.40% CSS 6.85% HTML 0.54% Svelte 40.76% MDX 6.82%

typedwebhook.tools's Introduction

typedwebhook.tools Logo


Inngest logo
Sponsored by Inngest


A webhook testing tool which automatically creates types for incoming requests. Any incoming request which is valid JSON is automatically converted to:

Here's the website. It's free to use. Knock yourself out!

Why?

Webhooks are great! But, to use them you almost always need to generate types for the request data. Why not have that done automatically for you?

At Inngest we love events. And types. So much that our service allows you to build & deploy serverless functions that run whenever events are received (like webhooks).

We hope this tool — and Inngest — is useful for you and saves you time as a developer ✨

Example types

JSONTypeScriptCueJSON Schema
{
  "name": "Test event",
  "data": {
    "id": 1,
    "name": "Tester McTestFace",
    "by": "Inngest",
    "at": "2022-02-21T21:19:05.529Z"
  },
  "user": {
    "email": "[email protected]"
  },
  "ts": 1645478345529
}
export interface Event {
  name: string;
  data: {
    by: string;
    at: string;
    id: number;
    name: string;
  };
  user: {
    email: string;
  };
  ts: number;
};
{
  data: {
    id:   int
    name: string
    by:   string
    at:   string
  }
  user: {
    email: string
  }
  ts:   int
  name: string
}
{
  "properties":{
    "data":{
      "properties":{
        "at":{
          "type":"string"
        },
        "by":{
          "type":"string"
        },
        "id":{
          "type":"integer"
        },
        "name":{
          "type":"string"
        }
      },
      "required":[
        "id",
        "name",
        "by",
        "at"
      ],
      "type":"object"
    },
    "name":{
      "type":"string"
    },
    "ts":{
      "type":"integer"
    },
    "user":{
      "properties":{
        "email":{
          "type":"string"
        }
      },
      "required":[
        "email"
      ],
      "type":"object"
    }
  },
  "required":[
    "data",
    "user",
    "ts",
    "name"
  ],
  "type":"object"
}

Architecture

There are three main components to this app:

  • The backend, hosted using Cloudflare workers.
  • The frontend, built using SvelteKit.
  • The type generator, built using Inngest's event schema packages and ran using webassembly.

The backend runs on Cloudflare workers. It accepts requests to create webhook endpoints; to susbcribe to webhook results via websockets; and accepts requests to a webhook URL to record the webhook data.

Each webhook has it own unique UUID. While the chance of collision is extremely low, webhooks are also created with a shared secret - transmitted only once when the webhook is created. This secret must be supplied when connecting via websockets to receive any requests sent to the URL. This means that:

  • Webhooks are private
  • Webhooks are transient (no data is stored using this service; they're proxied directly to the browser)
  • Webhooks are secure

Type creation

The fun stuff! To create types from plain ol' JSON objects we use the following pipeline:

  1. Convert the JSON to a Cue type. We do this for you. Cue is fantastic. It's both type definitions and constraints in one.
  2. Use our Cue-to-Typescript package we made. This was fun. It also properly generates enums, interfaces, etc. according to best practices.
  3. Use cue's JSON schema generation capabilities.

You might be wondering - hey, this is in go, how does this run? If you guessed webassembly, give yourself a lil pat on the back! We shift this to the browser because we dont want to see your data. We believe that utilities like this should be free (this is) and should be private (hey, this is too!). If we ran this on a server then, well, we'd have to send your event to a backend. And, as explained above, the current backend runs in Cloudflare and literally proxies the request to your websocket connection.

In the future maybe we rewrite this as a go app and do this as we process the request. Who knows. This works, and it only took us a couple days to make.

Hacking away & contributing

PRs are welcome! As are issues. If you're interested in hacking on the type creation stuff, that repo is here: https://github.com/inngest/event-schemas. PRs also welcome to that repo.

Development

# Install dependencies
$ npm install
# Start local development server with live reload
$ npm run dev
# Run tests
$ npm test
# Run type checking
$ npm run types:check

License

GPL, my friend. It's open-source, and should stay that way.

typedwebhook.tools's People

Contributors

tonyhb avatar djfarrelly avatar dependabot[bot] avatar

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.