cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/challenges/widgets.ts
392lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import * as Core from 'cloudflare/core'; |
| 4 | import { APIResource } from 'cloudflare/resource'; |
| 5 | import * as WidgetsAPI from 'cloudflare/resources/challenges/widgets'; |
| 6 | import { V4PagePaginationArray, type V4PagePaginationArrayParams } from 'cloudflare/pagination'; |
| 7 | |
| 8 | export class Widgets extends APIResource { |
| 9 | /** |
| 10 | * Lists challenge widgets. |
| 11 | */ |
| 12 | create(params: WidgetCreateParams, options?: Core.RequestOptions): Core.APIPromise<ChallengesWidget> { |
| 13 | const { account_id, direction, order, page, per_page, ...body } = params; |
| 14 | return ( |
| 15 | this._client.post(`/accounts/${account_id}/challenges/widgets`, { |
| 16 | query: { direction, order, page, per_page }, |
| 17 | body, |
| 18 | ...options, |
| 19 | }) as Core.APIPromise<{ result: ChallengesWidget }> |
| 20 | )._thenUnwrap((obj) => obj.result); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Update the configuration of a widget. |
| 25 | */ |
| 26 | update( |
| 27 | sitekey: string, |
| 28 | params: WidgetUpdateParams, |
| 29 | options?: Core.RequestOptions, |
| 30 | ): Core.APIPromise<ChallengesWidget> { |
| 31 | const { account_id, ...body } = params; |
| 32 | return ( |
| 33 | this._client.put(`/accounts/${account_id}/challenges/widgets/${sitekey}`, { |
| 34 | body, |
| 35 | ...options, |
| 36 | }) as Core.APIPromise<{ result: ChallengesWidget }> |
| 37 | )._thenUnwrap((obj) => obj.result); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Lists all turnstile widgets of an account. |
| 42 | */ |
| 43 | list( |
| 44 | params: WidgetListParams, |
| 45 | options?: Core.RequestOptions, |
| 46 | ): Core.PagePromise<ChallengesWidgetListsV4PagePaginationArray, ChallengesWidgetList> { |
| 47 | const { account_id, ...query } = params; |
| 48 | return this._client.getAPIList( |
| 49 | `/accounts/${account_id}/challenges/widgets`, |
| 50 | ChallengesWidgetListsV4PagePaginationArray, |
| 51 | { query, ...options }, |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Destroy a Turnstile Widget. |
| 57 | */ |
| 58 | delete( |
| 59 | sitekey: string, |
| 60 | params: WidgetDeleteParams, |
| 61 | options?: Core.RequestOptions, |
| 62 | ): Core.APIPromise<ChallengesWidget> { |
| 63 | const { account_id } = params; |
| 64 | return ( |
| 65 | this._client.delete( |
| 66 | `/accounts/${account_id}/challenges/widgets/${sitekey}`, |
| 67 | options, |
| 68 | ) as Core.APIPromise<{ result: ChallengesWidget }> |
| 69 | )._thenUnwrap((obj) => obj.result); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Show a single challenge widget configuration. |
| 74 | */ |
| 75 | get( |
| 76 | sitekey: string, |
| 77 | params: WidgetGetParams, |
| 78 | options?: Core.RequestOptions, |
| 79 | ): Core.APIPromise<ChallengesWidget> { |
| 80 | const { account_id } = params; |
| 81 | return ( |
| 82 | this._client.get(`/accounts/${account_id}/challenges/widgets/${sitekey}`, options) as Core.APIPromise<{ |
| 83 | result: ChallengesWidget; |
| 84 | }> |
| 85 | )._thenUnwrap((obj) => obj.result); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Generate a new secret key for this widget. If `invalidate_immediately` is set to |
| 90 | * `false`, the previous secret remains valid for 2 hours. |
| 91 | * |
| 92 | * Note that secrets cannot be rotated again during the grace period. |
| 93 | */ |
| 94 | rotateSecret( |
| 95 | sitekey: string, |
| 96 | params: WidgetRotateSecretParams, |
| 97 | options?: Core.RequestOptions, |
| 98 | ): Core.APIPromise<ChallengesWidget> { |
| 99 | const { account_id, ...body } = params; |
| 100 | return ( |
| 101 | this._client.post(`/accounts/${account_id}/challenges/widgets/${sitekey}/rotate_secret`, { |
| 102 | body, |
| 103 | ...options, |
| 104 | }) as Core.APIPromise<{ result: ChallengesWidget }> |
| 105 | )._thenUnwrap((obj) => obj.result); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | export class ChallengesWidgetListsV4PagePaginationArray extends V4PagePaginationArray<ChallengesWidgetList> {} |
| 110 | |
| 111 | /** |
| 112 | * A Turnstile widget's detailed configuration |
| 113 | */ |
| 114 | export interface ChallengesWidget { |
| 115 | /** |
| 116 | * If bot_fight_mode is set to `true`, Cloudflare issues computationally expensive |
| 117 | * challenges in response to malicious bots (ENT only). |
| 118 | */ |
| 119 | bot_fight_mode: boolean; |
| 120 | |
| 121 | /** |
| 122 | * If Turnstile is embedded on a Cloudflare site and the widget should grant |
| 123 | * challenge clearance, this setting can determine the clearance level to be set |
| 124 | */ |
| 125 | clearance_level: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive'; |
| 126 | |
| 127 | /** |
| 128 | * When the widget was created. |
| 129 | */ |
| 130 | created_on: string; |
| 131 | |
| 132 | domains: Array<string>; |
| 133 | |
| 134 | /** |
| 135 | * Widget Mode |
| 136 | */ |
| 137 | mode: 'non-interactive' | 'invisible' | 'managed'; |
| 138 | |
| 139 | /** |
| 140 | * When the widget was modified. |
| 141 | */ |
| 142 | modified_on: string; |
| 143 | |
| 144 | /** |
| 145 | * Human readable widget name. Not unique. Cloudflare suggests that you set this to |
| 146 | * a meaningful string to make it easier to identify your widget, and where it is |
| 147 | * used. |
| 148 | */ |
| 149 | name: string; |
| 150 | |
| 151 | /** |
| 152 | * Do not show any Cloudflare branding on the widget (ENT only). |
| 153 | */ |
| 154 | offlabel: boolean; |
| 155 | |
| 156 | /** |
| 157 | * Region where this widget can be used. |
| 158 | */ |
| 159 | region: 'world'; |
| 160 | |
| 161 | /** |
| 162 | * Secret key for this widget. |
| 163 | */ |
| 164 | secret: string; |
| 165 | |
| 166 | /** |
| 167 | * Widget item identifier tag. |
| 168 | */ |
| 169 | sitekey: string; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * A Turnstile Widgets configuration as it appears in listings |
| 174 | */ |
| 175 | export interface ChallengesWidgetList { |
| 176 | /** |
| 177 | * If bot_fight_mode is set to `true`, Cloudflare issues computationally expensive |
| 178 | * challenges in response to malicious bots (ENT only). |
| 179 | */ |
| 180 | bot_fight_mode: boolean; |
| 181 | |
| 182 | /** |
| 183 | * If Turnstile is embedded on a Cloudflare site and the widget should grant |
| 184 | * challenge clearance, this setting can determine the clearance level to be set |
| 185 | */ |
| 186 | clearance_level: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive'; |
| 187 | |
| 188 | /** |
| 189 | * When the widget was created. |
| 190 | */ |
| 191 | created_on: string; |
| 192 | |
| 193 | domains: Array<string>; |
| 194 | |
| 195 | /** |
| 196 | * Widget Mode |
| 197 | */ |
| 198 | mode: 'non-interactive' | 'invisible' | 'managed'; |
| 199 | |
| 200 | /** |
| 201 | * When the widget was modified. |
| 202 | */ |
| 203 | modified_on: string; |
| 204 | |
| 205 | /** |
| 206 | * Human readable widget name. Not unique. Cloudflare suggests that you set this to |
| 207 | * a meaningful string to make it easier to identify your widget, and where it is |
| 208 | * used. |
| 209 | */ |
| 210 | name: string; |
| 211 | |
| 212 | /** |
| 213 | * Do not show any Cloudflare branding on the widget (ENT only). |
| 214 | */ |
| 215 | offlabel: boolean; |
| 216 | |
| 217 | /** |
| 218 | * Region where this widget can be used. |
| 219 | */ |
| 220 | region: 'world'; |
| 221 | |
| 222 | /** |
| 223 | * Widget item identifier tag. |
| 224 | */ |
| 225 | sitekey: string; |
| 226 | } |
| 227 | |
| 228 | export interface WidgetCreateParams { |
| 229 | /** |
| 230 | * Path param: Identifier |
| 231 | */ |
| 232 | account_id: string; |
| 233 | |
| 234 | /** |
| 235 | * Body param: |
| 236 | */ |
| 237 | domains: Array<string>; |
| 238 | |
| 239 | /** |
| 240 | * Body param: Widget Mode |
| 241 | */ |
| 242 | mode: 'non-interactive' | 'invisible' | 'managed'; |
| 243 | |
| 244 | /** |
| 245 | * Body param: Human readable widget name. Not unique. Cloudflare suggests that you |
| 246 | * set this to a meaningful string to make it easier to identify your widget, and |
| 247 | * where it is used. |
| 248 | */ |
| 249 | name: string; |
| 250 | |
| 251 | /** |
| 252 | * Query param: Direction to order widgets. |
| 253 | */ |
| 254 | direction?: 'asc' | 'desc'; |
| 255 | |
| 256 | /** |
| 257 | * Query param: Field to order widgets by. |
| 258 | */ |
| 259 | order?: 'id' | 'sitekey' | 'name' | 'created_on' | 'modified_on'; |
| 260 | |
| 261 | /** |
| 262 | * Query param: Page number of paginated results. |
| 263 | */ |
| 264 | page?: number; |
| 265 | |
| 266 | /** |
| 267 | * Query param: Number of items per page. |
| 268 | */ |
| 269 | per_page?: number; |
| 270 | |
| 271 | /** |
| 272 | * Body param: If bot_fight_mode is set to `true`, Cloudflare issues |
| 273 | * computationally expensive challenges in response to malicious bots (ENT only). |
| 274 | */ |
| 275 | bot_fight_mode?: boolean; |
| 276 | |
| 277 | /** |
| 278 | * Body param: If Turnstile is embedded on a Cloudflare site and the widget should |
| 279 | * grant challenge clearance, this setting can determine the clearance level to be |
| 280 | * set |
| 281 | */ |
| 282 | clearance_level?: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive'; |
| 283 | |
| 284 | /** |
| 285 | * Body param: Do not show any Cloudflare branding on the widget (ENT only). |
| 286 | */ |
| 287 | offlabel?: boolean; |
| 288 | |
| 289 | /** |
| 290 | * Body param: Region where this widget can be used. |
| 291 | */ |
| 292 | region?: 'world'; |
| 293 | } |
| 294 | |
| 295 | export interface WidgetUpdateParams { |
| 296 | /** |
| 297 | * Path param: Identifier |
| 298 | */ |
| 299 | account_id: string; |
| 300 | |
| 301 | /** |
| 302 | * Body param: |
| 303 | */ |
| 304 | domains: Array<string>; |
| 305 | |
| 306 | /** |
| 307 | * Body param: Widget Mode |
| 308 | */ |
| 309 | mode: 'non-interactive' | 'invisible' | 'managed'; |
| 310 | |
| 311 | /** |
| 312 | * Body param: Human readable widget name. Not unique. Cloudflare suggests that you |
| 313 | * set this to a meaningful string to make it easier to identify your widget, and |
| 314 | * where it is used. |
| 315 | */ |
| 316 | name: string; |
| 317 | |
| 318 | /** |
| 319 | * Body param: If bot_fight_mode is set to `true`, Cloudflare issues |
| 320 | * computationally expensive challenges in response to malicious bots (ENT only). |
| 321 | */ |
| 322 | bot_fight_mode?: boolean; |
| 323 | |
| 324 | /** |
| 325 | * Body param: If Turnstile is embedded on a Cloudflare site and the widget should |
| 326 | * grant challenge clearance, this setting can determine the clearance level to be |
| 327 | * set |
| 328 | */ |
| 329 | clearance_level?: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive'; |
| 330 | |
| 331 | /** |
| 332 | * Body param: Do not show any Cloudflare branding on the widget (ENT only). |
| 333 | */ |
| 334 | offlabel?: boolean; |
| 335 | } |
| 336 | |
| 337 | export interface WidgetListParams extends V4PagePaginationArrayParams { |
| 338 | /** |
| 339 | * Path param: Identifier |
| 340 | */ |
| 341 | account_id: string; |
| 342 | |
| 343 | /** |
| 344 | * Query param: Direction to order widgets. |
| 345 | */ |
| 346 | direction?: 'asc' | 'desc'; |
| 347 | |
| 348 | /** |
| 349 | * Query param: Field to order widgets by. |
| 350 | */ |
| 351 | order?: 'id' | 'sitekey' | 'name' | 'created_on' | 'modified_on'; |
| 352 | } |
| 353 | |
| 354 | export interface WidgetDeleteParams { |
| 355 | /** |
| 356 | * Identifier |
| 357 | */ |
| 358 | account_id: string; |
| 359 | } |
| 360 | |
| 361 | export interface WidgetGetParams { |
| 362 | /** |
| 363 | * Identifier |
| 364 | */ |
| 365 | account_id: string; |
| 366 | } |
| 367 | |
| 368 | export interface WidgetRotateSecretParams { |
| 369 | /** |
| 370 | * Path param: Identifier |
| 371 | */ |
| 372 | account_id: string; |
| 373 | |
| 374 | /** |
| 375 | * Body param: If `invalidate_immediately` is set to `false`, the previous secret |
| 376 | * will remain valid for two hours. Otherwise, the secret is immediately |
| 377 | * invalidated, and requests using it will be rejected. |
| 378 | */ |
| 379 | invalidate_immediately?: boolean; |
| 380 | } |
| 381 | |
| 382 | export namespace Widgets { |
| 383 | export import ChallengesWidget = WidgetsAPI.ChallengesWidget; |
| 384 | export import ChallengesWidgetList = WidgetsAPI.ChallengesWidgetList; |
| 385 | export import ChallengesWidgetListsV4PagePaginationArray = WidgetsAPI.ChallengesWidgetListsV4PagePaginationArray; |
| 386 | export import WidgetCreateParams = WidgetsAPI.WidgetCreateParams; |
| 387 | export import WidgetUpdateParams = WidgetsAPI.WidgetUpdateParams; |
| 388 | export import WidgetListParams = WidgetsAPI.WidgetListParams; |
| 389 | export import WidgetDeleteParams = WidgetsAPI.WidgetDeleteParams; |
| 390 | export import WidgetGetParams = WidgetsAPI.WidgetGetParams; |
| 391 | export import WidgetRotateSecretParams = WidgetsAPI.WidgetRotateSecretParams; |
| 392 | } |