# TypeScript quickstart

The official `cbbd` package provides generated TypeScript operations, types,
and a fetch client for working with the API.

## Install the package

```bash
pnpm add cbbd
```

Set your key in the server-side Node environment:

```bash
export CBBD_API_KEY='your-api-key'
```

Keep this example in a server-side Node process. Do not put an API key in
frontend JavaScript, where users can inspect client-side code and network
requests.

## Retrieve games

This example retrieves the same Duke games as `GET
/games?season=2024&team=Duke`:

```typescript
import { client, getGames } from 'cbbd';

const apiKey = process.env.CBBD_API_KEY;

if (!apiKey) {
  throw new Error('CBBD_API_KEY is required');
}

client.setConfig({
  headers: {
    Authorization: `Bearer ${apiKey}`,
  },
});

const response = await getGames({
  query: {
    season: 2024,
    team: 'Duke',
  },
});

if (response.error) {
  throw response.error;
}

console.log(response.data?.[0]);
```

When the request succeeds, `response.data` contains generated game types.
Handle `response.error` according to your application's logging and retry
policy.

See the [official source repository](https://github.com/CFBD/cbbd-typescript)
and the [package on npm](https://www.npmjs.com/package/cbbd) for the complete
generated client reference and current package information.
