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

zeplo-sdk

v1.1.4

Published

A typed SDK for zeplo.io

Downloads

56

Readme

zeplo-sdk

NPM Downloads Mutation testing badge GitHub commit activity (branch) GitHub Repo stars GitHub contributors GitHub issues by-label Minified Size License

GitHub Sponsors

A typed SDK for zeplo.io

Getting Started

Next.js (Pages Router)

Depending on whether you're using API Routes or Router Handlers, paste the following:

Pages Router:

pages/api/queues/email.ts:

import { Queue } from "zeplo-sdk/dist/next-pages";

export default Queue(
  "api/queues/email", // 👈 the route it's reachable on
  async job => {
    await email.send( ... )
  },
  {
    baseUrl: "your-website.com",
    token: "your-zeplo-token"
  }
);

App Router:

app/api/queues/email/route.ts:

import { Queue } from "zeplo-sdk/dist/next-app";

export const EmailQueue = Queue(
  "api/queues/email", // 👈 the route it's reachable on
  async job => {
    await email.send( ... )
  },
  {
    baseUrl: "your-website.com",
    token: "your-zeplo-token"
  }
);

export const POST = EmailQueue;

Up top, we're importing Queue, which is a function that we use to declare a new Queue and export it as default.

Queue takes three arguments.

  • The first one is the location of the API Route it's been declared in. This is required for the Zeplo server to know where jobs need to be sent upon execution.
  • The second one is a worker function that actually executes the job. In this example, it sends an email.
  • The third one is a set of options, including all common options from the zeplo documentation.

Now that we declared the Queue, using it is straight forward. Simply import it and enqueue a new job:

// Pages Router
import EmailQueue from "pages/api/queues/email";
// App Router
import { EmailQueue } from "app/api/queues/email"

// could be some API route / getServerSideProps / ...
export default async (req, res) => {

  await EmailQueue.enqueue(
    ..., // job to be enqueued
    { delay: 10000 } // scheduling options
  )

};

Calling .enqueue will trigger a call to the Quirrel server to enqueue a new job. After 10 seconds, when the job is due, the Queue's worker function will receive the job payload and execute it.

Options

All common options from the zeplo documentation are available. JSDoc and Typescript typings should help you find them.

mode

There are three ways that Zeplo can be used:

  • production: Calling zeplo.to as expected. Default value.
  • direct: The easiest way to run Zeplo in your development environment is to simply remove the zeplo.to/ prefix based on an environment variable. This approach has the advantage that in development, errors are thrown directly which can lead to easier debugging 🙌. The downside is that it becomes a blocking promise and won't resolve until the endpoint is finished.
  • dev-server: Calls localhost:4747 for use with zeplo dev, a local dev server that can be used during development. It implements the same API as zeplo.to.

encryptionSecret / oldSecrets

A 32-character-long secret used for end-to-end encryption of your jobs. Can be generated using openssl rand -hex 16 or random.org. The token does tell zeplo that you enqueued the job but the token isn't carried into your endpoint, so you need a method for allowing open access for running jobs.

If your secret is leaked, move into the oldSecrets array and replace your encryptionSecret. Once all jobs that were encrypted with the old secret executed, remove oldSecrets.

serializer

By default, your jobs are serialized and deserialized using JSON.[parse,stringify]. You can replace this with your own serializer. Superjson is my favorite.

schema

By default, your deserialized jobs are just cast to your Queue<Payload> typescript type. You can provide a schema for runtime validating the type. Zod is my favorite.

Environment Variables

| Variable | Meaning | | ------------------------- | ----------------------------------------------------------------------- | | ZEPLO_TOKEN | Access token for Zeplo. | | ZEPLO_BASE_URL | The base URL of your application's deployment. | | ZEPLO_API_URL | The endpoint your Quirrel Server is running under, e.g. zeplo.to. | | ZEPLO_ENCRYPTION_SECRET | A 32-character-long secret used for end-to-end encryption of your jobs. | | ZEPLO_OLD_SECRETS | Leaked encryptionSecrets to continue decrypting them in the meantime. |