Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BeatsCM] Move API to new return format #27408

Closed
mattapperson opened this issue Dec 18, 2018 · 1 comment
Closed

[BeatsCM] Move API to new return format #27408

mattapperson opened this issue Dec 18, 2018 · 1 comment
Assignees
Labels

Comments

@mattapperson
Copy link
Contributor

mattapperson commented Dec 18, 2018

The api currently returns in a semi-eratic fashion the shape of data and errors.
We want to move to a more predictable pattern.

regardless of HTTP status code, the following data structure should be used:

export interface ReturnType {
  error?: {
    message: string;
    code?: number;
  };
  success: boolean;
}

export interface ReturnTypeCreate<T> extends ReturnType {
  item: T;
  action: 'created';
}

export interface ReturnTypeUpdate<T> extends ReturnType {
  item: T;
  action: 'updated';
}

export interface ReturnTypeBulkCreate extends ReturnType {
  results: Array<{
    success: boolean;
    action: 'created';
    error?: {
      message: string;
      code?: number;
    };
  }>;
}

// delete
export interface ReturnTypeDelete extends ReturnType {
  action: 'deleted';
}

export interface ReturnTypeBulkDelete extends ReturnType {
  results: Array<{
    success: boolean;
    action: 'deleted';
    error?: {
      message: string;
      code?: number;
    };
  }>;
}

// upsert
export interface ReturnTypeUpsert<T> extends ReturnType {
  item: T;
  action: 'created' | 'updated';
}

// upsert bulk
export interface ReturnTypeBulkUpsert extends ReturnType {
  results: Array<{
    success: boolean;
    action: 'created' | 'updated';
    error?: {
      message: string;
      code?: number;
    };
  }>;
}

// list
export interface ReturnTypeList<T> extends ReturnType {
  list: T[];
  page: number; // -1 is unpaged results
  total: number; // -1 is unknown due to unpaged results
}

// get
export interface ReturnTypeGet<T> extends ReturnType {
  item: T;
}

export interface ReturnTypeBulkGet<T> extends ReturnType {
  items: T[];
}

// action -- e.g. validate config block. Like ES simulate endpoint
export interface ReturnTypeAction extends ReturnType {
  result: {
    [key: string]: any;
  };
}
// e.g.
// {
//   result: {
//     username: { valid: true },
//     password: { valid: false, error: 'something' },
//     hosts: [
//       { valid: false }, { valid: true },
//     ]
//   }
// }

// bulk action -- e.g. assign tags to beats
export interface ReturnTypeBulkAction extends ReturnType {
  results?: Array<{
    success: boolean;
    result?: {
      [key: string]: any;
    };
    error?: {
      message: string;
      code?: number;
    };
  }>;
}
@mattapperson mattapperson added the loe:medium Medium Level of Effort label Feb 5, 2019
ph added a commit to ph/beats that referenced this issue Mar 21, 2019
Format is defined in elastic/kibana#27408
Main objective is to easier bubbling or errors and messages.

```
export interface ReturnType {
  error?: {
    message: string;
    code?: number;
  };
  success: boolean;
}

```
ph added a commit to elastic/beats that referenced this issue Mar 28, 2019
Format is defined in elastic/kibana#27408
Main objective is to easier bubbling or errors and messages.

```
export interface ReturnType {
  error?: {
    message: string;
    code?: number;
  };
  success: boolean;
}

```
@ph
Copy link
Contributor

ph commented Mar 29, 2019

closing PR are merged.

elastic/beats#11377
#31660

@ph ph closed this as completed Mar 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants