@aeriajs/builtins 0.0.134 → 0.0.136
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/authentication.d.ts +4 -4
- package/dist/authentication.js +2 -11
- package/dist/authentication.mjs +1 -10
- package/dist/collections/file/index.d.ts +3 -0
- package/dist/collections/file/index.js +1 -0
- package/dist/collections/file/index.mjs +1 -0
- package/dist/collections/user/authenticate.js +11 -2
- package/dist/collections/user/authenticate.mjs +11 -2
- package/dist/index.d.ts +3 -0
- package/package.json +6 -6
package/dist/authentication.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { RouteContext, SchemaWithId, TokenRecipient } from '@aeriajs/types';
|
|
2
|
-
import type { ObjectId } from '@aeriajs/core';
|
|
3
2
|
import type { description } from './collections/user/description.js';
|
|
3
|
+
export type TokenableUser = Pick<SchemaWithId<typeof description>, '_id' | 'name' | 'email' | 'roles' | 'active'>;
|
|
4
4
|
export type SuccessfulAuthentication = {
|
|
5
|
-
user:
|
|
6
|
-
_id:
|
|
5
|
+
user: TokenableUser & {
|
|
6
|
+
_id: null;
|
|
7
7
|
};
|
|
8
8
|
token: TokenRecipient;
|
|
9
9
|
};
|
|
@@ -11,7 +11,7 @@ export declare enum AuthenticationError {
|
|
|
11
11
|
InvalidCredentials = "INVALID_CREDENTIALS",
|
|
12
12
|
InactiveUser = "INACTIVE_USER"
|
|
13
13
|
}
|
|
14
|
-
export declare const successfulAuthentication: (
|
|
14
|
+
export declare const successfulAuthentication: <TUser extends TokenableUser>(user: TUser, context: RouteContext) => Promise<SuccessfulAuthentication>;
|
|
15
15
|
export declare const defaultSuccessfulAuthentication: () => Promise<{
|
|
16
16
|
user: {
|
|
17
17
|
_id: null;
|
package/dist/authentication.js
CHANGED
|
@@ -7,16 +7,7 @@ var AuthenticationError;
|
|
|
7
7
|
AuthenticationError["InvalidCredentials"] = "INVALID_CREDENTIALS";
|
|
8
8
|
AuthenticationError["InactiveUser"] = "INACTIVE_USER";
|
|
9
9
|
})(AuthenticationError || (exports.AuthenticationError = AuthenticationError = {}));
|
|
10
|
-
const successfulAuthentication = async (
|
|
11
|
-
const { error, result: user } = await context.collections.user.functions.get({
|
|
12
|
-
filters: {
|
|
13
|
-
_id: userId,
|
|
14
|
-
},
|
|
15
|
-
populate: ['picture_file'],
|
|
16
|
-
});
|
|
17
|
-
if (error) {
|
|
18
|
-
throw new Error();
|
|
19
|
-
}
|
|
10
|
+
const successfulAuthentication = async (user, context) => {
|
|
20
11
|
const tokenContent = {
|
|
21
12
|
sub: user._id,
|
|
22
13
|
roles: user.roles,
|
|
@@ -46,7 +37,7 @@ const successfulAuthentication = async (userId, context) => {
|
|
|
46
37
|
}
|
|
47
38
|
const token = await (0, core_1.signToken)(tokenContent);
|
|
48
39
|
return {
|
|
49
|
-
user
|
|
40
|
+
user,
|
|
50
41
|
token: {
|
|
51
42
|
type: 'bearer',
|
|
52
43
|
content: token,
|
package/dist/authentication.mjs
CHANGED
|
@@ -5,16 +5,7 @@ export var AuthenticationError = /* @__PURE__ */ ((AuthenticationError2) => {
|
|
|
5
5
|
AuthenticationError2["InactiveUser"] = "INACTIVE_USER";
|
|
6
6
|
return AuthenticationError2;
|
|
7
7
|
})(AuthenticationError || {});
|
|
8
|
-
export const successfulAuthentication = async (
|
|
9
|
-
const { error, result: user } = await context.collections.user.functions.get({
|
|
10
|
-
filters: {
|
|
11
|
-
_id: userId
|
|
12
|
-
},
|
|
13
|
-
populate: ["picture_file"]
|
|
14
|
-
});
|
|
15
|
-
if (error) {
|
|
16
|
-
throw new Error();
|
|
17
|
-
}
|
|
8
|
+
export const successfulAuthentication = async (user, context) => {
|
|
18
9
|
const tokenContent = {
|
|
19
10
|
sub: user._id,
|
|
20
11
|
roles: user.roles,
|
|
@@ -3,6 +3,7 @@ export declare const tempFile: Omit<import("@aeriajs/types").Collection<{
|
|
|
3
3
|
description: {
|
|
4
4
|
readonly $id: "tempFile";
|
|
5
5
|
readonly icon: "file";
|
|
6
|
+
readonly hidden: true;
|
|
6
7
|
readonly temporary: {
|
|
7
8
|
readonly index: "created_at";
|
|
8
9
|
readonly expireAfterSeconds: 3600;
|
|
@@ -33,6 +34,7 @@ export declare const tempFile: Omit<import("@aeriajs/types").Collection<{
|
|
|
33
34
|
item: import("@aeriajs/types").SchemaWithId<{
|
|
34
35
|
readonly $id: "tempFile";
|
|
35
36
|
readonly icon: "file";
|
|
37
|
+
readonly hidden: true;
|
|
36
38
|
readonly temporary: {
|
|
37
39
|
readonly index: "created_at";
|
|
38
40
|
readonly expireAfterSeconds: 3600;
|
|
@@ -62,6 +64,7 @@ export declare const tempFile: Omit<import("@aeriajs/types").Collection<{
|
|
|
62
64
|
description: {
|
|
63
65
|
readonly $id: "tempFile";
|
|
64
66
|
readonly icon: "file";
|
|
67
|
+
readonly hidden: true;
|
|
65
68
|
readonly temporary: {
|
|
66
69
|
readonly index: "created_at";
|
|
67
70
|
readonly expireAfterSeconds: 3600;
|
|
@@ -16,8 +16,17 @@ const authenticate = async (props, context) => {
|
|
|
16
16
|
const decodedToken = token
|
|
17
17
|
? await (0, core_1.decodeToken)(token.content)
|
|
18
18
|
: context.token;
|
|
19
|
+
const { error, result: user } = await context.collections.user.functions.get({
|
|
20
|
+
filters: {
|
|
21
|
+
_id: decodedToken.sub,
|
|
22
|
+
},
|
|
23
|
+
populate: ['picture_file'],
|
|
24
|
+
});
|
|
25
|
+
if (error) {
|
|
26
|
+
throw new Error();
|
|
27
|
+
}
|
|
19
28
|
return types_1.Result.result(decodedToken.sub
|
|
20
|
-
? await (0, authentication_js_1.successfulAuthentication)(
|
|
29
|
+
? await (0, authentication_js_1.successfulAuthentication)(user, context)
|
|
21
30
|
: await (0, authentication_js_1.defaultSuccessfulAuthentication)());
|
|
22
31
|
}
|
|
23
32
|
if (typeof props.email !== 'string') {
|
|
@@ -49,6 +58,6 @@ const authenticate = async (props, context) => {
|
|
|
49
58
|
code: authentication_js_1.AuthenticationError.InactiveUser,
|
|
50
59
|
});
|
|
51
60
|
}
|
|
52
|
-
return types_1.Result.result(await (0, authentication_js_1.successfulAuthentication)(user
|
|
61
|
+
return types_1.Result.result(await (0, authentication_js_1.successfulAuthentication)(user, context));
|
|
53
62
|
};
|
|
54
63
|
exports.authenticate = authenticate;
|
|
@@ -12,7 +12,16 @@ export const authenticate = async (props, context) => {
|
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
const decodedToken = token ? await decodeToken(token.content) : context.token;
|
|
15
|
-
|
|
15
|
+
const { error, result: user2 } = await context.collections.user.functions.get({
|
|
16
|
+
filters: {
|
|
17
|
+
_id: decodedToken.sub
|
|
18
|
+
},
|
|
19
|
+
populate: ["picture_file"]
|
|
20
|
+
});
|
|
21
|
+
if (error) {
|
|
22
|
+
throw new Error();
|
|
23
|
+
}
|
|
24
|
+
return Result.result(decodedToken.sub ? await successfulAuthentication(user2, context) : await defaultSuccessfulAuthentication());
|
|
16
25
|
}
|
|
17
26
|
if (typeof props.email !== "string") {
|
|
18
27
|
return context.error(HTTPStatus.Unauthorized, {
|
|
@@ -46,5 +55,5 @@ export const authenticate = async (props, context) => {
|
|
|
46
55
|
code: AuthenticationError.InactiveUser
|
|
47
56
|
});
|
|
48
57
|
}
|
|
49
|
-
return Result.result(await successfulAuthentication(user
|
|
58
|
+
return Result.result(await successfulAuthentication(user, context));
|
|
50
59
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -352,6 +352,7 @@ export declare const collections: {
|
|
|
352
352
|
description: {
|
|
353
353
|
readonly $id: "tempFile";
|
|
354
354
|
readonly icon: "file";
|
|
355
|
+
readonly hidden: true;
|
|
355
356
|
readonly temporary: {
|
|
356
357
|
readonly index: "created_at";
|
|
357
358
|
readonly expireAfterSeconds: 3600;
|
|
@@ -382,6 +383,7 @@ export declare const collections: {
|
|
|
382
383
|
item: import("@aeriajs/types").SchemaWithId<{
|
|
383
384
|
readonly $id: "tempFile";
|
|
384
385
|
readonly icon: "file";
|
|
386
|
+
readonly hidden: true;
|
|
385
387
|
readonly temporary: {
|
|
386
388
|
readonly index: "created_at";
|
|
387
389
|
readonly expireAfterSeconds: 3600;
|
|
@@ -411,6 +413,7 @@ export declare const collections: {
|
|
|
411
413
|
description: {
|
|
412
414
|
readonly $id: "tempFile";
|
|
413
415
|
readonly icon: "file";
|
|
416
|
+
readonly hidden: true;
|
|
414
417
|
readonly temporary: {
|
|
415
418
|
readonly index: "created_at";
|
|
416
419
|
readonly expireAfterSeconds: 3600;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/builtins",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.136",
|
|
4
4
|
"description": "## Installation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"mongodb": "^6.5.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@aeriajs/core": "^0.0.
|
|
49
|
-
"@aeriajs/common": "^0.0.
|
|
50
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
51
|
-
"@aeriajs/types": "^0.0.
|
|
52
|
-
"@aeriajs/validation": "^0.0.
|
|
48
|
+
"@aeriajs/core": "^0.0.136",
|
|
49
|
+
"@aeriajs/common": "^0.0.85",
|
|
50
|
+
"@aeriajs/entrypoint": "^0.0.87",
|
|
51
|
+
"@aeriajs/types": "^0.0.73",
|
|
52
|
+
"@aeriajs/validation": "^0.0.88"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"test": "echo skipping",
|