hapijs / address Goto Github PK
View Code? Open in Web Editor NEWValidate email addresses
License: Other
Validate email addresses
License: Other
Hi, thanks for the template and the code of conduct - very inspirational words. Hope everything will be ok with this issue.
I'd like to use this address
module: it is very exhaustive and I love the detailed feedback it gives back in case of error.
But I also need to translate error codes so I would like to have a list of all errors used and / or error codes. In my case have a translation/error-codes is mandatory and can compromise to use or not this library.
I'm here to discuss what is the best way to do it (if this can be a good idea for the maintainer) and hopefully find the time to have a mini pull-request.
One idea can be:
const errorsByCode = {
BE_STRING: 'Invalid input: email must be a string',
BE_NON_EMPTY_STRING: 'Address must be a non-empty string',
// ....
};
module.exports = {
errorsByCode,
domain: {
// ....
},
email: {
// ....
}
};
// use the error-codes in the rest of the source code
What do you think?
🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨
To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.
Since we didn’t receive a CI status on the greenkeeper/initial
branch, it’s possible that you don’t have CI set up yet.
We recommend using:
If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/
.
Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.
Staying in sync with hapi ecosystem.
Hi,
Atm we use Joi 14 which uses isEmail to validate email addresses.
We use it like this: Joi.string().email({ errorLevel: 68 })
.
As you can see we use the errorLevel to make the validation more relaxed, mainly for long email addresses.
Now the upgrade to a newer Joi version replaced isEmail with this module leaving us with no 'out of the box' option to migrate our email validation without breaking it.
I understand that this module tries to validate to spec as much as possible for our use case this strictness is just a bit too much (sadly :P).
The spec also states 4.5.3.1. Size Limits and Minimums [...] To the maximum extent possible, implementation techniques that impose no limits on the length of these objects should be used.
Would you consider an option to allow longer addresses and then exposing said option through Joi.email()?
I think it is mostly around this line https://github.com/hapijs/address/blob/master/lib/index.js#L98
If you want I can submit a PR for this.
I am trying to validate the following email provided by a customer (hello@1global
). While not common, it is a valid email without a tld that starts with a digit. This is how the domain is verified:
domain.analyze('1global', {minDomainSegments: 1, tlds: false})
// { error: 'Domain contains invalid character' }
The domain 1global
was invalid, and therefore the email hello@1global
was invalid as well
I expected the domain 1global
to be valid with the provided options, and therefore the email hello@1global
to be valid as well.
We are trying to verify emails using Joi. Following snippet demonstrates the way we are using Joi. The variable failingPayload
contains the email address which Joi rejects. The email domain "dpllp.cpa" is valid
const joiSchema = Joi.object({
emailAddress: Joi.string().email().required(),
});
const failingPayload = {
emailAdress: "[email protected]"
};
Joi.assert(failingPayload, joiSchema)
We got validation error stating that the email address is invalid.
Since this email is valid. We expect Joi to pass this validation.
Looking at the API docs (here), we figured out that this validation uses IANA TLD list. However, the TLD CPA
is present in (IANA TLD Directory)
Reverting #4 as it increases bundle size by 12K. Basically, the node Url shim it pretty big and includes punycode anyways so this saves nothing for now.
Convert the module to native TS code and export an ESM module.
V1-Commercial branch is missing API.md file
This module is very confusing. We used older version 4.1.0 of @hapi/address for build-in tlds list. Now that we make upgrade to the latest version 5.1.1 this tlds list is just gone! There no mention about it, aside of in here but without any reference to commit or PR. It just states
Remove built-in TLDS list support (moved to new @sideway/tlds module)
but such package not exists in npm! After some digging I finally found tlds list was removed in this commit
Also I noticed that in npm present @sideways/address 5.0.0 It looks like joi have some fight with hapi, your own business, but please do update documentation properly and explain where things going, why and which are latest and correst modules, and in old and deprecated ones state that they are deprecated, it is a mess now!
As discussed in the celebrate
repo under issue #222, I'm getting an error when trying to validate a link inside my schema. I have detailed all the code I'm running under the celebrate issue, so if you guys need to see the code I suggest you link to that issue. This is the schema I'm referring to:
link: Joi.string()
.uri({
domain: {
tlds: {
allow: true,
},
},
})
.required()
And this is the content I'm trying to validate:
http:/instagram.com or http:instagram.com
So the issue I've been having with this is that whenever I try to pass on an invalid uri like the ones from the example above (missing a forward slash or both) I get an invalid input error.
This is the error message I got:
Error: Invalid input: domain must be a string
at Object.exports.analyze (/Users/dev/Documents/Projetos/backend/node_modules/@sideway/address/lib/domain.js:21:15)
at Object.exports.isValid (/Users/dev/Documents/Projetos/backend/node_modules/@sideway/address/lib/domain.js:101:21)
at Object.validate (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/types/string.js:653:33)
at Object.internals.rules (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/validator.js:394:33)
at Object.exports.validate (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/validator.js:350:22)
at internals.Base.$_validate (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/base.js:773:26)
at Object.validate (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/types/keys.js:108:45)
at Object.exports.validate (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/validator.js:325:26)
at internals.Base.$_validate (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/base.js:773:26)
at Object.validate (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/types/array.js:273:45)
I expect the library to identify my input as a wrong domain format and validate it accordingly giving me back a validation message instead of an error.
Route definition:
server.route({
method: "POST",
path: "/register",
options: {
validate: {
payload: {
user: Joi.string().email().required(),
password: Joi.string().min(8).required()
}
},
},
handler: async (request, h) =>
{
return "Got here";
}
});
Request:
POST /register HTTP/1.1
Host: localhost:3000
User-Agent: curl/7.64.1
Accept: */*
Content-Type: application/json
Content-Length: 52
{"user":"\"one\"@email.com","password":"longenough"}
{"statusCode":400,"error":"Bad Request","message":"Invalid payload input"}
Using [email protected]
instead of "one"@email.com
works as expected
Got here
pathAbEmpty
in hierPart
Continued from hapijs/joi#2360
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.