Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Merge branch 'dev' of github.com:erxes/erxes-community
Browse files Browse the repository at this point in the history
  • Loading branch information
batamar committed Nov 7, 2022
2 parents 77b8744 + ee4d775 commit b4ac7df
Show file tree
Hide file tree
Showing 74 changed files with 1,169 additions and 672 deletions.
150 changes: 20 additions & 130 deletions packages/api-utils/src/automations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as moment from 'moment';
import { pluralFormation } from './commonUtils';

export const replacePlaceHolders = async ({
models,
Expand Down Expand Up @@ -118,16 +119,23 @@ export const OPERATORS = {
const getPerValue = async (args: {
models;
subdomain;
conformity;
relatedItem;
rule;
target;
getRelatedValue;
}) => {
const { models, subdomain, conformity, rule, target, getRelatedValue } = args;
const {
models,
subdomain,
relatedItem,
rule,
target,
getRelatedValue
} = args;
const { field, operator, value } = rule;
const op1Type = typeof conformity[field];
const op1Type = typeof relatedItem[field];

let op1 = conformity[field];
let op1 = relatedItem[field];

let updatedValue = (
await replacePlaceHolders({
Expand Down Expand Up @@ -207,148 +215,30 @@ const getPerValue = async (args: {
return updatedValue;
};

const replaceServiceTypes = value => {
return value.replace('cards:', '').replace('contacts:', '');
};

const getRelatedTargets = async (
subdomain,
triggerType,
action,
execution,
sendCommonMessage
) => {
const { config } = action;
const { target } = execution;

const { module } = config;

if (module === triggerType) {
return [target];
}

if (
triggerType === 'inbox:conversation' &&
['cards:task', 'cards:ticket', 'cards:deal'].includes(module)
) {
return sendCommonMessage({
subdomain,
serviceName: 'cards',
action: `${module.replace('cards:', '')}s.find`,
data: {
sourceConversationIds: { $in: [target._id] }
},
isRPC: true
});
}

if (
['contacts:customer', 'contacts:lead'].includes(triggerType) &&
target.isFormSubmission &&
['cards:task', 'cards:ticket', 'cards:deal'].includes(module)
) {
return sendCommonMessage({
subdomain,
serviceName: 'cards',
action: `${module.replace('cards:', '')}s.find`,
data: {
sourceConversationIds: { $in: [target.conversationId] }
},
isRPC: true
});
}

if (
triggerType === 'inbox:conversation' &&
['contacts:customer', 'contacts:company'].includes(module)
) {
return sendCommonMessage({
subdomain,
serviceName: 'contacts',
action: `${module.includes('customer') ? 'customers' : 'companies'}.find`,
data: {
_id: target[module.includes('customer') ? 'customerId' : 'companyId']
},
isRPC: true
});
}

if (
[
'cards:task',
'cards:ticket',
'cards:deal',
'contacts:customer',
'contacts:company'
].includes(triggerType) &&
[
'cards:task',
'cards:ticket',
'cards:deal',
'contacts:customer',
'contacts:company'
].includes(module)
) {
const relType = replaceServiceTypes(module);

const relTypeIds = await sendCommonMessage({
subdomain,
serviceName: 'core',
action: 'conformities.savedConformity',
data: {
mainType: replaceServiceTypes(triggerType),
mainTypeId: target._id,
relTypes: [relType]
},
isRPC: true
});

const [serviceName, collectionType] = module.split(':');

return sendCommonMessage({
subdomain,
serviceName,
action: `${collectionType}s.find`,
data: { _id: { $in: relTypeIds } },
isRPC: true
});
}

return [];
};

export const setProperty = async ({
models,
subdomain,
action,
module,
rules,
execution,
getRelatedValue,
triggerType,
relatedItems,
sendCommonMessage
}) => {
const { module, rules } = action.config;
const { target } = execution;
const [serviceName, collectionType] = module.split(':');

const result: any[] = [];

const conformities = await getRelatedTargets(
subdomain,
triggerType,
action,
execution,
sendCommonMessage
);

for (const conformity of conformities) {
for (const relatedItem of relatedItems) {
const setDoc = {};
const pushDoc = {};

for (const rule of rules) {
const value = await getPerValue({
models,
subdomain,
conformity,
relatedItem,
rule,
target,
getRelatedValue
Expand Down Expand Up @@ -393,8 +283,8 @@ export const setProperty = async ({
const response = await sendCommonMessage({
subdomain,
serviceName,
action: `${collectionType}s.updateMany`,
data: { selector: { _id: conformity._id }, modifier },
action: `${pluralFormation(collectionType)}.updateMany`,
data: { selector: { _id: relatedItem._id }, modifier },
isRPC: true
});

Expand All @@ -404,7 +294,7 @@ export const setProperty = async ({
}

result.push({
_id: conformity._id,
_id: relatedItem._id,
rules: (Object as any)
.values(setDoc)
.map(v => String(v))
Expand Down
21 changes: 16 additions & 5 deletions packages/api-utils/src/commonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface IOrderInput {
}

export const updateOrder = async (collection: any, orders: IOrderInput[]) => {

if (orders.length === 0) {
return [];
}
Expand All @@ -29,8 +28,8 @@ export const updateOrder = async (collection: any, orders: IOrderInput[]) => {
bulkOps.push({
updateOne: {
filter: { _id },
update: selector,
},
update: selector
}
});
}

Expand Down Expand Up @@ -59,7 +58,7 @@ export const encryptText = (text: string): IEncryptionData => {
algorithm,
key,
iv: iv.toString('hex'),
encryptedData: encrypted.toString('hex'),
encryptedData: encrypted.toString('hex')
};
} catch (e) {
throw new Error(e);
Expand All @@ -71,7 +70,11 @@ export const decryptText = (data: IEncryptionData): string => {

const encryptedText = Buffer.from(data.encryptedData, 'hex');

const decipher = crypto.createDecipheriv(data.algorithm, Buffer.from(data.key), iv);
const decipher = crypto.createDecipheriv(
data.algorithm,
Buffer.from(data.key),
iv
);

// decipher
let decrypted = decipher.update(encryptedText);
Expand All @@ -81,3 +84,11 @@ export const decryptText = (data: IEncryptionData): string => {

return decrypted.toString();
};

export const pluralFormation = (type: string) => {
if (type[type.length - 1] === 'y') {
return type.slice(0, -1) + 'ies';
}

return type + 's';
};
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function NavigationItem(props: Props) {
);
};

if (plugin.text === 'Settings') {
if (plugin.text === 'Settings' || plugin.text === 'Marketplace') {
return <React.Fragment key={plugin.url}>{renderItem()}</React.Fragment>;
}

Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/automations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
constants: {
triggers: [
{
type: 'core:user',
img: 'automation4.svg',
icon: 'users',
label: 'Team member',
description:
'Start with a blank workflow that enralls and is triggered off team members'
}
]
}
};
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import forms from './forms';
import { generateModels } from './connectionResolver';
import { authCookieOptions, getSubdomain } from '@erxes/api-utils/src/core';
import segments from './segments';
import automations from './automations';
import { moduleObjects } from './data/permissions/actions/permission';

const {
Expand Down Expand Up @@ -301,6 +302,7 @@ httpServer.listen(PORT, async () => {
logs: { providesActivityLog: true, consumers: logs },
forms,
segments,
automations,
permissions: moduleObjects
}
});
Expand Down
60 changes: 43 additions & 17 deletions packages/plugin-automations-api/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
export const ACTIONS = {
WAIT: "wait",
IF: "if",
SET_PROPERTY: "setProperty",
CREATE_TASK: "cards:task.create",
CREATE_TICKET: "cards:ticket.create",
CREATE_DEAL: "cards:deal.create",
CREATE_VOUCHER: "loyalties:voucher.create",
CHANGE_SCORE: "loyalties:scoreLog.create"
WAIT: 'wait',
IF: 'if',
SET_PROPERTY: 'setProperty'
};

export const TRIGGER_TYPES = {
LEAD: 'contacts:lead',
CUSTOMER: 'contacts:customer',
COMPANY: 'contacts:company',
DEAL: 'cards:deal',
TASK: 'cards:task',
TICKET: 'cards:ticket',
CONVERSATIONS: 'inbox:conversations',
}
export const UI_ACTIONS = [
{
type: 'if',
icon: 'sitemap-1',
label: 'Branches',
description: 'Create simple or if/then branches',
isAvailable: true
},
{
type: 'setProperty',
icon: 'flask',
label: 'Manage properties',
description:
'Update existing default or custom properties for Contacts, Companies, Cards, Conversations',
isAvailable: true
},
{
type: 'delay',
icon: 'hourglass',
label: 'Delay',
description:
'Delay the next action with a timeframe, a specific event or activity',
isAvailable: true
},
{
type: 'workflow',
icon: 'glass-martini-alt',
label: 'Workflow',
description:
'Enroll in another workflow, trigger outgoing webhook or write custom code',
isAvailable: false
},
{
type: 'externalCommunications',
icon: 'fast-mail',
label: 'External communications',
description: 'Send email, SMS or in-app messenger messages to Contacts',
isAvailable: false
}
];
Loading

0 comments on commit b4ac7df

Please sign in to comment.