Skip to content

Commit 1d5684d

Browse files
author
Dylan Bulmer
authored
Bug fixes (#8)
* fix regex warnings * fix Error class generic * bump version * fix bugs
1 parent f6345bf commit 1d5684d

File tree

7 files changed

+17
-95
lines changed

7 files changed

+17
-95
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codrjs/core",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "An open-sourced customizable annotation tool",
55
"main": "index.js",
66
"repository": "[email protected]:CodrJS/Core.git",

src/classes/Email.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const EmailRegex =
2-
/^([-!#-'*+/-9=?A-Z^-~]+(\.[-!#-'*+/-9=?A-Z^-~]+)*|"(\[\]!#-[^-~ \t]|(\\[\t -~]))+")@([0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?(\.[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?)*|\[((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|IPv6:((((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){6}|::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){5}|[0-9A-Fa-f]{0,4}::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){4}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):)?(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){3}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,2}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){2}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,3}(0|[1-9A-F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f][0-9A-Fa-f]{0,3}):){0,2}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){2}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,3}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,4}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::)((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3})|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,5}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,6}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::)|(?!IPv6:)[0-9A-Za-z-]*[0-9A-Za-z]:[!-Z^-~]+)])$/g;
33

44
export default class Email {
55
private $email: string;

src/classes/Error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ interface IError {
44
status: number;
55
}
66

7-
export default class Error<Details> extends Response<Details> {
7+
export default class Error<Details = undefined> extends Response<Details> {
88
status: IError["status"];
99

1010
constructor({ status, message }: IError & IResponse<Details>) {

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ import App from "./services/app";
33
const Codr = { App };
44

55
export { default as App } from "./services/app";
6+
export { default as Mail } from "./services/mail";
7+
export { default as Authentication } from "./services/auth";
68
export default Codr;

src/models/Profile.ts

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,11 @@
1-
import { EmailRegex } from "../classes/Email";
21
import { Schema, model } from "mongoose";
3-
// import { sign } from "jsonwebtoken";
4-
5-
const UserProfileProvider = new Schema({
6-
photo: { type: String },
7-
phone: { type: String },
8-
email: { type: String },
9-
uid: { type: String, required: [true, "Provider's user id is required"] },
10-
});
112

123
/* UserSchema will correspond to a collection in your MongoDB database. */
134
const UserProfileSchema = new Schema(
14-
{
15-
name: {
16-
type: String,
17-
required: [true, "Name is required."],
18-
},
19-
email: {
20-
type: String,
21-
lowercase: true,
22-
required: [true, "Email cannot be blank."],
23-
match: [
24-
// eslint-disable-next-line no-control-regex
25-
EmailRegex,
26-
"is invalid.",
27-
],
28-
index: true,
29-
},
30-
providers: {
31-
type: [UserProfileProvider],
32-
},
33-
},
5+
{},
346
{
357
timestamps: true,
36-
virtuals: {
37-
firstName: {
38-
get() {
39-
const displayNameRegex =
40-
/(?<lastName>\w+),(?<firstName>\w+)<?(?<preferredName>\w+)?>?/gm;
41-
const result = displayNameRegex.exec(<string>this.name);
42-
43-
// set name data
44-
if (result?.groups) {
45-
const { firstName } = result.groups;
46-
return firstName;
47-
}
48-
},
49-
},
50-
lastName: {
51-
get() {
52-
const displayNameRegex =
53-
/(?<lastName>\w+),(?<firstName>\w+)<?(?<preferredName>\w+)?>?/gm;
54-
const result = displayNameRegex.exec(<string>this.name);
55-
56-
// set name data
57-
if (result?.groups) {
58-
const { lastName } = result.groups;
59-
return lastName;
60-
}
61-
},
62-
},
63-
preferredName: {
64-
get() {
65-
const displayNameRegex =
66-
/(?<lastName>\w+),(?<firstName>\w+)<?(?<preferredName>\w+)?>?/gm;
67-
const result = displayNameRegex.exec(<string>this.name);
68-
69-
// set name data
70-
if (result?.groups) {
71-
const { preferredName } = result.groups;
72-
return preferredName;
73-
}
74-
},
75-
},
76-
name: {
77-
get() {
78-
const displayNameRegex =
79-
/(?<lastName>\w+),(?<firstName>\w+)<?(?<preferredName>\w+)?>?/gm;
80-
const result = displayNameRegex.exec(<string>this.name);
81-
82-
// set name data
83-
if (result?.groups) {
84-
const { firstName, lastName } = result.groups;
85-
return firstName + " " + lastName;
86-
}
87-
},
88-
},
89-
},
8+
virtuals: {},
909
methods: {
9110
// generateJWT: {
9211
// get() {
@@ -108,5 +27,5 @@ const UserProfileSchema = new Schema(
10827
);
10928

11029
// exports User model.
111-
const UserProfile = model("UserProfile", UserProfileSchema)
30+
const UserProfile = model("UserProfile", UserProfileSchema);
11231
export default UserProfile;

src/models/User.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const UserSchema = new Schema(
9999
}
100100
},
101101
},
102-
name: {
102+
fullname: {
103103
get() {
104104
const displayNameRegex =
105105
/(?<lastName>\w+),(?<firstName>\w+)<?(?<preferredName>\w+)?>?/gm;

src/services/auth.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ class Authentication {
2222

2323
// }
2424

25-
async signinWithEmail({ email, accessToken }: { email: Email; accessToken?: string }) {
25+
async signinWithEmail({
26+
email,
27+
accessToken,
28+
}: {
29+
email: Email;
30+
accessToken?: string;
31+
}): Promise<Response<undefined | { token: string }>> {
2632
if (!email)
2733
throw new Error({
2834
status: 400,
@@ -37,12 +43,7 @@ class Authentication {
3743
try {
3844
const user = await User.findOne({ email });
3945
if (!user) {
40-
// let reg = await register(email);
41-
// res.send({
42-
// ok: true,
43-
// message:
44-
// "Your account has been created, click the link in email to sign in 👻",
45-
// });
46+
// is user cannot be found, then they are not allowed in.
4647
throw new Error({
4748
status: 401,
4849
message:

0 commit comments

Comments
 (0)