npm package: @project-438/sdk
Description: Official TypeScript client SDK for Project-438 BaaS
Latest version: 0.1.4

# @project-438/sdk

Official TypeScript SDK for [Project-438](https://p438.io) — EU-sovereign backend-as-a-service for AI-generated apps.

Auth, auto-generated REST & GraphQL APIs, object storage, migrations, and admin tools. All EU-hosted, GDPR-native.

## Install

```bash
npm install @project-438/sdk
```

## Quick start

```ts
import { P438 } from '@project-438/sdk'

const app = new P438({
  apiKey: process.env.P438_API_KEY,
  projectId: process.env.P438_PROJECT_ID,
})

// Query data
const users = await app.db
  .from('users')
  .select('id', 'name', 'email')
  .eq('active', true)
  .limit(10)
  .get()

// Insert data
await app.db.from('posts').insert({ title: 'Hello, EU.' })
```

## Modules

| Module | Description |
|--------|-------------|
| `app.auth` | Sign up, sign in, email verification, password reset, session management |
| `app.db` | Query, insert, update, and delete data with a fluent query builder |
| `app.migrations` | Apply and list SQL migrations |
| `app.projects` | Create and list projects |
| `app.storage` | Upload, download, and manage files in S3-compatible buckets |
| `app.apiKeys` | Create, list, and revoke API keys |
| `app.admin` | Platform admin — manage users, roles, and audit logs |
| `app.serve()` | Drop-in route handlers for Next.js, Hono, Cloudflare Workers, etc. |

## Auth

```ts
// Sign up
const { id } = await app.auth.signUp({
  email: 'user@example.com',
  password: 'securepassword',
})

// Sign in (stores tokens automatically)
await app.auth.signIn({
  email: 'user@example.com',
  password: 'securepassword',
})

// Get current user
const user = await app.auth.me()
```

## Database

```ts
// Fluent query builder
const posts = await app.db
  .from('posts')
  .select('id', 'title')
  .eq('published', true)
  .order('created_at', 'desc')
  .limit(20)
  .get()

// Insert
await app.db.from('posts').insert({ title: 'New post', body: 'Content' })

// Update
await app.db.from('posts').eq('id', postId).update({ title: 'Updated' })

// Delete
await app.db.from('posts').eq('id', postId).delete()
```

## Migrations

```ts
// Apply a migration
await app.migrations.apply('create_posts', `
  CREATE TABLE posts (
    id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
    title text NOT NULL,
    body text,
    created_at timestamptz DEFAULT now()
  );
`)

// List applied migrations
const migrations = await app.migrations.list()
```

## Storage

```ts
// Upload a file
await app.storage.upload('avatars', 'user-1.png', file)

// Get a signed URL
const url = await app.storage.getSignedUrl('avatars', 'user-1.png')

// List objects
const { objects } = await app.storage.list('avatars')
```

## Serve (framework integration)

Drop-in route handlers that proxy requests to the Project-438 API. Works with Next.js App Router, Hono, Cloudflare Workers, and any framework that uses the Fetch API.

```ts
// app/api/p438/[...route]/route.ts (Next.js)
import { P438 } from '@project-438/sdk'

const app = new P438({ apiKey: process.env.P438_API_KEY })
export const { GET, POST, PATCH, PUT, DELETE } = app.serve()
```

## Configuration

```ts
const app = new P438({
  apiKey: 'your-api-key',        // Server-side API key
  projectId: 'your-project-id', // Default project for db/migrations/storage
  baseUrl: 'https://api.p438.io', // API URL (default)
  tokenStorage: 'memory',       // 'memory' (default) or 'localStorage'
})
```

## Requirements

- Node.js 18+
- Works in Node.js, browsers, Deno, Bun, and Cloudflare Workers

## License

MIT