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

bracket-api-client

v1.0.5

Published

Type-safe API client for Bracket tournament management system

Readme

@bracket/api-client

Type-safe API client for the Bracket tournament management system, powered by Eden Treaty.

Features

  • Full Type Safety: End-to-end type safety from backend to frontend
  • Auto-Generated Types: Types are automatically generated from your Elysia backend
  • Eden Treaty Integration: Leverages Elysia's official client for seamless integration
  • Authentication Support: Built-in API key authentication helper
  • Zero Configuration: Works out of the box with sensible defaults

Installation

npm install @bracket/api-client @elysiajs/eden
# or
yarn add @bracket/api-client @elysiajs/eden
# or
bun add @bracket/api-client @elysiajs/eden
# or
pnpm add @bracket/api-client @elysiajs/eden

Note: @elysiajs/eden is a peer dependency and must be installed alongside this package.

Usage

Basic Usage

import { createApiClient } from "@bracket/api-client";

// Create the client
const api = createApiClient("http://localhost:3000");

// Make type-safe API calls
const { data, error } = await api.tournaments.post({
  name: "My Tournament",
  pointsConfig: {
    win: 3,
    draw: 1,
    loss: 0,
    forfeitWin: 3,
    forfeitLoss: 0
  },
  tiebreakerConfig: {
    rules: [
      { order: 1, type: "points" },
      { order: 2, type: "score_difference" }
    ]
  }
});

if (error) {
  console.error("Error:", error);
} else {
  console.log("Tournament created:", data);
}

With API Key Authentication

import { createAuthenticatedApiClient } from "@bracket/api-client";

// Create authenticated client
const api = createAuthenticatedApiClient(
  "http://localhost:3000",
  "your-api-key-here"
);

// All requests will include the X-API-KEY header
const { data, error } = await api.tournaments.get();

Advanced Configuration

import { createApiClient } from "@bracket/api-client";

// Custom fetch implementation
const api = createApiClient("http://localhost:3000", {
  fetcher: customFetch,
  $fetch: {
    // Default fetch options
    headers: {
      "Custom-Header": "value"
    }
  }
});

API Reference

createApiClient(baseUrl, options?)

Creates a type-safe Eden Treaty client for the Bracket API.

Parameters:

  • baseUrl (string): The base URL of the API server (e.g., "http://localhost:3000")
  • options (optional):
    • fetcher: Custom fetch implementation
    • $fetch: Default RequestInit options to pass to all fetch calls

Returns: Fully typed API client

createAuthenticatedApiClient(baseUrl, apiKey, options?)

Creates a type-safe Eden Treaty client with API key authentication.

Parameters:

  • baseUrl (string): The base URL of the API server
  • apiKey (string): The API key for authentication
  • options (optional):
    • fetcher: Custom fetch implementation
    • $fetch: Default RequestInit options

Returns: Fully typed API client with authentication

Type Safety

All API calls are fully typed based on your backend Elysia application:

// TypeScript knows the exact shape of request and response
const { data, error } = await api.tournaments[":id"].get({
  $params: { id: "tournament-123" }
});

// data is typed as Tournament | null
// error is typed based on possible error responses

if (data) {
  // TypeScript knows all properties of Tournament
  console.log(data.name);
  console.log(data.pointsConfig);
}

Exported Types and Schemas

This package re-exports all relevant types from the backend, including:

API Types:

  • App - The main Elysia app type for type inference

Prisma Entity Types:

  • Tournament, Event, Stage, Round, Node, ParticipantSlot, Match
  • StageType, NodeType, MatchStatus

Schema Types: (TypeScript types, not validators)

  • All input/output schema types from the backend
  • Tournament, Event, Stage, Round, Node, and Match schemas
  • Points config, tiebreaker config, and more
import type {
  App,
  Tournament,
  CreateTournamentInput,
  PointsConfig,
  TiebreakerConfig
} from "bracket-api-client";

// Use types in your client code
const tournamentData: CreateTournamentInput = {
  name: "My Tournament",
  pointsConfig: { win: 3, draw: 1, loss: 0, forfeitWin: 3, forfeitLoss: 0 },
  tiebreakerConfig: {
    rules: [{ order: 1, type: "points" }]
  }
};

Error Handling

Eden Treaty returns responses in the format { data, error }:

const { data, error } = await api.tournaments.post(tournamentData);

if (error) {
  // Handle error
  console.error("Status:", error.status);
  console.error("Message:", error.value);
} else {
  // Handle success
  console.log("Created:", data);
}

Example: Complete CRUD Operations

import { createAuthenticatedApiClient } from "@bracket/api-client";

const api = createAuthenticatedApiClient(
  "http://localhost:3000",
  process.env.API_KEY
);

// Create a tournament
const { data: tournament } = await api.tournaments.post({
  name: "World Championship 2024",
  pointsConfig: { win: 3, draw: 1, loss: 0, forfeitWin: 3, forfeitLoss: 0 },
  tiebreakerConfig: {
    rules: [
      { order: 1, type: "points" },
      { order: 2, type: "score_difference" }
    ]
  }
});

// Get tournament by ID
const { data: fetchedTournament } = await api.tournaments[":id"].get({
  $params: { id: tournament.id }
});

// Update tournament
const { data: updated } = await api.tournaments[":id"].patch({
  $params: { id: tournament.id },
  name: "Updated Championship 2024"
});

// Delete tournament
await api.tournaments[":id"].delete({
  $params: { id: tournament.id }
});

Development

Building

bun run build

Development Mode (Watch)

bun run dev

Publishing

This package is designed to be published to npm. Before publishing:

  1. Update the version in package.json
  2. Build the package: bun run build
  3. Publish: npm publish --access public

The prepublishOnly script will automatically build the package before publishing.

Package Structure

@bracket/api-client/
├── src/
│   └── index.ts          # Main entry point
├── dist/                 # Built files (generated)
│   ├── index.js          # CommonJS bundle
│   ├── index.mjs         # ESM bundle
│   ├── index.d.ts        # TypeScript definitions
│   └── index.d.mts       # ESM TypeScript definitions
├── package.json
├── tsconfig.json
└── README.md

Requirements

  • Node.js >= 16
  • @elysiajs/eden >= 1.0.0 (peer dependency)

License

MIT

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Support

For issues and questions: