@aeriajs/builtins 0.0.229 → 0.0.230

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.
@@ -27,6 +27,7 @@ export declare const createAccount: (payload: Partial<PackReferences<SchemaWithI
27
27
  readonly properties: {
28
28
  readonly name: {
29
29
  readonly type: "string";
30
+ readonly minLength: 1;
30
31
  };
31
32
  readonly given_name: {
32
33
  readonly getter: (doc: object) => string | undefined;
@@ -48,6 +49,7 @@ export declare const createAccount: (payload: Partial<PackReferences<SchemaWithI
48
49
  readonly email: {
49
50
  readonly type: "string";
50
51
  readonly inputType: "email";
52
+ readonly minLength: 3;
51
53
  };
52
54
  readonly password: {
53
55
  readonly type: "string";
@@ -12,6 +12,7 @@ export declare const description: {
12
12
  readonly properties: {
13
13
  readonly name: {
14
14
  readonly type: "string";
15
+ readonly minLength: 1;
15
16
  };
16
17
  readonly given_name: {
17
18
  readonly getter: (doc: object) => string | undefined;
@@ -33,6 +34,7 @@ export declare const description: {
33
34
  readonly email: {
34
35
  readonly type: "string";
35
36
  readonly inputType: "email";
37
+ readonly minLength: 3;
36
38
  };
37
39
  readonly password: {
38
40
  readonly type: "string";
@@ -28,6 +28,7 @@ exports.description = (0, core_1.defineDescription)({
28
28
  properties: {
29
29
  name: {
30
30
  type: 'string',
31
+ minLength: 1,
31
32
  },
32
33
  given_name: {
33
34
  getter: (doc) => {
@@ -57,6 +58,7 @@ exports.description = (0, core_1.defineDescription)({
57
58
  email: {
58
59
  type: 'string',
59
60
  inputType: 'email',
61
+ minLength: 3,
60
62
  },
61
63
  password: {
62
64
  type: 'string',
@@ -21,7 +21,8 @@ export const description = defineDescription({
21
21
  unique: ["email"],
22
22
  properties: {
23
23
  name: {
24
- type: "string"
24
+ type: "string",
25
+ minLength: 1
25
26
  },
26
27
  given_name: {
27
28
  getter: (doc) => {
@@ -50,7 +51,8 @@ export const description = defineDescription({
50
51
  },
51
52
  email: {
52
53
  type: "string",
53
- inputType: "email"
54
+ inputType: "email",
55
+ minLength: 3
54
56
  },
55
57
  password: {
56
58
  type: "string",
@@ -10,6 +10,7 @@ export declare const editProfile: (payload: Partial<PackReferences<SchemaWithId<
10
10
  readonly properties: {
11
11
  readonly name: {
12
12
  readonly type: "string";
13
+ readonly minLength: 1;
13
14
  };
14
15
  readonly given_name: {
15
16
  readonly getter: (doc: object) => string | undefined;
@@ -31,6 +32,7 @@ export declare const editProfile: (payload: Partial<PackReferences<SchemaWithId<
31
32
  readonly email: {
32
33
  readonly type: "string";
33
34
  readonly inputType: "email";
35
+ readonly minLength: 3;
34
36
  };
35
37
  readonly password: {
36
38
  readonly type: "string";
@@ -28,6 +28,7 @@ export declare const getCurrentUser: (_payload: undefined, context: Context<type
28
28
  readonly properties: {
29
29
  readonly name: {
30
30
  readonly type: "string";
31
+ readonly minLength: 1;
31
32
  };
32
33
  readonly given_name: {
33
34
  readonly getter: (doc: object) => string | undefined;
@@ -49,6 +50,7 @@ export declare const getCurrentUser: (_payload: undefined, context: Context<type
49
50
  readonly email: {
50
51
  readonly type: "string";
51
52
  readonly inputType: "email";
53
+ readonly minLength: 3;
52
54
  };
53
55
  readonly password: {
54
56
  readonly type: "string";
@@ -10,6 +10,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
10
10
  readonly properties: {
11
11
  readonly name: {
12
12
  readonly type: "string";
13
+ readonly minLength: 1;
13
14
  };
14
15
  readonly given_name: {
15
16
  readonly getter: (doc: object) => string | undefined;
@@ -31,6 +32,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
31
32
  readonly email: {
32
33
  readonly type: "string";
33
34
  readonly inputType: "email";
35
+ readonly minLength: 3;
34
36
  };
35
37
  readonly password: {
36
38
  readonly type: "string";
@@ -113,6 +115,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
113
115
  readonly properties: {
114
116
  readonly name: {
115
117
  readonly type: "string";
118
+ readonly minLength: 1;
116
119
  };
117
120
  readonly given_name: {
118
121
  readonly getter: (doc: object) => string | undefined;
@@ -134,6 +137,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
134
137
  readonly email: {
135
138
  readonly type: "string";
136
139
  readonly inputType: "email";
140
+ readonly minLength: 3;
137
141
  };
138
142
  readonly password: {
139
143
  readonly type: "string";
@@ -253,6 +257,15 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
253
257
  readonly message: "tried to set unallowed roles";
254
258
  } & {
255
259
  httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
260
+ }> | import("@aeriajs/types").Result.Error<{
261
+ readonly code: import("@aeriajs/types").ACError.ResourceNotFound;
262
+ } & {
263
+ httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
264
+ }> | import("@aeriajs/types").Result.Error<{
265
+ readonly code: import("@aeriajs/types").ACError.AuthorizationError;
266
+ readonly message: "tried to edit an user with a roler higher in the hierarchy";
267
+ } & {
268
+ httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
256
269
  }> | import("@aeriajs/types").InsertReturnType<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>>>;
257
270
  readonly editProfile: (payload: Partial<import("@aeriajs/types").PackReferences<import("@aeriajs/types").SchemaWithId<{
258
271
  readonly $id: "user";
@@ -264,6 +277,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
264
277
  readonly properties: {
265
278
  readonly name: {
266
279
  readonly type: "string";
280
+ readonly minLength: 1;
267
281
  };
268
282
  readonly given_name: {
269
283
  readonly getter: (doc: object) => string | undefined;
@@ -285,6 +299,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
285
299
  readonly email: {
286
300
  readonly type: "string";
287
301
  readonly inputType: "email";
302
+ readonly minLength: 3;
288
303
  };
289
304
  readonly password: {
290
305
  readonly type: "string";
@@ -366,6 +381,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
366
381
  readonly properties: {
367
382
  readonly name: {
368
383
  readonly type: "string";
384
+ readonly minLength: 1;
369
385
  };
370
386
  readonly given_name: {
371
387
  readonly getter: (doc: object) => string | undefined;
@@ -387,6 +403,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
387
403
  readonly email: {
388
404
  readonly type: "string";
389
405
  readonly inputType: "email";
406
+ readonly minLength: 3;
390
407
  };
391
408
  readonly password: {
392
409
  readonly type: "string";
@@ -543,6 +560,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
543
560
  readonly properties: {
544
561
  readonly name: {
545
562
  readonly type: "string";
563
+ readonly minLength: 1;
546
564
  };
547
565
  readonly given_name: {
548
566
  readonly getter: (doc: object) => string | undefined;
@@ -564,6 +582,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
564
582
  readonly email: {
565
583
  readonly type: "string";
566
584
  readonly inputType: "email";
585
+ readonly minLength: 3;
567
586
  };
568
587
  readonly password: {
569
588
  readonly type: "string";
@@ -658,6 +677,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
658
677
  readonly properties: {
659
678
  readonly name: {
660
679
  readonly type: "string";
680
+ readonly minLength: 1;
661
681
  };
662
682
  readonly given_name: {
663
683
  readonly getter: (doc: object) => string | undefined;
@@ -679,6 +699,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
679
699
  readonly email: {
680
700
  readonly type: "string";
681
701
  readonly inputType: "email";
702
+ readonly minLength: 3;
682
703
  };
683
704
  readonly password: {
684
705
  readonly type: "string";
@@ -798,6 +819,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
798
819
  readonly properties: {
799
820
  readonly name: {
800
821
  readonly type: "string";
822
+ readonly minLength: 1;
801
823
  };
802
824
  readonly given_name: {
803
825
  readonly getter: (doc: object) => string | undefined;
@@ -819,6 +841,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
819
841
  readonly email: {
820
842
  readonly type: "string";
821
843
  readonly inputType: "email";
844
+ readonly minLength: 3;
822
845
  };
823
846
  readonly password: {
824
847
  readonly type: "string";
@@ -10,4 +10,13 @@ export declare const insert: <TDescription extends Description, TInsertPayload e
10
10
  readonly message: "tried to set unallowed roles";
11
11
  } & {
12
12
  httpStatus: HTTPStatus.Forbidden;
13
+ }> | import("@aeriajs/types").Result.Error<{
14
+ readonly code: ACError.ResourceNotFound;
15
+ } & {
16
+ httpStatus: HTTPStatus.NotFound;
17
+ }> | import("@aeriajs/types").Result.Error<{
18
+ readonly code: ACError.AuthorizationError;
19
+ readonly message: "tried to edit an user with a roler higher in the hierarchy";
20
+ } & {
21
+ httpStatus: HTTPStatus.Forbidden;
13
22
  }> | import("@aeriajs/types").InsertReturnType<SchemaWithId<TDescription>>>;
@@ -43,6 +43,24 @@ const insert = async (payload, context) => {
43
43
  });
44
44
  }
45
45
  }
46
+ if ('_id' in payload.what && typeof payload.what._id === 'string') {
47
+ context.collection.description.$id === 'oi';
48
+ const user = await context.collections.user.model.findOne({
49
+ _id: new core_1.ObjectId(payload.what._id),
50
+ });
51
+ if (!user) {
52
+ return context.error(types_1.HTTPStatus.NotFound, {
53
+ code: types_1.ACError.ResourceNotFound,
54
+ });
55
+ }
56
+ const allowed = user.roles.every((role) => isRoleAllowed(role, context));
57
+ if (!allowed) {
58
+ return context.error(types_1.HTTPStatus.Forbidden, {
59
+ code: types_1.ACError.AuthorizationError,
60
+ message: 'tried to edit an user with a roler higher in the hierarchy',
61
+ });
62
+ }
63
+ }
46
64
  }
47
65
  }
48
66
  if ('password' in payload.what && typeof payload.what.password === 'string') {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  import { HTTPStatus, ACError } from "@aeriajs/types";
3
3
  import { arraysIntersect } from "@aeriajs/common";
4
- import { insert as originalInsert } from "@aeriajs/core";
4
+ import { ObjectId, insert as originalInsert } from "@aeriajs/core";
5
5
  import * as bcrypt from "bcrypt";
6
6
  const isRoleAllowed = (targetRole, context) => {
7
7
  if (!context.config.security.rolesHierarchy || !context.token.authenticated) {
@@ -41,6 +41,24 @@ export const insert = async (payload, context) => {
41
41
  });
42
42
  }
43
43
  }
44
+ if ("_id" in payload.what && typeof payload.what._id === "string") {
45
+ context.collection.description.$id === "oi";
46
+ const user = await context.collections.user.model.findOne({
47
+ _id: new ObjectId(payload.what._id)
48
+ });
49
+ if (!user) {
50
+ return context.error(HTTPStatus.NotFound, {
51
+ code: ACError.ResourceNotFound
52
+ });
53
+ }
54
+ const allowed = user.roles.every((role) => isRoleAllowed(role, context));
55
+ if (!allowed) {
56
+ return context.error(HTTPStatus.Forbidden, {
57
+ code: ACError.AuthorizationError,
58
+ message: "tried to edit an user with a roler higher in the hierarchy"
59
+ });
60
+ }
61
+ }
44
62
  }
45
63
  }
46
64
  if ("password" in payload.what && typeof payload.what.password === "string") {
package/dist/index.d.ts CHANGED
@@ -474,6 +474,7 @@ export declare const collections: {
474
474
  readonly properties: {
475
475
  readonly name: {
476
476
  readonly type: "string";
477
+ readonly minLength: 1;
477
478
  };
478
479
  readonly given_name: {
479
480
  readonly getter: (doc: object) => string | undefined;
@@ -495,6 +496,7 @@ export declare const collections: {
495
496
  readonly email: {
496
497
  readonly type: "string";
497
498
  readonly inputType: "email";
499
+ readonly minLength: 3;
498
500
  };
499
501
  readonly password: {
500
502
  readonly type: "string";
@@ -577,6 +579,7 @@ export declare const collections: {
577
579
  readonly properties: {
578
580
  readonly name: {
579
581
  readonly type: "string";
582
+ readonly minLength: 1;
580
583
  };
581
584
  readonly given_name: {
582
585
  readonly getter: (doc: object) => string | undefined;
@@ -598,6 +601,7 @@ export declare const collections: {
598
601
  readonly email: {
599
602
  readonly type: "string";
600
603
  readonly inputType: "email";
604
+ readonly minLength: 3;
601
605
  };
602
606
  readonly password: {
603
607
  readonly type: "string";
@@ -717,6 +721,15 @@ export declare const collections: {
717
721
  readonly message: "tried to set unallowed roles";
718
722
  } & {
719
723
  httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
724
+ }> | import("@aeriajs/types").Result.Error<{
725
+ readonly code: import("@aeriajs/types").ACError.ResourceNotFound;
726
+ } & {
727
+ httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
728
+ }> | import("@aeriajs/types").Result.Error<{
729
+ readonly code: import("@aeriajs/types").ACError.AuthorizationError;
730
+ readonly message: "tried to edit an user with a roler higher in the hierarchy";
731
+ } & {
732
+ httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
720
733
  }> | import("@aeriajs/types").InsertReturnType<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>>>;
721
734
  readonly editProfile: (payload: Partial<import("@aeriajs/types").PackReferences<import("@aeriajs/types").SchemaWithId<{
722
735
  readonly $id: "user";
@@ -728,6 +741,7 @@ export declare const collections: {
728
741
  readonly properties: {
729
742
  readonly name: {
730
743
  readonly type: "string";
744
+ readonly minLength: 1;
731
745
  };
732
746
  readonly given_name: {
733
747
  readonly getter: (doc: object) => string | undefined;
@@ -749,6 +763,7 @@ export declare const collections: {
749
763
  readonly email: {
750
764
  readonly type: "string";
751
765
  readonly inputType: "email";
766
+ readonly minLength: 3;
752
767
  };
753
768
  readonly password: {
754
769
  readonly type: "string";
@@ -830,6 +845,7 @@ export declare const collections: {
830
845
  readonly properties: {
831
846
  readonly name: {
832
847
  readonly type: "string";
848
+ readonly minLength: 1;
833
849
  };
834
850
  readonly given_name: {
835
851
  readonly getter: (doc: object) => string | undefined;
@@ -851,6 +867,7 @@ export declare const collections: {
851
867
  readonly email: {
852
868
  readonly type: "string";
853
869
  readonly inputType: "email";
870
+ readonly minLength: 3;
854
871
  };
855
872
  readonly password: {
856
873
  readonly type: "string";
@@ -1007,6 +1024,7 @@ export declare const collections: {
1007
1024
  readonly properties: {
1008
1025
  readonly name: {
1009
1026
  readonly type: "string";
1027
+ readonly minLength: 1;
1010
1028
  };
1011
1029
  readonly given_name: {
1012
1030
  readonly getter: (doc: object) => string | undefined;
@@ -1028,6 +1046,7 @@ export declare const collections: {
1028
1046
  readonly email: {
1029
1047
  readonly type: "string";
1030
1048
  readonly inputType: "email";
1049
+ readonly minLength: 3;
1031
1050
  };
1032
1051
  readonly password: {
1033
1052
  readonly type: "string";
@@ -1122,6 +1141,7 @@ export declare const collections: {
1122
1141
  readonly properties: {
1123
1142
  readonly name: {
1124
1143
  readonly type: "string";
1144
+ readonly minLength: 1;
1125
1145
  };
1126
1146
  readonly given_name: {
1127
1147
  readonly getter: (doc: object) => string | undefined;
@@ -1143,6 +1163,7 @@ export declare const collections: {
1143
1163
  readonly email: {
1144
1164
  readonly type: "string";
1145
1165
  readonly inputType: "email";
1166
+ readonly minLength: 3;
1146
1167
  };
1147
1168
  readonly password: {
1148
1169
  readonly type: "string";
@@ -1262,6 +1283,7 @@ export declare const collections: {
1262
1283
  readonly properties: {
1263
1284
  readonly name: {
1264
1285
  readonly type: "string";
1286
+ readonly minLength: 1;
1265
1287
  };
1266
1288
  readonly given_name: {
1267
1289
  readonly getter: (doc: object) => string | undefined;
@@ -1283,6 +1305,7 @@ export declare const collections: {
1283
1305
  readonly email: {
1284
1306
  readonly type: "string";
1285
1307
  readonly inputType: "email";
1308
+ readonly minLength: 3;
1286
1309
  };
1287
1310
  readonly password: {
1288
1311
  readonly type: "string";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/builtins",
3
- "version": "0.0.229",
3
+ "version": "0.0.230",
4
4
  "description": "## Installation",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -55,7 +55,7 @@
55
55
  "mongodb": "^6.5.0"
56
56
  },
57
57
  "peerDependencies": {
58
- "@aeriajs/core": "^0.0.229",
58
+ "@aeriajs/core": "^0.0.230",
59
59
  "@aeriajs/common": "^0.0.131",
60
60
  "@aeriajs/entrypoint": "^0.0.134",
61
61
  "@aeriajs/types": "^0.0.113",