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

trivial-core

v1.6.4

Published

Build event processors to apply business rules

Downloads

80

Readme

Trivial-Core

Build event-driven apps from templates. Full documentation at trivial-js.org.

Getting Started

Building an example webhook processor app from a template.

const { AppBuilder, AppTemplate } = require('trivial-core')

async function WriteExample() {
  const template = new AppTemplate('webhook_relay', '0.1')
  const builder = new AppBuilder()
  let manifest = await template.initialManifest()
  manifest.app_id = 'WebhookRelayDemo'
  builder.writeLocally(manifest)
}

WriteExample()

// Expected output

// [AppBuilder]    Starting to write 'WebhookRelayDemo'
// [AppBuilder]    Building...
// [CodeGenerator] Generating code...
// [CodeGenerator] Done
// [AppBuilder]    Done!
// [AppBuilder]    Results at ./slugs/WebhookRelayDemo

To run the app:

node slugs/WebhookRelayDemo/serve.js

Your app is now ready to receive POST requests at http://localhost:5000/webhooks/receive

with a JSON body, eg:

{
    "name": "Kvothe",
    "nickname": "Kingkiller"
}

Running Tests

npm test
//  Expected output

//> [email protected] test
//> mocha 'test/**/*.js'
//  ...
//  456 passing (784ms)
//  2 pending

General Development

When running trivial-core it is necessary to build the ActionRegistry

In a local or server environment this is accomplished by entering the containing directory and running npm run build which includes all necessary logic.

However, when using trivial-core as dependency in a project or within a container you will need to construct the ActionRegistry as a part of your build step.

For example, if running your project within Docker you might create a build.js script to run as a part of your Dockerfile:

# build.js
const { ActionRegistry } = require('trivial-core')
const actionRegistry = new ActionRegistry()

console.log("Building ActionRegistry...")

try {
  actionRegistry.build()
  console.log("ActionRegistry built")
} catch (err) {
  console.log("Failed to build ActionRegistry")
  console.error(err)
}

# package.json
[other package information]
"scripts": {
  [your other scripts]
  "build": "node build.js"
}

# dockerfile
[other build logic]
RUN npm run build

Local Development

If you're making changes to this package while working on a project that imports this library, you'll want to link your project to the local version. This will let you use the unpublished version, without pushing to npm and re-installing. More info in the NPM Documentation

Note: If the Node versions are not the same for the package and the project you're importing into, npm link fail silently.

Make a global link to the local package directory:

cd ./trivial-core
nvm use vX.X.X # X.X.X should be match the dependent project's node version
npm link

In your example project, link to the unpublished version:

cd ../sample-project
npm link trivial-core

Install into your example app:

npm install trivial-core --package-lock-only

External Actions

You can supplement the catalog of actions trivial-core ships with.

Using gulp or a similar pre-builder, copy the action files into the package's action directory and build:

const { ActionRegistry } = require('trivial-core')
const actionRegistry = new ActionRegistry()

// Copy the files from your app into the package
function copyActionFiles(){
  return gulp.src(`source/lib/actions/**`) // this is the location of the new actions in your project
    .pipe(gulp.dest(`${actionRegistry.actionsRoot}/actionsv2/actions`)) // internal action location; unlikely you need to change this
}

// Define a gulp task to call the copyActionFiles function, then rebuild the registry
gulp.task('build', gulp.series(copyActionFiles, actionRegistry.build)

// In the shell, run the gulp task to copy the files to trivial-core and rebuild the action library files.
gulp build

Publishing

Bump the version following the symantic versioning spec. Commit and push. Then:

npm publish