-
Notifications
You must be signed in to change notification settings - Fork 4k
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(api-service): validate recipients in event request parsing #7758
Open
BiswaViraj
wants to merge
11
commits into
next
Choose a base branch
from
nv-5432-fix-typeerror-related-to-subscriberidtrim-function
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3e2d315
feat(api): validate recipients in event request parsing
BiswaViraj 7fe07c4
fix(shared): update subscriber ID regex to allow special characters
BiswaViraj 0192c6b
feat(api): enhance recipient validation with dry run feature and upda…
BiswaViraj 8e04add
fix(shared): update subscriber ID regex to include '@' character
BiswaViraj b920245
feat(api): refactor recipient validation logic and introduce zod sche…
BiswaViraj 41f549b
feat(schema): enhance subscriber ID validation with regex for special…
BiswaViraj 594303b
feat(api): integrate CommunityOrganizationRepository into event parsi…
BiswaViraj 426cb8e
refactor(api): rename subscriber variables to recipients for clarity …
BiswaViraj 65782a2
feat(api): optimize event parsing by fetching environment and organiz…
BiswaViraj e9715e2
refactor(api): remove unused subscriber email regex import from creat…
BiswaViraj 5206e63
Merge branch 'next' into nv-5432-fix-typeerror-related-to-subscriberi…
BiswaViraj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
8 changes: 8 additions & 0 deletions
8
apps/api/src/app/events/utils/trigger-recipient-validation.ts
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,8 @@ | ||
import { SUBSCRIBER_ID_REGEX } from '@novu/shared'; | ||
import { z } from 'zod'; | ||
|
||
export const subscriberIdSchema = z.string().trim().regex(SUBSCRIBER_ID_REGEX).or(z.string().trim().email()); | ||
export const subscriberObjectSchema = z.object({ subscriberId: subscriberIdSchema }).passthrough(); | ||
export const topicSchema = z.object({ topicKey: subscriberIdSchema }).passthrough(); | ||
export const RecipientSchema = z.union([subscriberIdSchema, subscriberObjectSchema, topicSchema]); | ||
export const RecipientsSchema = z.union([RecipientSchema, z.array(RecipientSchema)]); |
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
export const SUBSCRIBER_ID_REGEX = /^[a-zA-Z0-9_-]+$/; | ||
export const SUBSCRIBER_ID_REGEX = /^(?:[a-zA-Z0-9_-]+|\S+@\S+\.\S+)$/; |
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.
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.
We need to show in the error the invalid subscribers and why they are invalid. The error must be actionable.
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.
This still needs more work,
users will receive the
invalid_recipients
status when all of them are invalidbut lets say if out of 5 only 2 were invalid we need to add that in the activity feed