wabe 0.6.11 → 0.6.13

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 (162) hide show
  1. package/dist/authentication/Session.d.ts +10 -12
  2. package/dist/authentication/cookies.d.ts +1 -0
  3. package/dist/authentication/index.d.ts +1 -0
  4. package/dist/authentication/interface.d.ts +20 -0
  5. package/dist/authentication/security.d.ts +18 -0
  6. package/dist/database/DatabaseController.d.ts +57 -3
  7. package/dist/database/interface.d.ts +5 -0
  8. package/dist/file/interface.d.ts +23 -0
  9. package/dist/file/security.d.ts +6 -0
  10. package/dist/graphql/GraphQLSchema.d.ts +1 -1
  11. package/dist/graphql/resolvers.d.ts +1 -0
  12. package/dist/hooks/protected.d.ts +3 -0
  13. package/dist/hooks/virtualFields.d.ts +3 -0
  14. package/dist/index.js +1757 -818
  15. package/dist/schema/Schema.d.ts +66 -7
  16. package/dist/server/index.d.ts +2 -1
  17. package/dist/server/routes/index.d.ts +4 -1
  18. package/dist/utils/database.d.ts +1 -0
  19. package/dist/utils/export.d.ts +1 -0
  20. package/dist/utils/index.d.ts +1 -0
  21. package/package.json +7 -4
  22. package/bucket/b.txt +0 -1
  23. package/dev/index.ts +0 -215
  24. package/generated/schema.graphql +0 -1892
  25. package/generated/wabe.ts +0 -439
  26. package/src/authentication/OTP.test.ts +0 -69
  27. package/src/authentication/OTP.ts +0 -64
  28. package/src/authentication/Session.test.ts +0 -629
  29. package/src/authentication/Session.ts +0 -493
  30. package/src/authentication/defaultAuthentication.ts +0 -209
  31. package/src/authentication/index.ts +0 -3
  32. package/src/authentication/interface.ts +0 -155
  33. package/src/authentication/oauth/GitHub.test.ts +0 -91
  34. package/src/authentication/oauth/GitHub.ts +0 -121
  35. package/src/authentication/oauth/Google.test.ts +0 -91
  36. package/src/authentication/oauth/Google.ts +0 -101
  37. package/src/authentication/oauth/Oauth2Client.test.ts +0 -219
  38. package/src/authentication/oauth/Oauth2Client.ts +0 -135
  39. package/src/authentication/oauth/index.ts +0 -2
  40. package/src/authentication/oauth/utils.test.ts +0 -33
  41. package/src/authentication/oauth/utils.ts +0 -27
  42. package/src/authentication/providers/EmailOTP.test.ts +0 -127
  43. package/src/authentication/providers/EmailOTP.ts +0 -84
  44. package/src/authentication/providers/EmailPassword.test.ts +0 -176
  45. package/src/authentication/providers/EmailPassword.ts +0 -116
  46. package/src/authentication/providers/EmailPasswordSRP.test.ts +0 -208
  47. package/src/authentication/providers/EmailPasswordSRP.ts +0 -179
  48. package/src/authentication/providers/GitHub.ts +0 -24
  49. package/src/authentication/providers/Google.ts +0 -24
  50. package/src/authentication/providers/OAuth.test.ts +0 -185
  51. package/src/authentication/providers/OAuth.ts +0 -106
  52. package/src/authentication/providers/PhonePassword.test.ts +0 -176
  53. package/src/authentication/providers/PhonePassword.ts +0 -115
  54. package/src/authentication/providers/QRCodeOTP.test.ts +0 -77
  55. package/src/authentication/providers/QRCodeOTP.ts +0 -58
  56. package/src/authentication/providers/index.ts +0 -6
  57. package/src/authentication/resolvers/refreshResolver.test.ts +0 -30
  58. package/src/authentication/resolvers/refreshResolver.ts +0 -19
  59. package/src/authentication/resolvers/signInWithResolver.inte.test.ts +0 -59
  60. package/src/authentication/resolvers/signInWithResolver.test.ts +0 -293
  61. package/src/authentication/resolvers/signInWithResolver.ts +0 -92
  62. package/src/authentication/resolvers/signOutResolver.test.ts +0 -38
  63. package/src/authentication/resolvers/signOutResolver.ts +0 -18
  64. package/src/authentication/resolvers/signUpWithResolver.test.ts +0 -180
  65. package/src/authentication/resolvers/signUpWithResolver.ts +0 -65
  66. package/src/authentication/resolvers/verifyChallenge.test.ts +0 -133
  67. package/src/authentication/resolvers/verifyChallenge.ts +0 -62
  68. package/src/authentication/roles.test.ts +0 -49
  69. package/src/authentication/roles.ts +0 -40
  70. package/src/authentication/utils.test.ts +0 -97
  71. package/src/authentication/utils.ts +0 -39
  72. package/src/cache/InMemoryCache.test.ts +0 -62
  73. package/src/cache/InMemoryCache.ts +0 -45
  74. package/src/cron/index.test.ts +0 -17
  75. package/src/cron/index.ts +0 -43
  76. package/src/database/DatabaseController.test.ts +0 -613
  77. package/src/database/DatabaseController.ts +0 -1007
  78. package/src/database/index.test.ts +0 -1372
  79. package/src/database/index.ts +0 -9
  80. package/src/database/interface.ts +0 -302
  81. package/src/email/DevAdapter.ts +0 -7
  82. package/src/email/EmailController.test.ts +0 -29
  83. package/src/email/EmailController.ts +0 -13
  84. package/src/email/index.ts +0 -2
  85. package/src/email/interface.ts +0 -36
  86. package/src/email/templates/sendOtpCode.ts +0 -120
  87. package/src/file/FileController.ts +0 -28
  88. package/src/file/FileDevAdapter.ts +0 -51
  89. package/src/file/hookDeleteFile.ts +0 -25
  90. package/src/file/hookReadFile.ts +0 -66
  91. package/src/file/hookUploadFile.ts +0 -50
  92. package/src/file/index.test.ts +0 -932
  93. package/src/file/index.ts +0 -2
  94. package/src/file/interface.ts +0 -39
  95. package/src/graphql/GraphQLSchema.test.ts +0 -4408
  96. package/src/graphql/GraphQLSchema.ts +0 -880
  97. package/src/graphql/index.ts +0 -2
  98. package/src/graphql/parseGraphqlSchema.ts +0 -85
  99. package/src/graphql/parser.test.ts +0 -203
  100. package/src/graphql/parser.ts +0 -542
  101. package/src/graphql/pointerAndRelationFunction.ts +0 -191
  102. package/src/graphql/resolvers.ts +0 -442
  103. package/src/graphql/tests/aggregation.test.ts +0 -1115
  104. package/src/graphql/tests/e2e.test.ts +0 -590
  105. package/src/graphql/tests/scalars.test.ts +0 -250
  106. package/src/graphql/types.ts +0 -227
  107. package/src/hooks/HookObject.test.ts +0 -122
  108. package/src/hooks/HookObject.ts +0 -165
  109. package/src/hooks/authentication.ts +0 -67
  110. package/src/hooks/createUser.test.ts +0 -77
  111. package/src/hooks/createUser.ts +0 -10
  112. package/src/hooks/defaultFields.test.ts +0 -176
  113. package/src/hooks/defaultFields.ts +0 -32
  114. package/src/hooks/deleteSession.test.ts +0 -181
  115. package/src/hooks/deleteSession.ts +0 -20
  116. package/src/hooks/hashFieldHook.test.ts +0 -152
  117. package/src/hooks/hashFieldHook.ts +0 -89
  118. package/src/hooks/index.test.ts +0 -258
  119. package/src/hooks/index.ts +0 -414
  120. package/src/hooks/permissions.test.ts +0 -412
  121. package/src/hooks/permissions.ts +0 -93
  122. package/src/hooks/protected.test.ts +0 -551
  123. package/src/hooks/protected.ts +0 -60
  124. package/src/hooks/searchableFields.test.ts +0 -147
  125. package/src/hooks/searchableFields.ts +0 -86
  126. package/src/hooks/session.test.ts +0 -134
  127. package/src/hooks/session.ts +0 -76
  128. package/src/hooks/setEmail.test.ts +0 -216
  129. package/src/hooks/setEmail.ts +0 -33
  130. package/src/hooks/setupAcl.test.ts +0 -618
  131. package/src/hooks/setupAcl.ts +0 -25
  132. package/src/index.ts +0 -9
  133. package/src/schema/Schema.test.ts +0 -482
  134. package/src/schema/Schema.ts +0 -757
  135. package/src/schema/defaultResolvers.ts +0 -93
  136. package/src/schema/index.ts +0 -1
  137. package/src/schema/resolvers/meResolver.test.ts +0 -62
  138. package/src/schema/resolvers/meResolver.ts +0 -10
  139. package/src/schema/resolvers/resetPassword.test.ts +0 -341
  140. package/src/schema/resolvers/resetPassword.ts +0 -63
  141. package/src/schema/resolvers/sendEmail.test.ts +0 -118
  142. package/src/schema/resolvers/sendEmail.ts +0 -21
  143. package/src/schema/resolvers/sendOtpCode.test.ts +0 -141
  144. package/src/schema/resolvers/sendOtpCode.ts +0 -52
  145. package/src/security.test.ts +0 -3434
  146. package/src/server/defaultSessionHandler.test.ts +0 -62
  147. package/src/server/defaultSessionHandler.ts +0 -105
  148. package/src/server/generateCodegen.ts +0 -433
  149. package/src/server/index.test.ts +0 -532
  150. package/src/server/index.ts +0 -334
  151. package/src/server/interface.ts +0 -11
  152. package/src/server/routes/authHandler.ts +0 -169
  153. package/src/server/routes/index.ts +0 -39
  154. package/src/utils/crypto.test.ts +0 -41
  155. package/src/utils/crypto.ts +0 -105
  156. package/src/utils/export.ts +0 -11
  157. package/src/utils/helper.ts +0 -204
  158. package/src/utils/index.test.ts +0 -11
  159. package/src/utils/index.ts +0 -189
  160. package/src/utils/preload.ts +0 -8
  161. package/src/utils/testHelper.ts +0 -116
  162. package/tsconfig.json +0 -32
