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
package/src/file/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './FileDevAdapter'
2
- export * from './interface'
@@ -1,63 +0,0 @@
1
- import type { WabeContext, WabeTypes } from 'src/server'
2
-
3
- export type FileUploadSecurityConfig = {
4
- /**
5
- * Enable upload validation rules. Enabled by default in production.
6
- */
7
- enabled?: boolean
8
- /**
9
- * Maximum allowed file size in bytes.
10
- */
11
- maxFileSizeBytes?: number
12
- /**
13
- * Allowlist of MIME types accepted by uploads.
14
- */
15
- allowedMimeTypes?: string[]
16
- /**
17
- * Allowlist of file extensions accepted by uploads (without dot).
18
- */
19
- allowedExtensions?: string[]
20
- /**
21
- * Randomize uploaded file names (enabled by default in production).
22
- */
23
- randomizeFileName?: boolean
24
- }
25
-
26
- /**
27
- * The file config contains the adapter to use to upload file
28
- * @param adapter: FileAdapter
29
- * @param urlCacheInSeconds: number Number of seconds to cache the url, equal to the number of seconds the url will be valid
30
- * @param devDirectory: string The directory where the files will be uploaded
31
- */
32
- export type FileConfig<T extends WabeTypes> = {
33
- adapter: FileAdapter
34
- urlCacheInSeconds?: number
35
- devDirectory?: string
36
- beforeUpload?: (file: File, context: WabeContext<T>) => Promise<File> | File
37
- security?: FileUploadSecurityConfig
38
- }
39
-
40
- export interface ReadFileOptions {
41
- urlExpiresIn?: number
42
- port?: number
43
- }
44
-
45
- export interface FileAdapter {
46
- /**
47
- * Upload a file and returns the url of the file
48
- * @param file: File
49
- */
50
- uploadFile(file: File): Promise<void>
51
- /**
52
- * Read a file and returns the url of the file
53
- * @param fileName: string
54
- * @param urlExpiresIn: number Number of seconds to expire the url
55
- * @returns The url of file or null if the file doesn't exist
56
- */
57
- readFile(fileName: string, options?: ReadFileOptions): Promise<string | null> | string | null
58
- /*+
59
- * Delete a file
60
- * @param fileName: string
61
- */
62
- deleteFile(fileName: string): Promise<void>
63
- }
@@ -1,156 +0,0 @@
1
- import crypto from 'node:crypto'
2
- import path from 'node:path'
3
- import type { WabeContext, WabeTypes } from 'src/server'
4
- import type { FileUploadSecurityConfig } from './interface'
5
-
6
- const DEFAULT_MAX_FILE_SIZE_BYTES = 10 * 1024 * 1024
7
-
8
- const DEFAULT_ALLOWED_MIME_TYPES = [
9
- 'image/jpeg',
10
- 'image/png',
11
- 'image/gif',
12
- 'image/webp',
13
- 'application/pdf',
14
- 'text/plain',
15
- 'application/json',
16
- 'text/csv',
17
- ]
18
-
19
- const DEFAULT_ALLOWED_EXTENSIONS = [
20
- 'jpg',
21
- 'jpeg',
22
- 'png',
23
- 'gif',
24
- 'webp',
25
- 'pdf',
26
- 'txt',
27
- 'json',
28
- 'csv',
29
- ]
30
-
31
- const MIME_SIGNATURES: Array<{
32
- mimeType: string
33
- bytes: number[]
34
- offset?: number
35
- }> = [
36
- {
37
- mimeType: 'image/png',
38
- bytes: [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a],
39
- },
40
- { mimeType: 'image/jpeg', bytes: [0xff, 0xd8, 0xff] },
41
- { mimeType: 'image/gif', bytes: [0x47, 0x49, 0x46, 0x38] },
42
- { mimeType: 'image/webp', bytes: [0x52, 0x49, 0x46, 0x46] },
43
- { mimeType: 'application/pdf', bytes: [0x25, 0x50, 0x44, 0x46, 0x2d] },
44
- ]
45
-
46
- const MIME_TO_EXTENSIONS: Record<string, string[]> = {
47
- 'image/jpeg': ['jpg', 'jpeg'],
48
- 'image/png': ['png'],
49
- 'image/gif': ['gif'],
50
- 'image/webp': ['webp'],
51
- 'application/pdf': ['pdf'],
52
- 'text/plain': ['txt'],
53
- 'application/json': ['json'],
54
- 'text/csv': ['csv'],
55
- }
56
-
57
- const normalizeMimeType = (mimeType: string) =>
58
- mimeType.trim().toLowerCase().split(';')[0]?.trim() || ''
59
-
60
- const normalizeExtension = (fileName: string) =>
61
- path.extname(fileName).replace('.', '').trim().toLowerCase()
62
-
63
- const hasSignature = (fileHeader: Uint8Array, bytes: number[], offset = 0) =>
64
- bytes.every((value, index) => fileHeader[offset + index] === value)
65
-
66
- const detectMimeTypeFromContent = async (file: File) => {
67
- const header = new Uint8Array(await file.slice(0, 16).arrayBuffer())
68
-
69
- for (const signature of MIME_SIGNATURES) {
70
- if (hasSignature(header, signature.bytes, signature.offset)) {
71
- if (
72
- signature.mimeType === 'image/webp' &&
73
- !(header[8] === 0x57 && header[9] === 0x45 && header[10] === 0x42 && header[11] === 0x50)
74
- ) {
75
- continue
76
- }
77
-
78
- return signature.mimeType
79
- }
80
- }
81
-
82
- return null
83
- }
84
-
85
- const getUploadSecurityConfig = <T extends WabeTypes>(context: WabeContext<T>) => {
86
- const security = context.wabe.config.file?.security
87
- const enabled = security?.enabled ?? context.wabe.config.isProduction
88
- const maxFileSizeBytes = security?.maxFileSizeBytes ?? DEFAULT_MAX_FILE_SIZE_BYTES
89
- const allowedMimeTypes = (security?.allowedMimeTypes || DEFAULT_ALLOWED_MIME_TYPES).map(
90
- normalizeMimeType,
91
- )
92
- const allowedExtensions = (security?.allowedExtensions || DEFAULT_ALLOWED_EXTENSIONS).map(
93
- (value) => value.trim().toLowerCase(),
94
- )
95
- const randomizeFileName = security?.randomizeFileName ?? context.wabe.config.isProduction
96
-
97
- return {
98
- enabled,
99
- maxFileSizeBytes,
100
- allowedMimeTypes,
101
- allowedExtensions,
102
- randomizeFileName,
103
- }
104
- }
105
-
106
- const createRandomizedFile = async (file: File, extension: string) => {
107
- const uniqueName = `${crypto.randomUUID()}.${extension}`
108
- const content = await file.arrayBuffer()
109
-
110
- return new File([content], uniqueName, {
111
- type: file.type,
112
- lastModified: Date.now(),
113
- })
114
- }
115
-
116
- export const secureUploadedFile = async <T extends WabeTypes>(
117
- file: File,
118
- context: WabeContext<T>,
119
- ): Promise<File> => {
120
- const { enabled, maxFileSizeBytes, allowedMimeTypes, allowedExtensions, randomizeFileName } =
121
- getUploadSecurityConfig(context)
122
-
123
- if (!enabled) return file
124
-
125
- if (file.size > maxFileSizeBytes) throw new Error('File exceeds maximum allowed size')
126
-
127
- const extension = normalizeExtension(file.name)
128
- if (!extension || !allowedExtensions.includes(extension))
129
- throw new Error('File extension is not allowed')
130
-
131
- const mimeType = normalizeMimeType(file.type || '')
132
- if (!mimeType || !allowedMimeTypes.includes(mimeType))
133
- throw new Error('File MIME type is not allowed')
134
-
135
- const detectedMimeType = await detectMimeTypeFromContent(file)
136
-
137
- if (detectedMimeType && detectedMimeType !== mimeType)
138
- throw new Error('File content does not match MIME type')
139
-
140
- if (detectedMimeType && !allowedMimeTypes.includes(detectedMimeType))
141
- throw new Error('File content type is not allowed')
142
-
143
- const allowedExtensionsForMime = MIME_TO_EXTENSIONS[mimeType]
144
- if (allowedExtensionsForMime && !allowedExtensionsForMime.includes(extension))
145
- throw new Error('File extension does not match MIME type')
146
-
147
- if (!randomizeFileName) return file
148
-
149
- return createRandomizedFile(file, extension)
150
- }
151
-
152
- export const getUploadSecurityConfigForTests = <T extends WabeTypes>(
153
- context: WabeContext<T>,
154
- ): ReturnType<typeof getUploadSecurityConfig> => getUploadSecurityConfig(context)
155
-
156
- export type { FileUploadSecurityConfig }