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