|
| 1 | +import { Args, Flags } from '@oclif/core'; |
| 2 | +import { TWebhookPayloadMode } from '@linkedapi/node'; |
| 3 | + |
| 4 | +import { AdminBaseCommand } from '@admin-base-command'; |
| 5 | +import { formatAdminOutput } from '@core/output/admin-formatter'; |
| 6 | + |
| 7 | +export default class WebhookSet extends AdminBaseCommand { |
| 8 | + static override description = |
| 9 | + 'Register the outbound webhook that receives event deliveries (max one active per client)'; |
| 10 | + |
| 11 | + static override args = { |
| 12 | + url: Args.string({ |
| 13 | + description: 'HTTPS endpoint that will receive event deliveries', |
| 14 | + required: true, |
| 15 | + }), |
| 16 | + }; |
| 17 | + |
| 18 | + static override flags = { |
| 19 | + ...AdminBaseCommand.baseFlags, |
| 20 | + 'payload-mode': Flags.string({ |
| 21 | + description: 'fat inlines the workflow result; thin sends a reference to fetch via the API', |
| 22 | + options: ['fat', 'thin'], |
| 23 | + default: 'fat', |
| 24 | + }), |
| 25 | + }; |
| 26 | + |
| 27 | + static override examples = [ |
| 28 | + '<%= config.bin %> admin webhook set https://example.com/hooks/linkedapi', |
| 29 | + '<%= config.bin %> admin webhook set https://example.com/hooks --payload-mode thin', |
| 30 | + ]; |
| 31 | + |
| 32 | + public async run(): Promise<void> { |
| 33 | + const { args, flags } = await this.parse(WebhookSet); |
| 34 | + const admin = await this.buildAdminClient(); |
| 35 | + |
| 36 | + try { |
| 37 | + const webhook = await admin.webhooks.set({ |
| 38 | + url: args.url, |
| 39 | + payloadMode: flags['payload-mode'] as TWebhookPayloadMode, |
| 40 | + }); |
| 41 | + |
| 42 | + formatAdminOutput({ |
| 43 | + data: webhook, |
| 44 | + isJson: flags.json, |
| 45 | + fields: flags.fields, |
| 46 | + }); |
| 47 | + } catch (error) { |
| 48 | + this.handleError(error); |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments