meseret-utils
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

meseret-utils

A collection of handy utility functions and middleware compatible with meseret.

meseret-utils npm downloads npm code style: prettier

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 and remove) 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 error code and HTTP status) that is compatible with koa and our handle 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 our koa-controller methods and nicely handles our koa-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

Readme

Keywords

none

Package Sidebar

Install

npm i meseret-utils

Weekly Downloads

0

Version

0.0.6

License

MIT

Unpacked Size

154 kB

Total Files

128

Last publish

Collaborators

  • kaleabmelkie