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

robthebuilder

v0.5.1

Published

A service that handles templating over JSON-RPC

Downloads

2

Readme

robthebuilder

JSON-RPC service compiles and renders templates. It can also forward templates to an instance of postmaster to send an email.

Command-line Options

  • rpc-port: the port to listen for rpc calls on. Defaults to a random port between 8000-9999.
  • skyapi-addr: address of SkyAPI server to advertise robthebuilder to
  • postmaster-addr: address to reach postmaster instance(s)
  • templates-dir: directory to load templates from
  • addl-methods-dir: directory to load additional methods from
  • from-email: default the fromEmail param to this value
  • from-name: default the fromName param to this value
  • logger: change the default logging class (defaults to debuglog)
  • log-level: change the log level (defaults to info)

Advertising to SkyAPI is optional. Using postmaster is also optional.

modulelog is used for logging. This allows you to npm install your own logging library and pass the name to --logger.

Templates

Templates are compiled using lodash's _.template. Additional metadata in JSON format can be sent at the top of the template file in order to require params and nest templates. An example metadata block:

<!--
{
    "parent": {
        "name": "generic_base",
        "args": {"showFooter": false},
        "include_var": "body"
    },
    "params": [
        "cardLast4",
        "totalAmount"
    ]
}
-->

parent defines the parent template to load. The current template is rendered and then passed to the parent template as the include_var variable. You can also pass additional arguments to the parent.

params defines the required params that must be sent to this template in order to render it. The above example requires cardLast4 and totalAmount to be sent. Additionally, you'll have access to the escape function in order to escape params that are passed in.

For the above metadata example, the parent might look like:

<!--
{
    "params": [
        "body",
        "showFooter"
    ]
}
-->
<!DOCTYPE html><html><body>
<%= body %>
<% if (showFooter) { %>
<p> footer </p>
<% } %>
</body></html>

You can also specify a subject for emails in the template:

<!--
{
    "params": [
        "name"
    ],
    "subject": "Welcome Email"
}
-->

and if a subject is NOT sent with RenderAndEmail then it will use the one provided by the template.

RPC Methods

Rob.Render

Arguments:

  • name: (string) name of the template to render
  • params: (object) params to send to the template

Response:

{html: "<!DOCTYPE html><html><body>..."}

Rob.RenderAndEmail

Arguments:

  • name: (string) name of the template to render
  • params: (object) params to send to the template
  • toName: (optional string) name of the recipient
  • toEmail: (string) address to send the email to
  • subject: (optional string) subject of the email. Required unless template specifies a subject.
  • fromEmail: (optional string) address to send the email from. Required unless --from-email was specified.
  • fromName: (optional string) name of the sender. To fallback to --from-name don't send this property or send an empty string.
  • flags: (optional number) flags to pass along to postmaster for categorizing emails
  • uniqueID: (optional string) uniqueID for this email such as user_15_favorited_user_16. This will be used for duplicate detection.
  • dupThreshold: (optional number) minimum number of seconds required since the last time an email with the same uniqueID was sent. Dafaults to 0 which means no checking.

toName, toEmail can be sent by defining your own pre-processor using rpclib. You can store toName and toEmail on the response object using the set method and those will be used if toEmail or toName are empty. If you want to only use the pre-processor values, send an empty string for both values. Additionally, a user object can be stored on response and the name property and email property will be used for toName and toEmail, respectively. The user object will also be sent to the template if its not already defined in params. An example pre-processor can be found in tests/pre/pre.js.

In order to prevent accidential duplicate emails, you can send a uniqueID with every email and pass a dupThreshold to prevent an email from being sent twice to the same user in some amount of seconds. The uniqueID should be something unique to the email itself and NOT unique to each individual time its being sent. If you send a dupThreshold but no uniqueID it will be automatically generated by JSON'ing the params and passing that through sha512 and then base64.