New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@whook/whook

Package Overview
Dependencies
Maintainers
1
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@whook/whook

Build strong and efficient REST web services.

latest
Source
npmnpm
Version
21.0.1
Version published
Weekly downloads
511
93.56%
Maintainers
1
Weekly downloads
 
Created
Source

@whook/whook

Build strong and efficient REST web services.

GitHub license

whook allows you to create REST and GraphQL web services by providing its ingredients and the recipe to make it work altogether.

The recipe is your Open API (version 3.1) definition while ingredients are routes, crons, consumers, wrappers, services, commands and some environment configuration.

Quick start

npm init @whook

Looks at the repository's main README for more documentation.

API

Functions

prepareProcess(servicesNames, $)

Runs the Whook's process

prepareEnvironment($)

Prepare the Whook process environment

pickFirstHeaderValue(name, headers)string

Pick the first header value if exists

pickAllHeaderValues(name, headers)Array

Pick header values

initAPM(services)Promise.<Object>

Application monitoring service that simply log stringified contents.

initBaseURL(services)Promise.<String>

Initialize the BASE_URL service according to the HOST/PORT so that applications fallbacks to that default base URL.

initBuildConstants(constants)Promise.<Object>

Allow to proxy constants directly by serializing it in the build, saving some computing and increasing boot time of the build.

initCommands(services)Promise.<Object>

Initialize the COMMANDS service gathering the project commands.

initCronsDefinitions(services)Promise.<Object>

Initialize the CRONS_DEFINITIONS service gathering the project crons.

initCronsHandlers(services)Promise.<function()>

Initialize the Whook cron handlers used by the router to know which cron to run for a given cron name.

initCronsWrappers(services)Promise.<function()>

A simple passthrough service proxying the CRONS_WRAPPERS.

initDefinitions(services)Promise.<String>

Initialize the DEFINITIONS service.

initErrorHandler(services)Promise

Initialize an error handler for the HTTP router

initHost(services)Promise.<String>

Initialize the HOST service from ENV or auto-detection if none specified in ENV

initHTTPRouter(services)Promise

Initialize an HTTP router

initHTTPServer(services)Promise.<HTTPServer>

Initialize an HTTP server

initHTTPTransaction(services)Promise.<WhookHTTPTransaction>

Instantiate the httpTransaction service

initMainHandler(services)Promise.<function()>

An initializer to build a single Whook route handler.

initObfuscator(services)Promise.<Object>

Obfuscate sensible informations.

initPort(services)Promise.<Number>

Initialize the PORT service from ENV or auto-detection if none specified in ENV

wrapEnvForBuild(services)Promise.<Object>

Wrap the ENV service in order to filter ENV vars for the build

initRoutesDefinitions(services)Promise.<Object>

Initialize the ROUTES_DEFINITIONS service gathering the project routes definitions.

initRoutesHandlers(services)Promise.<function()>

Initialize the Whook routes handlers used by the router to know which handler to run for a given route.

initRoutesWrappers(services)Promise.<function()>

A simple passthrough service proxying the ROUTES_WRAPPERS.

initSchemaValidators(services)Promise.<Number>

Initialize the schema validator service for application schemas validation. This central place is aimed to compile schemas once and use them many times.

initWhookResolvedPlugins(services)Promise.<string>

Resolves the Whook plugins from their names

Typedefs

HTTPServer
WhookHTTPTransaction

prepareProcess(servicesNames, $) ⇒

Runs the Whook's process

Kind: global function
Returns: Object A promise of the injected services

ParamTypeDescription
servicesNamesArray.<String>Root dependencies names to instanciate and return
$KnifecycleThe Knifecycle instance to use for the run

prepareEnvironment($) ⇒

Prepare the Whook process environment

Kind: global function
Returns: Promise A promise of the Knifecycle instance

ParamTypeDescription
$KnifecycleThe Knifecycle instance to set the various services

pickFirstHeaderValue(name, headers) ⇒ string

Pick the first header value if exists

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

ParamTypeDescription
namestringThe header name
headersObjectThe headers map

pickAllHeaderValues(name, headers) ⇒ Array

Pick header values

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

ParamTypeDescription
namestringThe header name
headersObjectThe 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.

ParamTypeDescription
servicesObjectThe services to inject
[services.log]functionA logging function

initBaseURL(services) ⇒ Promise.<String>

Initialize the BASE_URL service according to the HOST/PORT so that applications fallbacks to that default base URL.

Kind: global function
Returns: Promise.<String> - A promise of a containing the actual host.

