Skip to content
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

remove pending from BE and DS #979

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions packages/backend/src/persistence/getDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ISessionDatabase } from '@dm3-org/dm3-lib-server-side';
import { UserStorage } from '@dm3-org/dm3-lib-storage';
import { PrismaClient } from '@prisma/client';
import { createClient } from 'redis';
import Pending from './pending';
import Session from './session';
import Storage from './storage';
import { ConversationRecord } from './storage/postgres/dto/ConversationRecord';
Expand All @@ -15,7 +14,6 @@ export enum RedisPrefix {
Sync = 'sync:',
Session = 'session:',
UserStorage = 'user.storage:',
Pending = 'pending:',
NotificationChannel = 'notificationChannel:',
GlobalNotification = 'globalNotification:',
Otp = 'otp:',
Expand Down Expand Up @@ -69,10 +67,6 @@ export async function getDatabase(
//Legacy remove after storage has been merged
getUserStorage: Storage.getUserStorageOld(redis),
setUserStorage: Storage.setUserStorageOld(redis),
//Pending
addPending: Pending.addPending(redis),
getPending: Pending.getPending(redis),
deletePending: Pending.deletePending(redis),
//Storage AddConversation
addConversation: Storage.addConversation(prisma),
getConversationList: Storage.getConversationList(prisma),
Expand Down Expand Up @@ -110,9 +104,6 @@ export interface IDatabase extends ISessionDatabase {
//Legacy remove after storage has been merged
getUserStorage: (ensName: string) => Promise<UserStorage | null>;
setUserStorage: (ensName: string, data: string) => Promise<void>;
addPending: (ensName: string, contactEnsName: string) => Promise<void>;
getPending: (ensName: string) => Promise<string[]>;
deletePending: (ensName: string) => Promise<void>;

addConversation: (
ensName: string,
Expand Down
11 changes: 0 additions & 11 deletions packages/backend/src/persistence/pending/addPending.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/backend/src/persistence/pending/deletePending.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/backend/src/persistence/pending/getPending.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/backend/src/persistence/pending/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/backend/src/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ describe('Profile', () => {
setSession: async (_: string, __: any) => {
return (_: any, __: any, ___: any) => {};
},
getPending: (_: any) => [],
getIdEnsName: async (ensName: string) => ensName,
};

Expand Down
43 changes: 0 additions & 43 deletions packages/delivery-service/src/delivery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,49 +69,6 @@ describe('Delivery', () => {
});
});

describe('getPendingMessages', () => {
it('Returns 200 if schema is valid', async () => {
const web3Provider = {
resolveName: async () =>
'0x99C19AB10b9EC8aC6fcda9586E81f6B73a298870',
};

const token = await createAuthToken(
'0x99C19AB10b9EC8aC6fcda9586E81f6B73a298870',
);

const db = {
getSession: async (ensName: string) => ({
challenge: 'deprecated challenge',
token: 'deprecated token that is not used anymore',
}),
setSession: async (_: string, __: any) => {
return (_: any, __: any, ___: any) => {};
},
getPending: (_: any) => [],
deletePending: (_: any) => [],
getIdEnsName: async (ensName: string) => ensName,
};
const app = express();
app.use(bodyParser.json());
app.use(
delivery(web3Provider as any, db as any, keysA, serverSecret),
);

const { status } = await request(app)
.post(
'/messages/0x99C19AB10b9EC8aC6fcda9586E81f6B73a298870/pending',
)
.set({
authorization: `Bearer ${token}`,
})

.send();

expect(status).toBe(200);
});
});

describe('syncAcknoledgment', () => {
it('Returns 200 if schema is valid', async () => {
const web3Provider = {
Expand Down
14 changes: 1 addition & 13 deletions packages/delivery-service/src/delivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default (
req.params.ensName,
//Fetch the last 10 messages per conversation
//If we decide to add pagination for that endpoint we can pass this value as a param
10,
1000,
);
res.json(incomingMessages);
} catch (e) {
Expand All @@ -97,18 +97,6 @@ export default (
},
);

router.post('/messages/:ensName/pending', async (req, res, next) => {
try {
const account = await db.getIdEnsName(req.params.ensName);
const pending = await db.getPending(account);
await db.deletePending(account);

res.json(pending);
} catch (e) {
next(e);
}
});

//TODO remove after storage refactoring
router.post(
'/messages/:ensName/syncAcknoledgment/:last_message_pull',
Expand Down
33 changes: 0 additions & 33 deletions packages/delivery-service/src/messaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,37 +249,4 @@ describe('Messaging', () => {
)(getSocketMock());
});
});

describe('pendingMessage', () => {
it('returns error if schema is invalid', async () => {
const data = {
accountAddress: '',
contactAddress: '',
};
const callback = jest.fn((e: any) => {
if (e.error !== 'invalid schema') {
throw Error(e);
}
expect(e.error).toBe('invalid schema');
});
const getSocketMock = jest.fn(() => {
return {
on: async (name: string, onPendingMessage: any) => {
//We just want to test the submitMessage callback fn
if (name === 'pendingMessage') {
await onPendingMessage(data, callback);
}
},
} as unknown as Socket;
});
onConnection(
io as any,
web3Provider as any,
db as any,
keysA,
serverSecret,
mockWsManager,
)(getSocketMock());
});
});
});
81 changes: 0 additions & 81 deletions packages/delivery-service/src/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ import { getDeliveryServiceProperties } from './config/getDeliveryServicePropert
import { IDatabase } from './persistence/getDatabase';
import { IWebSocketManager } from '@dm3-org/dm3-lib-shared';

const pendingMessageSchema = {
type: 'object',
properties: {
ensName: { type: 'string' },
contactEnsName: { type: 'string' },
token: { type: 'string' },
},
required: ['ensName', 'contactEnsName', 'token'],
additionalProperties: false,
};

export function onConnection(
io: Server,
web3Provider: ethers.providers.JsonRpcProvider,
Expand Down Expand Up @@ -116,75 +105,5 @@ export function onConnection(
}
},
);

/**
* Queue a message for a user that has not yet published their profile.
* The queue is managed on the delivery service of the sending user.
*/
socket.on('pendingMessage', async (data, callback) => {
const isSchemaValid = validateSchema(pendingMessageSchema, data);

if (!isSchemaValid) {
const error = 'invalid schema';
global.logger.warn({
method: 'WS PENDING MESSAGE',
error,
});

return callback({ error });
}

let idEnsName: string;
let idContactEnsName: string;
const ensName = normalizeEnsName(data.ensName);
const contactEnsName = normalizeEnsName(data.contactEnsName);

try {
idEnsName = await db.getIdEnsName(ensName);
idContactEnsName = await db.getIdEnsName(contactEnsName);
} catch (error) {
global.logger.warn({
method: 'WS PENDING MESSAGE',
error,
});

return callback({ error });
}

global.logger.info({
method: 'WS PENDING MESSAGE',
ensName,
contactEnsName,
});
try {
if (
!(await checkToken(
web3Provider,
db.getSession,
idEnsName,
data.token,
serverSecret,
))
) {
const error = 'Token check failed';
global.logger.warn({
method: 'WS PENDING MESSAGE',
error,
});
return callback({ error });
}

await db.addPending(ensName, idContactEnsName);

callback({ response: 'success' });
} catch (error) {
global.logger.warn({
method: 'WS PENDING MESSAGE',
error: (error as Error).toString(),
});

return callback({ error: "Can't add pending message" });
}
});
};
}
10 changes: 1 addition & 9 deletions packages/delivery-service/src/persistence/getDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Messages from './messages';
import { syncAcknowledge } from './messages/syncAcknowledge';
import Notification from './notification';
import Otp from './otp';
import Pending from './pending';
import Session from './session';

