npm package: @prestige-app-cloud/sdk
Description: TypeScript SDK for Prestige Cloud BaaS — Auth, APIs, Billing, AI Proxy, Push, Files, Lookup Tables
Author: Prestige Cloud
Latest version: 0.3.0

# @prestige-cloud/sdk

TypeScript SDK for Prestige Cloud OAuth 2.0 API.

Handles the full PKCE authorization flow, automatic token refresh, vault access,
API connections, and proxy calls.

## Installation

```bash
npm install @prestige-cloud/sdk
```

## Quick Start

```typescript
import { PrestigeClient } from "@prestige-cloud/sdk";

const client = new PrestigeClient({
  clientId: "your-client-id",
  redirectUri: "http://localhost:3000/callback",
  scopes: ["profile", "vault:standard_api", "connections:proxy"],
  storage: "localStorage",
});

// Start OAuth login
const loginUrl = await client.getLoginUrl();
window.open(loginUrl);

// After callback
await client.handleCallback(code);

// Read vault entries
const entries = await client.getVaultEntries("standard_api");

// Proxy API call (key never leaves Prestige Cloud)
const response = await client.proxy("openai-chat", {
  body: { model: "gpt-4", messages: [{ role: "user", content: "Hello" }] },
});
```

## API

### OAuth Flow

- `getLoginUrl(state?)` — Generate OAuth authorization URL with PKCE
- `handleCallback(code)` — Exchange authorization code for tokens
- `refreshTokens()` — Refresh the access token using the stored refresh token
- `setTokens(tokens)` — Set tokens directly (e.g. restoring from storage)
- `getTokens()` — Get the current token set, or `null` if not authenticated
- `clearTokens()` — Clear tokens from memory and persistent storage

### Vault

- `getVaultEntries(category)` — Read vault entries for a category
- `writeVaultEntries(category, entries)` — Write vault entries (write-if-empty semantics)

### Connections

- `getConnections()` — List API connections with per-placeholder fill status
- `createConnection(templateId, placeholderValues)` — Create a connection for an API template

### User

- `getUserProfile()` — Fetch the authenticated user's profile (requires `profile` scope)

### Proxy

- `proxy(templateSlug, options?)` — Forward a request through Prestige Cloud to a connected API

### App Config

- `getAppConfig()` — Get app integration config (requires authentication)
- `getPublicAppConfig()` — Get app config without authentication (identified by client ID)

### Manual Storage (Local)

- `saveManualValues(templateId, values)` — Save API key values to local storage
- `getManualValues(templateId)` — Load saved values for a specific template
- `getAllManualValues()` — Load all manually saved values across every template

## Configuration

```typescript
interface PrestigeClientConfig {
  /** OAuth client ID issued by Prestige Cloud. */
  clientId: string;
  /** URI that Prestige Cloud redirects to after authorization. */
  redirectUri: string;
  /** OAuth scopes to request. */
  scopes: string[];
  /** Base URL of the Prestige Cloud instance. Defaults to "https://prestige.cloud". */
  baseUrl?: string;
  /** Token storage strategy. Defaults to "none". */
  storage?: "localStorage" | "sessionStorage" | "none";
  /** Key used for web storage. Defaults to "prestige_tokens". */
  storageKey?: string;
}
```

## Exported Types

- `PrestigeClientConfig`
- `TokenSet`
- `VaultEntry`
- `WriteVaultResult`
- `Connection`
- `CreateConnectionResult`
- `UserProfile`
- `AppConfig`
- `StorageType`

## License

MIT