ParamTypeDefaultDescription
servicesObjectThe services BASE_URL depends on
services.ENVObjectThe process environment
services.CONFIGObjectThe injected CONFIG value
[services.PROTOCOL]ObjectThe injected PROTOCOL value
services.HOSTObjectThe injected HOST value
services.PORTObjectThe injected PORT value
[services.log]ObjectnoopAn optional logging service

initBuildConstants(constants) ⇒ Promise.<Object>

Allow to proxy constants directly by serializing it in the build, saving some computing and increasing boot time of the build.

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

ParamTypeDescription
constantsObjectThe serializable constants to gather

Example

import { initBuildConstants } from '@whook/whook';
import { alsoInject } from 'knifecycle';

export default alsoInject(['MY_OWN_CONSTANT'], initBuildConstants);

initCommands(services) ⇒ Promise.<Object>

Initialize the COMMANDS service gathering the project commands.

Kind: global function
Returns: Promise.<Object> - A promise of a containing the actual host.

ParamTypeDefaultDescription
servicesObjectThe services COMMANDS depends on
[services.WHOOK_PLUGINS]Array.<String>The activated plugins
services.WHOOK_RESOLVED_PLUGINSArrayThe resolved plugins
[services.COMMANDS_DEFINITIONS_OPTIONS]ObjectThe options to load the project commands
[services.COMMAND_DEFINITION_FILTER]ObjectA function to filter the project commands per definitions
services.importerObjectA service allowing to dynamically import ES modules
[services.log]ObjectnoopAn optional logging service

initCronsDefinitions(services) ⇒ Promise.<Object>

Initialize the CRONS_DEFINITIONS service gathering the project crons.

Kind: global function
Returns: Promise.<Object> - A promise of a containing the actual host.

ParamTypeDefaultDescription
servicesObjectThe services CRONS_DEFINITIONS depends on
[services.WHOOK_PLUGINS]Array.<String>The activated plugins
services.WHOOK_RESOLVED_PLUGINSArrayThe resolved plugins
[services.CRONS_DEFINITIONS_OPTIONS]ObjectThe options to load the project crons
[services.CRON_DEFINITION_FILTER]ObjectA function to filter the project crons per definitions
services.importerObjectA service allowing to dynamically import ES modules
[services.log]ObjectnoopAn optional logging service

initCronsHandlers(services) ⇒ Promise.<function()>

Initialize the Whook cron handlers used by the router to know which cron to run for a given cron name.

Kind: global function
Returns: Promise.<function()> - A promise of the CRONS_HANDLERS hash.

ParamTypeDefaultDescription
servicesObjectThe services CRONS_HANDLERS depends on
services.CRONS_WRAPPERSArrayAn optional list of wrappers to inject
[services.log]ObjectnoopAn optional logging service
services.CRONS_HANDLERSObjectThe rest is a hash of crons handlers mapped by name

initCronsWrappers(services) ⇒ Promise.<function()>

A simple passthrough service proxying the CRONS_WRAPPERS.

Kind: global function
Returns: Promise.<function()> - A promise of the CRONS_WRAPPERS hash.

ParamTypeDefaultDescription
servicesObjectThe services CRONS_WRAPPERS depends on
[services.CRONS_WRAPPERS_NAMES]ArrayThe global wrappers names to wrap the crons with
[services.log]ObjectnoopAn optional logging service
services.CRONS_WRAPPERSObjectThe dependencies must all be injected wrappers

initDefinitions(services) ⇒ Promise.<String>

Initialize the DEFINITIONS service.

Kind: global function
Returns: Promise.<String> - A promise of a containing the actual host.

ParamTypeDefaultDescription
servicesObjectThe services DEFINITIONS depends on
[services.ROUTES_DEFINITIONS]ObjectThe API routes modules
[services.COMMANDS_DEFINITIONS]ObjectThe commands modules
[services.CRONS_DEFINITIONS]ObjectThe crons modules
[services.log]ObjectnoopAn optional logging service

initErrorHandler(services) ⇒ Promise

Initialize an error handler for the HTTP router

Kind: global function
Returns: Promise - A promise of a function to handle errors

ParamTypeDescription
servicesObjectThe services the server depends on
services.ENVObjectThe app ENV
[services.DEBUG_NODE_ENVS]ArrayThe environnement that activate debugging (prints stack trace in HTTP errors responses)
[services.STRINGIFIERS]ObjectThe synchronous body stringifiers
[services.ERRORS_DESCRIPTORS]ObjectAn hash of the various error descriptors
[services.DEFAULT_ERROR_CODE]ObjectA string giving the default error code

