|
| 1 | +import type { |
| 2 | + EvaluationSeriesContext, |
| 3 | + EvaluationSeriesData, |
| 4 | + LDEvaluationReason, |
| 5 | + LDFlagValue, |
| 6 | + Hook as LDHook, |
| 7 | +} from '@launchdarkly/js-client-sdk' |
| 8 | + |
| 9 | +/** |
| 10 | + * Interface for extending SDK functionality via hooks that is compatible with both javascript client versions (<=3.x and >=4.x). |
| 11 | + */ |
| 12 | +export type Hook = Omit<LDHook, 'afterEvaluation'> & { |
| 13 | + /** |
| 14 | + * This method is called during the execution of the variation method |
| 15 | + * after the flag value has been determined. The method is executed synchronously. |
| 16 | + * |
| 17 | + * @param hookContext Contains read-only information about the evaluation |
| 18 | + * being performed. |
| 19 | + * @param data A record associated with each stage of hook invocations. Each |
| 20 | + * stage is called with the data of the previous stage for a series. |
| 21 | + * @param detail The result of the evaluation. This value should not be |
| 22 | + * modified. |
| 23 | + * @returns Data to use when executing the next state of the hook in the evaluation series. It is |
| 24 | + * recommended to expand the previous input into the return. This helps ensure your stage remains |
| 25 | + * compatible moving forward as more stages are added. |
| 26 | + * ```js |
| 27 | + * return {...data, "my-new-field": /*my data/*} |
| 28 | + * ``` |
| 29 | + */ |
| 30 | + afterEvaluation?( |
| 31 | + hookContext: EvaluationSeriesContext, |
| 32 | + data: EvaluationSeriesData, |
| 33 | + detail: { |
| 34 | + /** |
| 35 | + * The result of the flag evaluation. This will be either one of the flag's variations or |
| 36 | + * the default value that was passed to `LDClient.variationDetail`. |
| 37 | + */ |
| 38 | + value: LDFlagValue |
| 39 | + /** |
| 40 | + * The index of the returned value within the flag's list of variations, e.g. 0 for the |
| 41 | + * first variation-- or `null` if the default value was returned. |
| 42 | + */ |
| 43 | + variationIndex?: number | null |
| 44 | + /** |
| 45 | + * An object describing the main factor that influenced the flag evaluation value. |
| 46 | + */ |
| 47 | + reason?: LDEvaluationReason | null |
| 48 | + }, |
| 49 | + ): EvaluationSeriesData |
| 50 | +} |
0 commit comments