fix: Adjust info.json files to work with formattedData field

This commit is contained in:
Faruk AYDIN
2022-03-05 01:03:58 +03:00
committed by Ömer Faruk Aydın
parent 6a8ec97c31
commit e73f33f3db
16 changed files with 82 additions and 60 deletions

View File

@@ -53,7 +53,7 @@
"value": "{key}" "value": "{key}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -100,7 +100,7 @@
"value": "{createConnection.id}" "value": "{createConnection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -145,7 +145,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -192,7 +192,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {

View File

@@ -53,7 +53,7 @@
"value": "{key}" "value": "{key}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -100,7 +100,7 @@
"value": "{createConnection.id}" "value": "{createConnection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -145,7 +145,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -192,7 +192,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {

View File

@@ -53,7 +53,7 @@
"value": "{key}" "value": "{key}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -100,7 +100,7 @@
"value": "{createConnection.id}" "value": "{createConnection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -145,7 +145,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -192,7 +192,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {

View File

@@ -53,7 +53,7 @@
"value": "{key}" "value": "{key}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -100,7 +100,7 @@
"value": "{createConnection.id}" "value": "{createConnection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -145,7 +145,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -192,7 +192,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {

View File

@@ -89,7 +89,7 @@
"value": "{key}" "value": "{key}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -154,7 +154,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {

View File

@@ -89,7 +89,7 @@
"value": "{key}" "value": "{key}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -154,7 +154,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {

View File

@@ -41,7 +41,7 @@
"value": "{key}" "value": "{key}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -90,7 +90,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {

View File

@@ -53,7 +53,7 @@
"value": "{key}" "value": "{key}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -100,7 +100,7 @@
"value": "{createConnection.id}" "value": "{createConnection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -145,7 +145,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -192,7 +192,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {

View File

@@ -53,7 +53,7 @@
"value": "{key}" "value": "{key}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -100,7 +100,7 @@
"value": "{createConnection.id}" "value": "{createConnection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -145,7 +145,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -192,7 +192,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {

View File

