wabe 0.6.9 → 0.6.11
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/README.md +156 -50
- package/bucket/b.txt +1 -0
- package/dev/index.ts +215 -0
- package/dist/authentication/Session.d.ts +4 -1
- package/dist/authentication/interface.d.ts +16 -0
- package/dist/cron/index.d.ts +0 -1
- package/dist/database/DatabaseController.d.ts +41 -13
- package/dist/database/interface.d.ts +1 -0
- package/dist/email/DevAdapter.d.ts +0 -1
- package/dist/email/interface.d.ts +1 -1
- package/dist/graphql/resolvers.d.ts +4 -2
- package/dist/hooks/index.d.ts +8 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.js +32144 -32058
- package/dist/schema/Schema.d.ts +2 -1
- package/dist/server/index.d.ts +4 -2
- package/dist/utils/crypto.d.ts +7 -0
- package/dist/utils/helper.d.ts +5 -1
- package/generated/schema.graphql +22 -14
- package/generated/wabe.ts +4 -4
- package/package.json +23 -23
- package/src/authentication/OTP.test.ts +69 -0
- package/src/authentication/OTP.ts +64 -0
- package/src/authentication/Session.test.ts +629 -0
- package/src/authentication/Session.ts +493 -0
- package/src/authentication/defaultAuthentication.ts +209 -0
- package/src/authentication/index.ts +3 -0
- package/src/authentication/interface.ts +155 -0
- package/src/authentication/oauth/GitHub.test.ts +91 -0
- package/src/authentication/oauth/GitHub.ts +121 -0
- package/src/authentication/oauth/Google.test.ts +91 -0
- package/src/authentication/oauth/Google.ts +101 -0
- package/src/authentication/oauth/Oauth2Client.test.ts +219 -0
- package/src/authentication/oauth/Oauth2Client.ts +135 -0
- package/src/authentication/oauth/index.ts +2 -0
- package/src/authentication/oauth/utils.test.ts +33 -0
- package/src/authentication/oauth/utils.ts +27 -0
- package/src/authentication/providers/EmailOTP.test.ts +127 -0
- package/src/authentication/providers/EmailOTP.ts +84 -0
- package/src/authentication/providers/EmailPassword.test.ts +176 -0
- package/src/authentication/providers/EmailPassword.ts +116 -0
- package/src/authentication/providers/EmailPasswordSRP.test.ts +208 -0
- package/src/authentication/providers/EmailPasswordSRP.ts +179 -0
- package/src/authentication/providers/GitHub.ts +24 -0
- package/src/authentication/providers/Google.ts +24 -0
- package/src/authentication/providers/OAuth.test.ts +185 -0
- package/src/authentication/providers/OAuth.ts +106 -0
- package/src/authentication/providers/PhonePassword.test.ts +176 -0
- package/src/authentication/providers/PhonePassword.ts +115 -0
- package/src/authentication/providers/QRCodeOTP.test.ts +77 -0
- package/src/authentication/providers/QRCodeOTP.ts +58 -0
- package/src/authentication/providers/index.ts +6 -0
- package/src/authentication/resolvers/refreshResolver.test.ts +30 -0
- package/src/authentication/resolvers/refreshResolver.ts +19 -0
- package/src/authentication/resolvers/signInWithResolver.inte.test.ts +59 -0
- package/src/authentication/resolvers/signInWithResolver.test.ts +293 -0
- package/src/authentication/resolvers/signInWithResolver.ts +92 -0
- package/src/authentication/resolvers/signOutResolver.test.ts +38 -0
- package/src/authentication/resolvers/signOutResolver.ts +18 -0
- package/src/authentication/resolvers/signUpWithResolver.test.ts +180 -0
- package/src/authentication/resolvers/signUpWithResolver.ts +65 -0
- package/src/authentication/resolvers/verifyChallenge.test.ts +133 -0
- package/src/authentication/resolvers/verifyChallenge.ts +62 -0
- package/src/authentication/roles.test.ts +49 -0
- package/src/authentication/roles.ts +40 -0
- package/src/authentication/utils.test.ts +97 -0
- package/src/authentication/utils.ts +39 -0
- package/src/cache/InMemoryCache.test.ts +62 -0
- package/src/cache/InMemoryCache.ts +45 -0
- package/src/cron/index.test.ts +17 -0
- package/src/cron/index.ts +43 -0
- package/src/database/DatabaseController.test.ts +613 -0
- package/src/database/DatabaseController.ts +1007 -0
- package/src/database/index.test.ts +1372 -0
- package/src/database/index.ts +9 -0
- package/src/database/interface.ts +302 -0
- package/src/email/DevAdapter.ts +7 -0
- package/src/email/EmailController.test.ts +29 -0
- package/src/email/EmailController.ts +13 -0
- package/src/email/index.ts +2 -0
- package/src/email/interface.ts +36 -0
- package/src/email/templates/sendOtpCode.ts +120 -0
- package/src/file/FileController.ts +28 -0
- package/src/file/FileDevAdapter.ts +51 -0
- package/src/file/hookDeleteFile.ts +25 -0
- package/src/file/hookReadFile.ts +66 -0
- package/src/file/hookUploadFile.ts +50 -0
- package/src/file/index.test.ts +932 -0
- package/src/file/index.ts +2 -0
- package/src/file/interface.ts +39 -0
- package/src/graphql/GraphQLSchema.test.ts +4408 -0
- package/src/graphql/GraphQLSchema.ts +880 -0
- package/src/graphql/index.ts +2 -0
- package/src/graphql/parseGraphqlSchema.ts +85 -0
- package/src/graphql/parser.test.ts +203 -0
- package/src/graphql/parser.ts +542 -0
- package/src/graphql/pointerAndRelationFunction.ts +191 -0
- package/src/graphql/resolvers.ts +442 -0
- package/src/graphql/tests/aggregation.test.ts +1115 -0
- package/src/graphql/tests/e2e.test.ts +590 -0
- package/src/graphql/tests/scalars.test.ts +250 -0
- package/src/graphql/types.ts +227 -0
- package/src/hooks/HookObject.test.ts +122 -0
- package/src/hooks/HookObject.ts +165 -0
- package/src/hooks/authentication.ts +67 -0
- package/src/hooks/createUser.test.ts +77 -0
- package/src/hooks/createUser.ts +10 -0
- package/src/hooks/defaultFields.test.ts +176 -0
- package/src/hooks/defaultFields.ts +32 -0
- package/src/hooks/deleteSession.test.ts +181 -0
- package/src/hooks/deleteSession.ts +20 -0
- package/src/hooks/hashFieldHook.test.ts +152 -0
- package/src/hooks/hashFieldHook.ts +89 -0
- package/src/hooks/index.test.ts +258 -0
- package/src/hooks/index.ts +414 -0
- package/src/hooks/permissions.test.ts +412 -0
- package/src/hooks/permissions.ts +93 -0
- package/src/hooks/protected.test.ts +551 -0
- package/src/hooks/protected.ts +60 -0
- package/src/hooks/searchableFields.test.ts +147 -0
- package/src/hooks/searchableFields.ts +86 -0
- package/src/hooks/session.test.ts +134 -0
- package/src/hooks/session.ts +76 -0
- package/src/hooks/setEmail.test.ts +216 -0
- package/src/hooks/setEmail.ts +33 -0
- package/src/hooks/setupAcl.test.ts +618 -0
- package/src/hooks/setupAcl.ts +25 -0
- package/src/index.ts +9 -0
- package/src/schema/Schema.test.ts +482 -0
- package/src/schema/Schema.ts +757 -0
- package/src/schema/defaultResolvers.ts +93 -0
- package/src/schema/index.ts +1 -0
- package/src/schema/resolvers/meResolver.test.ts +62 -0
- package/src/schema/resolvers/meResolver.ts +10 -0
- package/src/schema/resolvers/resetPassword.test.ts +341 -0
- package/src/schema/resolvers/resetPassword.ts +63 -0
- package/src/schema/resolvers/sendEmail.test.ts +118 -0
- package/src/schema/resolvers/sendEmail.ts +21 -0
- package/src/schema/resolvers/sendOtpCode.test.ts +141 -0
- package/src/schema/resolvers/sendOtpCode.ts +52 -0
- package/src/security.test.ts +3434 -0
- package/src/server/defaultSessionHandler.test.ts +62 -0
- package/src/server/defaultSessionHandler.ts +105 -0
- package/src/server/generateCodegen.ts +433 -0
- package/src/server/index.test.ts +532 -0
- package/src/server/index.ts +334 -0
- package/src/server/interface.ts +11 -0
- package/src/server/routes/authHandler.ts +169 -0
- package/src/server/routes/index.ts +39 -0
- package/src/utils/crypto.test.ts +41 -0
- package/src/utils/crypto.ts +105 -0
- package/src/utils/export.ts +11 -0
- package/src/utils/helper.ts +204 -0
- package/src/utils/index.test.ts +11 -0
- package/src/utils/index.ts +189 -0
- package/src/utils/preload.ts +8 -0
- package/src/utils/testHelper.ts +116 -0
- package/tsconfig.json +32 -0
- package/bunfig.toml +0 -4
- package/dist/ai/index.d.ts +0 -1
- package/dist/ai/interface.d.ts +0 -9
- /package/dist/server/{defaultHandlers.d.ts → defaultSessionHandler.d.ts} +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
}
|