0.10.19 • Published 3 years ago

@durbintech/app-webhooks v0.10.19

Weekly downloads
299
License
MIT
Repository
github
Last release
3 years ago

Durbin Technologies - App Webhooks

Do yarn add @durbintech/app-webhooks and use!

API Docs

/* It all starts with this import */
import hooks from "@durbintech/app-webhooks";

/* For the API endpoints and Middlewares */
import express from "express";
const app = express();

/* Which kind of database you are planning to use?
 * Currently we support only `typeorm` which in turn can use postgres, sql and even mongodb!
 */
hooks.use("typeorm");

/* There are certain parameters which are required for the proper functioning
 * of the webhooks. You can use `.set(param, value)` for the same
 */

/* This express app will be finally used in turn with the webhooks.
 * The `POST /authenticate` endpoint will be served via this express instance.
 */
hooks.set("express-app", app);

/* You need to set the billable units with which this app will work.
 * These billable units will be required and accounts will read and give proper pricing amount for the same.
 * The names need to unique.
 */
hooks.set("billable-units", [
  { name: "unit-name", description: "What is this unit about?" },
]);

/* When creating an app on the Admin Panel of Accounts, you will get a Client ID and
 * Client Secret. The app needs to know them for proper internal functioning.
 */
hooks.set("client-id", process.env.CLIENT_ID);
hooks.set("client-secret", process.env.CLIENT_SECRET);

/* Optional: Webhook Path. This should match with accounts' knowledge else it won't work.
 * Default is `/webhook`. It can be changed with this set parameter.
 */
hooks.set("webhook-path", "/hookmeup");

/* Bomb has been planted! Fills up Coke on Database and gets ready to serve!
 */
await hooks.arm();

/* Middlewares that app-webhooks provides you
 */

/* `hooks.authenticated()` middleware will set the req.authenticated property on Request.
 * It will now either be `false` or will have the `uuid` of the user using the app
 */
app.use(hooks.authenticated());

/* `hooks.limitOrUse("unit")` will use (by default) 1 unit of the user and will set it in the
 * billing cycle for them. [Pre-requisite: hooks.authenticated() must run before this]
 * If they have reached their limit, it will return a 400 response with "MONTHLY_QUOTA_REACHED" in the body.
 */
app.get("/use-unit", hooks.limitOrUse("unit-name"));

app.get("/custom-path", (req) => {
  if (req.authenticated)
    /* Used up (by default) 1 unit of user from their billing table
     * If they have reached their limit, it will return `false`, else it will use the 1 unit and return `true`
     */
    hooks.addTransaction(req.authenticated, "unit-name");
});

Webhook Paths for Accounts Integration

  1. For inserting/updating max credits of an account
POST /webhook/upsert-credits
Authorization: Bearer <token>

{
    "uuid": "blah-blah-blah",
    "max": [
        { "unit": "understandable-unit", "value": 180 },
        { "unit": "understandable-unit", "value": 200 }
    ]
}
  1. Every Billing Cycle - Get user's usage for Billing
POST /webhook/billing-cycle
Authorization: Bearer <token>

{
    "uuid": "blah-blah-blah"
}

Returns the user's usage before resetting it to 0.

[
  { "unit": "understandable-unit", "value": 180 },
  { "unit": "understandable-unit", "value": 200 }
]
  1. Delete an User - Remove their Permission to use the app
POST /webhook/remove-user
Authorization: Bearer <token>

{
    "uuid": "blah-blah-blah"
}

Returns the user's usage before deleting the records.

[
  { "unit": "understandable-unit", "value": 180 },
  { "unit": "understandable-unit", "value": 200 }
]
0.10.18

3 years ago

0.10.19

3 years ago

0.10.17

3 years ago

0.10.16

3 years ago

0.10.14

3 years ago

0.10.15

3 years ago

0.10.13

3 years ago

0.10.9

3 years ago

0.10.10

3 years ago

0.10.11

3 years ago

0.10.12

3 years ago

0.10.8

3 years ago

0.10.6

3 years ago

0.10.7

3 years ago

0.10.4

3 years ago

0.10.5

3 years ago

0.10.3

3 years ago

0.10.2

3 years ago

0.10.1

3 years ago

0.10.0

3 years ago

0.9.7

3 years ago

0.9.6

3 years ago

0.9.5

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.8.9

3 years ago

0.8.8

3 years ago

0.8.5

3 years ago

0.8.4

3 years ago

0.8.7

3 years ago

0.8.6

3 years ago

0.8.12

3 years ago

0.8.11

3 years ago

0.8.14

3 years ago

0.8.13

3 years ago

0.8.10

3 years ago

0.8.16

3 years ago

0.8.15

3 years ago

0.8.18

3 years ago

0.8.17

3 years ago

0.9.0

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.7.8

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago