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,843 +0,0 @@
1
- import { describe, expect, it, spyOn } from 'bun:test'
2
- import { v4 as uuid } from 'uuid'
3
- import getPort from 'get-port'
4
- import { Wabe } from '.'
5
- import { Schema } from '../schema'
6
- import { OperationType } from '../hooks'
7
- import { getAnonymousClient } from '../utils/helper'
8
- import { gql } from 'graphql-request'
9
- import { getDatabaseAdapter } from '../utils/testHelper'
10
- import * as WobeYoga from 'wobe-graphql-yoga'
11
-
12
- describe('Server', () => {
13
- it('should throw error if no jwt secret provided but cookie session choosen', async () => {
14
- const databaseId = uuid()
15
-
16
- const port = await getPort()
17
- const wabe = new Wabe({
18
- isProduction: false,
19
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
20
- database: {
21
- // @ts-expect-error
22
- adapter: await getDatabaseAdapter(databaseId),
23
- },
24
- port,
25
- authentication: {
26
- // @ts-expect-error
27
- session: {
28
- cookieSession: true,
29
- },
30
- },
31
- routes: [
32
- {
33
- handler: (ctx) => ctx.res.send('Hello World!'),
34
- path: '/hello',
35
- method: 'GET',
36
- },
37
- ],
38
- schema: {
39
- classes: [
40
- {
41
- name: 'Collection1',
42
- fields: { name: { type: 'String' } },
43
- },
44
- ],
45
- },
46
- })
47
-
48
- expect(wabe.start()).rejects.toThrow('Authentication session requires jwt secret')
49
- })
50
-
51
- it('should throw error if no jwt secret provided but csrf protection is enabled', async () => {
52
- const databaseId = uuid()
53
-
54
- const port = await getPort()
55
- const wabe = new Wabe({
56
- isProduction: false,
57
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
58
- database: {
59
- // @ts-expect-error
60
- adapter: await getDatabaseAdapter(databaseId),
61
- },
62
- port,
63
- authentication: {
64
- // @ts-expect-error
65
- session: {},
66
- },
67
- security: {
68
- disableCSRFProtection: false,
69
- },
70
- routes: [
71
- {
72
- handler: (ctx) => ctx.res.send('Hello World!'),
73
- path: '/hello',
74
- method: 'GET',
75
- },
76
- ],
77
- schema: {
78
- classes: [
79
- {
80
- name: 'Collection1',
81
- fields: { name: { type: 'String' } },
82
- },
83
- ],
84
- },
85
- })
86
-
87
- expect(wabe.start()).rejects.toThrow('Authentication session requires jwt secret')
88
- })
89
-
90
- it('should return GraphiQL for GET /graphql in development', async () => {
91
- const databaseId = uuid()
92
- const port = await getPort()
93
- const wabe = new Wabe({
94
- isProduction: false,
95
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
96
- database: {
97
- // @ts-expect-error
98
- adapter: await getDatabaseAdapter(databaseId),
99
- },
100
- port,
101
- security: {
102
- disableCSRFProtection: true,
103
- },
104
- schema: {
105
- classes: [
106
- {
107
- name: 'Collection1',
108
- fields: { name: { type: 'String' } },
109
- },
110
- ],
111
- },
112
- })
113
-
114
- await wabe.start()
115
-
116
- const res = await fetch(`http://127.0.0.1:${port}/graphql`, {
117
- method: 'GET',
118
- headers: { Accept: 'text/html' },
119
- })
120
-
121
- const text = await res.text()
122
- expect(res.status).toBe(200)
123
- expect(text).toContain('GraphiQL')
124
-
125
- await wabe.close()
126
- })
127
-
128
- it('should return GraphiQL in production by default', async () => {
129
- const databaseId = uuid()
130
- const port = await getPort()
131
- const wabe = new Wabe({
132
- isProduction: true,
133
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
134
- database: {
135
- // @ts-expect-error
136
- adapter: await getDatabaseAdapter(databaseId),
137
- },
138
- port,
139
- security: {
140
- disableCSRFProtection: true,
141
- },
142
- schema: {
143
- classes: [
144
- {
145
- name: 'Collection1',
146
- fields: { name: { type: 'String' } },
147
- },
148
- ],
149
- },
150
- })
151
-
152
- await wabe.start()
153
-
154
- const res = await fetch(`http://127.0.0.1:${port}/graphql`, {
155
- method: 'GET',
156
- headers: { Accept: 'text/html' },
157
- })
158
-
159
- const text = await res.text()
160
- expect(res.status).toBe(200)
161
- expect(text).toContain('GraphiQL')
162
-
163
- await wabe.close()
164
- })
165
-
166
- it('should not return GraphiQL when disableGraphQLDashboard is true', async () => {
167
- const databaseId = uuid()
168
- const port = await getPort()
169
- const wabe = new Wabe({
170
- isProduction: false,
171
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
172
- database: {
173
- // @ts-expect-error
174
- adapter: await getDatabaseAdapter(databaseId),
175
- },
176
- port,
177
- security: {
178
- disableCSRFProtection: true,
179
- disableGraphQLDashboard: true,
180
- },
181
- schema: {
182
- classes: [
183
- {
184
- name: 'Collection1',
185
- fields: { name: { type: 'String' } },
186
- },
187
- ],
188
- },
189
- })
190
-
191
- await wabe.start()
192
-
193
- const res = await fetch(`http://127.0.0.1:${port}/graphql`, {
194
- method: 'GET',
195
- headers: { Accept: 'text/html' },
196
- })
197
-
198
- const text = await res.text()
199
- expect(text).not.toContain('GraphiQL')
200
-
201
- await wabe.close()
202
- })
203
-
204
- it('should pass graphql options to yoga plugin', async () => {
205
- const databaseId = uuid()
206
-
207
- const receivedOptions: any[] = []
208
- const originalPlugin = WobeYoga.WobeGraphqlYogaPlugin
209
- const pluginSpy = spyOn(WobeYoga, 'WobeGraphqlYogaPlugin').mockImplementation(
210
- (options: any) => {
211
- receivedOptions.push(options)
212
- return originalPlugin(options)
213
- },
214
- )
215
-
216
- const port = await getPort()
217
- const wabe = new Wabe({
218
- isProduction: true,
219
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
220
- database: {
221
- // @ts-expect-error
222
- adapter: await getDatabaseAdapter(databaseId),
223
- },
224
- port,
225
- authentication: {
226
- session: {
227
- jwtSecret: 'secret',
228
- },
229
- },
230
- security: {
231
- disableCSRFProtection: true,
232
- maxGraphqlDepth: 60,
233
- },
234
- schema: {
235
- classes: [
236
- {
237
- name: 'Collection1',
238
- fields: { name: { type: 'String' } },
239
- },
240
- ],
241
- },
242
- })
243
-
244
- try {
245
- await wabe.start()
246
- } finally {
247
- await wabe.close()
248
- pluginSpy.mockRestore()
249
- }
250
-
251
- expect(receivedOptions.length).toBeGreaterThan(0)
252
- const args = receivedOptions[0]
253
- expect(args?.allowIntrospection).toBe(true)
254
- expect(args?.maxDepth).toBe(60)
255
- expect(args?.allowMultipleOperations).toBe(true)
256
- })
257
-
258
- it('should mask graphql errors message', async () => {
259
- spyOn(console, 'error').mockReturnValue()
260
- const databaseId = uuid()
261
-
262
- const port = await getPort()
263
- const wabe = new Wabe({
264
- isProduction: false,
265
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
266
- database: {
267
- // @ts-expect-error
268
- adapter: await getDatabaseAdapter(databaseId),
269
- },
270
- security: {
271
- hideSensitiveErrorMessage: true,
272
- disableCSRFProtection: true,
273
- },
274
- port,
275
- schema: {
276
- resolvers: {
277
- queries: {
278
- tata: {
279
- type: 'Boolean',
280
- resolve: () => {
281
- throw new Error('Error message')
282
- },
283
- },
284
- },
285
- },
286
- },
287
- })
288
-
289
- await wabe.start()
290
-
291
- const graphqlClient = getAnonymousClient(port)
292
-
293
- expect(
294
- graphqlClient.request<any>(gql`
295
- query tata {
296
- tata
297
- }
298
- `),
299
- ).rejects.toThrow('Unexpected error')
300
-
301
- await wabe.close()
302
- })
303
-
304
- it('should load routes', async () => {
305
- const databaseId = uuid()
306
-
307
- const port = await getPort()
308
- const wabe = new Wabe({
309
- isProduction: false,
310
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
311
- database: {
312
- // @ts-expect-error
313
- adapter: await getDatabaseAdapter(databaseId),
314
- },
315
- security: {
316
- disableCSRFProtection: true,
317
- },
318
- port,
319
- routes: [
320
- {
321
- handler: (ctx) => ctx.res.send('Hello World!'),
322
- path: '/hello',
323
- method: 'GET',
324
- },
325
- ],
326
- schema: {
327
- classes: [
328
- {
329
- name: 'Collection1',
330
- fields: { name: { type: 'String' } },
331
- },
332
- ],
333
- },
334
- })
335
-
336
- await wabe.start()
337
-
338
- const res = await fetch(`http://127.0.0.1:${port}/hello`)
339
-
340
- expect(await res.text()).toBe('Hello World!')
341
- await wabe.close()
342
- })
343
-
344
- it('should disable /bucket route in production by default', async () => {
345
- const databaseId = uuid()
346
- const port = await getPort()
347
- const wabe = new Wabe({
348
- isProduction: true,
349
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
350
- database: {
351
- // @ts-expect-error
352
- adapter: await getDatabaseAdapter(databaseId),
353
- },
354
- port,
355
- security: {
356
- disableCSRFProtection: true,
357
- },
358
- schema: {
359
- classes: [
360
- {
361
- name: 'Collection1',
362
- fields: { name: { type: 'String' } },
363
- },
364
- ],
365
- },
366
- })
367
-
368
- await wabe.start()
369
-
370
- const res = await fetch(`http://127.0.0.1:${port}/bucket/test.txt`)
371
- expect(res.status).toBe(404)
372
-
373
- await wabe.close()
374
- })
375
-
376
- it('should setup the root key in context if the root key is correct', async () => {
377
- const databaseId = uuid()
378
-
379
- const port = await getPort()
380
- const wabe = new Wabe({
381
- isProduction: false,
382
- rootKey: 'thisistherootkey',
383
- database: {
384
- // @ts-expect-error
385
- adapter: await getDatabaseAdapter(databaseId),
386
- },
387
- security: {
388
- disableCSRFProtection: true,
389
- },
390
- port,
391
- schema: {
392
- classes: [
393
- {
394
- name: 'Collection1',
395
- fields: { name: { type: 'String' } },
396
- },
397
- ],
398
- },
399
- })
400
-
401
- await wabe.start()
402
-
403
- const res = await fetch(`http://127.0.0.1:${port}/graphql`, {
404
- method: 'POST',
405
- headers: {
406
- 'Content-Type': 'application/json',
407
- },
408
- body: JSON.stringify({
409
- query: `
410
- query {
411
- collection1s {
412
- edges {
413
- node {
414
- name
415
- }
416
- }
417
- }
418
- }
419
- `,
420
- }),
421
- })
422
-
423
- expect((await res.json()).errors[0].message).toEqual(
424
- 'Permission denied to read class Collection1',
425
- )
426
-
427
- expect(res.status).toEqual(200)
428
- await wabe.close()
429
- })
430
-
431
- it('should run server', async () => {
432
- const databaseId = uuid()
433
-
434
- const port = await getPort()
435
- const wabe = new Wabe({
436
- isProduction: false,
437
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
438
- database: {
439
- // @ts-expect-error
440
- adapter: await getDatabaseAdapter(databaseId),
441
- },
442
- security: {
443
- disableCSRFProtection: true,
444
- },
445
- port,
446
- schema: {
447
- classes: [
448
- {
449
- name: 'Collection1',
450
- fields: { name: { type: 'String' } },
451
- },
452
- ],
453
- },
454
- })
455
-
456
- await wabe.start()
457
-
458
- const res = await fetch(`http://127.0.0.1:${port}/health`)
459
-
460
- expect(res.status).toEqual(200)
461
- await wabe.close()
462
- })
463
-
464
- it('should run server on different hostname', async () => {
465
- const databaseId = uuid()
466
-
467
- const port = await getPort()
468
- const wabe = new Wabe({
469
- isProduction: false,
470
- hostname: '0.0.0.0',
471
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
472
- database: {
473
- // @ts-expect-error
474
- adapter: await getDatabaseAdapter(databaseId),
475
- },
476
- port,
477
- security: {
478
- disableCSRFProtection: true,
479
- },
480
- schema: {
481
- classes: [
482
- {
483
- name: 'Collection1',
484
- fields: { name: { type: 'String' } },
485
- },
486
- ],
487
- },
488
- })
489
-
490
- await wabe.start()
491
-
492
- const res = await fetch(`http://0.0.0.0:${port}/health`)
493
-
494
- expect(res.status).toEqual(200)
495
- await wabe.close()
496
- })
497
-
498
- it('should throw an error if hook has negative value', async () => {
499
- const databaseId = uuid()
500
-
501
- const port = await getPort()
502
- expect(
503
- async () =>
504
- new Wabe({
505
- isProduction: false,
506
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
507
- database: {
508
- // @ts-expect-error
509
- adapter: await getDatabaseAdapter(databaseId),
510
- },
511
- security: {
512
- disableCSRFProtection: true,
513
- },
514
- port,
515
- hooks: [
516
- {
517
- operationType: OperationType.BeforeCreate,
518
- callback: () => {},
519
- priority: -1,
520
- },
521
- ],
522
- }),
523
- ).toThrow('Hook priority <= 0 is reserved for internal uses')
524
-
525
- expect(
526
- async () =>
527
- new Wabe({
528
- isProduction: false,
529
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
530
- database: {
531
- // @ts-expect-error
532
- adapter: await getDatabaseAdapter(databaseId),
533
- },
534
- security: {
535
- disableCSRFProtection: true,
536
- },
537
- port,
538
- hooks: [],
539
- }),
540
- ).not.toThrow()
541
-
542
- expect(
543
- async () =>
544
- new Wabe({
545
- isProduction: false,
546
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
547
- database: {
548
- // @ts-expect-error
549
- adapter: await getDatabaseAdapter(databaseId),
550
- },
551
- port,
552
- security: {
553
- disableCSRFProtection: true,
554
- },
555
- hooks: [
556
- {
557
- operationType: OperationType.BeforeCreate,
558
- callback: () => {},
559
- priority: 1,
560
- },
561
- ],
562
- }),
563
- ).not.toThrow()
564
- })
565
-
566
- it('should run server without schema object', async () => {
567
- const databaseId = uuid()
568
-
569
- const port = await getPort()
570
- const wabe = new Wabe({
571
- isProduction: false,
572
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
573
- database: {
574
- // @ts-expect-error
575
- adapter: await getDatabaseAdapter(databaseId),
576
- },
577
- port,
578
- security: {
579
- disableCSRFProtection: true,
580
- },
581
- })
582
-
583
- await wabe.start()
584
-
585
- const res = await fetch(`http://127.0.0.1:${port}/health`)
586
-
587
- expect(res.status).toEqual(200)
588
- await wabe.close()
589
- })
590
-
591
- it('should update the schema to static Wabe after the Schema initialization', async () => {
592
- const spySchemaDefaultClass = spyOn(Schema.prototype, 'defaultClass')
593
- const spySchemaDefaultEnum = spyOn(Schema.prototype, 'defaultEnum')
594
-
595
- const databaseId = uuid()
596
-
597
- const port = await getPort()
598
-
599
- const wabe = new Wabe({
600
- isProduction: false,
601
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
602
- database: {
603
- // @ts-expect-error
604
- adapter: await getDatabaseAdapter(databaseId),
605
- },
606
- port,
607
- security: {
608
- disableCSRFProtection: true,
609
- },
610
- schema: {
611
- classes: [
612
- {
613
- name: 'Collection1',
614
- fields: { name: { type: 'String' } },
615
- },
616
- ],
617
- },
618
- })
619
-
620
- await wabe.start()
621
-
622
- // _Session class is a default class so if it's present the schema is updated
623
- const isSessionClassExist = wabe.config.schema?.classes?.find(
624
- (schemaClass) => schemaClass.name === '_Session',
625
- )
626
-
627
- expect(isSessionClassExist).not.toBeUndefined()
628
-
629
- expect(spySchemaDefaultClass).toHaveBeenCalledTimes(1)
630
- expect(spySchemaDefaultEnum).toHaveBeenCalledTimes(1)
631
-
632
- await wabe.close()
633
- })
634
-
635
- it('should allow introspection in development by default', async () => {
636
- const databaseId = uuid()
637
- const port = await getPort()
638
- const wabe = new Wabe({
639
- isProduction: false,
640
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
641
- database: {
642
- // @ts-expect-error
643
- adapter: await getDatabaseAdapter(databaseId),
644
- },
645
- port,
646
- security: {
647
- disableCSRFProtection: true,
648
- },
649
- schema: {
650
- classes: [
651
- {
652
- name: 'Collection1',
653
- fields: { name: { type: 'String' } },
654
- },
655
- ],
656
- },
657
- })
658
-
659
- await wabe.start()
660
-
661
- const res = await fetch(`http://127.0.0.1:${port}/graphql`, {
662
- method: 'POST',
663
- headers: { 'Content-Type': 'application/json' },
664
- body: JSON.stringify({
665
- query: '{ __schema { types { name } } }',
666
- }),
667
- })
668
-
669
- const json = (await res.json()) as { data?: { __schema?: { types?: { name: string }[] } } }
670
- expect(json.data?.__schema?.types).toBeDefined()
671
- expect(json.data?.__schema?.types?.length).toBeGreaterThan(0)
672
-
673
- await wabe.close()
674
- })
675
-
676
- it('should block introspection when disableIntrospection is true', async () => {
677
- const databaseId = uuid()
678
- const port = await getPort()
679
- const wabe = new Wabe({
680
- isProduction: false,
681
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
682
- database: {
683
- // @ts-expect-error
684
- adapter: await getDatabaseAdapter(databaseId),
685
- },
686
- port,
687
- security: {
688
- disableCSRFProtection: true,
689
- disableIntrospection: true,
690
- },
691
- schema: {
692
- classes: [
693
- {
694
- name: 'Collection1',
695
- fields: { name: { type: 'String' } },
696
- },
697
- ],
698
- },
699
- })
700
-
701
- await wabe.start()
702
-
703
- const res = await fetch(`http://127.0.0.1:${port}/graphql`, {
704
- method: 'POST',
705
- headers: { 'Content-Type': 'application/json' },
706
- body: JSON.stringify({
707
- query: '{ __schema { types { name } } }',
708
- }),
709
- })
710
-
711
- const json = (await res.json()) as { errors?: { message: string }[] }
712
- expect(json.errors).toBeDefined()
713
- expect(json.errors?.[0]?.message).toContain('introspection')
714
-
715
- await wabe.close()
716
- })
717
-
718
- it('should block introspection in production when disableIntrospection is true', async () => {
719
- const databaseId = uuid()
720
- const port = await getPort()
721
- const wabe = new Wabe({
722
- isProduction: true,
723
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
724
- database: {
725
- // @ts-expect-error
726
- adapter: await getDatabaseAdapter(databaseId),
727
- },
728
- port,
729
- security: {
730
- disableCSRFProtection: true,
731
- disableIntrospection: true,
732
- },
733
- schema: {
734
- classes: [
735
- {
736
- name: 'Collection1',
737
- fields: { name: { type: 'String' } },
738
- },
739
- ],
740
- },
741
- })
742
-
743
- await wabe.start()
744
-
745
- const res = await fetch(`http://127.0.0.1:${port}/graphql`, {
746
- method: 'POST',
747
- headers: { 'Content-Type': 'application/json' },
748
- body: JSON.stringify({
749
- query: '{ __schema { types { name } } }',
750
- }),
751
- })
752
-
753
- const json = (await res.json()) as { errors?: { message: string }[] }
754
- expect(json.errors).toBeDefined()
755
- expect(json.errors?.[0]?.message).toContain('introspection')
756
-
757
- await wabe.close()
758
- })
759
-
760
- it('should allow introspection in production by default', async () => {
761
- const databaseId = uuid()
762
- const port = await getPort()
763
- const wabe = new Wabe({
764
- isProduction: true,
765
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
766
- database: {
767
- // @ts-expect-error
768
- adapter: await getDatabaseAdapter(databaseId),
769
- },
770
- port,
771
- security: {
772
- disableCSRFProtection: true,
773
- },
774
- schema: {
775
- classes: [
776
- {
777
- name: 'Collection1',
778
- fields: { name: { type: 'String' } },
779
- },
780
- ],
781
- },
782
- })
783
-
784
- await wabe.start()
785
-
786
- const res = await fetch(`http://127.0.0.1:${port}/graphql`, {
787
- method: 'POST',
788
- headers: { 'Content-Type': 'application/json' },
789
- body: JSON.stringify({
790
- query: '{ __schema { types { name } } }',
791
- }),
792
- })
793
-
794
- const json = (await res.json()) as { data?: { __schema?: { types?: { name: string }[] } } }
795
- expect(json.data?.__schema?.types).toBeDefined()
796
- expect(json.data?.__schema?.types?.length).toBeGreaterThan(0)
797
-
798
- await wabe.close()
799
- })
800
-
801
- it('should load RoleEnum correctly', async () => {
802
- const databaseId = uuid()
803
-
804
- const port = await getPort()
805
-
806
- const wabe = new Wabe({
807
- isProduction: false,
808
- rootKey: 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
809
- database: {
810
- // @ts-expect-error
811
- adapter: await getDatabaseAdapter(databaseId),
812
- },
813
- port,
814
- security: {
815
- disableCSRFProtection: true,
816
- },
817
- schema: {
818
- classes: [
819
- {
820
- name: 'Collection1',
821
- fields: { name: { type: 'String' } },
822
- },
823
- ],
824
- },
825
- authentication: {
826
- roles: ['Admin', 'Client'],
827
- },
828
- })
829
-
830
- await wabe.start()
831
-
832
- const roleEnum = wabe.config.schema?.enums?.find((schemaEnum) => schemaEnum.name === 'RoleEnum')
833
-
834
- expect(roleEnum).not.toBeUndefined()
835
- expect(roleEnum?.values).toEqual({
836
- Admin: 'Admin',
837
- Client: 'Client',
838
- DashboardAdmin: 'DashboardAdmin',
839
- })
840
-
841
- await wabe.close()
842
- })
843
- })