cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dee3057bf3dcc911bd6a16ad12f5c079ef887bcc

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/challenges/widgets.ts

395lines · 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 * A Turnstile Widgets configuration as it appears in listings
176 */
177export interface WidgetListResponse {
178 /**
179 * If bot_fight_mode is set to `true`, Cloudflare issues computationally expensive
180 * challenges in response to malicious bots (ENT only).
181 */
182 bot_fight_mode: boolean;
183
184 /**
185 * If Turnstile is embedded on a Cloudflare site and the widget should grant
186 * challenge clearance, this setting can determine the clearance level to be set
187 */
188 clearance_level: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive';
189
190 /**
191 * When the widget was created.
192 */
193 created_on: string;
194
195 domains: Array<WidgetDomain>;
196
197 /**
198 * Widget Mode
199 */
200 mode: 'non-interactive' | 'invisible' | 'managed';
201
202 /**
203 * When the widget was modified.
204 */
205 modified_on: string;
206
207 /**
208 * Human readable widget name. Not unique. Cloudflare suggests that you set this to
209 * a meaningful string to make it easier to identify your widget, and where it is
210 * used.
211 */
212 name: string;
213
214 /**
215 * Do not show any Cloudflare branding on the widget (ENT only).
216 */
217 offlabel: boolean;
218
219 /**
220 * Region where this widget can be used.
221 */
222 region: 'world';
223
224 /**
225 * Widget item identifier tag.
226 */
227 sitekey: string;
228}
229
230export interface WidgetCreateParams {
231 /**
232 * Path param: Identifier
233 */
234 account_id: string;
235
236 /**
237 * Body param:
238 */
239 domains: Array<WidgetDomain>;
240
241 /**
242 * Body param: Widget Mode
243 */
244 mode: 'non-interactive' | 'invisible' | 'managed';
245
246 /**
247 * Body param: Human readable widget name. Not unique. Cloudflare suggests that you
248 * set this to a meaningful string to make it easier to identify your widget, and
249 * where it is used.
250 */
251 name: string;
252
253 /**
254 * Query param: Direction to order widgets.
255 */
256 direction?: 'asc' | 'desc';
257
258 /**
259 * Query param: Field to order widgets by.
260 */
261 order?: 'id' | 'sitekey' | 'name' | 'created_on' | 'modified_on';
262
263 /**
264 * Query param: Page number of paginated results.
265 */
266 page?: number;
267
268 /**
269 * Query param: Number of items per page.
270 */
271 per_page?: number;
272
273 /**
274 * Body param: If bot_fight_mode is set to `true`, Cloudflare issues
275 * computationally expensive challenges in response to malicious bots (ENT only).
276 */
277 bot_fight_mode?: boolean;
278
279 /**
280 * Body param: If Turnstile is embedded on a Cloudflare site and the widget should
281 * grant challenge clearance, this setting can determine the clearance level to be
282 * set
283 */
284 clearance_level?: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive';
285
286 /**
287 * Body param: Do not show any Cloudflare branding on the widget (ENT only).
288 */
289 offlabel?: boolean;
290
291 /**
292 * Body param: Region where this widget can be used.
293 */
294 region?: 'world';
295}
296
297export interface WidgetUpdateParams {
298 /**
299 * Path param: Identifier
300 */
301 account_id: string;
302
303 /**
304 * Body param:
305 */
306 domains: Array<WidgetDomain>;
307
308 /**
309 * Body param: Widget Mode
310 */
311 mode: 'non-interactive' | 'invisible' | 'managed';
312
313 /**
314 * Body param: Human readable widget name. Not unique. Cloudflare suggests that you
315 * set this to a meaningful string to make it easier to identify your widget, and
316 * where it is used.
317 */
318 name: string;
319
320 /**
321 * Body param: If bot_fight_mode is set to `true`, Cloudflare issues
322 * computationally expensive challenges in response to malicious bots (ENT only).
323 */
324 bot_fight_mode?: boolean;
325
326 /**
327 * Body param: If Turnstile is embedded on a Cloudflare site and the widget should
328 * grant challenge clearance, this setting can determine the clearance level to be
329 * set
330 */
331 clearance_level?: 'no_clearance' | 'jschallenge' | 'managed' | 'interactive';
332
333 /**
334 * Body param: Do not show any Cloudflare branding on the widget (ENT only).
335 */
336 offlabel?: boolean;
337}
338
339export interface WidgetListParams extends V4PagePaginationArrayParams {
340 /**
341 * Path param: Identifier
342 */
343 account_id: string;
344
345 /**
346 * Query param: Direction to order widgets.
347 */
348 direction?: 'asc' | 'desc';
349
350 /**
351 * Query param: Field to order widgets by.
352 */
353 order?: 'id' | 'sitekey' | 'name' | 'created_on' | 'modified_on';
354}
355
356export interface WidgetDeleteParams {
357 /**
358 * Identifier
359 */
360 account_id: string;
361}
362
363export interface WidgetGetParams {
364 /**
365 * Identifier
366 */
367 account_id: string;
368}
369
370export interface WidgetRotateSecretParams {
371 /**
372 * Path param: Identifier
373 */
374 account_id: string;
375
376 /**
377 * Body param: If `invalidate_immediately` is set to `false`, the previous secret
378 * will remain valid for two hours. Otherwise, the secret is immediately
379 * invalidated, and requests using it will be rejected.
380 */
381 invalidate_immediately?: boolean;
382}
383
384export namespace Widgets {
385 export import Widget = WidgetsAPI.Widget;
386 export import WidgetDomain = WidgetsAPI.WidgetDomain;
387 export import WidgetListResponse = WidgetsAPI.WidgetListResponse;
388 export import WidgetListResponsesV4PagePaginationArray = WidgetsAPI.WidgetListResponsesV4PagePaginationArray;
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