npm package: @tageery/sdk
Description: Official SDK for Tageery Developer API
Author: Tageery
Latest version: 1.0.0

# tageery-sdk

Official TypeScript/JavaScript SDK for Tageery Developer API.

## Installation

```bash
npm install tageery-sdk
# or
pnpm add tageery-sdk
# or
yarn add tageery-sdk
```

## Usage

### Using API Key (Developer API)

```typescript
import { PlatformClient } from 'tageery-sdk';

const client = new PlatformClient({
  apiKey: process.env.PLATFORM_API_KEY!,
  baseURL: 'https://api.yourplatform.com', // optional
});

// List your apps
const { apps } = await client.apps.list();

// Create a new app
const { app } = await client.apps.create({
  name: 'My App',
  description: 'A great app',
  category: 'marketing',
});
```

### Using OAuth Access Token (Store API)

```typescript
import { PlatformClient } from 'tageery-sdk';

const client = new PlatformClient({
  accessToken: process.env.PLATFORM_ACCESS_TOKEN!,
  baseURL: 'https://api.yourplatform.com',
});

// List products for a store
const { products } = await client.products.list('store_123', {
  limit: 50,
  status: 'active',
});

// Create a product
const { product } = await client.products.create('store_123', {
  name: 'New Product',
  basePrice: 29.99,
  status: 'active',
});

// List orders
const { orders } = await client.orders.list('store_123', {
  status: 'pending',
});
```

### Webhook Handling

```typescript
import { WebhookHandler } from 'tageery-sdk/webhooks';
import express from 'express';

const app = express();
const handler = new WebhookHandler(process.env.WEBHOOK_SECRET!);

app.post('/webhooks', express.raw({ type: 'application/json' }), (req, res) => {
  const signature = req.headers['x-platform-signature'] as string;
  const body = req.body.toString();
  
  if (!handler.verify(signature, body)) {
    return res.status(401).send('Invalid signature');
  }
  
  const event = handler.parse(body);
  
  // Handle event
  switch (event.event) {
    case 'order.created':
      console.log('New order:', event.data);
      break;
    case 'product.updated':
      console.log('Product updated:', event.data);
      break;
  }
  
  res.status(200).send('OK');
});
```

## API Reference

### Products

- `client.products.list(storeId, params?)` - List products
- `client.products.get(storeId, productId)` - Get product
- `client.products.create(storeId, product)` - Create product
- `client.products.update(storeId, productId, updates)` - Update product
- `client.products.delete(storeId, productId)` - Delete product

### Orders

- `client.orders.list(storeId, params?)` - List orders
- `client.orders.get(storeId, orderId)` - Get order
- `client.orders.update(storeId, orderId, updates)` - Update order

### Apps

- `client.apps.list(params?)` - List your apps
- `client.apps.get(appId)` - Get app
- `client.apps.create(app)` - Create app
- `client.apps.update(appId, updates)` - Update app
- `client.apps.publish(appId)` - Publish app for review

### Webhooks

- `client.webhooks.list(appId?)` - List webhooks
- `client.webhooks.create(webhook)` - Create webhook
- `client.webhooks.get(webhookId)` - Get webhook
- `client.webhooks.update(webhookId, updates)` - Update webhook
- `client.webhooks.delete(webhookId)` - Delete webhook

## License

MIT