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 did mailto package, replacing createDidMailtoFromEmail #722

Merged
merged 9 commits into from
Apr 4, 2023

Conversation

gobengo
Copy link
Contributor

@gobengo gobengo commented Apr 3, 2023

Motivation:

Breaking Changes

@gobengo gobengo marked this pull request as ready for review April 3, 2023 23:33
@gobengo gobengo requested review from Gozala and travis April 3, 2023 23:52
Copy link
Contributor

@Gozala Gozala left a comment

Choose a reason for hiding this comment

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

Suggested some suggestions, but ok to land as is as well

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Could we get rid of this module ? Maybe we could just add a function that does this into the new package ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally I didn't want to make a breaking change, and this function was exported from the package, but since both you and travis suggested it, and I verified we have no other repos depending on it, I went ahead and removed and marked this a breaking change.
93e29c6#diff-7136e328e23c0e6a0f91abc8e3007589dc0774d34a249b2001f9126d7d364029

`expected at least 2 @-delimtied segments, but got ${atParts.length}`
)
}
const domain = atParts.at(-1) ?? ''
Copy link
Contributor

Choose a reason for hiding this comment

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

Empty domain does not seems valid and should be an error perhaps worth considering checking it also has . in it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I personally would find it easier to follow this if it was something like:

const offset = email.lastIndexOf('@')
if (offset < 0 || email.length - offset <= 1) {
   throw
} else {
  const local = emal.slice(0, offset)
  const domain = email.slice(offset + 1)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we test that following fail email@ and [email protected]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both of those strings would match the EmailAddress type I have in here.
I'm willing to make it more picky to disallow those two cases, but let's do it in another PR. I looked into doing more strict email address parsing, and to do it fully feels like more work than is really useful. (and if you need that, they exist).

return `${decodeURIComponent(parts[3])}@${decodeURIComponent(parts[2])}`
}

