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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bagdock/worker-sdk

v0.1.0

Published

SDK for building Bagdock platform workers — lifecycle hooks, typed comms contract, webhook verification

Downloads

244

Readme

  ----++                                ----++                    ---+++     
  ---+++                                ---++                     ---++      
 ----+---     -----     ---------  --------++ ------     -----   ----++----- 
 ---------+ --------++----------++--------+++--------+ --------++---++---++++
 ---+++---++ ++++---++---+++---++---+++---++---+++---++---++---++------++++  
----++ ---++--------++---++----++---+++---++---++ ---+---++     -------++    
----+----+---+++---++---++----++---++----++---++---+++--++ --------+---++   
---------++--------+++--------+++--------++ -------+++ -------++---++----++  
 +++++++++   +++++++++- +++---++   ++++++++    ++++++    ++++++  ++++  ++++  
                     --------+++                                             
                       +++++++                                               

@bagdock/worker-sdk

Platform SDK for building Bagdock adapter workers on Cloudflare Workers — lifecycle hooks, typed comms contract, webhook verification primitives, and error boundaries.

npm version License: MIT

Install

npm install @bagdock/worker-sdk
yarn add @bagdock/worker-sdk
pnpm add @bagdock/worker-sdk
bun add @bagdock/worker-sdk

Requires @cloudflare/workers-types as a peer dependency.

Quick start

import { createCommsWorker } from '@bagdock/worker-sdk'
import type { HandlerContext } from '@bagdock/worker-sdk'

interface Env {
  TELNYX_API_KEY: string
  OPERATOR_CONFIG?: KVNamespace
}

async function handleSmsSend(ctx: HandlerContext<Env>): Promise<Response> {
  const { to, body } = await ctx.request.json() as { to: string; body: string }
  // Call your vendor's SMS API using ctx.env for secrets
  return Response.json({ id: crypto.randomUUID(), status: 'queued' })
}

export default createCommsWorker<Env>({
  capabilities: ['sms'],

  async onInstall(ctx) {
    // Provision vendor resources, store per-installation state
    await ctx.store.put('api_key', 'vendor-key-from-provisioning')
    return { installation_state: { provisioned: true } }
  },

  async onUninstall(ctx) {
    // Clean up vendor resources
  },

  routes: {
    'sms/send': handleSmsSend,
  },
})

What the SDK handles

| Concern | You write | SDK handles | |---------|-----------|-------------| | Lifecycle | onInstall / onUninstall hooks | Idempotency flags, retry safety, dual-write to platform state | | Routing | Route handlers as functions | __platform/setup, __platform/teardown, health, dispatch routing, 404s | | Comms contract | Declare capabilities | Compile-time route enforcement per capability (SMS, voice, numbers) | | Health | Optional vendor reachability check | Auto-generated health response, 15s TTL cache, in-flight dedup | | Webhooks | Adapter-local VerifyFunction | Clone-based body handoff, structured 401/500 error responses | | Errors | Nothing | Structured JSON errors with timing headers, global error boundary |

Webhook verification

The SDK is vendor-agnostic — it knows nothing about Telnyx, Stripe, Shopify, or any other vendor. Webhook verification follows the same pattern every major platform uses: the vendor who signs the webhook publishes the SDK that verifies it.

Default path: vendor SDK (recommended)

// src/verify.ts — adapter-local, wraps the vendor's own SDK
import Telnyx from 'telnyx'
import type { VerifyFunction } from '@bagdock/worker-sdk'
import type { Env } from './types'

const client = new Telnyx()

export const telnyxWebhookVerify: VerifyFunction<Env> = async (request, env, body) => {
  try {
    await client.webhooks.unwrap(body, {
      headers: {
        'telnyx-signature-ed25519': request.headers.get('telnyx-signature-ed25519') ?? '',
        'telnyx-timestamp': request.headers.get('telnyx-timestamp') ?? '',
      },
      key: env.TELNYX_WEBHOOK_PUBLIC_KEY,
    })
    return true
  } catch {
    return Response.json({ error: 'Invalid webhook signature' }, { status: 401 })
  }
}

Fallback path: SDK primitives

For vendors without a Workers-compatible SDK, wrap the SDK's crypto primitives:

import { ed25519Verify } from '@bagdock/worker-sdk'
import type { VerifyFunction } from '@bagdock/worker-sdk'
import type { Env } from './types'

export const vendorVerify: VerifyFunction<Env> = (req, env, body) =>
  ed25519Verify({
    signature: req.headers.get('x-sig-ed25519'),
    publicKey: env.VENDOR_PUBLIC_KEY,
    signingString: `${req.headers.get('x-timestamp')}|${body}`,
    timestamp: req.headers.get('x-timestamp'),
  })

Both hmacSha256Verify and ed25519Verify handle null signatures, timestamp skew, and constant-time comparison — callers can safely pass headers.get(...) without pre-checking.

API reference

Factories

| Export | Description | |--------|-------------| | createBagdockWorker(config) | Base factory — lifecycle hooks, health, routing, error boundaries | | createCommsWorker(config) | Comms factory — extends base with capabilities-driven typed route enforcement |

Verification primitives

| Export | Description | |--------|-------------| | hmacSha256Verify(opts) | HMAC-SHA256 verification with constant-time comparison | | ed25519Verify(opts) | Ed25519 verification via Web Crypto |

Types

| Type | Description | |------|-------------| | HandlerContext<E> | Unified context for all handlers — operator ID, installation ID, env, store, logger | | VerifyFunction<E> | Webhook verification contract — (request, env, rawBody) => Promise<true \| Response> | | CommsCapability | 'sms' \| 'voice' \| 'numbers' | | InstallStore | Per-installation encrypted state bag (KV-backed) | | RouteHandler<E> | (ctx: HandlerContext<E>) => Promise<Response> | | SendSMSParams / SendSMSResult | SMS contract types | | CreateCallParams / CallResult | Voice contract types | | NumberSearchParams / AvailableNumber | Numbers contract types |

Documentation

License

MIT — see LICENSE