feat: add websocket wizard foundation
This commit is contained in:
@@ -94,6 +94,7 @@ function loadStep(n, callback) {
|
||||
function step3PanelId() {
|
||||
if (wizardProtocol === 'graphql') return 'step-panel-3-graphql';
|
||||
if (wizardProtocol === 'grpc') return 'step-panel-3-grpc';
|
||||
if (wizardProtocol === 'websocket') return 'step-panel-3-websocket';
|
||||
if (wizardProtocol === 'soap') return 'step-panel-3-soap';
|
||||
return 'step-panel-3-rest';
|
||||
}
|
||||
@@ -103,6 +104,7 @@ var STEP3_LABELS = {
|
||||
rest: tKey('wizard.step3.rest.label'),
|
||||
graphql: tKey('wizard.step3.graphql.label'),
|
||||
grpc: tKey('wizard.step3.grpc.label'),
|
||||
websocket: tKey('wizard.step3.websocket.label'),
|
||||
soap: tKey('wizard.step3.soap.label'),
|
||||
};
|
||||
|
||||
@@ -217,6 +219,8 @@ function bindProtocolCards() {
|
||||
? 'graphql'
|
||||
: card.classList.contains('grpc')
|
||||
? 'grpc'
|
||||
: card.classList.contains('websocket')
|
||||
? 'websocket'
|
||||
: card.classList.contains('soap')
|
||||
? 'soap'
|
||||
: 'rest');
|
||||
@@ -1510,6 +1514,32 @@ function parseExecutionConfig(text) {
|
||||
useTls = !!value.tls.verify;
|
||||
}
|
||||
config.protocol_options = { grpc: { use_tls: useTls } };
|
||||
} else if (wizardProtocol === 'websocket') {
|
||||
var websocketProtocolOptions = value.protocol_options && value.protocol_options.websocket
|
||||
? value.protocol_options.websocket
|
||||
: {};
|
||||
var heartbeatInterval = websocketProtocolOptions.heartbeat_interval_ms != null
|
||||
? Number(websocketProtocolOptions.heartbeat_interval_ms)
|
||||
: numericValueOrNull('websocket-heartbeat-interval-ms');
|
||||
var reconnectAttempts = websocketProtocolOptions.reconnect_max_attempts != null
|
||||
? Number(websocketProtocolOptions.reconnect_max_attempts)
|
||||
: numericValueOrNull('websocket-reconnect-max-attempts');
|
||||
var reconnectBackoff = websocketProtocolOptions.reconnect_backoff_ms != null
|
||||
? Number(websocketProtocolOptions.reconnect_backoff_ms)
|
||||
: numericValueOrNull('websocket-reconnect-backoff-ms');
|
||||
var runtimeOptions = {};
|
||||
if (Number.isFinite(heartbeatInterval) && heartbeatInterval > 0) {
|
||||
runtimeOptions.heartbeat_interval_ms = heartbeatInterval;
|
||||
}
|
||||
if (Number.isFinite(reconnectAttempts) && reconnectAttempts >= 0) {
|
||||
runtimeOptions.reconnect_max_attempts = reconnectAttempts;
|
||||
}
|
||||
if (Number.isFinite(reconnectBackoff) && reconnectBackoff >= 0) {
|
||||
runtimeOptions.reconnect_backoff_ms = reconnectBackoff;
|
||||
}
|
||||
if (Object.keys(runtimeOptions).length) {
|
||||
config.protocol_options = { websocket: runtimeOptions };
|
||||
}
|
||||
}
|
||||
|
||||
config.streaming = collectStreamingConfig();
|
||||
@@ -1615,6 +1645,21 @@ function buildTarget() {
|
||||
};
|
||||
}
|
||||
|
||||
if (wizardProtocol === 'websocket') {
|
||||
return {
|
||||
kind: 'websocket',
|
||||
url: joinUrl(upstream.url, textValue('websocket-path')),
|
||||
subprotocols: textareaLines('websocket-subprotocols'),
|
||||
subscribe_message_template: stringValueOrNull('websocket-subscribe-template')
|
||||
? parseStructuredText(textValue('websocket-subscribe-template'))
|
||||
: null,
|
||||
unsubscribe_message_template: stringValueOrNull('websocket-unsubscribe-template')
|
||||
? parseStructuredText(textValue('websocket-unsubscribe-template'))
|
||||
: null,
|
||||
static_headers: parseHeaderMap(upstream.staticHeaders),
|
||||
};
|
||||
}
|
||||
|
||||
var route = textValue('grpc-manual-route') || (document.getElementById('grpc-path-value') ? document.getElementById('grpc-path-value').textContent.trim() : '');
|
||||
var descriptorRef = wizardCurrentVersion && wizardCurrentVersion.target && wizardCurrentVersion.target.kind === 'grpc'
|
||||
? wizardCurrentVersion.target.descriptor_ref
|
||||
@@ -1998,6 +2043,8 @@ function selectProtocol(protocol) {
|
||||
? 'graphql'
|
||||
: card.classList.contains('grpc')
|
||||
? 'grpc'
|
||||
: card.classList.contains('websocket')
|
||||
? 'websocket'
|
||||
: card.classList.contains('soap')
|
||||
? 'soap'
|
||||
: 'rest');
|
||||
@@ -2095,6 +2142,25 @@ function executionConfigToEditorValue(config) {
|
||||
if (config.protocol_options && config.protocol_options.grpc) {
|
||||
value.tls = { verify: !!config.protocol_options.grpc.use_tls };
|
||||
}
|
||||
if (config.protocol_options && config.protocol_options.websocket) {
|
||||
value.protocol_options = value.protocol_options || {};
|
||||
value.protocol_options.websocket = {};
|
||||
if (config.protocol_options.websocket.heartbeat_interval_ms != null) {
|
||||
value.protocol_options.websocket.heartbeat_interval_ms = config.protocol_options.websocket.heartbeat_interval_ms;
|
||||
}
|
||||
if (config.protocol_options.websocket.reconnect_max_attempts != null) {
|
||||
value.protocol_options.websocket.reconnect_max_attempts = config.protocol_options.websocket.reconnect_max_attempts;
|
||||
}
|
||||
if (config.protocol_options.websocket.reconnect_backoff_ms != null) {
|
||||
value.protocol_options.websocket.reconnect_backoff_ms = config.protocol_options.websocket.reconnect_backoff_ms;
|
||||
}
|
||||
if (!Object.keys(value.protocol_options.websocket).length) {
|
||||
delete value.protocol_options.websocket;
|
||||
}
|
||||
if (!Object.keys(value.protocol_options).length) {
|
||||
delete value.protocol_options;
|
||||
}
|
||||
}
|
||||
return window.jsyaml ? window.jsyaml.dump(value, { lineWidth: -1 }) : JSON.stringify(value, null, 2);
|
||||
}
|
||||
|
||||
@@ -2141,6 +2207,30 @@ function prefillWizardFromEdit(detail, versionDocument) {
|
||||
setValue('soap-action', target.soap_action || '');
|
||||
setValue('soap-version', target.soap_version || 'soap_11');
|
||||
setValue('soap-binding-style', target.binding_style || 'document_literal');
|
||||
} else if (target.kind === 'websocket') {
|
||||
prefillUpstream(
|
||||
target.url,
|
||||
target.static_headers || {},
|
||||
versionDocument.execution_config ? versionDocument.execution_config.auth_profile_ref : null
|
||||
);
|
||||
setValue('websocket-path', '');
|
||||
setValue('websocket-subprotocols', (target.subprotocols || []).join('\n'));
|
||||
setValue(
|
||||
'websocket-subscribe-template',
|
||||
target.subscribe_message_template ? JSON.stringify(target.subscribe_message_template, null, 2) : ''
|
||||
);
|
||||
setValue(
|
||||
'websocket-unsubscribe-template',
|
||||
target.unsubscribe_message_template ? JSON.stringify(target.unsubscribe_message_template, null, 2) : ''
|
||||
);
|
||||
var websocketOptions = versionDocument.execution_config
|
||||
&& versionDocument.execution_config.protocol_options
|
||||
&& versionDocument.execution_config.protocol_options.websocket
|
||||
? versionDocument.execution_config.protocol_options.websocket
|
||||
: null;
|
||||
setValue('websocket-heartbeat-interval-ms', websocketOptions && websocketOptions.heartbeat_interval_ms ? websocketOptions.heartbeat_interval_ms : '');
|
||||
setValue('websocket-reconnect-max-attempts', websocketOptions && websocketOptions.reconnect_max_attempts != null ? websocketOptions.reconnect_max_attempts : '');
|
||||
setValue('websocket-reconnect-backoff-ms', websocketOptions && websocketOptions.reconnect_backoff_ms ? websocketOptions.reconnect_backoff_ms : '');
|
||||
}
|
||||
|
||||
setValue('tool-name', detail.name);
|
||||
|
||||
Reference in New Issue
Block a user