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.
- package/dist/database/DatabaseController.d.ts +2 -0
- package/dist/file/FileDevAdapter.d.ts +1 -0
- package/dist/graphql/pointerAndRelationFunction.d.ts +6 -0
- package/dist/index.js +3827 -3541
- package/dist/schema/Schema.d.ts +2 -2
- package/dist/server/generateCodegen.d.ts +10 -0
- package/dist/server/index.d.ts +2 -1
- package/dist/utils/objectKeys.d.ts +1 -0
- package/package.json +7 -4
- package/dev/index.ts +0 -215
- package/dist/schema/resolvers/sendEmail.d.ts +0 -1
- package/generated/schema.graphql +0 -1945
- package/generated/wabe.ts +0 -448
- package/src/authentication/OTP.test.ts +0 -69
- package/src/authentication/OTP.ts +0 -64
- package/src/authentication/Session.test.ts +0 -629
- package/src/authentication/Session.ts +0 -517
- package/src/authentication/cookies.ts +0 -10
- package/src/authentication/defaultAuthentication.ts +0 -209
- package/src/authentication/index.ts +0 -4
- package/src/authentication/interface.ts +0 -177
- package/src/authentication/oauth/GitHub.test.ts +0 -91
- package/src/authentication/oauth/GitHub.ts +0 -121
- package/src/authentication/oauth/Google.test.ts +0 -91
- package/src/authentication/oauth/Google.ts +0 -101
- package/src/authentication/oauth/Oauth2Client.test.ts +0 -219
- package/src/authentication/oauth/Oauth2Client.ts +0 -135
- package/src/authentication/oauth/index.ts +0 -2
- package/src/authentication/oauth/utils.test.ts +0 -33
- package/src/authentication/oauth/utils.ts +0 -27
- package/src/authentication/providers/EmailOTP.test.ts +0 -127
- package/src/authentication/providers/EmailOTP.ts +0 -95
- package/src/authentication/providers/EmailPassword.test.ts +0 -263
- package/src/authentication/providers/EmailPassword.ts +0 -138
- package/src/authentication/providers/EmailPasswordSRP.test.ts +0 -208
- package/src/authentication/providers/EmailPasswordSRP.ts +0 -191
- package/src/authentication/providers/GitHub.ts +0 -24
- package/src/authentication/providers/Google.ts +0 -24
- package/src/authentication/providers/OAuth.test.ts +0 -185
- package/src/authentication/providers/OAuth.ts +0 -106
- package/src/authentication/providers/PhonePassword.test.ts +0 -221
- package/src/authentication/providers/PhonePassword.ts +0 -136
- package/src/authentication/providers/QRCodeOTP.test.ts +0 -77
- package/src/authentication/providers/QRCodeOTP.ts +0 -69
- package/src/authentication/providers/index.ts +0 -6
- package/src/authentication/resolvers/refreshResolver.test.ts +0 -30
- package/src/authentication/resolvers/refreshResolver.ts +0 -19
- package/src/authentication/resolvers/signInWithResolver.inte.test.ts +0 -59
- package/src/authentication/resolvers/signInWithResolver.test.ts +0 -306
- package/src/authentication/resolvers/signInWithResolver.ts +0 -106
- package/src/authentication/resolvers/signOutResolver.test.ts +0 -38
- package/src/authentication/resolvers/signOutResolver.ts +0 -18
- package/src/authentication/resolvers/signUpWithResolver.test.ts +0 -180
- package/src/authentication/resolvers/signUpWithResolver.ts +0 -68
- package/src/authentication/resolvers/verifyChallenge.test.ts +0 -230
- package/src/authentication/resolvers/verifyChallenge.ts +0 -78
- package/src/authentication/roles.test.ts +0 -49
- package/src/authentication/roles.ts +0 -40
- package/src/authentication/security.ts +0 -278
- package/src/authentication/utils.test.ts +0 -97
- package/src/authentication/utils.ts +0 -39
- package/src/cache/InMemoryCache.test.ts +0 -62
- package/src/cache/InMemoryCache.ts +0 -45
- package/src/cron/index.test.ts +0 -17
- package/src/cron/index.ts +0 -43
- package/src/database/DatabaseController.test.ts +0 -613
- package/src/database/DatabaseController.ts +0 -1415
- package/src/database/index.test.ts +0 -1551
- package/src/database/index.ts +0 -9
- package/src/database/interface.ts +0 -308
- package/src/email/DevAdapter.ts +0 -7
- package/src/email/EmailController.test.ts +0 -29
- package/src/email/EmailController.ts +0 -13
- package/src/email/index.ts +0 -2
- package/src/email/interface.ts +0 -36
- package/src/email/templates/sendOtpCode.ts +0 -120
- package/src/file/FileController.ts +0 -28
- package/src/file/FileDevAdapter.ts +0 -51
- package/src/file/hookDeleteFile.ts +0 -25
- package/src/file/hookReadFile.ts +0 -66
- package/src/file/hookUploadFile.ts +0 -52
- package/src/file/index.test.ts +0 -1031
- package/src/file/index.ts +0 -2
- package/src/file/interface.ts +0 -63
- package/src/file/security.ts +0 -156
- package/src/graphql/GraphQLSchema.test.ts +0 -5099
- package/src/graphql/GraphQLSchema.ts +0 -886
- package/src/graphql/index.ts +0 -2
- package/src/graphql/parseGraphqlSchema.ts +0 -85
- package/src/graphql/parser.test.ts +0 -203
- package/src/graphql/parser.ts +0 -707
- package/src/graphql/pointerAndRelationFunction.ts +0 -191
- package/src/graphql/resolvers.ts +0 -464
- package/src/graphql/tests/aggregation.test.ts +0 -1115
- package/src/graphql/tests/e2e.test.ts +0 -590
- package/src/graphql/tests/scalars.test.ts +0 -250
- package/src/graphql/types.ts +0 -227
- package/src/hooks/HookObject.test.ts +0 -122
- package/src/hooks/HookObject.ts +0 -165
- package/src/hooks/authentication.ts +0 -67
- package/src/hooks/createUser.test.ts +0 -77
- package/src/hooks/createUser.ts +0 -10
- package/src/hooks/defaultFields.test.ts +0 -176
- package/src/hooks/defaultFields.ts +0 -32
- package/src/hooks/deleteSession.test.ts +0 -181
- package/src/hooks/deleteSession.ts +0 -20
- package/src/hooks/hashFieldHook.test.ts +0 -152
- package/src/hooks/hashFieldHook.ts +0 -89
- package/src/hooks/index.test.ts +0 -258
- package/src/hooks/index.ts +0 -420
- package/src/hooks/permissions.test.ts +0 -412
- package/src/hooks/permissions.ts +0 -93
- package/src/hooks/protected.test.ts +0 -551
- package/src/hooks/protected.ts +0 -74
- package/src/hooks/searchableFields.test.ts +0 -147
- package/src/hooks/searchableFields.ts +0 -86
- package/src/hooks/session.test.ts +0 -134
- package/src/hooks/session.ts +0 -76
- package/src/hooks/setEmail.test.ts +0 -216
- package/src/hooks/setEmail.ts +0 -33
- package/src/hooks/setupAcl.test.ts +0 -618
- package/src/hooks/setupAcl.ts +0 -25
- package/src/hooks/virtualFields.test.ts +0 -228
- package/src/hooks/virtualFields.ts +0 -48
- package/src/index.ts +0 -9
- package/src/schema/Schema.test.ts +0 -482
- package/src/schema/Schema.ts +0 -839
- package/src/schema/defaultResolvers.ts +0 -93
- package/src/schema/index.ts +0 -1
- package/src/schema/resolvers/meResolver.test.ts +0 -62
- package/src/schema/resolvers/meResolver.ts +0 -10
- package/src/schema/resolvers/resetPassword.test.ts +0 -341
- package/src/schema/resolvers/resetPassword.ts +0 -63
- package/src/schema/resolvers/sendEmail.test.ts +0 -118
- package/src/schema/resolvers/sendEmail.ts +0 -21
- package/src/schema/resolvers/sendOtpCode.test.ts +0 -141
- package/src/schema/resolvers/sendOtpCode.ts +0 -52
- package/src/security.test.ts +0 -4136
- package/src/server/defaultSessionHandler.test.ts +0 -62
- package/src/server/defaultSessionHandler.ts +0 -104
- package/src/server/generateCodegen.ts +0 -433
- package/src/server/index.test.ts +0 -843
- package/src/server/index.ts +0 -336
- package/src/server/interface.ts +0 -11
- package/src/server/routes/authHandler.ts +0 -171
- package/src/server/routes/index.ts +0 -48
- package/src/utils/crypto.test.ts +0 -41
- package/src/utils/crypto.ts +0 -105
- package/src/utils/database.ts +0 -8
- package/src/utils/export.ts +0 -12
- package/src/utils/helper.ts +0 -204
- package/src/utils/index.test.ts +0 -11
- package/src/utils/index.ts +0 -196
- package/src/utils/preload.ts +0 -8
- package/src/utils/testHelper.ts +0 -124
- package/tsconfig.json +0 -32
package/src/file/index.ts
DELETED
package/src/file/interface.ts
DELETED
|
@@ -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
|
-
}
|
package/src/file/security.ts
DELETED
|
@@ -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 }
|