Add relay share invite endpoints#19
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds Clerk-backed user profile lookup, three /shares HTTP routes (list, invite, accept) with header-injected identity, Resend-based email sending for invites, a public-safe share summary transformer, and related Env configuration. ChangesShare Invite Flow with User Authentication and Email Delivery
Sequence DiagramsequenceDiagram
participant Client
participant RelayRouter
participant ClerkAPI
participant RelayObject
participant DurableState
participant ResendAPI
Client->>RelayRouter: POST /shares/invite with Bearer token
RelayRouter->>ClerkAPI: fetchClerkUserProfile (using CLERK_SECRET_KEY)
ClerkAPI-->>RelayRouter: ClerkUserProfile (displayName,email)
RelayRouter->>RelayObject: forward request with X-Aimux-User-* headers
RelayObject->>DurableState: loadSharingState / saveSharingState
DurableState-->>RelayObject: share record
RelayObject->>RelayObject: createShareInvite / summarizeShare
RelayObject->>ResendAPI: POST /emails (renderShareInviteEmail / shareInviteEmailText)
ResendAPI-->>RelayObject: email sent
RelayObject-->>Client: share summary + invite info
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly Related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@relay/src/index.ts`:
- Line 117: Wrap the call to fetchClerkUserProfile in a try/catch so
network/JSON errors don’t bubble up and cause a 500; on failure assign a safe
fallback profile (e.g., an object with userId and null/empty name/email or
minimal shape your downstream code expects) to the profile variable and continue
processing the /shares request. Ensure you reference fetchClerkUserProfile and
the local profile variable so downstream handlers still receive the expected
shape.
In `@relay/src/relay-object.ts`:
- Around line 417-440: The current flow persists the invite via
saveSharingState(this.ctx.storage, result.state) before calling
deliverShareInvite, which can cause “saved-but-400” when email send fails; fix
by reordering so deliverShareInvite({ env: this.env, owner, share:
result.token.share, inviteEmail: result.token.invite.email, acceptUrl }) is
attempted first and only on success call saveSharingState(this.ctx.storage,
result.state) and then return the 201 response; if you cannot reorder, instead
catch delivery errors and roll back the persisted state (e.g., delete the saved
invite/state) before returning an error, referencing saveSharingState and
deliverShareInvite and the result.token/result.state symbols to locate the code.
In `@relay/src/sharing-delivery.ts`:
- Around line 16-29: The fetch call posting to https://api.resend.com/emails
should check the HTTP response and fail on non-2xx statuses: assign the result
of fetch(...) to a variable (the POST that uses input.env.RESEND_API_KEY,
renderShareInviteEmail and shareInviteEmailText), then if (!response.ok) parse
response.json() or response.text() to capture error details and either throw or
log a descriptive error including response.status and the parsed body so invite
failures aren’t silently ignored.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: b6edd65d-ffb9-4bcc-b7f8-f6c5754cce9d
📒 Files selected for processing (8)
relay/src/auth.tsrelay/src/index.tsrelay/src/relay-object.tsrelay/src/sharing-delivery.tsrelay/src/sharing.test.tsrelay/src/sharing.tsrelay/src/types.tsrelay/wrangler.toml
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
Verification
Note: Prettier cannot infer a parser for relay/wrangler.toml in this repo, so TOML was not run through prettier.
Summary by CodeRabbit