cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/alerting/silences.ts
374lines · 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 { SinglePage } from '../../pagination'; |
| 6 | |
| 7 | export class Silences extends APIResource { |
| 8 | /** |
| 9 | * Creates a new silence for an account. |
| 10 | * |
| 11 | * @example |
| 12 | * ```ts |
| 13 | * const silence = await client.alerting.silences.create({ |
| 14 | * account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 15 | * body: [{}], |
| 16 | * }); |
| 17 | * ``` |
| 18 | */ |
| 19 | create(params: SilenceCreateParams, options?: Core.RequestOptions): Core.APIPromise<SilenceCreateResponse> { |
| 20 | const { account_id, body } = params; |
| 21 | return this._client.post(`/accounts/${account_id}/alerting/v3/silences`, { body: body, ...options }); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Updates existing silences for an account. |
| 26 | * |
| 27 | * @example |
| 28 | * ```ts |
| 29 | * // Automatically fetches more pages as needed. |
| 30 | * for await (const silenceUpdateResponse of client.alerting.silences.update( |
| 31 | * { |
| 32 | * account_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 33 | * body: [{}], |
| 34 | * }, |
| 35 | * )) { |
| 36 | * // ... |
| 37 | * } |
| 38 | * ``` |
| 39 | */ |
| 40 | update( |
| 41 | params: SilenceUpdateParams, |
| 42 | options?: Core.RequestOptions, |
| 43 | ): Core.PagePromise<SilenceUpdateResponsesSinglePage, SilenceUpdateResponse> { |
| 44 | const { account_id, body } = params; |
| 45 | return this._client.getAPIList( |
| 46 | `/accounts/${account_id}/alerting/v3/silences`, |
| 47 | SilenceUpdateResponsesSinglePage, |
| 48 | { body: body, method: 'put', ...options }, |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Gets a list of silences for an account. |
| 54 | * |
| 55 | * @example |
| 56 | * ```ts |
| 57 | * // Automatically fetches more pages as needed. |
| 58 | * for await (const silenceListResponse of client.alerting.silences.list( |
| 59 | * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, |
| 60 | * )) { |
| 61 | * // ... |
| 62 | * } |
| 63 | * ``` |
| 64 | */ |
| 65 | list( |
| 66 | params: SilenceListParams, |
| 67 | options?: Core.RequestOptions, |
| 68 | ): Core.PagePromise<SilenceListResponsesSinglePage, SilenceListResponse> { |
| 69 | const { account_id } = params; |
| 70 | return this._client.getAPIList( |
| 71 | `/accounts/${account_id}/alerting/v3/silences`, |
| 72 | SilenceListResponsesSinglePage, |
| 73 | options, |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Deletes an existing silence for an account. |
| 79 | * |
| 80 | * @example |
| 81 | * ```ts |
| 82 | * const silence = await client.alerting.silences.delete( |
| 83 | * 'f878e90c23f44126ae3cfc399f646977', |
| 84 | * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, |
| 85 | * ); |
| 86 | * ``` |
| 87 | */ |
| 88 | delete( |
| 89 | silenceId: string, |
| 90 | params: SilenceDeleteParams, |
| 91 | options?: Core.RequestOptions, |
| 92 | ): Core.APIPromise<SilenceDeleteResponse> { |
| 93 | const { account_id } = params; |
| 94 | return this._client.delete(`/accounts/${account_id}/alerting/v3/silences/${silenceId}`, options); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Gets a specific silence for an account. |
| 99 | * |
| 100 | * @example |
| 101 | * ```ts |
| 102 | * const silence = await client.alerting.silences.get( |
| 103 | * 'f878e90c23f44126ae3cfc399f646977', |
| 104 | * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, |
| 105 | * ); |
| 106 | * ``` |
| 107 | */ |
| 108 | get( |
| 109 | silenceId: string, |
| 110 | params: SilenceGetParams, |
| 111 | options?: Core.RequestOptions, |
| 112 | ): Core.APIPromise<SilenceGetResponse> { |
| 113 | const { account_id } = params; |
| 114 | return ( |
| 115 | this._client.get( |
| 116 | `/accounts/${account_id}/alerting/v3/silences/${silenceId}`, |
| 117 | options, |
| 118 | ) as Core.APIPromise<{ result: SilenceGetResponse }> |
| 119 | )._thenUnwrap((obj) => obj.result); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | export class SilenceUpdateResponsesSinglePage extends SinglePage<SilenceUpdateResponse> {} |
| 124 | |
| 125 | export class SilenceListResponsesSinglePage extends SinglePage<SilenceListResponse> {} |
| 126 | |
| 127 | export interface SilenceCreateResponse { |
| 128 | errors: Array<SilenceCreateResponse.Error>; |
| 129 | |
| 130 | messages: Array<SilenceCreateResponse.Message>; |
| 131 | |
| 132 | /** |
| 133 | * Whether the API call was successful |
| 134 | */ |
| 135 | success: true; |
| 136 | } |
| 137 | |
| 138 | export namespace SilenceCreateResponse { |
| 139 | export interface Error { |
| 140 | message: string; |
| 141 | |
| 142 | code?: number; |
| 143 | } |
| 144 | |
| 145 | export interface Message { |
| 146 | message: string; |
| 147 | |
| 148 | code?: number; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | export interface SilenceUpdateResponse { |
| 153 | /** |
| 154 | * Silence ID |
| 155 | */ |
| 156 | id?: string; |
| 157 | |
| 158 | /** |
| 159 | * When the silence was created. |
| 160 | */ |
| 161 | created_at?: string; |
| 162 | |
| 163 | /** |
| 164 | * When the silence ends. |
| 165 | */ |
| 166 | end_time?: string; |
| 167 | |
| 168 | /** |
| 169 | * The unique identifier of a notification policy |
| 170 | */ |
| 171 | policy_id?: string; |
| 172 | |
| 173 | /** |
| 174 | * When the silence starts. |
| 175 | */ |
| 176 | start_time?: string; |
| 177 | |
| 178 | /** |
| 179 | * When the silence was modified. |
| 180 | */ |
| 181 | updated_at?: string; |
| 182 | } |
| 183 | |
| 184 | export interface SilenceListResponse { |
| 185 | /** |
| 186 | * Silence ID |
| 187 | */ |
| 188 | id?: string; |
| 189 | |
| 190 | /** |
| 191 | * When the silence was created. |
| 192 | */ |
| 193 | created_at?: string; |
| 194 | |
| 195 | /** |
| 196 | * When the silence ends. |
| 197 | */ |
| 198 | end_time?: string; |
| 199 | |
| 200 | /** |
| 201 | * The unique identifier of a notification policy |
| 202 | */ |
| 203 | policy_id?: string; |
| 204 | |
| 205 | /** |
| 206 | * When the silence starts. |
| 207 | */ |
| 208 | start_time?: string; |
| 209 | |
| 210 | /** |
| 211 | * When the silence was modified. |
| 212 | */ |
| 213 | updated_at?: string; |
| 214 | } |
| 215 | |
| 216 | export interface SilenceDeleteResponse { |
| 217 | errors: Array<SilenceDeleteResponse.Error>; |
| 218 | |
| 219 | messages: Array<SilenceDeleteResponse.Message>; |
| 220 | |
| 221 | /** |
| 222 | * Whether the API call was successful |
| 223 | */ |
| 224 | success: true; |
| 225 | } |
| 226 | |
| 227 | export namespace SilenceDeleteResponse { |
| 228 | export interface Error { |
| 229 | message: string; |
| 230 | |
| 231 | code?: number; |
| 232 | } |
| 233 | |
| 234 | export interface Message { |
| 235 | message: string; |
| 236 | |
| 237 | code?: number; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | export interface SilenceGetResponse { |
| 242 | /** |
| 243 | * Silence ID |
| 244 | */ |
| 245 | id?: string; |
| 246 | |
| 247 | /** |
| 248 | * When the silence was created. |
| 249 | */ |
| 250 | created_at?: string; |
| 251 | |
| 252 | /** |
| 253 | * When the silence ends. |
| 254 | */ |
| 255 | end_time?: string; |
| 256 | |
| 257 | /** |
| 258 | * The unique identifier of a notification policy |
| 259 | */ |
| 260 | policy_id?: string; |
| 261 | |
| 262 | /** |
| 263 | * When the silence starts. |
| 264 | */ |
| 265 | start_time?: string; |
| 266 | |
| 267 | /** |
| 268 | * When the silence was modified. |
| 269 | */ |
| 270 | updated_at?: string; |
| 271 | } |
| 272 | |
| 273 | export interface SilenceCreateParams { |
| 274 | /** |
| 275 | * Path param: The account id |
| 276 | */ |
| 277 | account_id: string; |
| 278 | |
| 279 | /** |
| 280 | * Body param |
| 281 | */ |
| 282 | body: Array<SilenceCreateParams.Body>; |
| 283 | } |
| 284 | |
| 285 | export namespace SilenceCreateParams { |
| 286 | export interface Body { |
| 287 | /** |
| 288 | * When the silence ends. |
| 289 | */ |
| 290 | end_time?: string; |
| 291 | |
| 292 | /** |
| 293 | * The unique identifier of a notification policy |
| 294 | */ |
| 295 | policy_id?: string; |
| 296 | |
| 297 | /** |
| 298 | * When the silence starts. |
| 299 | */ |
| 300 | start_time?: string; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | export interface SilenceUpdateParams { |
| 305 | /** |
| 306 | * Path param: The account id |
| 307 | */ |
| 308 | account_id: string; |
| 309 | |
| 310 | /** |
| 311 | * Body param |
| 312 | */ |
| 313 | body: Array<SilenceUpdateParams.Body>; |
| 314 | } |
| 315 | |
| 316 | export namespace SilenceUpdateParams { |
| 317 | export interface Body { |
| 318 | /** |
| 319 | * Silence ID |
| 320 | */ |
| 321 | id?: string; |
| 322 | |
| 323 | /** |
| 324 | * When the silence ends. |
| 325 | */ |
| 326 | end_time?: string; |
| 327 | |
| 328 | /** |
| 329 | * When the silence starts. |
| 330 | */ |
| 331 | start_time?: string; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | export interface SilenceListParams { |
| 336 | /** |
| 337 | * The account id |
| 338 | */ |
| 339 | account_id: string; |
| 340 | } |
| 341 | |
| 342 | export interface SilenceDeleteParams { |
| 343 | /** |
| 344 | * The account id |
| 345 | */ |
| 346 | account_id: string; |
| 347 | } |
| 348 | |
| 349 | export interface SilenceGetParams { |
| 350 | /** |
| 351 | * The account id |
| 352 | */ |
| 353 | account_id: string; |
| 354 | } |
| 355 | |
| 356 | Silences.SilenceUpdateResponsesSinglePage = SilenceUpdateResponsesSinglePage; |
| 357 | Silences.SilenceListResponsesSinglePage = SilenceListResponsesSinglePage; |
| 358 | |
| 359 | export declare namespace Silences { |
| 360 | export { |
| 361 | type SilenceCreateResponse as SilenceCreateResponse, |
| 362 | type SilenceUpdateResponse as SilenceUpdateResponse, |
| 363 | type SilenceListResponse as SilenceListResponse, |
| 364 | type SilenceDeleteResponse as SilenceDeleteResponse, |
| 365 | type SilenceGetResponse as SilenceGetResponse, |
| 366 | SilenceUpdateResponsesSinglePage as SilenceUpdateResponsesSinglePage, |
| 367 | SilenceListResponsesSinglePage as SilenceListResponsesSinglePage, |
| 368 | type SilenceCreateParams as SilenceCreateParams, |
| 369 | type SilenceUpdateParams as SilenceUpdateParams, |
| 370 | type SilenceListParams as SilenceListParams, |
| 371 | type SilenceDeleteParams as SilenceDeleteParams, |
| 372 | type SilenceGetParams as SilenceGetParams, |
| 373 | }; |
| 374 | } |
| 375 | |