/**
Copy link
Member

Choose a reason for hiding this comment

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

what's this email() function for? it seems like it pulls the email address apart just to put it back together again.

If we get rid of this then we can also get rid of https://github.com/web3-storage/w3up/pull/722/files#diff-7136e328e23c0e6a0f91abc8e3007589dc0774d34a249b2001f9126d7d364029 which would be great.

At the very least, could you add a comment here explaining why this exists?

Copy link
Contributor Author

@gobengo gobengo Apr 4, 2023

Choose a reason for hiding this comment

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

it accepts a string and returns an EmailAddress (which is more specific than a string)

it seems like it pulls the email address apart just to put it back together again.

It also throws an error if what you passed it is definitely not an EmailAddress

The motivation was because in @web3-storage/access/agent, sometimes email is string and sometimes its ${string}@${string}. In this commit you can see how when removing createDidMailtoFromEmail, one spot needed to parse string -> ${string}@${string} using this function, and another did not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

ah I see. it feels kind of weird to be doing runtime work (ie, pulling the string apart and then reassembling it into the same string) for what should be compile-time typechecking (ie, ensuring that strings that are emails have the EmailAddress type during compilation)

I could see this being valuable if we thought we might change the EmailAddress type in the future to be more complicated without changing all these APIs - is that the kind of flexibility you're hoping to buy with this?

If that's not an explicit goal, I wonder if it might be better to have fromEmail take a string | EmailAddress and throw if the string isn't an actual EmailAddress?

I guess one nice thing about factoring things this way is that you make that string -> EmailAddress conversion optional, only needed by folks who haven't already checked and case the raw string. This line of thinking makes me think that maybe the name is the problem here - email() just feels like a puzzling thing to have to call on my string before I can use it with this API - maybe stringToEmailAddress or ensureEmailAddress or something would read a bit better?

I'm also fine with just leaving as-is, but I may propose a name change in the future :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could see this being valuable if we thought we might change the EmailAddress type in the future to be more complicated without changing all these APIs - is that the kind of flexibility you're hoping to buy with this?

yeah

I guess one nice thing about factoring things this way is that you make that string -> EmailAddress conversion optional, only needed by folks who haven't already checked and case the raw string.

👍

but I may propose a name change in the future :)

That's okay. afaic there can be many names, and it's unlikely everyone will be happy with any one name.
https://en.wikipedia.org/wiki/Law_of_triviality

@gobengo gobengo changed the title feat: add did mailto package feat!: add did mailto package Apr 4, 2023
@gobengo gobengo changed the title feat!: add did mailto package feat!: add did mailto package, replacing createDidMailtoFromEmail Apr 4, 2023
@gobengo gobengo merged commit b48c256 into main Apr 4, 2023
@gobengo gobengo deleted the 682-did-mailto-package branch April 4, 2023 20:56
travis pushed a commit that referenced this pull request Apr 6, 2023
🤖 I have created a release *beep* *boop*
---


## 1.0.0 (2023-04-06)


### ⚠ BREAKING CHANGES

* add did mailto package, replacing `createDidMailtoFromEmail`
([#722](#722))

### Features

* add did mailto package, replacing `createDidMailtoFromEmail`
([#722](#722))
([b48c256](b48c256))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
travis pushed a commit that referenced this pull request Apr 6, 2023
🤖 I have created a release *beep* *boop*
---


##
[12.0.0](access-v11.2.0...access-v12.0.0)
(2023-04-06)


### ⚠ BREAKING CHANGES

* add did mailto package, replacing `createDidMailtoFromEmail`
([#722](#722))

### Features

* add did mailto package, replacing `createDidMailtoFromEmail`
([#722](#722))
([b48c256](b48c256))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
gobengo added a commit that referenced this pull request Apr 7, 2023
🤖 I have created a release *beep* *boop*
---


##
[6.0.0](access-api-v5.2.1...access-api-v6.0.0)
(2023-04-06)


### ⚠ BREAKING CHANGES

* add did mailto package, replacing `createDidMailtoFromEmail`
([#722](#722))

### Features

* add did mailto package, replacing `createDidMailtoFromEmail`
([#722](#722))
([b48c256](b48c256))


### Bug Fixes

* bug where did:mailto with pct-encoded email parts was not decoded
correctly ([#719](#719))
([7003dd2](7003dd2))
* upgrade toucan-js and @web3-storage/worker-utils
([#728](#728))
([976c77c](976c77c))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: Benjamin Goering <[email protected]>
gobengo added a commit that referenced this pull request Apr 11, 2023
…722)

Motivation:
* #682 

Breaking Changes
* remove `createDidMailtoFromEmail` export from
`@web3-storage/access/agent`
93e29c6#diff-69a4efe733b2d7920dc103a0370eb1a285403e39c41e1b5e9a0718ea66b5a32fL33
* no dependencies under our org:
https://github.com/search?q=org%3Aweb3-storage%20createDidMailtoFromEmail&type=code
* Motivation: encouragement [from
@Gozala](#722 (comment))
and
[@travis](#722 (comment))
in review
gobengo pushed a commit that referenced this pull request Apr 11, 2023
🤖 I have created a release *beep* *boop*
---


## 1.0.0 (2023-04-06)


### ⚠ BREAKING CHANGES

* add did mailto package, replacing `createDidMailtoFromEmail`
([#722](#722))

### Features

* add did mailto package, replacing `createDidMailtoFromEmail`
([#722](#722))
([5a4123f](5a4123f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
gobengo pushed a commit that referenced this pull request Apr 11, 2023
🤖 I have created a release *beep* *boop*
---


##
[12.0.0](access-v11.2.0...access-v12.0.0)
(2023-04-06)


### ⚠ BREAKING CHANGES

* add did mailto package, replacing `createDidMailtoFromEmail`
([#722](#722))

### Features

* add did mailto package, replacing `createDidMailtoFromEmail`
([#722](#722))
([5a4123f](5a4123f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
gobengo added a commit that referenced this pull request Apr 11, 2023
🤖 I have created a release *beep* *boop*
---


##
[6.0.0](access-api-v5.2.1...access-api-v6.0.0)
(2023-04-06)


### ⚠ BREAKING CHANGES

* add did mailto package, replacing `createDidMailtoFromEmail`
([#722](#722))

### Features

* add did mailto package, replacing `createDidMailtoFromEmail`
([#722](#722))
([5a4123f](5a4123f))


### Bug Fixes

* bug where did:mailto with pct-encoded email parts was not decoded
correctly ([#719](#719))
([c367639](c367639))
* upgrade toucan-js and @web3-storage/worker-utils
([#728](#728))
([853559d](853559d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: Benjamin Goering <[email protected]>
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.

3 participants