# @oneclick.dev/sdk

Universal SDK for interacting with your OneClick Studio project.  
Easily send notifications, trigger automations, and integrate your app or services with the OneClick ecosystem.

---

## 🚀 Installation

Using npm:

```bash
npm install @oneclick.dev/sdk
```

Using pnpm:

```bash
pnpm add @oneclick.dev/sdk
```

Using yarn:

```bash
yarn add @oneclick.dev/sdk
```

---

## ✨ Clients

### 🔔 NotifyClient

Send push notifications to your project users from anywhere.

```ts
import { NotifyClient } from '@oneclick.dev/sdk'

// Create a NotifyClient instance
const notify = new NotifyClient({
  endpoint: process.env.CMS_ENDPOINT!,   // Your API endpoint
  key: process.env.PROJECT_KEY!,         // API key for authentication
  project: process.env.PROJECT_SLUG!     // Slug of your project
})

// Example: Send a notification
await notify.send({
  title: 'New Comment',
  message: 'A user left a new comment on your post.',
  user_id: 'user_123' // Optional: send to a specific user
})
```

---

### 🔥 FlowClient

Trigger any flow or automation you’ve set up in OneClick Studio.

```ts
import { FlowClient } from '@oneclick.dev/sdk'

// Create a FlowClient instance
const flow = new FlowClient({
  endpoint: process.env.CMS_ENDPOINT!,
  key: process.env.PROJECT_KEY!,
  project: process.env.PROJECT_SLUG!
})

// Example: Fire a flow
await flow.fire('daily-order-summary', {
  date: '2025-07-20',
  sendEmail: true,
  includeDrafts: false
})
```

Pass any number of dynamic variables to the flow as the second argument.

---

## 📖 API

### `new NotifyClient(config)`

| Param      | Type     | Description                          |
|------------|----------|--------------------------------------|
| `endpoint` | `string` | Your OneClick Studio API endpoint    |
| `key`      | `string` | API key for authentication           |
| `project`  | `string` | The slug of your OneClick project    |

#### `notify.send(options)`

| Param      | Type     | Description                          |
|------------|----------|--------------------------------------|
| `title`    | `string` | Title of the notification (required) |
| `message`  | `string` | Message content (required)           |
| `user_id`   | `string` | ID of user to send to (optional)     |

---

### `new FlowClient(config)`

| Param      | Type     | Description                          |
|------------|----------|--------------------------------------|
| `endpoint` | `string` | Your OneClick Studio API endpoint    |
| `key`      | `string` | API key for authentication           |
| `project`  | `string` | The slug of your OneClick project    |

#### `flow.fire(flowName, payload?)`

| Param        | Type               | Description                          |
|--------------|--------------------|--------------------------------------|
| `flowName`   | `string`           | Name or slug of the flow to trigger |
| `payload`    | `Record<string, any>` | Dynamic variables for the flow (optional) |

---

## 🛠 Requirements

- Node.js `>=16`
- A OneClick Studio project with API access

---

## 📚 Full Documentation

For advanced usage, authentication guides, and future clients:  
👉 [OneClick Studio Developer Docs](https://studio.oneclick.dev/docs)

---

## 📦 License

SEE LICENSE IN LICENSE
