Skip to content

feat: add minimal SDK example#14

Merged
prosdev merged 1 commit intomainfrom
feature/task-9-example-sdk
Dec 17, 2025
Merged

feat: add minimal SDK example#14
prosdev merged 1 commit intomainfrom
feature/task-9-example-sdk

Conversation

@prosdev
Copy link
Copy Markdown
Collaborator

@prosdev prosdev commented Dec 17, 2025

Implements #8 : Create Minimal Example SDK

Summary

A complete, working example SDK that demonstrates all core features of SDK Kit through three well-documented plugins.

Example SDK Plugins

1. Logger Plugin

  • Console logging with configurable levels
  • Exposes: debug(), info(), warn(), error(), getLogs()
  • Emits logger:logged events
  • Demonstrates namespace, defaults, expose, events

2. Analytics Plugin

  • Event tracking with batching
  • Auto-flush after batch size or interval
  • Exposes: track(), identify(), page(), flush()
  • Emits analytics:tracked, analytics:identified, analytics:page
  • Demonstrates timers, async operations, cleanup

3. Monitor Plugin

  • Cross-plugin event monitoring
  • Wildcard subscriptions (analytics:*)
  • Exposes: getStats(), resetStats()
  • Demonstrates plugin communication, statistics

What It Demonstrates

Plugin System

  • Three functional plugins working together
  • Each with unique namespace
  • Proper capability injection

Configuration

  • Hierarchical config with defaults
  • Dot-notation access
  • Runtime updates
  • Underwrite pattern (user config wins)

Events

  • Pub/sub pattern for loose coupling
  • Wildcard subscriptions (analytics:*)
  • Lifecycle events (sdk:init, sdk:ready, sdk:destroy)
  • Custom events for plugin communication

API Exposure

  • 11 public methods exposed from plugins
  • Type-safe module augmentation
  • Clean, intuitive API

Lifecycle

  • Proper init/destroy flow
  • Timer cleanup
  • Data flushing on destroy
  • Event-based hooks

Usage Example

import { createMySDK } from './index';

const sdk = createMySDK({
  logger: { level: 'debug' },
  analytics: { batchSize: 3 },
});

await sdk.init();

// Use exposed methods
sdk.info('Hello world');
sdk.track('button_clicked', { button: 'sign_up' });
sdk.identify('user-123', { name: 'John' });

// Check stats
const stats = sdk.getStats();
console.log(stats); // { trackedEvents: 1, ... }

await sdk.destroy();

File Structure

examples/minimal-sdk/
├── src/
│   ├── index.ts              # Main SDK (157 lines)
│   └── plugins/
│       ├── logger.ts         # Logging (104 lines)
│       ├── analytics.ts      # Tracking (148 lines)
│       └── monitor.ts        # Monitoring (98 lines)
├── README.md                 # Walkthrough (282 lines)
├── package.json
└── tsconfig.json

Documentation

The README includes:

  • Step-by-step code walkthrough
  • Expected console output
  • Key takeaways for each feature
  • How to extend with more plugins
  • Links to full API docs

Building & Running

cd examples/minimal-sdk
pnpm install
pnpm build    # ✅ Builds successfully

Key Takeaways

This example proves SDK Kit can be used to build real-world SDKs with:

  • Clean plugin architecture
  • Type-safe APIs
  • Flexible configuration
  • Event-driven communication
  • Proper lifecycle management

Perfect reference for developers building their own SDKs!

Closes #8

Implements Task #9 - Create Minimal Example SDK

Example SDK Features:
- Logger Plugin - Console logging with levels (debug, info, warn, error)
- Analytics Plugin - Event tracking with batching and auto-flush
- Monitor Plugin - Cross-plugin event monitoring with statistics

Demonstrates All Core Capabilities:
✅ Plugin registration and namespace setting
✅ Configuration with defaults (underwrite pattern)
✅ Event handling (pub/sub with wildcards)
✅ API exposure (plugin methods on SDK)
✅ Lifecycle management (init/destroy)
✅ Plugin communication via events

Example Structure:
- src/index.ts - Main SDK with demo usage
- src/plugins/logger.ts - Logging plugin (104 lines)
- src/plugins/analytics.ts - Analytics plugin (148 lines)
- src/plugins/monitor.ts - Monitoring plugin (98 lines)
- README.md - Comprehensive walkthrough (282 lines)
- package.json - Dependencies and scripts
- tsconfig.json - TypeScript configuration

Key Demonstrations:
- Multiple plugins working together
- Plugin-to-plugin communication
- Wildcard event subscriptions (analytics:*)
- Config sharing between plugins
- Proper cleanup on destroy
- Auto-flush with timers
- Statistics collection

Closes #8
@prosdev prosdev force-pushed the feature/task-9-example-sdk branch from aa2f557 to 3596652 Compare December 17, 2025 06:41
@prosdev prosdev merged commit ee2d30c into main Dec 17, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Minimal Example SDK

2 participants