meseret-utils
v0.0.6
Published
A collection of handy utility functions and middleware compatible with meseret.
Downloads
6
Readme
meseret-utils
A collection of handy utility functions and middleware compatible with meseret.
Getting Started
To install, inside a meseret project:
yarn add meseret-utils
# or, using npm:
# npm i meseret-utils --save
Then, we'll need to run the configuration/setup function (called configureMeseretUtils
) at our app's entry like:
// maybe, your index.ts
import { ServerApp } from 'meseret'
import { configureMeseretUtils } from 'meseret-utils'
import { serverAppConfig } from './path/to/your/server-app-config'
export const serverApp = new ServerApp(serverAppConfig)
configureMeseretUtils({
serverApp
})
serverApp.start().catch(console.error)
Utils
Helper Functions
C.R.U.D.: a collection of functions (
add
,get
,list
,search
,edit
andremove
) that perform read and write operations on MongoDB collections (as modelled by mongoose); these functions include extensive error handling, and highly customizable querying and action plugging.email: an easy way to send an email.
Grid: a nice abstraction of GridFS, the large-file-size-capable storage system inside MongoDB.
KoaController: a controller super-class that works hand-in-hand with our handle middleware.
KoaError: an extension of
Error
(with support for errorcode
and HTTPstatus
) that is compatible with koa and ourhandle
middleware.password: a pair of functions that assist in an account's password reset process.
PhotoGrid: coming soon, in the next few feature releases.
transact: an abstraction to quickly support MongoDB's session-based multi-document ACID-compatible transactions; these require MongoDB 4+.
Koa Middleware
authenticate: handles account authentication checks using koa-passport and responds to errors graciously.
authorize: handles authorization by account roles, after implicitly calling our
authenticate
middleware.handle: a koa middleware that implicitly calls our
transact
function on ourkoa-controller
methods and nicely handles ourkoa-error
throws.login: a helper koa middleware to quickly login to an account using
koa-passport
.logout: a helper koa middleware to quickly logout from an account.
sslRedirect: a koa middleware that redirects all HTTP requests to HTTPS in "production" environments (unless other environments are passed to it).
Mongoose Models
- KeyModel: a mongoose data model used in our
password
reset functions to store unique keys (tokens).
Types
- ObjectId: a shortcut for the type
mongoose.Schema.Types.ObjectId | string
.
License
Proudly, made with ♥ in Addis Ababa.
MIT License © 2019 Kaleab S. Melkie