Natural Performance Manager
    Have ideas to improve npm?Join in the discussion! »

    @whook/http-transaction
    TypeScript icon, indicating that this package has built-in type declarations

    8.0.4 • Public • Published

    @whook/http-transaction

    Isolated HTTP Transactions for the Whook framework

    GitHub license NPM version

    Whook takes a very unusual direction when it comes to dealing with HTTP transactions. It makes requests and responses serializable 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 objects from Node HTTP ones 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.

    API

    Functions

    default(services)Promise.<WhookHTTPTransaction>

    Instantiate the httpTransaction service

    initAPM(services)Promise.<Object>

    Application monitoring service that simply log stringified contents.

    initObfuscator(services)Promise.<Object>

    Obfuscate sensible informations.

    Typedefs

    WhookHTTPTransaction

    default(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';
    
    const httpTransaction = await initHTTPTransaction({
      log: console.log.bind(console),
      time: Date.now.bind(Date),
    });

    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';
    
    const obfuscator = await initObfuscator();
    
    console.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

    Install

    npm i @whook/http-transaction

    DownloadsWeekly Downloads

    51

    Version

    8.0.4

    License

    MIT

    Unpacked Size

    288 kB

    Total Files

    40

    Last publish

    Collaborators

    • avatar