New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(wip): add custom step #5323
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
981da4c
feat(wip): add custom step
djabarovgeorge 097fc39
feat: fix preview and step variablesfor custom
scopsy 1ffcfa2
fix: pointer
scopsy 527fa56
fix: workflow create menu
scopsy 9ff13b8
feat: merge next
djabarovgeorge 2b48ff6
feat: update hash after next merge
djabarovgeorge 45436b7
feat: change custom response naming
djabarovgeorge 2009163
test: add test server for echo
ainouzgali 2cc9a3e
Merge remote-tracking branch 'origin/next' into add-custom-step
ainouzgali 4a8be3b
Merge remote-tracking branch 'origin/next' into add-custom-step
ainouzgali 711988e
fix: update pnpm lock
ainouzgali File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Submodule .source
updated
from 9b5c34 to 2b9927
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as http from 'http'; | ||
import * as express from 'express'; | ||
import { serve } from '@novu/echo/express'; | ||
import { Echo } from '@novu/echo'; | ||
|
||
class EchoServer { | ||
private server: express.Express; | ||
private app: http.Server; | ||
private port = 9999; | ||
public echo = new Echo({ devModeBypassAuthentication: true }); | ||
|
||
get serverPath() { | ||
return `http://localhost:${this.port}`; | ||
} | ||
|
||
async start() { | ||
this.server = express(); | ||
this.server.use(express.json()); | ||
this.server.use(serve({ client: this.echo })); | ||
|
||
this.app = await this.server.listen(this.port); | ||
} | ||
|
||
async stop() { | ||
await this.app.close(); | ||
} | ||
} | ||
|
||
export const echoServer = new EchoServer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import axios from 'axios'; | ||
import { expect } from 'chai'; | ||
import { UserSession, SubscribersService } from '@novu/testing'; | ||
import { MessageRepository, SubscriberEntity, NotificationTemplateRepository } from '@novu/dal'; | ||
import { StepTypeEnum } from '@novu/shared'; | ||
import { echoServer } from '../../../../e2e/echo.server'; | ||
|
||
const eventTriggerPath = '/v1/events/trigger'; | ||
|
||
describe('Echo Trigger ', async () => { | ||
let session: UserSession; | ||
const messageRepository = new MessageRepository(); | ||
const workflowsRepository = new NotificationTemplateRepository(); | ||
let subscriber: SubscriberEntity; | ||
let subscriberService: SubscribersService; | ||
|
||
beforeEach(async () => { | ||
session = new UserSession(); | ||
await session.initialize(); | ||
subscriberService = new SubscribersService(session.organization._id, session.environment._id); | ||
subscriber = await subscriberService.createSubscriber(); | ||
}); | ||
|
||
it('should trigger the echo workflow', async () => { | ||
const workflowId = 'hello-world'; | ||
await echoServer.echo.workflow( | ||
workflowId, | ||
async ({ step, payload }) => { | ||
await step.email( | ||
'send-email', | ||
async (inputs) => { | ||
return { | ||
subject: 'This is an email subject ' + inputs.name, | ||
body: 'Body result ' + payload.name, | ||
}; | ||
}, | ||
{ | ||
inputSchema: { | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string', default: 'TEST' }, | ||
}, | ||
} as const, | ||
} | ||
); | ||
}, | ||
{ | ||
payloadSchema: { | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string', default: 'default_name' }, | ||
}, | ||
required: [], | ||
additionalProperties: false, | ||
} as const, | ||
} | ||
); | ||
|
||
const resultDiscover = await axios.get(echoServer.serverPath + '/echo?action=discover'); | ||
|
||
await session.testAgent.post(`/v1/echo/sync`).send({ | ||
chimeraUrl: echoServer.serverPath + '/echo', | ||
workflows: resultDiscover.data.workflows, | ||
}); | ||
|
||
const workflow = await workflowsRepository.findByTriggerIdentifier(session.environment._id, workflowId); | ||
expect(workflow).to.be.ok; | ||
|
||
if (!workflow) { | ||
throw new Error('Workflow not found'); | ||
} | ||
|
||
await axios.post( | ||
`${session.serverUrl}${eventTriggerPath}`, | ||
{ | ||
name: workflowId, | ||
to: { | ||
subscriberId: subscriber.subscriberId, | ||
email: '[email protected]', | ||
}, | ||
payload: { | ||
name: 'test_name', | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
authorization: `ApiKey ${session.apiKey}`, | ||
}, | ||
} | ||
); | ||
await session.awaitRunningJobs(workflow._id); | ||
|
||
const messagesAfter = await messageRepository.find({ | ||
_environmentId: session.environment._id, | ||
_subscriberId: subscriber._id, | ||
channel: StepTypeEnum.EMAIL, | ||
}); | ||
|
||
expect(messagesAfter.length).to.be.eq(1); | ||
expect(messagesAfter[0].subject).to.include('This is an email subject TEST'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
apps/web/src/pages/templates/components/custom-editor/TemplateCustomEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Controller, useFormContext } from 'react-hook-form'; | ||
import { StepSettings } from '../../workflow/SideBar/StepSettings'; | ||
import { useStepFormPath } from '../../hooks/useStepFormPath'; | ||
import { useState } from 'react'; | ||
import { Grid, Stack } from '@mantine/core'; | ||
import { InputVariablesForm } from '../InputVariablesForm'; | ||
|
||
export function TemplateCustomEditor() { | ||
const stepFormPath = useStepFormPath(); | ||
const { control } = useFormContext(); | ||
|
||
const [inputVariables, setInputVariables] = useState(); | ||
|
||
return ( | ||
<> | ||
<StepSettings /> | ||
<Grid gutter={24}> | ||
<Grid.Col span={'auto'}> | ||
<Controller | ||
name={`${stepFormPath}.template.content` as any} | ||
defaultValue="" | ||
control={control} | ||
render={({ field }) => ( | ||
<Stack spacing={8}> | ||
<InputVariablesForm | ||
onChange={(values) => { | ||
setInputVariables(values); | ||
}} | ||
/> | ||
</Stack> | ||
)} | ||
/> | ||
</Grid.Col> | ||
</Grid> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create ActionStepTypeEnum and skip by it