cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/dlp/datasets.ts
326lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. |
| 2 | |
| 3 | import * as Core from 'cloudflare/core'; |
| 4 | import { APIResource } from 'cloudflare/resource'; |
| 5 | import * as DatasetsAPI from 'cloudflare/resources/dlp/datasets'; |
| 6 | |
| 7 | export class Datasets extends APIResource { |
| 8 | /** |
| 9 | * Create a new dataset. |
| 10 | */ |
| 11 | create( |
| 12 | accountId: string, |
| 13 | body: DatasetCreateParams, |
| 14 | options?: Core.RequestOptions, |
| 15 | ): Core.APIPromise<DatasetCreateResponse> { |
| 16 | return ( |
| 17 | this._client.post(`/accounts/${accountId}/dlp/datasets`, { body, ...options }) as Core.APIPromise<{ |
| 18 | result: DatasetCreateResponse; |
| 19 | }> |
| 20 | )._thenUnwrap((obj) => obj.result); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Fetch a specific dataset with information about available versions. |
| 25 | */ |
| 26 | retrieve( |
| 27 | accountId: string, |
| 28 | datasetId: string, |
| 29 | options?: Core.RequestOptions, |
| 30 | ): Core.APIPromise<DatasetRetrieveResponse> { |
| 31 | return ( |
| 32 | this._client.get(`/accounts/${accountId}/dlp/datasets/${datasetId}`, options) as Core.APIPromise<{ |
| 33 | result: DatasetRetrieveResponse; |
| 34 | }> |
| 35 | )._thenUnwrap((obj) => obj.result); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Update details about a dataset. |
| 40 | */ |
| 41 | update( |
| 42 | accountId: string, |
| 43 | datasetId: string, |
| 44 | body: DatasetUpdateParams, |
| 45 | options?: Core.RequestOptions, |
| 46 | ): Core.APIPromise<DatasetUpdateResponse> { |
| 47 | return ( |
| 48 | this._client.put(`/accounts/${accountId}/dlp/datasets/${datasetId}`, { |
| 49 | body, |
| 50 | ...options, |
| 51 | }) as Core.APIPromise<{ result: DatasetUpdateResponse }> |
| 52 | )._thenUnwrap((obj) => obj.result); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Fetch all datasets with information about available versions. |
| 57 | */ |
| 58 | list(accountId: string, options?: Core.RequestOptions): Core.APIPromise<DatasetListResponse> { |
| 59 | return ( |
| 60 | this._client.get(`/accounts/${accountId}/dlp/datasets`, options) as Core.APIPromise<{ |
| 61 | result: DatasetListResponse; |
| 62 | }> |
| 63 | )._thenUnwrap((obj) => obj.result); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Delete a dataset. |
| 68 | * |
| 69 | * This deletes all versions of the dataset. |
| 70 | */ |
| 71 | delete(accountId: string, datasetId: string, options?: Core.RequestOptions): Core.APIPromise<void> { |
| 72 | return this._client.delete(`/accounts/${accountId}/dlp/datasets/${datasetId}`, { |
| 73 | ...options, |
| 74 | headers: { Accept: '*/*', ...options?.headers }, |
| 75 | }); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Upload a new version of a dataset. |
| 80 | */ |
| 81 | upload( |
| 82 | accountId: string, |
| 83 | datasetId: string, |
| 84 | version: number, |
| 85 | body: DatasetUploadParams, |
| 86 | options?: Core.RequestOptions, |
| 87 | ): Core.APIPromise<DatasetUploadResponse> { |
| 88 | return ( |
| 89 | this._client.post( |
| 90 | `/accounts/${accountId}/dlp/datasets/${datasetId}/upload/${version}`, |
| 91 | options, |
| 92 | ) as Core.APIPromise<{ result: DatasetUploadResponse }> |
| 93 | )._thenUnwrap((obj) => obj.result); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Prepare to upload a new version of a dataset. |
| 98 | */ |
| 99 | uploadPrepare( |
| 100 | accountId: string, |
| 101 | datasetId: string, |
| 102 | options?: Core.RequestOptions, |
| 103 | ): Core.APIPromise<DatasetUploadPrepareResponse> { |
| 104 | return ( |
| 105 | this._client.post( |
| 106 | `/accounts/${accountId}/dlp/datasets/${datasetId}/upload`, |
| 107 | options, |
| 108 | ) as Core.APIPromise<{ result: DatasetUploadPrepareResponse }> |
| 109 | )._thenUnwrap((obj) => obj.result); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | export interface DatasetCreateResponse { |
| 114 | dataset: DatasetCreateResponse.Dataset; |
| 115 | |
| 116 | max_cells: number; |
| 117 | |
| 118 | /** |
| 119 | * The version to use when uploading the dataset. |
| 120 | */ |
| 121 | version: number; |
| 122 | |
| 123 | /** |
| 124 | * The secret to use for Exact Data Match datasets. This is not present in Custom |
| 125 | * Wordlists. |
| 126 | */ |
| 127 | secret?: string; |
| 128 | } |
| 129 | |
| 130 | export namespace DatasetCreateResponse { |
| 131 | export interface Dataset { |
| 132 | id: string; |
| 133 | |
| 134 | created_at: string; |
| 135 | |
| 136 | name: string; |
| 137 | |
| 138 | num_cells: number; |
| 139 | |
| 140 | secret: boolean; |
| 141 | |
| 142 | status: 'empty' | 'uploading' | 'failed' | 'complete'; |
| 143 | |
| 144 | updated_at: string; |
| 145 | |
| 146 | uploads: Array<Dataset.Upload>; |
| 147 | |
| 148 | description?: string | null; |
| 149 | } |
| 150 | |
| 151 | export namespace Dataset { |
| 152 | export interface Upload { |
| 153 | num_cells: number; |
| 154 | |
| 155 | status: 'empty' | 'uploading' | 'failed' | 'complete'; |
| 156 | |
| 157 | version: number; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | export interface DatasetRetrieveResponse { |
| 163 | id: string; |
| 164 | |
| 165 | created_at: string; |
| 166 | |
| 167 | name: string; |
| 168 | |
| 169 | num_cells: number; |
| 170 | |
| 171 | secret: boolean; |
| 172 | |
| 173 | status: 'empty' | 'uploading' | 'failed' | 'complete'; |
| 174 | |
| 175 | updated_at: string; |
| 176 | |
| 177 | uploads: Array<DatasetRetrieveResponse.Upload>; |
| 178 | |
| 179 | description?: string | null; |
| 180 | } |
| 181 | |
| 182 | export namespace DatasetRetrieveResponse { |
| 183 | export interface Upload { |
| 184 | num_cells: number; |
| 185 | |
| 186 | status: 'empty' | 'uploading' | 'failed' | 'complete'; |
| 187 | |
| 188 | version: number; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | export interface DatasetUpdateResponse { |
| 193 | id: string; |
| 194 | |
| 195 | created_at: string; |
| 196 | |
| 197 | name: string; |
| 198 | |
| 199 | num_cells: number; |
| 200 | |
| 201 | secret: boolean; |
| 202 | |
| 203 | status: 'empty' | 'uploading' | 'failed' | 'complete'; |
| 204 | |
| 205 | updated_at: string; |
| 206 | |
| 207 | uploads: Array<DatasetUpdateResponse.Upload>; |
| 208 | |
| 209 | description?: string | null; |
| 210 | } |
| 211 | |
| 212 | export namespace DatasetUpdateResponse { |
| 213 | export interface Upload { |
| 214 | num_cells: number; |
| 215 | |
| 216 | status: 'empty' | 'uploading' | 'failed' | 'complete'; |
| 217 | |
| 218 | version: number; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | export type DatasetListResponse = Array<DatasetListResponse.DatasetListResponseItem>; |
| 223 | |
| 224 | export namespace DatasetListResponse { |
| 225 | export interface DatasetListResponseItem { |
| 226 | id: string; |
| 227 | |
| 228 | created_at: string; |
| 229 | |
| 230 | name: string; |
| 231 | |
| 232 | num_cells: number; |
| 233 | |
| 234 | secret: boolean; |
| 235 | |
| 236 | status: 'empty' | 'uploading' | 'failed' | 'complete'; |
| 237 | |
| 238 | updated_at: string; |
| 239 | |
| 240 | uploads: Array<DatasetListResponseItem.Upload>; |
| 241 | |
| 242 | description?: string | null; |
| 243 | } |
| 244 | |
| 245 | export namespace DatasetListResponseItem { |
| 246 | export interface Upload { |
| 247 | num_cells: number; |
| 248 | |
| 249 | status: 'empty' | 'uploading' | 'failed' | 'complete'; |
| 250 | |
| 251 | version: number; |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | export interface DatasetUploadResponse { |
| 257 | id: string; |
| 258 | |
| 259 | created_at: string; |
| 260 | |
| 261 | name: string; |
| 262 | |
| 263 | num_cells: number; |
| 264 | |
| 265 | secret: boolean; |
| 266 | |
| 267 | status: 'empty' | 'uploading' | 'failed' | 'complete'; |
| 268 | |
| 269 | updated_at: string; |
| 270 | |
| 271 | uploads: Array<DatasetUploadResponse.Upload>; |
| 272 | |
| 273 | description?: string | null; |
| 274 | } |
| 275 | |
| 276 | export namespace DatasetUploadResponse { |
| 277 | export interface Upload { |
| 278 | num_cells: number; |
| 279 | |
| 280 | status: 'empty' | 'uploading' | 'failed' | 'complete'; |
| 281 | |
| 282 | version: number; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | export interface DatasetUploadPrepareResponse { |
| 287 | max_cells: number; |
| 288 | |
| 289 | version: number; |
| 290 | |
| 291 | secret?: string; |
| 292 | } |
| 293 | |
| 294 | export interface DatasetCreateParams { |
| 295 | name: string; |
| 296 | |
| 297 | description?: string | null; |
| 298 | |
| 299 | /** |
| 300 | * Generate a secret dataset. |
| 301 | * |
| 302 | * If true, the response will include a secret to use with the EDM encoder. If |
| 303 | * false, the response has no secret and the dataset is uploaded in plaintext. |
| 304 | */ |
| 305 | secret?: boolean; |
| 306 | } |
| 307 | |
| 308 | export interface DatasetUpdateParams { |
| 309 | description?: string | null; |
| 310 | |
| 311 | name?: string | null; |
| 312 | } |
| 313 | |
| 314 | export interface DatasetUploadParams {} |
| 315 | |
| 316 | export namespace Datasets { |
| 317 | export import DatasetCreateResponse = DatasetsAPI.DatasetCreateResponse; |
| 318 | export import DatasetRetrieveResponse = DatasetsAPI.DatasetRetrieveResponse; |
| 319 | export import DatasetUpdateResponse = DatasetsAPI.DatasetUpdateResponse; |
| 320 | export import DatasetListResponse = DatasetsAPI.DatasetListResponse; |
| 321 | export import DatasetUploadResponse = DatasetsAPI.DatasetUploadResponse; |
| 322 | export import DatasetUploadPrepareResponse = DatasetsAPI.DatasetUploadPrepareResponse; |
| 323 | export import DatasetCreateParams = DatasetsAPI.DatasetCreateParams; |
| 324 | export import DatasetUpdateParams = DatasetsAPI.DatasetUpdateParams; |
| 325 | export import DatasetUploadParams = DatasetsAPI.DatasetUploadParams; |
| 326 | } |
| 327 | |