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