feat: Add dynamic fields structure to step arguments
This commit is contained in:
@@ -51,25 +51,20 @@ export default defineAction({
|
|||||||
value: false,
|
value: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
source: {
|
||||||
{
|
type: 'query',
|
||||||
label: 'Bot name',
|
name: 'getDynamicFields',
|
||||||
key: 'botName',
|
arguments: [
|
||||||
type: 'string' as const,
|
{
|
||||||
required: true,
|
name: 'key',
|
||||||
value: 'Automatisch',
|
value: 'listFieldsAfterSendAsBot',
|
||||||
description:
|
},
|
||||||
'Specify the bot name which appears as a bold username above the message inside Slack. Defaults to Automatisch.',
|
{
|
||||||
variables: true,
|
name: 'parameters.sendAsBot',
|
||||||
},
|
value: '{parameters.sendAsBot}',
|
||||||
{
|
},
|
||||||
label: 'Bot icon',
|
],
|
||||||
key: 'botIcon',
|
},
|
||||||
type: 'string' as const,
|
|
||||||
required: false,
|
|
||||||
description:
|
|
||||||
'Either an image url or an emoji available to your team (surrounded by :). For example, https://example.com/icon_256.png or :robot_face:',
|
|
||||||
variables: true,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
|
3
packages/backend/src/apps/slack/dynamic-fields/index.ts
Normal file
3
packages/backend/src/apps/slack/dynamic-fields/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import listFieldsAfterSendAsBot from './send-as-bot';
|
||||||
|
|
||||||
|
export default [listFieldsAfterSendAsBot];
|
@@ -0,0 +1,44 @@
|
|||||||
|
import { IGlobalVariable, IField, IJSONObject } from '@automatisch/types';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'List fields after send as bot',
|
||||||
|
key: 'listFieldsAfterSendAsBot',
|
||||||
|
|
||||||
|
async run($: IGlobalVariable) {
|
||||||
|
const sendAsBot = $.step.parameters.sendAsBot as boolean;
|
||||||
|
|
||||||
|
const remainingArguments: {
|
||||||
|
data: IJSONObject[];
|
||||||
|
error: IJSONObject | null;
|
||||||
|
} = {
|
||||||
|
data: [],
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (sendAsBot) {
|
||||||
|
remainingArguments.data = [
|
||||||
|
{
|
||||||
|
label: 'Bot name',
|
||||||
|
key: 'botName',
|
||||||
|
type: 'string' as const,
|
||||||
|
required: true,
|
||||||
|
value: 'Automatisch',
|
||||||
|
description:
|
||||||
|
'Specify the bot name which appears as a bold username above the message inside Slack. Defaults to Automatisch.',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Bot icon',
|
||||||
|
key: 'botIcon',
|
||||||
|
type: 'string' as const,
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'Either an image url or an emoji available to your team (surrounded by :). For example, https://example.com/icon_256.png or :robot_face:',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return remainingArguments;
|
||||||
|
},
|
||||||
|
};
|
@@ -3,6 +3,7 @@ import addAuthHeader from './common/add-auth-header';
|
|||||||
import actions from './actions';
|
import actions from './actions';
|
||||||
import auth from './auth';
|
import auth from './auth';
|
||||||
import dynamicData from './dynamic-data';
|
import dynamicData from './dynamic-data';
|
||||||
|
import dynamicFields from './dynamic-fields';
|
||||||
|
|
||||||
export default defineApp({
|
export default defineApp({
|
||||||
name: 'Slack',
|
name: 'Slack',
|
||||||
@@ -17,4 +18,5 @@ export default defineApp({
|
|||||||
auth,
|
auth,
|
||||||
actions,
|
actions,
|
||||||
dynamicData,
|
dynamicData,
|
||||||
|
dynamicFields,
|
||||||
});
|
});
|
||||||
|
53
packages/backend/src/graphql/queries/get-dynamic-fields.ts
Normal file
53
packages/backend/src/graphql/queries/get-dynamic-fields.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import { IDynamicFields, IJSONObject } from '@automatisch/types';
|
||||||
|
import Context from '../../types/express/context';
|
||||||
|
import App from '../../models/app';
|
||||||
|
import globalVariable from '../../helpers/global-variable';
|
||||||
|
|
||||||
|
type Params = {
|
||||||
|
stepId: string;
|
||||||
|
key: string;
|
||||||
|
parameters: IJSONObject;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getDynamicFields = async (
|
||||||
|
_parent: unknown,
|
||||||
|
params: Params,
|
||||||
|
context: Context
|
||||||
|
) => {
|
||||||
|
const step = await context.currentUser
|
||||||
|
.$relatedQuery('steps')
|
||||||
|
.withGraphFetched({
|
||||||
|
connection: true,
|
||||||
|
flow: true,
|
||||||
|
})
|
||||||
|
.findById(params.stepId);
|
||||||
|
|
||||||
|
if (!step) return null;
|
||||||
|
|
||||||
|
const connection = step.connection;
|
||||||
|
|
||||||
|
if (!connection || !step.appKey) return null;
|
||||||
|
|
||||||
|
const app = await App.findOneByKey(step.appKey);
|
||||||
|
const $ = await globalVariable({ connection, app, flow: step.flow, step });
|
||||||
|
|
||||||
|
const command = app.dynamicFields.find(
|
||||||
|
(data: IDynamicFields) => data.key === params.key
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const parameterKey in params.parameters) {
|
||||||
|
const parameterValue = params.parameters[parameterKey];
|
||||||
|
$.step.parameters[parameterKey] = parameterValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingArguments = await step.getSetupFields();
|
||||||
|
const remainingArguments = await command.run($);
|
||||||
|
|
||||||
|
if (remainingArguments.error) {
|
||||||
|
throw new Error(JSON.stringify(remainingArguments.error));
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...existingArguments, ...remainingArguments.data];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getDynamicFields;
|
@@ -9,6 +9,7 @@ import getExecution from './queries/get-execution';
|
|||||||
import getExecutions from './queries/get-executions';
|
import getExecutions from './queries/get-executions';
|
||||||
import getExecutionSteps from './queries/get-execution-steps';
|
import getExecutionSteps from './queries/get-execution-steps';
|
||||||
import getDynamicData from './queries/get-dynamic-data';
|
import getDynamicData from './queries/get-dynamic-data';
|
||||||
|
import getDynamicFields from './queries/get-dynamic-fields';
|
||||||
import getCurrentUser from './queries/get-current-user';
|
import getCurrentUser from './queries/get-current-user';
|
||||||
import getLicense from './queries/get-license.ee';
|
import getLicense from './queries/get-license.ee';
|
||||||
import healthcheck from './queries/healthcheck';
|
import healthcheck from './queries/healthcheck';
|
||||||
@@ -25,6 +26,7 @@ const queryResolvers = {
|
|||||||
getExecutions,
|
getExecutions,
|
||||||
getExecutionSteps,
|
getExecutionSteps,
|
||||||
getDynamicData,
|
getDynamicData,
|
||||||
|
getDynamicFields,
|
||||||
getCurrentUser,
|
getCurrentUser,
|
||||||
getLicense,
|
getLicense,
|
||||||
healthcheck,
|
healthcheck,
|
||||||
|
@@ -28,6 +28,11 @@ type Query {
|
|||||||
key: String!
|
key: String!
|
||||||
parameters: JSONObject
|
parameters: JSONObject
|
||||||
): JSONObject
|
): JSONObject
|
||||||
|
getDynamicFields(
|
||||||
|
stepId: String!
|
||||||
|
key: String!
|
||||||
|
parameters: JSONObject
|
||||||
|
): [Field]
|
||||||
getCurrentUser: User
|
getCurrentUser: User
|
||||||
getLicense: GetLicense
|
getLicense: GetLicense
|
||||||
healthcheck: AppHealth
|
healthcheck: AppHealth
|
||||||
|
@@ -149,6 +149,22 @@ class Step extends Base {
|
|||||||
|
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getSetupFields() {
|
||||||
|
let setupSupsteps;
|
||||||
|
|
||||||
|
if (this.isTrigger) {
|
||||||
|
setupSupsteps = (await this.getTriggerCommand()).substeps;
|
||||||
|
} else {
|
||||||
|
setupSupsteps = (await this.getActionCommand()).substeps;
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingArguments = setupSupsteps.find(
|
||||||
|
(substep) => substep.key === 'chooseTrigger'
|
||||||
|
).arguments;
|
||||||
|
|
||||||
|
return existingArguments;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Step;
|
export default Step;
|
||||||
|
5
packages/types/index.d.ts
vendored
5
packages/types/index.d.ts
vendored
@@ -167,6 +167,7 @@ export interface IApp {
|
|||||||
flowCount?: number;
|
flowCount?: number;
|
||||||
beforeRequest?: TBeforeRequest[];
|
beforeRequest?: TBeforeRequest[];
|
||||||
dynamicData?: IDynamicData;
|
dynamicData?: IDynamicData;
|
||||||
|
dynamicFields?: IDynamicFields;
|
||||||
triggers?: ITrigger[];
|
triggers?: ITrigger[];
|
||||||
actions?: IAction[];
|
actions?: IAction[];
|
||||||
connections?: IConnection[];
|
connections?: IConnection[];
|
||||||
@@ -180,6 +181,10 @@ export interface IDynamicData {
|
|||||||
[index: string]: any;
|
[index: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IDynamicFields {
|
||||||
|
[index: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IAuth {
|
export interface IAuth {
|
||||||
generateAuthUrl?($: IGlobalVariable): Promise<void>;
|
generateAuthUrl?($: IGlobalVariable): Promise<void>;
|
||||||
verifyCredentials?($: IGlobalVariable): Promise<void>;
|
verifyCredentials?($: IGlobalVariable): Promise<void>;
|
||||||
|
Reference in New Issue
Block a user