@@ -1,24 +1,22 @@
1
1
  import type { WabeContext } from "../server/interface";
2
- import type { User } from "../../generated/wabe";
3
- import type { WabeConfig } from "../server";
4
- import type { DevWabeTypes } from "../utils/helper";
5
- export declare class Session {
2
+ import type { WabeConfig, WabeTypes } from "../server";
3
+ export declare class Session<T extends WabeTypes> {
6
4
  private accessToken;
7
5
  private refreshToken;
8
- getAccessTokenExpireAt(config: WabeConfig<DevWabeTypes>);
9
- _getRefreshTokenExpiresInMs(config: WabeConfig<DevWabeTypes>);
10
- getRefreshTokenExpireAt(config: WabeConfig<DevWabeTypes>);
6
+ getAccessTokenExpireAt(config: WabeConfig<T>);
7
+ _getRefreshTokenExpiresInMs(config: WabeConfig<T>);
8
+ getRefreshTokenExpireAt(config: WabeConfig<T>);
11
9
  meFromAccessToken({ accessToken, csrfToken }: {
12
10
  accessToken: string;
13
11
  csrfToken: string;
14
- }, context: WabeContext<DevWabeTypes>): Promise<{
12
+ }, context: WabeContext<T>): Promise<{
15
13
  sessionId: string | null;
16
- user: User | null;
14
+ user: T["types"]["User"] | null;
17
15
  accessToken: string | null;
18
16
  refreshToken?: string | null;
19
17
  }>;
20
- create(userId: string, context: WabeContext<DevWabeTypes>);
21
- refresh(accessToken: string, refreshToken: string, context: WabeContext<DevWabeTypes>);
22
- delete(context: WabeContext<DevWabeTypes>);
18
+ create(userId: string, context: WabeContext<T>);
19
+ refresh(accessToken: string, refreshToken: string, context: WabeContext<T>);
20
+ delete(context: WabeContext<T>);
23
21
  _isRefreshTokenExpired(userRefreshTokenExpiresAt: Date, refreshTokenAgeInMs: number);
24
22
  }
