-
Notifications
You must be signed in to change notification settings - Fork 15
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
base: master
Are you sure you want to change the base?
Conversation
a108555
to
3d7c8df
Compare
f1150db
to
2967361
Compare
2967361
to
6993a1a
Compare
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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, {}); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
export async function action(message: Message): Promise<void> { | ||
await envelopDB.queryAsync('DELETE FROM subscribers WHERE address = ? AND verified > 0 LIMIT 1', [ |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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
This PR adds support for some of email subscriptions management through sequencer.
What will be supported (but same features still supported directly from envelop):
What will not be supported (and will remain on envelop):
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 subscriptionsdelete-email-subscription
: will delete a verified subscriptionHow to test
Features
Create a subscription
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 aemail 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
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, oremail not subscribed
when not existing.Delete a subscription
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