-
Notifications
You must be signed in to change notification settings - Fork 1
Backend v2 foundations #141
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
Merged
Merged
Changes from 42 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
7258784
Prisma model update
lourou e9d03eb
Data model migration
lourou 79bf2d8
Data model migration
lourou 85ff289
Update prisma and prisma client
lourou a1f9304
Implement JWT v2
lourou 849d6e6
Implement auth and notifications handlers
lourou 5778b6f
WIP notifications handlers
lourou fd1fbe6
Add path alias for prisma-zod
lourou 0b26361
Fix type and formatting
lourou c27648f
Fix lint and types
lourou 79f8ef2
Share the webhook between v1 and v2 API versions
lourou edf1d48
Validate hex string
lourou a539618
Fixes
lourou 6676e11
Fixes
lourou b33e2d9
Fixes
lourou 42b9637
Fixes
lourou 92230ba
Changed pushFailures to use atomic reset
lourou 9c6a812
Add transactions
lourou d44594d
Cache most used environment variables
lourou 0ed3839
Remove gatewayAuthorized
lourou bd456b5
Webhook handler header check as middleware
lourou 2b8698f
Fixes
lourou 929d1ed
Fixes
lourou 0554fbd
Fixes
lourou 03ff700
Fixes and adding debug logs
lourou fa467fc
Middleware update, better device registration
lourou 28ad060
Friendlier rate limiting
lourou f65f03b
Fix timestamp_ns (protobuf int64 compatibility)
lourou 98f0e05
Make v1 and v2 notifications payload live together during the migrati…
lourou 06775d6
Don't send encryptedMessage with welcomes over APNS
lourou d5b45a7
Enforce maxlength and non-empty value on deviceId and clientId
lourou 4875e82
Validate metadata size to prevent JWT bloat
lourou 52f966c
Refresh updatedAt by updating deviceId
lourou 53f7989
Cleanup notification server when needed
lourou 43a96f6
Better transactional consistency for cleanup of v2 notifications
lourou dd6ccf0
Better type safety for v1 and v2 notification types using union hat c…
lourou 3ab931e
Fix and protect webhook endpoint against configuration-based auth bypass
lourou bed066f
Protect against configuration-based auth bypass
lourou 7f2213d
Fixes and more generous rate limiting to accomodate multiple XMTP cli…
lourou ce6416c
Make pushToken nullable and unique
lourou 03ad380
Fix webhook auth, add return statements after errors
lourou 7aed79b
Fixes
lourou 9cb34ae
Handle the case when a push token is already registered to a differen…
lourou 6518628
Validate pushToken, allow null but not empty string
lourou cd880c8
Add missing return
lourou 8388fa9
Normalize pushToken empty string to null
lourou aec0b5c
Enforce UUID for clientId and deviceId as primary keys of our db
lourou 277d6fa
Invite proto update
lourou 6e0c0f6
Update invite v2 test with new proto
lourou 9c17fdd
Update invite slug
lourou 11ab9dc
Config update
lourou 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
37 changes: 37 additions & 0 deletions
37
prisma/migrations/20251003172324_add_v2_push_notification_models/migration.sql
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,37 @@ | ||
| -- CreateTable | ||
| CREATE TABLE "DeviceRegistration" ( | ||
| "deviceId" TEXT NOT NULL, | ||
| "pushToken" TEXT NOT NULL, | ||
| "pushTokenType" "PushTokenType" NOT NULL DEFAULT 'apns', | ||
| "apnsEnv" "ApnsEnvironment", | ||
| "pushFailures" INTEGER NOT NULL DEFAULT 0, | ||
| "disabled" BOOLEAN NOT NULL DEFAULT false, | ||
| "addedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" TIMESTAMP(3) NOT NULL, | ||
| "lastSentAt" TIMESTAMP(3), | ||
| "lastFailureAt" TIMESTAMP(3), | ||
|
|
||
| CONSTRAINT "DeviceRegistration_pkey" PRIMARY KEY ("deviceId") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "ClientIdentifier" ( | ||
| "id" TEXT NOT NULL, | ||
| "deviceId" TEXT NOT NULL, | ||
| "addedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
|
||
| CONSTRAINT "ClientIdentifier_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "DeviceRegistration_pushToken_idx" ON "DeviceRegistration"("pushToken"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "DeviceRegistration_disabled_pushFailures_idx" ON "DeviceRegistration"("disabled", "pushFailures"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "ClientIdentifier_deviceId_idx" ON "ClientIdentifier"("deviceId"); | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "ClientIdentifier" ADD CONSTRAINT "ClientIdentifier_deviceId_fkey" FOREIGN KEY ("deviceId") REFERENCES "DeviceRegistration"("deviceId") ON DELETE CASCADE ON UPDATE CASCADE; |
8 changes: 8 additions & 0 deletions
8
prisma/migrations/20251017193536_add_unique_constraint_to_push_tokens/migration.sql
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,8 @@ | ||
| -- AlterTable: Make pushToken nullable | ||
| ALTER TABLE "DeviceRegistration" ALTER COLUMN "pushToken" DROP NOT NULL; | ||
|
|
||
| -- Update any empty strings to NULL (clean up existing data) | ||
| UPDATE "DeviceRegistration" SET "pushToken" = NULL WHERE "pushToken" = ''; | ||
|
|
||
| -- CreateIndex: Add unique constraint on push token combination | ||
| CREATE UNIQUE INDEX "DeviceRegistration_pushTokenType_apnsEnv_pushToken_key" ON "DeviceRegistration"("pushTokenType", "apnsEnv", "pushToken"); |
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,9 @@ | ||
| /** | ||
| * Maximum number of consecutive push notification failures before disabling a device | ||
| */ | ||
| export const MAX_PUSH_FAILURES = 10; | ||
|
|
||
| /** | ||
| * Maximum size in bytes for JWT metadata to prevent token bloat | ||
| */ | ||
| export const MAX_JWT_METADATA_SIZE = 1024; // 1KB |
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.
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.