mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix lint
This commit is contained in:
@@ -22,7 +22,7 @@ export enum ComponentInputType {
|
||||
BaseModelArray = 'Database Records',
|
||||
JSONArray = 'List of JSON',
|
||||
LongText = 'Long Text',
|
||||
HTML = 'HTML'
|
||||
HTML = 'HTML',
|
||||
}
|
||||
|
||||
export enum ComponentType {
|
||||
|
||||
@@ -12,7 +12,7 @@ enum ComponentID {
|
||||
ApiPost = 'api-get',
|
||||
ApiDelete = 'api-get',
|
||||
SendEmail = 'send-email',
|
||||
IfElse = 'if-else'
|
||||
IfElse = 'if-else',
|
||||
}
|
||||
|
||||
export default ComponentID;
|
||||
|
||||
@@ -28,7 +28,8 @@ const components: Array<ComponentMetadata> = [
|
||||
description: 'Request Body in JSON',
|
||||
type: ComponentInputType.JSON,
|
||||
required: false,
|
||||
placeholder: 'Example: {"key1": "value1", "key2": "value2", ....}',
|
||||
placeholder:
|
||||
'Example: {"key1": "value1", "key2": "value2", ....}',
|
||||
},
|
||||
{
|
||||
id: 'query-string',
|
||||
@@ -37,7 +38,8 @@ const components: Array<ComponentMetadata> = [
|
||||
type: ComponentInputType.StringDictionary,
|
||||
required: false,
|
||||
isAdvanced: true,
|
||||
placeholder: 'Example: {"query1": "value1", "query2": "value2", ....}',
|
||||
placeholder:
|
||||
'Example: {"query1": "value1", "query2": "value2", ....}',
|
||||
},
|
||||
{
|
||||
id: 'request-headers',
|
||||
@@ -46,7 +48,8 @@ const components: Array<ComponentMetadata> = [
|
||||
type: ComponentInputType.StringDictionary,
|
||||
required: false,
|
||||
isAdvanced: true,
|
||||
placeholder: 'Example: {"header1": "value1", "header2": "value2", ....}',
|
||||
placeholder:
|
||||
'Example: {"header1": "value1", "header2": "value2", ....}',
|
||||
},
|
||||
],
|
||||
returnValues: [
|
||||
@@ -123,7 +126,8 @@ const components: Array<ComponentMetadata> = [
|
||||
description: 'Request Body in JSON',
|
||||
type: ComponentInputType.JSON,
|
||||
required: false,
|
||||
placeholder: 'Example: {"key1": "value1", "key2": "value2", ....}',
|
||||
placeholder:
|
||||
'Example: {"key1": "value1", "key2": "value2", ....}',
|
||||
},
|
||||
{
|
||||
id: 'query-string',
|
||||
@@ -132,7 +136,8 @@ const components: Array<ComponentMetadata> = [
|
||||
type: ComponentInputType.StringDictionary,
|
||||
required: false,
|
||||
isAdvanced: true,
|
||||
placeholder: 'Example: {"query1": "value1", "query2": "value2", ....}',
|
||||
placeholder:
|
||||
'Example: {"query1": "value1", "query2": "value2", ....}',
|
||||
},
|
||||
{
|
||||
id: 'request-headers',
|
||||
@@ -141,7 +146,8 @@ const components: Array<ComponentMetadata> = [
|
||||
type: ComponentInputType.StringDictionary,
|
||||
required: false,
|
||||
isAdvanced: true,
|
||||
placeholder: 'Example: {"header1": "value1", "header2": "value2", ....}',
|
||||
placeholder:
|
||||
'Example: {"header1": "value1", "header2": "value2", ....}',
|
||||
},
|
||||
],
|
||||
returnValues: [
|
||||
@@ -218,7 +224,8 @@ const components: Array<ComponentMetadata> = [
|
||||
description: 'Request Body in JSON',
|
||||
type: ComponentInputType.JSON,
|
||||
required: false,
|
||||
placeholder: 'Example: {"key1": "value1", "key2": "value2", ....}',
|
||||
placeholder:
|
||||
'Example: {"key1": "value1", "key2": "value2", ....}',
|
||||
},
|
||||
{
|
||||
id: 'query-string',
|
||||
@@ -227,7 +234,8 @@ const components: Array<ComponentMetadata> = [
|
||||
type: ComponentInputType.StringDictionary,
|
||||
required: false,
|
||||
isAdvanced: true,
|
||||
placeholder: 'Example: {"query1": "value1", "query2": "value2", ....}',
|
||||
placeholder:
|
||||
'Example: {"query1": "value1", "query2": "value2", ....}',
|
||||
},
|
||||
{
|
||||
id: 'request-headers',
|
||||
@@ -236,7 +244,8 @@ const components: Array<ComponentMetadata> = [
|
||||
type: ComponentInputType.StringDictionary,
|
||||
required: false,
|
||||
isAdvanced: true,
|
||||
placeholder: 'Example: {"header1": "value1", "header2": "value2", ....}',
|
||||
placeholder:
|
||||
'Example: {"header1": "value1", "header2": "value2", ....}',
|
||||
},
|
||||
],
|
||||
returnValues: [
|
||||
@@ -313,7 +322,8 @@ const components: Array<ComponentMetadata> = [
|
||||
description: 'Request Body in JSON',
|
||||
type: ComponentInputType.JSON,
|
||||
required: false,
|
||||
placeholder: 'Example: {"key1": "value1", "key2": "value2", ....}',
|
||||
placeholder:
|
||||
'Example: {"key1": "value1", "key2": "value2", ....}',
|
||||
},
|
||||
{
|
||||
id: 'query-string',
|
||||
@@ -322,7 +332,8 @@ const components: Array<ComponentMetadata> = [
|
||||
type: ComponentInputType.StringDictionary,
|
||||
required: false,
|
||||
isAdvanced: true,
|
||||
placeholder: 'Example: {"query1": "value1", "query2": "value2", ....}',
|
||||
placeholder:
|
||||
'Example: {"query1": "value1", "query2": "value2", ....}',
|
||||
},
|
||||
{
|
||||
id: 'request-headers',
|
||||
@@ -331,7 +342,8 @@ const components: Array<ComponentMetadata> = [
|
||||
type: ComponentInputType.StringDictionary,
|
||||
required: false,
|
||||
isAdvanced: true,
|
||||
placeholder: 'Example: {"header1": "value1", "header2": "value2", ....}',
|
||||
placeholder:
|
||||
'Example: {"header1": "value1", "header2": "value2", ....}',
|
||||
},
|
||||
],
|
||||
returnValues: [
|
||||
|
||||
@@ -30,7 +30,7 @@ export default class BaseModelComponent {
|
||||
description: `Query on ${model.singularName}`,
|
||||
required: true,
|
||||
id: 'query',
|
||||
placeholder: "Example: {'columnName': 'value', ...}"
|
||||
placeholder: "Example: {'columnName': 'value', ...}",
|
||||
},
|
||||
{
|
||||
type: ComponentInputType.Query,
|
||||
@@ -38,7 +38,7 @@ export default class BaseModelComponent {
|
||||
description: `Select on ${model.singularName}`,
|
||||
required: true,
|
||||
id: 'select',
|
||||
placeholder: "Example: {'columnName': true, ...}"
|
||||
placeholder: "Example: {'columnName': true, ...}",
|
||||
},
|
||||
],
|
||||
returnValues: [
|
||||
@@ -89,7 +89,7 @@ export default class BaseModelComponent {
|
||||
description: 'Please fill out this query',
|
||||
required: true,
|
||||
id: 'query',
|
||||
placeholder: "Example: {'columnName': 'value', ...}"
|
||||
placeholder: "Example: {'columnName': 'value', ...}",
|
||||
},
|
||||
{
|
||||
type: ComponentInputType.Query,
|
||||
@@ -97,7 +97,7 @@ export default class BaseModelComponent {
|
||||
description: `Select on ${model.singularName}`,
|
||||
required: true,
|
||||
id: 'select',
|
||||
placeholder: "Example: {'columnName': true, ...}"
|
||||
placeholder: "Example: {'columnName': true, ...}",
|
||||
},
|
||||
{
|
||||
type: ComponentInputType.Number,
|
||||
@@ -193,7 +193,7 @@ export default class BaseModelComponent {
|
||||
description: 'Please fill out this query',
|
||||
required: true,
|
||||
id: 'query',
|
||||
placeholder: "Example: {'columnName': 'value', ...}"
|
||||
placeholder: "Example: {'columnName': 'value', ...}",
|
||||
},
|
||||
],
|
||||
returnValues: [],
|
||||
@@ -236,7 +236,7 @@ export default class BaseModelComponent {
|
||||
description: 'Please fill out this query',
|
||||
required: true,
|
||||
id: 'query',
|
||||
placeholder: "Example: {'columnName': 'value', ...}"
|
||||
placeholder: "Example: {'columnName': 'value', ...}",
|
||||
},
|
||||
{
|
||||
type: ComponentInputType.Number,
|
||||
@@ -372,7 +372,8 @@ export default class BaseModelComponent {
|
||||
{
|
||||
id: 'json-array',
|
||||
name: 'JSON Array',
|
||||
placeholder: "Example: [{'columnName': 'value', ...}, {...}]",
|
||||
placeholder:
|
||||
"Example: [{'columnName': 'value', ...}, {...}]",
|
||||
description: 'List of models represented as JSON array',
|
||||
type: ComponentInputType.JSONArray,
|
||||
required: true,
|
||||
@@ -456,7 +457,7 @@ export default class BaseModelComponent {
|
||||
description: 'Please fill out this query',
|
||||
required: true,
|
||||
id: 'query',
|
||||
placeholder: "Example: {'columnName': 'value', ...}"
|
||||
placeholder: "Example: {'columnName': 'value', ...}",
|
||||
},
|
||||
{
|
||||
id: 'data',
|
||||
@@ -507,7 +508,7 @@ export default class BaseModelComponent {
|
||||
description: 'Please fill out this query',
|
||||
required: true,
|
||||
id: 'query',
|
||||
placeholder: "Example: {'columnName': 'value', ...}"
|
||||
placeholder: "Example: {'columnName': 'value', ...}",
|
||||
},
|
||||
{
|
||||
id: 'data',
|
||||
|
||||
@@ -18,7 +18,7 @@ const components: Array<ComponentMetadata> = [
|
||||
type: ComponentInputType.Text,
|
||||
name: 'Expression',
|
||||
description: 'Expression',
|
||||
placeholder: "x === y",
|
||||
placeholder: 'x === y',
|
||||
required: true,
|
||||
id: 'expression',
|
||||
},
|
||||
|
||||
@@ -18,7 +18,7 @@ const components: Array<ComponentMetadata> = [
|
||||
type: ComponentInputType.Text,
|
||||
name: 'From Email',
|
||||
description: 'Email to send from',
|
||||
placeholder: "Name <email@company.com>",
|
||||
placeholder: 'Name <email@company.com>',
|
||||
required: true,
|
||||
id: 'from',
|
||||
},
|
||||
@@ -26,7 +26,7 @@ const components: Array<ComponentMetadata> = [
|
||||
type: ComponentInputType.Text,
|
||||
name: 'To Email',
|
||||
description: 'Email to send to',
|
||||
placeholder: "email@company.com; email2@company.com; ...",
|
||||
placeholder: 'email@company.com; email2@company.com; ...',
|
||||
required: true,
|
||||
id: 'to',
|
||||
},
|
||||
|
||||
@@ -33,22 +33,24 @@ export default class ApiDelete extends ComponentCode {
|
||||
args: JSONObject,
|
||||
options: RunOptions
|
||||
): Promise<RunReturnType> {
|
||||
const result: { args: JSONObject; successPort: Port; errorPort: Port } =
|
||||
ApiComponentUtils.sanitizeArgs(this.getMetadata(), args, options);
|
||||
|
||||
const result: { args: JSONObject, successPort: Port, errorPort: Port } = ApiComponentUtils.sanitizeArgs(this.getMetadata(), args, options);
|
||||
|
||||
let apiResult: HTTPResponse<JSONObject> | HTTPErrorResponse | null = null;
|
||||
let apiResult: HTTPResponse<JSONObject> | HTTPErrorResponse | null =
|
||||
null;
|
||||
|
||||
try {
|
||||
|
||||
apiResult = await API.delete(args['url'] as URL, args['request-body'] as JSONObject, args['request-headers'] as Dictionary<string>);
|
||||
apiResult = await API.delete(
|
||||
args['url'] as URL,
|
||||
args['request-body'] as JSONObject,
|
||||
args['request-headers'] as Dictionary<string>
|
||||
);
|
||||
|
||||
return Promise.resolve({
|
||||
returnValues: ApiComponentUtils.getReturnValues(apiResult),
|
||||
executePort: result.successPort,
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (err instanceof HTTPErrorResponse) {
|
||||
return Promise.resolve({
|
||||
returnValues: ApiComponentUtils.getReturnValues(err),
|
||||
@@ -63,7 +65,9 @@ export default class ApiDelete extends ComponentCode {
|
||||
});
|
||||
}
|
||||
|
||||
throw options.onError(new APIException("Something wrong happened."));
|
||||
throw options.onError(
|
||||
new APIException('Something wrong happened.')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,22 +33,24 @@ export default class ApiGet extends ComponentCode {
|
||||
args: JSONObject,
|
||||
options: RunOptions
|
||||
): Promise<RunReturnType> {
|
||||
const result: { args: JSONObject; successPort: Port; errorPort: Port } =
|
||||
ApiComponentUtils.sanitizeArgs(this.getMetadata(), args, options);
|
||||
|
||||
const result: { args: JSONObject, successPort: Port, errorPort: Port } = ApiComponentUtils.sanitizeArgs(this.getMetadata(), args, options);
|
||||
|
||||
let apiResult: HTTPResponse<JSONObject> | HTTPErrorResponse | null = null;
|
||||
let apiResult: HTTPResponse<JSONObject> | HTTPErrorResponse | null =
|
||||
null;
|
||||
|
||||
try {
|
||||
|
||||
apiResult = await API.get(args['url'] as URL, args['request-body'] as JSONObject, args['request-headers'] as Dictionary<string>);
|
||||
apiResult = await API.get(
|
||||
args['url'] as URL,
|
||||
args['request-body'] as JSONObject,
|
||||
args['request-headers'] as Dictionary<string>
|
||||
);
|
||||
|
||||
return Promise.resolve({
|
||||
returnValues: ApiComponentUtils.getReturnValues(apiResult),
|
||||
executePort: result.successPort,
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (err instanceof HTTPErrorResponse) {
|
||||
return Promise.resolve({
|
||||
returnValues: ApiComponentUtils.getReturnValues(err),
|
||||
@@ -63,7 +65,9 @@ export default class ApiGet extends ComponentCode {
|
||||
});
|
||||
}
|
||||
|
||||
throw options.onError(new APIException("Something wrong happened."));
|
||||
throw options.onError(
|
||||
new APIException('Something wrong happened.')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,22 +33,24 @@ export default class ApiPost extends ComponentCode {
|
||||
args: JSONObject,
|
||||
options: RunOptions
|
||||
): Promise<RunReturnType> {
|
||||
const result: { args: JSONObject; successPort: Port; errorPort: Port } =
|
||||
ApiComponentUtils.sanitizeArgs(this.getMetadata(), args, options);
|
||||
|
||||
const result: { args: JSONObject, successPort: Port, errorPort: Port } = ApiComponentUtils.sanitizeArgs(this.getMetadata(), args, options);
|
||||
|
||||
let apiResult: HTTPResponse<JSONObject> | HTTPErrorResponse | null = null;
|
||||
let apiResult: HTTPResponse<JSONObject> | HTTPErrorResponse | null =
|
||||
null;
|
||||
|
||||
try {
|
||||
|
||||
apiResult = await API.post(args['url'] as URL, args['request-body'] as JSONObject, args['request-headers'] as Dictionary<string>);
|
||||
apiResult = await API.post(
|
||||
args['url'] as URL,
|
||||
args['request-body'] as JSONObject,
|
||||
args['request-headers'] as Dictionary<string>
|
||||
);
|
||||
|
||||
return Promise.resolve({
|
||||
returnValues: ApiComponentUtils.getReturnValues(apiResult),
|
||||
executePort: result.successPort,
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (err instanceof HTTPErrorResponse) {
|
||||
return Promise.resolve({
|
||||
returnValues: ApiComponentUtils.getReturnValues(err),
|
||||
@@ -63,7 +65,9 @@ export default class ApiPost extends ComponentCode {
|
||||
});
|
||||
}
|
||||
|
||||
throw options.onError(new APIException("Something wrong happened."));
|
||||
throw options.onError(
|
||||
new APIException('Something wrong happened.')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,22 +33,24 @@ export default class ApiPut extends ComponentCode {
|
||||
args: JSONObject,
|
||||
options: RunOptions
|
||||
): Promise<RunReturnType> {
|
||||
const result: { args: JSONObject; successPort: Port; errorPort: Port } =
|
||||
ApiComponentUtils.sanitizeArgs(this.getMetadata(), args, options);
|
||||
|
||||
const result: { args: JSONObject, successPort: Port, errorPort: Port } = ApiComponentUtils.sanitizeArgs(this.getMetadata(), args, options);
|
||||
|
||||
let apiResult: HTTPResponse<JSONObject> | HTTPErrorResponse | null = null;
|
||||
let apiResult: HTTPResponse<JSONObject> | HTTPErrorResponse | null =
|
||||
null;
|
||||
|
||||
try {
|
||||
|
||||
apiResult = await API.put(args['url'] as URL, args['request-body'] as JSONObject, args['request-headers'] as Dictionary<string>);
|
||||
apiResult = await API.put(
|
||||
args['url'] as URL,
|
||||
args['request-body'] as JSONObject,
|
||||
args['request-headers'] as Dictionary<string>
|
||||
);
|
||||
|
||||
return Promise.resolve({
|
||||
returnValues: ApiComponentUtils.getReturnValues(apiResult),
|
||||
executePort: result.successPort,
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (err instanceof HTTPErrorResponse) {
|
||||
return Promise.resolve({
|
||||
returnValues: ApiComponentUtils.getReturnValues(err),
|
||||
@@ -63,7 +65,9 @@ export default class ApiPut extends ComponentCode {
|
||||
});
|
||||
}
|
||||
|
||||
throw options.onError(new APIException("Something wrong happened."));
|
||||
throw options.onError(
|
||||
new APIException('Something wrong happened.')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,37 @@
|
||||
import BadDataException from "Common/Types/Exception/BadDataException";
|
||||
import { JSONObject } from "Common/Types/JSON";
|
||||
import ComponentMetadata, { Port } from "Common/Types/Workflow/Component";
|
||||
import { RunOptions } from "../../ComponentCode";
|
||||
import URL from "Common/Types/API/URL";
|
||||
import HTTPResponse from "Common/Types/API/HTTPResponse";
|
||||
import HTTPErrorResponse from "Common/Types/API/HTTPErrorResponse";
|
||||
import BadDataException from 'Common/Types/Exception/BadDataException';
|
||||
import { JSONObject } from 'Common/Types/JSON';
|
||||
import ComponentMetadata, { Port } from 'Common/Types/Workflow/Component';
|
||||
import { RunOptions } from '../../ComponentCode';
|
||||
import URL from 'Common/Types/API/URL';
|
||||
import HTTPResponse from 'Common/Types/API/HTTPResponse';
|
||||
import HTTPErrorResponse from 'Common/Types/API/HTTPErrorResponse';
|
||||
|
||||
export class ApiComponentUtils {
|
||||
|
||||
|
||||
public static getReturnValues(response: HTTPResponse<JSONObject> | HTTPErrorResponse): JSONObject {
|
||||
|
||||
|
||||
if(response instanceof HTTPErrorResponse){
|
||||
export class ApiComponentUtils {
|
||||
public static getReturnValues(
|
||||
response: HTTPResponse<JSONObject> | HTTPErrorResponse
|
||||
): JSONObject {
|
||||
if (response instanceof HTTPErrorResponse) {
|
||||
return {
|
||||
"response-status": response.statusCode,
|
||||
"response-body": response.jsonData,
|
||||
"response-headers": response.headers,
|
||||
"error": response.message || "Server Error."
|
||||
}
|
||||
'response-status': response.statusCode,
|
||||
'response-body': response.jsonData,
|
||||
'response-headers': response.headers,
|
||||
error: response.message || 'Server Error.',
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
"response-status": response.statusCode,
|
||||
"response-body": response.jsonData,
|
||||
"response-headers": response.headers,
|
||||
"error": null
|
||||
}
|
||||
}
|
||||
'response-status': response.statusCode,
|
||||
'response-body': response.jsonData,
|
||||
'response-headers': response.headers,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
public static sanitizeArgs(metadata: ComponentMetadata, args: JSONObject,
|
||||
options: RunOptions): {args: JSONObject, successPort: Port, errorPort: Port} {
|
||||
public static sanitizeArgs(
|
||||
metadata: ComponentMetadata,
|
||||
args: JSONObject,
|
||||
options: RunOptions
|
||||
): { args: JSONObject; successPort: Port; errorPort: Port } {
|
||||
const successPort: Port | undefined = metadata.outPorts.find(
|
||||
(p: Port) => {
|
||||
return p.id === 'success';
|
||||
@@ -53,35 +54,35 @@ export class ApiComponentUtils {
|
||||
throw options.onError(new BadDataException('Error port not found'));
|
||||
}
|
||||
|
||||
|
||||
if (args['request-body'] && typeof args['request-body'] === 'string') {
|
||||
args['request-body'] = JSON.parse(args['request-body'] as string);
|
||||
|
||||
}
|
||||
|
||||
if (args['query-string'] && typeof args['query-string'] === 'string') {
|
||||
args['query-string'] = JSON.parse(args['query-string'] as string);
|
||||
|
||||
}
|
||||
|
||||
if (args['request-headers'] && typeof args['request-headers'] === 'string') {
|
||||
args['request-headers'] = JSON.parse(args['request-headers'] as string);
|
||||
}
|
||||
|
||||
if(!args['url']){
|
||||
throw options.onError(
|
||||
new BadDataException('URL not found')
|
||||
if (
|
||||
args['request-headers'] &&
|
||||
typeof args['request-headers'] === 'string'
|
||||
) {
|
||||
args['request-headers'] = JSON.parse(
|
||||
args['request-headers'] as string
|
||||
);
|
||||
}
|
||||
|
||||
if(args['url'] && typeof args["url"] !== "string"){
|
||||
if (!args['url']) {
|
||||
throw options.onError(new BadDataException('URL not found'));
|
||||
}
|
||||
|
||||
if (args['url'] && typeof args['url'] !== 'string') {
|
||||
throw options.onError(
|
||||
new BadDataException('URL is not type of string')
|
||||
);
|
||||
}
|
||||
|
||||
args['url'] = URL.fromString(args["url"] as string);
|
||||
args['url'] = URL.fromString(args['url'] as string);
|
||||
|
||||
return {args, successPort, errorPort};
|
||||
return { args, successPort, errorPort };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,11 @@ export default class IfElse extends ComponentCode {
|
||||
public constructor() {
|
||||
super();
|
||||
|
||||
const Component: ComponentMetadata | undefined =
|
||||
Components.find((i: ComponentMetadata) => {
|
||||
const Component: ComponentMetadata | undefined = Components.find(
|
||||
(i: ComponentMetadata) => {
|
||||
return i.id === ComponentID.IfElse;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
if (!Component) {
|
||||
throw new BadDataException(
|
||||
@@ -35,9 +36,7 @@ export default class IfElse extends ComponentCode {
|
||||
);
|
||||
|
||||
if (!yesPort) {
|
||||
throw options.onError(
|
||||
new BadDataException('Yes port not found')
|
||||
);
|
||||
throw options.onError(new BadDataException('Yes port not found'));
|
||||
}
|
||||
|
||||
const noPort: Port | undefined = this.getMetadata().outPorts.find(
|
||||
@@ -69,7 +68,8 @@ export default class IfElse extends ComponentCode {
|
||||
});
|
||||
|
||||
const script: VMScript = new VMScript(
|
||||
`module.exports = async function() { return ${(args['expression'] as string) || ''
|
||||
`module.exports = async function() { return ${
|
||||
(args['expression'] as string) || ''
|
||||
} }`
|
||||
).compile();
|
||||
|
||||
@@ -79,19 +79,14 @@ export default class IfElse extends ComponentCode {
|
||||
|
||||
if (returnVal) {
|
||||
return {
|
||||
returnValues: {
|
||||
|
||||
},
|
||||
returnValues: {},
|
||||
executePort: yesPort,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
returnValues: {
|
||||
|
||||
},
|
||||
executePort: noPort,
|
||||
};
|
||||
}
|
||||
return {
|
||||
returnValues: {},
|
||||
executePort: noPort,
|
||||
};
|
||||
} catch (err: any) {
|
||||
options.log('Error running script');
|
||||
options.log(
|
||||
|
||||
@@ -27,8 +27,6 @@ export default class Email extends ComponentCode {
|
||||
args: JSONObject,
|
||||
options: RunOptions
|
||||
): Promise<RunReturnType> {
|
||||
|
||||
|
||||
const successPort: Port | undefined = this.getMetadata().outPorts.find(
|
||||
(p: Port) => {
|
||||
return p.id === 'success';
|
||||
@@ -52,93 +50,84 @@ export default class Email extends ComponentCode {
|
||||
}
|
||||
|
||||
if (!args['to']) {
|
||||
throw options.onError(
|
||||
new BadDataException('to not found')
|
||||
);
|
||||
throw options.onError(new BadDataException('to not found'));
|
||||
}
|
||||
|
||||
if (args['to'] && typeof args["to"] !== "string") {
|
||||
if (args['to'] && typeof args['to'] !== 'string') {
|
||||
throw options.onError(
|
||||
new BadDataException('to is not type of string')
|
||||
);
|
||||
}
|
||||
|
||||
if (!args['from']) {
|
||||
throw options.onError(
|
||||
new BadDataException('from not found')
|
||||
);
|
||||
throw options.onError(new BadDataException('from not found'));
|
||||
}
|
||||
|
||||
if (args['from'] && typeof args["from"] !== "string") {
|
||||
if (args['from'] && typeof args['from'] !== 'string') {
|
||||
throw options.onError(
|
||||
new BadDataException('from is not type of string')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (!args['smtp-username']) {
|
||||
throw options.onError(
|
||||
new BadDataException('email not found')
|
||||
);
|
||||
throw options.onError(new BadDataException('email not found'));
|
||||
}
|
||||
|
||||
if (args['smtp-username'] && typeof args["smtp-username"] !== "string") {
|
||||
if (
|
||||
args['smtp-username'] &&
|
||||
typeof args['smtp-username'] !== 'string'
|
||||
) {
|
||||
throw options.onError(
|
||||
new BadDataException('smtp-username is not type of string')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (!args['smtp-password']) {
|
||||
throw options.onError(
|
||||
new BadDataException('email not found')
|
||||
);
|
||||
throw options.onError(new BadDataException('email not found'));
|
||||
}
|
||||
|
||||
if (args['smtp-password'] && typeof args["smtp-password"] !== "string") {
|
||||
if (
|
||||
args['smtp-password'] &&
|
||||
typeof args['smtp-password'] !== 'string'
|
||||
) {
|
||||
throw options.onError(
|
||||
new BadDataException('smtp-username is not type of string')
|
||||
);
|
||||
}
|
||||
|
||||
if (!args['smtp-host']) {
|
||||
throw options.onError(
|
||||
new BadDataException('email not found')
|
||||
);
|
||||
throw options.onError(new BadDataException('email not found'));
|
||||
}
|
||||
|
||||
if (args['smtp-host'] && typeof args["smtp-host"] !== "string") {
|
||||
if (args['smtp-host'] && typeof args['smtp-host'] !== 'string') {
|
||||
throw options.onError(
|
||||
new BadDataException('smtp-host is not type of string')
|
||||
);
|
||||
}
|
||||
|
||||
if (!args['smtp-port']) {
|
||||
throw options.onError(
|
||||
new BadDataException('email not found')
|
||||
);
|
||||
throw options.onError(new BadDataException('email not found'));
|
||||
}
|
||||
|
||||
if (args['smtp-port'] && typeof args["smtp-port"] === "string") {
|
||||
if (args['smtp-port'] && typeof args['smtp-port'] === 'string') {
|
||||
args['smtp-port'] = parseInt(args['smtp-port']);
|
||||
}
|
||||
|
||||
if (args['smtp-port'] && typeof args["smtp-port"] !== "number") {
|
||||
if (args['smtp-port'] && typeof args['smtp-port'] !== 'number') {
|
||||
throw options.onError(
|
||||
new BadDataException('smtp-host is not type of number')
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
const mailer: Transporter = nodemailer.createTransport({
|
||||
host: args['smtp-host']?.toString(),
|
||||
port: args['smtp-port'] as number,
|
||||
secure: !!args['secure'],
|
||||
secure: Boolean(args['secure']),
|
||||
auth: {
|
||||
user: args['smtp-username'] as string,
|
||||
pass: args['smtp-password'] as string,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
await mailer.sendMail({
|
||||
@@ -148,15 +137,14 @@ export default class Email extends ComponentCode {
|
||||
html: args['body']?.toString() || '',
|
||||
});
|
||||
|
||||
options.log("Email sent.");
|
||||
|
||||
options.log('Email sent.');
|
||||
|
||||
return Promise.resolve({
|
||||
returnValues: {},
|
||||
executePort: successPort,
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
options.log(err);
|
||||
options.log(err);
|
||||
return Promise.resolve({
|
||||
returnValues: {},
|
||||
executePort: successPort,
|
||||
|
||||
@@ -44,9 +44,7 @@ const Components: Dictionary<ComponentCode> = {
|
||||
[ComponentID.ApiDelete]: new ApiPost(),
|
||||
[ComponentID.ApiPut]: new ApiPut(),
|
||||
[ComponentID.SendEmail]: new Email(),
|
||||
[ComponentID.IfElse]: new IfElse()
|
||||
|
||||
|
||||
[ComponentID.IfElse]: new IfElse(),
|
||||
};
|
||||
|
||||
for (const baseModelService of BaseModelServices) {
|
||||
|
||||
@@ -49,14 +49,11 @@ export default class JsonToText extends ComponentCode {
|
||||
}
|
||||
|
||||
if (!args['json']) {
|
||||
throw options.onError(
|
||||
new BadDataException('JSON is undefined.')
|
||||
);
|
||||
throw options.onError(new BadDataException('JSON is undefined.'));
|
||||
}
|
||||
|
||||
if (typeof args['json'] === 'string') {
|
||||
args['json'] = JSON.parse(args['json'] as string);
|
||||
|
||||
}
|
||||
|
||||
if (typeof args['json'] !== 'object') {
|
||||
@@ -66,17 +63,17 @@ export default class JsonToText extends ComponentCode {
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
const returnValue: string = JSON.stringify(args['json'] as JSONObject);
|
||||
const returnValue: string = JSON.stringify(
|
||||
args['json'] as JSONObject
|
||||
);
|
||||
return Promise.resolve({
|
||||
returnValues: {
|
||||
text: returnValue
|
||||
text: returnValue,
|
||||
},
|
||||
executePort: successPort,
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
options.log("JSON is not in the correct format.");
|
||||
options.log('JSON is not in the correct format.');
|
||||
return Promise.resolve({
|
||||
returnValues: {},
|
||||
executePort: errorPort,
|
||||
|
||||
@@ -49,14 +49,11 @@ export default class MergeJSON extends ComponentCode {
|
||||
}
|
||||
|
||||
if (!args['json1']) {
|
||||
throw options.onError(
|
||||
new BadDataException('JSON1 is undefined.')
|
||||
);
|
||||
throw options.onError(new BadDataException('JSON1 is undefined.'));
|
||||
}
|
||||
|
||||
if (typeof args['json1'] === 'string') {
|
||||
args['json1'] = JSON.parse(args['json1'] as string);
|
||||
|
||||
}
|
||||
|
||||
if (typeof args['json2'] !== 'object') {
|
||||
@@ -65,16 +62,12 @@ export default class MergeJSON extends ComponentCode {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (!args['json2']) {
|
||||
throw options.onError(
|
||||
new BadDataException('JSON2 is undefined.')
|
||||
);
|
||||
throw options.onError(new BadDataException('JSON2 is undefined.'));
|
||||
}
|
||||
|
||||
if (typeof args['json2'] === 'string') {
|
||||
args['json2'] = JSON.parse(args['json2'] as string);
|
||||
|
||||
}
|
||||
|
||||
if (typeof args['json2'] !== 'object') {
|
||||
@@ -86,9 +79,9 @@ export default class MergeJSON extends ComponentCode {
|
||||
return Promise.resolve({
|
||||
returnValues: {
|
||||
json: {
|
||||
...args['json1'] as JSONObject,
|
||||
...args['json2'] as JSONObject
|
||||
}
|
||||
...(args['json1'] as JSONObject),
|
||||
...(args['json2'] as JSONObject),
|
||||
},
|
||||
},
|
||||
executePort: successPort,
|
||||
});
|
||||
|
||||
@@ -49,12 +49,9 @@ export default class TextToJSON extends ComponentCode {
|
||||
}
|
||||
|
||||
if (!args['text']) {
|
||||
throw options.onError(
|
||||
new BadDataException('text is undefined.')
|
||||
);
|
||||
throw options.onError(new BadDataException('text is undefined.'));
|
||||
}
|
||||
|
||||
|
||||
if (typeof args['text'] !== 'string') {
|
||||
throw options.onError(
|
||||
new BadDataException('text is should be of type string.')
|
||||
@@ -62,17 +59,15 @@ export default class TextToJSON extends ComponentCode {
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
const returnValue: JSONObject = JSON.parse(args['text'] as string);
|
||||
return Promise.resolve({
|
||||
returnValues: {
|
||||
json: returnValue
|
||||
json: returnValue,
|
||||
},
|
||||
executePort: successPort,
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
options.log("text is not in the correct format.");
|
||||
options.log('text is not in the correct format.');
|
||||
return Promise.resolve({
|
||||
returnValues: {},
|
||||
executePort: errorPort,
|
||||
|
||||
@@ -107,11 +107,12 @@ const CodeEditor: FunctionComponent<ComponentProps> = (
|
||||
props.onFocus && props.onFocus();
|
||||
}}
|
||||
>
|
||||
|
||||
{helpText && <p
|
||||
className="bg-gray-50 text-gray-500 p-3 mt-2 mb-2 rounded text-base text-sm"
|
||||
|
||||
> {helpText} </p>}
|
||||
{helpText && (
|
||||
<p className="bg-gray-50 text-gray-500 p-3 mt-2 mb-2 rounded text-base text-sm">
|
||||
{' '}
|
||||
{helpText}{' '}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<Editor
|
||||
defaultLanguage={props.type}
|
||||
|
||||
Reference in New Issue
Block a user