npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

klark-js-plugins

v1.0.32

Published

Plugin modules for KlarkJS

Downloads

14

Readme

klark plugins

Plugin modules for KlarkJS

We are trying to create an ecosystem of utilities and functionalities that improve dramatically the automation of creating a robust API in NodeJS, ExpressJS and KlarkJS.

The main architecture that came up when we integrate a NodeJS API is the following:

  1. Receive request
  2. Check permissions
  3. Check Parameters
  4. Execute the controller
  5. Response

Hopefully, express js is organized in middlewares. We created a collection of middlewares and utilities in order to automate the CRUD functionality. The CRUD model is based on the Mongoose models.

Install plugins

  1. In the root project folder install klark-js-plugins

npm install --save klark-js-plugins

  1. Open the file that contains the Klark registration code.
var modules = `plugins/**/index.js`;
var subModules = `plugins/**/*.module.js`;

// locate the klark plugins inside the node_modules folder
var klarkPlugins = `node_modules/klark-js-plugins/plugins/**/*.js`;

klark.run({
  predicateFilePicker: function() {
    return [
      modules,
      subModules,
      klarkPlugins
    ]
  }
});

Notice

If you want to include a subset of the plugins, you should include only the corresponding internal dependencies. Let's assume that we only want to use the generators/create-user.module.js. Our configuration should look like this:

var modules = `plugins/**/index.js`;
var subModules = `plugins/**/*.module.js`;

// locate only the necessary klark plugins inside the node_modules folder
var klarkPlugins = [
    `node_modules/klark-js-plugins/plugins/generators/create-user.module.js`,
    `node_modules/klark-js-plugins/plugins/models/user/index.js`
  ];

klark.run({
  predicateFilePicker: function() {
    return [
      modules,
      subModules,
      klarkPlugins
    ]
  }
});

Example

Considering the following mongoose model:

var todoSchema = new $mongoose.Schema({
  content: {type: String, maxlength: [16], required: true}
});
var todoModel = $mongoose.model('Todo', schema);

Create a simple CRUD api

krkCrudGenerator creates and registers the CRUD functionality for a mongoose model.

KlarkModule(module, 'createSimpleTodoApi', function(krkCrudGenerator) {
  var app = // express app

  krkCrudGenerator(app, todoModel, {
    apiUrlPrefix: 'v1'
  });
});

Unauthorized creation

Request

POST http://.../v1/todo
{
  "content": "hi"
}

Response

401
{
  "code": 4001,
  "msg": "unauthorized user"
}

Authorized creation, invalid arguments

Request

HEADER Authorization: JWT ...
POST http://.../v1/todo
{
  "content": "hiiiiiiiiiiiiiiii"
}

Response

400
{
  "code": 1003,
  "msg": "invalid params, 'content' length"
}

Create a custom CRUD api

KlarkModule(module, 'createCustomTodoApi', function(krkCrudGenerator) {
  var app = // express app

  app.get(crudUrls.retrieveAll('Application'), [
    // everybody can access this route
    krkMiddlewarePermissions.check('FREE'),
    // check and sanitize all the necessary arguments like page, count etc
    krkMiddlewareParameterValidator.crud.retrieveAll(modelsApplication),
    // retrieves the records from the MongoDB
    middlewareRetrieveAllController,
    // response
    krkMiddlewareResponse.success
  ]);
});

Plugins

krkCrudGenerator

Name: krkCrudGenerator

Path: /plugins/crud-generator/index.js

Dependencies: lodash, krkMiddlewareParameterValidator, krkMiddlewarePermissions, krkMiddlewareCrudController, krkMiddlewareResponse, krkCrudGeneratorUrls


krkCrudGeneratorUrls

Name: krkCrudGeneratorUrls

Path: /plugins/crud-generator/urls.module.js


krkDbMongooseBinders

Name: krkDbMongooseBinders

Path: /plugins/db/mongoose-binders/index.js

Dependencies: lodash, mongoose, krkLogger, krkModelsApp


krkDbMongooseConnector

Name: krkDbMongooseConnector

Path: /plugins/db/mongoose-connector/index.js

Dependencies: q, mongoose, krkLogger


krkDbMongoosePluginsPassword

Name: krkDbMongoosePluginsPassword

Path: /plugins/db/mongoose-plugins/password.module.js

Dependencies: lodash, q, bcrypt, krkLogger


krkErrors

Name: krkErrors

Path: /plugins/errors/index.js

