SweatHost
SDK Reference

Installation

Install and configure the SweatHost SDK

Installation

Install the SweatHost SDK in your JavaScript or TypeScript project.

Package Managers

Install using your preferred package manager:

npm

npm install @sweathost/sdk

pnpm

pnpm add @sweathost/sdk

yarn

yarn add @sweathost/sdk

bun

bun add @sweathost/sdk

Requirements

  • Node.js: 18.x or higher
  • TypeScript: 5.x or higher (optional, but recommended)

Basic Setup

JavaScript (CommonJS)

const { SweatHostClient } = require('@sweathost/sdk');

const client = new SweatHostClient({
  apiKey: 'your-api-key-here',
});

JavaScript (ES Modules)

import { SweatHostClient } from '@sweathost/sdk';

const client = new SweatHostClient({
  apiKey: 'your-api-key-here',
});

TypeScript

import { SweatHostClient } from '@sweathost/sdk';

const client = new SweatHostClient({
  apiKey: process.env.SWEATHOST_API_KEY!,
  baseUrl: 'https://api.sweathost.com',
});

Configuration

Client Options

interface SweatHostClientOptions {
  /**
   * Your API key from the dashboard
   * @required
   */
  apiKey: string;

  /**
   * API base URL
   * @default "https://api.sweathost.com"
   */
  baseUrl?: string;

  /**
   * Request timeout in milliseconds
   * @default 30000
   */
  timeout?: number;

  /**
   * Custom headers to include in all requests
   */
  headers?: Record<string, string>;

  /**
   * Enable debug logging
   * @default false
   */
  debug?: boolean;
}

Example Configuration

const client = new SweatHostClient({
  apiKey: process.env.SWEATHOST_API_KEY!,
  baseUrl: process.env.SWEATHOST_API_URL || 'https://api.sweathost.com',
  timeout: 60000, // 60 seconds
  debug: process.env.NODE_ENV === 'development',
  headers: {
    'X-Custom-Header': 'value',
  },
});

Environment Variables

It's recommended to store your API key in environment variables:

.env File

Create a .env file in your project root:

SWEATHOST_API_KEY=your-api-key-here
SWEATHOST_API_URL=https://api.sweathost.com

Loading Environment Variables

Using dotenv

npm install dotenv
import 'dotenv/config';
import { SweatHostClient } from '@sweathost/sdk';

const client = new SweatHostClient({
  apiKey: process.env.SWEATHOST_API_KEY!,
});

Using Next.js

Next.js automatically loads .env.local:

// No additional setup needed
const client = new SweatHostClient({
  apiKey: process.env.SWEATHOST_API_KEY!,
});

TypeScript Configuration

tsconfig.json

Ensure your tsconfig.json includes:

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "strict": true,
    "skipLibCheck": true
  }
}

Type Imports

Import types for better IDE support:

import type {
  GameServer,
  Match,
  Region,
  PlayerStats,
  CreateGameServerParams,
  ListGameServersParams,
} from '@sweathost/sdk';

Verification

Test your installation:

import { SweatHostClient } from '@sweathost/sdk';

async function testConnection() {
  const client = new SweatHostClient({
    apiKey: process.env.SWEATHOST_API_KEY!,
  });

  try {
    const regions = await client.regions.list();
    console.log('✓ SDK installed and configured correctly');
    console.log(`  Available regions: ${regions.length}`);
  } catch (error) {
    console.error('✗ SDK configuration error:', error.message);
  }
}

testConnection();

Expected output:

✓ SDK installed and configured correctly
  Available regions: 12

Framework Integration

Next.js (App Router)

// app/lib/sweathost.ts
import { SweatHostClient } from '@sweathost/sdk';

export const sweathost = new SweatHostClient({
  apiKey: process.env.SWEATHOST_API_KEY!,
});

// app/api/servers/route.ts
import { sweathost } from '@/lib/sweathost';

export async function GET() {
  const servers = await sweathost.gameServers.list();
  return Response.json(servers);
}

Express.js

import express from 'express';
import { SweatHostClient } from '@sweathost/sdk';

const app = express();
const sweathost = new SweatHostClient({
  apiKey: process.env.SWEATHOST_API_KEY!,
});

app.get('/api/servers', async (req, res) => {
  try {
    const servers = await sweathost.gameServers.list();
    res.json(servers);
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

app.listen(3000);

NestJS

// sweathost.service.ts
import { Injectable } from '@nestjs/common';
import { SweatHostClient } from '@sweathost/sdk';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class SweatHostService {
  private client: SweatHostClient;

  constructor(private configService: ConfigService) {
    this.client = new SweatHostClient({
      apiKey: this.configService.get('SWEATHOST_API_KEY')!,
    });
  }

  async listServers() {
    return this.client.gameServers.list();
  }
}

Troubleshooting

Module Not Found

If you see Cannot find module '@sweathost/sdk':

  1. Ensure the package is installed: npm list @sweathost/sdk
  2. Clear node_modules and reinstall: rm -rf node_modules && npm install
  3. Check your package.json includes the dependency

Type Errors

If you see TypeScript errors:

  1. Ensure TypeScript is version 5.x or higher
  2. Run npm install --save-dev @types/node
  3. Check your tsconfig.json configuration

API Key Issues

If you see "Invalid API key":

  1. Verify your API key is correct
  2. Check the key has the required scopes
  3. Ensure the key hasn't expired

Next Steps

Now that the SDK is installed:

Support

Need help with installation?

On this page