Skip to content

Commit 7418527

Browse files
committed
WIP
1 parent cd15bd0 commit 7418527

9 files changed

Lines changed: 19 additions & 345 deletions

File tree

src/api/v1/init/handlers/init.ts

Lines changed: 15 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ import { DeviceOS } from "@prisma/client";
22
import type { Request, Response } from "express";
33
import { z } from "zod";
44
import { prisma } from "@/utils/prisma";
5-
import { namestoneService } from "../../../../utils/namestone";
6-
import {
7-
validateOnChainName,
8-
validateUsernameUniqueness,
9-
} from "../../profiles/handlers/validate-profile";
105

116
export const createUserRequestBodySchema = z.object({
127
device: z.object({
@@ -19,12 +14,16 @@ export const createUserRequestBodySchema = z.object({
1914
xmtpId: z.string(),
2015
xmtpInstallationId: z.string().optional(), // TO DO remove optional once all users have fully migrated to newer version of app
2116
}),
22-
profile: z.object({
23-
name: z.string().min(1).optional(),
24-
username: z.string().min(1).optional(),
25-
description: z.string().nullable().optional(),
26-
avatar: z.string().url().nullable().optional(),
27-
}),
17+
// Profile data no longer accepted as profiles have been removed
18+
// Keeping for backwards compatibility but will be ignored
19+
profile: z
20+
.object({
21+
name: z.string().min(1).optional(),
22+
username: z.string().min(1).optional(),
23+
description: z.string().nullable().optional(),
24+
avatar: z.string().url().nullable().optional(),
25+
})
26+
.optional(),
2827
});
2928

3029
export type InitRequestBody = z.infer<typeof createUserRequestBodySchema>;
@@ -40,13 +39,7 @@ export type InitResponse = {
4039
identityAddress: string | null;
4140
xmtpId: string | null;
4241
};
43-
profile: {
44-
id: string;
45-
name: string | null;
46-
username: string | null;
47-
description: string | null;
48-
avatar: string | null;
49-
};
42+
profile: null; // Profiles have been removed, returning null for backwards compatibility
5043
};
5144

5245
export async function init(
@@ -70,28 +63,7 @@ export async function init(
7063
throw parseError;
7164
}
7265

73-
// Validate username uniqueness only if username is provided
74-
if (body.profile.username?.trim()) {
75-
const uniquenessResult = await validateUsernameUniqueness(
76-
body.profile.username,
77-
);
78-
if (!uniquenessResult.success) {
79-
res.status(400).json(uniquenessResult);
80-
return;
81-
}
82-
}
83-
84-
// If name contains a dot, validate on-chain name ownership
85-
if (body.profile.name && body.profile.name.includes(".")) {
86-
const onChainResult = await validateOnChainName({
87-
name: body.profile.name,
88-
xmtpId: body.identity.xmtpId,
89-
});
90-
if (!onChainResult.success) {
91-
res.status(400).json(onChainResult);
92-
return;
93-
}
94-
}
66+
// Profile validation removed as profiles are no longer supported
9567

9668
// Execute all database operations in a transaction to ensure atomicity
9769
const { device, deviceIdentity } = await prisma.$transaction(async (tx) => {
@@ -108,22 +80,11 @@ export async function init(
10880
},
10981
});
11082

111-
// Create device identity
83+
// Create device identity without profile (profiles have been removed)
11284
const deviceIdentity = await tx.deviceIdentity.create({
11385
data: {
11486
xmtpId: body.identity.xmtpId,
11587
identityAddress: body.identity.identityAddress,
116-
profile: {
117-
create: {
118-
name: body.profile.name || null,
119-
username: body.profile.username || null,
120-
description: body.profile.description,
121-
avatar: body.profile.avatar,
122-
},
123-
},
124-
},
125-
include: {
126-
profile: true,
12788
},
12889
});
12990

@@ -139,10 +100,6 @@ export async function init(
139100
return { device, deviceIdentity };
140101
});
141102

142-
if (!deviceIdentity.profile) {
143-
throw new Error("Profile was not created successfully");
144-
}
145-
146103
const returnedUser: InitResponse = {
147104
device: {
148105
id: device.id,
@@ -154,46 +111,10 @@ export async function init(
154111
identityAddress: deviceIdentity.identityAddress,
155112
xmtpId: deviceIdentity.xmtpId,
156113
},
157-
profile: {
158-
id: deviceIdentity.profile.id,
159-
name: deviceIdentity.profile.name,
160-
username: deviceIdentity.profile.username,
161-
description: deviceIdentity.profile.description,
162-
avatar: deviceIdentity.profile.avatar,
163-
},
114+
profile: null, // Profiles have been removed
164115
};
165116

166-
// Register the username with Namestone only if both username and identityAddress are available
167-
if (deviceIdentity.identityAddress && deviceIdentity.profile.username) {
168-
// Don't await to avoid blocking the user creation response
169-
namestoneService
170-
.setName({
171-
username: deviceIdentity.profile.username,
172-
address: deviceIdentity.identityAddress,
173-
textRecords: {
174-
...(deviceIdentity.profile.name && {
175-
"display.name": deviceIdentity.profile.name,
176-
}),
177-
...(deviceIdentity.profile.description && {
178-
description: deviceIdentity.profile.description,
179-
}),
180-
...(deviceIdentity.profile.avatar && {
181-
avatar: deviceIdentity.profile.avatar,
182-
}),
183-
},
184-
})
185-
.catch((namestoneError: unknown) => {
186-
// Log error but don't fail user creation
187-
req.log.error(
188-
{
189-
error: namestoneError,
190-
username: deviceIdentity.profile?.username,
191-
address: deviceIdentity.identityAddress,
192-
},
193-
"Failed to register username with Namestone during user creation",
194-
);
195-
});
196-
}
117+
// Namestone registration removed as profiles are no longer supported
197118

198119
res.status(201).json(returnedUser);
199120
} catch (error) {

src/middleware/auth.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ const NOTIFICATION_EXTENSION_ALLOWED_ROUTES = [
6262
{ method: "GET", path: "/api/v1/invites/:inviteId/with-group" },
6363
{ method: "GET", path: "/api/v1/invites/:inviteId" },
6464
{ method: "DELETE", path: "/api/v1/invites/:inviteId" },
65-
66-
// Profiles routes
67-
{ method: "GET", path: "/api/v1/profiles/search" },
68-
{ method: "GET", path: "/api/v1/profiles/check/:username" },
69-
{ method: "POST", path: "/api/v1/profiles/batch" },
70-
{ method: "GET", path: "/api/v1/profiles/:xmtpId" }, // For getting profile by xmtp ID
7165
].map((route) => ({
7266
...route,
7367
regexp: pathToRegexp(route.path), // Pre-compile the regex for better performance

tests/devices.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ afterAll(async () => {
5050

5151
beforeEach(async () => {
5252
// clean up the database before each test
53-
await prisma.profile.deleteMany();
5453
await prisma.identitiesOnDevice.deleteMany();
5554
await prisma.deviceIdentity.deleteMany();
5655
await prisma.device.deleteMany();

tests/init.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ afterAll(async () => {
3737

3838
beforeEach(async () => {
3939
// clean up the database before each test
40-
await prisma.profile.deleteMany();
4140
await prisma.identitiesOnDevice.deleteMany();
4241
await prisma.deviceIdentity.deleteMany();
4342
await prisma.device.deleteMany();
@@ -81,7 +80,8 @@ describe("/init API", () => {
8180
createUserBody.identity.identityAddress || null,
8281
);
8382
expect(user.identity.xmtpId).toBe(createUserBody.identity.xmtpId);
84-
expect(user.profile.name).toBe(createUserBody.profile.name ?? null);
83+
// Profile has been removed, should be null
84+
expect(user.profile).toBe(null);
8585
});
8686

8787
test("POST /init can create two users with different devices", async () => {

tests/invite-requests.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ beforeEach(async () => {
5454
await prisma.inviteCodeRequest.deleteMany();
5555
await prisma.inviteCodeUse.deleteMany();
5656
await prisma.inviteCode.deleteMany();
57-
await prisma.profile.deleteMany();
5857
await prisma.identitiesOnDevice.deleteMany();
5958
await prisma.deviceIdentity.deleteMany();
6059
await prisma.device.deleteMany();

tests/invites.test.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,18 @@ beforeEach(async () => {
5555
await prisma.inviteCodeRequest.deleteMany();
5656
await prisma.inviteCodeUse.deleteMany();
5757
await prisma.inviteCode.deleteMany();
58-
await prisma.profile.deleteMany();
5958
await prisma.identitiesOnDevice.deleteMany();
6059
await prisma.deviceIdentity.deleteMany();
6160
await prisma.device.deleteMany();
6261
});
6362

6463
// Helper function to create a test user with DeviceIdentity
6564
async function createTestUser(suffix = "", xmtpId = AUTH_USER_XMTP_ID) {
66-
// Create DeviceIdentity directly
65+
// Create DeviceIdentity directly (without profile)
6766
const deviceIdentity = await prisma.deviceIdentity.create({
6867
data: {
6968
xmtpId,
7069
identityAddress: `test-turnkey-address${suffix}`,
71-
profile: {
72-
create: {
73-
name: `Test User${suffix}`,
74-
username: `test-user${suffix.replace(/-/g, "")}`,
75-
description: "Test bio",
76-
},
77-
},
78-
},
79-
include: {
80-
profile: true,
8170
},
8271
});
8372

@@ -110,13 +99,7 @@ async function createTestUser(suffix = "", xmtpId = AUTH_USER_XMTP_ID) {
11099
identityAddress: deviceIdentity.identityAddress,
111100
xmtpId: deviceIdentity.xmtpId,
112101
},
113-
profile: {
114-
id: deviceIdentity.profile!.id,
115-
name: deviceIdentity.profile!.name,
116-
username: deviceIdentity.profile!.username,
117-
description: deviceIdentity.profile!.description,
118-
avatar: deviceIdentity.profile!.avatar,
119-
},
102+
profile: null, // Profiles have been removed
120103
} as InitResponse;
121104
}
122105

tests/notifications-invites.test.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ describe("Invite Notifications Integration", () => {
9797
await prisma.inviteCodeRequest.deleteMany();
9898
await prisma.inviteCodeUse.deleteMany();
9999
await prisma.inviteCode.deleteMany();
100-
await prisma.profile.deleteMany();
101100
await prisma.identitiesOnDevice.deleteMany();
102101
await prisma.deviceIdentity.deleteMany();
103102
await prisma.device.deleteMany();
@@ -109,15 +108,7 @@ describe("Invite Notifications Integration", () => {
109108
data: {
110109
xmtpId: "test-creator-xmtp-id-notifications",
111110
identityAddress: "0x1234creator",
112-
profile: {
113-
create: {
114-
name: "Test Creator",
115-
username: "testcreator",
116-
description: "Test creator user",
117-
},
118-
},
119111
},
120-
include: { profile: true },
121112
});
122113
const creatorDevice = await prisma.device.create({
123114
data: {
@@ -141,15 +132,7 @@ describe("Invite Notifications Integration", () => {
141132
data: {
142133
xmtpId: "test-requester-xmtp-id-notifications",
143134
identityAddress: "0x1234requester",
144-
profile: {
145-
create: {
146-
name: "Test Requester",
147-
username: "testrequester",
148-
description: "Test requester user",
149-
},
150-
},
151135
},
152-
include: { profile: true },
153136
});
154137
const requesterDevice = await prisma.device.create({
155138
data: {
@@ -173,15 +156,7 @@ describe("Invite Notifications Integration", () => {
173156
data: {
174157
xmtpId: "test-notification-target-xmtp-id",
175158
identityAddress: "0x1234notificationtarget",
176-
profile: {
177-
create: {
178-
name: "Test Notification Target",
179-
username: "testnotificationtarget",
180-
description: "Test notification target user",
181-
},
182-
},
183159
},
184-
include: { profile: true },
185160
});
186161
const notifyDevice = await prisma.device.create({
187162
data: {

tests/notifications.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ describe("/notifications API - Register/Unregister (Auth Required)", () => {
5959

6060
beforeEach(async () => {
6161
await prisma.identitiesOnDevice.deleteMany();
62-
await prisma.profile.deleteMany();
6362
await prisma.deviceIdentity.deleteMany();
6463
await prisma.device.deleteMany();
6564

0 commit comments

Comments
 (0)