initErrorHandler~errorHandler(transactionId, responseSpec, err) ⇒ Promise

Handle an HTTP transaction error and map it to a serializable response

Kind: inner method of initErrorHandler
Returns: Promise - A promise resolving when the operation completes

ParamTypeDescription
transactionIdStringA raw NodeJS HTTP incoming message
responseSpecObjectThe response specification
errYHTTPErrorThe encountered error

initHost(services) ⇒ Promise.<String>

Initialize the HOST service from ENV or auto-detection if none specified in ENV

Kind: global function
Returns: Promise.<String> - A promise of a containing the actual host.

ParamTypeDefaultDescription
servicesObjectThe services HOST depends on
[services.ENV]Object{}An optional environment object
[services.log]ObjectnoopAn optional logging service
services.importerObjectA service allowing to dynamically import ES modules

initHTTPRouter(services) ⇒ Promise

Initialize an HTTP router

Kind: global function
Returns: Promise - A promise of a function to handle HTTP requests.

ParamTypeDefaultDescription
servicesObjectThe services the server depends on
[services.BUFFER_LIMIT]StringThe maximum bufferisation before parsing the request body
[services.BASE_PATH]StringAPI base path
services.ROUTES_HANDLERSObjectThe handlers for the operations decribe by the OpenAPI API definition
services.APIObjectThe OpenAPI definition of the API
[services.PARSERS]ObjectThe synchronous body parsers (for operations that defines a request body schema)
[services.STRINGIFIERS]ObjectThe synchronous body stringifiers (for operations that defines a response body schema)
[services.ENCODERS]ObjectA map of encoder stream constructors
[services.DECODERS]ObjectA map of decoder stream constructors
[services.queryParserBuilder]ObjectA query parser builder from OpenAPI parameters
[services.COERCION_OPTIONS]ObjectOptions for type coercion of parameters values
[services.log]functionnoopA logging function
services.httpTransactionfunctionA function to create a new HTTP transaction

initHTTPRouter~httpRouter(req, res) ⇒ Promise

Handle an HTTP incoming message

Kind: inner method of initHTTPRouter
Returns: Promise - A promise resolving when the operation completes

ParamTypeDescription
reqHTTPRequestA raw NodeJS HTTP incoming message
resHTTPResponseA raw NodeJS HTTP response

initHTTPServer(services) ⇒ Promise.<HTTPServer>

Initialize an HTTP server

Kind: global function
Returns: Promise.<HTTPServer> - A promise of an object with a NodeJS HTTP server in its service property.

ParamTypeDefaultDescription
servicesObjectThe services the server depends on
[services.ENV]ObjectThe process environment variables
services.ENV.DESTROY_SOCKETSStringWhether the server sockets whould be destroyed or if the server should wait while sockets are kept alive
[services.HTTP_SERVER_OPTIONS]ObjectSee https://nodejs.org/docs/latest/api/http.html#class-httpserver
services.HOSTStringThe server host
services.PORTNumberThe server port
services.httpRouterfunctionThe function to run with the req/res tuple
[services.log]functionnoopA logging function

initHTTPTransaction(services) ⇒ Promise.<WhookHTTPTransaction>

Instantiate the httpTransaction service

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

ParamTypeDefaultDescription
servicesObjectThe services to inject
[services.TIMEOUT]Number30000A number indicating how many ms the transaction should take to complete before being cancelled.
[services.TRANSACTIONS]Object{}A hash of every current transactions
services.delayObjectA delaying service
services.obfuscatorObjectA service to avoid logging sensible informations
[services.log]functionA logging function
[services.apm]functionAn apm function
[services.time]functionA timing function
[services.uniqueId]functionA function returning unique identifiers

Example

import initHTTPTransaction from '@whook/whook';
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.

ParamTypeDescription
reqHTTPRequestA raw NodeJS HTTP incoming message
resHTTPResponseA raw NodeJS HTTP response

initMainHandler(services) ⇒ Promise.<function()>

An initializer to build a single Whook route handler.

Kind: global function
Returns: Promise.<function()> - A promise of the MAIN_HANDLER service.

ParamTypeDefaultDescription
servicesObjectThe services $autoload depends on
services.WRAPPERSArrayAn optional list of wrappers to inject
services.MAIN_WRAPPERfunctionThe main route handle wrapper
services.BASE_HANDLERfunctionThe base handler
[services.log]functionnoopAn optional logging service

initObfuscator(services) ⇒ Promise.<Object>

Obfuscate sensible informations.

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

