cloudflare
Version:
The official TypeScript library for the Cloudflare API
136 lines • 4.98 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../core/resource.mjs";
import { V4PagePaginationArray } from "../../core/pagination.mjs";
import { path } from "../../internal/utils/path.mjs";
export var BaseWidgets = /* @__PURE__ */ (() => {
class BaseWidgets extends APIResource {
/**
* Creates a Turnstile widget for an account.
*
* @example
* ```ts
* const widget = await client.turnstile.widgets.create({
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* domains: [
* '203.0.113.1',
* 'cloudflare.com',
* 'blog.example.com',
* ],
* mode: 'invisible',
* name: 'blog.cloudflare.com login form',
* });
* ```
*/
create(params, options) {
const { account_id, direction, filter, order, page, per_page, ...body } = params;
return this._client.post(path `/accounts/${account_id}/challenges/widgets`, {
query: { direction, filter, order, page, per_page },
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Updates the configuration of a Turnstile widget.
*
* @example
* ```ts
* const widget = await client.turnstile.widgets.update(
* '0x4AAF00AAAABn0R22HWm-YUc',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* domains: [
* '203.0.113.1',
* 'cloudflare.com',
* 'blog.example.com',
* ],
* mode: 'invisible',
* name: 'blog.cloudflare.com login form',
* },
* );
* ```
*/
update(sitekey, params, options) {
const { account_id, ...body } = params;
return this._client.put(path `/accounts/${account_id}/challenges/widgets/${sitekey}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Lists Turnstile widgets for an account.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const widgetListResponse of client.turnstile.widgets.list(
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* )) {
* // ...
* }
* ```
*/
list(params, options) {
const { account_id, ...query } = params;
return this._client.getAPIList(path `/accounts/${account_id}/challenges/widgets`, (V4PagePaginationArray), { query, ...options });
}
/**
* Deletes a Turnstile widget from an account.
*
* @example
* ```ts
* const widget = await client.turnstile.widgets.delete(
* '0x4AAF00AAAABn0R22HWm-YUc',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
delete(sitekey, params, options) {
const { account_id } = params;
return this._client.delete(path `/accounts/${account_id}/challenges/widgets/${sitekey}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Returns the configuration of a Turnstile widget.
*
* @example
* ```ts
* const widget = await client.turnstile.widgets.get(
* '0x4AAF00AAAABn0R22HWm-YUc',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
get(sitekey, params, options) {
const { account_id } = params;
return this._client.get(path `/accounts/${account_id}/challenges/widgets/${sitekey}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Generates a new secret key for this widget. If `invalidate_immediately` is set
* to `false`, the previous secret remains valid for 2 hours.
*
* Note that secrets cannot be rotated again during the grace period.
*
* @example
* ```ts
* const widget = await client.turnstile.widgets.rotateSecret(
* '0x4AAF00AAAABn0R22HWm-YUc',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
rotateSecret(sitekey, params, options) {
const { account_id, ...body } = params;
return this._client.post(path `/accounts/${account_id}/challenges/widgets/${sitekey}/rotate_secret`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
}
BaseWidgets._key = Object.freeze([
'turnstile',
'widgets',
]);
return BaseWidgets;
})();
export class Widgets extends BaseWidgets {
}
//# sourceMappingURL=widgets.mjs.map