trigger-mesh-sdk
v1.0.13
Published
Official TriggerMesh SDK for Node.js
Downloads
76
Maintainers
Readme
TriggerMesh SDK
Official TypeScript/JavaScript SDK for the TriggerMesh automation platform.
Installation
Option 1: NPM (Recommended)
npm install @trigger-mesh/sdkOption 2: Local Development
npm install ../trigger-mesh-sdkOption 3: Git Installation
npm install git+https://github.com/yourusername/trigger-mesh-sdk.gitQuick Start
import { TriggerMeshSDK } from '@trigger-mesh/sdk';
// Initialize SDK
const sdk = new TriggerMeshSDK({
apiKey: 'your-api-key-here',
baseUrl: 'http://localhost:3000', // Your backend URL
timeout: 30000
});
// Create a workflow
const workflow = await sdk.workflows.create({
name: 'Daily Report Generator',
description: 'Generates daily reports automatically',
desktopId: 'desktop-123',
parameters: {
reportType: 'daily',
format: 'pdf'
}
});
// Schedule it to run daily at 9 AM
const cronJob = await sdk.cronJobs.create({
name: 'Daily Report - 9 AM',
workflowId: workflow.id,
desktopId: 'desktop-123',
cronExpression: '0 9 * * *',
timezone: 'UTC'
});
// Run immediately
const task = await sdk.tasks.create({
workflowId: workflow.id,
desktopId: 'desktop-123',
triggerType: 'MANUAL'
});API Reference
Core Managers
WorkflowManager
// Create workflow
const workflow = await sdk.workflows.create(data);
// Get workflow by ID
const workflow = await sdk.workflows.getById(id);
// List workflows
const workflows = await sdk.workflows.getAll(filters);
// Update workflow
const updated = await sdk.workflows.update(id, data);
// Delete workflow
await sdk.workflows.delete(id);
// Execute workflow
const result = await sdk.workflows.execute(workflowId, parameters);TaskManager
// Create task
const task = await sdk.tasks.create({
workflowId: 'workflow-123',
desktopId: 'desktop-123',
priority: 1,
parameters: { key: 'value' },
triggerType: 'MANUAL'
});
// Get task by ID
const task = await sdk.tasks.getById(id);
// List tasks
const tasks = await sdk.tasks.getAll(filters);
// Cancel task
await sdk.tasks.cancel(id);
// Retry failed task
await sdk.tasks.retry(id);CronJobManager
// Create cron job
const cronJob = await sdk.cronJobs.create({
name: 'Daily Backup',
workflowId: 'workflow-123',
desktopId: 'desktop-123',
cronExpression: '0 2 * * *',
timezone: 'UTC'
});
// List cron jobs
const cronJobs = await sdk.cronJobs.getAll();
// Activate/Deactivate
await sdk.cronJobs.activate(id);
await sdk.cronJobs.deactivate(id);
// Trigger manually
await sdk.cronJobs.trigger(id, parameters);WebhookManager
// Incoming webhooks (trigger workflows)
const incoming = await sdk.webhooks.createIncoming({
name: 'API Trigger',
workflowId: 'workflow-123',
desktopId: 'desktop-123',
url: 'https://your-app.com/webhook',
secret: 'your-secret'
});
// Outgoing webhooks (task notifications)
const outgoing = await sdk.webhooks.createOutgoing({
taskId: 'task-123',
url: 'https://your-app.com/notifications',
events: ['task.completed', 'task.failed']
});Convenience Methods
// Create and schedule workflow in one call
const { workflow, cronJob } = await sdk.createAndScheduleWorkflow({
name: 'Weekly Backup',
desktopId: 'desktop-123',
cronExpression: '0 2 * * 0',
parameters: { backupType: 'full' }
});
// Create and run workflow immediately
const { workflow, task } = await sdk.createAndRunWorkflow({
name: 'Immediate Test',
desktopId: 'desktop-123',
priority: 1
});
// Get comprehensive system status
const status = await sdk.getSystemStatus();Error Handling
The SDK provides comprehensive error handling:
try {
const workflow = await sdk.workflows.create(data);
} catch (error) {
if (error instanceof TriggerMeshSDKError) {
console.error('API Error:', error.message);
console.error('Status Code:', error.statusCode);
console.error('Details:', error.details);
} else {
console.error('Unexpected error:', error);
}
}Response Handling
Standard Response Format
// All SDK methods return the data directly
const workflow = await sdk.workflows.create(data);
// workflow is the actual Workflow object
// For enhanced response handling, use requestWithResponse
const response = await sdk.client.requestWithResponse('workflow.create', data);
// response = { success: true, data: Workflow, meta: { timestamp, requestId, version } }Paginated Responses
// List methods support pagination
const workflows = await sdk.workflows.getAll({
limit: 10,
offset: 0
});Publishing the SDK
1. Update Version
npm version patch # or minor/major2. Build
npm run build3. Publish
npm publish4. Verify
npm view @trigger-mesh/sdkDevelopment
Setup
npm install
npm run buildTesting
npm testWatch Mode
npm run devTypeScript Support
The SDK is written in TypeScript and provides full type definitions:
import {
TriggerMeshSDK,
Workflow,
Task,
CronJob,
CreateWorkflowData
} from '@trigger-mesh/sdk';
const sdk: TriggerMeshSDK = new TriggerMeshSDK(config);
const workflow: Workflow = await sdk.workflows.create(data);Examples
See the examples/ directory for comprehensive usage examples:
- Basic workflow creation and execution
- Advanced scheduling with cron jobs
- Webhook management
- Error handling patterns
- Workflow pack management
Support
- Documentation: https://docs.trigger-mesh.com
- Issues: GitHub Issues
- Email: [email protected]
License
MIT License - see LICENSE file for details.
