|
| 1 | +/** |
| 2 | + * Having Survey types in types.ts was confusing tsc |
| 3 | + * and generating an invalid module.d.ts |
| 4 | + * See https://github.com/PostHog/posthog-js/issues/698 |
| 5 | + */ |
| 6 | + |
| 7 | +export interface SurveyAppearance { |
| 8 | + // keep in sync with frontend/src/types.ts -> SurveyAppearance |
| 9 | + backgroundColor?: string |
| 10 | + submitButtonColor?: string |
| 11 | + // deprecate submit button text eventually |
| 12 | + submitButtonText?: string |
| 13 | + submitButtonTextColor?: string |
| 14 | + ratingButtonColor?: string |
| 15 | + ratingButtonActiveColor?: string |
| 16 | + autoDisappear?: boolean |
| 17 | + displayThankYouMessage?: boolean |
| 18 | + thankYouMessageHeader?: string |
| 19 | + thankYouMessageDescription?: string |
| 20 | + thankYouMessageDescriptionContentType?: SurveyQuestionDescriptionContentType |
| 21 | + thankYouMessageCloseButtonText?: string |
| 22 | + borderColor?: string |
| 23 | + position?: 'left' | 'right' | 'center' |
| 24 | + placeholder?: string |
| 25 | + shuffleQuestions?: boolean |
| 26 | + surveyPopupDelaySeconds?: number |
| 27 | + // widget options |
| 28 | + widgetType?: 'button' | 'tab' | 'selector' |
| 29 | + widgetSelector?: string |
| 30 | + widgetLabel?: string |
| 31 | + widgetColor?: string |
| 32 | +} |
| 33 | + |
| 34 | +export enum SurveyType { |
| 35 | + Popover = 'popover', |
| 36 | + API = 'api', |
| 37 | + Widget = 'widget', |
| 38 | +} |
| 39 | + |
| 40 | +export type SurveyQuestion = BasicSurveyQuestion | LinkSurveyQuestion | RatingSurveyQuestion | MultipleSurveyQuestion |
| 41 | + |
| 42 | +export type SurveyQuestionDescriptionContentType = 'html' | 'text' |
| 43 | + |
| 44 | +interface SurveyQuestionBase { |
| 45 | + question: string |
| 46 | + description?: string | null |
| 47 | + descriptionContentType?: SurveyQuestionDescriptionContentType |
| 48 | + optional?: boolean |
| 49 | + buttonText?: string |
| 50 | + originalQuestionIndex: number |
| 51 | + branching?: NextQuestionBranching | EndBranching | ResponseBasedBranching | SpecificQuestionBranching |
| 52 | +} |
| 53 | + |
| 54 | +export interface BasicSurveyQuestion extends SurveyQuestionBase { |
| 55 | + type: SurveyQuestionType.Open |
| 56 | +} |
| 57 | + |
| 58 | +export interface LinkSurveyQuestion extends SurveyQuestionBase { |
| 59 | + type: SurveyQuestionType.Link |
| 60 | + link?: string | null |
| 61 | +} |
| 62 | + |
| 63 | +export interface RatingSurveyQuestion extends SurveyQuestionBase { |
| 64 | + type: SurveyQuestionType.Rating |
| 65 | + display: 'number' | 'emoji' |
| 66 | + scale: 3 | 5 | 7 | 10 |
| 67 | + lowerBoundLabel: string |
| 68 | + upperBoundLabel: string |
| 69 | +} |
| 70 | + |
| 71 | +export interface MultipleSurveyQuestion extends SurveyQuestionBase { |
| 72 | + type: SurveyQuestionType.SingleChoice | SurveyQuestionType.MultipleChoice |
| 73 | + choices: string[] |
| 74 | + hasOpenChoice?: boolean |
| 75 | + shuffleOptions?: boolean |
| 76 | +} |
| 77 | + |
| 78 | +export enum SurveyQuestionType { |
| 79 | + Open = 'open', |
| 80 | + MultipleChoice = 'multiple_choice', |
| 81 | + SingleChoice = 'single_choice', |
| 82 | + Rating = 'rating', |
| 83 | + Link = 'link', |
| 84 | +} |
| 85 | + |
| 86 | +export enum SurveyQuestionBranchingType { |
| 87 | + NextQuestion = 'next_question', |
| 88 | + End = 'end', |
| 89 | + ResponseBased = 'response_based', |
| 90 | + SpecificQuestion = 'specific_question', |
| 91 | +} |
| 92 | + |
| 93 | +interface NextQuestionBranching { |
| 94 | + type: SurveyQuestionBranchingType.NextQuestion |
| 95 | +} |
| 96 | + |
| 97 | +interface EndBranching { |
| 98 | + type: SurveyQuestionBranchingType.End |
| 99 | +} |
| 100 | + |
| 101 | +interface ResponseBasedBranching { |
| 102 | + type: SurveyQuestionBranchingType.ResponseBased |
| 103 | + responseValues: Record<string, any> |
| 104 | +} |
| 105 | + |
| 106 | +interface SpecificQuestionBranching { |
| 107 | + type: SurveyQuestionBranchingType.SpecificQuestion |
| 108 | + index: number |
| 109 | +} |
| 110 | + |
| 111 | +export interface SurveyResponse { |
| 112 | + surveys: Survey[] |
| 113 | +} |
| 114 | + |
| 115 | +export type SurveyCallback = (surveys: Survey[]) => void |
| 116 | + |
| 117 | +export type SurveyUrlMatchType = 'regex' | 'not_regex' | 'exact' | 'is_not' | 'icontains' | 'not_icontains' |
| 118 | + |
| 119 | +export interface SurveyElement { |
| 120 | + text?: string |
| 121 | + $el_text?: string |
| 122 | + tag_name?: string |
| 123 | + href?: string |
| 124 | + attr_id?: string |
| 125 | + attr_class?: string[] |
| 126 | + nth_child?: number |
| 127 | + nth_of_type?: number |
| 128 | + attributes?: Record<string, any> |
| 129 | + event_id?: number |
| 130 | + order?: number |
| 131 | + group_id?: number |
| 132 | +} |
| 133 | +export interface SurveyRenderReason { |
| 134 | + visible: boolean |
| 135 | + disabledReason?: string |
| 136 | +} |
| 137 | + |
| 138 | +export interface Survey { |
| 139 | + // Sync this with the backend's SurveyAPISerializer! |
| 140 | + id: string |
| 141 | + name: string |
| 142 | + description: string |
| 143 | + type: SurveyType |
| 144 | + feature_flag_keys: |
| 145 | + | { |
| 146 | + key: string |
| 147 | + value?: string |
| 148 | + }[] |
| 149 | + | null |
| 150 | + linked_flag_key: string | null |
| 151 | + targeting_flag_key: string | null |
| 152 | + internal_targeting_flag_key: string | null |
| 153 | + questions: SurveyQuestion[] |
| 154 | + appearance: SurveyAppearance | null |
| 155 | + conditions: { |
| 156 | + url?: string |
| 157 | + selector?: string |
| 158 | + seenSurveyWaitPeriodInDays?: number |
| 159 | + urlMatchType?: SurveyUrlMatchType |
| 160 | + events: { |
| 161 | + repeatedActivation?: boolean |
| 162 | + values: { |
| 163 | + name: string |
| 164 | + }[] |
| 165 | + } | null |
| 166 | + actions: { |
| 167 | + values: SurveyActionType[] |
| 168 | + } | null |
| 169 | + } | null |
| 170 | + start_date: string | null |
| 171 | + end_date: string | null |
| 172 | + current_iteration: number | null |
| 173 | + current_iteration_start_date: string | null |
| 174 | +} |
| 175 | + |
| 176 | +export interface SurveyActionType { |
| 177 | + id: number |
| 178 | + name: string | null |
| 179 | + steps?: ActionStepType[] |
| 180 | +} |
| 181 | + |
| 182 | +/** Sync with plugin-server/src/types.ts */ |
| 183 | +export type ActionStepStringMatching = 'contains' | 'exact' | 'regex' |
| 184 | + |
| 185 | +export interface ActionStepType { |
| 186 | + event?: string | null |
| 187 | + selector?: string | null |
| 188 | + /** @deprecated Only `selector` should be used now. */ |
| 189 | + tag_name?: string |
| 190 | + text?: string | null |
| 191 | + /** @default StringMatching.Exact */ |
| 192 | + text_matching?: ActionStepStringMatching | null |
| 193 | + href?: string | null |
| 194 | + /** @default ActionStepStringMatching.Exact */ |
| 195 | + href_matching?: ActionStepStringMatching | null |
| 196 | + url?: string | null |
| 197 | + /** @default StringMatching.Contains */ |
| 198 | + url_matching?: ActionStepStringMatching | null |
| 199 | +} |
0 commit comments