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

saucier-core

v2.0.1

Published

Saucier. A headless-drupal set of tools.

Downloads

2

Readme

                       _           
                      (_)          
  ___  __ _ _   _  ___ _  ___ _ __ 
 / __|/ _` | | | |/ __| |/ _ \ '__|
 \__ \ (_| | |_| | (__| |  __/ |   
 |___/\__,_|\__,_|\___|_|\___|_|   
                                   
                                   

Saucier

Saucier is a Node.JS framework for helping you build headless Drupal websites.

Usage

Setup

There are two additional companion modules you can use when starting out, saucier-get and saucier-cache. These modules provide functionality that was previously baked directly into Saucier.

var env = require('./_config/env.json'),
    https = require('https'),
    saucierGet = require('saucier-get')( new https.Agent({ keepAlive: true}) ),
    saucierCache = require('saucier-cache')(),
    templates = require('./public/templates/views'),
    saucier = require('saucier-core')(saucierGet, saucierCache, templates, {
      logFormat: '\033[1;32m:remote-addr ->\033[m [:date] \033[1;35m:method :url\033[m :http-version \033[1;34m:status\033[m :res[Content-Length]',
      staticDir: 'public',
      maxAge: '4d',
      envConfig: env
    });

In this example we are using the default saucier-get and saucier-cache modules.

Saucier has four required options to function correctly, and API compatible saucier-get, saucier-cache, a templates function, and an options object. Saucier Get/Cache are explained in their own repositories.

In this instance templates is a series of compiled Dust.JS templates. You can technically use any template engine/object as long as it supports a render() function.

The following properties are expected when passing in an options object:

  • logFormat : Log Format is any Morgan compatible log string. Default is dev.

  • staticDir : This is where your static assets will be served from. Default is public.

  • maxAge : Length of time in which to cache static assets with the client. Default is 4d.

  • envConfig : REQUIRED This is an environmental configuration object.

{
  "local": {
    "environment": "local",
    "api": "https://fakeapi.ssl.dev",
    "ttl": "800",
    "maxAttempts" : 2,
    "retryDelay": 100
  }
}

Each primary object should match the environment variable set at NODE_ENV. This defaults to local.

  • api : The backend API path.
  • ttl : The TTL attached to cache keys in Redis.
  • maxAttempts : The number of attempts to try when requesting data from the backend API. Default is 2.
  • retryDelay : Delay between retrying requests to the backend API in milliseconds. Default is 100.

Routes

When creating your routes, Saucier V1 routes are compatible. The only difference is how route processors are handled. Pass the completely created Saucier object to your routes.

Routes are essentially node modules.

module.exports = function attach(app) {
  app.handleGet('/', 'example.dust', {
    resource: ['sample'],
    processors: {
      sample: function (data) {
        data.cheese = 'cake';
        return data;
      }
    }
  });
}

The function app.handleGet() is a wrapper for app.get() which supports some additional options.

  • / : The route pattern you wish to match on. Routes are processed sequentially within the file, and then sequentially in the order that they are required.
  • example.dust : This is the name of the template. That will be rendered for this route.
  • An options object:
    • resource : An array of resources to request data from. These names will be merged with the value of api from your env.json, https://fakeapi.ssl.dev/sample. These resources are are processed asynchronously and will return an object containing JSON from the backend resource.
    • processors : An object of functions that will modify the data. The data object is the response from the previously collected resources.

Extras

  • SAUCIERRENDER : An environment variable that can be set to return JSON instead of a rendered route. False is the only accepted value, SAUCIERRENDER=false
  • DEBUG=saucier:* : Saucier and each of it's core modules has a debug name space, saucier:*. Enable this to get wonderful debug output when developing your application.