> For the complete documentation index, see [llms.txt](https://trident-cas.sabn.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trident-cas.sabn.xyz/api/upgrader.md).

# Upgrader

#### Overview

The upgrader allows users to bet an amount to upgrade to a more expensive item based on calculated win chances with a house edge.

**Base Path**: `/upgrader`

***

#### Endpoints

**1. GET `/upgrader/items`**

Get all inventory items with caching. Returns items sorted by price in descending order.

**Query Parameters**

None.

**Response**

Returns an array of item objects, filtered to only include items with valid prices (> $0).

```typescript
Array<{
    appid: number;
    marketHashName: string;
    gunName: string;
    skinName: string;
    image: string;
    price: string;
    nextPriceFetch: number;
}>;
```

**Example Request**

```bash
curl http://localhost:4000/upgrader/items
```

**Example Response**

```json
[
    {
        "appid": 730,
        "marketHashName": "★ Butterfly Knife | Lore",
        "gunName": "★ Butterfly Knife",
        "skinName": "Lore",
        "image": "https://community.fastly.steamstatic.com/economy/image/-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpovbSsLQJf0ebcZThQ6tCvq4OeqPXhJ6_UhG1d8fp9hfvEyoD8j1yg5UplNz_ydo-ddw5rYQqB-1G4ye_vhMftuMubyCdn6XUk4XneyUS0hh1SLrs4xn-YYas/360fx360f",
        "price": "$2349.74",
        "nextPriceFetch": 1735123456789
    },
    {
        "appid": 730,
        "marketHashName": "★ Karambit | Tiger Tooth",
        "gunName": "★ Karambit",
        "skinName": "Tiger Tooth",
        "image": "https://...",
        "price": "$1836.23",
        "nextPriceFetch": 1735123456789
    }
]
```

**Notes**

* Uses in-memory caching with 1-hour duration
* Automatically filters out items without prices or with price ≤ $0
* Items are sorted by price in descending order (most expensive first)

***

**2. GET `/upgrader/items/pagination`**

Get paginated inventory items with search and sorting capabilities.

**Query Parameters**

| Parameter | Type     | Default        | Description                                                             |
| --------- | -------- | -------------- | ----------------------------------------------------------------------- |
| `page`    | `number` | `1`            | Page number for pagination (minimum: 1)                                 |
| `limit`   | `number` | `18`           | Number of items per page                                                |
| `sort`    | `string` | `"Descending"` | Sort order by price: `"Ascending"` or `"Descending"`                    |
| `search`  | `string` | `""`           | Search term to filter items by gun name or skin name (case-insensitive) |

**Response**

```typescript
{
    items: Array<ItemObject>;
    pagination: {
        currentPage: number;
        totalPages: number;
        totalItems: number;
        hasNextPage: boolean;
        hasPrevPage: boolean;
        limit: number;
    }
}
```

**Example Request**

```bash
# Default pagination
curl "http://localhost:4000/upgrader/items/pagination"

# With custom parameters
curl "http://localhost:4000/upgrader/items/pagination?page=2&limit=10&sort=Ascending&search=AK-47"
```

**Example Response**

```json
{
    "items": [
        {
            "appid": 730,
            "marketHashName": "AK-47 | Panthera onca (Field-Tested)",
            "gunName": "AK-47",
            "skinName": "Panthera onca",
            "image": "https://...",
            "price": "$327.64",
            "nextPriceFetch": 1754082321623
        },
        {
            "appid": 730,
            "marketHashName": "AK-47 | Inheritance (Factory New)",
            "gunName": "AK-47",
            "skinName": "Inheritance",
            "image": "https://...",
            "price": "$285.27",
            "nextPriceFetch": 1754082315375
        }
    ],
    "pagination": {
        "currentPage": 1,
        "totalPages": 5,
        "totalItems": 14,
        "hasNextPage": true,
        "hasPrevPage": false,
        "limit": 3
    }
}
```

**Notes**

* Search is performed across both `gunName` and `skinName` fields
* Search is case-insensitive
* Items without valid prices (null or ≤ $0) are automatically filtered out
* Sorting is applied after filtering and searching

***

#### Data Models

**Item Object**

```typescript
{
    appid: number; // Steam app ID (730 = CS2, 252490 = Rust)
    marketHashName: string; // Full item name as it appears on Steam Market
    gunName: string; // Weapon/item name
    skinName: string; // Skin/variant name
    image: string; // CDN URL for item image (360x360)
    price: string; // Formatted price string (e.g., "$12.50")
    nextPriceFetch: number; // Unix timestamp for next price update
}
```

**Inventory Database Schema**

```typescript
{
    appid: number; // Required
    marketHashName: string; // Required, unique identifier
    gunName: string; // Required
    skinName: string; // Required
    image: string; // Required
    price: string; // Required (can be null initially)
    nextPriceFetch: number; // Default: Date.now()
    customPrice: boolean; // Default: false (if true, price won't auto-update)
}
```

***

#### Error Handling

All endpoints include comprehensive error handling:

* **200**: Success
* **500**: Internal Server Error (database or network issues)

Error responses follow this format:

```json
{
    "error": "Error message describing what went wrong"
}
```

***

#### Frontend Integration

**Example: Fetching All Items**

```javascript
const response = await fetch("http://localhost:4000/upgrader/items");
const items = await response.json();

// Use items in upgrader UI
console.log(`Loaded ${items.length} items`);
```

**Example: Paginated Items with Search**

```javascript
const params = new URLSearchParams(
    page: "1",
    limit: "20",
    sort: "Descending",
    search: "AK-47",
});

const response = await fetch(`http://localhost:4000/upgrader/items/pagination?${params}`);
const { items, pagination } = await response.json();

console.log(`Page ${pagination.currentPage} of ${pagination.totalPages}`);
console.log(`Found ${pagination.totalItems} items matching "AK-47"`)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trident-cas.sabn.xyz/api/upgrader.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
