Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 95 additions & 70 deletions x-pack/plugins/actions/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ export const IncidentConfigurationSchema = schema.object({
mapping: schema.arrayOf(MapRecordSchema),
});

export const UserSchema = schema.object({
fullName: schema.nullable(schema.string()),
username: schema.nullable(schema.string()),
});

export const EntityInformation = {
createdAt: schema.maybe(schema.string()),
createdBy: schema.maybe(schema.any()),
createdAt: schema.nullable(schema.string()),
createdBy: schema.nullable(UserSchema),
updatedAt: schema.nullable(schema.string()),
updatedBy: schema.nullable(schema.any()),
updatedBy: schema.nullable(UserSchema),
};

export const EntityInformationSchema = schema.object(EntityInformation);

export const CommentSchema = schema.object({
commentId: schema.string(),
comment: schema.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,38 @@

import { TypeOf } from '@kbn/config-schema';
import {
ExecutorSubActionGetIncidentParamsSchema,
ExecutorSubActionHandshakeParamsSchema,
} from './schema';
import { IncidentConfigurationSchema, MapRecordSchema } from './case_shema';
import {
PushToServiceApiParams,
ExternalServiceIncidentResponse,
ExternalServiceParams,
} from './types';
IncidentConfigurationSchema,
MapRecordSchema,
CommentSchema,
EntityInformationSchema,
} from './common_schema';

export interface CreateCommentRequest {
[key: string]: string;
}

export type IncidentConfiguration = TypeOf<typeof IncidentConfigurationSchema>;
export type MapRecord = TypeOf<typeof MapRecordSchema>;
export type Comment = TypeOf<typeof CommentSchema>;
export type EntityInformation = TypeOf<typeof EntityInformationSchema>;

export interface ExternalServiceCommentResponse {
commentId: string;
pushedDate: string;
externalCommentId?: string;
}

export type ExecutorSubActionGetIncidentParams = TypeOf<
typeof ExecutorSubActionGetIncidentParamsSchema
>;

export type ExecutorSubActionHandshakeParams = TypeOf<
typeof ExecutorSubActionHandshakeParamsSchema
>;

export interface PushToServiceResponse extends ExternalServiceIncidentResponse {
comments?: ExternalServiceCommentResponse[];
}

export interface PipedField {
key: string;
value: string;
actionType: string;
pipes: string[];
}

export interface TransformFieldsArgs {
params: PushToServiceApiParams;
export interface TransformFieldsArgs<P, S> {
params: P;
fields: PipedField[];
currentIncident?: ExternalServiceParams;
currentIncident?: S;
}

export interface TransformerArgs {
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/actions/server/builtin_action_types/case/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ export const buildMap = (mapping: MapRecord[]): Map<string, MapRecord> => {
}, new Map());
};

export const mapParams = (
params: Partial<ExecutorSubActionPushParams>,
mapping: Map<string, MapRecord>
): AnyParams => {
export const mapParams = <T extends {}>(params: T, mapping: Map<string, MapRecord>): AnyParams => {
return Object.keys(params).reduce((prev: AnyParams, curr: string): AnyParams => {
const field = mapping.get(curr);
if (field) {
Expand Down Expand Up @@ -106,7 +103,10 @@ export const createConnectorExecutor = ({
const { comments, externalId, ...restParams } = pushToServiceParams;

const mapping = buildMap(config.casesConfiguration.mapping);
const externalCase = mapParams(restParams, mapping);
const externalCase = mapParams<ExecutorSubActionPushParams>(
restParams as ExecutorSubActionPushParams,
mapping
);

data = await api.pushToService({
externalService,
Expand Down
Loading