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

@whook/http-transaction

v16.0.0

Published

Isolated HTTP Transactions for the Whook framework

Downloads

687

Readme

@whook/http-transaction

Isolated HTTP Transactions for the Whook framework

GitHub license

Whook takes a very unusual direction when it comes to dealing with HTTP transactions. It makes requests and responses serializable (thanks to WhookRequest and WhookResponse types) to:

  • only work with functions that take request and return responses ( allowing your handlers to be pure functions),
  • have easily unit testable handlers thanks to concise snapshots.

This service is intended to build those litteral objects from Node HTTP ones (famously known as req/res) before passing them to the handlers. It also keeps track of running queries and ensure it is well handled by the server before releasing it. If not, the transaction is resolved with an error response (for timeouts or when an error were catched).

API

Functions

Typedefs

initHTTPTransaction(services) ⇒ Promise.<WhookHTTPTransaction>

Instantiate the httpTransaction service

Kind: global function
Returns: Promise.<WhookHTTPTransaction> - A promise of the httpTransaction function

| Param | Type | Default | Description | | --- | --- | --- | --- | | services | Object | | The services to inject | | [services.TIMEOUT] | Number | 30000 | A number indicating how many ms the transaction should take to complete before being cancelled. | | [services.TRANSACTIONS] | Object | {} | A hash of every current transactions | | services.delay | Object | | A delaying service | | services.obfuscator | Object | | A service to avoid logging sensible informations | | [services.log] | function | | A logging function | | [services.apm] | function | | An apm function | | [services.time] | function | | A timing function | | [services.uniqueId] | function | | A function returning unique identifiers |

Example

import initHTTPTransaction from '@whook/http-transaction';
import { log } from 'node:console';

const httpTransaction = await initHTTPTransaction({
  log,
  time: Date.now.bind(Date),
});

initHTTPTransaction~httpTransaction(req, res) ⇒ Array

Create a new HTTP transaction

Kind: inner method of initHTTPTransaction
Returns: Array - The normalized request and the HTTP transaction created in an array.

| Param | Type | Description | | --- | --- | --- | | req | HTTPRequest | A raw NodeJS HTTP incoming message | | res | HTTPResponse | A raw NodeJS HTTP response |

pickFirstHeaderValue(name, headers) ⇒ string

Pick the first header value if exists

Kind: global function
Returns: string - The value if defined.

| Param | Type | Description | | --- | --- | --- | | name | string | The header name | | headers | Object | The headers map |

pickAllHeaderValues(name, headers) ⇒ Array

Pick header values

Kind: global function
Returns: Array - The values in an array.

| Param | Type | Description | | --- | --- | --- | | name | string | The header name | | headers | Object | The headers map |

initAPM(services) ⇒ Promise.<Object>

Application monitoring service that simply log stringified contents.

Kind: global function
Returns: Promise.<Object> - A promise of the apm service.

| Param | Type | Description | | --- | --- | --- | | services | Object | The services to inject | | [services.log] | function | A logging function |

initObfuscator(services) ⇒ Promise.<Object>

Obfuscate sensible informations.

Kind: global function
Returns: Promise.<Object> - A promise of an object containing the gathered constants.

| Param | Type | Description | | --- | --- | --- | | services | Object | The service dependend on | | [services.SHIELD_CHAR] | Object | The char for replacing sensible informations | | [services.MAX_CLEAR_CHARS] | Object | The maximum clear chars to display | | [services.MAX_CLEAR_RATIO] | Object | The maximum clear chars ratio to display | | [services.SENSIBLE_PROPS] | Object | Sensible properties names | | [services.SENSIBLE_HEADERS] | Object | Sensible headers names |

Example

import { initObfuscator } from '@whook/http-transaction';
import { alsoInject } from 'knifecycle';
import { log } from 'node:console';

const obfuscator = await initObfuscator();

log(obfuscator('my very secret information!));
// my ...on!

WhookHTTPTransaction

Kind: global typedef

WhookHTTPTransaction.id

Id of the transaction

Kind: static property of WhookHTTPTransaction

WhookHTTPTransaction.start ⇒ Promise.<Object>

Start the transaction

Kind: static property of WhookHTTPTransaction
Returns: Promise.<Object> - A promise to be resolved with the signed token.

| Param | Type | Description | | --- | --- | --- | | buildResponse | function | A function that builds a response |

WhookHTTPTransaction.catch ⇒ Promise

Catch a transaction error

Kind: static property of WhookHTTPTransaction
Returns: Promise - A promise to be resolved with the signed token.

| Param | Type | Description | | --- | --- | --- | | err | Error | A function that builds a response |

WhookHTTPTransaction.end ⇒ Promise.<Object>

End the transaction

Kind: static property of WhookHTTPTransaction
Returns: Promise.<Object> - A promise to be resolved with the signed token.

| Param | Type | Description | | --- | --- | --- | | response | Object | A response for the transaction |

Authors

License

MIT