@aeriajs/builtins 0.0.226 → 0.0.228
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/activate.d.ts +2 -2
- package/dist/collections/user/activate.js +14 -17
- package/dist/collections/user/activate.mjs +11 -27
- package/dist/collections/user/authenticate.js +1 -0
- package/dist/collections/user/authenticate.mjs +2 -1
- package/dist/collections/user/editProfile.d.ts +1 -9
- package/dist/collections/user/editProfile.js +2 -12
- package/dist/collections/user/editProfile.mjs +7 -20
- package/dist/collections/user/getActivationLink.js +4 -2
- package/dist/collections/user/getActivationLink.mjs +4 -1
- package/dist/collections/user/index.d.ts +2 -10
- package/dist/index.d.ts +2 -10
- package/package.json +2 -2
|
@@ -12,7 +12,7 @@ export declare const activate: (payload: {
|
|
|
12
12
|
password?: string;
|
|
13
13
|
userId?: string;
|
|
14
14
|
token?: string;
|
|
15
|
-
}, context: Context<typeof description>) => Promise<
|
|
15
|
+
}, context: Context<typeof description>) => Promise<Result.Error<{
|
|
16
16
|
readonly code: ActivationError.InvalidLink;
|
|
17
17
|
} & {
|
|
18
18
|
httpStatus: HTTPStatus.NotFound;
|
|
@@ -38,4 +38,4 @@ export declare const activate: (payload: {
|
|
|
38
38
|
readonly result: {
|
|
39
39
|
readonly userId: ObjectId;
|
|
40
40
|
};
|
|
41
|
-
}
|
|
41
|
+
}>;
|
|
@@ -47,11 +47,6 @@ const activate = async (payload, context) => {
|
|
|
47
47
|
}
|
|
48
48
|
if (!user.password) {
|
|
49
49
|
if (!password) {
|
|
50
|
-
if (context.request.method === 'GET') {
|
|
51
|
-
return context.response.writeHead(302, {
|
|
52
|
-
location: `/user/activation?step=password&u=${userId}&t=${token}`,
|
|
53
|
-
}).end();
|
|
54
|
-
}
|
|
55
50
|
return context.error(types_1.HTTPStatus.UnprocessableContent, {
|
|
56
51
|
code: types_1.ACError.MalformedInput,
|
|
57
52
|
});
|
|
@@ -64,20 +59,22 @@ const activate = async (payload, context) => {
|
|
|
64
59
|
password: await bcrypt.hash(password, 10),
|
|
65
60
|
},
|
|
66
61
|
});
|
|
67
|
-
return;
|
|
68
62
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return context.response.writeHead(302, {
|
|
78
|
-
location: '/user/activation',
|
|
79
|
-
}).end();
|
|
63
|
+
else {
|
|
64
|
+
await context.collection.model.updateOne({
|
|
65
|
+
_id: user._id,
|
|
66
|
+
}, {
|
|
67
|
+
$set: {
|
|
68
|
+
active: true,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
80
71
|
}
|
|
72
|
+
// if( context.request.method === 'GET' ) {
|
|
73
|
+
// return context.response.writeHead(302, {
|
|
74
|
+
// location: '/user/activation',
|
|
75
|
+
// }).end()
|
|
76
|
+
// }
|
|
77
|
+
//
|
|
81
78
|
return types_1.Result.result({
|
|
82
79
|
userId: user._id,
|
|
83
80
|
});
|
|
@@ -49,42 +49,26 @@ export const activate = async (payload, context) => {
|
|
|
49
49
|
}
|
|
50
50
|
if (!user.password) {
|
|
51
51
|
if (!password) {
|
|
52
|
-
if (context.request.method === "GET") {
|
|
53
|
-
return context.response.writeHead(302, {
|
|
54
|
-
location: `/user/activation?step=password&u=${userId}&t=${token}`
|
|
55
|
-
}).end();
|
|
56
|
-
}
|
|
57
52
|
return context.error(HTTPStatus.UnprocessableContent, {
|
|
58
53
|
code: ACError.MalformedInput
|
|
59
54
|
});
|
|
60
55
|
}
|
|
61
|
-
await context.collection.model.updateOne(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
active: true,
|
|
68
|
-
password: await bcrypt.hash(password, 10)
|
|
69
|
-
}
|
|
56
|
+
await context.collection.model.updateOne({
|
|
57
|
+
_id: user._id
|
|
58
|
+
}, {
|
|
59
|
+
$set: {
|
|
60
|
+
active: true,
|
|
61
|
+
password: await bcrypt.hash(password, 10)
|
|
70
62
|
}
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
await context.collection.model.updateOne(
|
|
75
|
-
{
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
await context.collection.model.updateOne({
|
|
76
66
|
_id: user._id
|
|
77
|
-
},
|
|
78
|
-
{
|
|
67
|
+
}, {
|
|
79
68
|
$set: {
|
|
80
69
|
active: true
|
|
81
70
|
}
|
|
82
|
-
}
|
|
83
|
-
);
|
|
84
|
-
if (context.request.method === "GET") {
|
|
85
|
-
return context.response.writeHead(302, {
|
|
86
|
-
location: "/user/activation"
|
|
87
|
-
}).end();
|
|
71
|
+
});
|
|
88
72
|
}
|
|
89
73
|
return Result.result({
|
|
90
74
|
userId: user._id
|
|
@@ -18,7 +18,8 @@ export const authenticate = async (props, context) => {
|
|
|
18
18
|
}
|
|
19
19
|
const { error, result: user2 } = await context.collections.user.functions.get({
|
|
20
20
|
filters: {
|
|
21
|
-
_id: decodedToken.sub
|
|
21
|
+
_id: decodedToken.sub,
|
|
22
|
+
active: true
|
|
22
23
|
},
|
|
23
24
|
populate: ["picture_file"]
|
|
24
25
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { description } from './description.js';
|
|
1
2
|
import { HTTPStatus, ACError, type Context, type SchemaWithId, type PackReferences } from '@aeriajs/types';
|
|
2
|
-
import { type description } from './description.js';
|
|
3
3
|
export declare const editProfile: (payload: Partial<PackReferences<SchemaWithId<typeof description>>> & Record<string, unknown>, context: Context<typeof description>) => Promise<import("@aeriajs/types").InsertReturnType<SchemaWithId<{
|
|
4
4
|
readonly $id: "user";
|
|
5
5
|
readonly icon: "users";
|
|
@@ -103,14 +103,6 @@ export declare const editProfile: (payload: Partial<PackReferences<SchemaWithId<
|
|
|
103
103
|
};
|
|
104
104
|
};
|
|
105
105
|
}>> | import("@aeriajs/types").Result.Error<{
|
|
106
|
-
readonly code: ACError.MalformedInput;
|
|
107
|
-
} & {
|
|
108
|
-
httpStatus: HTTPStatus.BadRequest;
|
|
109
|
-
}> | import("@aeriajs/types").Result.Error<{
|
|
110
|
-
readonly code: ACError.AuthorizationError;
|
|
111
|
-
} & {
|
|
112
|
-
httpStatus: HTTPStatus.Unauthorized;
|
|
113
|
-
}> | import("@aeriajs/types").Result.Error<{
|
|
114
106
|
readonly code: ACError.TargetImmutable;
|
|
115
107
|
} & {
|
|
116
108
|
httpStatus: HTTPStatus.Forbidden;
|
|
@@ -6,19 +6,9 @@ const core_1 = require("@aeriajs/core");
|
|
|
6
6
|
const bcrypt = require("bcrypt");
|
|
7
7
|
const editProfile = async (payload, context) => {
|
|
8
8
|
const mutableProperties = context.config.security.mutableUserProperties;
|
|
9
|
-
if (!context.token.
|
|
9
|
+
if (!context.token.sub) {
|
|
10
10
|
throw new Error;
|
|
11
11
|
}
|
|
12
|
-
if (!payload._id) {
|
|
13
|
-
return context.error(types_1.HTTPStatus.BadRequest, {
|
|
14
|
-
code: types_1.ACError.MalformedInput,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
if (!context.token.sub.equals(payload._id)) {
|
|
18
|
-
return context.error(types_1.HTTPStatus.Unauthorized, {
|
|
19
|
-
code: types_1.ACError.AuthorizationError,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
12
|
const user = await context.collections.user.model.findOne({
|
|
23
13
|
_id: context.token.sub,
|
|
24
14
|
});
|
|
@@ -37,8 +27,8 @@ const editProfile = async (payload, context) => {
|
|
|
37
27
|
}
|
|
38
28
|
return (0, core_1.insert)({
|
|
39
29
|
what: {
|
|
40
|
-
_id: payload._id,
|
|
41
30
|
...payload,
|
|
31
|
+
_id: context.token.sub,
|
|
42
32
|
},
|
|
43
33
|
}, context);
|
|
44
34
|
};
|
|
@@ -4,19 +4,9 @@ import { insert as originalInsert } from "@aeriajs/core";
|
|
|
4
4
|
import * as bcrypt from "bcrypt";
|
|
5
5
|
export const editProfile = async (payload, context) => {
|
|
6
6
|
const mutableProperties = context.config.security.mutableUserProperties;
|
|
7
|
-
if (!context.token.
|
|
7
|
+
if (!context.token.sub) {
|
|
8
8
|
throw new Error();
|
|
9
9
|
}
|
|
10
|
-
if (!payload._id) {
|
|
11
|
-
return context.error(HTTPStatus.BadRequest, {
|
|
12
|
-
code: ACError.MalformedInput
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
if (!context.token.sub.equals(payload._id)) {
|
|
16
|
-
return context.error(HTTPStatus.Unauthorized, {
|
|
17
|
-
code: ACError.AuthorizationError
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
10
|
const user = await context.collections.user.model.findOne({
|
|
21
11
|
_id: context.token.sub
|
|
22
12
|
});
|
|
@@ -33,13 +23,10 @@ export const editProfile = async (payload, context) => {
|
|
|
33
23
|
code: ACError.TargetImmutable
|
|
34
24
|
});
|
|
35
25
|
}
|
|
36
|
-
return originalInsert(
|
|
37
|
-
{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
context
|
|
44
|
-
);
|
|
26
|
+
return originalInsert({
|
|
27
|
+
what: {
|
|
28
|
+
...payload,
|
|
29
|
+
_id: context.token.sub
|
|
30
|
+
}
|
|
31
|
+
}, context);
|
|
45
32
|
};
|
|
@@ -42,9 +42,11 @@ const getActivationLink = async (payload, context) => {
|
|
|
42
42
|
const activationToken = await (0, exports.getActivationToken)(payload.userId.toString(), context);
|
|
43
43
|
//const url = `${context.config.webPublicUrl}/user/activation?step=password&u=${payload.userId.toString()}&t=${activationToken}`
|
|
44
44
|
const url = new URL(`${context.config.webPublicUrl}/user/activation`);
|
|
45
|
-
url.searchParams.set('
|
|
46
|
-
url.searchParams.set('u', payload.userId.toString());
|
|
45
|
+
url.searchParams.set('u', payload.userId.toString());
|
|
47
46
|
url.searchParams.set('t', activationToken);
|
|
47
|
+
if (!user.password) {
|
|
48
|
+
url.searchParams.set('step', 'password');
|
|
49
|
+
}
|
|
48
50
|
if (payload.redirect) {
|
|
49
51
|
url.searchParams.set('next', payload.redirect);
|
|
50
52
|
}
|
|
@@ -38,8 +38,11 @@ export const getActivationLink = async (payload, context) => {
|
|
|
38
38
|
}
|
|
39
39
|
const activationToken = await getActivationToken(payload.userId.toString(), context);
|
|
40
40
|
const url = new URL(`${context.config.webPublicUrl}/user/activation`);
|
|
41
|
-
url.searchParams.set("
|
|
41
|
+
url.searchParams.set("u", payload.userId.toString());
|
|
42
42
|
url.searchParams.set("t", activationToken);
|
|
43
|
+
if (!user.password) {
|
|
44
|
+
url.searchParams.set("step", "password");
|
|
45
|
+
}
|
|
43
46
|
if (payload.redirect) {
|
|
44
47
|
url.searchParams.set("next", payload.redirect);
|
|
45
48
|
}
|
|
@@ -449,14 +449,6 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
449
449
|
};
|
|
450
450
|
};
|
|
451
451
|
}>> | import("@aeriajs/types").Result.Error<{
|
|
452
|
-
readonly code: import("@aeriajs/types").ACError.MalformedInput;
|
|
453
|
-
} & {
|
|
454
|
-
httpStatus: import("@aeriajs/types").HTTPStatus.BadRequest;
|
|
455
|
-
}> | import("@aeriajs/types").Result.Error<{
|
|
456
|
-
readonly code: import("@aeriajs/types").ACError.AuthorizationError;
|
|
457
|
-
} & {
|
|
458
|
-
httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
|
|
459
|
-
}> | import("@aeriajs/types").Result.Error<{
|
|
460
452
|
readonly code: import("@aeriajs/types").ACError.TargetImmutable;
|
|
461
453
|
} & {
|
|
462
454
|
httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
|
|
@@ -504,7 +496,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
504
496
|
password?: string;
|
|
505
497
|
userId?: string;
|
|
506
498
|
token?: string;
|
|
507
|
-
}, context: Omit<Context, "token">) => Promise<import("@aeriajs/types").
|
|
499
|
+
}, context: Omit<Context, "token">) => Promise<import("@aeriajs/types").Result.Error<{
|
|
508
500
|
readonly code: import("./activate.js").ActivationError.InvalidLink;
|
|
509
501
|
} & {
|
|
510
502
|
httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
|
|
@@ -530,7 +522,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
530
522
|
readonly result: {
|
|
531
523
|
readonly userId: import("@aeriajs/core").ObjectId;
|
|
532
524
|
};
|
|
533
|
-
}
|
|
525
|
+
}>;
|
|
534
526
|
readonly createAccount: (payload: Partial<import("@aeriajs/types").PackReferences<import("@aeriajs/types").SchemaWithId<{
|
|
535
527
|
readonly $id: "user";
|
|
536
528
|
readonly icon: "users";
|
package/dist/index.d.ts
CHANGED
|
@@ -913,14 +913,6 @@ export declare const collections: {
|
|
|
913
913
|
};
|
|
914
914
|
};
|
|
915
915
|
}>> | import("@aeriajs/types").Result.Error<{
|
|
916
|
-
readonly code: import("@aeriajs/types").ACError.MalformedInput;
|
|
917
|
-
} & {
|
|
918
|
-
httpStatus: import("@aeriajs/types").HTTPStatus.BadRequest;
|
|
919
|
-
}> | import("@aeriajs/types").Result.Error<{
|
|
920
|
-
readonly code: import("@aeriajs/types").ACError.AuthorizationError;
|
|
921
|
-
} & {
|
|
922
|
-
httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
|
|
923
|
-
}> | import("@aeriajs/types").Result.Error<{
|
|
924
916
|
readonly code: import("@aeriajs/types").ACError.TargetImmutable;
|
|
925
917
|
} & {
|
|
926
918
|
httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
|
|
@@ -968,7 +960,7 @@ export declare const collections: {
|
|
|
968
960
|
password?: string;
|
|
969
961
|
userId?: string;
|
|
970
962
|
token?: string;
|
|
971
|
-
}, context: Omit<import("@aeriajs/types").Context, "token">) => Promise<import("@aeriajs/types").
|
|
963
|
+
}, context: Omit<import("@aeriajs/types").Context, "token">) => Promise<import("@aeriajs/types").Result.Error<{
|
|
972
964
|
readonly code: import("./collections/user/activate.js").ActivationError.InvalidLink;
|
|
973
965
|
} & {
|
|
974
966
|
httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
|
|
@@ -994,7 +986,7 @@ export declare const collections: {
|
|
|
994
986
|
readonly result: {
|
|
995
987
|
readonly userId: import("mongodb").ObjectId;
|
|
996
988
|
};
|
|
997
|
-
}
|
|
989
|
+
}>;
|
|
998
990
|
readonly createAccount: (payload: Partial<import("@aeriajs/types").PackReferences<import("@aeriajs/types").SchemaWithId<{
|
|
999
991
|
readonly $id: "user";
|
|
1000
992
|
readonly icon: "users";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/builtins",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.228",
|
|
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.
|
|
58
|
+
"@aeriajs/core": "^0.0.228",
|
|
59
59
|
"@aeriajs/common": "^0.0.130",
|
|
60
60
|
"@aeriajs/entrypoint": "^0.0.133",
|
|
61
61
|
"@aeriajs/types": "^0.0.112",
|