Dependencies: lodash, krkLogger


krkGeneratorsCreateUser

Name: krkGeneratorsCreateUser

Path: /plugins/generators/create-user.module.js

Dependencies: mongoose, krkModelsUser


krkGeneratorsLogin

Name: krkGeneratorsLogin

Path: /plugins/generators/login.module.js

Dependencies: krkMiddlewarePermissions


krkLogger

Name: krkLogger

Path: /plugins/logger/index.js


krkMiddlewareCrudController

Name: krkMiddlewareCrudController

Path: /plugins/middleware/crud-controller/index.js

Dependencies: lodash, q, krkDbMongooseBinders


krkMiddlewareInitiateResponseParams

Name: krkMiddlewareInitiateResponseParams

Path: /plugins/middleware/initiate-response-params/index.js

Dependencies: lodash, krkLogger, krkErrors


krkMiddlewareParameterValidator

Name: krkMiddlewareParameterValidator

Path: /plugins/middleware/parameter-validator/index.js

Dependencies: q, lodash, krkParameterValidator


krkMiddlewarePermissionsAuthorizeStrategy

Name: krkMiddlewarePermissionsAuthorizeStrategy

Path: /plugins/middleware/permissions/authorize-strategy.module.js

Dependencies: lodash, passport-jwt, krkModelsUser


krkMiddlewarePermissions

Name: krkMiddlewarePermissions

Path: /plugins/middleware/permissions/index.js

Dependencies: lodash, passport, jwt-simple, krkLogger, krkMiddlewarePermissionsRoles


krkMiddlewarePermissionsRoles

Name: krkMiddlewarePermissionsRoles

Path: /plugins/middleware/permissions/roles.module.js


krkMiddlewareResponse

Name: krkMiddlewareResponse

Path: /plugins/middleware/response/index.js

Dependencies: lodash


krkModelsApp

Name: krkModelsApp

Path: /plugins/models/app/index.js

Dependencies: mongoose


krkModelsUser

Name: krkModelsUser

Path: /plugins/models/user/index.js

Dependencies: lodash, q, mongoose, mongoose-type-email, mongoose-createdmodified, krkMiddlewarePermissionsRoles, krkDbMongoosePluginsPassword


krkNotificationsEmail

Name: krkNotificationsEmail

Path: /plugins/notifications/email.module.js

Dependencies: lodash, q, nodemailer


krkParameterValidator

Name: krkParameterValidator

Path: /plugins/parameter-validator/index.js

Dependencies: q, lodash, express-validator


krkPromiseExtension

Name: krkPromiseExtension

Path: /plugins/promise-extension/index.js

Dependencies: lodash


krkRouter

Name: krkRouter

Path: /plugins/router/index.js

Dependencies: express


krkRoutesAuthorize

Name: krkRoutesAuthorize

Path: /plugins/routers/authorize/index.js

Dependencies: lodash, q, crypto, krkLogger, krkDbMongooseBinders, krkRoutersAuthorizeVerifyAccountEmailTmpl, krkNotificationsEmail, krkMiddlewareResponse, krkParameterValidator, krkMiddlewarePermissions, krkModelsUser


krkRoutersAuthorizeVerifyAccountEmailTmpl

Name: krkRoutersAuthorizeVerifyAccountEmailTmpl

Path: /plugins/routers/authorize/verify-account-email-tmpl.module.js

Dependencies: config


krkRoutesMultimedia

Name: krkRoutesMultimedia

Path: /plugins/routers/multimedia/index.js

Dependencies: q, lodash, fs, multer, crypto, mkdirp, krkMiddlewarePermissions, krkMiddlewareResponse


krkRoutesServerInfo

Name: krkRoutesServerInfo

Path: /plugins/routers/server-info/index.js

Dependencies: krkMiddlewareResponse


krkRoutesUsers

Name: krkRoutesUsers

Path: /plugins/routers/users/index.js

Dependencies: crypto, q, lodash, krkModelsUser, krkRoutersAuthorizeVerifyAccountEmailTmpl, krkParameterValidator, krkNotificationsEmail, krkMiddlewareResponse, krkMiddlewareCrudController, krkMiddlewarePermissions


krkServer

Name: krkServer

Path: /plugins/server/index.js

Dependencies: http, krkLogger


krkUtilitiesDate

Name: krkUtilitiesDate

Path: /plugins/utilities/date.module.js

Dependencies: lodash, moment