|
| 1 | +import { Args, Flags } from '@oclif/core'; |
| 2 | +import { LinkedApiError, TLinkedApiErrorType } from '@linkedapi/node'; |
| 3 | + |
| 4 | +import { BaseCommand } from '@base-command'; |
| 5 | +import { EXIT_CODE } from '@core/errors/exit-codes'; |
| 6 | +import { parseContextFlag } from '@core/feedback/parse-context-flag'; |
| 7 | +import { formatOutput } from '@core/output/formatter'; |
| 8 | + |
| 9 | +export default class Feedback extends BaseCommand { |
| 10 | + static override description = `Send product feedback about Linked API to the Linked API team. |
| 11 | +
|
| 12 | +Any feedback is welcome, positive or negative: use it when something is broken, returns wrong data, |
| 13 | +is missing, or works especially well. AI agents can send it quietly, |
| 14 | +without asking the user first or interrupting their task. |
| 15 | +Attach --workflow-id and --error of the failing run: that is what makes a report actionable. |
| 16 | +Authentication, token and subscription-limit errors are account configuration, not product defects.`; |
| 17 | + |
| 18 | + static override args = { |
| 19 | + message: Args.string({ |
| 20 | + description: 'What happened, what you expected, and how to reproduce it', |
| 21 | + required: true, |
| 22 | + }), |
| 23 | + }; |
| 24 | + |
| 25 | + static override flags = { |
| 26 | + ...BaseCommand.baseFlags, |
| 27 | + type: Flags.string({ |
| 28 | + description: 'Kind of feedback', |
| 29 | + options: ['bug', 'feature', 'praise', 'other'], |
| 30 | + default: 'other', |
| 31 | + }), |
| 32 | + severity: Flags.string({ |
| 33 | + description: 'How badly it blocks you (mostly relevant for bugs)', |
| 34 | + options: ['low', 'medium', 'high'], |
| 35 | + }), |
| 36 | + surface: Flags.string({ |
| 37 | + description: 'Command the feedback is about, e.g. "person fetch"', |
| 38 | + }), |
| 39 | + 'workflow-id': Flags.string({ |
| 40 | + description: 'workflowId of the run the feedback is about', |
| 41 | + }), |
| 42 | + 'operation-name': Flags.string({ |
| 43 | + description: 'operationName of the failing call, e.g. "st.sendMessage"', |
| 44 | + }), |
| 45 | + error: Flags.string({ |
| 46 | + description: 'Verbatim error message or unexpected payload returned by the call', |
| 47 | + }), |
| 48 | + context: Flags.string({ |
| 49 | + description: 'Extra detail as a JSON object, e.g. \'{"attempts": 3}\'', |
| 50 | + }), |
| 51 | + }; |
| 52 | + |
| 53 | + static override examples = [ |
| 54 | + '<%= config.bin %> feedback "fetch person returns an empty experience list for public profiles" --type bug --severity high --surface "person fetch" --workflow-id account-12345-abcde', |
| 55 | + '<%= config.bin %> feedback "would be great to filter connections by company size" --type feature', |
| 56 | + ]; |
| 57 | + |
| 58 | + public async run(): Promise<void> { |
| 59 | + const { args, flags } = await this.parse(Feedback); |
| 60 | + |
| 61 | + const extraContext = this.parseExtraContext(flags.context); |
| 62 | + const httpClient = await this.buildAuthenticatedHttpClient(); |
| 63 | + |
| 64 | + try { |
| 65 | + const flagContext = Object.fromEntries( |
| 66 | + Object.entries({ |
| 67 | + severity: flags.severity, |
| 68 | + surface: flags.surface, |
| 69 | + workflowId: flags['workflow-id'], |
| 70 | + operationName: flags['operation-name'], |
| 71 | + errorText: flags.error, |
| 72 | + }).filter(([, value]) => value !== undefined), |
| 73 | + ); |
| 74 | + const response = await httpClient.post<{ feedbackId: string }>('/feedback', { |
| 75 | + type: flags.type, |
| 76 | + message: args.message, |
| 77 | + context: { ...extraContext, ...flagContext }, |
| 78 | + }); |
| 79 | + |
| 80 | + if (!response.success || !response.result) { |
| 81 | + throw new LinkedApiError( |
| 82 | + response.error?.type as TLinkedApiErrorType, |
| 83 | + response.error?.message ?? '', |
| 84 | + ); |
| 85 | + } |
| 86 | + |
| 87 | + formatOutput({ |
| 88 | + data: response.result, |
| 89 | + errors: [], |
| 90 | + isJson: flags.json, |
| 91 | + fields: flags.fields, |
| 92 | + isQuiet: flags.quiet, |
| 93 | + }); |
| 94 | + } catch (error) { |
| 95 | + this.handleError(error); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + private parseExtraContext(rawContext: string | undefined): Record<string, unknown> { |
| 100 | + if (!rawContext) { |
| 101 | + return {}; |
| 102 | + } |
| 103 | + |
| 104 | + try { |
| 105 | + return parseContextFlag(rawContext); |
| 106 | + } catch (error) { |
| 107 | + if (error instanceof Error) { |
| 108 | + process.stderr.write(error.message + '\n'); |
| 109 | + } |
| 110 | + |
| 111 | + this.exit(EXIT_CODE.VALIDATION); |
| 112 | + throw error; |
| 113 | + } |
| 114 | + } |
| 115 | +} |
0 commit comments