import { isObject, doRequest, getRequestOptions } from './utils'; export default class { constructor (host, auth, headers) { this.host = host; this.auth = auth; this.headers = headers; } get (options) { const operationSettings = { "requiresBody": false, "queryParams": [ { "name": "process_definition_name", "nameCamelCase": "processDefinitionName" }, { "name": "start_time", "nameCamelCase": "startTime" }, { "name": "end_time", "nameCamelCase": "endTime" }, { "name": "max_records", "nameCamelCase": "maxRecords" }, { "name": "allowed_statuses", "nameCamelCase": "allowedStatuses" } ], "isApplicationJson": false, "isFormUrlEncoded": false, "method": "GET" }; return getRequestOptions(operationSettings, options) .then((opts) => { const uri = `${this.host}/api/processes/`; const auth = opts.auth || this.auth; const headers = this.headers || {}; // Layer in some options local to this class const requestOpts = Object.assign({ headers }, opts, { auth, uri }); return doRequest(requestOpts).then(function (serverResponse) { switch (serverResponse.statusCode) { case 200: if (requestOpts.json) { return Promise.resolve(serverResponse.body); } else { return Promise.resolve(JSON.parse(serverResponse.body)); } default: return Promise.reject(new Error('Unknown response code: ' + serverResponse.statusCode)); } }); }); } getByProcessId (processId, options) { const operationSettings = { "requiresBody": false, "queryParams": [], "isApplicationJson": false, "isFormUrlEncoded": false, "method": "GET" }; return getRequestOptions(operationSettings, options) .then((opts) => { const uri = `${this.host}/api/processes/${processId}`; const auth = opts.auth || this.auth; const headers = this.headers || {}; // Layer in some options local to this class const requestOpts = Object.assign({ headers }, opts, { auth, uri }); return doRequest(requestOpts).then(function (serverResponse) { switch (serverResponse.statusCode) { case 200: if (requestOpts.json) { return Promise.resolve(serverResponse.body); } else { return Promise.resolve(JSON.parse(serverResponse.body)); } default: return Promise.reject(new Error('Unknown response code: ' + serverResponse.statusCode)); } }); }); } postRetryByProcessId (processId, options) { const operationSettings = { "requiresBody": true, "queryParams": [], "isApplicationJson": false, "isFormUrlEncoded": true, "method": "POST" }; return getRequestOptions(operationSettings, options) .then((opts) => { const uri = `${this.host}/api/processes/${processId}/retry`; const auth = opts.auth || this.auth; const headers = this.headers || {}; // Layer in some options local to this class const requestOpts = Object.assign({ headers }, opts, { auth, uri }); return doRequest(requestOpts).then(function (serverResponse) { switch (serverResponse.statusCode) { case 204: return Promise.resolve(); default: return Promise.reject(new Error('Unknown response code: ' + serverResponse.statusCode)); } }); }); } postKillByProcessId (processId, options) { const operationSettings = { "requiresBody": true, "queryParams": [], "isApplicationJson": false, "isFormUrlEncoded": true, "method": "POST" }; return getRequestOptions(operationSettings, options) .then((opts) => { const uri = `${this.host}/api/processes/${processId}/kill`; const auth = opts.auth || this.auth; const headers = this.headers || {}; // Layer in some options local to this class const requestOpts = Object.assign({ headers }, opts, { auth, uri }); return doRequest(requestOpts).then(function (serverResponse) { switch (serverResponse.statusCode) { case 204: return Promise.resolve(); default: return Promise.reject(new Error('Unknown response code: ' + serverResponse.statusCode)); } }); }); } }