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