UNPKG

@swell/cli

Version:

Swell's command line interface/utility

62 lines (58 loc) 2.16 kB
import { InspectResourceCommand, inspectResourceBaseArgs, inspectResourceBaseFlags, } from '../../inspect-resource-command.js'; export default class Webhooks extends InspectResourceCommand { static summary = 'Webhooks with delivery state.'; static description = `Lists webhooks across all apps, grouped by app. Pass --app=<slug> or --app=. (current swell.json) to scope. List output: paste-back key + status (disabled, events, failures since date). Pass an identifier to view a single record as JSON. Identifier forms: app.<app>.<alias> — full paste-back key (list column 1) <alias> — requires --app= scope <24-char id> — any scope `; static args = { ...inspectResourceBaseArgs }; static flags = { ...inspectResourceBaseFlags }; static examples = [ 'swell inspect webhooks', 'swell inspect webhooks --app=my-app', 'swell inspect webhooks app.my-app.order-sync', 'swell inspect webhooks order-sync --app=my-app', 'swell inspect webhooks --live', ]; resourceLabel = 'Webhooks'; resourceLabelSingular = 'webhook'; adminPath = '/data/:webhooks'; commandName = 'webhooks'; nameField = 'alias'; async run() { const { args, flags } = await this.parse(Webhooks); await this.runInspect({ args, flags }); } metaFor(r) { const parts = []; if (r.auto_disabled) { parts.push('auto-disabled'); } else if (!r.enabled) { parts.push('disabled'); } if (r.events?.length) { parts.push(r.events.join(',')); } const failed = r.attempts_failed ?? 0; if (failed > 0) { const suffix = r.date_final_attempt ? ` since ${r.date_final_attempt}` : ''; parts.push(`${failed} fails${suffix}`); } return parts.length > 0 ? parts.join(' · ') : undefined; } hints(record) { if (!record.id) { return []; } return [ `swell api get '/events:webhooks?where[webhook_id]=${record.id}&limit=10'`, ]; } }