cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
fc0e3df7a7617630a04034afaebe2b244b14213c

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/challenges/widgets.ts

368lines · modecode

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