@@ -53,7 +53,7 @@
"value": "{key}" "value": "{key}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -100,7 +100,7 @@
"value": "{createConnection.id}" "value": "{createConnection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -145,7 +145,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {
@@ -192,7 +192,7 @@
"value": "{connection.id}" "value": "{connection.id}"
}, },
{ {
"name": "data", "name": "formattedData",
"value": null, "value": null,
"properties": [ "properties": [
{ {

View File

@@ -5,7 +5,6 @@ import Processor from '../../services/processor';
type Params = { type Params = {
stepId: string; stepId: string;
data: Record<string, unknown>;
}; };
const executeFlowResolver = async ( const executeFlowResolver = async (
params: Params, params: Params,

View File

@@ -34,7 +34,7 @@ const updateConnection = {
type: connectionType, type: connectionType,
args: { args: {
id: { type: GraphQLNonNull(GraphQLString) }, id: { type: GraphQLNonNull(GraphQLString) },
data: { type: GraphQLNonNull(GraphQLJSONObject) }, formattedData: { type: GraphQLNonNull(GraphQLJSONObject) },
}, },
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => resolve: (_: any, params: Params, req: RequestWithCurrentUser) =>
updateConnectionResolver(params, req), updateConnectionResolver(params, req),

View File

@@ -19,7 +19,7 @@ class Connection extends Base {
static jsonSchema = { static jsonSchema = {
type: 'object', type: 'object',
required: ['key', 'data'], required: ['key'],
properties: { properties: {
id: { type: 'string', format: 'uuid' }, id: { type: 'string', format: 'uuid' },
@@ -44,14 +44,18 @@ class Connection extends Base {
encryptData(): void { encryptData(): void {
if (!this.eligibleForEncryption()) return; if (!this.eligibleForEncryption()) return;
this.data = AES.encrypt( this.data = AES.encrypt(
JSON.stringify(this.formattedData), JSON.stringify(this.formattedData),
appConfig.encryptionKey appConfig.encryptionKey
).toString(); ).toString();
delete this['formattedData'];
} }
decryptData(): void { decryptData(): void {
if (!this.eligibleForEncryption()) return; if (!this.eligibleForDecryption()) return;
this.formattedData = JSON.parse( this.formattedData = JSON.parse(
AES.decrypt(this.data, appConfig.encryptionKey).toString(enc.Utf8) AES.decrypt(this.data, appConfig.encryptionKey).toString(enc.Utf8)
); );
@@ -61,6 +65,10 @@ class Connection extends Base {
return this.formattedData ? true : false; return this.formattedData ? true : false;
} }
eligibleForDecryption(): boolean {
return this.data ? true : false;
}
// TODO: Make another abstraction like beforeSave instead of using // TODO: Make another abstraction like beforeSave instead of using
// beforeInsert and beforeUpdate separately for the same operation. // beforeInsert and beforeUpdate separately for the same operation.
async $beforeInsert(queryContext: QueryContext): Promise<void> { async $beforeInsert(queryContext: QueryContext): Promise<void> {

View File

@@ -41,12 +41,19 @@ class Processor {
key, key,
type, type,
parameters: rawParameters = {}, parameters: rawParameters = {},
id id,
} = step; } = step;
const isTrigger = type === 'trigger'; const isTrigger = type === 'trigger';
const AppClass = (await import(`../apps/${appKey}`)).default; const AppClass = (await import(`../apps/${appKey}`)).default;
const computedParameters = Processor.computeParameters(rawParameters, priorExecutionSteps); const computedParameters = Processor.computeParameters(
const appInstance = new AppClass(appData, connection.data, computedParameters); rawParameters,
priorExecutionSteps
);
const appInstance = new AppClass(
appData,
connection.formattedData,
computedParameters
);
const commands = isTrigger ? appInstance.triggers : appInstance.actions; const commands = isTrigger ? appInstance.triggers : appInstance.actions;
const command = commands[key]; const command = commands[key];
fetchedData = await command.run(); fetchedData = await command.run();
@@ -70,12 +77,16 @@ class Processor {
return fetchedData; 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); const entries = Object.entries(parameters);
return entries.reduce((result, [key, value]: [string, string]) => { return entries.reduce((result, [key, value]: [string, string]) => {
const parts = value.split(Processor.variableRegExp); const parts = value.split(Processor.variableRegExp);
const computedValue = parts.map((part: string) => { const computedValue = parts
.map((part: string) => {
const isVariable = part.match(Processor.variableRegExp); const isVariable = part.match(Processor.variableRegExp);
if (isVariable) { if (isVariable) {
const stepIdAndKeyPath = part.replace(/{{step.|}}/g, '') as string; const stepIdAndKeyPath = part.replace(/{{step.|}}/g, '') as string;
@@ -88,12 +99,13 @@ class Processor {
} }
return part; return part;
}).join(''); })
.join('');
return { return {
...result, ...result,
[key]: computedValue, [key]: computedValue,
} };
}, {}); }, {});
} }
} }

View File

@@ -1,8 +1,11 @@
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const CREATE_CONNECTION = gql` export const CREATE_CONNECTION = gql`
mutation CreateConnection($key: AvailableAppsEnumType!, $data: JSONObject!) { mutation CreateConnection(
createConnection(key: $key, formattedData: $data) { $key: AvailableAppsEnumType!
$formattedData: JSONObject!
) {
createConnection(key: $key, formattedData: $formattedData) {
id id
key key
verified verified

View File

@@ -1,8 +1,8 @@
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const UPDATE_CONNECTION = gql` export const UPDATE_CONNECTION = gql`
mutation UpdateConnection($id: String!, $data: JSONObject!) { mutation UpdateConnection($id: String!, $formattedData: JSONObject!) {
updateConnection(id: $id, data: $data) { updateConnection(id: $id, formattedData: $formattedData) {
id id
key key
verified verified