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

@autotelic/fastify-cloudprnt

v0.5.0

Published

Fastify plugin to run a server following the Star Micronics CloudPRNT protocol.

Downloads

58

Readme

fastify-cloudprnt

A fastify plugin to run a server that follows the Star Micronics CloudPRNT protocol.

Commit linting with Husky

The npm postinstall script has been removed as it fails on the GH action runner. If you would like lint-staged to run on each commit, run husky install manually.

Usage

import fastifyCloudPrnt from '@autotelic/fastify-cloudprnt'
import view from '@fastify/point-of-view'

export default async function basic (fastify, options) {
  // point-of-view must be registered and available before fastify-cloudprnt
  await fastify.register(view, viewConfig)

  await fastify.register(fastifyCloudPrnt, config)
}

Once the plugin is registered it exposes the CloudPRNT Protocol endpoints:

In addition it exposes:

  • POST /job to queue print jobs. Body:
{
  "token": <string>,
  "jobData": <object>
}

Returns 201 Created and echos the token back { "token": <string> }. The token should be a unique identifier for the print job - e.g. the order id if printing a receipt.

See API for config options.

See examples for working examples.

Template Rendering

Templates should be in Star Document Markup, and template rendering requires cputil to be in the path. The provided Dockerfile builds a container with the app and cputil in. Additionally, @fastify/view must be registered to fastify before fastify-cloudprnt.

Star Micronics provides a Star Document Markup Designer web app.

API

@autotelic/fastify-cloudprnt exports a fastify plugin. When registered the plugin expects a configuration object:

  • queueJob: (token, jobData) => any: method that takes a url-safe string token and an object of data jobData, to be passed to point-of-view for template rendering, and adds the job to the print queue.
  • getJob: (request) => token: method that returns the url-safe string token for the next available print job on the queue. request is the fastify request object.
  • getJobData: (token, request) => object: method that returns the data object for the job enqueued with the url-safe string token. request is the fastify request object.
  • deleteJob: (token, request) => any: method that deletes the job enqueued with the url-safe string token from the print queue. request is the fastify request object.
  • routePrefix: string: string which will configure a prefix for all cloudprnt routes.
  • defaultTemplate: string which will configure the default template to be joined with templatesDir and used by @fastify/point-of-view to render the template (default to receipt.stm). If jobData contains a template value, it will be used instead of the defaultTemplate.
  • templatesDir: string which will configure the directory to be joined with either the defaultTemplate or jobData.template and used by @fastify/point-of-view to render the template (default to an empty string).
  • routeOptions: object: object which will apply the configured fastify router options to all cloudprnt routes. Note: method, url, schema and handler cannot be configured through routeOptions.
  • formatPrntCommandData: (renderedReceipt) => : method that accepts the receipt rendered by @fastify/point-of-view and returns star PRNT Core command data. if configured, the formatPrntCommandData method will bypass the use of the cputil to encode receipt data in the star PRNT Core format.

Examples

Basic

An example fastify app using node-cache. To run the basic example, use the following command:

  npm run example:basic

Redis

An example fastify app using redis. To run the redis example, use the following command:

  npm run example:redis