http-utils
/
3.3.1
http-utils 3.3.1
Install from the command line:
Learn more about npm packages
$ npm install @wymp/http-utils@3.3.1
Install via package.json:
"@wymp/http-utils": "3.3.1"
About this version
This is a small typescript package providing various utilities for HTTP environments. These are built assuming Express as a HTTP request handler framework.
The utilities are:
-
logger
- Take an HTTP request/response pair and attach a logger tagged with the essential request details. Returns the same logger (stored inres.locals
) when called with the samereq
/res
pair. -
isAuthdReq
- A type guard function indicating that the object passed in has anauth
key whose value conforms to theAuth.ReqInfo
type from@wymp/types
. -
assertAuthdReq
- A type assertion function asserting the above (throws error if not). -
isBitwiseAuthdReq
- A type guard function indicating the above, but specifically for ReqInfo using bitwise client and user roles. -
isStringAuthdReq
- A type guard function indicating the above, but specifically for ReqInfo using string client and user roles (e.g. "user", "sysadmin", "employee", .....). -
authorize
- A function taking a request and anAuthSpec
and either returning true or throwing a 403 error indicating the requirements for valid authorization. Seesrc/index.ts::authorize
for more information. -
getCollectionParams
- A function that takes in query parameters and an optional set of default values and returns anApi.CollectionParams
object. -
Translator
- Instantiate this class with DB and API data definitions (and an optional value transformer) to provide an easy way to translate objects between the Wymp-standard API format and a flat DB format. Seesrc/Translator.ts
for more information.