@@ -0,0 +1 @@
1
+ export declare const getSessionCookieSameSite: unknown;
@@ -1,3 +1,4 @@
1
1
  export * from "./interface";
2
2
  export * from "./oauth";
3
3
  export * from "./OTP";
4
+ export * from "./Session";
@@ -121,6 +121,25 @@ export interface SessionConfig<T extends WabeTypes> {
121
121
  */
122
122
  jwtTokenFields?: SelectType<T, "User", keyof T["types"]["User"]>;
123
123
  }
124
+ export interface AuthenticationRateLimitConfig {
125
+ /**
126
+ * Enable this rate limiter. Enabled by default in production.
127
+ */
128
+ enabled?: boolean;
129
+ maxAttempts?: number;
130
+ windowMs?: number;
131
+ blockDurationMs?: number;
132
+ }
133
+ export interface AuthenticationSecurityConfig {
134
+ signInRateLimit?: AuthenticationRateLimitConfig;
135
+ signUpRateLimit?: AuthenticationRateLimitConfig;
136
+ verifyChallengeRateLimit?: AuthenticationRateLimitConfig;
137
+ mfaChallengeTtlMs?: number;
138
+ /**
139
+ * Require a valid challenge token during verifyChallenge in production.
140
+ */
141
+ requireMfaChallengeInProduction?: boolean;
142
+ }
124
143
  export interface AuthenticationConfig<T extends WabeTypes> {
125
144
  session?: SessionConfig<T>;
126
145
  roles?: RoleConfig;
@@ -132,6 +151,7 @@ export interface AuthenticationConfig<T extends WabeTypes> {
132
151
  customAuthenticationMethods?: CustomAuthenticationMethods<T>[];
133
152
  sessionHandler?: (context: WobeCustomContext<T>) => void | Promise<void>;
134
153
  disableSignUp?: boolean;
154
+ security?: AuthenticationSecurityConfig;
135
155
  }
136
156
  export interface CreateTokenFromAuthorizationCodeOptions {
137
157
  code: string;
@@ -0,0 +1,18 @@
1
+ import type { WabeContext } from "../server/interface";
2
+ import type { WabeTypes } from "../server";
3
+ import { DevWabeTypes } from "src/utils/helper";
4
+ type RateLimitScope = "signIn" | "signUp" | "verifyChallenge";
5
+ export declare const isRateLimited: <T extends WabeTypes>(context: WabeContext<T>, scope: RateLimitScope, key: string) => boolean;
6
+ export declare const registerRateLimitFailure: unknown;
7
+ export declare const clearRateLimit: unknown;
8
+ export declare const createMfaChallenge: (context: WabeContext<DevWabeTypes>, { userId, provider }: {
9
+ userId: string;
10
+ provider: string;
11
+ }) => Promise<string>;
12
+ export declare const consumeMfaChallenge: (context: WabeContext<DevWabeTypes>, { challengeToken, userId, provider }: {
13
+ challengeToken: string;
14
+ userId: string;
15
+ provider: string;
16
+ }) => Promise<boolean>;
17
+ export declare const shouldRequireMfaChallenge: unknown;
18
+ export {};
@@ -2,7 +2,7 @@ import type { WabeTypes } from "../..";
2
2
  import { OperationType } from "../hooks";
3
3
  import type { SchemaInterface } from "../schema";
4
4
  import type { WabeContext } from "../server/interface";
5
- import type { CountOptions, CreateObjectOptions, CreateObjectsOptions, DatabaseAdapter, DeleteObjectOptions, DeleteObjectsOptions, GetObjectOptions, GetObjectsOptions, OutputType, UpdateObjectOptions, UpdateObjectsOptions, WhereType } from "./interface";
5
+ import { type CountOptions, type CreateObjectOptions, type CreateObjectsOptions, type DatabaseAdapter, type DeleteObjectOptions, type DeleteObjectsOptions, type GetObjectOptions, type GetObjectsOptions, type OutputType, type UpdateObjectOptions, type UpdateObjectsOptions, type WhereType } from "./interface";
6
6
  export type Select = Record<string, boolean>;
7
7
  type SelectWithObject = Record<string, object | boolean>;
8
8
  export declare class DatabaseController<T extends WabeTypes> {
@@ -19,6 +19,43 @@ export declare class DatabaseController<T extends WabeTypes> {
19
19
  type: string;
20
20
  class?: string;
21
21
  } | undefined;
22
+ _getVirtualFieldsForClass(className: keyof T["types"], context: WabeContext<T>);
23
+ _buildReadSelects({ className, context, selectWithoutPointers }: {
24
+ className: keyof T["types"];
25
+ context: WabeContext<T>;
26
+ selectWithoutPointers: Select;
27
+ }): {};
28
+ _buildHookReadSelect({ className, context, userSelect, selectWithoutPointers }: {
29
+ className: keyof T["types"];
30
+ context: WabeContext<T>;
31
+ userSelect: Select;
32
+ selectWithoutPointers: Select;
33
+ }): Select;
34
+ _initializeReadHook<K extends keyof T["types"]>({ className, context, userSelect, selectWithoutPointers, _skipHooks }: {
35
+ className: K;
36
+ context: WabeContext<T>;
37
+ userSelect: Select;
38
+ selectWithoutPointers: Select;
39
+ _skipHooks?: boolean;
40
+ });
41
+ _buildSelectWithPointers({ adapterSelect, pointers }: {
42
+ adapterSelect: Select;
43
+ pointers: Record<string, {
44
+ className: string;
45
+ select: Select;
46
+ }>;
47
+ });
48
+ _isEmptySelect(select?: Record<string, unknown>): boolean;
49
+ _projectObjectForUserSelect({ object, select }: {
50
+ object: Record<string, any> | null | undefined;
51
+ select?: SelectWithObject;
52
+ }): any;
53
+ _stripVirtualFieldsFromPayload({ className, context, payload }: {
54
+ className: keyof T["types"];
55
+ context: WabeContext<T>;
56
+ payload: unknown;
57
+ }): any;
58
+ _stripVirtualFieldsFromSchema(schema: SchemaInterface<T>): SchemaInterface<T>;
22
59
  _getSelectMinusPointersAndRelations({ className, context, select }: {
23
60
  className: keyof T["types"];
24
61
  context: WabeContext<T>;
@@ -61,14 +98,31 @@ export declare class DatabaseController<T extends WabeTypes> {
61
98
  id: string;
62
99
  } | null>;
63
100
  });
101
+ _getRelationSelectWithoutTotalCount(currentSelect?: Select): Select;
102
+ _resolvePointerField({ currentClassName, object, pointerField, currentSelect, context, _skipHooks }: {
103
+ currentClassName: string;
104
+ object: Record<string, any>;
105
+ pointerField: string;
106
+ currentSelect?: Select;
107
+ context: WabeContext<any>;
108
+ _skipHooks?: boolean;
109
+ });
110
+ _resolveRelationField({ currentClassName, object, pointerField, currentSelect, context, _skipHooks }: {
111
+ currentClassName: string;
112
+ object: Record<string, any>;
113
+ pointerField: string;
114
+ currentSelect?: Select;
115
+ context: WabeContext<any>;
116
+ _skipHooks?: boolean;
117
+ });
64
118
  _getFinalObjectWithPointerAndRelation({ pointers, context, originClassName, object, _skipHooks }: {
65
- originClassName: string;
119
+ originClassName: keyof T["types"];
66
120
  pointers: Record<string, {
67
121
  className: string;
68
122
  select: Select;
69
123
  }>;
70
124
  context: WabeContext<any>;
71
- object: Record<string, any>;
125
+ object: Record<string, any> | null | undefined;
72
126
  _skipHooks?: boolean;
73
127
  });
74
128
  close();
@@ -46,6 +46,11 @@ export type WhereType<
46
46
  T extends WabeTypes,
47
47
  K = keyof T["where"]
48
48
  > = Partial<WhereAggregation<T, K>> & WhereConditional<T, K>;
49
+ /** Structure for relation where input (have / isEmpty) */
50
+ export type RelationWhereInput<THave = unknown> = {
51
+ have?: THave;
52
+ isEmpty?: boolean;
53
+ };
49
54
  type SelectObject<
50
55
  T,
51
56
  K extends WabeTypes,
@@ -1,4 +1,26 @@
1
1
  import type { WabeContext, WabeTypes } from "src/server";
2
+ export type FileUploadSecurityConfig = {
3
+ /**
4
+ * Enable upload validation rules. Enabled by default in production.
5
+ */
6
+ enabled?: boolean;
7
+ /**
8
+ * Maximum allowed file size in bytes.
9
+ */
10
+ maxFileSizeBytes?: number;
11
+ /**
12
+ * Allowlist of MIME types accepted by uploads.
13
+ */
14
+ allowedMimeTypes?: string[];
15
+ /**
16
+ * Allowlist of file extensions accepted by uploads (without dot).
17
+ */
18
+ allowedExtensions?: string[];
19
+ /**
20
+ * Randomize uploaded file names (enabled by default in production).
21
+ */
22
+ randomizeFileName?: boolean;
23
+ };
2
24
  /**
3
25
  * The file config contains the adapter to use to upload file
4
26
  * @param adapter: FileAdapter
@@ -10,6 +32,7 @@ export type FileConfig<T extends WabeTypes> = {
10
32
  urlCacheInSeconds?: number;
11
33
  devDirectory?: string;
12
34
  beforeUpload?: (file: File, context: WabeContext<T>) => Promise<File> | File;
35
+ security?: FileUploadSecurityConfig;
13
36
  };
14
37
  export interface ReadFileOptions {
15
38
  urlExpiresIn?: number;
@@ -0,0 +1,6 @@
1
+ import type { WabeContext, WabeTypes } from "src/server";
2
+ import type { FileUploadSecurityConfig } from "./interface";
3
+ declare const getUploadSecurityConfig: <T extends WabeTypes>(context: WabeContext<T>) => {};
4
+ export declare const secureUploadedFile: <T extends WabeTypes>(file: File, context: WabeContext<T>) => Promise<File>;
5
+ export declare const getUploadSecurityConfigForTests: <T extends WabeTypes>(context: WabeContext<T>) => ReturnType<typeof getUploadSecurityConfig>;
6
+ export type { FileUploadSecurityConfig };
@@ -2,7 +2,7 @@ import { GraphQLEnumType, type GraphQLFieldConfig, GraphQLInputObjectType, Graph
2
2
  import type { ClassInterface, MutationResolver, QueryResolver, Schema, SchemaFields } from "../schema";
3
3
  import type { DevWabeTypes } from "../utils/helper";
4
4
  import { type GraphqlParserFactory } from "./parser";
5
- type AllPossibleObject = "object" | "inputObject" | "whereInputObject" | "connectionObject" | "pointerInputObject" | "relationInputObject" | "updateInputObject" | "createInputObject" | "orderEnumType";
5
+ type AllPossibleObject = "object" | "inputObject" | "whereInputObject" | "connectionObject" | "pointerInputObject" | "relationInputObject" | "relationWhereInputObject" | "updateInputObject" | "createInputObject" | "orderEnumType";
6
6
  export type AllObjects = Record<string, Partial<Record<AllPossibleObject, any>>>;
7
7
  export declare class GraphQLSchema {
8
8
  private schemas;
@@ -2,6 +2,7 @@ import type { SelectionSetNode, FragmentDefinitionNode } from "graphql";
2
2
  import type { WabeContext } from "../server/interface";
3
3
  export declare const extractFieldsFromSetNode: (selectionSet: SelectionSetNode, className: string, fragments?: Record<string, FragmentDefinitionNode>, options?: {
4
4
  ignoreClassField?: boolean;
5
+ variables?: Record<string, any>;
5
6
  }) => Record<string, any>;
6
7
  export declare const getFieldsOfClassName: ({ fields, className, context }: {
7
8
  fields: string[];
@@ -1,3 +1,6 @@
1
+ import type { SchemaClassWithProtectedFields } from "../schema/Schema";
2
+ import type { WabeContext } from "../server/interface";
3
+ export declare const canUserReadField: (schemaClass: SchemaClassWithProtectedFields, fieldName: string, context: Pick<WabeContext<any>, "isRoot" | "user">) => boolean;
1
4
  export declare const defaultCheckProtectedOnBeforeRead: unknown;
2
5
  export declare const defaultCheckProtectedOnBeforeUpdate: unknown;
3
6
  export declare const defaultCheckProtectedOnBeforeCreate: unknown;
@@ -0,0 +1,3 @@
1
+ import type { Hook } from ".";
2
+ import type { DevWabeTypes } from "../utils/helper";
3
+ export declare const defaultVirtualFieldsAfterRead: Hook<DevWabeTypes, any>["callback"];