# @gamevault/sdk

[![npm](https://img.shields.io/npm/v/@gamevault/sdk)](https://npmjs.com/package/@gamevault/sdk)
[![JSR](https://img.shields.io/jsr/v/@gamevault/sdk)](https://jsr.io/@gamevault/sdk)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

GameVault SDK - Unified API for game asset marketplace. Works in Node.js, Deno, Bun, and browsers.

## Installation

### npm

```bash
npm install @gamevault/sdk
```

### JSR (Deno)

```bash
deno add jsr:@gamevault/sdk
```

## Documentation

Full documentation at: **https://gamevault.com/docs**

## Features

- **Asset Management** — Search, download, and manage game assets
- **Authentication** — OAuth device code flow for user authentication
- **Generation** — AI-powered asset generation (sprites, animations, creatures)
- **Bundles** — Read/write `.gas` bundle format for cross-engine asset sharing
- **Runtime** — Universal runtime loader for game engines

## Usage

```typescript
import { createSDK, GameVaultSDK } from "@gamevault/sdk";

// Create SDK instance
const sdk = createSDK({
  serverUrl: "https://gamevault.com",
  apiKey: process.env.GAMEVAULT_API_KEY,
});

// Search assets
const assets = await sdk.assets.search({
  query: "explosion sprite",
  type: "sprite",
  limit: 10,
});

// Download asset
const bundle = await sdk.assets.download(assetId);

// Load bundle in your engine
import { RuntimeLoader } from "@gamevault/sdk/runtime";
const loader = new RuntimeLoader(engine);
await loader.loadBundle(bundle);
```

## API Overview

### `createSDK(config)`

Creates an SDK instance with the provided configuration.

```typescript
const sdk = createSDK({
  serverUrl: "https://gamevault.com",
  apiKey: "your-api-key",
  timeout: 30000,
});
```

### Services

| Service | Description |
|---------|-------------|
| `sdk.assets` | Search, browse, download assets |
| `sdk.store` | Store management and settings |
| `sdk.users` | User profile and preferences |
| `sdk.projects` | Project management |
| `sdk.generation` | AI asset generation |
| `sdk.auth` | Authentication utilities |

### Bundle Format

The SDK supports the universal `.gas` bundle format:

```typescript
import { GasBundle } from "@gamevault/sdk/bundle";

// Read a .gas bundle
const bundle = await GasBundle.read("./asset.gas");

// Access sprite data
const sprite = bundle.getSprite("idle");
console.log(sprite.width, sprite.height);

// Write a modified bundle
await bundle.write("./modified.gas");
```

## Development

```bash
npm run build    # TypeScript compilation
npm run test     # Run tests
npm run lint     # Lint code
```

## License

MIT
