feat(useAuthenticateApp): use REST API endpoint to reset connection

This commit is contained in:
Ali BARIN
2024-09-24 11:40:35 +00:00
parent bc0e18d074
commit 5e6f4bfb88
4 changed files with 34 additions and 59 deletions

View File

@@ -27,12 +27,7 @@ const authenticationStepsWithoutAuthUrl = [
{
type: 'mutation',
name: 'verifyConnection',
arguments: [
{
name: 'id',
value: '{createConnection.id}',
},
],
arguments: [],
},
];
@@ -79,12 +74,7 @@ const authenticationStepsWithAuthUrl = [
{
type: 'mutation',
name: 'verifyConnection',
arguments: [
{
name: 'id',
value: '{createConnection.id}',
},
],
arguments: [],
},
];
@@ -131,12 +121,7 @@ const sharedAuthenticationStepsWithAuthUrl = [
{
type: 'mutation',
name: 'verifyConnection',
arguments: [
{
name: 'id',
value: '{createConnection.id}',
},
],
arguments: [],
},
];

View File

@@ -1,54 +1,23 @@
import cloneDeep from 'lodash/cloneDeep.js';
const connectionIdArgument = {
name: 'id',
value: '{connection.id}',
};
const resetConnectionStep = {
type: 'mutation',
name: 'resetConnection',
arguments: [connectionIdArgument],
arguments: [],
};
function replaceCreateConnection(string) {
return string.replace('{createConnection.id}', '{connection.id}');
}
function removeAppKeyArgument(args) {
return args.filter((argument) => argument.name !== 'key');
}
function addConnectionId(step) {
step.arguments = step.arguments.map((argument) => {
if (typeof argument.value === 'string') {
argument.value = replaceCreateConnection(argument.value);
}
if (argument.properties) {
argument.properties = argument.properties.map((property) => {
return {
name: property.name,
value: replaceCreateConnection(property.value),
};
});
}
return argument;
});
return step;
}
function replaceCreateConnectionsWithUpdate(steps) {
const updatedSteps = cloneDeep(steps);
return updatedSteps.map((step) => {
const updatedStep = addConnectionId(step);
const updatedStep = { ...step };
if (step.name === 'createConnection') {
updatedStep.name = 'updateConnection';
updatedStep.arguments = removeAppKeyArgument(updatedStep.arguments);
updatedStep.arguments.unshift(connectionIdArgument);
return updatedStep;
}