cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v7

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/aisearch/tokens.ts

302lines · modecode

1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3import { APIResource } from '../../core/resource';
4import { APIPromise } from '../../core/api-promise';
5import { PagePromise, V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../core/pagination';
6import { RequestOptions } from '../../internal/request-options';
7import { path } from '../../internal/utils/path';
8
9export class BaseTokens extends APIResource {
10 static override readonly _key: readonly ['aiSearch', 'tokens'] = Object.freeze([
11 'aiSearch',
12 'tokens',
13 ] as const);
14
15 /**
16 * Create a new token.
17 *
18 * @example
19 * ```ts
20 * const token = await client.aiSearch.tokens.create({
21 * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
22 * cf_api_id: 'a1b2c3d4e5f6',
23 * cf_api_key: 'abc123',
24 * name: 'my-token',
25 * });
26 * ```
27 */
28 create(params: TokenCreateParams, options?: RequestOptions): APIPromise<TokenCreateResponse> {
29 const { account_id, ...body } = params;
30 return (
31 this._client.post(path`/accounts/${account_id}/ai-search/tokens`, { body, ...options }) as APIPromise<{
32 result: TokenCreateResponse;
33 }>
34 )._thenUnwrap((obj) => obj.result);
35 }
36
37 /**
38 * Update token.
39 *
40 * @example
41 * ```ts
42 * const token = await client.aiSearch.tokens.update(
43 * '62af0db3-c410-40b2-9ee3-0e93f6dd1de0',
44 * {
45 * account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22',
46 * cf_api_id: 'a1b2c3d4e5f6',
47 * cf_api_key: 'abc123',
48 * name: 'my-token',
49 * },
50 * );
51 * ```
52 */
53 update(id: string, params: TokenUpdateParams, options?: RequestOptions): APIPromise<TokenUpdateResponse> {
54 const { account_id, ...body } = params;
55 return (
56 this._client.put(path`/accounts/${account_id}/ai-search/tokens/${id}`, {
57 body,
58 ...options,
59 }) as APIPromise<{ result: TokenUpdateResponse }>
60 )._thenUnwrap((obj) => obj.result);
61 }
62
63 /**
64 * List tokens.
65 *
66 * @example
67 * ```ts
68 * // Automatically fetches more pages as needed.
69 * for await (const tokenListResponse of client.aiSearch.tokens.list(
70 * { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' },
71 * )) {
72 * // ...
73 * }
74 * ```
75 */
76 list(
77 params: TokenListParams,
78 options?: RequestOptions,
79 ): PagePromise<TokenListResponsesV4PagePaginationArray, TokenListResponse> {
80 const { account_id, ...query } = params;
81 return this._client.getAPIList(
82 path`/accounts/${account_id}/ai-search/tokens`,
83 V4PagePaginationArray<TokenListResponse>,
84 { query, ...options },
85 );
86 }
87
88 /**
89 * Delete token.
90 *
91 * @example
92 * ```ts
93 * const token = await client.aiSearch.tokens.delete(
94 * '62af0db3-c410-40b2-9ee3-0e93f6dd1de0',
95 * { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' },
96 * );
97 * ```
98 */
99 delete(id: string, params: TokenDeleteParams, options?: RequestOptions): APIPromise<TokenDeleteResponse> {
100 const { account_id } = params;
101 return (
102 this._client.delete(path`/accounts/${account_id}/ai-search/tokens/${id}`, options) as APIPromise<{
103 result: TokenDeleteResponse;
104 }>
105 )._thenUnwrap((obj) => obj.result);
106 }
107
108 /**
109 * Read token.
110 *
111 * @example
112 * ```ts
113 * const response = await client.aiSearch.tokens.read(
114 * '62af0db3-c410-40b2-9ee3-0e93f6dd1de0',
115 * { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22' },
116 * );
117 * ```
118 */
119 read(id: string, params: TokenReadParams, options?: RequestOptions): APIPromise<TokenReadResponse> {
120 const { account_id } = params;
121 return (
122 this._client.get(path`/accounts/${account_id}/ai-search/tokens/${id}`, options) as APIPromise<{
123 result: TokenReadResponse;
124 }>
125 )._thenUnwrap((obj) => obj.result);
126 }
127}
128export class Tokens extends BaseTokens {}
129
130export type TokenListResponsesV4PagePaginationArray = V4PagePaginationArray<TokenListResponse>;
131
132export interface TokenCreateResponse {
133 id: string;
134
135 cf_api_id: string;
136
137 created_at: string;
138
139 modified_at: string;
140
141 name: string;
142
143 created_by?: string | null;
144
145 enabled?: boolean;
146
147 legacy?: boolean;
148
149 modified_by?: string | null;
150}
151
152export interface TokenUpdateResponse {
153 id: string;
154
155 cf_api_id: string;
156
157 created_at: string;
158
159 modified_at: string;
160
161 name: string;
162
163 created_by?: string | null;
164
165 enabled?: boolean;
166
167 legacy?: boolean;
168
169 modified_by?: string | null;
170}
171
172export interface TokenListResponse {
173 id: string;
174
175 cf_api_id: string;
176
177 created_at: string;
178
179 modified_at: string;
180
181 name: string;
182
183 created_by?: string | null;
184
185 enabled?: boolean;
186
187 legacy?: boolean;
188
189 modified_by?: string | null;
190}
191
192export type TokenDeleteResponse = unknown;
193
194export interface TokenReadResponse {
195 id: string;
196
197 cf_api_id: string;
198
199 created_at: string;
200
201 modified_at: string;
202
203 name: string;
204
205 created_by?: string | null;
206
207 enabled?: boolean;
208
209 legacy?: boolean;
210
211 modified_by?: string | null;
212}
213
214export interface TokenCreateParams {
215 /**
216 * Path param
217 */
218 account_id: string;
219
220 /**
221 * Body param
222 */
223 cf_api_id: string;
224
225 /**
226 * Body param
227 */
228 cf_api_key: string;
229
230 /**
231 * Body param
232 */
233 name: string;
234
235 /**
236 * Body param
237 */
238 legacy?: boolean;
239}
240
241export interface TokenUpdateParams {
242 /**
243 * Path param
244 */
245 account_id: string;
246
247 /**
248 * Body param
249 */
250 cf_api_id: string;
251
252 /**
253 * Body param
254 */
255 cf_api_key: string;
256
257 /**
258 * Body param
259 */
260 name: string;
261
262 /**
263 * Body param
264 */
265 legacy?: boolean;
266}
267
268export interface TokenListParams extends V4PagePaginationArrayParams {
269 /**
270 * Path param
271 */
272 account_id: string;
273
274 /**
275 * Query param: Filter tokens whose name contains this string (case-insensitive).
276 */
277 search?: string;
278}
279
280export interface TokenDeleteParams {
281 account_id: string;
282}
283
284export interface TokenReadParams {
285 account_id: string;
286}
287
288export declare namespace Tokens {
289 export {
290 type TokenCreateResponse as TokenCreateResponse,
291 type TokenUpdateResponse as TokenUpdateResponse,
292 type TokenListResponse as TokenListResponse,
293 type TokenDeleteResponse as TokenDeleteResponse,
294 type TokenReadResponse as TokenReadResponse,
295 type TokenListResponsesV4PagePaginationArray as TokenListResponsesV4PagePaginationArray,
296 type TokenCreateParams as TokenCreateParams,
297 type TokenUpdateParams as TokenUpdateParams,
298 type TokenListParams as TokenListParams,
299 type TokenDeleteParams as TokenDeleteParams,
300 type TokenReadParams as TokenReadParams,
301 };
302}
303