#!/usr/bin/env node import { Command } from 'commander'; import { initCommand } from './commands/init.js'; import { addProviderCommand } from './commands/add-provider.js'; import { testCommand } from './commands/test.js'; import { connectionsListCommand, doctorCommand, providersInspectCommand, providersListCommand, syncBackfillCommand, webhooksReplayCommand, } from './commands/runtime.js'; const program = new Command(); program .name('plugfn') .description('CLI tool for PlugFn SDK') .version('0.0.4'); // Init command program .command('init') .description('Initialize a new PlugFn project') .option('-d, --directory ', 'Target directory', '.') .action(initCommand); // Add provider command program .command('add-provider') .description('Create a new provider from template') .option('-n, --name ', 'Provider name (required)') .option('-a, --auth ', 'Auth type (oauth2, api-key, jwt, basic)', 'api-key') .option('-o, --output ', 'Output directory', './src/providers') .action(addProviderCommand); // Test command program .command('test') .description('Test connections and actions') .option('-p, --provider ', 'Provider to test') .option('-u, --user-id ', 'User ID to resolve connections for') .option('-a, --action ', 'Action to test') .option('-c, --connection-id ', 'Connection ID to use') .option('--params-file ', 'JSON file with action params') .option('--webhook-fixture ', 'JSON file with webhook diagnostic fixture') .option('--json', 'Emit machine-readable JSON output') .option('--live', 'Run optional provider live health check') .action(testCommand); const providers = program.command('providers').description('Inspect registered providers'); providers .command('list') .description('List providers registered by the PlugFn runtime') .option('--json', 'Emit machine-readable JSON output') .action(providersListCommand); providers .command('inspect') .description('Inspect a registered provider') .argument('', 'Provider id') .option('--json', 'Emit machine-readable JSON output') .action(providersInspectCommand); const connections = program.command('connections').description('Inspect PlugFn connections'); connections .command('list') .description('List connections for a user') .option('-p, --provider ', 'Provider to filter by') .requiredOption('-u, --user-id ', 'User ID') .option('--json', 'Emit machine-readable JSON output') .action(connectionsListCommand); const sync = program.command('sync').description('Run PlugFn sync jobs'); sync .command('backfill') .description('Start a full backfill sync job') .requiredOption('-p, --provider ', 'Provider id') .requiredOption('-c, --connection ', 'Connection id') .requiredOption('-r, --resource ', 'Resource name') .option('-u, --user-id ', 'Actor user ID') .option('--json', 'Emit machine-readable JSON output') .action(syncBackfillCommand); const webhooks = program.command('webhooks').description('Inspect and replay PlugFn webhooks'); webhooks .command('replay') .description('Inspect a persisted webhook receipt and deliveries') .requiredOption('--receipt ', 'Webhook receipt id') .option('--json', 'Emit machine-readable JSON output') .action(webhooksReplayCommand); program .command('doctor') .description('Validate PlugFn runtime wiring') .option('--json', 'Emit machine-readable JSON output') .action(doctorCommand); program.parse(process.argv);