@@ -16,15 +16,31 @@ import {
16
16
BrokenLinksResultV1_BrokenLinkCheckerOptions ,
17
17
BrokenLinksResultV1_BrokenLinkCheckerOptions_LinkOrder ,
18
18
BrokenLinksResultV1_BrokenLinkCheckerOptions_PerLinkOption ,
19
+ BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions ,
20
+ BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition ,
19
21
ResponseStatusCode ,
20
22
ResponseStatusCode_StatusClass ,
21
23
} from '@google-cloud/synthetics-sdk-api' ;
22
24
import {
23
25
BrokenLinkCheckerOptions ,
24
26
LinkOrder ,
25
27
StatusClass ,
28
+ ScreenshotCondition ,
26
29
} from './broken_links' ;
27
30
31
+ /**
32
+ * Validates input options and sets defaults in `options`.
33
+ *
34
+ * @param inputOptions - The input options for the broken link checker.
35
+ * @returns The processed broken link checker options.
36
+ */
37
+ export function processOptions (
38
+ inputOptions : BrokenLinkCheckerOptions
39
+ ) : BrokenLinksResultV1_BrokenLinkCheckerOptions {
40
+ const validOptions = validateInputOptions ( inputOptions ) ;
41
+ return setDefaultOptions ( validOptions ) ;
42
+ }
43
+
28
44
/**
29
45
* Validates the input options for the Broken Link Checker.
30
46
*
@@ -130,6 +146,26 @@ export function validateInputOptions(
130
146
) ;
131
147
}
132
148
149
+ // Check storage_location
150
+ if (
151
+ inputOptions . screenshot_options ?. storage_location !== undefined &&
152
+ typeof inputOptions . screenshot_options ?. storage_location !== 'string'
153
+ ) {
154
+ throw new Error ( 'Invalid storage_location value, must be a string' ) ;
155
+ }
156
+
157
+ // check storage_condition
158
+ if (
159
+ inputOptions . screenshot_options ?. screenshot_condition !== undefined &&
160
+ ! Object . values ( ScreenshotCondition ) . includes (
161
+ inputOptions . screenshot_options ?. screenshot_condition
162
+ )
163
+ ) {
164
+ throw new Error (
165
+ 'Invalid screenshot_condition value, must be `ALL`, `FAILING`, OR `NONE`'
166
+ ) ;
167
+ }
168
+
133
169
// per_link_options
134
170
for ( const [ key , value ] of Object . entries (
135
171
inputOptions . per_link_options || { }
@@ -180,6 +216,11 @@ export function validateInputOptions(
180
216
wait_for_selector : inputOptions . wait_for_selector ,
181
217
per_link_options : inputOptions . per_link_options ,
182
218
total_synthetic_timeout_millis : inputOptions . total_synthetic_timeout_millis ,
219
+ screenshot_options : {
220
+ screenshot_condition :
221
+ inputOptions . screenshot_options ?. screenshot_condition ,
222
+ storage_location : inputOptions . screenshot_options ?. storage_location ,
223
+ } ,
183
224
} ;
184
225
}
185
226
@@ -192,7 +233,7 @@ export function validateInputOptions(
192
233
export function setDefaultOptions (
193
234
inputOptions : BrokenLinkCheckerOptions
194
235
) : BrokenLinksResultV1_BrokenLinkCheckerOptions {
195
- const defaulOptions : BrokenLinksResultV1_BrokenLinkCheckerOptions = {
236
+ const defaultOptions : BrokenLinksResultV1_BrokenLinkCheckerOptions = {
196
237
origin_uri : '' ,
197
238
link_limit : 10 ,
198
239
query_selector_all : 'a' ,
@@ -203,17 +244,26 @@ export function setDefaultOptions(
203
244
wait_for_selector : '' ,
204
245
per_link_options : { } ,
205
246
total_synthetic_timeout_millis : 60000 ,
247
+ screenshot_options : {
248
+ screenshot_condition :
249
+ BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition . FAILING ,
250
+ storage_location : '' ,
251
+ } ,
206
252
} ;
207
253
208
254
const outputOptions : BrokenLinksResultV1_BrokenLinkCheckerOptions =
209
255
{ } as BrokenLinksResultV1_BrokenLinkCheckerOptions ;
210
256
211
- const optionsKeys = Object . keys ( defaulOptions ) as Array <
257
+ const optionsKeys = Object . keys ( defaultOptions ) as Array <
212
258
keyof BrokenLinksResultV1_BrokenLinkCheckerOptions
213
259
> ;
214
260
for ( const optionName of optionsKeys ) {
215
261
// per_link_options and linkorder are handled below
216
- if ( optionName === 'per_link_options' || optionName === 'link_order' )
262
+ if (
263
+ optionName === 'per_link_options' ||
264
+ optionName === 'link_order' ||
265
+ optionName === 'screenshot_options'
266
+ )
217
267
continue ;
218
268
219
269
if (
@@ -222,13 +272,35 @@ export function setDefaultOptions(
222
272
( inputOptions as any ) [ optionName ] === undefined
223
273
) {
224
274
// eslint-disable-next-line @typescript-eslint/no-explicit-any
225
- ( outputOptions as any ) [ optionName ] = defaulOptions [ optionName ] ;
275
+ ( outputOptions as any ) [ optionName ] = defaultOptions [ optionName ] ;
226
276
} else {
227
277
// eslint-disable-next-line @typescript-eslint/no-explicit-any
228
278
( outputOptions as any ) [ optionName ] = inputOptions [ optionName ] ;
229
279
}
230
280
}
231
281
282
+ // converting inputOptions.screenshot_options to
283
+ // BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions
284
+ outputOptions . screenshot_options =
285
+ { } as BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions ;
286
+ if ( inputOptions . screenshot_options ?. screenshot_condition ) {
287
+ outputOptions . screenshot_options ! . screenshot_condition =
288
+ BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition [
289
+ inputOptions . screenshot_options . screenshot_condition
290
+ ] ;
291
+ } else {
292
+ outputOptions . screenshot_options ! . screenshot_condition =
293
+ defaultOptions . screenshot_options ! . screenshot_condition ;
294
+ }
295
+
296
+ if ( outputOptions . screenshot_options ?. storage_location ) {
297
+ outputOptions . screenshot_options . storage_location =
298
+ inputOptions . screenshot_options ! . storage_location ! ;
299
+ } else {
300
+ outputOptions . screenshot_options . storage_location =
301
+ defaultOptions . screenshot_options ! . storage_location ! ;
302
+ }
303
+
232
304
// converting inputOptions.link_order, type: LinkOrder to
233
305
// outputOptions.link_order, type BrokenLinksResultV1_BrokenLinkCheckerOptions_LinkOrder
234
306
if ( inputOptions . link_order ) {
@@ -237,7 +309,7 @@ export function setDefaultOptions(
237
309
inputOptions . link_order
238
310
] ;
239
311
} else {
240
- outputOptions . link_order = defaulOptions . link_order ;
312
+ outputOptions . link_order = defaultOptions . link_order ;
241
313
}
242
314
243
315
// Convert `inputOptions.per_link_options`, type: {[key: string]: PerLinkOption}
0 commit comments