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