wabe 0.6.12 → 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/package.json +4 -1
- package/dev/index.ts +0 -215
- package/generated/schema.graphql +0 -1945
- package/generated/wabe.ts +0 -448
- 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 -517
- package/src/authentication/cookies.ts +0 -10
- package/src/authentication/defaultAuthentication.ts +0 -209
- package/src/authentication/index.ts +0 -4
- package/src/authentication/interface.ts +0 -177
- 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 -95
- package/src/authentication/providers/EmailPassword.test.ts +0 -263
- package/src/authentication/providers/EmailPassword.ts +0 -138
- package/src/authentication/providers/EmailPasswordSRP.test.ts +0 -208
- package/src/authentication/providers/EmailPasswordSRP.ts +0 -191
- 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 -221
- package/src/authentication/providers/PhonePassword.ts +0 -136
- package/src/authentication/providers/QRCodeOTP.test.ts +0 -77
- package/src/authentication/providers/QRCodeOTP.ts +0 -69
- 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 -306
- package/src/authentication/resolvers/signInWithResolver.ts +0 -106
- 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 -68
- package/src/authentication/resolvers/verifyChallenge.test.ts +0 -230
- package/src/authentication/resolvers/verifyChallenge.ts +0 -78
- package/src/authentication/roles.test.ts +0 -49
- package/src/authentication/roles.ts +0 -40
- package/src/authentication/security.ts +0 -278
- 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 -1415
- package/src/database/index.test.ts +0 -1551
- package/src/database/index.ts +0 -9
- package/src/database/interface.ts +0 -308
- 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 -52
- package/src/file/index.test.ts +0 -1031
- package/src/file/index.ts +0 -2
- package/src/file/interface.ts +0 -63
- package/src/file/security.ts +0 -156
- package/src/graphql/GraphQLSchema.test.ts +0 -5099
- package/src/graphql/GraphQLSchema.ts +0 -886
- 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 -707
- package/src/graphql/pointerAndRelationFunction.ts +0 -191
- package/src/graphql/resolvers.ts +0 -464
- 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 -420
- 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 -74
- 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/hooks/virtualFields.test.ts +0 -228
- package/src/hooks/virtualFields.ts +0 -48
- package/src/index.ts +0 -9
- package/src/schema/Schema.test.ts +0 -482
- package/src/schema/Schema.ts +0 -839
- 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 -4136
- package/src/server/defaultSessionHandler.test.ts +0 -62
- package/src/server/defaultSessionHandler.ts +0 -104
- package/src/server/generateCodegen.ts +0 -433
- package/src/server/index.test.ts +0 -843
- package/src/server/index.ts +0 -336
- package/src/server/interface.ts +0 -11
- package/src/server/routes/authHandler.ts +0 -171
- package/src/server/routes/index.ts +0 -48
- package/src/utils/crypto.test.ts +0 -41
- package/src/utils/crypto.ts +0 -105
- package/src/utils/database.ts +0 -8
- package/src/utils/export.ts +0 -12
- package/src/utils/helper.ts +0 -204
- package/src/utils/index.test.ts +0 -11
- package/src/utils/index.ts +0 -196
- package/src/utils/preload.ts +0 -8
- package/src/utils/testHelper.ts +0 -124
- package/tsconfig.json +0 -32
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { describe, afterAll, beforeAll, it, spyOn, expect, beforeEach } from 'bun:test'
|
|
2
|
-
import { gql, type GraphQLClient } from 'graphql-request'
|
|
3
|
-
import type { Wabe } from '../../server'
|
|
4
|
-
import { type DevWabeTypes, getGraphqlClient, getAnonymousClient } from '../../utils/helper'
|
|
5
|
-
import { setupTests, closeTests } from '../../utils/testHelper'
|
|
6
|
-
import { EmailDevAdapter } from '../../email/DevAdapter'
|
|
7
|
-
|
|
8
|
-
describe('sendOtpCodeResolver', () => {
|
|
9
|
-
let wabe: Wabe<DevWabeTypes>
|
|
10
|
-
let port: number
|
|
11
|
-
let client: GraphQLClient
|
|
12
|
-
|
|
13
|
-
const spySend = spyOn(EmailDevAdapter.prototype, 'send')
|
|
14
|
-
|
|
15
|
-
beforeAll(async () => {
|
|
16
|
-
const setup = await setupTests()
|
|
17
|
-
wabe = setup.wabe
|
|
18
|
-
port = setup.port
|
|
19
|
-
client = getGraphqlClient(port)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
afterAll(async () => {
|
|
23
|
-
await closeTests(wabe)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
beforeEach(() => {
|
|
27
|
-
spySend.mockClear()
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('should use the provided email template if provided', async () => {
|
|
31
|
-
const previous = wabe.config.email
|
|
32
|
-
// @ts-expect-error
|
|
33
|
-
wabe.config.email = {
|
|
34
|
-
...wabe.config.email,
|
|
35
|
-
htmlTemplates: {
|
|
36
|
-
sendOTPCode: {
|
|
37
|
-
fn: () => 'toto',
|
|
38
|
-
subject: 'Confirmation code',
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
await client.request<any>(graphql.createUser, {
|
|
44
|
-
input: {
|
|
45
|
-
fields: {
|
|
46
|
-
authentication: {
|
|
47
|
-
emailPassword: {
|
|
48
|
-
email: 'tata@toto.fr',
|
|
49
|
-
password: 'totototo',
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
await client.request<any>(graphql.sendOtpCode, {
|
|
57
|
-
input: {
|
|
58
|
-
email: 'tata@toto.fr',
|
|
59
|
-
},
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
expect(spySend).toHaveBeenCalledTimes(1)
|
|
63
|
-
expect(spySend).toHaveBeenCalledWith({
|
|
64
|
-
from: 'main.email@wabe.com',
|
|
65
|
-
to: ['tata@toto.fr'],
|
|
66
|
-
subject: 'Confirmation code',
|
|
67
|
-
html: 'toto',
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
wabe.config.email = previous
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it("should send an OTP code to the user's email as anonymous client", async () => {
|
|
74
|
-
const anonymousClient = getAnonymousClient(port)
|
|
75
|
-
|
|
76
|
-
await anonymousClient.request<any>(graphql.createUserWithAnonymous, {
|
|
77
|
-
input: {
|
|
78
|
-
fields: {
|
|
79
|
-
authentication: {
|
|
80
|
-
emailPassword: {
|
|
81
|
-
email: 'toto@toto.fr',
|
|
82
|
-
password: 'totototo',
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
await anonymousClient.request<any>(graphql.sendOtpCode, {
|
|
90
|
-
input: {
|
|
91
|
-
email: 'toto@toto.fr',
|
|
92
|
-
},
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
expect(spySend).toHaveBeenCalledTimes(1)
|
|
96
|
-
expect(spySend).toHaveBeenCalledWith({
|
|
97
|
-
from: 'main.email@wabe.com',
|
|
98
|
-
to: ['toto@toto.fr'],
|
|
99
|
-
subject: 'Your OTP code',
|
|
100
|
-
html: expect.any(String),
|
|
101
|
-
})
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
it("should return true if the user doesn't exist (hide sensitive data)", async () => {
|
|
105
|
-
const spySend = spyOn(EmailDevAdapter.prototype, 'send')
|
|
106
|
-
|
|
107
|
-
const res = await client.request<any>(graphql.sendOtpCode, {
|
|
108
|
-
input: {
|
|
109
|
-
email: 'invalidUser@toto.fr',
|
|
110
|
-
},
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
expect(res.sendOtpCode).toEqual(true)
|
|
114
|
-
|
|
115
|
-
expect(spySend).toHaveBeenCalledTimes(0)
|
|
116
|
-
})
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
const graphql = {
|
|
120
|
-
createUser: gql`
|
|
121
|
-
mutation createUser($input: CreateUserInput!) {
|
|
122
|
-
createUser(input: $input) {
|
|
123
|
-
user {
|
|
124
|
-
id
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
`,
|
|
129
|
-
createUserWithAnonymous: gql`
|
|
130
|
-
mutation createUser($input: CreateUserInput!) {
|
|
131
|
-
createUser(input: $input) {
|
|
132
|
-
ok
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
`,
|
|
136
|
-
sendOtpCode: gql`
|
|
137
|
-
mutation sendOtpCode($input: SendOtpCodeInput!) {
|
|
138
|
-
sendOtpCode(input: $input)
|
|
139
|
-
}
|
|
140
|
-
`,
|
|
141
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { MutationSendOtpCodeArgs } from '../../../generated/wabe'
|
|
2
|
-
import type { WabeContext } from '../../server/interface'
|
|
3
|
-
import type { DevWabeTypes } from '../../utils/helper'
|
|
4
|
-
import { sendOtpCodeTemplate } from '../../email/templates/sendOtpCode'
|
|
5
|
-
import { OTP } from '../../authentication/OTP'
|
|
6
|
-
import { contextWithRoot } from '../../utils/export'
|
|
7
|
-
|
|
8
|
-
export const sendOtpCodeResolver = async (
|
|
9
|
-
_: any,
|
|
10
|
-
{ input }: MutationSendOtpCodeArgs,
|
|
11
|
-
context: WabeContext<DevWabeTypes>,
|
|
12
|
-
) => {
|
|
13
|
-
const emailController = context.wabe.controllers.email
|
|
14
|
-
|
|
15
|
-
if (!emailController) throw new Error('Email adapter not defined')
|
|
16
|
-
|
|
17
|
-
const user = await context.wabe.controllers.database.getObjects({
|
|
18
|
-
className: 'User',
|
|
19
|
-
where: {
|
|
20
|
-
email: {
|
|
21
|
-
equalTo: input.email,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
select: { id: true },
|
|
25
|
-
first: 1,
|
|
26
|
-
context: contextWithRoot(context),
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
// We return true if the user doesn't exist to avoid leaking that the user exists or not
|
|
30
|
-
if (user.length === 0) return true
|
|
31
|
-
|
|
32
|
-
const userId = user[0]?.id
|
|
33
|
-
|
|
34
|
-
if (!userId) return false
|
|
35
|
-
|
|
36
|
-
const otpClass = new OTP(context.wabe.config.rootKey)
|
|
37
|
-
|
|
38
|
-
const otp = otpClass.generate(userId)
|
|
39
|
-
|
|
40
|
-
const mainEmail = context.wabe.config.email?.mainEmail || 'noreply@wabe.com'
|
|
41
|
-
|
|
42
|
-
const template = context.wabe.config.email?.htmlTemplates?.sendOTPCode
|
|
43
|
-
|
|
44
|
-
await emailController.send({
|
|
45
|
-
from: mainEmail,
|
|
46
|
-
to: [input.email],
|
|
47
|
-
subject: template?.subject || 'Your OTP code',
|
|
48
|
-
html: template?.fn ? await template.fn({ otp }) : sendOtpCodeTemplate(otp),
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
return true
|
|
52
|
-
}
|