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

paygron-core

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

paygron-core

Paygron Core

  • 1.0.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Paygron Core

A library that allows initializing all the necessary tools to build projects with ease.

Installation

npm i paygron-core

Notes

This library requires node-config and js-yaml, so both should be listed as dependencies in the package.json file.

To initialize the project, a YAML configuration file is needed in which the rules for initializing connectors, workers, and APIs will be defined.

Config

Basic configuration

appName: myApp
env: local

Connectors

Connectors will be initialized upon detecting the following configuration:

connectorA:
  default:
    connection:
      url: myservice://127.0.0.1/exampleA
  serverA:
    connection:
      url: another-url
  serverB:
    connection:
      url: another-example
      options:
        optionA: valueA
        optionB: valueB
        optionN: ...
connectorB:
  default:
    connection:
      url: myservice://127.0.0.1/exampleB

As seen above, you can specify multiple connections for each connector. The supported connectors are as follows: mysql, mongodb, rabbitmq, and redis

Connectors share the following nesting structure: connectorA.*.connection, where connectorA.default.connection will be the default connector if no particular connector is specified when initializing the library.

Cronjobs

You can register multiple cronjobs directly in the cronjobs.handlers array. Each cronjob requires the following attributes:

AttributeRequiredDefaultDescription
handlerName of the module that will be searched in src/cronjobs
enabledfalseDefine whether the cronjob should be registered. By default, it will not be registered
scheduleSchedule expression. See more here
params{}Object that will be injected into the cronjob. Useful for passing configurations.

Example:

cronjobs:
  handlers:
    - handler: myFirstCron
      enabled: true
      schedule: '* * * * *' # every minute
      params:
        any: param
        will: be pass
        to: this handler

API

Required configuration:

api:
  protocol: http
  host: 127.0.0.1
  port: 8080

The routes must be loaded at initialization time in the following way:

// index.ts
import core from 'paygron-core'
import config from 'config'

import routes from './routes'

const setup = async() => {
  const app = core( config )
  await app({ api: { routes } })
}

setup()
// routes.ts
import { RouteGroup, Deps, Context } from 'paygron-core'

const routes: RouteGroup = {
  prefix: 'api',
  namespace: 'users',
  modules: [
    {
      version: '1',
      module: 'create',
      command: 'user',
      middlewares: [],
      method: 'POST',
      handler: ( deps: Deps ) => async( ctx: Context ) => {
        ctx.body = { 'Hello': 'World' }
      },
    },
  ],
}

export default [ routes ]

Tech specs

Minimum requirements

node: 18.13.0
npm: 8.19.3

Packages

Contribute

git clone git@github.com:paygron/core.git;
cd core;
nvm i && npm i;

Testing

npm run test

Coverage

npm run coverage

FAQs

Package last updated on 25 Aug 2023

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