wabe 0.6.9 → 0.6.10
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/README.md +138 -32
- package/bucket/b.txt +1 -0
- package/dev/index.ts +215 -0
- package/dist/authentication/Session.d.ts +4 -1
- package/dist/authentication/interface.d.ts +16 -0
- package/dist/email/interface.d.ts +1 -1
- package/dist/graphql/resolvers.d.ts +4 -2
- package/dist/hooks/index.d.ts +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +8713 -8867
- package/dist/server/index.d.ts +4 -2
- package/dist/utils/crypto.d.ts +7 -0
- package/dist/utils/helper.d.ts +4 -1
- package/generated/schema.graphql +16 -14
- package/generated/wabe.ts +4 -4
- package/package.json +15 -15
- package/src/authentication/OTP.test.ts +69 -0
- package/src/authentication/OTP.ts +66 -0
- package/src/authentication/Session.test.ts +665 -0
- package/src/authentication/Session.ts +529 -0
- package/src/authentication/defaultAuthentication.ts +214 -0
- package/src/authentication/index.ts +3 -0
- package/src/authentication/interface.ts +157 -0
- package/src/authentication/oauth/GitHub.test.ts +105 -0
- package/src/authentication/oauth/GitHub.ts +133 -0
- package/src/authentication/oauth/Google.test.ts +105 -0
- package/src/authentication/oauth/Google.ts +110 -0
- package/src/authentication/oauth/Oauth2Client.test.ts +225 -0
- package/src/authentication/oauth/Oauth2Client.ts +140 -0
- package/src/authentication/oauth/index.ts +2 -0
- package/src/authentication/oauth/utils.test.ts +35 -0
- package/src/authentication/oauth/utils.ts +28 -0
- package/src/authentication/providers/EmailOTP.test.ts +138 -0
- package/src/authentication/providers/EmailOTP.ts +93 -0
- package/src/authentication/providers/EmailPassword.test.ts +187 -0
- package/src/authentication/providers/EmailPassword.ts +130 -0
- package/src/authentication/providers/EmailPasswordSRP.test.ts +206 -0
- package/src/authentication/providers/EmailPasswordSRP.ts +184 -0
- package/src/authentication/providers/GitHub.ts +30 -0
- package/src/authentication/providers/Google.ts +30 -0
- package/src/authentication/providers/OAuth.test.ts +185 -0
- package/src/authentication/providers/OAuth.ts +112 -0
- package/src/authentication/providers/PhonePassword.test.ts +187 -0
- package/src/authentication/providers/PhonePassword.ts +129 -0
- package/src/authentication/providers/QRCodeOTP.test.ts +79 -0
- package/src/authentication/providers/QRCodeOTP.ts +65 -0
- package/src/authentication/providers/index.ts +6 -0
- package/src/authentication/resolvers/refreshResolver.test.ts +37 -0
- package/src/authentication/resolvers/refreshResolver.ts +20 -0
- package/src/authentication/resolvers/signInWithResolver.inte.test.ts +59 -0
- package/src/authentication/resolvers/signInWithResolver.test.ts +307 -0
- package/src/authentication/resolvers/signInWithResolver.ts +102 -0
- package/src/authentication/resolvers/signOutResolver.test.ts +41 -0
- package/src/authentication/resolvers/signOutResolver.ts +22 -0
- package/src/authentication/resolvers/signUpWithResolver.test.ts +186 -0
- package/src/authentication/resolvers/signUpWithResolver.ts +69 -0
- package/src/authentication/resolvers/verifyChallenge.test.ts +136 -0
- package/src/authentication/resolvers/verifyChallenge.ts +69 -0
- package/src/authentication/roles.test.ts +59 -0
- package/src/authentication/roles.ts +40 -0
- package/src/authentication/utils.test.ts +99 -0
- package/src/authentication/utils.ts +43 -0
- package/src/cache/InMemoryCache.test.ts +62 -0
- package/src/cache/InMemoryCache.ts +45 -0
- package/src/cron/index.test.ts +17 -0
- package/src/cron/index.ts +46 -0
- package/src/database/DatabaseController.test.ts +625 -0
- package/src/database/DatabaseController.ts +983 -0
- package/src/database/index.test.ts +1230 -0
- package/src/database/index.ts +9 -0
- package/src/database/interface.ts +312 -0
- package/src/email/DevAdapter.ts +8 -0
- package/src/email/EmailController.test.ts +29 -0
- package/src/email/EmailController.ts +13 -0
- package/src/email/index.ts +2 -0
- package/src/email/interface.ts +36 -0
- package/src/email/templates/sendOtpCode.ts +120 -0
- package/src/file/FileController.ts +28 -0
- package/src/file/FileDevAdapter.ts +54 -0
- package/src/file/hookDeleteFile.ts +27 -0
- package/src/file/hookReadFile.ts +70 -0
- package/src/file/hookUploadFile.ts +53 -0
- package/src/file/index.test.ts +979 -0
- package/src/file/index.ts +2 -0
- package/src/file/interface.ts +42 -0
- package/src/graphql/GraphQLSchema.test.ts +4399 -0
- package/src/graphql/GraphQLSchema.ts +928 -0
- package/src/graphql/index.ts +2 -0
- package/src/graphql/parseGraphqlSchema.ts +94 -0
- package/src/graphql/parser.test.ts +217 -0
- package/src/graphql/parser.ts +566 -0
- package/src/graphql/pointerAndRelationFunction.ts +200 -0
- package/src/graphql/resolvers.ts +467 -0
- package/src/graphql/tests/aggregation.test.ts +1123 -0
- package/src/graphql/tests/e2e.test.ts +596 -0
- package/src/graphql/tests/scalars.test.ts +250 -0
- package/src/graphql/types.ts +219 -0
- package/src/hooks/HookObject.test.ts +122 -0
- package/src/hooks/HookObject.ts +168 -0
- package/src/hooks/authentication.ts +76 -0
- package/src/hooks/createUser.test.ts +77 -0
- package/src/hooks/createUser.ts +10 -0
- package/src/hooks/defaultFields.test.ts +187 -0
- package/src/hooks/defaultFields.ts +40 -0
- package/src/hooks/deleteSession.test.ts +181 -0
- package/src/hooks/deleteSession.ts +20 -0
- package/src/hooks/hashFieldHook.test.ts +163 -0
- package/src/hooks/hashFieldHook.ts +97 -0
- package/src/hooks/index.test.ts +207 -0
- package/src/hooks/index.ts +430 -0
- package/src/hooks/permissions.test.ts +424 -0
- package/src/hooks/permissions.ts +113 -0
- package/src/hooks/protected.test.ts +551 -0
- package/src/hooks/protected.ts +72 -0
- package/src/hooks/searchableFields.test.ts +166 -0
- package/src/hooks/searchableFields.ts +98 -0
- package/src/hooks/session.test.ts +138 -0
- package/src/hooks/session.ts +78 -0
- package/src/hooks/setEmail.test.ts +216 -0
- package/src/hooks/setEmail.ts +35 -0
- package/src/hooks/setupAcl.test.ts +589 -0
- package/src/hooks/setupAcl.ts +29 -0
- package/src/index.ts +9 -0
- package/src/schema/Schema.test.ts +484 -0
- package/src/schema/Schema.ts +795 -0
- package/src/schema/defaultResolvers.ts +94 -0
- package/src/schema/index.ts +1 -0
- package/src/schema/resolvers/meResolver.test.ts +62 -0
- package/src/schema/resolvers/meResolver.ts +14 -0
- package/src/schema/resolvers/newFile.ts +0 -0
- package/src/schema/resolvers/resetPassword.test.ts +345 -0
- package/src/schema/resolvers/resetPassword.ts +64 -0
- package/src/schema/resolvers/sendEmail.test.ts +118 -0
- package/src/schema/resolvers/sendEmail.ts +21 -0
- package/src/schema/resolvers/sendOtpCode.test.ts +153 -0
- package/src/schema/resolvers/sendOtpCode.ts +52 -0
- package/src/security.test.ts +3461 -0
- package/src/server/defaultSessionHandler.test.ts +66 -0
- package/src/server/defaultSessionHandler.ts +115 -0
- package/src/server/generateCodegen.ts +476 -0
- package/src/server/index.test.ts +552 -0
- package/src/server/index.ts +354 -0
- package/src/server/interface.ts +11 -0
- package/src/server/routes/authHandler.ts +187 -0
- package/src/server/routes/index.ts +40 -0
- package/src/utils/crypto.test.ts +41 -0
- package/src/utils/crypto.ts +121 -0
- package/src/utils/export.ts +13 -0
- package/src/utils/helper.ts +195 -0
- package/src/utils/index.test.ts +11 -0
- package/src/utils/index.ts +201 -0
- package/src/utils/preload.ts +8 -0
- package/src/utils/testHelper.ts +117 -0
- package/tsconfig.json +32 -0
- package/bunfig.toml +0 -4
- package/dist/ai/index.d.ts +0 -1
- package/dist/ai/interface.d.ts +0 -9
- /package/dist/server/{defaultHandlers.d.ts → defaultSessionHandler.d.ts} +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { HookObject } from '../hooks/HookObject'
|
|
2
|
+
|
|
3
|
+
const getFile = async (hookObject: HookObject<any, any>) => {
|
|
4
|
+
const schema = hookObject.context.wabe.config.schema?.classes?.find(
|
|
5
|
+
(currentClass) => currentClass.name === hookObject.className,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
if (!schema) return
|
|
9
|
+
|
|
10
|
+
const urlCacheInSeconds =
|
|
11
|
+
hookObject.context.wabe.config.file?.urlCacheInSeconds || 3600 * 24
|
|
12
|
+
|
|
13
|
+
// After read we get the file URL and we update the field url with an URL.
|
|
14
|
+
// For security purpose we recommend to use a presigned URL
|
|
15
|
+
await Promise.all(
|
|
16
|
+
Object.entries(schema.fields)
|
|
17
|
+
.filter(([_, value]) => value.type === 'File')
|
|
18
|
+
.map(async ([fieldName]) => {
|
|
19
|
+
const fileInfo = hookObject.object?.[fieldName]
|
|
20
|
+
|
|
21
|
+
if (!fileInfo) return
|
|
22
|
+
|
|
23
|
+
const fileName = fileInfo.name as string
|
|
24
|
+
|
|
25
|
+
if (!fileName && fileInfo.url) return fileInfo.url
|
|
26
|
+
|
|
27
|
+
const fileUrlGeneratedAt = new Date(fileInfo.urlGeneratedAt)
|
|
28
|
+
|
|
29
|
+
if (
|
|
30
|
+
fileUrlGeneratedAt &&
|
|
31
|
+
fileUrlGeneratedAt.getTime() + urlCacheInSeconds * 1000 > Date.now()
|
|
32
|
+
)
|
|
33
|
+
return
|
|
34
|
+
|
|
35
|
+
if (!hookObject.context.wabe.controllers.file)
|
|
36
|
+
throw new Error('No file adapter found')
|
|
37
|
+
|
|
38
|
+
const fileUrlFromBucket =
|
|
39
|
+
await hookObject.context.wabe.controllers.file?.readFile(fileName)
|
|
40
|
+
|
|
41
|
+
const newUrl = fileUrlFromBucket || fileInfo.url
|
|
42
|
+
const newUrlGeneratedAt = new Date()
|
|
43
|
+
|
|
44
|
+
// Mutate the object returned to the caller so AfterRead effects are visible immediately
|
|
45
|
+
// @ts-expect-error
|
|
46
|
+
hookObject.object[fieldName] = {
|
|
47
|
+
...fileInfo,
|
|
48
|
+
urlGeneratedAt: newUrlGeneratedAt,
|
|
49
|
+
url: newUrl,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return hookObject.context.wabe.controllers.database.updateObject({
|
|
53
|
+
className: hookObject.className,
|
|
54
|
+
context: hookObject.context,
|
|
55
|
+
id: hookObject.object?.id || '',
|
|
56
|
+
data: {
|
|
57
|
+
[fieldName]: {
|
|
58
|
+
...fileInfo,
|
|
59
|
+
urlGeneratedAt: newUrlGeneratedAt,
|
|
60
|
+
url: newUrl,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
_skipHooks: true,
|
|
64
|
+
})
|
|
65
|
+
}),
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const defaultAfterReadFile = (hookObject: HookObject<any, any>) =>
|
|
70
|
+
getFile(hookObject)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { HookObject } from '../hooks/HookObject'
|
|
2
|
+
|
|
3
|
+
const handleFile = async (hookObject: HookObject<any, any>) => {
|
|
4
|
+
const newData = hookObject.getNewData()
|
|
5
|
+
|
|
6
|
+
const schema = hookObject.context.wabe.config.schema?.classes?.find(
|
|
7
|
+
(currentClass) => currentClass.name === hookObject.className,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
if (!schema) return
|
|
11
|
+
|
|
12
|
+
const beforeUpload = hookObject.context.wabe.config.file?.beforeUpload
|
|
13
|
+
|
|
14
|
+
await Promise.all(
|
|
15
|
+
Object.keys(newData).map(async (keyName) => {
|
|
16
|
+
const file = newData[keyName]?.file as File
|
|
17
|
+
const url = newData[keyName]?.url as string
|
|
18
|
+
|
|
19
|
+
if (!file && !url) return
|
|
20
|
+
|
|
21
|
+
if (url) {
|
|
22
|
+
hookObject.upsertNewData(keyName, {
|
|
23
|
+
url,
|
|
24
|
+
isPresignedUrl: false,
|
|
25
|
+
})
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (schema.fields[keyName]?.type !== 'File' || !(file instanceof File))
|
|
30
|
+
return
|
|
31
|
+
|
|
32
|
+
if (!hookObject.context.wabe.controllers.file)
|
|
33
|
+
throw new Error('No file adapter found')
|
|
34
|
+
|
|
35
|
+
const fileToUpload =
|
|
36
|
+
(await beforeUpload?.(file, hookObject.context)) || file
|
|
37
|
+
|
|
38
|
+
// We upload the file and set the name of the file in the newData
|
|
39
|
+
await hookObject.context.wabe.controllers.file?.uploadFile(fileToUpload)
|
|
40
|
+
|
|
41
|
+
hookObject.upsertNewData(keyName, {
|
|
42
|
+
name: file.name,
|
|
43
|
+
isPresignedUrl: true,
|
|
44
|
+
})
|
|
45
|
+
}),
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const defaultBeforeCreateUpload = (hookObject: HookObject<any, any>) =>
|
|
50
|
+
handleFile(hookObject)
|
|
51
|
+
|
|
52
|
+
export const defaultBeforeUpdateUpload = (hookObject: HookObject<any, any>) =>
|
|
53
|
+
handleFile(hookObject)
|