( now: Date, statusLookup: NpsStatusLookup, rl: ReadlineInterface, eventCapture: EventCapture, commandState: CommandState, )
| 90 | } |
| 91 | |
| 92 | export async function handleNpsSurveyImpl( |
| 93 | now: Date, |
| 94 | statusLookup: NpsStatusLookup, |
| 95 | rl: ReadlineInterface, |
| 96 | eventCapture: EventCapture, |
| 97 | commandState: CommandState, |
| 98 | ) { |
| 99 | if ( |
| 100 | isCi() || |
| 101 | maybeInGitHook() || |
| 102 | isInNpmLifecycleHook() || |
| 103 | isInContainer() || |
| 104 | daysSinceFirstCommand(commandState) < 1 |
| 105 | ) { |
| 106 | return |
| 107 | } |
| 108 | |
| 109 | const config = await readConfig() |
| 110 | if (config && isWithinTimeframe(now, config.acknowledgedTimeframe)) { |
| 111 | // the user has already acknowledged an NPS survey covering the current date |
| 112 | return |
| 113 | } |
| 114 | |
| 115 | const status = await statusLookup.status() |
| 116 | if (!status.currentTimeframe || !isWithinTimeframe(now, status.currentTimeframe)) { |
| 117 | // no NPS survey is currently active |
| 118 | return |
| 119 | } |
| 120 | |
| 121 | const result = await collectFeedback(rl) |
| 122 | |
| 123 | if (result.rating) { |
| 124 | await submitSurveyEvent({ rating: result.rating, ...result }, eventCapture) |
| 125 | rl.write('Thanks for your feedback!\n') |
| 126 | } |
| 127 | |
| 128 | await writeConfig({ acknowledgedTimeframe: status.currentTimeframe }) |
| 129 | } |
| 130 | |
| 131 | async function collectFeedback(rl: ReadlineInterface): Promise<NpsSurveyResult> { |
| 132 | const question = rl.question( |
no test coverage detected