@kumologica/sdk 3.6.0-beta3 → 3.6.0-beta4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21208,7 +21208,7 @@ RED.view.tools = (function() {
21208
21208
  RED.sidebar.info.init();
21209
21209
  RED.sidebar.test.init();
21210
21210
  RED.sidebar.git.init();
21211
- //RED.sidebar.kumohub.init();
21211
+ RED.sidebar.kumohub.init();
21212
21212
  RED.sidebar.azure.init();
21213
21213
  RED.sidebar.awsDeploy.init();
21214
21214
 
@@ -26730,7 +26730,833 @@ RED.sidebar.azure = (function () {
26730
26730
  init: init,
26731
26731
  show: show,
26732
26732
  };
26733
- })();;RED.palette = (function () {
26733
+ })();;RED.sidebar.kumohub = (function () {
26734
+ marked.setOptions({
26735
+ renderer: new marked.Renderer(),
26736
+ gfm: true,
26737
+ tables: true,
26738
+ breaks: false,
26739
+ pedantic: false,
26740
+ sanitize: true,
26741
+ smartLists: true,
26742
+ smartypants: false,
26743
+ });
26744
+
26745
+ var content;
26746
+ var sections;
26747
+ var functionSection;
26748
+ var environmentSection;
26749
+ var initialised = false;
26750
+ var parameters;
26751
+ var SELECT_KUMOHUB_PROFILE = 'Select Kumohub profile...';
26752
+ var DEFINE_KUMOHUB_PROFILE = 'Define Kumohub profile';
26753
+ let workspaces; // workspaces from kumohub.io
26754
+ // store for workspace, storage, policy from profile before kumohub login
26755
+ let profileWorkspace;
26756
+ let profileStage;
26757
+ let profilePolicy;
26758
+
26759
+ const DEPLOYING = 'DEPLOYING';
26760
+ const NOTDEPLOYING = 'NOTDEPLOYING';
26761
+ let deployState = NOTDEPLOYING;
26762
+
26763
+ function initCss() {
26764
+ $('<style>')
26765
+ .text(
26766
+ `
26767
+ select {
26768
+ outline: 1.5px solid #ccc;
26769
+ }
26770
+ select:focus {
26771
+ outline: 1.5px solid #ccc;
26772
+ outline-offset: 0px;
26773
+ }
26774
+ .invalid {
26775
+ border: 1px solid red;
26776
+ }
26777
+
26778
+ .valid {
26779
+ border: 1px solid green;
26780
+ }
26781
+ datalist {
26782
+ max-height: 300px;
26783
+ overflow-y: auto !important;
26784
+ }
26785
+ .editor-button-xsmall {
26786
+ height: 16px;
26787
+ min-width: 16px;
26788
+ line-height: 14px;
26789
+ font-size: 10px;
26790
+ border-radius: 2px;
26791
+ padding: 0 2px;
26792
+ }
26793
+ `
26794
+ )
26795
+ .appendTo(document.head);
26796
+ }
26797
+
26798
+ function initHTML() {
26799
+ initCss();
26800
+ content = document.createElement('div');
26801
+ content.className = 'sidebar-kumohub';
26802
+
26803
+ RED.actions.add('core:show-kumohub-tab', show);
26804
+
26805
+ var stackContainer = $('<div>', {
26806
+ class: 'sidebar-node-info-stack',
26807
+ }).appendTo(content);
26808
+
26809
+ let headerContentHtml = `
26810
+ <div class="sidebar-title-wrapper">
26811
+ <span>Deploy: Kumohub</span>
26812
+ </div>
26813
+ <div id="kumohub-sidebar-header" class="sidebar-header">
26814
+ <div id="kumohub-instrumentation" class="node-info">
26815
+ <div id="kumohub-profiles-wrapper">
26816
+ <span style="padding-left: 3px">Profiles</span>
26817
+ <select id="kumohub-sidebar-profiles" class="palette-textinput" style="padding: 0px;">
26818
+ <option value="Select Kumohub profile..." style="color:#3988CB !important">Click to select one...</option>
26819
+ </select>
26820
+ </div>
26821
+
26822
+ <div id="kumohub-wrapper">
26823
+ <!-- connect btn -->
26824
+ <div>
26825
+ <a id="kumohub-sidebar-connect-btn" class="sidebar-header-button" href="#">
26826
+ <i id="kumohub-sidebar-connect-icon" class="fa fa-circle" style="color: red"></i>
26827
+ Connect
26828
+ </a>
26829
+ </div>
26830
+
26831
+ <!-- deploy btn -->
26832
+ <div style="margin-right: 4px;">
26833
+ <a id="kumohub-sidebar-deploy-btn" class="sidebar-header-button" href="#">
26834
+ <i id="kumohub-sidebar-deploy-icon" class="fa fa-cloud-upload"></i>
26835
+ Deploy
26836
+ </a>
26837
+ </div>
26838
+
26839
+ <!-- export btn -->
26840
+ <div id="kumohub-options-dropdown">
26841
+ <a id="kumohub-sidebar-export-btn" class="sidebar-header-button" href="#">
26842
+ <i class="fa fa-ellipsis-h"></i>
26843
+ </a>
26844
+ </div>
26845
+ <div id="kumohub-options-dropdown-content">
26846
+ <span id="kumohub-buildZipBtn" class="option">Export as Zip</span>
26847
+ <!--span id="kumohub-exportServerlessBtn" class="option">Serverless</span-->
26848
+ </div>
26849
+ </div>
26850
+ </div>
26851
+ <table hidden id="kumohub-sidebar-error" class="node-info" style="margin: 0px;">
26852
+ <tr>
26853
+ <td style="border: 0px solid white; padding: 3px; width: 100%;">
26854
+ <p style="font-size: 12px; margin: 0px; text-align: center; color:red;"><span>Kumohub profile has not been configured</span></p>
26855
+ </td>
26856
+
26857
+ <td style="border: 0px solid white; padding: 3px;">
26858
+ <a id="kumohub-sidebar-error-help-btn" class="editor-button editor-button-xsmall" href="https://docs.kumologica.com/docs/guide/GettingStarted.html#installation" target="_blank">
26859
+ <i class="fa fa-question"></i>
26860
+ </a>
26861
+ </td>
26862
+
26863
+ <td style="border: 0px solid white; padding: 3px 6px 3px 3px;">
26864
+ <a id="kumohub-sidebar-error-close-btn" class="editor-button editor-button-xsmall" href="#">
26865
+ <i class="fa fa-times"></i></a>
26866
+ </td>
26867
+ </tr>
26868
+ </table>
26869
+ </div>
26870
+ `;
26871
+
26872
+ $(headerContentHtml).appendTo(stackContainer);
26873
+
26874
+ let bodyContainer = $(`<div id="kumohub-sidebar-body" style="display:none"></div>`);
26875
+ bodyContainer.appendTo(stackContainer);
26876
+
26877
+ sections = RED.stack
26878
+ .create({
26879
+ container: bodyContainer,
26880
+ })
26881
+ .hide();
26882
+
26883
+ // function section
26884
+ functionSection = sections.add({
26885
+ title: 'function',
26886
+ collapsible: true,
26887
+ });
26888
+ functionSection.expand();
26889
+
26890
+ // environment section
26891
+ environmentSection = sections.add({
26892
+ title: 'environment',
26893
+ collapsible: true,
26894
+ });
26895
+ //environmentSection.expand();
26896
+
26897
+ RED.sidebar.addTab({
26898
+ id: 'kumohub',
26899
+ label: 'Kumohub',
26900
+ name: 'Kumohub Deployer',
26901
+ iconClass: 'fa fa-cloud',
26902
+ action: 'core:show-kumohub-tab',
26903
+ content: content,
26904
+ pinned: true,
26905
+ enableOnEdit: true,
26906
+ onchange: onchange,
26907
+ onsame: onsame
26908
+ });
26909
+
26910
+ // Function content init
26911
+ let functionSectionHtml = `
26912
+ <table class="node-info">
26913
+ <tr class="node-info-node-row">
26914
+ <td>Service Name</td>
26915
+ <td colspan="2" style="background: white"><input style="width:100%" id="kumohub-fn-name" class="palette-textinput" pattern="[a-zA-Z0-9-_]{1,64}" type="text"></td>
26916
+ </tr>
26917
+ <tr class="node-info-node-row">
26918
+ <td>Description</td>
26919
+ <td colspan="2" style="background: white"><input style="width:100%" id="kumohub-fn-description" class="palette-textinput" type="text"></td>
26920
+ </tr>
26921
+ <tr class="node-info-node-row">
26922
+ <td>Memory (MB)</td>
26923
+ <td colspan="2" style="background: white"><input id="kumohub-fn-memory" class="palette-textinput" type="number" min="128" max="1536"></td>
26924
+ </tr>
26925
+ <tr class="node-info-node-row">
26926
+ <td>Timeout (s)</td>
26927
+ <td colspan="2" style="background: white"><input id="kumohub-fn-timeout" class="palette-textinput" type="number" min="5" max="900"></td>
26928
+ </tr>
26929
+ <tr class="node-info-node-row">
26930
+ <td>Workspace</td>
26931
+ <td colspan="2" style="background: white">
26932
+ <select type="text" class="palette-textinput" id="kumohub-fn-workspace" style="float: left; width: 100%; padding: 0px; outline: 0px solid #ccc; ">
26933
+ <option value="UNDEFINED" selected="true">Undefined</option>
26934
+ </select>
26935
+ </td>
26936
+ </tr>
26937
+
26938
+ <tr class="node-info-node-row">
26939
+ <td>Stage</td>
26940
+ <td colspan="2" style="background: white">
26941
+ <select type="text" class="palette-textinput" id="kumohub-fn-stage" style="float: left; width: 100%; padding: 0px; outline: 0px solid #ccc; ">
26942
+ <option value="UNDEFINED" selected="true">Undefined</option>
26943
+ </select>
26944
+ </td>
26945
+ </tr>
26946
+
26947
+ <tr class="node-info-node-row">
26948
+ <td>Policy</td>
26949
+ <td colspan="2" style="background: white">
26950
+ <select type="text" class="palette-textinput" id="kumohub-fn-policy" style="float: left; width: 100%; padding: 0px; outline: 0px solid #ccc; ">
26951
+ <option value="Public" selected="true">Public</option>
26952
+ </select>
26953
+ </td>
26954
+ </tr>
26955
+ </table>
26956
+ `;
26957
+ $(functionSectionHtml).appendTo(functionSection.content);
26958
+ functionSection.container.show();
26959
+
26960
+ // Environment section init
26961
+ let environmentSectionHtml = `
26962
+ <div style="display:flex; flex-direction: column; justify-content: flex-start;">
26963
+ <div style="display:flex; justify-content: flex-end; padding:6px">
26964
+ <a id="kumohub-add-environment-variable" href="#" class="editor-button editor-button-small red-ui-editableList-addButton">
26965
+ <i class="fa fa-plus"></i> Add
26966
+ </a>
26967
+ </div>
26968
+ <div id="kumohub-fn-env" style="display:flex; flex-direction: column">
26969
+ <table id="kumohub-fn-env-table" class="node-info" style="table-layout: fixed">
26970
+
26971
+ </table>
26972
+ </div>
26973
+ </div>
26974
+ `;
26975
+ $(environmentSectionHtml).appendTo(environmentSection.content);
26976
+ environmentSection.container.show();
26977
+
26978
+ // Tooltips
26979
+ RED.popover.tooltip($('#kumohub-sidebar-deploy-btn'), 'Deploy to Kumohub');
26980
+ RED.popover.tooltip($('#kumohub-options-dropdown'), 'Other Kumohub Operations');
26981
+ RED.popover.tooltip($('#kumohub-sidebar-connect-btn'), 'Connect to Kumohub');
26982
+ }
26983
+
26984
+ function onchange(){
26985
+ RED.actions.invoke('core:show-sidebar');
26986
+ }
26987
+
26988
+ function onsame(){
26989
+ RED.actions.invoke('core:hide-sidebar');
26990
+ }
26991
+
26992
+ function sanitizeLambdaName(name) {
26993
+ return name
26994
+ .replace('.json', '')
26995
+ .trim()
26996
+ .replace(/^@/, '')
26997
+ .replace(/[^a-zA-Z0-9-_]/g, '_')
26998
+ .substr(0, 140);
26999
+ }
27000
+
27001
+ function setLambdaName(name) {
27002
+ $('#kumohub-fn-name').val(sanitizeLambdaName(name));
27003
+ }
27004
+
27005
+ function setValues(params) {
27006
+ // storing for setting it up after login to kumohub
27007
+ profileWorkspace = params.workspace || params.account;
27008
+ profileStage = params.stage;
27009
+ profilePolicy = params.policy;
27010
+ console.log(`profile stored: ${profileWorkspace} - ${profileStage} - ${profilePolicy}`);
27011
+
27012
+ if (!initialised) {
27013
+ parameters = params;
27014
+ return;
27015
+ }
27016
+
27017
+ if (params && (params.name || params.functionName)) {
27018
+ setLambdaName(params.name || params.functionName || params["service-name"]);
27019
+ } else {
27020
+ if (window.__kumologica.settings.projectFlowName) {
27021
+ setLambdaName(window.__kumologica.settings.projectFlowName);
27022
+ }
27023
+ }
27024
+ if (!params) {
27025
+ return;
27026
+ }
27027
+ if (params.profile) {
27028
+ setProfile(params.profile);
27029
+ }
27030
+ if (params.description) {
27031
+ $('#kumohub-fn-description').val(params.description);
27032
+ }
27033
+ if (params.memory) {
27034
+ $('#kumohub-fn-memory').val(params.memory);
27035
+ }
27036
+ if (params.timeout) {
27037
+ $('#kumohub-fn-timeout').val(params.timeout);
27038
+ }
27039
+ if (params.account) {
27040
+ $('#kumohub-fn-workspace').val(params.workspace || params.account);
27041
+ fillStages(params.workspace || params.account);
27042
+ }
27043
+ if (params.workspace) {
27044
+ $('#kumohub-fn-workspace').val(params.workspace);
27045
+ fillStages(params.workspace);
27046
+ }
27047
+
27048
+ if (params.stage) {
27049
+ $('#kumohub-fn-stage').val(params.stage);
27050
+ }
27051
+ if (params.policy) {
27052
+ $('#kumohub-fn-policy').val(params.policy);
27053
+ }
27054
+
27055
+ if (params.environment && params.environment.length > 0) {
27056
+ let environmentTable = $('#kumohub-fn-env-table');
27057
+
27058
+ params.environment.forEach(function (e, i) {
27059
+ $(`
27060
+ <tr class="node-info-node-row">
27061
+ <td style="background: white; width:46%"><input id="kumohub-fn-env-key" class="palette-textinput" type="text" placeholder="key" style="width:100%" value="${e.key}"></td>
27062
+ <td style="background: white; width:46%"><input id="kumohub-fn-env-val" class="palette-textinput" type="text" placeholder="value" style="width:100%" value="${e.value}"></td>
27063
+ <td id="kumohub-fn-env-row" style="text-align:center; width:8%" class="removeRow"><i class="fa fa-minus"></i></td>
27064
+ </tr>`).appendTo(environmentTable);
27065
+ });
27066
+ }
27067
+ }
27068
+
27069
+ function getValues() {
27070
+ // Basic information
27071
+ let fnProfile = getProfile();
27072
+ let fnName = $('#kumohub-fn-name').val();
27073
+ let fnDescription = $('#kumohub-fn-description').val();
27074
+ let fnMemory = $('#kumohub-fn-memory').val();
27075
+ let fnTimeout = $('#kumohub-fn-timeout').val();
27076
+ let fnStage = $('#kumohub-fn-stage').val();
27077
+ let fnAccount = $('#kumohub-fn-account').val();
27078
+ let fnWorkspace = $('#kumohub-fn-workspace').val();
27079
+ let fnPolicy = $('#kumohub-fn-policy').val();
27080
+
27081
+ // Environment variables
27082
+ let environment = [];
27083
+ let envvarRows = $('#kumohub-fn-env-table tr');
27084
+
27085
+ envvarRows.map((index, row) => {
27086
+ let envvar = $(row).find('td').find('input');
27087
+ let key = $(envvar[0]).val();
27088
+ let value = $(envvar[1]).val();
27089
+ environment.push({ key, value });
27090
+ });
27091
+
27092
+ return {
27093
+ profile: fnProfile,
27094
+ "service-name": fnName,
27095
+ description: fnDescription,
27096
+ memory: fnMemory,
27097
+ timeout: fnTimeout,
27098
+ workspace: fnWorkspace || fnAccount,
27099
+ stage: fnStage,
27100
+ environment: environment,
27101
+ policy: fnPolicy
27102
+ };
27103
+ }
27104
+
27105
+ function fillWorkspaces() {
27106
+ let dropdown = $('#kumohub-fn-workspace');
27107
+
27108
+ if (workspaces.length > 0) {
27109
+ dropdown.empty();
27110
+ }
27111
+ workspaces.forEach(function (w) {
27112
+ dropdown.append($('<option></option>').val(w.name).text(w.name));
27113
+ });
27114
+
27115
+ if (profileWorkspace) {
27116
+ $('#kumohub-fn-workspace').val(profileWorkspace);
27117
+ fillStages(profileWorkspace);
27118
+ }
27119
+ }
27120
+
27121
+ function fillStages(fnWorkspace) {
27122
+
27123
+ let dropdown = $('#kumohub-fn-stage');
27124
+ if (fnWorkspace == "UNDEFINED") {
27125
+ //dropdown.append($('<option></option>').val("UNDEFINED").text("Undefined"));
27126
+ return;
27127
+ }
27128
+ let ws;
27129
+
27130
+ if (workspaces) {
27131
+ ws = workspaces.find(w => w.name === fnWorkspace);
27132
+ }
27133
+
27134
+ if (ws) {
27135
+ dropdown.empty();
27136
+ if (ws.stages && ws.stages.length > 0) {
27137
+ ws.stages.forEach(function (s) {
27138
+ dropdown.append($('<option></option>').val(s.name).text(s.name));
27139
+ });
27140
+ if (profileStage) {
27141
+ $('#kumohub-fn-stage').val(profileStage);
27142
+ fillPolicies(fnWorkspace, profileStage);
27143
+ }
27144
+ } else {
27145
+ dropdown.append($('<option></option>').val("UNDEFINED").text("Undefined"));
27146
+ }
27147
+
27148
+ }
27149
+ }
27150
+
27151
+ function fillPolicies(workspace, stage) {
27152
+
27153
+ let dropdown = $('#kumohub-fn-policy');
27154
+ if (workspace == "UNDEFINED") {
27155
+ //dropdown.append($('<option></option>').val("UNDEFINED").text("Undefined"));
27156
+ return;
27157
+ }
27158
+ let ws;
27159
+
27160
+ if (workspaces) {
27161
+ ws = workspaces.find(w => w.name === workspace);
27162
+ }
27163
+
27164
+ if (ws) {
27165
+ let st = ws.stages.find(s => s.name === stage);
27166
+ if (st && st.policies) {
27167
+ dropdown.empty();
27168
+
27169
+ if (st.policies && st.policies.length > 0) {
27170
+ st.policies.forEach(function (p) {
27171
+ dropdown.append($('<option></option>').val(p.name).text(p.name));
27172
+ });
27173
+ if (profilePolicy) {
27174
+ $('#kumohub-fn-policy').val(profilePolicy);
27175
+ }
27176
+ } else {
27177
+ dropdown.append($('<option></option>').val("Public").text("Public"));
27178
+ }
27179
+ }
27180
+ }
27181
+ }
27182
+
27183
+ function fillProfiles() {
27184
+ try {
27185
+ const profiles = window.__kumologica.kumohub.listProfiles();
27186
+ let dropdown = $('#kumohub-sidebar-profiles');
27187
+
27188
+ if (profiles.length > 0) {
27189
+ dropdown.empty();
27190
+ dropdown.append($('<option disabled>Available Kumohub Profiles</option>'));
27191
+ }
27192
+ profiles.forEach(function (profile) {
27193
+ dropdown.append($('<option></option>').val(profile).text(profile));
27194
+ });
27195
+
27196
+ // in case kumohub-config.json was loaded already and
27197
+ // setValues could not select correct profile, doing it now
27198
+ if (window.__kumologica.kumohub.profile) {
27199
+ setProfile(window.__kumologica.kumohub.profile);
27200
+ }
27201
+ } catch (Error) {
27202
+ console.log(`error: ${Error}`);
27203
+ showProfileError();
27204
+ }
27205
+ }
27206
+
27207
+ function getProfile() {
27208
+ return $('#kumohub-sidebar-profiles').find(':selected').val();
27209
+ }
27210
+
27211
+ function setProfile(profile) {
27212
+ window.__kumologica.kumohub.profile = profile;
27213
+
27214
+ // Show the body if profile is set to existing profile
27215
+ if (profile != SELECT_KUMOHUB_PROFILE &&
27216
+ $('#kumohub-sidebar-profiles').find('option[value=' + profile + ']').length) {
27217
+
27218
+ $(`#kumohub-sidebar-profiles option[value='${SELECT_KUMOHUB_PROFILE}']`).remove();
27219
+ $('#kumohub-sidebar-profiles').val(profile);
27220
+ } else {
27221
+ $('#kumohub-sidebar-profiles').val(SELECT_KUMOHUB_PROFILE);
27222
+ }
27223
+ }
27224
+
27225
+
27226
+ function showProfileError() {
27227
+ $('#kumohub-sidebar-error').show();
27228
+ }
27229
+
27230
+ RED.events.on('settings:cloud-config-changed', function() {
27231
+ fillProfiles();
27232
+ });
27233
+
27234
+ // event triggered when kumohub-config.json file has been loaded
27235
+ RED.events.on('kumohub-config', function () {
27236
+ if (!$('#kumohub-fn-name').val() &&
27237
+ window.__kumologica.settings.projectFlowName
27238
+ ) {
27239
+ setLambdaName(window.__kumologica.settings.projectFlowName);
27240
+ }
27241
+
27242
+ if (window.__kumologica.settings.kumohubConfig ) {
27243
+ const params = window.__kumologica.settings.kumohubConfig.getKumohubConfig();
27244
+
27245
+ setValues(params);
27246
+
27247
+ } else {
27248
+ console.log('kumologica.settings.kumohubConfig not present');
27249
+ }
27250
+ });
27251
+
27252
+ function initJs() {
27253
+ fillProfiles();
27254
+
27255
+ // Initialize fields with default values
27256
+ if (window.__kumologica.settings.projectFlowName) {
27257
+ setLambdaName(window.__kumologica.settings.projectFlowName);
27258
+ }
27259
+
27260
+ $('#kumohub-fn-description').val('kumologica flow');
27261
+ $('#kumohub-fn-memory').val('512');
27262
+ $('#kumohub-fn-timeout').val('20');
27263
+
27264
+ $('#kumohub-fn-timeout, #kumohub-fn-workspace, #kumohub-fn-stage, #kumohub-fn-policy, #kumohub-fn-memory, #kumohub-fn-description, #kumohub-fn-name').change(function () {
27265
+ saveSettings();
27266
+ });
27267
+
27268
+ $('#kumohub-fn-name').change(function () {
27269
+ this.value = sanitizeLambdaName(this.value);
27270
+ });
27271
+
27272
+ $('#kumohub-fn-workspace').on('change', function() {
27273
+ fillStages( this.value );
27274
+ });
27275
+
27276
+ $('#kumohub-fn-stage').on('change', function() {
27277
+ fillPolicies($('#kumohub-fn-workspace').val(), this.value);
27278
+ });
27279
+
27280
+ $('#kumohub-sidebar-profiles').change(function () {
27281
+
27282
+ if (this.value) {
27283
+ $('#kumohub-sidebar-body').show();
27284
+ }
27285
+ saveSettings();
27286
+
27287
+ if (this.value != SELECT_KUMOHUB_PROFILE) {
27288
+ $(`#kumohub-sidebar-profiles option[value='${SELECT_KUMOHUB_PROFILE}']`).remove();
27289
+ window.__kumologica.kumohub.profile = this.value;
27290
+ disconnectFromKumohub();
27291
+ }
27292
+ });
27293
+
27294
+ // Attach the environment variables
27295
+ $('#kumohub-add-environment-variable').click((e) => {
27296
+ let environmentTable = $('#kumohub-fn-env-table');
27297
+ let environmentRowHtml = `
27298
+ <tr class="node-info-node-row">
27299
+ <td style="background: white; width:46%"><input id="kumohub-fn-env-key" class="palette-textinput" type="text" placeholder="key" style="width:100%"></td>
27300
+ <td style="background: white; width:46%"><input id="kumohub-fn-env-val" class="palette-textinput" type="text" placeholder="value" style="width:100%"></td>
27301
+ <td id="kumohub-fn-env-row" style="text-align:center; width:8%" class="removeRow"><i class="fa fa-minus"></i></td>
27302
+ </tr>`;
27303
+ $(environmentRowHtml).appendTo(environmentTable);
27304
+
27305
+ $('#kumohub-fn-env-table')
27306
+ .find('input')
27307
+ .each(function () {
27308
+ $(this).change(function () {
27309
+ saveSettings();
27310
+ });
27311
+ });
27312
+ });
27313
+
27314
+ $('#kumohub-fn-env-table')
27315
+ .find('input')
27316
+ .each(function () {
27317
+ $(this).change(function () {
27318
+ saveSettings();
27319
+ });
27320
+ });
27321
+
27322
+ $('#kumohub-fn-env-table').on('click', '.removeRow', function () {
27323
+ $(this).parent().remove();
27324
+ saveSettings();
27325
+ });
27326
+
27327
+ // Close export menu when click in the window
27328
+ $('.sidebar-kumohub').click(function (e) {
27329
+ $('#kumohub-options-dropdown-content').hide();
27330
+ });
27331
+
27332
+ // Connect to AWS button
27333
+ $('#kumohub-sidebar-connect-btn').click((e) => {
27334
+ e.preventDefault();
27335
+ connectToKumohub();
27336
+ });
27337
+
27338
+ // Deploy to kumohub button
27339
+ $('#kumohub-sidebar-deploy-btn').click((e) => {
27340
+ e.preventDefault();
27341
+ deploy();
27342
+ });
27343
+
27344
+ $('#kumohub-buildZipBtn').click((e) => {
27345
+ e.preventDefault();
27346
+ hideMenu();
27347
+ buildZip();
27348
+ });
27349
+
27350
+ // Export cloudformation script
27351
+ $('#kumohub-exportCloudFormationBtn').click((e) => {
27352
+ e.preventDefault();
27353
+ hideMenu();
27354
+ exportScript(window.__kumologica.cloud.provider.aws);
27355
+ });
27356
+
27357
+ // Export serverless script
27358
+ $('#kumohub-exportServerlessBtn').click((e) => {
27359
+ e.preventDefault();
27360
+ hideMenu();
27361
+ exportScript(window.__kumologica.cloud.provider.serverless);
27362
+ });
27363
+
27364
+ $('#kumohub-options-dropdown').click((e) => {
27365
+ e.stopPropagation();
27366
+
27367
+ $('#kumohub-sidebar-export-btn').toggleClass('dropdown-selected');
27368
+
27369
+ $('#kumohub-options-dropdown-content').toggle();
27370
+ });
27371
+
27372
+ initialised = true;
27373
+ if (parameters) {
27374
+ setValues(parameters);
27375
+ }
27376
+
27377
+ connectUIDisconnected();
27378
+ }
27379
+
27380
+ function hideMenu() {
27381
+ $('#kumohub-sidebar-export-btn').removeClass('dropdown-selected');
27382
+ $('#kumohub-options-dropdown-content').hide();
27383
+ }
27384
+
27385
+ async function exportScript(provider) {
27386
+
27387
+ $('#workspace-terminal').show();
27388
+ try {
27389
+ await window.__kumologica.cloud.generateScript(
27390
+ provider,
27391
+ RED.header.getCurrentProjectInfo(),
27392
+ getValues()
27393
+ );
27394
+ } catch (Error) {
27395
+ handleError(Error);
27396
+ }
27397
+ }
27398
+
27399
+ async function buildZip(provider) {
27400
+
27401
+ $('#workspace-terminal').show();
27402
+ try {
27403
+ await window.__kumologica.kumohub.build(RED.header.getCurrentProjectInfo());
27404
+ /*await window.__kumologica.cloud.generateScript(
27405
+ provider,
27406
+ RED.header.getCurrentProjectInfo(),
27407
+ getValues()
27408
+ );*/
27409
+ } catch (Error) {
27410
+ handleError(Error);
27411
+ }
27412
+ }
27413
+
27414
+ async function connectToKumohub() {
27415
+ profile = getProfile();
27416
+
27417
+ if (!profile || profile == SELECT_KUMOHUB_PROFILE) {
27418
+ RED.notify(`<strong>Error</strong>: Please select Kumohub profile before connecting to Kumohub account.`, 'error');
27419
+ return;
27420
+ }
27421
+
27422
+ if (window.__kumologica.kumohub.isLoggedIn(profile)) {
27423
+ RED.notify(`<strong>Information</strong>: Already connected to ${profile} Kumohub account.`, 'info');
27424
+ return;
27425
+ }
27426
+
27427
+ connectUIConnecting();
27428
+
27429
+ try {
27430
+ await window.__kumologica.kumohub.login(profile);
27431
+ workspaces = await window.__kumologica.kumohub.getWorkspaces(profile);
27432
+
27433
+ fillWorkspaces(profileWorkspace);
27434
+ } catch (err) {
27435
+ connectUIDisconnected();
27436
+
27437
+ RED.notify(`<strong>Error</strong>: ${err.stderr? err.stderr: err}`, 'error');
27438
+ return;
27439
+ }
27440
+ connectUIConnected();
27441
+ }
27442
+
27443
+ function disconnectFromKumohub() {
27444
+ window.__kumologica.kumohub.logout();
27445
+ connectUIDisconnected();
27446
+ }
27447
+
27448
+ function connectUIDisconnected() {
27449
+ // show connect button
27450
+ $('#kumohub-sidebar-connect-btn').show();
27451
+ if ($('#kumohub-sidebar-connect-btn') && $('#kumohub-sidebar-connect-btn').html()) {
27452
+ $('#kumohub-sidebar-connect-btn').html($('#kumohub-sidebar-connect-btn').html().replace('Connecting', 'Connect'));
27453
+ }
27454
+ $('#kumohub-sidebar-connect-icon').attr({'class': 'fa fa-circle'});
27455
+ $('#kumohub-sidebar-connect-icon').css({'color': 'red'});
27456
+ // hide deploy and export buttons
27457
+ $('#kumohub-sidebar-deploy-btn').hide();
27458
+ $('#kumohub-sidebar-export-btn').hide();
27459
+ $('#kumohub-sidebar-body').hide();
27460
+ }
27461
+
27462
+ function connectUIConnecting() {
27463
+ $('#kumohub-sidebar-connect-icon').attr({'class': 'fa fa-spinner fa-spin'});
27464
+ $('#kumohub-sidebar-connect-icon').css({'color': 'black'});
27465
+ }
27466
+
27467
+ function connectUIConnected() {
27468
+ // hide connect button
27469
+ $('#kumohub-sidebar-connect-btn').hide();
27470
+ //$('#kumohub-sidebar-connect-btn').html($('#kumohub-sidebar-connect-btn').html().replace('Connect', 'Connected'));
27471
+ //$('#kumohub-sidebar-connect-icon').attr({'class': 'fa fa-circle'});
27472
+ //$('#kumohub-sidebar-connect-icon').css({'color': 'green'});
27473
+
27474
+ // show deploy and options buttons
27475
+ $('#kumohub-sidebar-deploy-btn').show();
27476
+
27477
+ // dont show until functionality implemented
27478
+ $('#kumohub-sidebar-export-btn').show();
27479
+ $('#kumohub-sidebar-body').show();
27480
+ }
27481
+
27482
+ function deployingUIDeploying() {
27483
+ $('#kumohub-sidebar-deploy-icon').attr({'class': 'fa fa-spinner fa-spin'});
27484
+ }
27485
+ function deployingUINotDeploying() {
27486
+ $('#kumohub-sidebar-deploy-icon').attr({'class': 'fa fa-cloud-upload'});
27487
+ }
27488
+
27489
+ async function deploy() {
27490
+
27491
+ const profile = getProfile();
27492
+ if (!profile || profile == SELECT_KUMOHUB_PROFILE) {
27493
+ RED.notify(`Please select kumohub profile before deploying flows.`, 'error');
27494
+ return;
27495
+ }
27496
+
27497
+ if (deployState == DEPLOYING) {
27498
+ RED.notify(`<strong>Information</strong>: Already deploying to Kumohub.`, 'info');
27499
+ return;
27500
+ }
27501
+
27502
+ RED.deploy.save();
27503
+
27504
+ deployingUIDeploying();
27505
+ deployState = DEPLOYING;
27506
+
27507
+ $('#workspace-terminal').show();
27508
+
27509
+ let params = getValues();
27510
+
27511
+ let envs = params.environment;
27512
+
27513
+ if (envs) {
27514
+ let variables = {Variables: {}};
27515
+
27516
+ envs.forEach(function(e) {
27517
+ variables.Variables[e.key] = e.value;
27518
+ });
27519
+ params.environment = {};
27520
+ params.environment = JSON.stringify(variables);
27521
+ };
27522
+
27523
+ try {
27524
+ await window.__kumologica.kumohub.deploy(
27525
+ RED.header.getCurrentProjectInfo(),
27526
+ params
27527
+ );
27528
+
27529
+ } catch (Error) {
27530
+ handleError(Error);
27531
+ }
27532
+
27533
+ deployState = NOTDEPLOYING;
27534
+ deployingUINotDeploying();
27535
+ }
27536
+
27537
+ function handleError(error) {
27538
+ let msg = error.toString();
27539
+ RED.notify(msg, 'error');
27540
+ }
27541
+
27542
+ function saveSettings() {
27543
+ window.__kumologica.settings.kumohubConfig.setKumohubConfig(getValues());
27544
+ }
27545
+
27546
+ function show() {
27547
+ RED.sidebar.show('kumohub');
27548
+ }
27549
+
27550
+ function init() {
27551
+ initHTML();
27552
+ initJs();
27553
+ }
27554
+
27555
+ return {
27556
+ init: init,
27557
+ show: show,
27558
+ };
27559
+ })();;RED.palette = (function () {
26734
27560
  const options = {
26735
27561
  nodes: {
26736
27562
  header: 'palette-option-nodes-a',