fix: Adjust info.json files to work with formattedData field
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
6a8ec97c31
commit
e73f33f3db
@@ -53,7 +53,7 @@
|
||||
"value": "{key}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -100,7 +100,7 @@
|
||||
"value": "{createConnection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -145,7 +145,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -192,7 +192,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
|
@@ -53,7 +53,7 @@
|
||||
"value": "{key}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -100,7 +100,7 @@
|
||||
"value": "{createConnection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -145,7 +145,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -192,7 +192,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
|
@@ -53,7 +53,7 @@
|
||||
"value": "{key}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -100,7 +100,7 @@
|
||||
"value": "{createConnection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -145,7 +145,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -192,7 +192,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
|
@@ -53,7 +53,7 @@
|
||||
"value": "{key}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -100,7 +100,7 @@
|
||||
"value": "{createConnection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -145,7 +145,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -192,7 +192,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
|
@@ -89,7 +89,7 @@
|
||||
"value": "{key}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -154,7 +154,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
|
@@ -89,7 +89,7 @@
|
||||
"value": "{key}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -154,7 +154,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
|
@@ -41,7 +41,7 @@
|
||||
"value": "{key}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -90,7 +90,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
|
@@ -53,7 +53,7 @@
|
||||
"value": "{key}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -100,7 +100,7 @@
|
||||
"value": "{createConnection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -145,7 +145,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -192,7 +192,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
|
@@ -53,7 +53,7 @@
|
||||
"value": "{key}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -100,7 +100,7 @@
|
||||
"value": "{createConnection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -145,7 +145,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -192,7 +192,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
|
@@ -53,7 +53,7 @@
|
||||
"value": "{key}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -100,7 +100,7 @@
|
||||
"value": "{createConnection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -145,7 +145,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
@@ -192,7 +192,7 @@
|
||||
"value": "{connection.id}"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"name": "formattedData",
|
||||
"value": null,
|
||||
"properties": [
|
||||
{
|
||||
|
@@ -5,7 +5,6 @@ import Processor from '../../services/processor';
|
||||
|
||||
type Params = {
|
||||
stepId: string;
|
||||
data: Record<string, unknown>;
|
||||
};
|
||||
const executeFlowResolver = async (
|
||||
params: Params,
|
||||
|
@@ -34,7 +34,7 @@ const updateConnection = {
|
||||
type: connectionType,
|
||||
args: {
|
||||
id: { type: GraphQLNonNull(GraphQLString) },
|
||||
data: { type: GraphQLNonNull(GraphQLJSONObject) },
|
||||
formattedData: { type: GraphQLNonNull(GraphQLJSONObject) },
|
||||
},
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) =>
|
||||
updateConnectionResolver(params, req),
|
||||
|
@@ -19,7 +19,7 @@ class Connection extends Base {
|
||||
|
||||
static jsonSchema = {
|
||||
type: 'object',
|
||||
required: ['key', 'data'],
|
||||
required: ['key'],
|
||||
|
||||
properties: {
|
||||
id: { type: 'string', format: 'uuid' },
|
||||
@@ -44,14 +44,18 @@ class Connection extends Base {
|
||||
|
||||
encryptData(): void {
|
||||
if (!this.eligibleForEncryption()) return;
|
||||
|
||||
this.data = AES.encrypt(
|
||||
JSON.stringify(this.formattedData),
|
||||
appConfig.encryptionKey
|
||||
).toString();
|
||||
|
||||
delete this['formattedData'];
|
||||
}
|
||||
|
||||
decryptData(): void {
|
||||
if (!this.eligibleForEncryption()) return;
|
||||
if (!this.eligibleForDecryption()) return;
|
||||
|
||||
this.formattedData = JSON.parse(
|
||||
AES.decrypt(this.data, appConfig.encryptionKey).toString(enc.Utf8)
|
||||
);
|
||||
@@ -61,6 +65,10 @@ class Connection extends Base {
|
||||
return this.formattedData ? true : false;
|
||||
}
|
||||
|
||||
eligibleForDecryption(): boolean {
|
||||
return this.data ? true : false;
|
||||
}
|
||||
|
||||
// TODO: Make another abstraction like beforeSave instead of using
|
||||
// beforeInsert and beforeUpdate separately for the same operation.
|
||||
async $beforeInsert(queryContext: QueryContext): Promise<void> {
|
||||
|
@@ -41,12 +41,19 @@ class Processor {
|
||||
key,
|
||||
type,
|
||||
parameters: rawParameters = {},
|
||||
id
|
||||
id,
|
||||
} = step;
|
||||
const isTrigger = type === 'trigger';
|
||||
const AppClass = (await import(`../apps/${appKey}`)).default;
|
||||
const computedParameters = Processor.computeParameters(rawParameters, priorExecutionSteps);
|
||||
const appInstance = new AppClass(appData, connection.data, computedParameters);
|
||||
const computedParameters = Processor.computeParameters(
|
||||
rawParameters,
|
||||
priorExecutionSteps
|
||||
);
|
||||
const appInstance = new AppClass(
|
||||
appData,
|
||||
connection.formattedData,
|
||||
computedParameters
|
||||
);
|
||||
const commands = isTrigger ? appInstance.triggers : appInstance.actions;
|
||||
const command = commands[key];
|
||||
fetchedData = await command.run();
|
||||
@@ -70,30 +77,35 @@ class Processor {
|
||||
return fetchedData;
|
||||
}
|
||||
|
||||
static computeParameters(parameters: Step["parameters"], executionSteps: ExecutionSteps): Step["parameters"] {
|
||||
static computeParameters(
|
||||
parameters: Step['parameters'],
|
||||
executionSteps: ExecutionSteps
|
||||
): Step['parameters'] {
|
||||
const entries = Object.entries(parameters);
|
||||
return entries.reduce((result, [key, value]: [string, string]) => {
|
||||
const parts = value.split(Processor.variableRegExp);
|
||||
|
||||
const computedValue = parts.map((part: string) => {
|
||||
const isVariable = part.match(Processor.variableRegExp);
|
||||
if (isVariable) {
|
||||
const stepIdAndKeyPath = part.replace(/{{step.|}}/g, '') as string;
|
||||
const [stepId, ...keyPaths] = stepIdAndKeyPath.split('.');
|
||||
const keyPath = keyPaths.join('.');
|
||||
const executionStep = executionSteps[stepId.toString() as string];
|
||||
const data = executionStep?.dataOut;
|
||||
const dataValue = get(data, keyPath);
|
||||
return dataValue;
|
||||
}
|
||||
const computedValue = parts
|
||||
.map((part: string) => {
|
||||
const isVariable = part.match(Processor.variableRegExp);
|
||||
if (isVariable) {
|
||||
const stepIdAndKeyPath = part.replace(/{{step.|}}/g, '') as string;
|
||||
const [stepId, ...keyPaths] = stepIdAndKeyPath.split('.');
|
||||
const keyPath = keyPaths.join('.');
|
||||
const executionStep = executionSteps[stepId.toString() as string];
|
||||
const data = executionStep?.dataOut;
|
||||
const dataValue = get(data, keyPath);
|
||||
return dataValue;
|
||||
}
|
||||
|
||||
return part;
|
||||
}).join('');
|
||||
return part;
|
||||
})
|
||||
.join('');
|
||||
|
||||
return {
|
||||
...result,
|
||||
[key]: computedValue,
|
||||
}
|
||||
};
|
||||
}, {});
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,11 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const CREATE_CONNECTION = gql`
|
||||
mutation CreateConnection($key: AvailableAppsEnumType!, $data: JSONObject!) {
|
||||
createConnection(key: $key, formattedData: $data) {
|
||||
mutation CreateConnection(
|
||||
$key: AvailableAppsEnumType!
|
||||
$formattedData: JSONObject!
|
||||
) {
|
||||
createConnection(key: $key, formattedData: $formattedData) {
|
||||
id
|
||||
key
|
||||
verified
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const UPDATE_CONNECTION = gql`
|
||||
mutation UpdateConnection($id: String!, $data: JSONObject!) {
|
||||
updateConnection(id: $id, data: $data) {
|
||||
mutation UpdateConnection($id: String!, $formattedData: JSONObject!) {
|
||||
updateConnection(id: $id, formattedData: $formattedData) {
|
||||
id
|
||||
key
|
||||
verified
|
||||
|
Reference in New Issue
Block a user