Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

klark-js-plugins

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

klark-js-plugins

Plugin modules for KlarkJS

  • 1.0.28
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 07 Dec 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc