npm package: @masterunoco/casinowebengine-api
Description: Typed front-end SDK for casino web-engine API
Latest version: 0.1.11

# 🕹️ Casino Web Engine API SDK

[![npm version](https://img.shields.io/npm/v/@masterunoco/casinowebengine-api.svg)](https://www.npmjs.com/package/@masterunoco/casinowebengine-api)
[![npm downloads](https://img.shields.io/npm/dm/@masterunoco/casinowebengine-api.svg)](https://www.npmjs.com/package/@masterunoco/casinowebengine-api)

A **TypeScript front-end SDK** for interacting with the casino web-engine API across casino front-end projects.
It provides a unified interface for games, authentication, content, player preferences, website settings, and more — all with full type safety and automatic JWT handling.

---

## ✨ Features

- 🤩 **Typed API layer** – all endpoints return strongly-typed responses.
- 🔐 **Built-in JWT auth** – automatically attaches `Authorization: JWT <token>` to protected requests.
- 🌐 **Public + private endpoints** – transparent auth handling (`none`, `optional`, `required`).
- ⚙️ **Configurable** – base URL and timeout.
- 🗾 **Persistent storage** – stores tokens and user data via localStorage helper.
- 🧠 **Framework-agnostic** – works with any front-end (React, Vue, Next.js, etc.).
- 🥷 **Ready for npm** – ships with ESM + CJS + `.d.ts` types.

---

## 📦 Installation

```bash
npm install @masterunoco/casinowebengine-api
```

### Local development
If the SDK is cloned locally:
```bash
# In SDK directory
npm run build

# In your front-end project
npm install ../path-to/casinowebengine-api
# or
npm i file:../path-to/casinowebengine-api
```

---

## 🧰 Basic Setup

```ts
import { createGameSDK } from '@masterunoco/casinowebengine-api';

const sdk = createGameSDK({
  baseUrl: import.meta.env.VITE_GAMESERVICE_URL,
  timeoutMs: 15000,
});
```

---

## 🔑 Authentication

```ts
// Login (stores JWT in localStorage automatically)
await sdk.auth.login('player3', '123123', '<recaptcha-token>');

// Check if authenticated
if (sdk.auth.isAuthenticated()) {
  console.log('Logged in as', sdk.auth.getUser()?.username);
}

// Logout (clears token + user)
sdk.auth.clear();
```

---

## 🤩 Example Usage

### 🎮 Games
```ts
// Search games
const result = await sdk.games.search({ category: 'slots', page: 1 });
console.log(result.totalCount, result.results[0].name);

// Get demo link
const demo = await sdk.games.getDemoLink(1234);
window.open(demo.gameLink, '_blank');
```

### 📄 Content Pages
```ts
const pages = await sdk.settings.getContent();
const about = await sdk.settings.getContentItem('about-us', 'en');
console.log(about.title);
```

### ⚙️ Preferences
```ts
const prefs = await sdk.settings.getPreferences();
await sdk.settings.updatePreferences({ displayMode: 'dark' });
```

### 💬 Website Settings
```ts
const footer = await sdk.settings.getWebSetting('en');
const providers = await sdk.settings.getWebSettingProviders('en');
const support = await sdk.settings.getSupportEmail('en');
```

### 🌍 Geolocation
```ts
const geo = await sdk.geolocation.getGeolocation();
console.log(geo);
```

---

## 🧱 Architecture

```
src/
├─ sdk.ts                # Core GameSDK class
├─ index.ts              # Barrel exports
├─ http/client.ts        # Fetch wrapper with timeout & authPolicy
├─ auth/jwtAuth.ts       # JWT lifecycle (login, store, clear)
├─ apis/
│  ├─ games.ts
│  ├─ settings.ts
│  ├─ geo.ts
│  └─ ...
├─ types/
│  ├─ auth.ts
│  ├─ gamesSearch.ts
│  ├─ settings.ts
│  └─ signup.ts
└─ localStorage.ts
```

---

## 🗾 Build Output

```
dist/
├─ index.js         (ESM)
├─ index.cjs        (CJS)
└─ index.d.ts       (Type declarations)
```

---

## 🗾 License

MIT © 2025