ParamTypeDescription
servicesObjectThe service dependend on
[services.SHIELD_CHAR]ObjectThe char for replacing sensible informations
[services.MAX_CLEAR_CHARS]ObjectThe maximum clear chars to display
[services.MAX_CLEAR_RATIO]ObjectThe maximum clear chars ratio to display
[services.SENSIBLE_PROPS]ObjectSensible properties names
[services.SENSIBLE_HEADERS]ObjectSensible headers names

Example

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

const obfuscator = await initObfuscator();

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

initPort(services) ⇒ Promise.<Number>

Initialize the PORT service from ENV or auto-detection if none specified in ENV

Kind: global function
Returns: Promise.<Number> - A promise of a number representing the actual port.

ParamTypeDefaultDescription
servicesObjectThe services PORT depends on
[services.ENV]Object{}An optional environment object
[services.log]ObjectnoopAn optional logging service
services.importerObjectA service allowing to dynamically import ES modules

wrapEnvForBuild(services) ⇒ Promise.<Object>

Wrap the ENV service in order to filter ENV vars for the build

Kind: global function
Returns: Promise.<Object> - A promise of an object containing the reshaped env vars.

ParamTypeDefaultDescription
servicesObjectThe services ENV depends on
[services.PROXIED_ENV_VARS]Object{}A list of environment variable names to proxy
[services.log]ObjectnoopAn optional logging service

initRoutesDefinitions(services) ⇒ Promise.<Object>

Initialize the ROUTES_DEFINITIONS service gathering the project routes definitions.

Kind: global function
Returns: Promise.<Object> - A promise of a containing the actual host.

ParamTypeDefaultDescription
servicesObjectThe services ROUTES_DEFINITIONS depends on
[services.WHOOK_PLUGINS]Array.<String>The activated plugins
services.WHOOK_RESOLVED_PLUGINSArrayThe resolved plugins
[services.ROUTES_DEFINITIONS_OPTIONS]ObjectThe options to load the routes in the file system
[services.ROUTE_DEFINITION_FILTER]ObjectA function to filter the routes per definitions
services.importerObjectA service allowing to dynamically import ES modules
[services.log]ObjectnoopAn optional logging service

initRoutesHandlers(services) ⇒ Promise.<function()>

Initialize the Whook routes handlers used by the router to know which handler to run for a given route.

Kind: global function
Returns: Promise.<function()> - A promise of the ROUTES_HANDLERS hash.

ParamTypeDefaultDescription
servicesObjectThe services ROUTES_HANDLERS depends on
services.ROUTES_WRAPPERSArrayAn optional list of wrappers to inject
[services.log]ObjectnoopAn optional logging service
services.ROUTES_HANDLERSObjectThe rest is a hash of routesHandlers mapped by their operation id

initRoutesWrappers(services) ⇒ Promise.<function()>

A simple passthrough service proxying the ROUTES_WRAPPERS.

Kind: global function
Returns: Promise.<function()> - A promise of the ROUTES_WRAPPERS hash.

ParamTypeDefaultDescription
servicesObjectThe services ROUTES_WRAPPERS depends on
[services.ROUTES_WRAPPERS_NAMES]ArrayThe global wrappers names to wrap the routes with
[services.log]ObjectnoopAn optional logging service
services.ROUTES_WRAPPERSObjectThe dependencies must all be injected wrappers

initSchemaValidators(services) ⇒ Promise.<Number>

Initialize the schema validator service for application schemas validation. This central place is aimed to compile schemas once and use them many times.

Kind: global function
Returns: Promise.<Number> - A promise of a schema validators registry

ParamTypeDefaultDescription
servicesObjectThe services it depends on
[services.SCHEMA_VALIDATORS_OPTIONS]Object{}Options for the schema validators registry
[services.ENV]Object{}An optional environment object
[services.log]ObjectnoopAn optional logging service
services.APIObjectA valid Open API file

initWhookResolvedPlugins(services) ⇒ Promise.<string>

Resolves the Whook plugins from their names

Kind: global function
Returns: Promise.<string> - A promise of a number representing the actual port.

ParamTypeDefaultDescription
servicesObjectThe services WHOOK_RESOLVED_PLUGINS depends on
[services.WHOOK_PLUGINS]Array.<String>The activated plugins
[services.log]ObjectnoopAn optional logging service

HTTPServer

Kind: global typedef

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.

ParamTypeDescription
buildResponsefunctionA 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.

ParamTypeDescription
errErrorA 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.

ParamTypeDescription
responseObjectA response for the transaction

Authors

License

MIT

Keywords

whook

FAQs

Package last updated on 01 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts