wabe 0.6.7 → 0.6.9

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 (68) hide show
  1. package/README.md +10 -7
  2. package/dist/authentication/OTP.d.ts +8 -0
  3. package/dist/authentication/Session.d.ts +5 -5
  4. package/dist/authentication/index.d.ts +1 -0
  5. package/dist/authentication/interface.d.ts +43 -26
  6. package/dist/authentication/oauth/GitHub.d.ts +1 -1
  7. package/dist/authentication/oauth/Google.d.ts +1 -1
  8. package/dist/authentication/oauth/Oauth2Client.d.ts +11 -11
  9. package/dist/authentication/oauth/utils.d.ts +1 -0
  10. package/dist/authentication/providers/EmailOTP.d.ts +2 -2
  11. package/dist/authentication/providers/EmailPassword.d.ts +3 -3
  12. package/dist/authentication/providers/EmailPasswordSRP.d.ts +21 -0
  13. package/dist/authentication/providers/GitHub.d.ts +3 -2
  14. package/dist/authentication/providers/Google.d.ts +3 -2
  15. package/dist/authentication/providers/OAuth.d.ts +2 -2
  16. package/dist/authentication/providers/PhonePassword.d.ts +3 -3
  17. package/dist/authentication/providers/QRCodeOTP.d.ts +11 -0
  18. package/dist/authentication/providers/index.d.ts +1 -0
  19. package/dist/authentication/resolvers/signInWithResolver.d.ts +4 -0
  20. package/dist/authentication/resolvers/signUpWithResolver.d.ts +4 -0
  21. package/dist/authentication/utils.d.ts +0 -1
  22. package/dist/cron/index.d.ts +8 -8
  23. package/dist/database/{controllers/DatabaseController.d.ts → DatabaseController.d.ts} +38 -36
  24. package/dist/database/index.d.ts +6 -9
  25. package/dist/database/{adapters/adaptersInterface.d.ts → interface.d.ts} +37 -47
  26. package/dist/email/DevAdapter.d.ts +1 -0
  27. package/dist/email/interface.d.ts +4 -4
  28. package/dist/{files → file}/FileController.d.ts +1 -1
  29. package/dist/{files → file}/FileDevAdapter.d.ts +1 -1
  30. package/dist/{files → file}/interface.d.ts +9 -3
  31. package/dist/graphql/GraphQLSchema.d.ts +32 -32
  32. package/dist/graphql/parser.d.ts +13 -13
  33. package/dist/graphql/pointerAndRelationFunction.d.ts +6 -6
  34. package/dist/graphql/resolvers.d.ts +5 -5
  35. package/dist/hooks/HookObject.d.ts +13 -12
  36. package/dist/hooks/createUser.d.ts +1 -0
  37. package/dist/hooks/deleteSession.d.ts +2 -0
  38. package/dist/hooks/hashFieldHook.d.ts +6 -0
  39. package/dist/hooks/index.d.ts +17 -13
  40. package/dist/hooks/setEmail.d.ts +2 -0
  41. package/dist/index.d.ts +1 -2
  42. package/dist/index.js +51013 -486
  43. package/dist/schema/Schema.d.ts +59 -57
  44. package/dist/schema/defaultResolvers.d.ts +2 -2
  45. package/dist/server/index.d.ts +20 -24
  46. package/dist/server/interface.d.ts +1 -0
  47. package/dist/server/routes/authHandler.d.ts +11 -0
  48. package/dist/utils/crypto.d.ts +11 -0
  49. package/dist/utils/export.d.ts +2 -0
  50. package/dist/utils/helper.d.ts +3 -6
  51. package/dist/utils/index.d.ts +20 -2
  52. package/generated/schema.graphql +87 -76
  53. package/generated/wabe.ts +49 -52
  54. package/package.json +52 -54
  55. package/dist/authentication/srp/processSRPChallenge.d.ts +0 -1
  56. package/dist/authentication/srp/signInWithSRP.d.ts +0 -1
  57. package/dist/authentication/srp/signUpWithSRP.d.ts +0 -1
  58. package/dist/database/adapters/MongoAdapter.d.ts +0 -64
  59. package/dist/database/adapters/index.d.ts +0 -2
  60. package/dist/database/controllers/index.d.ts +0 -1
  61. package/dist/payment/DevAdapter.d.ts +0 -17
  62. package/dist/payment/PaymentController.d.ts +0 -19
  63. package/dist/payment/index.d.ts +0 -2
  64. package/dist/payment/interface.d.ts +0 -235
  65. /package/dist/{files → file}/hookDeleteFile.d.ts +0 -0
  66. /package/dist/{files → file}/hookReadFile.d.ts +0 -0
  67. /package/dist/{files → file}/hookUploadFile.d.ts +0 -0
  68. /package/dist/{files → file}/index.d.ts +0 -0
