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

@alavida/sdk

v0.1.0

Published

Alavida component SDK — schema, auth context, callbacks, middleware

Readme

@alavida/sdk

Component SDK for the Alavida platform. Provides schema definition, auth context extraction, gateway middleware, and async job callbacks for components deployed as standalone services.

Installation

npm install @alavida/sdk

Zero runtime dependencies — uses native fetch() only.

Quick Start

import { Hono } from "hono";
import {
  defineSchemaHono,
  alavidaMiddlewareHono,
  getAuthContext,
  completeJob,
  failJob,
} from "@alavida/sdk";
import type { ComponentSchema } from "@alavida/sdk";

const schema: ComponentSchema = {
  slug: "my-component",
  name: "My Component",
  type: "workflow",
  version: "1.0.0",
  actions: {
    run: {
      description: "Run the main workflow",
      input_schema: {
        type: "object",
        properties: { query: { type: "string" } },
        required: ["query"],
      },
      output_schema: {
        type: "object",
        properties: { result: { type: "string" } },
      },
    },
  },
};

const app = new Hono();

// Schema endpoint — no auth required
app.get("/schema", defineSchemaHono(schema));

// Protected routes — only accept gateway traffic
app.use("/run", alavidaMiddlewareHono());

app.post("/run", async (c) => {
  const { teamId, userId, jobId, callbackUrl } = getAuthContext(c.req.raw.headers);
  const body = await c.req.json();

  // Do your work...
  const result = await doWork(body.input);

  // Report completion back to the platform
  await completeJob(callbackUrl!, {
    result,
    credits_used: 100,
  });

  return c.json({ status: "accepted" });
});

API Reference

defineSchema(config: ComponentSchema)

Returns a (req: Request) => Response handler that serves the component schema as JSON. Framework-agnostic.

import { defineSchema } from "@alavida/sdk";

const handler = defineSchema(schema);
// Use with any framework that gives you a Request object

defineSchemaHono(config: ComponentSchema)

Hono-specific shortcut. Returns (c) => c.json(config).

app.get("/schema", defineSchemaHono(schema));

getAuthContext(headers: Headers | Record<string, string | undefined>)

Extracts auth context from gateway-injected headers:

| Header | Field | Required | |--------|-------|----------| | X-Alavida-Team-Id | teamId | Yes | | X-Alavida-User-Id | userId | Yes | | X-Alavida-Job-Id | jobId | Yes | | X-Alavida-Callback-Url | callbackUrl | No (only for async) |

Throws AlavidaAuthError if any required header is missing.

import { getAuthContext, AlavidaAuthError } from "@alavida/sdk";

try {
  const ctx = getAuthContext(request.headers);
  console.log(ctx.teamId, ctx.userId, ctx.jobId);
} catch (err) {
  if (err instanceof AlavidaAuthError) {
    // Request didn't come through the gateway
  }
}

alavidaMiddleware()

Returns a generic middleware function (req, next) => Response | Promise<Response> that rejects requests missing the X-Alavida-Team-Id header with a 401.

alavidaMiddlewareHono()

Hono-specific middleware. Rejects non-gateway requests with 401.

app.use("/run", alavidaMiddlewareHono());

completeJob(callbackUrl: string, result: JobResult)

Reports successful job completion to the platform.

await completeJob(callbackUrl, {
  result: { companies: [...] },
  credits_used: 500,
});

failJob(callbackUrl: string, error: JobError)

Reports job failure.

await failJob(callbackUrl, {
  error_code: "processing_failed",
  error_message: "API rate limit exceeded",
});

updateProgress(callbackUrl: string, progress: number)

Reports progress (0-100) for long-running jobs.

await updateProgress(callbackUrl, 50); // 50% done

Types

interface ComponentSchema {
  slug: string;
  name: string;
  type: "workflow" | "tool";
  version: string;
  actions: Record<string, ActionSchema>;
}

interface ActionSchema {
  description: string;
  input_schema: Record<string, unknown>;  // JSON Schema
  output_schema: Record<string, unknown>; // JSON Schema
}

interface AuthContext {
  teamId: string;
  userId: string;
  jobId: string;
  callbackUrl?: string;
}

interface JobResult {
  result: unknown;
  credits_used: number;
}

interface JobError {
  error_code: string;
  error_message: string;
}

Environment Variables

| Variable | Description | |----------|-------------| | INTERNAL_SECRET | Shared secret for callback auth. Required for completeJob, failJob, updateProgress. |

How It Works

  1. The Alavida gateway proxies user requests to your component service
  2. The gateway injects X-Alavida-* headers with auth context and callback URLs
  3. Your component uses getAuthContext() to read these headers
  4. For async workflows, call completeJob() or failJob() when done
  5. The platform handles credits, job tracking, and user notifications