Repository navigation
fix: surface invite-email send failures instead of swallowing them #752
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
Open
SomSamantray
wants to merge
20
commits into
oss-apps:main
Choose a base branch
from
SomSamantray:fix/722-surface-smtp-invite-email-errors
base: main
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.
+444
−37
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
13540ff
fix: propagate sendInviteEmail's send result instead of discarding it
SomSamantray 1203c10
fix: surface invite-email send failures from inviteFriend mutation
SomSamantray 5959eb8
fix: show toast and reconcile UI state on invite-email failure
SomSamantray ddf6890
fix(review): apply review findings
SomSamantray 501dc85
chore: fix comment wording mangled by pre-commit autofix
SomSamantray f8bef61
fix: add machine-readable AppError cause for tRPC error discrimination
SomSamantray d60a7c7
fix: escape inviter name in invite-email HTML to prevent HTML injection
SomSamantray 121c948
fix: rate-limit invite-email sends and stop logging raw recipient emails
SomSamantray 70e58a6
fix: discriminate genuine send failures from other invite errors, cli…
SomSamantray 31fa028
refactor: consolidate invite-error codes and toast mapping into one m…
SomSamantray b0cadd3
fix: harden inviteFriend against concurrent-create races and silent t…
SomSamantray 135eb75
test: add coverage for inviteErrors.ts; align to project's test-struc…
SomSamantray 13e6ee4
fix: apply the same error-recovery pattern to SelectUserOrGroup.tsx
SomSamantray 1c9bd68
fix: wire the send_invite button to actually send an invite email
SomSamantray 00a85fe
fix: replace persisted invite cooldown with in-memory map
SomSamantray e93c12f
fix(review): scope invite recovery to email failures
SomSamantray 9c8f444
test: cover all invite email HTML escapes
SomSamantray 45e8c97
fix: key invite cooldown by user pair
SomSamantray 29242c6
fix: keep invite recovery independent
SomSamantray 6f1abc9
fix: bound SMTP invite delivery timeouts
SomSamantray 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,15 @@ | ||
| export const InviteErrorCode = { | ||
|
SomSamantray marked this conversation as resolved.
|
||
| INVITES_DISABLED: 'INVITES_DISABLED', | ||
| INVITE_RATE_LIMITED: 'INVITE_RATE_LIMITED', | ||
| INVITE_EMAIL_SEND_FAILED: 'INVITE_EMAIL_SEND_FAILED', | ||
| } as const; | ||
|
|
||
| export const isInviteEmailSendFailed = (appErrorCode: unknown): boolean => | ||
| InviteErrorCode.INVITE_EMAIL_SEND_FAILED === appErrorCode; | ||
|
|
||
| export const getInviteErrorToastKey = ( | ||
| appErrorCode: string | null | undefined, | ||
| ): 'errors.invite_email_failed' | 'errors.add_member_failed' => | ||
| InviteErrorCode.INVITE_EMAIL_SEND_FAILED === appErrorCode | ||
| ? 'errors.invite_email_failed' | ||
| : 'errors.add_member_failed'; | ||
This file contains hidden or 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,27 @@ | ||
| const INVITE_COOLDOWN_MS = 60_000; | ||
| const lastInviteAtByUserPair = new Map<string, number>(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's narrow this key type down to |
||
| let nextCleanupAt = 0; | ||
|
|
||
| export const claimInviteCooldown = ( | ||
| inviteeId: number, | ||
| inviterId: number, | ||
| now = Date.now(), | ||
| ): boolean => { | ||
| const userPair = `${inviteeId}:${inviterId}`; | ||
| const lastInviteAt = lastInviteAtByUserPair.get(userPair); | ||
| if (undefined !== lastInviteAt && now - lastInviteAt < INVITE_COOLDOWN_MS) { | ||
| return false; | ||
| } | ||
|
|
||
| if (now >= nextCleanupAt) { | ||
| lastInviteAtByUserPair.forEach((inviteAt, pair) => { | ||
| if (now - inviteAt >= INVITE_COOLDOWN_MS) { | ||
| lastInviteAtByUserPair.delete(pair); | ||
| } | ||
| }); | ||
| nextCleanupAt = now + INVITE_COOLDOWN_MS; | ||
| } | ||
|
|
||
| lastInviteAtByUserPair.set(userPair, now); | ||
| return true; | ||
| }; | ||
This file contains hidden or 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 hidden or 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,12 @@ | ||
| export class AppError extends Error { | ||
| readonly code: string; | ||
|
|
||
| constructor(code: string, message: string) { | ||
| super(message); | ||
| this.name = 'AppError'; | ||
| this.code = code; | ||
| } | ||
| } | ||
|
|
||
| export const getAppErrorCode = (cause: unknown): string | null => | ||
| cause instanceof AppError ? cause.code : null; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.