feat: add soap wizard foundation
This commit is contained in:
+243
-1
@@ -8,8 +8,11 @@ var wizardCurrentOperation = null;
|
||||
var wizardCurrentVersion = null;
|
||||
var wizardProtoUpload = null;
|
||||
var wizardDescriptorSetUpload = null;
|
||||
var wizardSoapWsdlUpload = null;
|
||||
var wizardSoapXsdUpload = null;
|
||||
var wizardTestResponsePreview = null;
|
||||
var grpcDescriptorServices = [];
|
||||
var soapServiceCatalog = [];
|
||||
var wizardProtocolCapabilities = null;
|
||||
function tKey(key) {
|
||||
return typeof t === 'function' ? t(key) : key;
|
||||
@@ -91,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 === 'soap') return 'step-panel-3-soap';
|
||||
return 'step-panel-3-rest';
|
||||
}
|
||||
|
||||
@@ -99,6 +103,7 @@ var STEP3_LABELS = {
|
||||
rest: tKey('wizard.step3.rest.label'),
|
||||
graphql: tKey('wizard.step3.graphql.label'),
|
||||
grpc: tKey('wizard.step3.grpc.label'),
|
||||
soap: tKey('wizard.step3.soap.label'),
|
||||
};
|
||||
|
||||
var CHECK_SVG = '<svg width="10" height="10"><use href="' + (window.APP_BASE||'') + 'icons/general/check.svg#icon"/></svg>';
|
||||
@@ -212,6 +217,8 @@ function bindProtocolCards() {
|
||||
? 'graphql'
|
||||
: card.classList.contains('grpc')
|
||||
? 'grpc'
|
||||
: card.classList.contains('soap')
|
||||
? 'soap'
|
||||
: 'rest');
|
||||
|
||||
wizardProtocol = proto;
|
||||
@@ -1586,6 +1593,28 @@ function buildTarget() {
|
||||
};
|
||||
}
|
||||
|
||||
if (wizardProtocol === 'soap') {
|
||||
var endpointOverride = textValue('soap-endpoint-override') || upstream.url;
|
||||
var existingWsdlRef = wizardCurrentVersion && wizardCurrentVersion.target && wizardCurrentVersion.target.kind === 'soap'
|
||||
? wizardCurrentVersion.target.wsdl_ref
|
||||
: 'sample_wsdl_pending';
|
||||
|
||||
return {
|
||||
kind: 'soap',
|
||||
wsdl_ref: existingWsdlRef,
|
||||
service_name: textValue('soap-service-name') || 'Service',
|
||||
port_name: textValue('soap-port-name') || 'Port',
|
||||
operation_name: textValue('soap-operation-name') || 'Operation',
|
||||
endpoint_override: endpointOverride || null,
|
||||
soap_version: textValue('soap-version') || 'soap_11',
|
||||
soap_action: textValue('soap-action') || null,
|
||||
binding_style: textValue('soap-binding-style') || 'document_literal',
|
||||
headers: [],
|
||||
fault_contract: null,
|
||||
metadata: { input_part_names: [], output_part_names: [], namespaces: [] },
|
||||
};
|
||||
}
|
||||
|
||||
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
|
||||
@@ -1963,7 +1992,15 @@ function selectProtocol(protocol) {
|
||||
wizardProtocol = protocol || 'rest';
|
||||
document.querySelectorAll('.protocol-card').forEach(function(card) {
|
||||
var proto = card.dataset.protocol
|
||||
|| (card.classList.contains('rest') ? 'rest' : card.classList.contains('graphql') ? 'graphql' : 'grpc');
|
||||
|| (card.classList.contains('rest')
|
||||
? 'rest'
|
||||
: card.classList.contains('graphql')
|
||||
? 'graphql'
|
||||
: card.classList.contains('grpc')
|
||||
? 'grpc'
|
||||
: card.classList.contains('soap')
|
||||
? 'soap'
|
||||
: 'rest');
|
||||
var selected = proto === wizardProtocol;
|
||||
card.classList.toggle('selected', selected);
|
||||
card.setAttribute('aria-checked', selected ? 'true' : 'false');
|
||||
@@ -2091,6 +2128,19 @@ function prefillWizardFromEdit(detail, versionDocument) {
|
||||
setValue('grpc-manual-res-type', '');
|
||||
grpcManualRouteInput(route);
|
||||
grpcManualTypeInput();
|
||||
} else if (target.kind === 'soap') {
|
||||
prefillUpstream(
|
||||
target.endpoint_override || '',
|
||||
{},
|
||||
versionDocument.execution_config ? versionDocument.execution_config.auth_profile_ref : null
|
||||
);
|
||||
setValue('soap-service-name', target.service_name || '');
|
||||
setValue('soap-port-name', target.port_name || '');
|
||||
setValue('soap-operation-name', target.operation_name || '');
|
||||
setValue('soap-endpoint-override', target.endpoint_override || '');
|
||||
setValue('soap-action', target.soap_action || '');
|
||||
setValue('soap-version', target.soap_version || 'soap_11');
|
||||
setValue('soap-binding-style', target.binding_style || 'document_literal');
|
||||
}
|
||||
|
||||
setValue('tool-name', detail.name);
|
||||
@@ -2123,6 +2173,15 @@ function bindWizardLiveActions() {
|
||||
if (input) input.click();
|
||||
});
|
||||
bindLiveAction('wizard-upload-descriptor-set', tKey('wizard.busy.descriptor'), uploadDescriptorSetAndDiscover);
|
||||
bindClick('wizard-select-soap-wsdl', function() {
|
||||
var input = document.getElementById('wizard-soap-wsdl-input');
|
||||
if (input) input.click();
|
||||
});
|
||||
bindClick('wizard-select-soap-xsd', function() {
|
||||
var input = document.getElementById('wizard-soap-xsd-input');
|
||||
if (input) input.click();
|
||||
});
|
||||
bindLiveAction('wizard-upload-soap-contracts', tKey('wizard.busy.wsdl'), uploadSoapArtifactsAndInspect);
|
||||
bindClick('wizard-import-yaml-file-trigger', function() {
|
||||
var input = document.getElementById('wizard-import-yaml-file');
|
||||
if (input) input.click();
|
||||
@@ -2130,6 +2189,10 @@ function bindWizardLiveActions() {
|
||||
|
||||
var descriptorInput = document.getElementById('wizard-descriptor-set-input');
|
||||
if (descriptorInput) descriptorInput.addEventListener('change', handleDescriptorSetSelection);
|
||||
var soapWsdlInput = document.getElementById('wizard-soap-wsdl-input');
|
||||
if (soapWsdlInput) soapWsdlInput.addEventListener('change', handleSoapWsdlSelection);
|
||||
var soapXsdInput = document.getElementById('wizard-soap-xsd-input');
|
||||
if (soapXsdInput) soapXsdInput.addEventListener('change', handleSoapXsdSelection);
|
||||
|
||||
var yamlInput = document.getElementById('wizard-import-yaml-file');
|
||||
if (yamlInput) yamlInput.addEventListener('change', handleImportYamlFileSelection);
|
||||
@@ -2290,6 +2353,44 @@ async function uploadPendingGrpcArtifacts(payload) {
|
||||
);
|
||||
}
|
||||
|
||||
async function uploadPendingSoapArtifacts(payload) {
|
||||
if (wizardProtocol !== 'soap' || !wizardEditId) return;
|
||||
|
||||
var wsdlResponse = null;
|
||||
if (wizardSoapWsdlUpload) {
|
||||
wsdlResponse = await window.CrankApi.uploadWsdlFile(
|
||||
wizardWorkspaceId,
|
||||
wizardEditId,
|
||||
wizardSoapWsdlUpload.bytes,
|
||||
wizardSoapWsdlUpload.fileName
|
||||
);
|
||||
wizardSoapWsdlUpload = null;
|
||||
var wsdlName = document.getElementById('wizard-soap-wsdl-name');
|
||||
if (wsdlName) wsdlName.textContent = tKey('wizard.step3.soap.wsdl_uploaded');
|
||||
}
|
||||
|
||||
if (wizardSoapXsdUpload) {
|
||||
await window.CrankApi.uploadXsdFile(
|
||||
wizardWorkspaceId,
|
||||
wizardEditId,
|
||||
wizardSoapXsdUpload.bytes,
|
||||
wizardSoapXsdUpload.fileName
|
||||
);
|
||||
wizardSoapXsdUpload = null;
|
||||
var xsdName = document.getElementById('wizard-soap-xsd-name');
|
||||
if (xsdName) xsdName.textContent = tKey('wizard.step3.soap.xsd_uploaded');
|
||||
}
|
||||
|
||||
if (!wsdlResponse) return;
|
||||
|
||||
payload.target.wsdl_ref = wsdlResponse.descriptor_id;
|
||||
await window.CrankApi.updateOperation(
|
||||
wizardWorkspaceId,
|
||||
wizardEditId,
|
||||
updateOperationPayload(payload)
|
||||
);
|
||||
}
|
||||
|
||||
async function persistCurrentDraft(stayOnPage) {
|
||||
if (!wizardWorkspaceId) {
|
||||
throw new Error(tKey('wizard.error.no_workspace'));
|
||||
@@ -2322,6 +2423,7 @@ async function persistCurrentDraft(stayOnPage) {
|
||||
}
|
||||
|
||||
await uploadPendingGrpcArtifacts(payload);
|
||||
await uploadPendingSoapArtifacts(payload);
|
||||
await refreshCurrentOperationState();
|
||||
|
||||
if (stayOnPage) {
|
||||
@@ -2487,6 +2589,38 @@ function handleDescriptorSetSelection(event) {
|
||||
reader.readAsArrayBuffer(file);
|
||||
}
|
||||
|
||||
function handleSoapWsdlSelection(event) {
|
||||
var file = event.target.files && event.target.files[0];
|
||||
if (!file) return;
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(loadEvent) {
|
||||
wizardSoapWsdlUpload = {
|
||||
fileName: file.name,
|
||||
bytes: new Uint8Array(loadEvent.target.result),
|
||||
};
|
||||
var fileNameEl = document.getElementById('wizard-soap-wsdl-name');
|
||||
if (fileNameEl) fileNameEl.textContent = file.name;
|
||||
showWizardLiveStatus(tKey('wizard.step3.soap.wsdl_selected'), tKey('wizard.step3.soap.wsdl_selected_body'));
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
}
|
||||
|
||||
function handleSoapXsdSelection(event) {
|
||||
var file = event.target.files && event.target.files[0];
|
||||
if (!file) return;
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(loadEvent) {
|
||||
wizardSoapXsdUpload = {
|
||||
fileName: file.name,
|
||||
bytes: new Uint8Array(loadEvent.target.result),
|
||||
};
|
||||
var fileNameEl = document.getElementById('wizard-soap-xsd-name');
|
||||
if (fileNameEl) fileNameEl.textContent = file.name;
|
||||
showWizardLiveStatus(tKey('wizard.step3.soap.xsd_selected'), tKey('wizard.step3.soap.xsd_selected_body'));
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
}
|
||||
|
||||
function renderDescriptorServiceList(services) {
|
||||
grpcDescriptorServices = services || [];
|
||||
var summaryEl = document.getElementById('wizard-descriptor-services-summary');
|
||||
@@ -2574,3 +2708,111 @@ async function uploadDescriptorSetAndDiscover() {
|
||||
renderDescriptorServiceList(services.services || []);
|
||||
showWizardLiveStatus(tKey('wizard.descriptor.discovered'), tKey('wizard.descriptor.discovered_body'));
|
||||
}
|
||||
|
||||
function renderSoapServiceCatalog(services) {
|
||||
soapServiceCatalog = services || [];
|
||||
var summaryEl = document.getElementById('wizard-soap-services-summary');
|
||||
var listEl = document.getElementById('wizard-soap-services-list');
|
||||
if (!summaryEl || !listEl) return;
|
||||
|
||||
var portCount = 0;
|
||||
var operationCount = 0;
|
||||
soapServiceCatalog.forEach(function(service) {
|
||||
portCount += (service.ports || []).length;
|
||||
(service.ports || []).forEach(function(port) {
|
||||
operationCount += (port.operations || []).length;
|
||||
});
|
||||
});
|
||||
|
||||
summaryEl.textContent = soapServiceCatalog.length
|
||||
? tfKey('wizard.step3.soap.services_discovered', {
|
||||
services: soapServiceCatalog.length,
|
||||
ports: portCount,
|
||||
operations: operationCount
|
||||
})
|
||||
: tKey('wizard.step3.soap.services_none');
|
||||
listEl.innerHTML = '';
|
||||
|
||||
soapServiceCatalog.forEach(function(service, serviceIndex) {
|
||||
var group = document.createElement('div');
|
||||
group.className = 'config-card';
|
||||
group.style.marginBottom = '0';
|
||||
|
||||
var body = document.createElement('div');
|
||||
body.className = 'config-card-body';
|
||||
body.style.padding = '16px';
|
||||
body.style.gap = '10px';
|
||||
|
||||
var title = document.createElement('div');
|
||||
title.className = 'config-card-title';
|
||||
title.textContent = service.service_name;
|
||||
body.appendChild(title);
|
||||
|
||||
(service.ports || []).forEach(function(port, portIndex) {
|
||||
var portLabel = document.createElement('div');
|
||||
portLabel.className = 'form-hint';
|
||||
portLabel.textContent = port.port_name + ' · ' + port.soap_version;
|
||||
body.appendChild(portLabel);
|
||||
|
||||
(port.operations || []).forEach(function(operation, operationIndex) {
|
||||
var button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'btn-ghost-sm';
|
||||
button.style.width = '100%';
|
||||
button.style.justifyContent = 'space-between';
|
||||
button.textContent = operation.operation_name;
|
||||
button.addEventListener('click', function() {
|
||||
applyDiscoveredSoapOperation(serviceIndex, portIndex, operationIndex);
|
||||
});
|
||||
body.appendChild(button);
|
||||
});
|
||||
});
|
||||
|
||||
group.appendChild(body);
|
||||
listEl.appendChild(group);
|
||||
});
|
||||
}
|
||||
|
||||
function applyDiscoveredSoapOperation(serviceIndex, portIndex, operationIndex) {
|
||||
var service = soapServiceCatalog[serviceIndex];
|
||||
var port = service && service.ports ? service.ports[portIndex] : null;
|
||||
var operation = port && port.operations ? port.operations[operationIndex] : null;
|
||||
if (!service || !port || !operation) return;
|
||||
|
||||
setValue('soap-service-name', service.service_name);
|
||||
setValue('soap-port-name', port.port_name);
|
||||
setValue('soap-operation-name', operation.operation_name);
|
||||
setValue('soap-version', port.soap_version || 'soap_11');
|
||||
setValue('soap-action', operation.soap_action || '');
|
||||
setValue('soap-binding-style', operation.binding_style || 'document_literal');
|
||||
if (!textValue('soap-endpoint-override') && port.endpoint) {
|
||||
setValue('soap-endpoint-override', port.endpoint);
|
||||
}
|
||||
|
||||
showWizardLiveStatus(tKey('wizard.step3.soap.applied'), tKey('wizard.step3.soap.applied_body'));
|
||||
}
|
||||
|
||||
async function uploadSoapArtifactsAndInspect() {
|
||||
var hasSavedWsdl = !!(
|
||||
wizardCurrentVersion
|
||||
&& wizardCurrentVersion.target
|
||||
&& wizardCurrentVersion.target.kind === 'soap'
|
||||
&& wizardCurrentVersion.target.wsdl_ref
|
||||
&& wizardCurrentVersion.target.wsdl_ref !== 'sample_wsdl_pending'
|
||||
);
|
||||
|
||||
if (!wizardSoapWsdlUpload && !hasSavedWsdl) {
|
||||
showWizardLiveStatus(tKey('wizard.step3.soap.no_wsdl_error'), tKey('wizard.step3.soap.no_wsdl_error_body'), true);
|
||||
return;
|
||||
}
|
||||
|
||||
await persistCurrentDraft(true);
|
||||
|
||||
var services = await window.CrankApi.listSoapServices(
|
||||
wizardWorkspaceId,
|
||||
wizardEditId,
|
||||
currentDraftVersion()
|
||||
);
|
||||
renderSoapServiceCatalog(services.services || []);
|
||||
showWizardLiveStatus(tKey('wizard.step3.soap.discovered'), tKey('wizard.step3.soap.discovered_body'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user