cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/challenges/widgets.ts
624lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. |
| 2 | |
| 3 | import * as Core from 'cloudflare/core'; |
| 4 | import { APIResource } from 'cloudflare/resource'; |
| 5 | import { isRequestOptions } from 'cloudflare/core'; |
| 6 | import * as WidgetsAPI from 'cloudflare/resources/challenges/widgets'; |
| 7 | |
| 8 | export class Widgets extends APIResource { |
| 9 | /** |
| 10 | * Lists challenge widgets. |
| 11 | */ |
| 12 | create( |
| 13 | accountIdentifier: string, |
| 14 | params: WidgetCreateParams, |
| 15 | options?: Core.RequestOptions, |
| 16 | ): Core.APIPromise<WidgetCreateResponse> { |
| 17 | const { direction, order, page, per_page, ...body } = params; |
| 18 | return ( |
| 19 | this._client.post(`/accounts/${accountIdentifier}/challenges/widgets`, { |
| 20 | query: { direction, order, page, per_page }, |
| 21 | body, |
| 22 | ...options, |
| 23 | }) as Core.APIPromise<{ result: WidgetCreateResponse }> |
| 24 | )._thenUnwrap((obj) => obj.result); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Show a single challenge widget configuration. |
| 29 | */ |
| 30 | retrieve( |
| 31 | accountIdentifier: string, |
| 32 | sitekey: string, |
| 33 | options?: Core.RequestOptions, |
| 34 | ): Core.APIPromise<WidgetRetrieveResponse> { |
| 35 | return ( |
| 36 | this._client.get( |
| 37 | `/accounts/${accountIdentifier}/challenges/widgets/${sitekey}`, |
| 38 | options, |
| 39 | ) as Core.APIPromise<{ result: WidgetRetrieveResponse }> |
| 40 | )._thenUnwrap((obj) => obj.result); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Update the configuration of a widget. |
| 45 | */ |
| 46 | update( |
| 47 | accountIdentifier: string, |
| 48 | sitekey: string, |
| 49 | body: WidgetUpdateParams, |
| 50 | options?: Core.RequestOptions, |
| 51 | ): Core.APIPromise<WidgetUpdateResponse> { |
| 52 | return ( |
| 53 | this._client.put(`/accounts/${accountIdentifier}/challenges/widgets/${sitekey}`, { |
| 54 | body, |
| 55 | ...options, |
| 56 | }) as Core.APIPromise<{ result: WidgetUpdateResponse }> |
| 57 | )._thenUnwrap((obj) => obj.result); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Lists all turnstile widgets of an account. |
| 62 | */ |
| 63 | list( |
| 64 | accountIdentifier: string, |
| 65 | query?: WidgetListParams, |
| 66 | options?: Core.RequestOptions, |
| 67 | ): Core.APIPromise<WidgetListResponse>; |
| 68 | list(accountIdentifier: string, options?: Core.RequestOptions): Core.APIPromise<WidgetListResponse>; |
| 69 | list( |
| 70 | accountIdentifier: string, |
| 71 | query: WidgetListParams | Core.RequestOptions = {}, |
| 72 | options?: Core.RequestOptions, |
| 73 | ): Core.APIPromise<WidgetListResponse> { |
| 74 | if (isRequestOptions(query)) { |
| 75 | return this.list(accountIdentifier, {}, query); |
| 76 | } |
| 77 | return ( |
| 78 | this._client.get(`/accounts/${accountIdentifier}/challenges/widgets`, { |
| 79 | query, |
| 80 | ...options, |
| 81 | }) as Core.APIPromise<{ result: WidgetListResponse }> |
| 82 | )._thenUnwrap((obj) => obj.result); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Destroy a Turnstile Widget. |
| 87 | */ |
| 88 | delete( |
| 89 | accountIdentifier: string, |
| 90 | sitekey: string, |
| 91 | options?: Core.RequestOptions, |
| 92 | ): Core.APIPromise<WidgetDeleteResponse> { |
| 93 | return ( |
| 94 | this._client.delete( |
| 95 | `/accounts/${accountIdentifier}/challenges/widgets/${sitekey}`, |
| 96 | options, |
| 97 | ) as Core.APIPromise<{ result: WidgetDeleteResponse }> |
| 98 | )._thenUnwrap((obj) => obj.result); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Generate a new secret key for this widget. If `invalidate_immediately` is set to |
| 103 | * `false`, the previous secret remains valid for 2 hours. |
| 104 | * |
| 105 | * Note that secrets cannot be rotated again during the grace period. |
| 106 | */ |
| 107 | rotateSecret( |
| 108 | accountIdentifier: string, |
| 109 | sitekey: string, |
| 110 | body: WidgetRotateSecretParams, |
| 111 | options?: Core.RequestOptions, |
| 112 | ): Core.APIPromise<WidgetRotateSecretResponse> { |
| 113 | return ( |
| 114 | this._client.post(`/accounts/${accountIdentifier}/challenges/widgets/${sitekey}/rotate_secret`, { |
| 115 | body, |
| 116 | ...options, |
| 117 | }) as Core.APIPromise<{ result: WidgetRotateSecretResponse }> |
| 118 | )._thenUnwrap((obj) => obj.result); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * A Turnstile widget's detailed configuration |
| 124 | */ |
| 125 | export interface WidgetCreateResponse { |
| 126 | /** |
| 127 | * If bot_fight_mode is set to `true`, Cloudflare issues computationally expensive |
| 128 | * challenges in response to malicious bots (ENT only). |
| 129 | */ |
| 130 | bot_fight_mode: boolean; |
| 131 | |
| 132 | /** |
| 133 | * If Turnstile is embedded on a Cloudflare site and the widget should grant |
| 134 | * challenge clearance, this setting can determine the clearance level to be set |
| 135 | */ |
| 136 | clearance_level: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive'; |
| 137 | |
| 138 | /** |
| 139 | * When the widget was created. |
| 140 | */ |
| 141 | created_on: string; |
| 142 | |
| 143 | domains: Array<string>; |
| 144 | |
| 145 | /** |
| 146 | * Widget Mode |
| 147 | */ |
| 148 | mode: 'non-interactive' | 'invisible' | 'managed'; |
| 149 | |
| 150 | /** |
| 151 | * When the widget was modified. |
| 152 | */ |
| 153 | modified_on: string; |
| 154 | |
| 155 | /** |
| 156 | * Human readable widget name. Not unique. Cloudflare suggests that you set this to |
| 157 | * a meaningful string to make it easier to identify your widget, and where it is |
| 158 | * used. |
| 159 | */ |
| 160 | name: string; |
| 161 | |
| 162 | /** |
| 163 | * Do not show any Cloudflare branding on the widget (ENT only). |
| 164 | */ |
| 165 | offlabel: boolean; |
| 166 | |
| 167 | /** |
| 168 | * Region where this widget can be used. |
| 169 | */ |
| 170 | region: 'world'; |
| 171 | |
| 172 | /** |
| 173 | * Secret key for this widget. |
| 174 | */ |
| 175 | secret: string; |
| 176 | |
| 177 | /** |
| 178 | * Widget item identifier tag. |
| 179 | */ |
| 180 | sitekey: string; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * A Turnstile widget's detailed configuration |
| 185 | */ |
| 186 | export interface WidgetRetrieveResponse { |
| 187 | /** |
| 188 | * If bot_fight_mode is set to `true`, Cloudflare issues computationally expensive |
| 189 | * challenges in response to malicious bots (ENT only). |
| 190 | */ |
| 191 | bot_fight_mode: boolean; |
| 192 | |
| 193 | /** |
| 194 | * If Turnstile is embedded on a Cloudflare site and the widget should grant |
| 195 | * challenge clearance, this setting can determine the clearance level to be set |
| 196 | */ |
| 197 | clearance_level: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive'; |
| 198 | |
| 199 | /** |
| 200 | * When the widget was created. |
| 201 | */ |
| 202 | created_on: string; |
| 203 | |
| 204 | domains: Array<string>; |
| 205 | |
| 206 | /** |
| 207 | * Widget Mode |
| 208 | */ |
| 209 | mode: 'non-interactive' | 'invisible' | 'managed'; |
| 210 | |
| 211 | /** |
| 212 | * When the widget was modified. |
| 213 | */ |
| 214 | modified_on: string; |
| 215 | |
| 216 | /** |
| 217 | * Human readable widget name. Not unique. Cloudflare suggests that you set this to |
| 218 | * a meaningful string to make it easier to identify your widget, and where it is |
| 219 | * used. |
| 220 | */ |
| 221 | name: string; |
| 222 | |
| 223 | /** |
| 224 | * Do not show any Cloudflare branding on the widget (ENT only). |
| 225 | */ |
| 226 | offlabel: boolean; |
| 227 | |
| 228 | /** |
| 229 | * Region where this widget can be used. |
| 230 | */ |
| 231 | region: 'world'; |
| 232 | |
| 233 | /** |
| 234 | * Secret key for this widget. |
| 235 | */ |
| 236 | secret: string; |
| 237 | |
| 238 | /** |
| 239 | * Widget item identifier tag. |
| 240 | */ |
| 241 | sitekey: string; |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * A Turnstile widget's detailed configuration |
| 246 | */ |
| 247 | export interface WidgetUpdateResponse { |
| 248 | /** |
| 249 | * If bot_fight_mode is set to `true`, Cloudflare issues computationally expensive |
| 250 | * challenges in response to malicious bots (ENT only). |
| 251 | */ |
| 252 | bot_fight_mode: boolean; |
| 253 | |
| 254 | /** |
| 255 | * If Turnstile is embedded on a Cloudflare site and the widget should grant |
| 256 | * challenge clearance, this setting can determine the clearance level to be set |
| 257 | */ |
| 258 | clearance_level: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive'; |
| 259 | |
| 260 | /** |
| 261 | * When the widget was created. |
| 262 | */ |
| 263 | created_on: string; |
| 264 | |
| 265 | domains: Array<string>; |
| 266 | |
| 267 | /** |
| 268 | * Widget Mode |
| 269 | */ |
| 270 | mode: 'non-interactive' | 'invisible' | 'managed'; |
| 271 | |
| 272 | /** |
| 273 | * When the widget was modified. |
| 274 | */ |
| 275 | modified_on: string; |
| 276 | |
| 277 | /** |
| 278 | * Human readable widget name. Not unique. Cloudflare suggests that you set this to |
| 279 | * a meaningful string to make it easier to identify your widget, and where it is |
| 280 | * used. |
| 281 | */ |
| 282 | name: string; |
| 283 | |
| 284 | /** |
| 285 | * Do not show any Cloudflare branding on the widget (ENT only). |
| 286 | */ |
| 287 | offlabel: boolean; |
| 288 | |
| 289 | /** |
| 290 | * Region where this widget can be used. |
| 291 | */ |
| 292 | region: 'world'; |
| 293 | |
| 294 | /** |
| 295 | * Secret key for this widget. |
| 296 | */ |
| 297 | secret: string; |
| 298 | |
| 299 | /** |
| 300 | * Widget item identifier tag. |
| 301 | */ |
| 302 | sitekey: string; |
| 303 | } |
| 304 | |
| 305 | export type WidgetListResponse = Array<WidgetListResponse.WidgetListResponseItem>; |
| 306 | |
| 307 | export namespace WidgetListResponse { |
| 308 | /** |
| 309 | * A Turnstile Widgets configuration as it appears in listings |
| 310 | */ |
| 311 | export interface WidgetListResponseItem { |
| 312 | /** |
| 313 | * If bot_fight_mode is set to `true`, Cloudflare issues computationally expensive |
| 314 | * challenges in response to malicious bots (ENT only). |
| 315 | */ |
| 316 | bot_fight_mode: boolean; |
| 317 | |
| 318 | /** |
| 319 | * If Turnstile is embedded on a Cloudflare site and the widget should grant |
| 320 | * challenge clearance, this setting can determine the clearance level to be set |
| 321 | */ |
| 322 | clearance_level: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive'; |
| 323 | |
| 324 | /** |
| 325 | * When the widget was created. |
| 326 | */ |
| 327 | created_on: string; |
| 328 | |
| 329 | domains: Array<string>; |
| 330 | |
| 331 | /** |
| 332 | * Widget Mode |
| 333 | */ |
| 334 | mode: 'non-interactive' | 'invisible' | 'managed'; |
| 335 | |
| 336 | /** |
| 337 | * When the widget was modified. |
| 338 | */ |
| 339 | modified_on: string; |
| 340 | |
| 341 | /** |
| 342 | * Human readable widget name. Not unique. Cloudflare suggests that you set this to |
| 343 | * a meaningful string to make it easier to identify your widget, and where it is |
| 344 | * used. |
| 345 | */ |
| 346 | name: string; |
| 347 | |
| 348 | /** |
| 349 | * Do not show any Cloudflare branding on the widget (ENT only). |
| 350 | */ |
| 351 | offlabel: boolean; |
| 352 | |
| 353 | /** |
| 354 | * Region where this widget can be used. |
| 355 | */ |
| 356 | region: 'world'; |
| 357 | |
| 358 | /** |
| 359 | * Widget item identifier tag. |
| 360 | */ |
| 361 | sitekey: string; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * A Turnstile widget's detailed configuration |
| 367 | */ |
| 368 | export interface WidgetDeleteResponse { |
| 369 | /** |
| 370 | * If bot_fight_mode is set to `true`, Cloudflare issues computationally expensive |
| 371 | * challenges in response to malicious bots (ENT only). |
| 372 | */ |
| 373 | bot_fight_mode: boolean; |
| 374 | |
| 375 | /** |
| 376 | * If Turnstile is embedded on a Cloudflare site and the widget should grant |
| 377 | * challenge clearance, this setting can determine the clearance level to be set |
| 378 | */ |
| 379 | clearance_level: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive'; |
| 380 | |
| 381 | /** |
| 382 | * When the widget was created. |
| 383 | */ |
| 384 | created_on: string; |
| 385 | |
| 386 | domains: Array<string>; |
| 387 | |
| 388 | /** |
| 389 | * Widget Mode |
| 390 | */ |
| 391 | mode: 'non-interactive' | 'invisible' | 'managed'; |
| 392 | |
| 393 | /** |
| 394 | * When the widget was modified. |
| 395 | */ |
| 396 | modified_on: string; |
| 397 | |
| 398 | /** |
| 399 | * Human readable widget name. Not unique. Cloudflare suggests that you set this to |
| 400 | * a meaningful string to make it easier to identify your widget, and where it is |
| 401 | * used. |
| 402 | */ |
| 403 | name: string; |
| 404 | |
| 405 | /** |
| 406 | * Do not show any Cloudflare branding on the widget (ENT only). |
| 407 | */ |
| 408 | offlabel: boolean; |
| 409 | |
| 410 | /** |
| 411 | * Region where this widget can be used. |
| 412 | */ |
| 413 | region: 'world'; |
| 414 | |
| 415 | /** |
| 416 | * Secret key for this widget. |
| 417 | */ |
| 418 | secret: string; |
| 419 | |
| 420 | /** |
| 421 | * Widget item identifier tag. |
| 422 | */ |
| 423 | sitekey: string; |
| 424 | } |
| 425 | |
| 426 | /** |
| 427 | * A Turnstile widget's detailed configuration |
| 428 | */ |
| 429 | export interface WidgetRotateSecretResponse { |
| 430 | /** |
| 431 | * If bot_fight_mode is set to `true`, Cloudflare issues computationally expensive |
| 432 | * challenges in response to malicious bots (ENT only). |
| 433 | */ |
| 434 | bot_fight_mode: boolean; |
| 435 | |
| 436 | /** |
| 437 | * If Turnstile is embedded on a Cloudflare site and the widget should grant |
| 438 | * challenge clearance, this setting can determine the clearance level to be set |
| 439 | */ |
| 440 | clearance_level: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive'; |
| 441 | |
| 442 | /** |
| 443 | * When the widget was created. |
| 444 | */ |
| 445 | created_on: string; |
| 446 | |
| 447 | domains: Array<string>; |
| 448 | |
| 449 | /** |
| 450 | * Widget Mode |
| 451 | */ |
| 452 | mode: 'non-interactive' | 'invisible' | 'managed'; |
| 453 | |
| 454 | /** |
| 455 | * When the widget was modified. |
| 456 | */ |
| 457 | modified_on: string; |
| 458 | |
| 459 | /** |
| 460 | * Human readable widget name. Not unique. Cloudflare suggests that you set this to |
| 461 | * a meaningful string to make it easier to identify your widget, and where it is |
| 462 | * used. |
| 463 | */ |
| 464 | name: string; |
| 465 | |
| 466 | /** |
| 467 | * Do not show any Cloudflare branding on the widget (ENT only). |
| 468 | */ |
| 469 | offlabel: boolean; |
| 470 | |
| 471 | /** |
| 472 | * Region where this widget can be used. |
| 473 | */ |
| 474 | region: 'world'; |
| 475 | |
| 476 | /** |
| 477 | * Secret key for this widget. |
| 478 | */ |
| 479 | secret: string; |
| 480 | |
| 481 | /** |
| 482 | * Widget item identifier tag. |
| 483 | */ |
| 484 | sitekey: string; |
| 485 | } |
| 486 | |
| 487 | export interface WidgetCreateParams { |
| 488 | /** |
| 489 | * Body param: |
| 490 | */ |
| 491 | domains: Array<string>; |
| 492 | |
| 493 | /** |
| 494 | * Body param: Widget Mode |
| 495 | */ |
| 496 | mode: 'non-interactive' | 'invisible' | 'managed'; |
| 497 | |
| 498 | /** |
| 499 | * Body param: Human readable widget name. Not unique. Cloudflare suggests that you |
| 500 | * set this to a meaningful string to make it easier to identify your widget, and |
| 501 | * where it is used. |
| 502 | */ |
| 503 | name: string; |
| 504 | |
| 505 | /** |
| 506 | * Query param: Direction to order widgets. |
| 507 | */ |
| 508 | direction?: 'asc' | 'desc'; |
| 509 | |
| 510 | /** |
| 511 | * Query param: Field to order widgets by. |
| 512 | */ |
| 513 | order?: 'id' | 'sitekey' | 'name' | 'created_on' | 'modified_on'; |
| 514 | |
| 515 | /** |
| 516 | * Query param: Page number of paginated results. |
| 517 | */ |
| 518 | page?: number; |
| 519 | |
| 520 | /** |
| 521 | * Query param: Number of items per page. |
| 522 | */ |
| 523 | per_page?: number; |
| 524 | |
| 525 | /** |
| 526 | * Body param: If bot_fight_mode is set to `true`, Cloudflare issues |
| 527 | * computationally expensive challenges in response to malicious bots (ENT only). |
| 528 | */ |
| 529 | bot_fight_mode?: boolean; |
| 530 | |
| 531 | /** |
| 532 | * Body param: If Turnstile is embedded on a Cloudflare site and the widget should |
| 533 | * grant challenge clearance, this setting can determine the clearance level to be |
| 534 | * set |
| 535 | */ |
| 536 | clearance_level?: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive'; |
| 537 | |
| 538 | /** |
| 539 | * Body param: Do not show any Cloudflare branding on the widget (ENT only). |
| 540 | */ |
| 541 | offlabel?: boolean; |
| 542 | |
| 543 | /** |
| 544 | * Body param: Region where this widget can be used. |
| 545 | */ |
| 546 | region?: 'world'; |
| 547 | } |
| 548 | |
| 549 | export interface WidgetUpdateParams { |
| 550 | domains: Array<string>; |
| 551 | |
| 552 | /** |
| 553 | * Widget Mode |
| 554 | */ |
| 555 | mode: 'non-interactive' | 'invisible' | 'managed'; |
| 556 | |
| 557 | /** |
| 558 | * Human readable widget name. Not unique. Cloudflare suggests that you set this to |
| 559 | * a meaningful string to make it easier to identify your widget, and where it is |
| 560 | * used. |
| 561 | */ |
| 562 | name: string; |
| 563 | |
| 564 | /** |
| 565 | * If bot_fight_mode is set to `true`, Cloudflare issues computationally expensive |
| 566 | * challenges in response to malicious bots (ENT only). |
| 567 | */ |
| 568 | bot_fight_mode?: boolean; |
| 569 | |
| 570 | /** |
| 571 | * If Turnstile is embedded on a Cloudflare site and the widget should grant |
| 572 | * challenge clearance, this setting can determine the clearance level to be set |
| 573 | */ |
| 574 | clearance_level?: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive'; |
| 575 | |
| 576 | /** |
| 577 | * Do not show any Cloudflare branding on the widget (ENT only). |
| 578 | */ |
| 579 | offlabel?: boolean; |
| 580 | } |
| 581 | |
| 582 | export interface WidgetListParams { |
| 583 | /** |
| 584 | * Direction to order widgets. |
| 585 | */ |
| 586 | direction?: 'asc' | 'desc'; |
| 587 | |
| 588 | /** |
| 589 | * Field to order widgets by. |
| 590 | */ |
| 591 | order?: 'id' | 'sitekey' | 'name' | 'created_on' | 'modified_on'; |
| 592 | |
| 593 | /** |
| 594 | * Page number of paginated results. |
| 595 | */ |
| 596 | page?: number; |
| 597 | |
| 598 | /** |
| 599 | * Number of items per page. |
| 600 | */ |
| 601 | per_page?: number; |
| 602 | } |
| 603 | |
| 604 | export interface WidgetRotateSecretParams { |
| 605 | /** |
| 606 | * If `invalidate_immediately` is set to `false`, the previous secret will remain |
| 607 | * valid for two hours. Otherwise, the secret is immediately invalidated, and |
| 608 | * requests using it will be rejected. |
| 609 | */ |
| 610 | invalidate_immediately?: boolean; |
| 611 | } |
| 612 | |
| 613 | export namespace Widgets { |
| 614 | export import WidgetCreateResponse = WidgetsAPI.WidgetCreateResponse; |
| 615 | export import WidgetRetrieveResponse = WidgetsAPI.WidgetRetrieveResponse; |
| 616 | export import WidgetUpdateResponse = WidgetsAPI.WidgetUpdateResponse; |
| 617 | export import WidgetListResponse = WidgetsAPI.WidgetListResponse; |
| 618 | export import WidgetDeleteResponse = WidgetsAPI.WidgetDeleteResponse; |
| 619 | export import WidgetRotateSecretResponse = WidgetsAPI.WidgetRotateSecretResponse; |
| 620 | export import WidgetCreateParams = WidgetsAPI.WidgetCreateParams; |
| 621 | export import WidgetUpdateParams = WidgetsAPI.WidgetUpdateParams; |
| 622 | export import WidgetListParams = WidgetsAPI.WidgetListParams; |
| 623 | export import WidgetRotateSecretParams = WidgetsAPI.WidgetRotateSecretParams; |
| 624 | } |
| 625 | |