cloudflare/cloudflare-typescript

Public

mirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v3.2.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/resources/challenges/widgets.ts

401lines · modecode

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