/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { IncidentioCore } from "../core.js"; import { encodeFormQuery as encodeFormQuery$ } from "../lib/encodings.js"; import * as m$ from "../lib/matchers.js"; import * as schemas$ from "../lib/schemas.js"; import { RequestOptions } from "../lib/sdks.js"; import { pathToFunc } from "../lib/url.js"; import * as components from "../models/components/index.js"; import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError, } from "../models/errors/httpclienterrors.js"; import { SDKError } from "../models/errors/sdkerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import * as operations from "../models/operations/index.js"; import { Result } from "../types/fp.js"; /** * List Incidents V2 * * @remarks * List all incidents for an organisation. * * This endpoint supports a number of filters, which can help find incidents matching certain * criteria. * * Filters are provided as query parameters, but due to the dynamic nature of what you can * query by (different accounts have different custom fields, statuses, etc) they are more * complex than most. * * To help, here are some exemplar curl requests with a human description of what they search * for. * * Note that: * - Filters may be used together, and the result will be incidents that match all filters. * - IDs are normally in UUID format, but have been replaced with shorter strings to improve * readability. * - All query parameters must be URI encoded. * * ### By status * * With status of id=ABC, find all incidents that are set to that status: * * curl --get 'https://api.incident.io/v2/incidents' \ * --data 'status[one_of]=ABC' * * Or all incidents that are not set to status with id=ABC: * * curl --get 'https://api.incident.io/v2/incidents' \ * --data 'status[not_in]=ABC' * * ### By created_at or updated_at * * Find all incidents that follow specified date parameters for created_at and updated_at fields. * Possible values are "gte" (greater than or equal to) and "lte" (less than or equal to). The * following example finds all incidents created before or on 2021-01-02T00:00:00Z: * * curl --get 'https://api.incident.io/v2/incidents' \ * --data 'created_at[lte]=2021-01-02' * * ### By status category * * Find all incidents that are in a status category. Possible values are "triage", * "declined", "merged", "canceled", "live", "learning" and "closed": * * curl --get 'https://api.incident.io/v2/incidents' \ * --data 'status_category[one_of]=live' * * Or all incidents that are not in a status category: * * curl --get 'https://api.incident.io/v2/incidents' \ * --data 'status_category[not_in]=live' * * ### By severity * * With severity of id=ABC, find all incidents that are set to that severity: * * curl --get 'https://api.incident.io/v2/incidents' \ * --data 'severity[one_of]=ABC' * * Or all incidents where severity rank is greater-than-or-equal-to the rank of severity * id=ABC: * * curl --get 'https://api.incident.io/v2/incidents' \ * --data 'severity[gte]=ABC' * * Or all incidents where severity rank is less-than-or-equal-to the rank of severity id=ABC: * * curl --get 'https://api.incident.io/v2/incidents' \ * --data 'severity[lte]=ABC' * * ### By incident type * * With incident type of id=ABC, find all incidents that are of that type: * * curl --get 'https://api.incident.io/v2/incidents' \ * --data 'incident_type[one_of]=ABC' * * Or all incidents not of that type: * * curl --get 'https://api.incident.io/v2/incidents' \ * --data 'incident_type[not_in]=ABC' * * ### By incident mode * * By default, we return standard and retrospective incidents. This means that test and * tutorial incidents are filtered out. To override this behaviour, you can use the * mode filter to specify which modes you want to get. * * To find incidents of all modes: * * curl --get 'https://api.incident.io/v2/incidents' \ * --data 'mode[one_of]=standard&mode[one_of]=retrospective&mode[one_of]=test&mode[one_of]=tutorial' * * To find just test incidents: * * curl --get 'https://api.incident.io/v2/incidents' \ * --data 'mode[one_of]=test' * * ### By incident role * * Roles and custom fields have another nested layer in the query parameter, to account for * operations against any of the roles or custom fields created in the account. * * With incident role id=ABC, find all incidents where that role is unset: * * curl --get 'https://api.incident.io/v2/incidents' \ * --data 'incident_role[ABC][is_blank]=true' * * Or where the role has been set: * * curl --get 'https://api.incident.io/v2/incidents' \ * --data 'incident_role[ABC][is_blank]=false' * * ### By option custom fields * * With an option custom field id=ABC, all incidents that have field ABC set to the custom * field option of id=XYZ: * * curl \ * --get 'https://api.incident.io/v2/incidents' \ * --data 'custom_field[ABC][one_of]=XYZ' * * Or all incidents that do not have custom field id=ABC set to option id=XYZ: * * curl \ * --get 'https://api.incident.io/v2/incidents' \ * --data 'custom_field[ABC][not_in]=XYZ' */ export async function incidentsList( client$: IncidentioCore, request: operations.IncidentsV2NumberListRequest, options?: RequestOptions, ): Promise< Result< components.ListResponseBody15, | SDKError | SDKValidationError | UnexpectedClientError | InvalidRequestError | RequestAbortedError | RequestTimeoutError | ConnectionError > > { const input$ = request; const parsed$ = schemas$.safeParse( input$, (value$) => operations.IncidentsV2NumberListRequest$outboundSchema.parse(value$), "Input validation failed", ); if (!parsed$.ok) { return parsed$; } const payload$ = parsed$.value; const body$ = null; const path$ = pathToFunc("/v2/incidents")(); const query$ = encodeFormQuery$({ "after": payload$.after, "created_at": payload$.created_at, "custom_field": payload$.custom_field, "incident_role": payload$.incident_role, "incident_type": payload$.incident_type, "mode": payload$.mode, "page_size": payload$.page_size, "severity": payload$.severity, "status": payload$.status, "status_category": payload$.status_category, "updated_at": payload$.updated_at, }); const headers$ = new Headers({ Accept: "application/json", }); const context = { operationID: "Incidents V2#List", oAuth2Scopes: [], securitySource: null, }; const requestRes = client$.createRequest$(context, { method: "GET", path: path$, headers: headers$, query: query$, body: body$, timeoutMs: options?.timeoutMs || client$.options$.timeoutMs || -1, }, options); if (!requestRes.ok) { return requestRes; } const request$ = requestRes.value; const doResult = await client$.do$(request$, { context, errorCodes: ["4XX", "5XX"], retryConfig: options?.retries || client$.options$.retryConfig, retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }); if (!doResult.ok) { return doResult; } const response = doResult.value; const [result$] = await m$.match< components.ListResponseBody15, | SDKError | SDKValidationError | UnexpectedClientError | InvalidRequestError | RequestAbortedError | RequestTimeoutError | ConnectionError >( m$.json(200, components.ListResponseBody15$inboundSchema), m$.fail(["4XX", "5XX"]), )(response); if (!result$.ok) { return result$; } return result$; }