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

@studiometa/forge-api

v0.4.3

Published

Laravel Forge API client — HTTP client, types, config storage, and rate limiting

Readme

@studiometa/forge-api

npm version License: MIT

Internal HTTP client, TypeScript types, configuration storage, and rate limiting for the Laravel Forge API. This is the foundation package for all @studiometa/forge-* packages.

Note: Most users should use @studiometa/forge-sdk instead, which provides a fluent, chainable API on top of this package.

Installation

npm install @studiometa/forge-api

Usage

HTTP Client

import { HttpClient } from '@studiometa/forge-api';

const client = new HttpClient({
  token: 'your-api-token',
});

// Direct API calls (base URL: https://forge.laravel.com/api)
const response = await client.get('/orgs/my-org/servers');
const server = await client.post('/orgs/my-org/servers', { name: 'web-1', ... });
await client.delete('/orgs/my-org/servers/123');

Configuration

Read API token and organization slug from environment variables or config file:

import {
  getToken,
  setToken,
  deleteToken,
  getOrganizationSlug,
  setOrganizationSlug,
} from "@studiometa/forge-api";

// Resolution: FORGE_API_TOKEN env var > config file
const token = getToken();

// Resolution: FORGE_ORG env var > config file
const orgSlug = getOrganizationSlug();

// Save to config file (~/.config/forge-tools/config.json)
setToken("your-token");
setOrganizationSlug("my-org");

// Remove token from config
deleteToken();

JSON:API Response Helpers

The Forge v2 API returns JSON:API-formatted responses. Use these helpers to unwrap them:

import { HttpClient, unwrapDocument, unwrapListDocument } from "@studiometa/forge-api";
import type {
  JsonApiDocument,
  JsonApiListDocument,
  ServerAttributes,
  SiteAttributes,
} from "@studiometa/forge-api";

const client = new HttpClient({ token: "your-token" });

// Single resource
const doc = await client.get<JsonApiDocument<ServerAttributes>>("/orgs/my-org/servers/123");
const server = unwrapDocument(doc); // ServerAttributes & { id: number }

// List of resources
const listDoc = await client.get<JsonApiListDocument<SiteAttributes>>(
  "/orgs/my-org/servers/123/sites",
);
const sites = unwrapListDocument(listDoc); // Array<SiteAttributes & { id: number }>

Error Handling

import { ForgeApiError, isForgeApiError } from "@studiometa/forge-api";

try {
  await client.get("/orgs/my-org/servers/999");
} catch (error) {
  if (isForgeApiError(error)) {
    console.log(error.status); // 404
    console.log(error.statusText); // "Resource not found"
    console.log(error.url); // "/orgs/my-org/servers/999"
    console.log(error.body); // API response body
  }
}

Rate Limiting

The HTTP client includes automatic rate limiting (60 requests/minute) with exponential backoff on 429 responses:

const client = new HttpClient({
  token: "your-token",
  rateLimit: {
    maxRetries: 3, // Max retries on 429 (default: 3)
    baseDelay: 1000, // Base delay in ms (default: 1000)
  },
});

Dependency Injection (Testing)

const mockFetch = async () => ({
  ok: true,
  status: 200,
  headers: new Headers({ "content-type": "application/json" }),
  json: async () => ({ data: [] }),
  text: async () => "{}",
});

const client = new HttpClient({
  token: "test",
  fetch: mockFetch,
});

Exports

| Export | Description | | ------------------------------------------------------------------ | ----------------------------------------------------- | | HttpClient | Low-level HTTP client with auth, rate limiting, retry | | ForgeApiError | Typed error with status, url, body | | isForgeApiError() | Type guard for ForgeApiError | | RateLimiter | Sliding window rate limiter (60 req/min) | | ConfigStore | XDG-compliant JSON config store | | getToken / setToken / deleteToken | Token management helpers | | getOrganizationSlug / setOrganizationSlug | Organization slug management helpers | | unwrapDocument / unwrapListDocument / unwrapResource | JSON:API response unwrapping helpers | | JsonApiDocument, JsonApiListDocument, etc. | JSON:API type definitions | | ServerAttributes, SiteAttributes, DeploymentAttributes, etc. | v2 resource attribute types | | CreateServerData, CreateSiteData, etc. | Input types for create operations |

Config Storage

| Platform | Path | | -------- | ------------------------------------------------------- | | Linux | ~/.config/forge-tools/config.json | | macOS | ~/Library/Application Support/forge-tools/config.json | | Windows | %APPDATA%/forge-tools/config.json |

Config fields:

  • apiToken — Forge API token (from Forge dashboard)
  • organizationSlug — Default organization slug (e.g. studio-meta), also via FORGE_ORG env var

License

MIT © Studio Meta