@@ -1,101 +1,103 @@
1
1
  import type { WabeConfig, WabeTypes } from "../server";
2
2
  import type { HookObject } from "../hooks/HookObject";
3
- export type WabePrimaryTypes = "String" | "Int" | "Float" | "Boolean" | "Email" | "Phone" | "Date" | "File";
3
+ export type WabePrimaryTypes = "String" | "Int" | "Float" | "Boolean" | "Email" | "Phone" | "Date" | "File" | "Hash";
4
4
  export type WabeCustomTypes = "Array" | "Object";
5
5
  export type WabeRelationTypes = "Pointer" | "Relation";
6
- type WabeFieldTypes = WabeCustomTypes | WabePrimaryTypes | WabeRelationTypes;
6
+ export type WabeFieldTypes = WabeCustomTypes | WabePrimaryTypes | WabeRelationTypes;
7
7
  export type WabeObject<T extends WabeTypes> = {
8
- name: string
9
- fields: SchemaFields<T>
10
- description?: string
11
- required?: boolean
8
+ name: string;
9
+ fields: SchemaFields<T>;
10
+ description?: string;
11
+ required?: boolean;
12
12
  };
13
13
  type FieldBase<T extends WabeTypes> = {
14
- required?: boolean
15
- description?: string
14
+ required?: boolean;
15
+ description?: string;
16
16
  protected?: {
17
- authorizedRoles: Array<T["enums"]["RoleEnum"] | "rootOnly">
18
- protectedOperations: Array<"create" | "read" | "update">
19
- }
17
+ authorizedRoles: Array<T["enums"]["RoleEnum"] | "rootOnly">;
18
+ protectedOperations: Array<"create" | "read" | "update">;
19
+ };
20
20
  };
21
21
  type TypeFieldBase<
22
22
  U,
23
23
  K extends WabeFieldTypes
24
24
  > = {
25
- type: K
26
- defaultValue?: U
25
+ type: K;
26
+ defaultValue?: U;
27
27
  };
28
28
  type TypeFieldArray<T extends WabeTypes> = {
29
- type: "Array"
30
- requiredValue?: boolean
31
- defaultValue?: any[]
29
+ type: "Array";
30
+ requiredValue?: boolean;
31
+ defaultValue?: any[];
32
32
  } & ({
33
- typeValue: WabePrimaryTypes
33
+ // For the moment we only keep object and not array because we don't
34
+ // support array of array
35
+ typeValue: WabePrimaryTypes;
34
36
  } | {
35
- typeValue: "Object"
36
- object: WabeObject<T>
37
+ typeValue: "Object";
38
+ object: WabeObject<T>;
37
39
  });
38
40
  type TypeFieldObject<T extends WabeTypes> = {
39
- type: "Object"
40
- object: WabeObject<T>
41
- defaultValue?: any
41
+ type: "Object";
42
+ object: WabeObject<T>;
43
+ defaultValue?: any;
42
44
  };
