diff --git a/x-pack/plugins/actions/server/builtin_action_types/case/utils.ts b/x-pack/plugins/actions/server/builtin_action_types/case/utils.ts index 8228fc1e2eb401..ebb33efbee6e5f 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/case/utils.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/case/utils.ts @@ -145,34 +145,30 @@ export const throwIfNotAlive = ( } }; -export const request = async ({ +export const request = async ({ axios, url, method = 'get', - data = {}, + data, }: { axios: AxiosInstance; url: string; method?: Method; - // This will have to remain `any` until we can extend connectors with generics - // eslint-disable-next-line @typescript-eslint/no-explicit-any - data?: any; + data?: T; }): Promise => { - const res = await axios(url, { method, data }); + const res = await axios(url, { method, data: data ?? {} }); throwIfNotAlive(res.status, res.headers['content-type']); return res; }; -export const patch = ({ +export const patch = async ({ axios, url, data, }: { axios: AxiosInstance; url: string; - // This will have to remain `any` until we can extend connectors with generics - // eslint-disable-next-line @typescript-eslint/no-explicit-any - data: any; + data: T; }): Promise => { return request({ axios, diff --git a/x-pack/plugins/actions/server/builtin_action_types/jira/service.ts b/x-pack/plugins/actions/server/builtin_action_types/jira/service.ts index 554d82b6e9dd2c..ff22b8368e7dd2 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/jira/service.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/jira/service.ts @@ -7,7 +7,13 @@ import axios from 'axios'; import { ExternalServiceCredentials, ExternalService, ExternalServiceParams } from '../case/types'; -import { JiraPublicConfigurationType, JiraSecretConfigurationType } from './types'; +import { + JiraPublicConfigurationType, + JiraSecretConfigurationType, + CreateIncidentRequest, + UpdateIncidentRequest, + CreateCommentRequest, +} from './types'; import * as i18n from './translations'; import { getErrorMessage, request } from '../case/utils'; @@ -66,7 +72,7 @@ export const createExternalService = ({ // The function makes two calls when creating an issue. One to create the issue and one to get // the created issue with all the necessary fields. try { - const res = await request({ + const res = await request({ axios: axiosInstance, url: `${incidentUrl}`, method: 'post', @@ -92,7 +98,7 @@ export const createExternalService = ({ const updateIncident = async ({ incidentId, incident }: ExternalServiceParams) => { try { - await request({ + await request({ axios: axiosInstance, method: 'put', url: `${incidentUrl}/${incidentId}`, @@ -119,7 +125,7 @@ export const createExternalService = ({ const createComment = async ({ incidentId, comment, field }: ExternalServiceParams) => { try { - const res = await request({ + const res = await request({ axios: axiosInstance, method: 'post', url: getCommentsURL(incidentId), diff --git a/x-pack/plugins/actions/server/builtin_action_types/jira/types.ts b/x-pack/plugins/actions/server/builtin_action_types/jira/types.ts index 0051ef6c70b2c6..8d9c6b92abb3b2 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/jira/types.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/jira/types.ts @@ -9,3 +9,24 @@ import { JiraPublicConfigurationSchema, JiraSecretConfigurationSchema } from './ export type JiraPublicConfigurationType = TypeOf; export type JiraSecretConfigurationType = TypeOf; + +interface CreateIncidentBasicRequestArgs { + summary: string; + description: string; +} +interface CreateIncidentRequestArgs extends CreateIncidentBasicRequestArgs { + project: { key: string }; + issuetype: { name: string }; +} + +export interface CreateIncidentRequest { + fields: CreateIncidentRequestArgs; +} + +export interface UpdateIncidentRequest { + fields: Partial; +} + +export interface CreateCommentRequest { + body: string; +} diff --git a/x-pack/plugins/actions/server/builtin_action_types/servicenow/service.ts b/x-pack/plugins/actions/server/builtin_action_types/servicenow/service.ts index ca050beb10b03b..541fefce2f2ff5 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/servicenow/service.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/servicenow/service.ts @@ -10,7 +10,13 @@ import { ExternalServiceCredentials, ExternalService, ExternalServiceParams } fr import { addTimeZoneToDate, patch, request, getErrorMessage } from '../case/utils'; import * as i18n from './translations'; -import { ServiceNowPublicConfigurationType, ServiceNowSecretConfigurationType } from './types'; +import { + ServiceNowPublicConfigurationType, + ServiceNowSecretConfigurationType, + CreateIncidentRequest, + UpdateIncidentRequest, + CreateCommentRequest, +} from './types'; const API_VERSION = 'v2'; const INCIDENT_URL = `api/now/${API_VERSION}/table/incident`; @@ -57,7 +63,7 @@ export const createExternalService = ({ const createIncident = async ({ incident }: ExternalServiceParams) => { try { - const res = await request({ + const res = await request({ axios: axiosInstance, url: `${incidentUrl}`, method: 'post', @@ -79,7 +85,7 @@ export const createExternalService = ({ const updateIncident = async ({ incidentId, incident }: ExternalServiceParams) => { try { - const res = await patch({ + const res = await patch({ axios: axiosInstance, url: `${incidentUrl}/${incidentId}`, data: { ...incident }, @@ -103,7 +109,7 @@ export const createExternalService = ({ const createComment = async ({ incidentId, comment, field }: ExternalServiceParams) => { try { - const res = await patch({ + const res = await patch({ axios: axiosInstance, url: `${commentUrl}/${incidentId}`, data: { [field]: comment.comment }, diff --git a/x-pack/plugins/actions/server/builtin_action_types/servicenow/types.ts b/x-pack/plugins/actions/server/builtin_action_types/servicenow/types.ts index 7b4f781e51b134..d8476b7dca54a5 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/servicenow/types.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/servicenow/types.ts @@ -8,3 +8,14 @@ export { ExternalIncidentServiceConfiguration as ServiceNowPublicConfigurationType, ExternalIncidentServiceSecretConfiguration as ServiceNowSecretConfigurationType, } from '../case/types'; + +export interface CreateIncidentRequest { + summary: string; + description: string; +} + +export type UpdateIncidentRequest = Partial; + +export interface CreateCommentRequest { + [key: string]: string; +}