@aeriajs/builtins 0.0.228 → 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.
- package/dist/collections/user/createAccount.d.ts +2 -0
- package/dist/collections/user/description.d.ts +2 -0
- package/dist/collections/user/description.js +2 -0
- package/dist/collections/user/description.mjs +4 -2
- package/dist/collections/user/editProfile.d.ts +2 -0
- package/dist/collections/user/getCurrentUser.d.ts +2 -0
- package/dist/collections/user/index.d.ts +34 -1
- package/dist/collections/user/insert.d.ts +21 -1
- package/dist/collections/user/insert.js +59 -0
- package/dist/collections/user/insert.mjs +60 -1
- package/dist/functions/describe.d.ts +3 -2
- package/dist/functions/describe.js +7 -2
- package/dist/functions/describe.mjs +8 -3
- package/dist/index.d.ts +34 -1
- package/package.json +6 -6
|
@@ -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";
|
|
@@ -243,7 +247,26 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
243
247
|
} & {
|
|
244
248
|
httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
|
|
245
249
|
}>>;
|
|
246
|
-
readonly insert: (payload: NoInfer<import("@aeriajs/types").InsertPayload<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>>>, context: Omit<Context, "token">) => Promise<import("@aeriajs/types").
|
|
250
|
+
readonly insert: (payload: NoInfer<import("@aeriajs/types").InsertPayload<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>>>, context: Omit<Context, "token">) => Promise<import("@aeriajs/types").Result.Error<{
|
|
251
|
+
readonly code: import("@aeriajs/types").ACError.AuthorizationError;
|
|
252
|
+
readonly message: "user is not allowed to edit other users roles";
|
|
253
|
+
} & {
|
|
254
|
+
httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
|
|
255
|
+
}> | import("@aeriajs/types").Result.Error<{
|
|
256
|
+
readonly code: import("@aeriajs/types").ACError.AuthorizationError;
|
|
257
|
+
readonly message: "tried to set unallowed roles";
|
|
258
|
+
} & {
|
|
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;
|
|
269
|
+
}> | import("@aeriajs/types").InsertReturnType<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>>>;
|
|
247
270
|
readonly editProfile: (payload: Partial<import("@aeriajs/types").PackReferences<import("@aeriajs/types").SchemaWithId<{
|
|
248
271
|
readonly $id: "user";
|
|
249
272
|
readonly icon: "users";
|
|
@@ -254,6 +277,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
254
277
|
readonly properties: {
|
|
255
278
|
readonly name: {
|
|
256
279
|
readonly type: "string";
|
|
280
|
+
readonly minLength: 1;
|
|
257
281
|
};
|
|
258
282
|
readonly given_name: {
|
|
259
283
|
readonly getter: (doc: object) => string | undefined;
|
|
@@ -275,6 +299,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
275
299
|
readonly email: {
|
|
276
300
|
readonly type: "string";
|
|
277
301
|
readonly inputType: "email";
|
|
302
|
+
readonly minLength: 3;
|
|
278
303
|
};
|
|
279
304
|
readonly password: {
|
|
280
305
|
readonly type: "string";
|
|
@@ -356,6 +381,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
356
381
|
readonly properties: {
|
|
357
382
|
readonly name: {
|
|
358
383
|
readonly type: "string";
|
|
384
|
+
readonly minLength: 1;
|
|
359
385
|
};
|
|
360
386
|
readonly given_name: {
|
|
361
387
|
readonly getter: (doc: object) => string | undefined;
|
|
@@ -377,6 +403,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
377
403
|
readonly email: {
|
|
378
404
|
readonly type: "string";
|
|
379
405
|
readonly inputType: "email";
|
|
406
|
+
readonly minLength: 3;
|
|
380
407
|
};
|
|
381
408
|
readonly password: {
|
|
382
409
|
readonly type: "string";
|
|
@@ -533,6 +560,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
533
560
|
readonly properties: {
|
|
534
561
|
readonly name: {
|
|
535
562
|
readonly type: "string";
|
|
563
|
+
readonly minLength: 1;
|
|
536
564
|
};
|
|
537
565
|
readonly given_name: {
|
|
538
566
|
readonly getter: (doc: object) => string | undefined;
|
|
@@ -554,6 +582,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
554
582
|
readonly email: {
|
|
555
583
|
readonly type: "string";
|
|
556
584
|
readonly inputType: "email";
|
|
585
|
+
readonly minLength: 3;
|
|
557
586
|
};
|
|
558
587
|
readonly password: {
|
|
559
588
|
readonly type: "string";
|
|
@@ -648,6 +677,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
648
677
|
readonly properties: {
|
|
649
678
|
readonly name: {
|
|
650
679
|
readonly type: "string";
|
|
680
|
+
readonly minLength: 1;
|
|
651
681
|
};
|
|
652
682
|
readonly given_name: {
|
|
653
683
|
readonly getter: (doc: object) => string | undefined;
|
|
@@ -669,6 +699,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
669
699
|
readonly email: {
|
|
670
700
|
readonly type: "string";
|
|
671
701
|
readonly inputType: "email";
|
|
702
|
+
readonly minLength: 3;
|
|
672
703
|
};
|
|
673
704
|
readonly password: {
|
|
674
705
|
readonly type: "string";
|
|
@@ -788,6 +819,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
788
819
|
readonly properties: {
|
|
789
820
|
readonly name: {
|
|
790
821
|
readonly type: "string";
|
|
822
|
+
readonly minLength: 1;
|
|
791
823
|
};
|
|
792
824
|
readonly given_name: {
|
|
793
825
|
readonly getter: (doc: object) => string | undefined;
|
|
@@ -809,6 +841,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
809
841
|
readonly email: {
|
|
810
842
|
readonly type: "string";
|
|
811
843
|
readonly inputType: "email";
|
|
844
|
+
readonly minLength: 3;
|
|
812
845
|
};
|
|
813
846
|
readonly password: {
|
|
814
847
|
readonly type: "string";
|
|
@@ -1,2 +1,22 @@
|
|
|
1
1
|
import type { Context, SchemaWithId, InsertPayload, Description } from '@aeriajs/types';
|
|
2
|
-
|
|
2
|
+
import { HTTPStatus, ACError } from '@aeriajs/types';
|
|
3
|
+
export declare const insert: <TDescription extends Description, TInsertPayload extends InsertPayload<SchemaWithId<TDescription>>>(payload: NoInfer<TInsertPayload>, context: Context<TDescription>) => Promise<import("@aeriajs/types").Result.Error<{
|
|
4
|
+
readonly code: ACError.AuthorizationError;
|
|
5
|
+
readonly message: "user is not allowed to edit other users roles";
|
|
6
|
+
} & {
|
|
7
|
+
httpStatus: HTTPStatus.Forbidden;
|
|
8
|
+
}> | import("@aeriajs/types").Result.Error<{
|
|
9
|
+
readonly code: ACError.AuthorizationError;
|
|
10
|
+
readonly message: "tried to set unallowed roles";
|
|
11
|
+
} & {
|
|
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;
|
|
22
|
+
}> | import("@aeriajs/types").InsertReturnType<SchemaWithId<TDescription>>>;
|
|
@@ -1,9 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.insert = void 0;
|
|
4
|
+
const types_1 = require("@aeriajs/types");
|
|
5
|
+
const common_1 = require("@aeriajs/common");
|
|
4
6
|
const core_1 = require("@aeriajs/core");
|
|
5
7
|
const bcrypt = require("bcrypt");
|
|
8
|
+
const isRoleAllowed = (targetRole, context) => {
|
|
9
|
+
if (!context.config.security.rolesHierarchy || !context.token.authenticated) {
|
|
10
|
+
throw new Error;
|
|
11
|
+
}
|
|
12
|
+
for (const role of context.token.roles) {
|
|
13
|
+
if (role in context.config.security.rolesHierarchy) {
|
|
14
|
+
const hierarchy = context.config.security.rolesHierarchy[role];
|
|
15
|
+
if (!hierarchy) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (hierarchy === true || hierarchy.includes(targetRole)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
};
|
|
6
25
|
const insert = async (payload, context) => {
|
|
26
|
+
if (!context.token.authenticated) {
|
|
27
|
+
throw new Error;
|
|
28
|
+
}
|
|
29
|
+
if ('roles' in payload.what) {
|
|
30
|
+
if (context.config.security.rolesHierarchy) {
|
|
31
|
+
if (!(0, common_1.arraysIntersect)(context.token.roles, Object.keys(context.config.security.rolesHierarchy))) {
|
|
32
|
+
return context.error(types_1.HTTPStatus.Forbidden, {
|
|
33
|
+
code: types_1.ACError.AuthorizationError,
|
|
34
|
+
message: 'user is not allowed to edit other users roles',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (Array.isArray(payload.what.roles)) {
|
|
38
|
+
const allowed = payload.what.roles.every((role) => isRoleAllowed(role, context));
|
|
39
|
+
if (!allowed) {
|
|
40
|
+
return context.error(types_1.HTTPStatus.Forbidden, {
|
|
41
|
+
code: types_1.ACError.AuthorizationError,
|
|
42
|
+
message: 'tried to set unallowed roles',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
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
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
7
66
|
if ('password' in payload.what && typeof payload.what.password === 'string') {
|
|
8
67
|
payload.what.password = await bcrypt.hash(payload.what.password, 10);
|
|
9
68
|
}
|
|
@@ -1,7 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
2
|
+
import { HTTPStatus, ACError } from "@aeriajs/types";
|
|
3
|
+
import { arraysIntersect } from "@aeriajs/common";
|
|
4
|
+
import { ObjectId, insert as originalInsert } from "@aeriajs/core";
|
|
3
5
|
import * as bcrypt from "bcrypt";
|
|
6
|
+
const isRoleAllowed = (targetRole, context) => {
|
|
7
|
+
if (!context.config.security.rolesHierarchy || !context.token.authenticated) {
|
|
8
|
+
throw new Error();
|
|
9
|
+
}
|
|
10
|
+
for (const role of context.token.roles) {
|
|
11
|
+
if (role in context.config.security.rolesHierarchy) {
|
|
12
|
+
const hierarchy = context.config.security.rolesHierarchy[role];
|
|
13
|
+
if (!hierarchy) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (hierarchy === true || hierarchy.includes(targetRole)) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
};
|
|
4
23
|
export const insert = async (payload, context) => {
|
|
24
|
+
if (!context.token.authenticated) {
|
|
25
|
+
throw new Error();
|
|
26
|
+
}
|
|
27
|
+
if ("roles" in payload.what) {
|
|
28
|
+
if (context.config.security.rolesHierarchy) {
|
|
29
|
+
if (!arraysIntersect(context.token.roles, Object.keys(context.config.security.rolesHierarchy))) {
|
|
30
|
+
return context.error(HTTPStatus.Forbidden, {
|
|
31
|
+
code: ACError.AuthorizationError,
|
|
32
|
+
message: "user is not allowed to edit other users roles"
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(payload.what.roles)) {
|
|
36
|
+
const allowed = payload.what.roles.every((role) => isRoleAllowed(role, context));
|
|
37
|
+
if (!allowed) {
|
|
38
|
+
return context.error(HTTPStatus.Forbidden, {
|
|
39
|
+
code: ACError.AuthorizationError,
|
|
40
|
+
message: "tried to set unallowed roles"
|
|
41
|
+
});
|
|
42
|
+
}
|
|
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
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
5
64
|
if ("password" in payload.what && typeof payload.what.password === "string") {
|
|
6
65
|
payload.what.password = await bcrypt.hash(payload.what.password, 10);
|
|
7
66
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Description, RouteContext } from '@aeriajs/types';
|
|
1
|
+
import type { Description, RouteContext, RolesHierarchy, UserRole } from '@aeriajs/types';
|
|
2
2
|
import { Result, ACError, HTTPStatus } from '@aeriajs/types';
|
|
3
3
|
import { authenticate } from '../collections/user/authenticate.js';
|
|
4
4
|
declare const Payload: Partial<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
|
|
@@ -56,9 +56,10 @@ export declare const describe: (contextOrPayload: RouteContext | typeof Payload)
|
|
|
56
56
|
readonly error: undefined;
|
|
57
57
|
readonly result: {
|
|
58
58
|
descriptions: Record<string, Description>;
|
|
59
|
-
roles?:
|
|
59
|
+
roles?: UserRole[];
|
|
60
60
|
auth?: Awaited<ReturnType<typeof authenticate>> extends Result.Either<unknown, infer Right> ? Partial<Right> : never;
|
|
61
61
|
router?: unknown;
|
|
62
|
+
rolesHierarchy?: RolesHierarchy;
|
|
62
63
|
};
|
|
63
64
|
}>;
|
|
64
65
|
export {};
|
|
@@ -33,7 +33,9 @@ const [Payload, validatePayload] = (0, validation_1.validator)({
|
|
|
33
33
|
},
|
|
34
34
|
});
|
|
35
35
|
const describe = async (contextOrPayload) => {
|
|
36
|
-
const result = {
|
|
36
|
+
const result = {
|
|
37
|
+
descriptions: {},
|
|
38
|
+
};
|
|
37
39
|
let props;
|
|
38
40
|
if ('request' in contextOrPayload) {
|
|
39
41
|
const { error, result: validatedPayload } = validatePayload(contextOrPayload.request.payload);
|
|
@@ -72,7 +74,7 @@ const describe = async (contextOrPayload) => {
|
|
|
72
74
|
const collection = typeof candidate === 'function'
|
|
73
75
|
? candidate()
|
|
74
76
|
: candidate;
|
|
75
|
-
if (!(0,
|
|
77
|
+
if (!(0, common_1.isValidCollection)(collection)) {
|
|
76
78
|
throw new Error(`The "${collectionName}" symbol exported from the entrypoint doesn't seem like a valid collection. Make sure only collections are exported from the "import('.').collections".`);
|
|
77
79
|
}
|
|
78
80
|
const { description: rawDescription } = collection;
|
|
@@ -89,6 +91,9 @@ const describe = async (contextOrPayload) => {
|
|
|
89
91
|
? userRolesProperty.items.enum
|
|
90
92
|
: [];
|
|
91
93
|
result.roles = Array.from(new Set(userRoles.concat(await (0, entrypoint_1.getAvailableRoles)())));
|
|
94
|
+
if ('config' in contextOrPayload) {
|
|
95
|
+
result.rolesHierarchy = contextOrPayload.config.security.rolesHierarchy;
|
|
96
|
+
}
|
|
92
97
|
}
|
|
93
98
|
if (props.router) {
|
|
94
99
|
result.router = await (0, core_1.getEndpoints)();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { createContext, preloadDescription, getEndpoints
|
|
2
|
+
import { createContext, preloadDescription, getEndpoints } from "@aeriajs/core";
|
|
3
3
|
import { getCollections, getAvailableRoles } from "@aeriajs/entrypoint";
|
|
4
4
|
import { Result, ACError, HTTPStatus } from "@aeriajs/types";
|
|
5
|
-
import { serialize, endpointError } from "@aeriajs/common";
|
|
5
|
+
import { serialize, endpointError, isValidCollection } from "@aeriajs/common";
|
|
6
6
|
import { validator } from "@aeriajs/validation";
|
|
7
7
|
import { authenticate } from "../collections/user/authenticate.mjs";
|
|
8
8
|
const [Payload, validatePayload] = validator({
|
|
@@ -31,7 +31,9 @@ const [Payload, validatePayload] = validator({
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
export const describe = async (contextOrPayload) => {
|
|
34
|
-
const result = {
|
|
34
|
+
const result = {
|
|
35
|
+
descriptions: {}
|
|
36
|
+
};
|
|
35
37
|
let props;
|
|
36
38
|
if ("request" in contextOrPayload) {
|
|
37
39
|
const { error, result: validatedPayload } = validatePayload(contextOrPayload.request.payload);
|
|
@@ -78,6 +80,9 @@ export const describe = async (contextOrPayload) => {
|
|
|
78
80
|
const userRolesProperty = userCollection.description.properties.roles;
|
|
79
81
|
const userRoles = "enum" in userRolesProperty.items ? userRolesProperty.items.enum : [];
|
|
80
82
|
result.roles = Array.from(new Set(userRoles.concat(await getAvailableRoles())));
|
|
83
|
+
if ("config" in contextOrPayload) {
|
|
84
|
+
result.rolesHierarchy = contextOrPayload.config.security.rolesHierarchy;
|
|
85
|
+
}
|
|
81
86
|
}
|
|
82
87
|
if (props.router) {
|
|
83
88
|
result.router = await getEndpoints();
|
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";
|
|
@@ -707,7 +711,26 @@ export declare const collections: {
|
|
|
707
711
|
} & {
|
|
708
712
|
httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
|
|
709
713
|
}>>;
|
|
710
|
-
readonly insert: (payload: NoInfer<import("@aeriajs/types").InsertPayload<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>>>, context: Omit<import("@aeriajs/types").Context, "token">) => Promise<import("@aeriajs/types").
|
|
714
|
+
readonly insert: (payload: NoInfer<import("@aeriajs/types").InsertPayload<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>>>, context: Omit<import("@aeriajs/types").Context, "token">) => Promise<import("@aeriajs/types").Result.Error<{
|
|
715
|
+
readonly code: import("@aeriajs/types").ACError.AuthorizationError;
|
|
716
|
+
readonly message: "user is not allowed to edit other users roles";
|
|
717
|
+
} & {
|
|
718
|
+
httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
|
|
719
|
+
}> | import("@aeriajs/types").Result.Error<{
|
|
720
|
+
readonly code: import("@aeriajs/types").ACError.AuthorizationError;
|
|
721
|
+
readonly message: "tried to set unallowed roles";
|
|
722
|
+
} & {
|
|
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;
|
|
733
|
+
}> | import("@aeriajs/types").InsertReturnType<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>>>;
|
|
711
734
|
readonly editProfile: (payload: Partial<import("@aeriajs/types").PackReferences<import("@aeriajs/types").SchemaWithId<{
|
|
712
735
|
readonly $id: "user";
|
|
713
736
|
readonly icon: "users";
|
|
@@ -718,6 +741,7 @@ export declare const collections: {
|
|
|
718
741
|
readonly properties: {
|
|
719
742
|
readonly name: {
|
|
720
743
|
readonly type: "string";
|
|
744
|
+
readonly minLength: 1;
|
|
721
745
|
};
|
|
722
746
|
readonly given_name: {
|
|
723
747
|
readonly getter: (doc: object) => string | undefined;
|
|
@@ -739,6 +763,7 @@ export declare const collections: {
|
|
|
739
763
|
readonly email: {
|
|
740
764
|
readonly type: "string";
|
|
741
765
|
readonly inputType: "email";
|
|
766
|
+
readonly minLength: 3;
|
|
742
767
|
};
|
|
743
768
|
readonly password: {
|
|
744
769
|
readonly type: "string";
|
|
@@ -820,6 +845,7 @@ export declare const collections: {
|
|
|
820
845
|
readonly properties: {
|
|
821
846
|
readonly name: {
|
|
822
847
|
readonly type: "string";
|
|
848
|
+
readonly minLength: 1;
|
|
823
849
|
};
|
|
824
850
|
readonly given_name: {
|
|
825
851
|
readonly getter: (doc: object) => string | undefined;
|
|
@@ -841,6 +867,7 @@ export declare const collections: {
|
|
|
841
867
|
readonly email: {
|
|
842
868
|
readonly type: "string";
|
|
843
869
|
readonly inputType: "email";
|
|
870
|
+
readonly minLength: 3;
|
|
844
871
|
};
|
|
845
872
|
readonly password: {
|
|
846
873
|
readonly type: "string";
|
|
@@ -997,6 +1024,7 @@ export declare const collections: {
|
|
|
997
1024
|
readonly properties: {
|
|
998
1025
|
readonly name: {
|
|
999
1026
|
readonly type: "string";
|
|
1027
|
+
readonly minLength: 1;
|
|
1000
1028
|
};
|
|
1001
1029
|
readonly given_name: {
|
|
1002
1030
|
readonly getter: (doc: object) => string | undefined;
|
|
@@ -1018,6 +1046,7 @@ export declare const collections: {
|
|
|
1018
1046
|
readonly email: {
|
|
1019
1047
|
readonly type: "string";
|
|
1020
1048
|
readonly inputType: "email";
|
|
1049
|
+
readonly minLength: 3;
|
|
1021
1050
|
};
|
|
1022
1051
|
readonly password: {
|
|
1023
1052
|
readonly type: "string";
|
|
@@ -1112,6 +1141,7 @@ export declare const collections: {
|
|
|
1112
1141
|
readonly properties: {
|
|
1113
1142
|
readonly name: {
|
|
1114
1143
|
readonly type: "string";
|
|
1144
|
+
readonly minLength: 1;
|
|
1115
1145
|
};
|
|
1116
1146
|
readonly given_name: {
|
|
1117
1147
|
readonly getter: (doc: object) => string | undefined;
|
|
@@ -1133,6 +1163,7 @@ export declare const collections: {
|
|
|
1133
1163
|
readonly email: {
|
|
1134
1164
|
readonly type: "string";
|
|
1135
1165
|
readonly inputType: "email";
|
|
1166
|
+
readonly minLength: 3;
|
|
1136
1167
|
};
|
|
1137
1168
|
readonly password: {
|
|
1138
1169
|
readonly type: "string";
|
|
@@ -1252,6 +1283,7 @@ export declare const collections: {
|
|
|
1252
1283
|
readonly properties: {
|
|
1253
1284
|
readonly name: {
|
|
1254
1285
|
readonly type: "string";
|
|
1286
|
+
readonly minLength: 1;
|
|
1255
1287
|
};
|
|
1256
1288
|
readonly given_name: {
|
|
1257
1289
|
readonly getter: (doc: object) => string | undefined;
|
|
@@ -1273,6 +1305,7 @@ export declare const collections: {
|
|
|
1273
1305
|
readonly email: {
|
|
1274
1306
|
readonly type: "string";
|
|
1275
1307
|
readonly inputType: "email";
|
|
1308
|
+
readonly minLength: 3;
|
|
1276
1309
|
};
|
|
1277
1310
|
readonly password: {
|
|
1278
1311
|
readonly type: "string";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/builtins",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.230",
|
|
4
4
|
"description": "## Installation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"mongodb": "^6.5.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@aeriajs/core": "^0.0.
|
|
59
|
-
"@aeriajs/common": "^0.0.
|
|
60
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
61
|
-
"@aeriajs/types": "^0.0.
|
|
62
|
-
"@aeriajs/validation": "^0.0.
|
|
58
|
+
"@aeriajs/core": "^0.0.230",
|
|
59
|
+
"@aeriajs/common": "^0.0.131",
|
|
60
|
+
"@aeriajs/entrypoint": "^0.0.134",
|
|
61
|
+
"@aeriajs/types": "^0.0.113",
|
|
62
|
+
"@aeriajs/validation": "^0.0.146"
|
|
63
63
|
}
|
|
64
64
|
}
|