43
45
  type TypeFieldPointer<T extends WabeTypes> = {
44
- type: "Pointer"
45
- class: keyof T["types"]
46
+ type: "Pointer";
47
+ class: keyof T["types"];
46
48
  };
47
49
  type TypeFieldRelation<T extends WabeTypes> = {
48
- type: "Relation"
49
- class: keyof T["types"]
50
+ type: "Relation";
51
+ class: keyof T["types"];
50
52
  };
51
53
  type TypeFieldFile = {
52
- type: "File"
54
+ type: "File";
53
55
  };
54
56
  type TypeFieldCustomScalars<T extends WabeTypes> = {
55
- type: T["scalars"]
56
- required?: boolean
57
- defaultValue?: any
57
+ type: T["scalars"];
58
+ required?: boolean;
59
+ defaultValue?: any;
58
60
  };
59
61
  type TypeFieldCustomEnums<T extends WabeTypes> = {
60
- type: keyof T["enums"]
61
- defaultValue?: any
62
+ type: keyof T["enums"];
63
+ defaultValue?: any;
62
64
  };
63
- export type TypeField<T extends WabeTypes> = (TypeFieldBase<string, "String"> | TypeFieldBase<number, "Int"> | TypeFieldBase<number, "Float"> | TypeFieldBase<boolean, "Boolean"> | TypeFieldBase<Date, "Date"> | TypeFieldBase<string, "Email"> | TypeFieldBase<string, "Phone"> | TypeFieldArray<T> | TypeFieldObject<T> | TypeFieldPointer<T> | TypeFieldRelation<T> | TypeFieldFile | TypeFieldCustomScalars<T> | TypeFieldCustomEnums<T>) & FieldBase<T>;
65
+ export type TypeField<T extends WabeTypes> = (TypeFieldBase<string, "String"> | TypeFieldBase<number, "Int"> | TypeFieldBase<number, "Float"> | TypeFieldBase<boolean, "Boolean"> | TypeFieldBase<Date, "Date"> | TypeFieldBase<string, "Email"> | TypeFieldBase<string, "Phone"> | TypeFieldBase<string, "Hash"> | TypeFieldArray<T> | TypeFieldObject<T> | TypeFieldPointer<T> | TypeFieldRelation<T> | TypeFieldFile | TypeFieldCustomScalars<T> | TypeFieldCustomEnums<T>) & FieldBase<T>;
64
66
  export type SchemaFields<T extends WabeTypes> = Record<string, TypeField<T>>;
65
67
  export type ResolverType<T extends WabeTypes> = {
66
- required?: boolean
67
- description?: string
68
- resolve: (...args: any) => any
68
+ required?: boolean;
69
+ description?: string;
70
+ resolve: (...args: any) => any;
69
71
  } & ({
70
- type: WabePrimaryTypes | T["enums"] | T["scalars"]
72
+ type: WabePrimaryTypes | T["enums"] | T["scalars"];
71
73
  } | {
72
- type: "Object"
73
- outputObject: ClassInterface<T>
74
+ type: "Object";
75
+ outputObject: ClassInterface<T>;
74
76
  } | {
75
- type: "Array"
76
- typeValue: WabePrimaryTypes
77
- typeValueRequired?: boolean
77
+ type: "Array";
78
+ typeValue: WabePrimaryTypes;
79
+ typeValueRequired?: boolean;
78
80
  } | {
79
- type: "Array"
80
- typeValue: "Object"
81
- outputObject: ClassInterface<T>
82
- typeValueRequired?: boolean
81
+ type: "Array";
82
+ typeValue: "Object";
83
+ outputObject: ClassInterface<T>;
84
+ typeValueRequired?: boolean;
83
85
  });
84
86
  export type QueryResolver<T extends WabeTypes> = {
85
- args?: SchemaFields<T>
87
+ args?: SchemaFields<T>;
86
88
  } & ResolverType<T>;
