feat(devices): add /devices register and revoke endpoints; emit syste…#245
Open
EDOHWARES wants to merge 1 commit into
Open
feat(devices): add /devices register and revoke endpoints; emit syste…#245EDOHWARES wants to merge 1 commit into
EDOHWARES wants to merge 1 commit into
Conversation
…m events on device add/revoke
|
@EDOHWARES Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Author
|
@codebestia , pls review PR |
Owner
|
@EDOHWARES Please fix the CI |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
feat(devices): device registration + system events on add/revoke
Summary
POST /devices) and device revoke endpoint (DELETE /devices/:id).identityPublicKeyis base64 encoded and exactly 32 bytes.(userId, deviceId)registrations by returning409 Conflict.Files changed (high level)
devices.tsAdded:
RegisterDeviceSchemaPOST /devicesendpointDELETE /devices/:idendpointemitDeviceChangeEventhelperDevice registration (
POST /devices)identityPublicKeyas:(userId, deviceId)registrations with409 Conflict.req.auth.userId.Device revoke (
DELETE /devices/:id)req.auth.userId.Device change events
emitDeviceChangeEvent:Existing prekeys functionality remains unchanged.
Acceptance Criteria Mapping
Requires JWT; device bound to
req.auth.userIdrequireAuth.req.auth.userId.Invalid or short public key returns
400identityPublicKeymust:Duplicate device returns
409(userId, deviceId)pair and returns409 Conflict.New device starts with zero prekeys
Adding or revoking a device produces a system event in shared conversations
emitDeviceChangeEventinserts a message into each conversation the user belongs to.messages.content.Example payload:
{ "userId": "user-id", "change": "device_added" }or
{ "userId": "user-id", "change": "device_revoked" }Cache invalidation for members is triggered
invalidateConversationCaches()is called for conversation members after emitting events.Implementation details & notes
System event content
System events are currently stored in:
as a JSON stringified object:
{ "userId": "...", "change": "device_added" }or
{ "userId": "...", "change": "device_revoked" }The
messagestable does not currently contain acontent_typecolumn.If explicit system message typing is desired, a migration will be required.
Suggested schema change:
Socket.IO
Uses the existing server instance:
to emit inserted messages into conversation rooms.
Cache invalidation
Conversation caches are invalidated for affected members immediately after broadcasting.
Revoke behavior
Revocation is scoped to:
to prevent users from deleting devices belonging to others.
Error handling
Testing / verification
Unit and integration tests should verify:
POST /devices201 Createdon successResponse shape:
{ "id": "...", "deviceId": "...", "createdAt": "..." }✅
400 Bad Requestfor:✅
409 Conflictfor duplicate registrationsDELETE /devices/:id200 OKwhen revoked404 Not Foundwhen device does not exist403 Forbiddenwhen attempting to revoke another user's deviceDevice change events
After add or revoke:
new_messageSocket.IO broadcast occursSocket.IO interactions can be mocked in tests.
Manual verification
Register a device for User A and verify:
{ "userId": "...", "change": "device_added" }Revoke the device and verify:
device_revokedmessageMigration / Follow-ups
If explicit system message typing is desired:
messagestablecontent_typecolumn or enuminside
emitDeviceChangeEvent.Additional improvements:
Closes #155
Closes #168