# webtask-tools

> Tools to facilitate working in a webtask context

Latest version **3.4.1** (published 2019-08-27) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install webtask-tools
pnpm add webtask-tools
yarn add webtask-tools
bun add webtask-tools
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.4.1 |
| Published | 2019-08-27 |
| First published | 2015-07-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 29.1 KB |
| Known vulnerabilities | 0 (+5 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 32 |
| Author | Geoff Goodman |
| Maintainers | filearts, jcenturion, woloski |
| Keywords | webtask, auth0, server |

## Links

- npm: https://www.npmjs.com/package/webtask-tools
- Repository: https://github.com/auth0/webtask-tools
- Homepage: https://github.com/auth0/webtask-tools#readme
- Issues: https://github.com/auth0/webtask-tools/issues
- npm.io page: https://npm.io/package/webtask-tools

## Dependencies (5)

- [pug](https://npm.io/package/pug.md) ^2.0.3
- [boom](https://npm.io/package/boom.md) ^7.2.0
- [superagent](https://npm.io/package/superagent.md) ^3.8.3
- [safe-buffer](https://npm.io/package/safe-buffer.md) ^5.0.1
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^5.7.0

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 3.4.1 (latest) — 2019-08-27
- 3.4.0 — 2018-08-14
- 3.3.0 — 2018-08-02
- 3.2.1 — 2018-03-26
- 3.2.0 — 2017-01-18
- 3.1.1 — 2016-10-25
- 3.1.0 — 2016-10-14
- 3.0.0 — 2016-09-26
- 2.2.0 — 2016-06-17
- 2.1.0 — 2016-05-24
- 2.0.1 — 2016-04-28
- 2.0.0 — 2016-04-27
- 1.4.0 — 2016-04-25
- 1.3.0 — 2016-02-10
- 1.2.0 — 2015-12-17
- … 5 more at https://npm.io/package/webtask-tools/versions

## README

# Usage

This module contains helper functions to convert common http(s) servers
to functions suitable for running in a webtask.

### Example

This example shows how you can transform an entire express server into a
function suitable for using in a webtask.

**webtask.js**

```javascript
var Express = require('express');
var Webtask = require('webtask-tools');
var server = Express();

server.use(require('body-parser').json());

// Create
server.post('/', function (req, res) {
    createInMongo(req.webtaskContext.data.MONGO_URL, req.body, function (err, data) {
        if (err) return res.status(500).send("Error creating record.");
        
        res.json(data);
    });
});

// Read
server.get('/', function (req, res) {
    fetchDataFromMongo(req.webtaskContext.data.MONGO_URL, function (err, data) {
        if (err) return res.status(500).send("Error reading record.");
        
        res.json(data);
    });
});

// Update
server.put('/', function (req, res) {
    updateInMongo(req.webtaskContext.data.MONGO_URL, req.body, function (err, data) {
        if (err) return res.status(500).send("Error updating record.");
        
        res.json(data);
    });
});

// Delete
server.del('/', function (req, res) {
    removeFromMongo(req.webtaskContext.data.MONGO_URL, function (err, data) {
        if (err) return res.status(500).send("Error removing record.");
        
        res.json(data);
    });
});

// Expose this express server as a webtask-compatible function

module.exports = Webtask.fromExpress(server);
```

# API

## Runner.fromConnect(connectServer)

*Alias: `Runner.fromExpress`*

Returns a function that will inject a single request into the supplied server
with the 3-argument webtask signature:

```javascript
function (context, req, res) {}
```

The webtask `context` object will be available as `req.webtaskContext` from
within route handlers.


## Runner.fromServer(httpServer)

*Alias: `Runner.fromRestify`*

Returns a function that will inject a single request into the supplied server
with the 3-argument webtask signature:

```javascript
function (context, req, res) {}
```

The webtask `context` object will be available as `req.webtaskContext` from
within route handlers.

## Runner.fromHapi(hapiServer)

Returns a function that will inject a single request into the supplied server
with the 3-argument webtask signature:

```javascript
function (context, req, res) {}
```

The webtask `context` object will be available as `request.webtaskContext` from
within route handlers.

## Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues.

## Author

[Auth0](auth0.com)

## License

This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.

---
_Source: https://npm.io/package/webtask-tools · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