export enum RedisPrefix {
Expand All @@ -21,7 +20,6 @@ export enum RedisPrefix {
Sync = 'sync:',
Session = 'session:',
UserStorage = 'user.storage:',
Pending = 'pending:',
NotificationChannel = 'notificationChannel:',
GlobalNotification = 'globalNotification:',
Otp = 'otp:',
Expand Down Expand Up @@ -73,11 +71,8 @@ export async function getDatabase(
//Session
setSession: Session.setSession(redis),
getSession: Session.getSession(redis),
//Pending
addPending: Pending.addPending(redis),
getPending: Pending.getPending(redis),
deletePending: Pending.deletePending(redis),
getIdEnsName: getIdEnsName(redis),
//Sync
syncAcknowledge: syncAcknowledge(redis),
//Notification
getUsersNotificationChannels:
Expand Down Expand Up @@ -116,9 +111,6 @@ export interface IDatabase extends ISessionDatabase {
createdAt?: number,
) => Promise<void>;
deleteExpiredMessages: (time: number) => Promise<void>;
addPending: (ensName: string, contactEnsName: string) => Promise<void>;
getPending: (ensName: string) => Promise<string[]>;
deletePending: (ensName: string) => Promise<void>;
getIdEnsName: (ensName: string) => Promise<string>;
syncAcknowledge: (
conversationId: string,
Expand Down
11 changes: 0 additions & 11 deletions packages/delivery-service/src/persistence/pending/addPending.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/delivery-service/src/persistence/pending/deletePending.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/delivery-service/src/persistence/pending/getPending.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/delivery-service/src/persistence/pending/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/delivery-service/src/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ describe('Profile', () => {
setSession: async (_: string, __: any) => {
return (_: any, __: any, ___: any) => {};
},
getPending: (_: any) => [],
getIdEnsName: async (ensName: string) => ensName,
};
const app = express();
Expand Down Expand Up @@ -110,7 +109,6 @@ describe('Profile', () => {
setSession: async (_: string, __: any) => {
return (_: any, __: any, ___: any) => {};
},
getPending: (_: any) => [],
getIdEnsName: async (ensName: string) => ensName,
};

Expand Down
Loading
Loading