UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

106 lines • 3.95 kB
// 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 BaseTokens = /* @__PURE__ */ (() => { class BaseTokens extends APIResource { /** * Create a stored Cloudflare credential for an AI Search instance to access its * data source. * * @example * ```ts * const token = await client.aiSearch.tokens.create({ * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * cf_api_id: 'a1b2c3d4e5f6', * cf_api_key: 'abc123', * name: 'my-token', * }); * ``` */ create(params, options) { const { account_id, ...body } = params; return this._client.post(path `/accounts/${account_id}/ai-search/tokens`, { body, ...options })._thenUnwrap((obj) => obj.result); } /** * Replace a stored AI Search credential and invalidate cached credentials for * instances that use it. * * @example * ```ts * const token = await client.aiSearch.tokens.update( * '62af0db3-c410-40b2-9ee3-0e93f6dd1de0', * { * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', * cf_api_id: 'a1b2c3d4e5f6', * cf_api_key: 'abc123', * name: 'my-token', * }, * ); * ``` */ update(id, params, options) { const { account_id, ...body } = params; return this._client.put(path `/accounts/${account_id}/ai-search/tokens/${id}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * List stored AI Search credentials in the account without exposing their secrets. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const tokenListResponse of client.aiSearch.tokens.list( * { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' }, * )) { * // ... * } * ``` */ list(params, options) { const { account_id, ...query } = params; return this._client.getAPIList(path `/accounts/${account_id}/ai-search/tokens`, (V4PagePaginationArray), { query, ...options }); } /** * Permanently delete a stored AI Search credential. Credentials in use by an * instance cannot be deleted. * * @example * ```ts * const token = await client.aiSearch.tokens.delete( * '62af0db3-c410-40b2-9ee3-0e93f6dd1de0', * { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' }, * ); * ``` */ delete(id, params, options) { const { account_id } = params; return this._client.delete(path `/accounts/${account_id}/ai-search/tokens/${id}`, options)._thenUnwrap((obj) => obj.result); } /** * Retrieve a stored AI Search credential without exposing its secret. * * @example * ```ts * const response = await client.aiSearch.tokens.read( * '62af0db3-c410-40b2-9ee3-0e93f6dd1de0', * { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' }, * ); * ``` */ read(id, params, options) { const { account_id } = params; return this._client.get(path `/accounts/${account_id}/ai-search/tokens/${id}`, options)._thenUnwrap((obj) => obj.result); } } BaseTokens._key = Object.freeze([ 'aiSearch', 'tokens', ]); return BaseTokens; })(); export class Tokens extends BaseTokens { } //# sourceMappingURL=tokens.mjs.map