wabe 0.6.12 → 0.6.14

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 (156) hide show
  1. package/dist/database/DatabaseController.d.ts +2 -0
  2. package/dist/file/FileDevAdapter.d.ts +1 -0
  3. package/dist/graphql/pointerAndRelationFunction.d.ts +6 -0
  4. package/dist/index.js +3827 -3541
  5. package/dist/schema/Schema.d.ts +2 -2
  6. package/dist/server/generateCodegen.d.ts +10 -0
  7. package/dist/server/index.d.ts +2 -1
  8. package/dist/utils/objectKeys.d.ts +1 -0
  9. package/package.json +7 -4
  10. package/dev/index.ts +0 -215
  11. package/dist/schema/resolvers/sendEmail.d.ts +0 -1
  12. package/generated/schema.graphql +0 -1945
  13. package/generated/wabe.ts +0 -448
  14. package/src/authentication/OTP.test.ts +0 -69
  15. package/src/authentication/OTP.ts +0 -64
  16. package/src/authentication/Session.test.ts +0 -629
  17. package/src/authentication/Session.ts +0 -517
  18. package/src/authentication/cookies.ts +0 -10
  19. package/src/authentication/defaultAuthentication.ts +0 -209
  20. package/src/authentication/index.ts +0 -4
  21. package/src/authentication/interface.ts +0 -177
  22. package/src/authentication/oauth/GitHub.test.ts +0 -91
  23. package/src/authentication/oauth/GitHub.ts +0 -121
  24. package/src/authentication/oauth/Google.test.ts +0 -91
  25. package/src/authentication/oauth/Google.ts +0 -101
  26. package/src/authentication/oauth/Oauth2Client.test.ts +0 -219
  27. package/src/authentication/oauth/Oauth2Client.ts +0 -135
  28. package/src/authentication/oauth/index.ts +0 -2
  29. package/src/authentication/oauth/utils.test.ts +0 -33
  30. package/src/authentication/oauth/utils.ts +0 -27
  31. package/src/authentication/providers/EmailOTP.test.ts +0 -127
  32. package/src/authentication/providers/EmailOTP.ts +0 -95
  33. package/src/authentication/providers/EmailPassword.test.ts +0 -263
  34. package/src/authentication/providers/EmailPassword.ts +0 -138
  35. package/src/authentication/providers/EmailPasswordSRP.test.ts +0 -208
  36. package/src/authentication/providers/EmailPasswordSRP.ts +0 -191
  37. package/src/authentication/providers/GitHub.ts +0 -24
  38. package/src/authentication/providers/Google.ts +0 -24
  39. package/src/authentication/providers/OAuth.test.ts +0 -185
  40. package/src/authentication/providers/OAuth.ts +0 -106
  41. package/src/authentication/providers/PhonePassword.test.ts +0 -221
  42. package/src/authentication/providers/PhonePassword.ts +0 -136
  43. package/src/authentication/providers/QRCodeOTP.test.ts +0 -77
  44. package/src/authentication/providers/QRCodeOTP.ts +0 -69
  45. package/src/authentication/providers/index.ts +0 -6
  46. package/src/authentication/resolvers/refreshResolver.test.ts +0 -30
  47. package/src/authentication/resolvers/refreshResolver.ts +0 -19
  48. package/src/authentication/resolvers/signInWithResolver.inte.test.ts +0 -59
  49. package/src/authentication/resolvers/signInWithResolver.test.ts +0 -306
  50. package/src/authentication/resolvers/signInWithResolver.ts +0 -106
  51. package/src/authentication/resolvers/signOutResolver.test.ts +0 -38
  52. package/src/authentication/resolvers/signOutResolver.ts +0 -18
  53. package/src/authentication/resolvers/signUpWithResolver.test.ts +0 -180
  54. package/src/authentication/resolvers/signUpWithResolver.ts +0 -68
  55. package/src/authentication/resolvers/verifyChallenge.test.ts +0 -230
  56. package/src/authentication/resolvers/verifyChallenge.ts +0 -78
  57. package/src/authentication/roles.test.ts +0 -49
  58. package/src/authentication/roles.ts +0 -40
  59. package/src/authentication/security.ts +0 -278
  60. package/src/authentication/utils.test.ts +0 -97
  61. package/src/authentication/utils.ts +0 -39
  62. package/src/cache/InMemoryCache.test.ts +0 -62
  63. package/src/cache/InMemoryCache.ts +0 -45
  64. package/src/cron/index.test.ts +0 -17
  65. package/src/cron/index.ts +0 -43
  66. package/src/database/DatabaseController.test.ts +0 -613
  67. package/src/database/DatabaseController.ts +0 -1415
  68. package/src/database/index.test.ts +0 -1551
  69. package/src/database/index.ts +0 -9
  70. package/src/database/interface.ts +0 -308
  71. package/src/email/DevAdapter.ts +0 -7
  72. package/src/email/EmailController.test.ts +0 -29
  73. package/src/email/EmailController.ts +0 -13
  74. package/src/email/index.ts +0 -2
  75. package/src/email/interface.ts +0 -36
  76. package/src/email/templates/sendOtpCode.ts +0 -120
  77. package/src/file/FileController.ts +0 -28
  78. package/src/file/FileDevAdapter.ts +0 -51
  79. package/src/file/hookDeleteFile.ts +0 -25
  80. package/src/file/hookReadFile.ts +0 -66
  81. package/src/file/hookUploadFile.ts +0 -52
  82. package/src/file/index.test.ts +0 -1031
  83. package/src/file/index.ts +0 -2
  84. package/src/file/interface.ts +0 -63
  85. package/src/file/security.ts +0 -156
  86. package/src/graphql/GraphQLSchema.test.ts +0 -5099
  87. package/src/graphql/GraphQLSchema.ts +0 -886
  88. package/src/graphql/index.ts +0 -2
  89. package/src/graphql/parseGraphqlSchema.ts +0 -85
  90. package/src/graphql/parser.test.ts +0 -203
  91. package/src/graphql/parser.ts +0 -707
  92. package/src/graphql/pointerAndRelationFunction.ts +0 -191
  93. package/src/graphql/resolvers.ts +0 -464
  94. package/src/graphql/tests/aggregation.test.ts +0 -1115
  95. package/src/graphql/tests/e2e.test.ts +0 -590
  96. package/src/graphql/tests/scalars.test.ts +0 -250
  97. package/src/graphql/types.ts +0 -227
  98. package/src/hooks/HookObject.test.ts +0 -122
  99. package/src/hooks/HookObject.ts +0 -165
  100. package/src/hooks/authentication.ts +0 -67
  101. package/src/hooks/createUser.test.ts +0 -77
  102. package/src/hooks/createUser.ts +0 -10
  103. package/src/hooks/defaultFields.test.ts +0 -176
  104. package/src/hooks/defaultFields.ts +0 -32
  105. package/src/hooks/deleteSession.test.ts +0 -181
  106. package/src/hooks/deleteSession.ts +0 -20
  107. package/src/hooks/hashFieldHook.test.ts +0 -152
  108. package/src/hooks/hashFieldHook.ts +0 -89
  109. package/src/hooks/index.test.ts +0 -258
  110. package/src/hooks/index.ts +0 -420
  111. package/src/hooks/permissions.test.ts +0 -412
  112. package/src/hooks/permissions.ts +0 -93
  113. package/src/hooks/protected.test.ts +0 -551
  114. package/src/hooks/protected.ts +0 -74
  115. package/src/hooks/searchableFields.test.ts +0 -147
  116. package/src/hooks/searchableFields.ts +0 -86
  117. package/src/hooks/session.test.ts +0 -134
  118. package/src/hooks/session.ts +0 -76
  119. package/src/hooks/setEmail.test.ts +0 -216
  120. package/src/hooks/setEmail.ts +0 -33
  121. package/src/hooks/setupAcl.test.ts +0 -618
  122. package/src/hooks/setupAcl.ts +0 -25
  123. package/src/hooks/virtualFields.test.ts +0 -228
  124. package/src/hooks/virtualFields.ts +0 -48
  125. package/src/index.ts +0 -9
  126. package/src/schema/Schema.test.ts +0 -482
  127. package/src/schema/Schema.ts +0 -839
  128. package/src/schema/defaultResolvers.ts +0 -93
  129. package/src/schema/index.ts +0 -1
  130. package/src/schema/resolvers/meResolver.test.ts +0 -62
  131. package/src/schema/resolvers/meResolver.ts +0 -10
  132. package/src/schema/resolvers/resetPassword.test.ts +0 -341
  133. package/src/schema/resolvers/resetPassword.ts +0 -63
  134. package/src/schema/resolvers/sendEmail.test.ts +0 -118
  135. package/src/schema/resolvers/sendEmail.ts +0 -21
  136. package/src/schema/resolvers/sendOtpCode.test.ts +0 -141
  137. package/src/schema/resolvers/sendOtpCode.ts +0 -52
  138. package/src/security.test.ts +0 -4136
  139. package/src/server/defaultSessionHandler.test.ts +0 -62
  140. package/src/server/defaultSessionHandler.ts +0 -104
  141. package/src/server/generateCodegen.ts +0 -433
  142. package/src/server/index.test.ts +0 -843
  143. package/src/server/index.ts +0 -336
  144. package/src/server/interface.ts +0 -11
  145. package/src/server/routes/authHandler.ts +0 -171
  146. package/src/server/routes/index.ts +0 -48
  147. package/src/utils/crypto.test.ts +0 -41
  148. package/src/utils/crypto.ts +0 -105
  149. package/src/utils/database.ts +0 -8
  150. package/src/utils/export.ts +0 -12
  151. package/src/utils/helper.ts +0 -204
  152. package/src/utils/index.test.ts +0 -11
  153. package/src/utils/index.ts +0 -196
  154. package/src/utils/preload.ts +0 -8
  155. package/src/utils/testHelper.ts +0 -124
  156. 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
- }