0.1.0 • Published 6 months ago

api-city-sdk v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Tapestry Plugin SDK

A powerful SDK for building plugins for the Tapestry Chat platform. Create interactive plugins that can integrate with Solana wallets, manage state, and provide rich user interfaces.

Features

  • 🔒 Secure wallet integration
  • 💾 Persistent storage
  • 🎨 React-based UI components
  • 📨 Message handling
  • 🔔 Notification system
  • ⚙️ Settings management

Installation

npm install @tapestry/plugin-sdk
# or
pnpm add @tapestry/plugin-sdk

Quick Start

  1. Create a new plugin by extending the BasePlugin class:
import { BasePlugin, PluginManifest } from '@tapestry/plugin-sdk';

const manifest: PluginManifest = {
  name: 'My Plugin',
  version: '1.0.0',
  description: 'A simple plugin',
  author: 'Your Name',
  permissions: ['wallet:read', 'ui:render'],
  entryPoints: {
    main: 'index.ts'
  }
};

export class MyPlugin extends BasePlugin {
  constructor() {
    super(manifest);
  }

  protected async onInitialize(): Promise<void> {
    // Initialize your plugin
    this.showNotification('Plugin initialized!');
  }

  protected async onCleanup(): Promise<void> {
    // Cleanup when plugin is disabled
  }
}
  1. Use the provided APIs:
// Wallet operations
const address = await this.wallet.getAddress();
const signature = await this.wallet.signMessage('Hello');

// Storage operations
await this.storage.set('myKey', { value: 123 });
const data = await this.storage.get('myKey');

// UI rendering
this.ui.render(
  <div className="p-4">
    <h1>My Plugin UI</h1>
    <button onClick={() => this.showNotification('Clicked!')}>
      Click me
    </button>
  </div>
);

// Notifications
this.showNotification('Operation successful!', 'success');

Plugin Manifest

The manifest defines your plugin's metadata and required permissions:

interface PluginManifest {
  name: string;
  version: string;
  description: string;
  author: string;
  permissions: PluginPermission[];
  entryPoints: {
    main: string;
    settings?: string;
    styles?: string;
  };
}

Available permissions:

  • wallet:read - Read wallet address and public data
  • wallet:write - Sign messages and send transactions
  • storage:read - Read from plugin storage
  • storage:write - Write to plugin storage
  • ui:render - Render UI components
  • notifications:create - Show notifications

Best Practices

  1. Error Handling
try {
  await this.wallet.sendTransaction(tx);
  this.showNotification('Success!', 'success');
} catch (error) {
  this.showNotification(error.message, 'error');
}
  1. State Management
// Save state on changes
private async saveState(): Promise<void> {
  await this.storage.set('pluginState', this.state);
}

// Load state on initialization
protected async onInitialize(): Promise<void> {
  this.state = await this.storage.get('pluginState') || defaultState;
}
  1. UI Updates
// Update UI when state changes
private updateUI(): void {
  this.ui.update(
    <MyComponent 
      data={this.state}
      onAction={this.handleAction}
    />
  );
}

Examples

Check out our example plugins:

Development

  1. Clone the repository
  2. Install dependencies:
pnpm install
  1. Build the SDK:
pnpm build
  1. Run tests:
pnpm test

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

MIT License - see LICENSE for details