wabe 0.6.9 → 0.6.10

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.
Files changed (158) hide show
  1. package/README.md +138 -32
  2. package/bucket/b.txt +1 -0
  3. package/dev/index.ts +215 -0
  4. package/dist/authentication/Session.d.ts +4 -1
  5. package/dist/authentication/interface.d.ts +16 -0
  6. package/dist/email/interface.d.ts +1 -1
  7. package/dist/graphql/resolvers.d.ts +4 -2
  8. package/dist/hooks/index.d.ts +1 -0
  9. package/dist/index.d.ts +0 -1
  10. package/dist/index.js +8713 -8867
  11. package/dist/server/index.d.ts +4 -2
  12. package/dist/utils/crypto.d.ts +7 -0
  13. package/dist/utils/helper.d.ts +4 -1
  14. package/generated/schema.graphql +16 -14
  15. package/generated/wabe.ts +4 -4
  16. package/package.json +15 -15
  17. package/src/authentication/OTP.test.ts +69 -0
  18. package/src/authentication/OTP.ts +66 -0
  19. package/src/authentication/Session.test.ts +665 -0
  20. package/src/authentication/Session.ts +529 -0
  21. package/src/authentication/defaultAuthentication.ts +214 -0
  22. package/src/authentication/index.ts +3 -0
  23. package/src/authentication/interface.ts +157 -0
  24. package/src/authentication/oauth/GitHub.test.ts +105 -0
  25. package/src/authentication/oauth/GitHub.ts +133 -0
  26. package/src/authentication/oauth/Google.test.ts +105 -0
  27. package/src/authentication/oauth/Google.ts +110 -0
  28. package/src/authentication/oauth/Oauth2Client.test.ts +225 -0
  29. package/src/authentication/oauth/Oauth2Client.ts +140 -0
  30. package/src/authentication/oauth/index.ts +2 -0
  31. package/src/authentication/oauth/utils.test.ts +35 -0
  32. package/src/authentication/oauth/utils.ts +28 -0
  33. package/src/authentication/providers/EmailOTP.test.ts +138 -0
  34. package/src/authentication/providers/EmailOTP.ts +93 -0
  35. package/src/authentication/providers/EmailPassword.test.ts +187 -0
  36. package/src/authentication/providers/EmailPassword.ts +130 -0
  37. package/src/authentication/providers/EmailPasswordSRP.test.ts +206 -0
  38. package/src/authentication/providers/EmailPasswordSRP.ts +184 -0
  39. package/src/authentication/providers/GitHub.ts +30 -0
  40. package/src/authentication/providers/Google.ts +30 -0
  41. package/src/authentication/providers/OAuth.test.ts +185 -0
  42. package/src/authentication/providers/OAuth.ts +112 -0
  43. package/src/authentication/providers/PhonePassword.test.ts +187 -0
  44. package/src/authentication/providers/PhonePassword.ts +129 -0
  45. package/src/authentication/providers/QRCodeOTP.test.ts +79 -0
  46. package/src/authentication/providers/QRCodeOTP.ts +65 -0
  47. package/src/authentication/providers/index.ts +6 -0
  48. package/src/authentication/resolvers/refreshResolver.test.ts +37 -0
  49. package/src/authentication/resolvers/refreshResolver.ts +20 -0
  50. package/src/authentication/resolvers/signInWithResolver.inte.test.ts +59 -0
  51. package/src/authentication/resolvers/signInWithResolver.test.ts +307 -0
  52. package/src/authentication/resolvers/signInWithResolver.ts +102 -0
  53. package/src/authentication/resolvers/signOutResolver.test.ts +41 -0
  54. package/src/authentication/resolvers/signOutResolver.ts +22 -0
  55. package/src/authentication/resolvers/signUpWithResolver.test.ts +186 -0
  56. package/src/authentication/resolvers/signUpWithResolver.ts +69 -0
  57. package/src/authentication/resolvers/verifyChallenge.test.ts +136 -0
  58. package/src/authentication/resolvers/verifyChallenge.ts +69 -0
  59. package/src/authentication/roles.test.ts +59 -0
  60. package/src/authentication/roles.ts +40 -0
  61. package/src/authentication/utils.test.ts +99 -0
  62. package/src/authentication/utils.ts +43 -0
  63. package/src/cache/InMemoryCache.test.ts +62 -0
  64. package/src/cache/InMemoryCache.ts +45 -0
  65. package/src/cron/index.test.ts +17 -0
  66. package/src/cron/index.ts +46 -0
  67. package/src/database/DatabaseController.test.ts +625 -0
  68. package/src/database/DatabaseController.ts +983 -0
  69. package/src/database/index.test.ts +1230 -0
  70. package/src/database/index.ts +9 -0
  71. package/src/database/interface.ts +312 -0
  72. package/src/email/DevAdapter.ts +8 -0
  73. package/src/email/EmailController.test.ts +29 -0
  74. package/src/email/EmailController.ts +13 -0
  75. package/src/email/index.ts +2 -0
  76. package/src/email/interface.ts +36 -0
  77. package/src/email/templates/sendOtpCode.ts +120 -0
  78. package/src/file/FileController.ts +28 -0
  79. package/src/file/FileDevAdapter.ts +54 -0
  80. package/src/file/hookDeleteFile.ts +27 -0
  81. package/src/file/hookReadFile.ts +70 -0
  82. package/src/file/hookUploadFile.ts +53 -0
  83. package/src/file/index.test.ts +979 -0
  84. package/src/file/index.ts +2 -0
  85. package/src/file/interface.ts +42 -0
  86. package/src/graphql/GraphQLSchema.test.ts +4399 -0
  87. package/src/graphql/GraphQLSchema.ts +928 -0
  88. package/src/graphql/index.ts +2 -0
  89. package/src/graphql/parseGraphqlSchema.ts +94 -0
  90. package/src/graphql/parser.test.ts +217 -0
  91. package/src/graphql/parser.ts +566 -0
  92. package/src/graphql/pointerAndRelationFunction.ts +200 -0
  93. package/src/graphql/resolvers.ts +467 -0
  94. package/src/graphql/tests/aggregation.test.ts +1123 -0
  95. package/src/graphql/tests/e2e.test.ts +596 -0
  96. package/src/graphql/tests/scalars.test.ts +250 -0
  97. package/src/graphql/types.ts +219 -0
  98. package/src/hooks/HookObject.test.ts +122 -0
  99. package/src/hooks/HookObject.ts +168 -0
  100. package/src/hooks/authentication.ts +76 -0
  101. package/src/hooks/createUser.test.ts +77 -0
  102. package/src/hooks/createUser.ts +10 -0
  103. package/src/hooks/defaultFields.test.ts +187 -0
  104. package/src/hooks/defaultFields.ts +40 -0
  105. package/src/hooks/deleteSession.test.ts +181 -0
  106. package/src/hooks/deleteSession.ts +20 -0
  107. package/src/hooks/hashFieldHook.test.ts +163 -0
  108. package/src/hooks/hashFieldHook.ts +97 -0
  109. package/src/hooks/index.test.ts +207 -0
  110. package/src/hooks/index.ts +430 -0
  111. package/src/hooks/permissions.test.ts +424 -0
  112. package/src/hooks/permissions.ts +113 -0
  113. package/src/hooks/protected.test.ts +551 -0
  114. package/src/hooks/protected.ts +72 -0
  115. package/src/hooks/searchableFields.test.ts +166 -0
  116. package/src/hooks/searchableFields.ts +98 -0
  117. package/src/hooks/session.test.ts +138 -0
  118. package/src/hooks/session.ts +78 -0
  119. package/src/hooks/setEmail.test.ts +216 -0
  120. package/src/hooks/setEmail.ts +35 -0
  121. package/src/hooks/setupAcl.test.ts +589 -0
  122. package/src/hooks/setupAcl.ts +29 -0
  123. package/src/index.ts +9 -0
  124. package/src/schema/Schema.test.ts +484 -0
  125. package/src/schema/Schema.ts +795 -0
  126. package/src/schema/defaultResolvers.ts +94 -0
  127. package/src/schema/index.ts +1 -0
  128. package/src/schema/resolvers/meResolver.test.ts +62 -0
  129. package/src/schema/resolvers/meResolver.ts +14 -0
  130. package/src/schema/resolvers/newFile.ts +0 -0
  131. package/src/schema/resolvers/resetPassword.test.ts +345 -0
  132. package/src/schema/resolvers/resetPassword.ts +64 -0
  133. package/src/schema/resolvers/sendEmail.test.ts +118 -0
  134. package/src/schema/resolvers/sendEmail.ts +21 -0
  135. package/src/schema/resolvers/sendOtpCode.test.ts +153 -0
  136. package/src/schema/resolvers/sendOtpCode.ts +52 -0
  137. package/src/security.test.ts +3461 -0
  138. package/src/server/defaultSessionHandler.test.ts +66 -0
  139. package/src/server/defaultSessionHandler.ts +115 -0
  140. package/src/server/generateCodegen.ts +476 -0
  141. package/src/server/index.test.ts +552 -0
  142. package/src/server/index.ts +354 -0
  143. package/src/server/interface.ts +11 -0
  144. package/src/server/routes/authHandler.ts +187 -0
  145. package/src/server/routes/index.ts +40 -0
  146. package/src/utils/crypto.test.ts +41 -0
  147. package/src/utils/crypto.ts +121 -0
  148. package/src/utils/export.ts +13 -0
  149. package/src/utils/helper.ts +195 -0
  150. package/src/utils/index.test.ts +11 -0
  151. package/src/utils/index.ts +201 -0
  152. package/src/utils/preload.ts +8 -0
  153. package/src/utils/testHelper.ts +117 -0
  154. package/tsconfig.json +32 -0
  155. package/bunfig.toml +0 -4
  156. package/dist/ai/index.d.ts +0 -1
  157. package/dist/ai/interface.d.ts +0 -9
  158. /package/dist/server/{defaultHandlers.d.ts → defaultSessionHandler.d.ts} +0 -0
@@ -0,0 +1,187 @@
1
+ import {
2
+ describe,
3
+ expect,
4
+ it,
5
+ mock,
6
+ spyOn,
7
+ afterEach,
8
+ afterAll,
9
+ } from 'bun:test'
10
+ import * as crypto from '../../utils/crypto'
11
+
12
+ import { PhonePassword } from './PhonePassword'
13
+
14
+ describe('Phone password', () => {
15
+ const mockGetObjects = mock(() => Promise.resolve([]))
16
+ const mockCount = mock(() => Promise.resolve(0)) as any
17
+ const mockCreateObject = mock(() => Promise.resolve({ id: 'userId' })) as any
18
+
19
+ const spyArgonPasswordVerify = spyOn(crypto, 'verifyArgon2')
20
+ const spyBunPasswordHash = spyOn(crypto, 'hashArgon2')
21
+
22
+ const controllers = {
23
+ controllers: {
24
+ database: {
25
+ getObjects: mockGetObjects,
26
+ createObject: mockCreateObject,
27
+ count: mockCount,
28
+ },
29
+ },
30
+ } as any
31
+
32
+ afterEach(() => {
33
+ mockGetObjects.mockClear()
34
+ mockCreateObject.mockClear()
35
+ spyArgonPasswordVerify.mockClear()
36
+ spyBunPasswordHash.mockClear()
37
+ })
38
+
39
+ afterAll(() => {
40
+ spyArgonPasswordVerify.mockRestore()
41
+ spyBunPasswordHash.mockRestore()
42
+ })
43
+
44
+ const phonePassword = new PhonePassword()
45
+
46
+ it('should signUp with phone password', async () => {
47
+ spyBunPasswordHash.mockResolvedValueOnce('$argon2id$hashedPassword')
48
+
49
+ const {
50
+ authenticationDataToSave: { phone },
51
+ } = await phonePassword.onSignUp({
52
+ context: { wabe: controllers } as any,
53
+ input: { phone: 'phone@test.fr', password: 'password' },
54
+ })
55
+
56
+ expect(phone).toBe('phone@test.fr')
57
+ })
58
+
59
+ it('should signIn with phone password', async () => {
60
+ mockGetObjects.mockResolvedValue([
61
+ {
62
+ id: 'userId',
63
+ authentication: {
64
+ phonePassword: {
65
+ phone: 'phone@test.fr',
66
+ password: 'hashedPassword',
67
+ },
68
+ },
69
+ } as never,
70
+ ])
71
+
72
+ spyArgonPasswordVerify.mockResolvedValueOnce(true)
73
+
74
+ const { user } = await phonePassword.onSignIn({
75
+ context: { wabe: controllers } as any,
76
+ input: { phone: 'phone@test.fr', password: 'password' },
77
+ })
78
+
79
+ expect(user).toEqual({
80
+ id: 'userId',
81
+ authentication: {
82
+ phonePassword: {
83
+ phone: 'phone@test.fr',
84
+ password: 'hashedPassword',
85
+ },
86
+ },
87
+ })
88
+
89
+ expect(spyArgonPasswordVerify).toHaveBeenCalledTimes(1)
90
+ expect(spyArgonPasswordVerify).toHaveBeenCalledWith(
91
+ 'password',
92
+ 'hashedPassword',
93
+ )
94
+ })
95
+
96
+ it('should not signIn with phone password if password is undefined', () => {
97
+ spyArgonPasswordVerify.mockResolvedValueOnce(false)
98
+
99
+ expect(
100
+ phonePassword.onSignIn({
101
+ context: { wabe: controllers } as any,
102
+ // @ts-expect-error
103
+ input: { phone: 'phone@test.fr' },
104
+ }),
105
+ ).rejects.toThrow('Invalid authentication credentials')
106
+ })
107
+
108
+ it('should not signIn with phone password if there is no user found', () => {
109
+ mockGetObjects.mockResolvedValue([])
110
+
111
+ expect(
112
+ phonePassword.onSignIn({
113
+ context: { wabe: controllers } as any,
114
+ input: {
115
+ phone: 'invalidEmail@test.fr',
116
+ password: 'password',
117
+ },
118
+ }),
119
+ ).rejects.toThrow('Invalid authentication credentials')
120
+
121
+ expect(spyArgonPasswordVerify).toHaveBeenCalledTimes(1)
122
+ })
123
+
124
+ it('should not signIn with phone password if there is phone is invalid', () => {
125
+ mockGetObjects.mockResolvedValue([
126
+ {
127
+ authentication: {
128
+ phonePassword: {
129
+ password: 'hashedPassword',
130
+ },
131
+ },
132
+ } as never,
133
+ ])
134
+
135
+ spyArgonPasswordVerify.mockResolvedValueOnce(true)
136
+
137
+ expect(
138
+ phonePassword.onSignIn({
139
+ context: { wabe: controllers } as any,
140
+ input: {
141
+ phone: 'invalidEmail@test.fr',
142
+ password: 'password',
143
+ },
144
+ }),
145
+ ).rejects.toThrow('Invalid authentication credentials')
146
+
147
+ expect(spyArgonPasswordVerify).toHaveBeenCalledTimes(1)
148
+ })
149
+
150
+ it('should not update authentication data if there is no user found', () => {
151
+ mockGetObjects.mockResolvedValue([])
152
+
153
+ spyArgonPasswordVerify.mockResolvedValueOnce(true)
154
+
155
+ expect(
156
+ phonePassword.onUpdateAuthenticationData?.({
157
+ context: { wabe: controllers } as any,
158
+ input: {
159
+ phone: 'phone@test.fr',
160
+ password: 'password',
161
+ },
162
+ userId: 'userId',
163
+ }),
164
+ ).rejects.toThrow('User not found')
165
+ })
166
+
167
+ it('should update authentication data if the userId match with an user', async () => {
168
+ mockGetObjects.mockResolvedValue([
169
+ {
170
+ id: 'id',
171
+ },
172
+ ] as any)
173
+
174
+ spyBunPasswordHash.mockResolvedValueOnce('$argon2id$hashedPassword')
175
+
176
+ const res = await phonePassword.onUpdateAuthenticationData?.({
177
+ context: { wabe: controllers } as any,
178
+ input: {
179
+ phone: 'phone@test.fr',
180
+ password: 'password',
181
+ },
182
+ userId: 'userId',
183
+ })
184
+
185
+ expect(res.authenticationDataToSave.phone).toBe('phone@test.fr')
186
+ })
187
+ })
@@ -0,0 +1,129 @@
1
+ import type {
2
+ AuthenticationEventsOptions,
3
+ AuthenticationEventsOptionsWithUserId,
4
+ ProviderInterface,
5
+ } from '../interface'
6
+ import { contextWithRoot, verifyArgon2 } from '../../utils/export'
7
+ import type { DevWabeTypes } from '../../utils/helper'
8
+
9
+ const DUMMY_PASSWORD_HASH =
10
+ '$argon2id$v=19$m=65536,t=2,p=1$wHZB9xRS/Mbo7L3SL9e935Ag5K+T2EuT/XgB8akwZgo$SPf8EZ4T1HYkuIll4v2hSzNCH7woX3VrZJo3yWg5u8U'
11
+
12
+ type PhonePasswordInterface = {
13
+ password: string
14
+ phone: string
15
+ otp?: string
16
+ }
17
+
18
+ export class PhonePassword
19
+ implements ProviderInterface<DevWabeTypes, PhonePasswordInterface>
20
+ {
21
+ async onSignIn({
22
+ input,
23
+ context,
24
+ }: AuthenticationEventsOptions<DevWabeTypes, PhonePasswordInterface>) {
25
+ const users = await context.wabe.controllers.database.getObjects({
26
+ className: 'User',
27
+ where: {
28
+ authentication: {
29
+ phonePassword: {
30
+ phone: { equalTo: input.phone },
31
+ },
32
+ },
33
+ },
34
+ context: contextWithRoot(context),
35
+ select: {
36
+ authentication: true,
37
+ role: true,
38
+ secondFA: true,
39
+ email: true,
40
+ id: true,
41
+ provider: true,
42
+ isOauth: true,
43
+ createdAt: true,
44
+ updatedAt: true,
45
+ },
46
+ first: 1,
47
+ })
48
+
49
+ const user = users[0]
50
+ const userDatabasePassword = user?.authentication?.phonePassword?.password
51
+
52
+ const passwordHashToCheck = userDatabasePassword ?? DUMMY_PASSWORD_HASH
53
+
54
+ const isPasswordEquals = await verifyArgon2(
55
+ input.password,
56
+ passwordHashToCheck,
57
+ )
58
+
59
+ if (
60
+ !user ||
61
+ !isPasswordEquals ||
62
+ input.phone !== user.authentication?.phonePassword?.phone
63
+ )
64
+ throw new Error('Invalid authentication credentials')
65
+
66
+ return {
67
+ user,
68
+ }
69
+ }
70
+
71
+ async onSignUp({
72
+ input,
73
+ context,
74
+ }: AuthenticationEventsOptions<DevWabeTypes, PhonePasswordInterface>) {
75
+ const users = await context.wabe.controllers.database.count({
76
+ className: 'User',
77
+ where: {
78
+ authentication: {
79
+ phonePassword: {
80
+ phone: { equalTo: input.phone },
81
+ },
82
+ },
83
+ },
84
+ context: contextWithRoot(context),
85
+ })
86
+
87
+ if (users > 0) throw new Error('Not authorized to create user')
88
+
89
+ return {
90
+ authenticationDataToSave: {
91
+ phone: input.phone,
92
+ password: input.password,
93
+ },
94
+ }
95
+ }
96
+
97
+ async onUpdateAuthenticationData({
98
+ userId,
99
+ input,
100
+ context,
101
+ }: AuthenticationEventsOptionsWithUserId<
102
+ DevWabeTypes,
103
+ PhonePasswordInterface
104
+ >) {
105
+ const users = await context.wabe.controllers.database.getObjects({
106
+ className: 'User',
107
+ where: {
108
+ id: {
109
+ equalTo: userId,
110
+ },
111
+ },
112
+ context,
113
+ select: { authentication: true },
114
+ })
115
+
116
+ if (users.length === 0) throw new Error('User not found')
117
+
118
+ const user = users[0]
119
+
120
+ return {
121
+ authenticationDataToSave: {
122
+ phone: input.phone ?? user?.authentication?.phonePassword?.phone,
123
+ password: input.password
124
+ ? input.password
125
+ : user?.authentication?.phonePassword?.password,
126
+ },
127
+ }
128
+ }
129
+ }
@@ -0,0 +1,79 @@
1
+ import { describe, expect, it, beforeAll, afterAll, afterEach } from 'bun:test'
2
+ import type { DevWabeTypes } from '../../utils/helper'
3
+ import { setupTests, closeTests } from '../../utils/testHelper'
4
+ import type { Wabe } from '../..'
5
+ import { OTP } from '../OTP'
6
+ import { QRCodeOTP } from './QRCodeOTP'
7
+
8
+ describe('QRCodeOTPProvider', () => {
9
+ let wabe: Wabe<DevWabeTypes>
10
+
11
+ beforeAll(async () => {
12
+ const setup = await setupTests()
13
+ wabe = setup.wabe
14
+ })
15
+
16
+ afterAll(async () => {
17
+ await closeTests(wabe)
18
+ })
19
+
20
+ afterEach(async () => {
21
+ await wabe.controllers.database.clearDatabase()
22
+ })
23
+
24
+ it('should return the userId if the OTP code is valid', async () => {
25
+ const createdUser = await wabe.controllers.database.createObject({
26
+ className: 'User',
27
+ context: {
28
+ wabe,
29
+ isRoot: true,
30
+ },
31
+ data: {
32
+ email: 'email@test.fr',
33
+ },
34
+ select: {
35
+ id: true,
36
+ },
37
+ })
38
+
39
+ if (!createdUser) throw new Error('User not created')
40
+
41
+ const otp = new OTP(wabe.config.rootKey).authenticatorGenerate(
42
+ createdUser.id,
43
+ )
44
+
45
+ const qrCodeOTP = new QRCodeOTP()
46
+
47
+ expect(
48
+ await qrCodeOTP.onVerifyChallenge({
49
+ context: {
50
+ wabe,
51
+ isRoot: false,
52
+ },
53
+ input: {
54
+ email: 'email@test.fr',
55
+ otp,
56
+ },
57
+ }),
58
+ ).toEqual({
59
+ userId: createdUser.id,
60
+ })
61
+ })
62
+
63
+ it("should return null if the user doesn't exist", async () => {
64
+ const qrCodeOTP = new QRCodeOTP()
65
+
66
+ expect(
67
+ await qrCodeOTP.onVerifyChallenge({
68
+ context: {
69
+ wabe,
70
+ isRoot: false,
71
+ },
72
+ input: {
73
+ email: 'email@test.fr',
74
+ otp: '123456',
75
+ },
76
+ }),
77
+ ).toEqual(null)
78
+ })
79
+ })
@@ -0,0 +1,65 @@
1
+ import { contextWithRoot } from '../..'
2
+ import type { DevWabeTypes } from '../../utils/helper'
3
+ import type {
4
+ OnVerifyChallengeOptions,
5
+ SecondaryProviderInterface,
6
+ } from '../interface'
7
+ import { OTP } from '../OTP'
8
+
9
+ const DUMMY_USER_ID = '00000000-0000-0000-0000-000000000000'
10
+
11
+ type QRCodeOTPInterface = {
12
+ email: string
13
+ otp: string
14
+ }
15
+
16
+ export class QRCodeOTP
17
+ implements SecondaryProviderInterface<DevWabeTypes, QRCodeOTPInterface>
18
+ {
19
+ async onSendChallenge() {
20
+ // The user should check the application and get the OTP code
21
+ }
22
+
23
+ async onVerifyChallenge({
24
+ context,
25
+ input,
26
+ }: OnVerifyChallengeOptions<DevWabeTypes, QRCodeOTPInterface>) {
27
+ const users = await context.wabe.controllers.database.getObjects({
28
+ className: 'User',
29
+ where: {
30
+ email: {
31
+ equalTo: input.email,
32
+ },
33
+ },
34
+ select: {
35
+ authentication: true,
36
+ role: true,
37
+ secondFA: true,
38
+ email: true,
39
+ id: true,
40
+ provider: true,
41
+ isOauth: true,
42
+ createdAt: true,
43
+ updatedAt: true,
44
+ },
45
+ first: 1,
46
+ context: contextWithRoot(context),
47
+ })
48
+
49
+ const realUser = users.length > 0 ? users[0] : null
50
+ const userId = realUser?.id ?? DUMMY_USER_ID
51
+
52
+ const isDevBypass =
53
+ !context.wabe.config.isProduction &&
54
+ input.otp === '000000' &&
55
+ realUser !== null
56
+
57
+ const otpClass = new OTP(context.wabe.config.rootKey)
58
+
59
+ const isOtpValid = otpClass.authenticatorVerify(input.otp, userId)
60
+
61
+ if (realUser && (isOtpValid || isDevBypass)) return { userId: realUser.id }
62
+
63
+ return null
64
+ }
65
+ }
@@ -0,0 +1,6 @@
1
+ export * from './EmailPassword'
2
+ export * from './Google'
3
+ export * from './GitHub'
4
+ export * from './PhonePassword'
5
+ export * from './EmailOTP'
6
+ export * from './QRCodeOTP'
@@ -0,0 +1,37 @@
1
+ import { describe, expect, it, spyOn } from 'bun:test'
2
+ import { refreshResolver } from './refreshResolver'
3
+ import type { WabeContext } from '../../server/interface'
4
+ import { Session } from '../Session'
5
+
6
+ const context: WabeContext<any> = {
7
+ sessionId: 'sessionId',
8
+ user: {} as any,
9
+ isRoot: false,
10
+ } as WabeContext<any>
11
+
12
+ describe('refreshResolver', () => {
13
+ it('should refresh the session', async () => {
14
+ const spyRefreshSession = spyOn(
15
+ Session.prototype,
16
+ 'refresh',
17
+ ).mockResolvedValue({} as any)
18
+
19
+ await refreshResolver(
20
+ null,
21
+ {
22
+ input: {
23
+ accessToken: 'accessToken',
24
+ refreshToken: 'refreshToken',
25
+ },
26
+ },
27
+ context,
28
+ )
29
+
30
+ expect(spyRefreshSession).toHaveBeenCalledTimes(1)
31
+ expect(spyRefreshSession).toHaveBeenCalledWith(
32
+ 'accessToken',
33
+ 'refreshToken',
34
+ context,
35
+ )
36
+ })
37
+ })
@@ -0,0 +1,20 @@
1
+ import type { WabeContext } from '../../server/interface'
2
+ import type { DevWabeTypes } from '../../utils/helper'
3
+ import { Session } from '../Session'
4
+
5
+ export const refreshResolver = async (
6
+ _: any,
7
+ args: any,
8
+ context: WabeContext<DevWabeTypes>,
9
+ ) => {
10
+ const {
11
+ input: { refreshToken, accessToken },
12
+ } = args
13
+
14
+ const session = new Session()
15
+
16
+ const { accessToken: newAccessToken, refreshToken: newRefreshToken } =
17
+ await session.refresh(accessToken, refreshToken, context)
18
+
19
+ return { accessToken: newAccessToken, refreshToken: newRefreshToken }
20
+ }
@@ -0,0 +1,59 @@
1
+ import { describe, it, beforeAll, afterAll, expect } from 'bun:test'
2
+ import { gql } from 'graphql-request'
3
+ import type { Wabe } from 'src'
4
+ import { getAdminUserClient, type DevWabeTypes } from 'src/utils/helper'
5
+ import { setupTests, closeTests } from 'src/utils/testHelper'
6
+
7
+ describe('signInWithResolver integration test', () => {
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 all fields of the user on signInWith resolver', async () => {
20
+ const adminClient = await getAdminUserClient(wabe.config.port, wabe, {
21
+ email: 'admin@wabe.dev',
22
+ password: 'admin',
23
+ })
24
+ const res = await adminClient.request<any>(
25
+ gql`
26
+ mutation signInWith($input: SignInWithInput!) {
27
+ signInWith(input: $input) {
28
+ user {
29
+ id
30
+ authentication {
31
+ emailPassword {
32
+ email
33
+ }
34
+ }
35
+ role {
36
+ name
37
+ }
38
+ }
39
+ }
40
+ }
41
+ `,
42
+ {
43
+ input: {
44
+ authentication: {
45
+ emailPassword: {
46
+ email: 'admin@wabe.dev',
47
+ password: 'admin',
48
+ },
49
+ },
50
+ },
51
+ },
52
+ )
53
+
54
+ expect(res.signInWith.user.role.name).toBe('Admin')
55
+ expect(res.signInWith.user.authentication.emailPassword).toEqual({
56
+ email: 'admin@wabe.dev',
57
+ })
58
+ })
59
+ })