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

feat: add email subscriptions #470

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

feat: add email subscriptions #470

wants to merge 8 commits into from

Conversation

wa0x6e
Copy link
Contributor

@wa0x6e wa0x6e commented Nov 12, 2024

This PR adds support for some of email subscriptions management through sequencer.

What will be supported (but same features still supported directly from envelop):

  • create a new subscription
  • update the subscription
  • delete a subscription

What will not be supported (and will remain on envelop):

  • Email verification

This PR will make use of new changes from snapshot-labs/snapshot.js#1081

This PR introduces 2 new writers:

  • email-subscription: will create a new subscription when passing an email, else will update existing subscriptions
  • delete-email-subscription: will delete a verified subscription

How to test

Features

Create a subscription

await client.emailSubscription(wallet, wallet.address, {
    email: '[email protected]',
    subscriptions: []
  });  

This call from the SDK will create a new email subscription, if user is not subscribed yet.
In case the couple wallet.address/email already exist, it will return a email already subscribed error.

This call will create a new unverified email subscription. The user will then receive an email on the given email address asking the user to verify his email (verification will be done through envelop directly)

For test purpose, you have to connect to the database, and update the verified column to something greater than 0 to continue testing update and deletion.

The subscriptions value is empty, and always ignored on creation, and will default to everything.

Update a subscription

await client.emailSubscription(wallet, wallet.address, {
    subscriptions: ['summary']
  });  

This call from the SDK will update an existing subscription.

The email property is skipped (and uncessary), as there can be only one verified email associated to the wallet.

This call will fail with email not verified if email is not verified, or email not subscribed when not existing.

Delete a subscription

await client.deleteEmailSubscription(wallet, wallet.address, {});  

This call from the SDK will delete the active email subscription associated to the address.

Once again, email is not passed for privacy reason (and also unecessary), and this will delete the verified email subscription if any.

Call will fail with email not subscribed if there's not verified email subscription to delete.

For the email-subscription type, ipfs pinning will be skipped on email creation, and an empty string will be returned instead, as to not expose the user's email. (ipfs still pinning for email subscription update)

Todo

@wa0x6e wa0x6e force-pushed the feat-add-subscription branch 6 times, most recently from a108555 to 3d7c8df Compare November 13, 2024 10:37
@wa0x6e wa0x6e force-pushed the feat-add-subscription branch 4 times, most recently from f1150db to 2967361 Compare November 16, 2024 08:09
@wa0x6e wa0x6e marked this pull request as ready for review November 16, 2024 08:18
@wa0x6e wa0x6e requested a review from ChaituVR November 18, 2024 04:07
@wa0x6e
Copy link
Contributor Author

wa0x6e commented Nov 18, 2024

Tests are failing for issue unrelated to this PR, should he fixed via #469

const sequencerDB = mysql.createPool(sequencerConfig);

export { hubDB as default, sequencerDB };
// @ts-ignore
const envelopConfig = parse(process.env.ENVELOP_DATABASE_URL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make this optional

@@ -31,6 +31,10 @@ const NETWORK_METADATA = {
}
};

function shouldPinIpfs(type: string, message: any) {
return !(type === 'email-subscription' && message.email);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can exclude if it is email-subscription and delete-email-subscription
irrespective email. because it doesn't make sense to save few and exclude few

@@ -5,6 +5,7 @@ import { DEFAULT_NETWORK_ID, jsonParse, NETWORK_IDS } from '../helpers/utils';

export async function verify(body): Promise<any> {
const msg = jsonParse(body.msg, {});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

}

export async function action(message: Message): Promise<void> {
await envelopDB.queryAsync('DELETE FROM subscribers WHERE address = ? AND verified > 0 LIMIT 1', [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should delete even if it is not verified no? if I add some wrong email by mistake

subscriptions JSON DEFAULT NULL,
created BIGINT NOT NULL,
verified BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (email, address),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The primary key can be just address no? because a user cannot use multiple emails. this will help us to use queries like INSERT ... ON DUPLICATE KEY UPDATE to insert or update email subscription in src/writer/email-subscription.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants