UNPKG

@nestbox-ai/cli

Version:

The cli tools that helps developers to build agents

145 lines 8.01 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.registerDocProcWebhookCommands = registerDocProcWebhookCommands; const chalk_1 = __importDefault(require("chalk")); const apiUtils_1 = require("./apiUtils"); const helpers_1 = require("./helpers"); function registerDocProcWebhookCommands(docProcCommand) { const webhookCommand = docProcCommand.command('webhook').description('Manage document-processing webhooks'); webhookCommand .command('create') .description('Create webhook for receiving notifications') .requiredOption('--url <url>', 'Webhook URL') .option('--secret <secret>', 'Signing secret') .option('--event <event...>', 'Event name(s)') .option('--project <projectId>', 'Project ID or name (defaults to current project)') .option('--instance <instanceId>', 'Document processing instance ID') .option('--json', 'Output JSON') .action((options) => { (0, helpers_1.withDocProcErrorHandling)(() => __awaiter(this, void 0, void 0, function* () { const apis = (0, apiUtils_1.createDocProcApis)(); if (!apis) return; const context = yield (0, helpers_1.resolveDocProcContext)(apis, options); const response = yield apis.documentProcessingApi.documentProcessingControllerCreateWebhook(context.projectId, context.instanceId, { data: { url: options.url, secret: options.secret, events: options.event, }, }); const data = (0, helpers_1.getResponseData)(response); if ((0, helpers_1.maybePrintJson)(data, options.json)) return; console.log(chalk_1.default.green('Webhook created successfully.')); console.log(JSON.stringify(data, null, 2)); })); }); webhookCommand .command('list') .description('List webhooks') .option('--page <page>', 'Page number', '1') .option('--limit <limit>', 'Page size', '20') .option('--project <projectId>', 'Project ID or name (defaults to current project)') .option('--instance <instanceId>', 'Document processing instance ID') .option('--json', 'Output JSON') .action((options) => { (0, helpers_1.withDocProcErrorHandling)(() => __awaiter(this, void 0, void 0, function* () { const apis = (0, apiUtils_1.createDocProcApis)(); if (!apis) return; const context = yield (0, helpers_1.resolveDocProcContext)(apis, options); const response = yield apis.documentProcessingApi.documentProcessingControllerListWebhooks(context.projectId, context.instanceId, { params: { page: Number(options.page), limit: Number(options.limit) } }); const data = (0, helpers_1.getResponseData)(response); if ((0, helpers_1.maybePrintJson)(data, options.json)) return; const webhooks = (data === null || data === void 0 ? void 0 : data.data) || data || []; if (!webhooks.length) { console.log(chalk_1.default.yellow('No webhooks found.')); return; } (0, helpers_1.printSimpleTable)(['Webhook ID', 'URL', 'Created At'], webhooks.map((webhook) => [webhook.id || 'N/A', webhook.url || 'N/A', webhook.createdAt || 'N/A'])); })); }); webhookCommand .command('show') .description('Get webhook details by ID') .requiredOption('--webhook <webhookId>', 'Webhook ID') .option('--project <projectId>', 'Project ID or name (defaults to current project)') .option('--instance <instanceId>', 'Document processing instance ID') .option('--json', 'Output JSON') .action((options) => { (0, helpers_1.withDocProcErrorHandling)(() => __awaiter(this, void 0, void 0, function* () { const apis = (0, apiUtils_1.createDocProcApis)(); if (!apis) return; const context = yield (0, helpers_1.resolveDocProcContext)(apis, options); const response = yield apis.documentProcessingApi.documentProcessingControllerGetWebhook(context.projectId, context.instanceId, options.webhook); const data = (0, helpers_1.getResponseData)(response); if ((0, helpers_1.maybePrintJson)(data, options.json)) return; console.log(JSON.stringify(data, null, 2)); })); }); webhookCommand .command('update') .description('Update webhook configuration') .requiredOption('--webhook <webhookId>', 'Webhook ID') .option('--url <url>', 'Webhook URL') .option('--secret <secret>', 'Signing secret') .option('--event <event...>', 'Event name(s)') .option('--active <active>', 'Set webhook active state (true|false)') .option('--project <projectId>', 'Project ID or name (defaults to current project)') .option('--instance <instanceId>', 'Document processing instance ID') .option('--json', 'Output JSON') .action((options) => { (0, helpers_1.withDocProcErrorHandling)(() => __awaiter(this, void 0, void 0, function* () { const apis = (0, apiUtils_1.createDocProcApis)(); if (!apis) return; const context = yield (0, helpers_1.resolveDocProcContext)(apis, options); const response = yield apis.documentProcessingApi.documentProcessingControllerUpdateWebhook(context.projectId, context.instanceId, options.webhook, { data: { url: options.url, secret: options.secret, events: options.event, active: options.active === undefined ? undefined : options.active === 'true', }, }); const data = (0, helpers_1.getResponseData)(response); if ((0, helpers_1.maybePrintJson)(data, options.json)) return; console.log(chalk_1.default.green('Webhook updated successfully.')); console.log(JSON.stringify(data, null, 2)); })); }); webhookCommand .command('delete') .description('Delete a webhook') .requiredOption('--webhook <webhookId>', 'Webhook ID') .option('--project <projectId>', 'Project ID or name (defaults to current project)') .option('--instance <instanceId>', 'Document processing instance ID') .action((options) => { (0, helpers_1.withDocProcErrorHandling)(() => __awaiter(this, void 0, void 0, function* () { const apis = (0, apiUtils_1.createDocProcApis)(); if (!apis) return; const context = yield (0, helpers_1.resolveDocProcContext)(apis, options); yield apis.documentProcessingApi.documentProcessingControllerDeleteWebhook(context.projectId, context.instanceId, options.webhook); console.log(chalk_1.default.green('Webhook deleted successfully.')); })); }); } //# sourceMappingURL=webhook.js.map