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,8 +0,0 @@
1
- import type { WabeTypes } from '../server'
2
- import type { WabeContext } from '../server/interface'
3
-
4
- export const getDatabaseController = <T extends WabeTypes>(context: WabeContext<T>) => {
5
- const databaseController = context.wabe.controllers?.database
6
- if (!databaseController) throw new Error('No database controller found')
7
- return databaseController
8
- }
@@ -1,12 +0,0 @@
1
- import type { WabeContext } from '../server/interface'
2
-
3
- export const contextWithRoot = (context: WabeContext<any>): WabeContext<any> => ({
4
- ...context,
5
- isRoot: true,
6
- })
7
-
8
- export const notEmpty = <T>(value: T | null | undefined): value is T =>
9
- value !== null && value !== undefined
10
-
11
- export * from './crypto'
12
- export * from './database'
@@ -1,204 +0,0 @@
1
- import { gql, GraphQLClient } from 'graphql-request'
2
- import {
3
- RoleEnum,
4
- type WabeSchemaWhereTypes,
5
- type WabeSchemaEnums,
6
- type WabeSchemaScalars,
7
- type WabeSchemaTypes,
8
- } from '../../generated/wabe'
9
- import type { Wabe, WabeTypes } from '../server'
10
- import { defaultPrivateFields } from 'src/schema'
11
-
12
- export interface DevWabeTypes extends WabeTypes {
13
- types: WabeSchemaTypes
14
- scalars: WabeSchemaScalars
15
- enums: WabeSchemaEnums
16
- where: WabeSchemaWhereTypes
17
- }
18
-
19
- export const selectFieldsWithoutPrivateFields = <T extends Record<string, any>>(select?: T): T =>
20
- Object.entries(select || {}).reduce((acc, [key, value]) => {
21
- if (defaultPrivateFields.includes(key)) return acc
22
-
23
- return {
24
- ...acc,
25
- [key]: value,
26
- }
27
- }, {} as T)
28
-
29
- export const firstLetterUpperCase = (str: string): string =>
30
- str.charAt(0).toUpperCase() + str.slice(1)
31
-
32
- export const getGraphqlClient = (port: number): GraphQLClient => {
33
- const client = new GraphQLClient(`http://127.0.0.1:${port}/graphql`, {
34
- headers: {
35
- 'Wabe-Root-Key': 'dev',
36
- },
37
- })
38
-
39
- return { ...client, request: client.request<any> } as GraphQLClient
40
- }
41
-
42
- export const getAnonymousClient = (port: number): GraphQLClient => {
43
- const client = new GraphQLClient(`http://127.0.0.1:${port}/graphql`)
44
-
45
- return { ...client, request: client.request<any> } as GraphQLClient
46
- }
47
-
48
- export const getUserClient = (
49
- port: number,
50
- options: {
51
- accessToken?: string
52
- csrfToken?: string
53
- },
54
- ): GraphQLClient => {
55
- const client = new GraphQLClient(`http://127.0.0.1:${port}/graphql`, {
56
- headers: {
57
- 'Wabe-Access-Token': options.accessToken || '',
58
- 'Wabe-Csrf-Token': options.csrfToken || '',
59
- },
60
- })
61
-
62
- return { ...client, request: client.request<any> } as GraphQLClient
63
- }
64
-
65
- export const getAdminUserClient = async (
66
- port: number,
67
- wabe: Wabe<DevWabeTypes>,
68
- { email, password }: { email: string; password: string },
69
- ): Promise<GraphQLClient> => {
70
- const roles = await wabe.controllers.database.getObjects({
71
- className: 'Role',
72
- context: {
73
- isRoot: true,
74
- wabe,
75
- } as any,
76
- select: { id: true },
77
- where: {
78
- name: { equalTo: RoleEnum.Admin },
79
- },
80
- })
81
-
82
- const adminRoleId = roles[0]?.id
83
-
84
- const res = await getGraphqlClient(port).request<any>(
85
- gql`
86
- mutation signUpWith($input: SignUpWithInput!) {
87
- signUpWith(input: $input) {
88
- id
89
- accessToken
90
- }
91
- }
92
- `,
93
- {
94
- input: {
95
- authentication: {
96
- emailPassword: {
97
- email,
98
- password,
99
- },
100
- },
101
- },
102
- },
103
- )
104
-
105
- const accessToken = res.signUpWith.accessToken
106
- const userId = res.signUpWith.id
107
-
108
- await wabe.controllers.database.updateObjects({
109
- className: 'User',
110
- context: {
111
- isRoot: true,
112
- wabe,
113
- } as any,
114
- data: {
115
- role: adminRoleId,
116
- },
117
- select: {},
118
- where: {
119
- id: { equalTo: userId },
120
- },
121
- })
122
-
123
- const client = new GraphQLClient(`http://127.0.0.1:${port}/graphql`, {
124
- headers: {
125
- 'Wabe-Access-Token': accessToken,
126
- },
127
- })
128
-
129
- return { ...client, request: client.request<any> } as GraphQLClient
130
- }
131
-
132
- export const createUserAndUpdateRole = async ({
133
- anonymousClient,
134
- rootClient,
135
- roleName,
136
- port,
137
- email,
138
- }: {
139
- port: number
140
- anonymousClient: GraphQLClient
141
- rootClient: GraphQLClient
142
- roleName: string
143
- email?: string
144
- }) => {
145
- const random = Math.random().toString(36).substring(2)
146
-
147
- const res = await anonymousClient.request<any>(
148
- gql`
149
- mutation signUpWith($input: SignUpWithInput!) {
150
- signUpWith(input: $input) {
151
- id
152
- accessToken
153
- refreshToken
154
- }
155
- }
156
- `,
157
- {
158
- input: {
159
- authentication: {
160
- emailPassword: {
161
- email: email || `email${random}@test.fr`,
162
- password: 'password',
163
- },
164
- },
165
- },
166
- },
167
- )
168
-
169
- const resOfRoles = await rootClient.request<any>(gql`
170
- query getRoles {
171
- roles(where: {name: {equalTo: "${roleName}"}}) {
172
- edges {
173
- node {
174
- id
175
- }
176
- }
177
- }
178
- }
179
- `)
180
-
181
- const roleId = resOfRoles.roles.edges[0].node.id
182
-
183
- await rootClient.request<any>(gql`
184
- mutation updateUser {
185
- updateUser(input: {id: "${res.signUpWith.id}", fields: {role: {link: "${roleId}"}}}) {
186
- user {
187
- id
188
- }
189
- }
190
- }
191
- `)
192
-
193
- const userClient = getUserClient(port, {
194
- accessToken: res.signUpWith.accessToken,
195
- })
196
-
197
- return {
198
- userClient,
199
- roleId,
200
- userId: res.signUpWith.id,
201
- refreshToken: res.signUpWith.refreshToken,
202
- accessToken: res.signUpWith.accessToken,
203
- }
204
- }
@@ -1,11 +0,0 @@
1
- import { describe, expect, it } from 'bun:test'
2
- import { firstLetterInLowerCase } from '.'
3
-
4
- describe('utils', () => {
5
- it('should put the first letter in lowercase', () => {
6
- expect(firstLetterInLowerCase('Hello')).toEqual('hello')
7
- expect(firstLetterInLowerCase('User')).toEqual('user')
8
- expect(firstLetterInLowerCase('USer')).toEqual('uSer')
9
- expect(firstLetterInLowerCase('99 User')).toEqual('99 user')
10
- })
11
- })
@@ -1,196 +0,0 @@
1
- import { timingSafeEqual } from 'node:crypto'
2
- import type { ClassInterface } from '../schema'
3
- import type { WabeTypes, WabeConfig, WabeContext } from '../server'
4
-
5
- export const isValidRootKey = (headers: Headers, rootKey: string): boolean => {
6
- const headerRootKey = Buffer.from(headers.get('Wabe-Root-Key') || '')
7
- const key = Buffer.from(rootKey)
8
- return headerRootKey.length === key.length && timingSafeEqual(key, headerRootKey)
9
- }
10
-
11
- export const contextWithoutGraphQLCall = (context: WabeContext<any>): WabeContext<any> => ({
12
- ...context,
13
- isGraphQLCall: false,
14
- })
15
-
16
- const RFC4648 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'
17
- const RFC4648_HEX = '0123456789ABCDEFGHIJKLMNOPQRSTUV'
18
- const CROCKFORD = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'
19
-
20
- type Base32Variant = 'RFC3548' | 'RFC4648' | 'RFC4648-HEX' | 'Crockford'
21
-
22
- interface Base32Options {
23
- padding?: boolean
24
- }
25
-
26
- /**
27
- * Convert supported input types to Uint8Array.
28
- */
29
- export const toUint8Array = (data: string | ArrayBuffer | Uint8Array | Buffer): Uint8Array => {
30
- if (data instanceof Uint8Array) return data
31
-
32
- if (typeof data === 'string') {
33
- const encoder = new TextEncoder()
34
- return encoder.encode(data)
35
- }
36
-
37
- if (data instanceof ArrayBuffer) return new Uint8Array(data)
38
-
39
- throw new TypeError('Unsupported data type for base32 encoding')
40
- }
41
-
42
- /**
43
- * Encode binary data to base32 using specified variant.
44
- * Base on https://github.com/LinusU/base32-encode/blob/master/index.js
45
- */
46
- export const base32Encode = (
47
- data: string | ArrayBuffer | Uint8Array | Buffer,
48
- variant: Base32Variant,
49
- options: Base32Options = {},
50
- ): string => {
51
- let alphabet: string
52
- let defaultPadding: boolean
53
-
54
- switch (variant) {
55
- case 'RFC3548':
56
- case 'RFC4648':
57
- alphabet = RFC4648
58
- defaultPadding = true
59
- break
60
- case 'RFC4648-HEX':
61
- alphabet = RFC4648_HEX
62
- defaultPadding = true
63
- break
64
- case 'Crockford':
65
- alphabet = CROCKFORD
66
- defaultPadding = false
67
- break
68
- default:
69
- throw new Error(`Unknown base32 variant: ${variant}`)
70
- }
71
-
72
- const padding = options.padding !== undefined ? options.padding : defaultPadding
73
- const view = toUint8Array(data)
74
-
75
- let bits = 0
76
- let value = 0
77
- let output = ''
78
-
79
- for (let i = 0; i < view.length; i++) {
80
- // @ts-expect-error
81
- value = (value << 8) | view[i]
82
- bits += 8
83
-
84
- while (bits >= 5) {
85
- output += alphabet[(value >>> (bits - 5)) & 31]
86
- bits -= 5
87
- }
88
- }
89
-
90
- if (bits > 0) {
91
- output += alphabet[(value << (5 - bits)) & 31]
92
- }
93
-
94
- if (padding) {
95
- while (output.length % 8 !== 0) {
96
- output += '='
97
- }
98
- }
99
-
100
- return output
101
- }
102
-
103
- export const getNewObjectAfterUpdateNestedProperty = (obj: any, path: string, value: any) => {
104
- const keys = path.split('.')
105
- let current = { ...obj }
106
-
107
- for (let i = 0; i < keys.length - 1; i++) {
108
- const key = keys[i]
109
-
110
- if (!key) continue
111
-
112
- if (current[key] === undefined) {
113
- current[key] = {}
114
- }
115
- current = current[key]
116
- }
117
-
118
- // @ts-expect-error
119
- current[keys[keys.length - 1]] = value
120
- return obj
121
- }
122
-
123
- export const getNestedProperty = (obj: any, path: string) => {
124
- return path.split('.').reduce((acc, part) => acc?.[part], obj)
125
- }
126
-
127
- export const firstLetterInUpperCase = (str: string) => {
128
- const indexOfFirstLetter = str.search(/[a-z]/i)
129
-
130
- return (
131
- str.slice(0, indexOfFirstLetter) +
132
- str[indexOfFirstLetter]?.toUpperCase() +
133
- str.slice(indexOfFirstLetter + 1)
134
- )
135
- }
136
-
137
- export const firstLetterInLowerCase = (str: string) => {
138
- const indexOfFirstLetter = str.search(/[a-z]/i)
139
-
140
- return (
141
- str.slice(0, indexOfFirstLetter) +
142
- str[indexOfFirstLetter]?.toLowerCase() +
143
- str.slice(indexOfFirstLetter + 1)
144
- )
145
- }
146
-
147
- export const getClassFromClassName = <T extends WabeTypes>(
148
- className: string,
149
- config: WabeConfig<any>,
150
- ): ClassInterface<T> => {
151
- const classInSchema = config.schema?.classes?.find(
152
- (schemaClass) => schemaClass.name === className,
153
- )
154
-
155
- if (!classInSchema) throw new Error('Class not found in schema')
156
-
157
- return classInSchema
158
- }
159
-
160
- // TODO: Put this in wobe
161
- export const getCookieInRequestHeaders = (cookieName: string, headers: Headers) => {
162
- const cookies = headers.get('Cookie')
163
-
164
- if (!cookies) return
165
-
166
- const cookie = cookies.split(';').find((c) => c.includes(cookieName))
167
-
168
- if (!cookie) return
169
-
170
- return cookie.split('=')[1]
171
- }
172
-
173
- /**
174
- * This apply the following transformations on string:
175
- * - lowercase
176
- * - normalize with NFD
177
- * - remove diacritics and accents characters
178
- * - replace matching abbreviation with long version (if disableAbbreviations is not set)
179
- * - replace 2 or more spaces by one
180
- * - replace all non alpha characters by a space
181
- * - trim
182
- */
183
- export const tokenize = (value: string) => {
184
- const tmpValue = value
185
- .toLowerCase()
186
- .normalize('NFD')
187
- .replace(/[\u0300-\u036f]/g, '')
188
- .replace(/\s\s+/g, ' ')
189
-
190
- return (
191
- tmpValue
192
- // Replace all non alpha
193
- .replace(/[\W_]+/g, ' ')
194
- .trim()
195
- )
196
- }
@@ -1,8 +0,0 @@
1
- import { runDatabase } from 'wabe-mongodb-launcher'
2
-
3
- const setupEnvironment = () => {
4
- process.env.TEST = 'true'
5
- }
6
-
7
- await runDatabase()
8
- setupEnvironment()
@@ -1,124 +0,0 @@
1
- import { v4 as uuid } from 'uuid'
2
- import type { RateLimitOptions } from 'wobe'
3
- import { type ClassInterface, EmailDevAdapter, FileDevAdapter } from '..'
4
- import { Wabe } from '../server'
5
- import type { DevWabeTypes } from './helper'
6
- import getPort from 'get-port'
7
-
8
- export const getDatabaseAdapter = async (databaseName: string) => {
9
- const mongodbAdapter = await import('wabe-mongodb')
10
-
11
- return new mongodbAdapter.MongoAdapter<DevWabeTypes>({
12
- // For postgres
13
- // databaseUrl: 'postgresql://wabe:wabe@localhost:5432',
14
- databaseUrl: 'mongodb://localhost:27045',
15
- databaseName,
16
- })
17
- }
18
-
19
- export const setupTests = async (
20
- additionalClasses: ClassInterface<any>[] = [],
21
- options: {
22
- isProduction?: boolean
23
- disableCSRFProtection?: boolean
24
- disableIntrospection?: boolean
25
- rootKey?: string
26
- rateLimit?: RateLimitOptions
27
- } = {},
28
- ) => {
29
- const databaseId = uuid()
30
-
31
- const port = await getPort()
32
-
33
- const wabe = new Wabe<DevWabeTypes>({
34
- isProduction: !!options.isProduction,
35
- rootKey: options.rootKey ?? 'dev',
36
- database: {
37
- // @ts-expect-error
38
- adapter: await getDatabaseAdapter(databaseId),
39
- },
40
- security: {
41
- // To make test easier keep default value to true
42
- disableCSRFProtection: options.disableCSRFProtection ?? true,
43
- ...(options.disableIntrospection !== undefined && {
44
- disableIntrospection: options.disableIntrospection,
45
- }),
46
- ...(options.rateLimit && { rateLimit: options.rateLimit }),
47
- },
48
- authentication: {
49
- roles: ['Client', 'Client2', 'Client3', 'Admin'],
50
- session: {
51
- jwtSecret: 'dev',
52
- cookieSession: true,
53
- },
54
- },
55
- port,
56
- email: {
57
- adapter: new EmailDevAdapter(),
58
- mainEmail: 'main.email@wabe.com',
59
- },
60
- file: {
61
- adapter: new FileDevAdapter(),
62
- // 12 hours of cache
63
- urlCacheInSeconds: 3600 * 12,
64
- },
65
- schema: {
66
- classes: [
67
- ...additionalClasses,
68
- {
69
- name: 'User',
70
- fields: {
71
- name: { type: 'String' },
72
- age: { type: 'Int' },
73
- isAdmin: { type: 'Boolean', defaultValue: false },
74
- floatValue: { type: 'Float' },
75
- birthDate: { type: 'Date' },
76
- arrayValue: {
77
- type: 'Array',
78
- typeValue: 'String',
79
- },
80
- test: { type: 'TestScalar' },
81
- },
82
- searchableFields: ['email'],
83
- permissions: {
84
- create: {
85
- requireAuthentication: false,
86
- },
87
- delete: {
88
- requireAuthentication: true,
89
- },
90
- update: {
91
- requireAuthentication: false,
92
- },
93
- read: {
94
- requireAuthentication: false,
95
- },
96
- acl: async (hookObject) => {
97
- await hookObject.addACL('users', {
98
- userId: hookObject.object?.id,
99
- read: true,
100
- write: true,
101
- })
102
-
103
- await hookObject.addACL('roles', null)
104
- },
105
- },
106
- },
107
- ],
108
- scalars: [
109
- {
110
- name: 'TestScalar',
111
- description: 'Test scalar',
112
- },
113
- ],
114
- },
115
- })
116
-
117
- await wabe.start()
118
-
119
- return { wabe, port }
120
- }
121
-
122
- export const closeTests = async (wabe: Wabe<DevWabeTypes>) => {
123
- await wabe.close()
124
- }
package/tsconfig.json DELETED
@@ -1,32 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- // Environment setup & latest features
4
- "lib": ["ESNext"],
5
- "target": "ESNext",
6
- "module": "Preserve",
7
- "moduleDetection": "force",
8
- "jsx": "react-jsx",
9
- "allowJs": true,
10
-
11
- // Bundler mode
12
- "moduleResolution": "bundler",
13
- "allowImportingTsExtensions": true,
14
- "verbatimModuleSyntax": false,
15
- "noEmit": true,
16
-
17
- // Best practices
18
- "strict": true,
19
- "skipLibCheck": true,
20
- "noFallthroughCasesInSwitch": true,
21
- "noUncheckedIndexedAccess": true,
22
- "noImplicitOverride": true,
23
-
24
- // Some stricter flags (disabled by default)
25
- "noUnusedLocals": false,
26
- "noUnusedParameters": false,
27
- "noPropertyAccessFromIndexSignature": false,
28
- "baseUrl": "."
29
- },
30
- "exclude": ["node_modules", "dist", "generated"],
31
- "include": ["src/**/*.ts", "dev/**/*.ts"]
32
- }