UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

111 lines • 4.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Tokens = exports.BaseTokens = void 0; // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. const resource_1 = require("../../core/resource.js"); const pagination_1 = require("../../core/pagination.js"); const path_1 = require("../../internal/utils/path.js"); var BaseTokens = /* @__PURE__ */ (() => { class BaseTokens extends resource_1.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((0, path_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/ai-search/tokens`, (pagination_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/ai-search/tokens/${id}`, options)._thenUnwrap((obj) => obj.result); } } BaseTokens._key = Object.freeze([ 'aiSearch', 'tokens', ]); return BaseTokens; })(); exports.BaseTokens = BaseTokens; class Tokens extends BaseTokens { } exports.Tokens = Tokens; //# sourceMappingURL=tokens.js.map