1 | import { createClient } from '@typeform/api-client' |
2 |
|
3 | type Typeform = { |
4 | token: string |
5 | baseUrl: string |
6 | } |
7 |
|
8 | export async function main( |
9 | resource: Typeform, |
10 | data: { |
11 | id?: string |
12 | title?: string |
13 | language?: |
14 | | 'en' |
15 | | 'es' |
16 | | 'ca' |
17 | | 'fr' |
18 | | 'de' |
19 | | 'ru' |
20 | | 'it' |
21 | | 'da' |
22 | | 'pt' |
23 | | 'ch' |
24 | | 'zh' |
25 | | 'nl' |
26 | | 'no' |
27 | | 'uk' |
28 | | 'ja' |
29 | | 'ko' |
30 | | 'hr' |
31 | | 'fi' |
32 | | 'sv' |
33 | | 'pl' |
34 | | 'el' |
35 | | 'hu' |
36 | | 'tr' |
37 | | 'cs' |
38 | | 'et' |
39 | | 'di' |
40 | fields?: { |
41 | id?: string |
42 | ref?: string |
43 | title?: string |
44 | type?: |
45 | | 'address' |
46 | | 'calendly' |
47 | | 'contact_info' |
48 | | 'date' |
49 | | 'dropdown' |
50 | | 'email' |
51 | | 'file_upload' |
52 | | 'group' |
53 | | 'legal' |
54 | | 'long_text' |
55 | | 'matrix' |
56 | | 'multiple_choice' |
57 | | 'nps' |
58 | | 'number' |
59 | | 'opinion_scale' |
60 | | 'payment' |
61 | | 'phone_number' |
62 | | 'picture_choice' |
63 | | 'ranking' |
64 | | 'rating' |
65 | | 'short_text' |
66 | | 'statement' |
67 | | 'website' |
68 | | 'yes_no' |
69 | properties?: { |
70 | description?: string |
71 | choices?: { |
72 | id?: string |
73 | ref?: string |
74 | label?: string |
75 | attachment?: { |
76 | type?: 'image' | 'video' |
77 | href?: string |
78 | scale?: 0.4 | 0.6 | 0.8 | 1 |
79 | } |
80 | }[] |
81 | fields?: any[] |
82 | allow_multiple_selection?: boolean |
83 | randomize?: boolean |
84 | allow_other_choice?: boolean |
85 | vertical_alignment?: boolean |
86 | supersized?: boolean |
87 | show_labels?: boolean |
88 | alphabetical_order?: boolean |
89 | hide_marks?: boolean |
90 | button_text?: string |
91 | steps?: 5 | 6 | 7 | 8 | 9 | 10 | 11 |
92 | shape?: |
93 | | 'cat' |
94 | | 'circle' |
95 | | 'cloud' |
96 | | 'crown' |
97 | | 'dog' |
98 | | 'droplet' |
99 | | 'flag' |
100 | | 'heart' |
101 | | 'lightbulb' |
102 | | 'pencil' |
103 | | 'skull' |
104 | | 'star' |
105 | | 'thunderbolt' |
106 | | 'tick' |
107 | | 'trophy' |
108 | | 'up' |
109 | | 'user' |
110 | labels?: { |
111 | left?: string |
112 | right?: string |
113 | center?: string |
114 | } |
115 | start_at_one?: boolean |
116 | structure?: 'MMDDYYYY' | 'DDMMYYYY' | 'YYYYMMDD' |
117 | separator?: '/' | '-' | '.' |
118 | currency?: |
119 | | 'AUD' |
120 | | 'BRL' |
121 | | 'CAD' |
122 | | 'CHF' |
123 | | 'DKK' |
124 | | 'EUR' |
125 | | 'GBP' |
126 | | 'MXN' |
127 | | 'NOK' |
128 | | 'SEK' |
129 | | 'USD' |
130 | } |
131 | validations?: { |
132 | required?: boolean |
133 | max_length?: number |
134 | min_value?: number |
135 | max_value?: number |
136 | } |
137 | attachment?: { |
138 | type?: 'image' | 'video' |
139 | href?: string |
140 | scale?: 0.4 | 0.6 | 0.8 | 1 |
141 | } |
142 | }[] |
143 | hidden?: string[] |
144 | welcome_screens?: { |
145 | ref?: string |
146 | title?: string |
147 | properties?: { |
148 | description?: string |
149 | show_button?: boolean |
150 | button_text?: string |
151 | } |
152 | attachment?: { |
153 | type?: 'image' | 'video' |
154 | href?: string |
155 | scale?: 0.4 | 0.6 | 0.8 | 1 |
156 | } |
157 | }[] |
158 | thankyou_screens?: { |
159 | ref?: string |
160 | title?: string |
161 | properties?: { |
162 | show_button?: boolean |
163 | button_text?: string |
164 | button_mode?: 'reload' | 'redirect' |
165 | redirect_url?: string |
166 | share_icons?: boolean |
167 | } |
168 | attachment?: { |
169 | type?: 'image' | 'video' |
170 | href?: string |
171 | scale?: 0.4 | 0.6 | 0.8 | 1 |
172 | } |
173 | }[] |
174 | logic?: { |
175 | type?: 'field' | 'hidden' |
176 | actions?: { |
177 | action?: 'jump' | 'add' | 'subtract' | 'multiply' | 'divide' |
178 | details?: { |
179 | to?: { |
180 | type?: 'field' | 'hidden' | 'thankyou' |
181 | value?: string |
182 | } |
183 | target?: { |
184 | type?: 'variable' |
185 | value?: 'score' | 'price' |
186 | } |
187 | value?: { |
188 | type?: 'constant' |
189 | value?: number |
190 | } |
191 | } |
192 | condition?: |
193 | | { |
194 | op?: |
195 | | 'begins_with' |
196 | | 'ends_with' |
197 | | 'contains' |
198 | | 'not_contains' |
199 | | 'lower_than' |
200 | | 'lower_equal_than' |
201 | | 'greater_than' |
202 | | 'greater_equal_than' |
203 | | 'is' |
204 | | 'is_not' |
205 | | 'equal' |
206 | | 'not_equal' |
207 | | 'always' |
208 | | 'on' |
209 | | 'not_on' |
210 | | 'earlier_than' |
211 | | 'earlier_than_or_on' |
212 | | 'later_than' |
213 | | 'later_than_or_on' |
214 | vars?: { |
215 | type?: 'field' | 'hidden' | 'variable' | 'constant' | 'end' | 'choice' |
216 | value?: any |
217 | }[] |
218 | } |
219 | | { |
220 | op?: 'and' | 'or' |
221 | vars: Array<any> |
222 | } |
223 | }[] |
224 | }[] |
225 | theme?: |
226 | | { |
227 | href?: string |
228 | } |
229 | | string |
230 | workspace?: { |
231 | href?: string |
232 | } |
233 | _links?: { |
234 | display?: string |
235 | } |
236 | settings?: { |
237 | are_uploads_public?: boolean |
238 | autosave_progress?: boolean |
239 | free_form_navigation?: boolean |
240 | hide_navigation?: boolean |
241 | is_public?: boolean |
242 | language?: |
243 | | 'en' |
244 | | 'es' |
245 | | 'ca' |
246 | | 'fr' |
247 | | 'de' |
248 | | 'ru' |
249 | | 'it' |
250 | | 'da' |
251 | | 'pt' |
252 | | 'ch' |
253 | | 'zh' |
254 | | 'nl' |
255 | | 'no' |
256 | | 'uk' |
257 | | 'ja' |
258 | | 'ko' |
259 | | 'hr' |
260 | | 'fi' |
261 | | 'sv' |
262 | | 'pl' |
263 | | 'el' |
264 | | 'hu' |
265 | | 'tr' |
266 | | 'cs' |
267 | | 'et' |
268 | | 'di' |
269 | meta?: { |
270 | allow_indexing?: boolean |
271 | description?: string |
272 | image?: { |
273 | href?: string |
274 | } |
275 | } |
276 | pro_subdomain_enabled?: boolean |
277 | progress_bar?: 'percentage' | 'proportion' |
278 | show_cookie_consent?: boolean |
279 | show_key_hint_on_choices?: boolean |
280 | show_number_of_submissions?: boolean |
281 | show_progress_bar?: boolean |
282 | show_question_number?: boolean |
283 | show_time_to_complete?: boolean |
284 | show_typeform_branding?: boolean |
285 | use_lead_qualification?: boolean |
286 | redirect_after_submit_url?: string |
287 | google_analytics?: string |
288 | facebook_pixel?: string |
289 | google_tag_manager?: string |
290 | notification?: { |
291 | self?: { |
292 | enabled?: boolean |
293 | recipients?: string[] |
294 | reply_to?: string |
295 | subject?: string |
296 | message?: string |
297 | } |
298 | respondent?: { |
299 | enabled?: boolean |
300 | recipient?: string |
301 | reply_to?: string[] |
302 | subject?: string |
303 | message?: string |
304 | } |
305 | } |
306 | } |
307 | variables?: { |
308 | score?: 0 |
309 | price?: number |
310 | } |
311 | } |
312 | ) { |
313 | const typeformAPI = createClient({ |
314 | token: resource.token, |
315 | apiBaseUrl: resource.baseUrl |
316 | }) |
317 |
|
318 | return await typeformAPI.forms.create({ |
319 | data |
320 | }) |
321 | } |
322 |
|