87
89
  export type MutationResolver<T extends WabeTypes> = {
88
90
  args?: {
89
- input: SchemaFields<T>
90
- }
91
+ input: SchemaFields<T>;
92
+ };
91
93
  } & ResolverType<T>;
92
94
  export type TypeResolver<T extends WabeTypes> = {
93
95
  queries?: {
94
- [key: string]: QueryResolver<T>
95
- }
96
+ [key: string]: QueryResolver<T>;
97
+ };
96
98
  mutations?: {
97
- [key: string]: MutationResolver<T>
98
- }
99
+ [key: string]: MutationResolver<T>;
100
+ };
99
101
  };
100
102
  export type PermissionsOperations = "create" | "read" | "update" | "delete";
101
103
  export interface PermissionProperties<T extends WabeTypes> {
@@ -112,13 +114,13 @@ export interface PermissionProperties<T extends WabeTypes> {
112
114
  */
113
115
  export type ACLProperties = (hookObject: HookObject<any, any>) => void | Promise<void>;
114
116
  export type ClassPermissions<T extends WabeTypes> = Partial<Record<PermissionsOperations, PermissionProperties<T>> & {
115
- acl: ACLProperties
117
+ acl: ACLProperties;
116
118
  }>;
117
119
  export type SearchableFields = Array<string>;
118
120
  export type ClassIndexes = Array<{
119
- field: string
120
- order: "ASC" | "DESC"
121
- unique?: boolean
121
+ field: string;
122
+ order: "ASC" | "DESC";
123
+ unique?: boolean;
122
124
  }>;
123
125
  export interface ClassInterface<T extends WabeTypes> {
124
126
  name: string;
@@ -1,7 +1,7 @@
1
1
  import type { MutationResolver, QueryResolver } from "./Schema";
2
2
  export declare const defaultQueries: {
3
- [key: string]: QueryResolver<any>
3
+ [key: string]: QueryResolver<any>;
4
4
  };
5
5
  export declare const defaultMutations: {
6
- [key: string]: MutationResolver<any>
6
+ [key: string]: MutationResolver<any>;
7
7
  };
@@ -1,5 +1,5 @@
1
1
  import type { DatabaseConfig } from "../database";
2
- import { DatabaseController } from "../database/controllers/DatabaseController";
2
+ import { DatabaseController } from "../database/DatabaseController";
3
3
  import { type SchemaInterface } from "../schema/Schema";
4
4
  import { GraphQLSchema } from "graphql";
5
5
  import type { AuthenticationConfig } from "../authentication/interface";
@@ -9,18 +9,16 @@ import { generateCodegen } from "./generateCodegen";
9
9
  import { Wobe } from "wobe";
10
10
  import type { Context, CorsOptions, RateLimitOptions } from "wobe";
11
11
  import type { WabeContext } from "./interface";
12
- import type { FileConfig } from "../files";
13
12
  import type { EmailConfig } from "../email";
14
13
  import { EmailController } from "../email/EmailController";
15
- import type { PaymentConfig } from "../payment/interface";
16
- import { PaymentController } from "../payment/PaymentController";
17
14
  import type { AIConfig } from "../ai";
18
- import { FileController } from "../files/FileController";
15
+ import { FileController } from "../file/FileController";
19
16
  import type { CronConfig } from "../cron";
17
+ import type { FileConfig } from "../file";
20
18
  type SecurityConfig = {
21
- corsOptions?: CorsOptions
22
- rateLimit?: RateLimitOptions
23
- maskErrorMessage?: boolean
19
+ corsOptions?: CorsOptions;
20
+ rateLimit?: RateLimitOptions;
21
+ hideSensitiveErrorMessage?: boolean;
24
22
  };
25
23
  export * from "./interface";
26
24
  export * from "./routes";
@@ -31,43 +29,41 @@ export interface WabeConfig<T extends WabeTypes> {
31
29
  security?: SecurityConfig;
32
30
  schema?: SchemaInterface<T>;
33
31
  graphqlSchema?: GraphQLSchema;
34
- database: DatabaseConfig;
32
+ database: DatabaseConfig<T>;
35
33
  codegen?: {
36
- enabled: true
37
- path: string
34
+ enabled: true;
35
+ path: string;
38
36
  } | {
39
- enabled?: false
37
+ enabled?: false;
40
38
  };
41
39
  authentication?: AuthenticationConfig<T>;
42
40
  routes?: WabeRoute[];
43
41
  rootKey: string;
44
42
  hooks?: Hook<T, any>[];
45
43
  email?: EmailConfig;
46
- payment?: PaymentConfig;
47
44
  ai?: AIConfig;
48
- file?: FileConfig;
45
+ file?: FileConfig<T>;
49
46
  crons?: CronConfig<T>;
50
47
  }
51
48
  export type WabeTypes = {
52
- types: Record<any, any>
53
- where: Record<any, any>
54
- scalars: string
55
- enums: Record<any, any>
49
+ types: Record<any, any>;
50
+ where: Record<any, any>;
51
+ scalars: string;
52
+ enums: Record<any, any>;
56
53
  };
57
54
  export type WobeCustomContext<T extends WabeTypes> = Context & {
58
- wabe: WabeContext<T>
55
+ wabe: WabeContext<T>;
59
56
  };
60
57
  type WabeControllers<T extends WabeTypes> = {
61
- database: DatabaseController<T>
62
- email?: EmailController
63
- payment?: PaymentController
64
- file?: FileController
58
+ database: DatabaseController<T>;
59
+ email?: EmailController;
60
+ file?: FileController;
65
61
  };
66
62
  export declare class Wabe<T extends WabeTypes> {
67
63
  server: Wobe<WobeCustomContext<T>>;
68
64
  config: WabeConfig<T>;
69
65
  controllers: WabeControllers<T>;
70
- constructor({ isProduction, port, hostname, security, schema, database, authentication, rootKey, codegen, hooks, file, email, payment, routes, crons }: WabeConfig<T>);
66
+ constructor({ isProduction, port, hostname, security, schema, database, authentication, rootKey, codegen, hooks, file, email, routes, crons }: WabeConfig<T>);
71
67
  loadCrons();
72
68
  loadRoleEnum();
73
69
  loadAuthenticationMethods();
@@ -6,4 +6,5 @@ export interface WabeContext<T extends WabeTypes> {
6
6
  sessionId?: string | null;
7
7
  isRoot: boolean;
8
8
  wabe: Wabe<T>;
9
+ isGraphQLCall?: boolean;
9
10
  }
@@ -1,2 +1,13 @@
1
+ /*
2
+ - Generate code verifier (back)
3
+ - Sent post request to a route on back with code verifier in url (back)
4
+ - Generate code challenge (back)
5
+ - Redirect the user to google auth page with code challenge (back -> front)
6
+ - User sign in with google (front)
7
+ - The user is redirected to the route with the code (front -> back)
8
+ - Get the code from the url (back)
9
+ - Validate and sign in with google provider (back)
10
+ */
11
+ // https://www.rfc-editor.org/rfc/rfc7636#section-4.4 not precise the storage of codeVerifier
1
12
  export declare const oauthHandlerCallback: unknown;
2
13
  export declare const authHandler: unknown;
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Hash a string with Argon2id and PHC format
3
+ * @return : Returns the PHC format of the hashed text
4
+ */
5
+ export declare const hashArgon2: unknown;
6
+ /*
7
+ * Verify if a hash matchs with a string
8
+ * @return : Returns true if the password matchs with the hash, false otherwise
9
+ */
10
+ export declare const verifyArgon2: unknown;
11
+ export declare const isArgon2Hash: (value: string) => boolean;
@@ -1,2 +1,4 @@
1
1
  import type { WabeContext } from "../server/interface";
2
2
  export declare const contextWithRoot: (context: WabeContext<any>) => WabeContext<any>;
3
+ export declare const notEmpty: <T>(value: T | null | undefined) => value is T;
4
+ export * from "./crypto";
@@ -1,6 +1,6 @@
1
1
  import { GraphQLClient } from "graphql-request";
2
2
  import { type WabeSchemaWhereTypes, type WabeSchemaEnums, type WabeSchemaScalars, type WabeSchemaTypes } from "../../generated/wabe";
3
- import { Wabe, type WabeTypes } from "../server";
3
+ import type { Wabe, WabeTypes } from "../server";
4
4
  export interface DevWabeTypes extends WabeTypes {
5
5
  types: WabeSchemaTypes;
6
6
  scalars: WabeSchemaScalars;
@@ -8,14 +8,11 @@ export interface DevWabeTypes extends WabeTypes {
8
8
  where: WabeSchemaWhereTypes;
9
9
  }
10
10
  export declare const firstLetterUpperCase: (str: string) => string;
11
- export declare const notEmpty: <T>(value: T | null | undefined) => value is T;
12
11
  export declare const getGraphqlClient: (port: number) => GraphQLClient;
13
12
  export declare const getAnonymousClient: (port: number) => GraphQLClient;
14
13
  export declare const getUserClient: (port: number, accessToken: string) => GraphQLClient;
15
14
  export declare const getAdminUserClient: (port: number, wabe: Wabe<DevWabeTypes>, { email, password }: {
16
- email: string
17
- password: string
15
+ email: string;
16
+ password: string;
18
17
  }) => Promise<GraphQLClient>;
19
- export declare const setupTests: unknown;
20
- export declare const closeTests: unknown;
21
18
  export declare const createUserAndUpdateRole: unknown;
@@ -1,17 +1,35 @@
1
1
  import type { ClassInterface } from "../schema";
2
- import type { WabeTypes, WabeConfig } from "../server";
2
+ import type { WabeTypes, WabeConfig, WabeContext } from "../server";
3
+ export declare const contextWithoutGraphQLCall: (context: WabeContext<any>) => WabeContext<any>;
4
+ type Base32Variant = "RFC3548" | "RFC4648" | "RFC4648-HEX" | "Crockford";
5
+ interface Base32Options {
6
+ padding?: boolean;
7
+ }
8
+ /**
9
+ * Convert supported input types to Uint8Array.
10
+ */
11
+ export declare const toUint8Array: (data: string | ArrayBuffer | Uint8Array | Buffer) => Uint8Array;
12
+ /**
13
+ * Encode binary data to base32 using specified variant.
14
+ * Base on https://github.com/LinusU/base32-encode/blob/master/index.js
15
+ */
16
+ export declare const base32Encode: (data: string | ArrayBuffer | Uint8Array | Buffer, variant: Base32Variant, options?: Base32Options) => string;
17
+ export declare const getNewObjectAfterUpdateNestedProperty: unknown;
18
+ export declare const getNestedProperty: unknown;
3
19
  export declare const firstLetterInUpperCase: unknown;
4
20
  export declare const firstLetterInLowerCase: unknown;
5
21
  export declare const getClassFromClassName: <T extends WabeTypes>(className: string, config: WabeConfig<any>) => ClassInterface<T>;
22
+ // TODO: Put this in wobe
6
23
  export declare const getCookieInRequestHeaders: unknown;
7
24
  /**
8
25
  * This apply the following transformations on string:
9
26
  * - lowercase
10
27
  * - normalize with NFD
11
28
  * - remove diacritics and accents characters
12
- * - replace matching abbreviation with long version (if disableAbbrevations is not set)
29
+ * - replace matching abbreviation with long version (if disableAbbreviations is not set)
13
30
  * - replace 2 or more spaces by one
14
31
  * - replace all non alpha characters by a space
15
32
  * - trim
16
33
  */
17
34
  export declare const tokenize: unknown;
35
+ export {};