// src/index.ts
import { IntegrationCLI, IntegrationEventPayload, IntegrationEventType, Spec } from '@redplanethq/sdk';
import { integrationCreate } from './account-create';
import { handleSchedule } from './schedule'; // or createActivityEvent + identify
import { getTools, callTool } from './mcp';
export async function run(eventPayload: IntegrationEventPayload) {
switch (eventPayload.event) {
case IntegrationEventType.SETUP:
return await integrationCreate(eventPayload.eventBody);
case IntegrationEventType.SYNC:
return await handleSchedule(eventPayload.config, eventPayload.state);
case IntegrationEventType.GET_TOOLS:
return await getTools();
case IntegrationEventType.CALL_TOOL:
const { name, arguments: args } = eventPayload.eventBody;
return await callTool(name, args, eventPayload.config.apiKey);
default:
return { message: `Unknown event: ${eventPayload.event}` };
}
}
class YourServiceCLI extends IntegrationCLI {
constructor() {
super('your-service', '1.0.0');
}
protected async handleEvent(eventPayload: IntegrationEventPayload) {
return await run(eventPayload);
}
protected async getSpec(): Promise<Spec> {
return {
name: 'Your Service',
key: 'your-service',
description: 'Integration description',
icon: 'your-service',
schedule: { frequency: '*/5 * * * *' }, // For schedule-based
auth: {
OAuth2: {
token_url: 'https://api.service.com/oauth/token',
authorization_url: 'https://api.service.com/oauth/authorize',
scopes: ['read', 'write'],
scope_separator: ',',
},
},
mcp: { type: 'cli' },
};
}
}
function main() {
const cli = new YourServiceCLI();
cli.parse();
}
main();