npm package: @nexapi/sdk
Description: Official SDK for APIFlow - AI-powered API automation platform
Author: NexAPI Team
Latest version: 1.0.0

# NexAPI SDK

Official TypeScript/JavaScript SDK for NexAPI - the AI-powered API automation platform.

## Installation

```bash
npm install @nexapi/sdk
```

## Quick Start

```typescript
import NexAPISDK from '@nexapi/sdk';

const nexapi = new NexAPISDK({
  apiKey: 'your-api-key-here',
  baseURL: 'https://api.nexapi.com' // optional
});

// Create a new automation flow
const flow = await nexapi.createFlow('Send SMS when Stripe payment received');

// Execute a test
const testResult = await nexapi.executeTest(flow.id, {
  mockData: { amount: 100, currency: 'USD' }
});

// Deploy the flow
const deployment = await nexapi.deployFlow(flow.id, 'replit');
```

## Configuration

### Basic Configuration

```typescript
const nexapi = new NexAPISDK({
  apiKey: 'your-api-key-here'
});
```

### Advanced Configuration

```typescript
const nexapi = new NexAPISDK({
  apiKey: 'your-api-key-here',
  baseURL: 'https://api.nexapi.com',
  timeout: 30000 // 30 seconds
});
```

## Flow Management

### Create a Flow

```typescript
const flow = await nexapi.createFlow('Send email when new GitHub issue created');
console.log(flow.id, flow.intent, flow.apis);
```

### Get Flow Details

```typescript
const flow = await nexapi.getFlow('flow-id');
console.log(flow.name, flow.status, flow.code);
```

### List All Flows

```typescript
const flows = await nexapi.listFlows();
flows.forEach(flow => console.log(flow.name));
```

### Update Flow

```typescript
const updatedFlow = await apiflow.updateFlow('flow-id', {
  name: 'Updated Flow Name',
  status: 'active'
});
```

### Delete Flow

```typescript
await apiflow.deleteFlow('flow-id');
```

## API Discovery

### Search APIs

```typescript
const apis = await apiflow.searchAPIs('payment', ['webhook', 'processing']);
apis.forEach(api => console.log(api.name, api.category));
```

### Get API Details

```typescript
const api = await apiflow.getAPI(123);
console.log(api.name, api.documentation, api.capabilities);
```

### List All APIs

```typescript
const apis = await apiflow.listAPIs();
console.log(`Found ${apis.length} APIs`);
```

## Templates

### Get Templates

```typescript
const templates = await apiflow.getTemplates();
templates.forEach(template => console.log(template.name, template.category));
```

### Get Template by ID

```typescript
const template = await apiflow.getTemplate(1);
console.log(template.prompt, template.usageCount);
```

### Get Templates by Category

```typescript
const ecommerceTemplates = await apiflow.getTemplatesByCategory('E-commerce');
```

## Testing

### Execute Test

```typescript
const testExecution = await apiflow.executeTest(flowId, {
  apiKeys: {
    stripe: 'sk_test_...',
    twilio: 'AC...'
  },
  mockData: {
    amount: 100,
    currency: 'USD',
    customer: 'cus_...'
  }
});
```

### Get Test Results

```typescript
const testResult = await apiflow.getTestExecution(testId);
console.log(testResult.status, testResult.results, testResult.logs);
```

### Get All Test Executions for Flow

```typescript
const tests = await apiflow.getTestExecutions(flowId);
tests.forEach(test => console.log(test.status, test.duration));
```

## Deployment

### Deploy Flow

```typescript
const deployment = await apiflow.deployFlow(flowId, 'replit');
console.log(deployment.status, deployment.url);
```

### Get Deployment Status

```typescript
const deployment = await apiflow.getDeployment(deploymentId);
console.log(deployment.status, deployment.logs);
```

### Get All Deployments for Flow

```typescript
const deployments = await apiflow.getDeployments(flowId);
deployments.forEach(dep => console.log(dep.platform, dep.status));
```

## Subflows (Reusable Components)

### Get Subflows

```typescript
const subflows = await apiflow.getSubflows();
subflows.forEach(subflow => console.log(subflow.name, subflow.category));
```

### Create Subflow

```typescript
const subflow = await apiflow.createSubflow({
  name: 'Email Notification',
  description: 'Send email with template',
  category: 'Communication',
  isPublic: true,
  steps: [
    { type: 'email', template: 'notification', to: '{{email}}' }
  ]
});
```

### Update Subflow

```typescript
const updatedSubflow = await apiflow.updateSubflow(subflowId, {
  description: 'Updated description',
  isPublic: false
});
```

## Plugins

### Get Available Plugins

```typescript
const plugins = await apiflow.getPlugins();
plugins.forEach(plugin => console.log(plugin.name, plugin.category));
```

### Install Plugin

```typescript
const plugin = await apiflow.installPlugin('plugin-id');
console.log(`Installed ${plugin.name}`);
```

### Uninstall Plugin

```typescript
await apiflow.uninstallPlugin('plugin-id');
```

## Usage & Billing

### Get Usage Metrics

```typescript
const usage = await apiflow.getUsage('30d');
console.log(usage.usage.flows, usage.limits.flows);
```

### Get Billing Plans

```typescript
const plans = await apiflow.getBillingPlans();
plans.forEach(plan => console.log(plan.plan, plan.price));
```

## Webhooks

### Create Webhook

```typescript
const webhook = await apiflow.createWebhook('https://your-app.com/webhook', [
  'flow.created',
  'flow.executed',
  'test.completed'
]);
```

### Get Webhooks

```typescript
const webhooks = await apiflow.getWebhooks();
webhooks.forEach(webhook => console.log(webhook.url, webhook.events));
```

### Delete Webhook

```typescript
await apiflow.deleteWebhook('webhook-id');
```

## Utility Methods

### Validate API Key

```typescript
const isValid = await apiflow.validateAPIKey();
if (!isValid) {
  console.error('Invalid API key');
}
```

### Check Service Health

```typescript
const health = await apiflow.getHealth();
console.log(health.status, health.uptime);
```

## Error Handling

```typescript
try {
  const flow = await apiflow.createFlow('Invalid prompt');
} catch (error) {
  if (error.response?.status === 400) {
    console.error('Bad request:', error.response.data.message);
  } else if (error.response?.status === 401) {
    console.error('Unauthorized: Check your API key');
  } else {
    console.error('Unexpected error:', error.message);
  }
}
```

## TypeScript Support

The SDK is written in TypeScript and includes full type definitions:

```typescript
import NexAPISDK, { Flow, API, Template } from '@nexapi/sdk';

const nexapi = new NexAPISDK({ apiKey: 'your-key' });

// Full typing support
const flow: Flow = await nexapi.createFlow('prompt');
const apis: API[] = await nexapi.searchAPIs('query');
const templates: Template[] = await nexapi.getTemplates();
```

## Authentication

Get your API key from the [NexAPI Dashboard](https://nexapi.com/dashboard/api-keys).

## Rate Limits

- Free plan: 100 requests per hour
- Pro plan: 1,000 requests per hour
- Enterprise plan: 10,000 requests per hour

## Support

- Documentation: https://docs.nexapi.com
- GitHub Issues: https://github.com/nexapi/sdk/issues
- Email: support@nexapi.com

## License

MIT License - see LICENSE file for details.