-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins): add deployment tool plugin
- Loading branch information
Showing
19 changed files
with
7,435 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"plugins": [ | ||
"@babel/plugin-proposal-class-properties" | ||
], | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", { | ||
"modules": false, | ||
"targets": { | ||
"electron": "6" | ||
} | ||
} | ||
], | ||
"@babel/preset-react" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"extends": [ | ||
"plugin:bpmn-io/es6", | ||
"plugin:bpmn-io/jsx", | ||
"plugin:bpmn-io/mocha" | ||
], | ||
"rules": { | ||
"import/first": "error", | ||
"import/no-amd": "error", | ||
"import/no-webpack-loader-syntax": "error", | ||
"react/jsx-uses-react": "error", | ||
"react/react-in-jsx-scope": "error" | ||
}, | ||
"plugins": [ | ||
"import" | ||
], | ||
"env": { | ||
"browser": true, | ||
"es6": true | ||
}, | ||
"settings": { | ||
"react": { | ||
"version": "16.4" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information regarding copyright | ||
* ownership. | ||
* | ||
* Camunda licenses this file to you under the MIT; you may not use this file | ||
* except in compliance with the MIT License. | ||
*/ | ||
|
||
const AuthTypes = { | ||
none: 'none', | ||
basic: 'basic', | ||
bearer: 'bearer' | ||
}; | ||
|
||
export default AuthTypes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/** | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information regarding copyright | ||
* ownership. | ||
* | ||
* Camunda licenses this file to you under the MIT; you may not use this file | ||
* except in compliance with the MIT License. | ||
*/ | ||
|
||
export default class CamundaAPI { | ||
constructor(baseUrl) { | ||
this.baseUrl = baseUrl; | ||
} | ||
|
||
async deployDiagram(diagram, details) { | ||
const { | ||
auth, | ||
deploymentName, | ||
tenantId | ||
} = details; | ||
|
||
const form = new FormData(); | ||
|
||
form.append('deployment-name', deploymentName); | ||
form.append('deployment-source', 'Camunda Modeler'); | ||
form.append('deploy-changed-only', 'true'); | ||
|
||
if (tenantId) { | ||
form.append('tenant-id', tenantId); | ||
} | ||
|
||
const diagramName = diagram.name; | ||
|
||
const blob = new Blob([ diagram.contents ], { type: 'text/xml' }); | ||
|
||
form.append(diagramName, blob, diagramName); | ||
|
||
const headers = this.getHeaders(auth); | ||
|
||
let response; | ||
|
||
try { | ||
response = await fetch(`${this.baseUrl}/deployment/create`, { | ||
method: 'POST', | ||
body: form, | ||
headers | ||
}); | ||
} catch (error) { | ||
response = { | ||
json: () => { | ||
return { message: 'Fetch failed' }; | ||
} | ||
}; | ||
|
||
console.error(error); | ||
} | ||
|
||
if (response.ok) { | ||
|
||
const { | ||
id, | ||
deployedProcessDefinitions | ||
} = await response.json(); | ||
|
||
return { | ||
id, | ||
deployedProcessDefinitions, | ||
deployedProcessDefinition: Object.values(deployedProcessDefinitions || {})[0] | ||
}; | ||
} | ||
|
||
const json = await response.json(); | ||
|
||
throw responseError('Deployment failed', response, json); | ||
} | ||
|
||
getHeaders(auth) { | ||
const headers = { | ||
accept: 'application/json' | ||
}; | ||
|
||
if (auth) { | ||
headers.authorization = this.getAuthHeader(auth); | ||
} | ||
|
||
return headers; | ||
} | ||
|
||
getAuthHeader({ bearer, username, password }) { | ||
if (bearer) { | ||
return `Bearer ${bearer}`; | ||
} | ||
|
||
if (username && password) { | ||
const credentials = window.btoa(`${username}:${password}`); | ||
|
||
return `Basic ${credentials}`; | ||
} | ||
|
||
throw new Error('Unknown auth options.'); | ||
} | ||
} | ||
|
||
|
||
|
||
// helpers ////////////// | ||
|
||
const parseError = 'ENGINE-09005 Could not parse BPMN process. Errors: \n*'; | ||
|
||
function responseError(message, response, details) { | ||
const error = new Error(message); | ||
|
||
error.details = details; | ||
error.response = response; | ||
|
||
// fix engine not exposing details | ||
if (details && details.message.startsWith(parseError)) { | ||
details.problems = details.message.substring(parseError.length).split(/\s?\n\*\s?/g); | ||
details.message = 'ENGINE-09005 Could not parse BPMN process'; | ||
} | ||
|
||
return error; | ||
} |
Oops, something went wrong.