wabe 0.6.11 → 0.6.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authentication/Session.d.ts +10 -12
- package/dist/authentication/cookies.d.ts +1 -0
- package/dist/authentication/index.d.ts +1 -0
- package/dist/authentication/interface.d.ts +20 -0
- package/dist/authentication/security.d.ts +18 -0
- package/dist/database/DatabaseController.d.ts +57 -3
- package/dist/database/interface.d.ts +5 -0
- package/dist/file/interface.d.ts +23 -0
- package/dist/file/security.d.ts +6 -0
- package/dist/graphql/GraphQLSchema.d.ts +1 -1
- package/dist/graphql/resolvers.d.ts +1 -0
- package/dist/hooks/protected.d.ts +3 -0
- package/dist/hooks/virtualFields.d.ts +3 -0
- package/dist/index.js +1757 -818
- package/dist/schema/Schema.d.ts +66 -7
- package/dist/server/index.d.ts +2 -1
- package/dist/server/routes/index.d.ts +4 -1
- package/dist/utils/database.d.ts +1 -0
- package/dist/utils/export.d.ts +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +7 -4
- package/bucket/b.txt +0 -1
- package/dev/index.ts +0 -215
- package/generated/schema.graphql +0 -1892
- package/generated/wabe.ts +0 -439
- package/src/authentication/OTP.test.ts +0 -69
- package/src/authentication/OTP.ts +0 -64
- package/src/authentication/Session.test.ts +0 -629
- package/src/authentication/Session.ts +0 -493
- package/src/authentication/defaultAuthentication.ts +0 -209
- package/src/authentication/index.ts +0 -3
- package/src/authentication/interface.ts +0 -155
- package/src/authentication/oauth/GitHub.test.ts +0 -91
- package/src/authentication/oauth/GitHub.ts +0 -121
- package/src/authentication/oauth/Google.test.ts +0 -91
- package/src/authentication/oauth/Google.ts +0 -101
- package/src/authentication/oauth/Oauth2Client.test.ts +0 -219
- package/src/authentication/oauth/Oauth2Client.ts +0 -135
- package/src/authentication/oauth/index.ts +0 -2
- package/src/authentication/oauth/utils.test.ts +0 -33
- package/src/authentication/oauth/utils.ts +0 -27
- package/src/authentication/providers/EmailOTP.test.ts +0 -127
- package/src/authentication/providers/EmailOTP.ts +0 -84
- package/src/authentication/providers/EmailPassword.test.ts +0 -176
- package/src/authentication/providers/EmailPassword.ts +0 -116
- package/src/authentication/providers/EmailPasswordSRP.test.ts +0 -208
- package/src/authentication/providers/EmailPasswordSRP.ts +0 -179
- package/src/authentication/providers/GitHub.ts +0 -24
- package/src/authentication/providers/Google.ts +0 -24
- package/src/authentication/providers/OAuth.test.ts +0 -185
- package/src/authentication/providers/OAuth.ts +0 -106
- package/src/authentication/providers/PhonePassword.test.ts +0 -176
- package/src/authentication/providers/PhonePassword.ts +0 -115
- package/src/authentication/providers/QRCodeOTP.test.ts +0 -77
- package/src/authentication/providers/QRCodeOTP.ts +0 -58
- package/src/authentication/providers/index.ts +0 -6
- package/src/authentication/resolvers/refreshResolver.test.ts +0 -30
- package/src/authentication/resolvers/refreshResolver.ts +0 -19
- package/src/authentication/resolvers/signInWithResolver.inte.test.ts +0 -59
- package/src/authentication/resolvers/signInWithResolver.test.ts +0 -293
- package/src/authentication/resolvers/signInWithResolver.ts +0 -92
- package/src/authentication/resolvers/signOutResolver.test.ts +0 -38
- package/src/authentication/resolvers/signOutResolver.ts +0 -18
- package/src/authentication/resolvers/signUpWithResolver.test.ts +0 -180
- package/src/authentication/resolvers/signUpWithResolver.ts +0 -65
- package/src/authentication/resolvers/verifyChallenge.test.ts +0 -133
- package/src/authentication/resolvers/verifyChallenge.ts +0 -62
- package/src/authentication/roles.test.ts +0 -49
- package/src/authentication/roles.ts +0 -40
- package/src/authentication/utils.test.ts +0 -97
- package/src/authentication/utils.ts +0 -39
- package/src/cache/InMemoryCache.test.ts +0 -62
- package/src/cache/InMemoryCache.ts +0 -45
- package/src/cron/index.test.ts +0 -17
- package/src/cron/index.ts +0 -43
- package/src/database/DatabaseController.test.ts +0 -613
- package/src/database/DatabaseController.ts +0 -1007
- package/src/database/index.test.ts +0 -1372
- package/src/database/index.ts +0 -9
- package/src/database/interface.ts +0 -302
- package/src/email/DevAdapter.ts +0 -7
- package/src/email/EmailController.test.ts +0 -29
- package/src/email/EmailController.ts +0 -13
- package/src/email/index.ts +0 -2
- package/src/email/interface.ts +0 -36
- package/src/email/templates/sendOtpCode.ts +0 -120
- package/src/file/FileController.ts +0 -28
- package/src/file/FileDevAdapter.ts +0 -51
- package/src/file/hookDeleteFile.ts +0 -25
- package/src/file/hookReadFile.ts +0 -66
- package/src/file/hookUploadFile.ts +0 -50
- package/src/file/index.test.ts +0 -932
- package/src/file/index.ts +0 -2
- package/src/file/interface.ts +0 -39
- package/src/graphql/GraphQLSchema.test.ts +0 -4408
- package/src/graphql/GraphQLSchema.ts +0 -880
- package/src/graphql/index.ts +0 -2
- package/src/graphql/parseGraphqlSchema.ts +0 -85
- package/src/graphql/parser.test.ts +0 -203
- package/src/graphql/parser.ts +0 -542
- package/src/graphql/pointerAndRelationFunction.ts +0 -191
- package/src/graphql/resolvers.ts +0 -442
- package/src/graphql/tests/aggregation.test.ts +0 -1115
- package/src/graphql/tests/e2e.test.ts +0 -590
- package/src/graphql/tests/scalars.test.ts +0 -250
- package/src/graphql/types.ts +0 -227
- package/src/hooks/HookObject.test.ts +0 -122
- package/src/hooks/HookObject.ts +0 -165
- package/src/hooks/authentication.ts +0 -67
- package/src/hooks/createUser.test.ts +0 -77
- package/src/hooks/createUser.ts +0 -10
- package/src/hooks/defaultFields.test.ts +0 -176
- package/src/hooks/defaultFields.ts +0 -32
- package/src/hooks/deleteSession.test.ts +0 -181
- package/src/hooks/deleteSession.ts +0 -20
- package/src/hooks/hashFieldHook.test.ts +0 -152
- package/src/hooks/hashFieldHook.ts +0 -89
- package/src/hooks/index.test.ts +0 -258
- package/src/hooks/index.ts +0 -414
- package/src/hooks/permissions.test.ts +0 -412
- package/src/hooks/permissions.ts +0 -93
- package/src/hooks/protected.test.ts +0 -551
- package/src/hooks/protected.ts +0 -60
- package/src/hooks/searchableFields.test.ts +0 -147
- package/src/hooks/searchableFields.ts +0 -86
- package/src/hooks/session.test.ts +0 -134
- package/src/hooks/session.ts +0 -76
- package/src/hooks/setEmail.test.ts +0 -216
- package/src/hooks/setEmail.ts +0 -33
- package/src/hooks/setupAcl.test.ts +0 -618
- package/src/hooks/setupAcl.ts +0 -25
- package/src/index.ts +0 -9
- package/src/schema/Schema.test.ts +0 -482
- package/src/schema/Schema.ts +0 -757
- package/src/schema/defaultResolvers.ts +0 -93
- package/src/schema/index.ts +0 -1
- package/src/schema/resolvers/meResolver.test.ts +0 -62
- package/src/schema/resolvers/meResolver.ts +0 -10
- package/src/schema/resolvers/resetPassword.test.ts +0 -341
- package/src/schema/resolvers/resetPassword.ts +0 -63
- package/src/schema/resolvers/sendEmail.test.ts +0 -118
- package/src/schema/resolvers/sendEmail.ts +0 -21
- package/src/schema/resolvers/sendOtpCode.test.ts +0 -141
- package/src/schema/resolvers/sendOtpCode.ts +0 -52
- package/src/security.test.ts +0 -3434
- package/src/server/defaultSessionHandler.test.ts +0 -62
- package/src/server/defaultSessionHandler.ts +0 -105
- package/src/server/generateCodegen.ts +0 -433
- package/src/server/index.test.ts +0 -532
- package/src/server/index.ts +0 -334
- package/src/server/interface.ts +0 -11
- package/src/server/routes/authHandler.ts +0 -169
- package/src/server/routes/index.ts +0 -39
- package/src/utils/crypto.test.ts +0 -41
- package/src/utils/crypto.ts +0 -105
- package/src/utils/export.ts +0 -11
- package/src/utils/helper.ts +0 -204
- package/src/utils/index.test.ts +0 -11
- package/src/utils/index.ts +0 -189
- package/src/utils/preload.ts +0 -8
- package/src/utils/testHelper.ts +0 -116
- package/tsconfig.json +0 -32
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type { MutationResolver, QueryResolver } from './Schema'
|
|
2
|
-
import { meResolver } from './resolvers/meResolver'
|
|
3
|
-
import { sendEmailResolver } from './resolvers/sendEmail'
|
|
4
|
-
import { resetPasswordResolver } from './resolvers/resetPassword'
|
|
5
|
-
import { sendOtpCodeResolver } from './resolvers/sendOtpCode'
|
|
6
|
-
|
|
7
|
-
export const defaultQueries: {
|
|
8
|
-
[key: string]: QueryResolver<any>
|
|
9
|
-
} = {
|
|
10
|
-
me: {
|
|
11
|
-
type: 'Object',
|
|
12
|
-
outputObject: {
|
|
13
|
-
name: 'MeOutput',
|
|
14
|
-
fields: {
|
|
15
|
-
user: {
|
|
16
|
-
type: 'Pointer',
|
|
17
|
-
class: 'User',
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
resolve: meResolver,
|
|
22
|
-
},
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const defaultMutations: {
|
|
26
|
-
[key: string]: MutationResolver<any>
|
|
27
|
-
} = {
|
|
28
|
-
resetPassword: {
|
|
29
|
-
type: 'Boolean',
|
|
30
|
-
description: 'Mutation to reset the password of the user',
|
|
31
|
-
args: {
|
|
32
|
-
input: {
|
|
33
|
-
password: {
|
|
34
|
-
type: 'String',
|
|
35
|
-
required: true,
|
|
36
|
-
},
|
|
37
|
-
email: {
|
|
38
|
-
type: 'Email',
|
|
39
|
-
},
|
|
40
|
-
phone: {
|
|
41
|
-
type: 'String',
|
|
42
|
-
},
|
|
43
|
-
otp: {
|
|
44
|
-
type: 'String',
|
|
45
|
-
required: true,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
resolve: resetPasswordResolver,
|
|
50
|
-
},
|
|
51
|
-
sendOtpCode: {
|
|
52
|
-
type: 'Boolean',
|
|
53
|
-
description: 'Send an OTP code by email to the user',
|
|
54
|
-
args: {
|
|
55
|
-
input: {
|
|
56
|
-
email: {
|
|
57
|
-
type: 'Email',
|
|
58
|
-
required: true,
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
resolve: sendOtpCodeResolver,
|
|
63
|
-
},
|
|
64
|
-
sendEmail: {
|
|
65
|
-
type: 'String',
|
|
66
|
-
description: 'Send basic email with text and html, returns the id of the email',
|
|
67
|
-
args: {
|
|
68
|
-
input: {
|
|
69
|
-
from: {
|
|
70
|
-
type: 'String',
|
|
71
|
-
required: true,
|
|
72
|
-
},
|
|
73
|
-
to: {
|
|
74
|
-
type: 'Array',
|
|
75
|
-
typeValue: 'String',
|
|
76
|
-
required: true,
|
|
77
|
-
requiredValue: true,
|
|
78
|
-
},
|
|
79
|
-
subject: {
|
|
80
|
-
type: 'String',
|
|
81
|
-
required: true,
|
|
82
|
-
},
|
|
83
|
-
text: {
|
|
84
|
-
type: 'String',
|
|
85
|
-
},
|
|
86
|
-
html: {
|
|
87
|
-
type: 'String',
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
resolve: sendEmailResolver,
|
|
92
|
-
},
|
|
93
|
-
}
|
package/src/schema/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Schema'
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { describe, beforeAll, afterAll, it, expect } from 'bun:test'
|
|
2
|
-
import type { Wabe } from '../../server'
|
|
3
|
-
import { getAdminUserClient, type DevWabeTypes } from '../../utils/helper'
|
|
4
|
-
import { setupTests, closeTests } from '../../utils/testHelper'
|
|
5
|
-
import { gql } from 'graphql-request'
|
|
6
|
-
|
|
7
|
-
describe('me', () => {
|
|
8
|
-
let wabe: Wabe<DevWabeTypes>
|
|
9
|
-
|
|
10
|
-
beforeAll(async () => {
|
|
11
|
-
const setup = await setupTests()
|
|
12
|
-
wabe = setup.wabe
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
afterAll(async () => {
|
|
16
|
-
await closeTests(wabe)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('should return information about current user', async () => {
|
|
20
|
-
const adminClient = await getAdminUserClient(wabe.config.port, wabe, {
|
|
21
|
-
email: 'admin@wabe.dev',
|
|
22
|
-
password: 'admin',
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
const {
|
|
26
|
-
me: { user },
|
|
27
|
-
} = await adminClient.request<any>(graphql.me)
|
|
28
|
-
|
|
29
|
-
expect(user.role.name).toBe('Admin')
|
|
30
|
-
|
|
31
|
-
expect(user.authentication.emailPassword.email).toBe('admin@wabe.dev')
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
const graphql = {
|
|
36
|
-
signUpWith: gql`
|
|
37
|
-
mutation signUpWith($input: SignUpWithInput!) {
|
|
38
|
-
signUpWith(input: $input) {
|
|
39
|
-
id
|
|
40
|
-
accessToken
|
|
41
|
-
refreshToken
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
`,
|
|
45
|
-
me: gql`
|
|
46
|
-
query me {
|
|
47
|
-
me {
|
|
48
|
-
user {
|
|
49
|
-
id
|
|
50
|
-
authentication {
|
|
51
|
-
emailPassword {
|
|
52
|
-
email
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
role {
|
|
56
|
-
name
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
`,
|
|
62
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { WabeContext } from '../../server/interface'
|
|
2
|
-
import type { DevWabeTypes } from '../../utils/helper'
|
|
3
|
-
|
|
4
|
-
export const meResolver = (_: any, __: any, context: WabeContext<DevWabeTypes>) => {
|
|
5
|
-
if (!context.user?.id) return { user: undefined }
|
|
6
|
-
|
|
7
|
-
return {
|
|
8
|
-
user: context.user,
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
import { describe, it, afterAll, beforeAll, expect, beforeEach } from 'bun:test'
|
|
2
|
-
import { gql, type GraphQLClient } from 'graphql-request'
|
|
3
|
-
import { type DevWabeTypes, getAnonymousClient, getGraphqlClient } from '../../utils/helper'
|
|
4
|
-
import { setupTests, closeTests } from '../../utils/testHelper'
|
|
5
|
-
import type { Wabe } from '../../server'
|
|
6
|
-
import { OTP } from 'src'
|
|
7
|
-
|
|
8
|
-
describe('resetPasswordResolver', () => {
|
|
9
|
-
let wabe: Wabe<DevWabeTypes>
|
|
10
|
-
let port: number
|
|
11
|
-
let client: GraphQLClient
|
|
12
|
-
|
|
13
|
-
beforeAll(async () => {
|
|
14
|
-
const setup = await setupTests()
|
|
15
|
-
wabe = setup.wabe
|
|
16
|
-
port = setup.port
|
|
17
|
-
client = getGraphqlClient(port)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
afterAll(async () => {
|
|
21
|
-
await closeTests(wabe)
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
beforeEach(async () => {
|
|
25
|
-
await wabe.controllers.database.clearDatabase()
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('should let an anonymous reset the password of an user', async () => {
|
|
29
|
-
process.env.NODE_ENV = 'production'
|
|
30
|
-
|
|
31
|
-
const anonymousClient = getAnonymousClient(port)
|
|
32
|
-
|
|
33
|
-
await anonymousClient.request<any>(graphql.createUser, {
|
|
34
|
-
input: {
|
|
35
|
-
fields: {
|
|
36
|
-
authentication: {
|
|
37
|
-
emailPassword: {
|
|
38
|
-
email: 'toto@toto.fr',
|
|
39
|
-
password: 'totototo',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
const {
|
|
47
|
-
users: { edges },
|
|
48
|
-
} = await getGraphqlClient(port).request<any>(gql`
|
|
49
|
-
query users {
|
|
50
|
-
users(where: { email: { equalTo: "toto@toto.fr" } }) {
|
|
51
|
-
edges {
|
|
52
|
-
node {
|
|
53
|
-
id
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
`)
|
|
59
|
-
|
|
60
|
-
const userId = edges[0].node.id
|
|
61
|
-
|
|
62
|
-
const otp = new OTP(wabe.config.rootKey)
|
|
63
|
-
|
|
64
|
-
await anonymousClient.request<any>(graphql.resetPassword, {
|
|
65
|
-
input: {
|
|
66
|
-
email: 'toto@toto.fr',
|
|
67
|
-
password: 'tata',
|
|
68
|
-
otp: otp.generate(userId),
|
|
69
|
-
},
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
const res = await anonymousClient.request<any>(graphql.signInWith, {
|
|
73
|
-
input: {
|
|
74
|
-
authentication: {
|
|
75
|
-
emailPassword: {
|
|
76
|
-
email: 'toto@toto.fr',
|
|
77
|
-
password: 'tata',
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
expect(res.signInWith.user.id).toEqual(userId)
|
|
84
|
-
|
|
85
|
-
process.env.NODE_ENV = 'test'
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
it('should reset password of an user if the OTP code is valid', async () => {
|
|
89
|
-
process.env.NODE_ENV = 'production'
|
|
90
|
-
|
|
91
|
-
const {
|
|
92
|
-
createUser: { user },
|
|
93
|
-
} = await client.request<any>(graphql.createUserWithRoot, {
|
|
94
|
-
input: {
|
|
95
|
-
fields: {
|
|
96
|
-
authentication: {
|
|
97
|
-
emailPassword: {
|
|
98
|
-
email: 'toto@toto.fr',
|
|
99
|
-
password: 'totototo',
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
const userId = user.id
|
|
107
|
-
|
|
108
|
-
const otp = new OTP(wabe.config.rootKey)
|
|
109
|
-
|
|
110
|
-
await client.request<any>(graphql.resetPassword, {
|
|
111
|
-
input: {
|
|
112
|
-
email: 'toto@toto.fr',
|
|
113
|
-
password: 'tata',
|
|
114
|
-
otp: otp.generate(userId),
|
|
115
|
-
},
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
const res = await client.request<any>(graphql.signInWith, {
|
|
119
|
-
input: {
|
|
120
|
-
authentication: {
|
|
121
|
-
emailPassword: {
|
|
122
|
-
email: 'toto@toto.fr',
|
|
123
|
-
password: 'tata',
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
expect(res.signInWith.user.id).toEqual(userId)
|
|
130
|
-
|
|
131
|
-
process.env.NODE_ENV = 'test'
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it('should reset password in dev mode with valid normal code', async () => {
|
|
135
|
-
process.env.NODE_ENV = 'test'
|
|
136
|
-
|
|
137
|
-
const {
|
|
138
|
-
createUser: { user },
|
|
139
|
-
} = await client.request<any>(graphql.createUserWithRoot, {
|
|
140
|
-
input: {
|
|
141
|
-
fields: {
|
|
142
|
-
authentication: {
|
|
143
|
-
emailPassword: {
|
|
144
|
-
email: 'toto@toto.fr',
|
|
145
|
-
password: 'totototo',
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
const userId = user.id
|
|
153
|
-
|
|
154
|
-
const otp = new OTP(wabe.config.rootKey)
|
|
155
|
-
|
|
156
|
-
await client.request<any>(graphql.resetPassword, {
|
|
157
|
-
input: {
|
|
158
|
-
email: 'toto@toto.fr',
|
|
159
|
-
password: 'tata',
|
|
160
|
-
otp: otp.generate(userId),
|
|
161
|
-
},
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
const res = await client.request<any>(graphql.signInWith, {
|
|
165
|
-
input: {
|
|
166
|
-
authentication: {
|
|
167
|
-
emailPassword: {
|
|
168
|
-
email: 'toto@toto.fr',
|
|
169
|
-
password: 'tata',
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
expect(res.signInWith.user.id).toEqual(userId)
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
it('should reset password in dev mode with code 000000', async () => {
|
|
179
|
-
process.env.NODE_ENV = 'test'
|
|
180
|
-
|
|
181
|
-
const {
|
|
182
|
-
createUser: { user },
|
|
183
|
-
} = await client.request<any>(graphql.createUserWithRoot, {
|
|
184
|
-
input: {
|
|
185
|
-
fields: {
|
|
186
|
-
authentication: {
|
|
187
|
-
emailPassword: {
|
|
188
|
-
email: 'toto2@toto.fr',
|
|
189
|
-
password: 'totototo',
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
const userId = user.id
|
|
197
|
-
|
|
198
|
-
await client.request<any>(graphql.resetPassword, {
|
|
199
|
-
input: {
|
|
200
|
-
email: 'toto2@toto.fr',
|
|
201
|
-
password: 'tata',
|
|
202
|
-
otp: '000000',
|
|
203
|
-
},
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
const res = await client.request<any>(graphql.signInWith, {
|
|
207
|
-
input: {
|
|
208
|
-
authentication: {
|
|
209
|
-
emailPassword: {
|
|
210
|
-
email: 'toto2@toto.fr',
|
|
211
|
-
password: 'tata',
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
|
-
},
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
expect(res.signInWith.user.id).toEqual(userId)
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
it("should return true if the user doesn't exist (hide sensitive data)", async () => {
|
|
221
|
-
process.env.NODE_ENV = 'test'
|
|
222
|
-
|
|
223
|
-
const res = await client.request<any>(graphql.resetPassword, {
|
|
224
|
-
input: {
|
|
225
|
-
email: 'invalidUser@toto.fr',
|
|
226
|
-
password: 'tata',
|
|
227
|
-
otp: '000000',
|
|
228
|
-
},
|
|
229
|
-
})
|
|
230
|
-
|
|
231
|
-
expect(res.resetPassword).toEqual(true)
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
it('should not reset password of an user if the OTP code is invalid', async () => {
|
|
235
|
-
process.env.NODE_ENV = 'production'
|
|
236
|
-
|
|
237
|
-
await client.request<any>(graphql.createUserWithRoot, {
|
|
238
|
-
input: {
|
|
239
|
-
fields: {
|
|
240
|
-
authentication: {
|
|
241
|
-
emailPassword: {
|
|
242
|
-
email: 'toto3@toto.fr',
|
|
243
|
-
password: 'totototo',
|
|
244
|
-
},
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
},
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
expect(
|
|
251
|
-
client.request<any>(graphql.resetPassword, {
|
|
252
|
-
input: {
|
|
253
|
-
email: 'toto3@toto.fr',
|
|
254
|
-
password: 'tata',
|
|
255
|
-
otp: 'invalidOtp',
|
|
256
|
-
},
|
|
257
|
-
}),
|
|
258
|
-
).rejects.toThrow('Invalid OTP code')
|
|
259
|
-
|
|
260
|
-
process.env.NODE_ENV = 'test'
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
it('should reset password of another provider than emailPassword', async () => {
|
|
264
|
-
process.env.NODE_ENV = 'production'
|
|
265
|
-
|
|
266
|
-
const {
|
|
267
|
-
createUser: { user },
|
|
268
|
-
} = await client.request<any>(graphql.createUserWithRoot, {
|
|
269
|
-
input: {
|
|
270
|
-
fields: {
|
|
271
|
-
authentication: {
|
|
272
|
-
phonePassword: {
|
|
273
|
-
phone: '+33600000000',
|
|
274
|
-
password: 'totototo',
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
})
|
|
280
|
-
|
|
281
|
-
const userId = user.id
|
|
282
|
-
|
|
283
|
-
const otp = new OTP(wabe.config.rootKey)
|
|
284
|
-
|
|
285
|
-
await client.request<any>(graphql.resetPassword, {
|
|
286
|
-
input: {
|
|
287
|
-
phone: '+33600000000',
|
|
288
|
-
password: 'tata',
|
|
289
|
-
otp: otp.generate(userId),
|
|
290
|
-
},
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
const res = await client.request<any>(graphql.signInWith, {
|
|
294
|
-
input: {
|
|
295
|
-
authentication: {
|
|
296
|
-
phonePassword: {
|
|
297
|
-
phone: '+33600000000',
|
|
298
|
-
password: 'tata',
|
|
299
|
-
},
|
|
300
|
-
},
|
|
301
|
-
},
|
|
302
|
-
})
|
|
303
|
-
|
|
304
|
-
expect(res.signInWith.user.id).toEqual(userId)
|
|
305
|
-
|
|
306
|
-
process.env.NODE_ENV = 'test'
|
|
307
|
-
})
|
|
308
|
-
})
|
|
309
|
-
|
|
310
|
-
const graphql = {
|
|
311
|
-
signInWith: gql`
|
|
312
|
-
mutation signInWith($input: SignInWithInput!) {
|
|
313
|
-
signInWith(input: $input) {
|
|
314
|
-
user {
|
|
315
|
-
id
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
`,
|
|
320
|
-
createUser: gql`
|
|
321
|
-
mutation createUser($input: CreateUserInput!) {
|
|
322
|
-
createUser(input: $input) {
|
|
323
|
-
ok
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
`,
|
|
327
|
-
createUserWithRoot: gql`
|
|
328
|
-
mutation createUser($input: CreateUserInput!) {
|
|
329
|
-
createUser(input: $input) {
|
|
330
|
-
user {
|
|
331
|
-
id
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
`,
|
|
336
|
-
resetPassword: gql`
|
|
337
|
-
mutation resetPassword($input: ResetPasswordInput!) {
|
|
338
|
-
resetPassword(input: $input)
|
|
339
|
-
}
|
|
340
|
-
`,
|
|
341
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { MutationResetPasswordArgs } from '../../../generated/wabe'
|
|
2
|
-
import { OTP } from '../../authentication/OTP'
|
|
3
|
-
import type { WabeContext } from '../../server/interface'
|
|
4
|
-
import { contextWithRoot } from '../../utils/export'
|
|
5
|
-
import type { DevWabeTypes } from '../../utils/helper'
|
|
6
|
-
|
|
7
|
-
const DUMMY_USER_ID = '00000000-0000-0000-0000-000000000000'
|
|
8
|
-
|
|
9
|
-
export const resetPasswordResolver = async (
|
|
10
|
-
_: any,
|
|
11
|
-
{ input: { email, phone, password, otp } }: MutationResetPasswordArgs,
|
|
12
|
-
context: WabeContext<DevWabeTypes>,
|
|
13
|
-
) => {
|
|
14
|
-
if (!email && !phone) throw new Error('Email or phone is required')
|
|
15
|
-
|
|
16
|
-
const users = await context.wabe.controllers.database.getObjects({
|
|
17
|
-
className: 'User',
|
|
18
|
-
where: {
|
|
19
|
-
...(email && { email: { equalTo: email } }),
|
|
20
|
-
...(phone && {
|
|
21
|
-
authentication: { phonePassword: { phone: { equalTo: phone } } },
|
|
22
|
-
}),
|
|
23
|
-
},
|
|
24
|
-
select: { id: true, authentication: true },
|
|
25
|
-
first: 1,
|
|
26
|
-
context: contextWithRoot(context),
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
const realUser = users.length > 0 ? users[0] : null
|
|
30
|
-
const userId = realUser?.id ?? DUMMY_USER_ID
|
|
31
|
-
|
|
32
|
-
const otpClass = new OTP(context.wabe.config.rootKey)
|
|
33
|
-
const isOtpValid = otpClass.verify(otp, userId)
|
|
34
|
-
|
|
35
|
-
if (realUser) {
|
|
36
|
-
const inProd = process.env.NODE_ENV === 'production'
|
|
37
|
-
const devBypass = !inProd && otp === '000000'
|
|
38
|
-
|
|
39
|
-
if (!isOtpValid && !(devBypass && !inProd)) throw new Error('Invalid OTP code')
|
|
40
|
-
|
|
41
|
-
const providerKey = phone ? 'phonePassword' : 'emailPassword'
|
|
42
|
-
|
|
43
|
-
await context.wabe.controllers.database.updateObject({
|
|
44
|
-
className: 'User',
|
|
45
|
-
id: realUser.id,
|
|
46
|
-
data: {
|
|
47
|
-
authentication: {
|
|
48
|
-
[providerKey]: {
|
|
49
|
-
...(phone && {
|
|
50
|
-
phone: realUser.authentication?.phonePassword?.phone,
|
|
51
|
-
}),
|
|
52
|
-
...(email && { email }),
|
|
53
|
-
password,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
select: {},
|
|
58
|
-
context: contextWithRoot(context),
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return true
|
|
63
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, mock } from 'bun:test'
|
|
2
|
-
import { sendEmailResolver } from './sendEmail'
|
|
3
|
-
import type { WabeContext } from '../../server/interface'
|
|
4
|
-
|
|
5
|
-
describe('SendEmail', () => {
|
|
6
|
-
it('should throw an error if email adapter is not defined', () => {
|
|
7
|
-
expect(() =>
|
|
8
|
-
sendEmailResolver(
|
|
9
|
-
undefined,
|
|
10
|
-
{
|
|
11
|
-
input: { from: 'from', to: ['to'], subject: 'subject', text: 'text' },
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
isRoot: false,
|
|
15
|
-
user: {
|
|
16
|
-
id: 'id',
|
|
17
|
-
},
|
|
18
|
-
wabe: {
|
|
19
|
-
controllers: {
|
|
20
|
-
email: undefined,
|
|
21
|
-
} as any,
|
|
22
|
-
},
|
|
23
|
-
} as WabeContext<any>,
|
|
24
|
-
),
|
|
25
|
-
).toThrow('Email adapter not defined')
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('should send email when user is connected', async () => {
|
|
29
|
-
const mockSend = mock(() => {}).mockResolvedValueOnce(true as never)
|
|
30
|
-
|
|
31
|
-
const res = await sendEmailResolver(
|
|
32
|
-
undefined,
|
|
33
|
-
{
|
|
34
|
-
input: { from: 'from', to: ['to'], subject: 'subject', text: 'text' },
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
isRoot: false,
|
|
38
|
-
user: {
|
|
39
|
-
id: 'id',
|
|
40
|
-
},
|
|
41
|
-
wabe: {
|
|
42
|
-
controllers: {
|
|
43
|
-
email: {
|
|
44
|
-
send: mockSend,
|
|
45
|
-
},
|
|
46
|
-
} as any,
|
|
47
|
-
},
|
|
48
|
-
} as WabeContext<any>,
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
expect(res).toBeTrue()
|
|
52
|
-
|
|
53
|
-
expect(mockSend).toHaveBeenCalledTimes(1)
|
|
54
|
-
expect(mockSend).toHaveBeenCalledWith({
|
|
55
|
-
from: 'from',
|
|
56
|
-
to: ['to'],
|
|
57
|
-
subject: 'subject',
|
|
58
|
-
text: 'text',
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('should send email when user is root', async () => {
|
|
63
|
-
const mockSend = mock(() => {}).mockResolvedValueOnce(true as never)
|
|
64
|
-
|
|
65
|
-
const res = await sendEmailResolver(
|
|
66
|
-
undefined,
|
|
67
|
-
{
|
|
68
|
-
input: { from: 'from', to: ['to'], subject: 'subject', text: 'text' },
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
isRoot: true,
|
|
72
|
-
wabe: {
|
|
73
|
-
controllers: {
|
|
74
|
-
email: {
|
|
75
|
-
send: mockSend,
|
|
76
|
-
},
|
|
77
|
-
} as any,
|
|
78
|
-
},
|
|
79
|
-
} as WabeContext<any>,
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
expect(res).toBeTrue()
|
|
83
|
-
|
|
84
|
-
expect(mockSend).toHaveBeenCalledTimes(1)
|
|
85
|
-
expect(mockSend).toHaveBeenCalledWith({
|
|
86
|
-
from: 'from',
|
|
87
|
-
to: ['to'],
|
|
88
|
-
subject: 'subject',
|
|
89
|
-
text: 'text',
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
it('should not send email when user is not connected and is not root', () => {
|
|
94
|
-
const mockSend = mock(() => {}).mockResolvedValueOnce(true as never)
|
|
95
|
-
|
|
96
|
-
expect(() =>
|
|
97
|
-
sendEmailResolver(
|
|
98
|
-
undefined,
|
|
99
|
-
{
|
|
100
|
-
input: { from: 'from', to: ['to'], subject: 'subject', text: 'text' },
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
isRoot: false,
|
|
104
|
-
user: undefined,
|
|
105
|
-
wabe: {
|
|
106
|
-
controllers: {
|
|
107
|
-
email: {
|
|
108
|
-
send: mockSend,
|
|
109
|
-
},
|
|
110
|
-
} as any,
|
|
111
|
-
},
|
|
112
|
-
} as WabeContext<any>,
|
|
113
|
-
),
|
|
114
|
-
).toThrow('Permission denied')
|
|
115
|
-
|
|
116
|
-
expect(mockSend).toHaveBeenCalledTimes(0)
|
|
117
|
-
})
|
|
118
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { MutationSendEmailArgs } from '../../../generated/wabe'
|
|
2
|
-
import type { WabeContext } from '../../server/interface'
|
|
3
|
-
import type { DevWabeTypes } from '../../utils/helper'
|
|
4
|
-
|
|
5
|
-
export const sendEmailResolver = (
|
|
6
|
-
_: any,
|
|
7
|
-
{ input }: MutationSendEmailArgs,
|
|
8
|
-
context: WabeContext<DevWabeTypes>,
|
|
9
|
-
) => {
|
|
10
|
-
if (!context.user && !context.isRoot) throw new Error('Permission denied')
|
|
11
|
-
|
|
12
|
-
const emailController = context.wabe.controllers.email
|
|
13
|
-
|
|
14
|
-
if (!emailController) throw new Error('Email adapter not defined')
|
|
15
|
-
|
|
16
|
-
return emailController.send({
|
|
17
|
-
...input,
|
|
18
|
-
text: input.text ?? undefined,
|
|
19
|
-
html: input.html ?? undefined,
|
|
20
|
-
})
|
|
21
|
-
}
|