npm package: @fiberwise/sdk
Description: JavaScript SDK for accessing FiberWise Dynamic Data Platform
Author: FiberWise Team
Latest version: 0.1.3

# FiberWise SDK (v0.1.3)

## Overview
The FiberWise SDK provides a comprehensive JavaScript/Node.js interface for the FiberWise Platform. It includes modules for:

- Dynamic Data Management (`data`)
- Serverless Functions (`functions`)
- Intelligent Agents (`agents`) 
- Real-time Communication (`realtime`)
- OAuth Credential Management (`credentials`)
- App Management (`apps`)
- Configuration (`config`)

## Installation
Install via npm:

```bash
npm install fiberwise@0.1.3
```

> Note: The SDK requires Node.js 14+ or modern browsers with ES6 support

## Usage

```javascript
import FiberWise from 'fiberwise';

// Create instance with configuration
const fiber = new Fiberwise({
  baseUrl: 'https://api.example.com/api/v1',  // Required
  apiKey: 'your-api-key',                     // Required for authenticated calls
  appId: 'your-app-id'                        // Required for app-specific operations
});

// Initialize with AppBridge (for platform integration)
fiber.initialize(appBridge, manifest);

// Example: Using DynamicData
const users = await fiber.data.listItems('users');
console.log(users);

// Example: Running a function
const result = await fiber.functions.activate('processData', { param: 'value' });

// Example: Real-time communication
fiber.realtime.on('message', (msg) => {
  console.log('Received message:', msg);
});
```

## Core Modules

### DynamicData
```javascript
// CRUD operations
await fiber.data.createItem('products', { name: 'New Product' });
const products = await fiber.data.listItems('products');
const product = await fiber.data.getItem('products', '123');
await fiber.data.updateItem('products', '123', { price: 99.99 });
await fiber.data.deleteItem('products', '123');
```

### Functions
```javascript
// Execute functions
const result = await fiber.functions.activate('calculate', { x: 5, y: 10 });

// List available functions
const functions = await fiber.functions.list();
```

### Agents
```javascript 
// Run agent with streaming
const controller = await fiber.agents.activateStreaming(
  'chat-agent',
  { message: 'Hello' },
  {},
  {},
  {
    onMessage: (chunk) => console.log('Chunk:', chunk),
    onComplete: (result) => console.log('Complete:', result)
  }
);

// Stop streaming when needed
controller.close();
```

### Realtime
```javascript
// Connect to realtime service
await fiber.realtime.connect();

// Subscribe to messages
fiber.realtime.subscribe('update', (msg) => {
  console.log('Update received:', msg);
});

// Send messages
fiber.realtime.send('chat', { text: 'Hello world' });
```

### CredentialService
```javascript
// OAuth flow
const authUrl = fiber.credentials.getAuthUrl('google', {
  returnTo: '/dashboard'
});

// Check connection status
const isConnected = await fiber.credentials.isConnected('slack');
```

## Configuration
```javascript
// Get current config
const config = fiber.getConfig();
console.log('Current config:', config);

// Update config (non-destructive merge)
fiber.setConfig({
  apiKey: 'new-key',
  baseUrl: 'https://new-api.example.com/api/v1'
});

// Access specific values
const appId = fiber.getAppId();
const apiKey = fiber.getApiKey();
const baseUrl = fiber.getBaseUrl();

// Check initialization status
if (fiber.isInitialized()) {
  const appBridge = fiber.getAppBridge();
}
```

## Build and Deploy
```bash
# Build the SDK
npm run build

# Available bundles:
# - ES Module: dist/fiberwise.esm.js
# - CommonJS: dist/fiberwise.js
# - TypeScript types: dist/index.d.ts
```

## License
MIT License. See LICENSE for details.