@aeriajs/builtins 0.0.277 → 0.0.278
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.js +6 -11
- package/dist/collections/file/description.js +10 -14
- package/dist/collections/file/download.js +21 -25
- package/dist/collections/file/index.js +15 -18
- package/dist/collections/file/insert.js +8 -12
- package/dist/collections/file/remove.js +7 -11
- package/dist/collections/file/removeAll.js +5 -9
- package/dist/collections/index.js +4 -20
- package/dist/collections/log/index.js +5 -8
- package/dist/collections/resourceUsage/index.js +2 -5
- package/dist/collections/user/activate.js +31 -35
- package/dist/collections/user/authenticate.js +29 -33
- package/dist/collections/user/createAccount.js +25 -29
- package/dist/collections/user/description.js +5 -8
- package/dist/collections/user/editProfile.js +12 -16
- package/dist/collections/user/getActivationLink.js +21 -26
- package/dist/collections/user/getCurrentUser.js +12 -16
- package/dist/collections/user/getInfo.js +22 -26
- package/dist/collections/user/getRedefinePasswordLink.js +15 -19
- package/dist/collections/user/index.d.ts +10 -10
- package/dist/collections/user/index.js +39 -42
- package/dist/collections/user/insert.js +16 -20
- package/dist/collections/user/redefinePassword.js +31 -35
- package/dist/functions/describe.js +21 -25
- package/dist/functions/index.js +1 -17
- package/dist/index.d.ts +15 -15
- package/dist/index.js +11 -29
- package/package.json +11 -17
- package/dist/authentication.mjs +0 -58
- package/dist/collections/file/description.mjs +0 -75
- package/dist/collections/file/download.mjs +0 -115
- package/dist/collections/file/index.mjs +0 -59
- package/dist/collections/file/insert.mjs +0 -44
- package/dist/collections/file/remove.mjs +0 -21
- package/dist/collections/file/removeAll.mjs +0 -22
- package/dist/collections/index.mjs +0 -5
- package/dist/collections/log/index.mjs +0 -55
- package/dist/collections/resourceUsage/index.mjs +0 -39
- package/dist/collections/user/activate.mjs +0 -119
- package/dist/collections/user/authenticate.mjs +0 -165
- package/dist/collections/user/createAccount.mjs +0 -93
- package/dist/collections/user/description.mjs +0 -149
- package/dist/collections/user/editProfile.mjs +0 -52
- package/dist/collections/user/getActivationLink.mjs +0 -88
- package/dist/collections/user/getCurrentUser.mjs +0 -57
- package/dist/collections/user/getInfo.mjs +0 -85
- package/dist/collections/user/getRedefinePasswordLink.mjs +0 -63
- package/dist/collections/user/index.mjs +0 -71
- package/dist/collections/user/insert.mjs +0 -70
- package/dist/collections/user/redefinePassword.mjs +0 -110
- package/dist/functions/describe.mjs +0 -95
- package/dist/functions/index.mjs +0 -2
- package/dist/index.mjs +0 -21
|
@@ -1,47 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const core_1 = require("@aeriajs/core");
|
|
8
|
-
const description_js_1 = require("./description.js");
|
|
9
|
-
exports.CreateAccountError = {
|
|
1
|
+
import { defineContract, HTTPStatus, ACError, functionSchemas, endpointErrorSchema, resultSchema } from '@aeriajs/types';
|
|
2
|
+
import { validate } from '@aeriajs/validation';
|
|
3
|
+
import * as bcrypt from 'bcryptjs';
|
|
4
|
+
import { insert as originalInsert } from '@aeriajs/core';
|
|
5
|
+
import { description } from './description.js';
|
|
6
|
+
export const CreateAccountError = {
|
|
10
7
|
SignupDisallowed: 'SIGNUP_DISALLOWED',
|
|
11
8
|
};
|
|
12
|
-
|
|
9
|
+
export const createAccountContract = defineContract({
|
|
13
10
|
payload: {
|
|
14
11
|
type: 'object',
|
|
15
12
|
required: [],
|
|
16
13
|
additionalProperties: true,
|
|
17
|
-
properties:
|
|
14
|
+
properties: description.properties,
|
|
18
15
|
},
|
|
19
16
|
response: [
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
functionSchemas.insertError(),
|
|
18
|
+
endpointErrorSchema({
|
|
22
19
|
httpStatus: [
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
HTTPStatus.Forbidden,
|
|
21
|
+
HTTPStatus.UnprocessableContent,
|
|
25
22
|
],
|
|
26
23
|
code: [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
ACError.MalformedInput,
|
|
25
|
+
ACError.OwnershipError,
|
|
26
|
+
CreateAccountError.SignupDisallowed,
|
|
30
27
|
],
|
|
31
28
|
}),
|
|
32
|
-
|
|
29
|
+
resultSchema({
|
|
33
30
|
$ref: 'user',
|
|
34
31
|
}),
|
|
35
32
|
],
|
|
36
33
|
});
|
|
37
|
-
const createAccount = async (payload, context) => {
|
|
34
|
+
export const createAccount = async (payload, context) => {
|
|
38
35
|
const userCandidate = Object.assign({}, payload);
|
|
39
36
|
if (!context.config.security.allowSignup) {
|
|
40
|
-
return context.error(
|
|
41
|
-
code:
|
|
37
|
+
return context.error(HTTPStatus.Forbidden, {
|
|
38
|
+
code: CreateAccountError.SignupDisallowed,
|
|
42
39
|
});
|
|
43
40
|
}
|
|
44
|
-
const { error, result: user } =
|
|
41
|
+
const { error, result: user } = validate(userCandidate, {
|
|
45
42
|
type: 'object',
|
|
46
43
|
required: [
|
|
47
44
|
'name',
|
|
@@ -60,8 +57,8 @@ const createAccount = async (payload, context) => {
|
|
|
60
57
|
},
|
|
61
58
|
});
|
|
62
59
|
if (error) {
|
|
63
|
-
return context.error(
|
|
64
|
-
code:
|
|
60
|
+
return context.error(HTTPStatus.UnprocessableContent, {
|
|
61
|
+
code: ACError.MalformedInput,
|
|
65
62
|
details: error,
|
|
66
63
|
});
|
|
67
64
|
}
|
|
@@ -76,8 +73,8 @@ const createAccount = async (payload, context) => {
|
|
|
76
73
|
email: user.email,
|
|
77
74
|
});
|
|
78
75
|
if (userWithExistingEmail) {
|
|
79
|
-
return context.error(
|
|
80
|
-
code:
|
|
76
|
+
return context.error(HTTPStatus.Forbidden, {
|
|
77
|
+
code: ACError.OwnershipError,
|
|
81
78
|
});
|
|
82
79
|
}
|
|
83
80
|
if (!context.token.authenticated) {
|
|
@@ -85,7 +82,7 @@ const createAccount = async (payload, context) => {
|
|
|
85
82
|
self_registered: true,
|
|
86
83
|
});
|
|
87
84
|
}
|
|
88
|
-
return (
|
|
85
|
+
return originalInsert({
|
|
89
86
|
what: {
|
|
90
87
|
...user,
|
|
91
88
|
...defaults,
|
|
@@ -93,4 +90,3 @@ const createAccount = async (payload, context) => {
|
|
|
93
90
|
},
|
|
94
91
|
}, context);
|
|
95
92
|
};
|
|
96
|
-
exports.createAccount = createAccount;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.description = void 0;
|
|
4
|
-
const core_1 = require("@aeriajs/core");
|
|
5
|
-
const description_js_1 = require("../file/description.js");
|
|
1
|
+
import { defineDescription, ObjectId } from '@aeriajs/core';
|
|
2
|
+
import { getFileLink } from '../file/description.js';
|
|
6
3
|
/**
|
|
7
4
|
* This description complies with JWT claims specified in RFC-7519.
|
|
8
5
|
* Reference: https://www.iana.org/assignments/jwt/jwt.xhtml#claims
|
|
9
6
|
*/
|
|
10
|
-
|
|
7
|
+
export const description = defineDescription({
|
|
11
8
|
$id: 'user',
|
|
12
9
|
icon: 'users',
|
|
13
10
|
required: [
|
|
@@ -78,8 +75,8 @@ exports.description = (0, core_1.defineDescription)({
|
|
|
78
75
|
picture: {
|
|
79
76
|
type: 'getter',
|
|
80
77
|
getter: (doc) => {
|
|
81
|
-
if ('picture_file' in doc && doc.picture_file && typeof doc.picture_file === 'object' && '_id' in doc.picture_file && doc.picture_file._id instanceof
|
|
82
|
-
return
|
|
78
|
+
if ('picture_file' in doc && doc.picture_file && typeof doc.picture_file === 'object' && '_id' in doc.picture_file && doc.picture_file._id instanceof ObjectId) {
|
|
79
|
+
return getFileLink(doc.picture_file._id);
|
|
83
80
|
}
|
|
84
81
|
},
|
|
85
82
|
},
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const bcrypt = require("bcryptjs");
|
|
7
|
-
const description_js_1 = require("./description.js");
|
|
8
|
-
exports.editProfileContract = (0, types_1.defineContract)({
|
|
1
|
+
import { HTTPStatus, ACError, defineContract, functionSchemas, resultSchema } from '@aeriajs/types';
|
|
2
|
+
import { insert as originalInsert } from '@aeriajs/core';
|
|
3
|
+
import * as bcrypt from 'bcryptjs';
|
|
4
|
+
import { description } from './description.js';
|
|
5
|
+
export const editProfileContract = defineContract({
|
|
9
6
|
payload: {
|
|
10
7
|
type: 'object',
|
|
11
8
|
required: [],
|
|
12
9
|
properties: {
|
|
13
|
-
...
|
|
10
|
+
...description.properties,
|
|
14
11
|
picture_file: {
|
|
15
12
|
type: 'string',
|
|
16
13
|
format: 'objectid',
|
|
@@ -18,13 +15,13 @@ exports.editProfileContract = (0, types_1.defineContract)({
|
|
|
18
15
|
},
|
|
19
16
|
},
|
|
20
17
|
response: [
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
functionSchemas.insertError(),
|
|
19
|
+
resultSchema({
|
|
23
20
|
$ref: 'user',
|
|
24
21
|
}),
|
|
25
22
|
],
|
|
26
23
|
});
|
|
27
|
-
const editProfile = async (payload, context) => {
|
|
24
|
+
export const editProfile = async (payload, context) => {
|
|
28
25
|
const mutableProperties = context.config.security.mutableUserProperties;
|
|
29
26
|
if (!context.token.sub) {
|
|
30
27
|
throw new Error;
|
|
@@ -41,15 +38,14 @@ const editProfile = async (payload, context) => {
|
|
|
41
38
|
const whatPropKeyArray = Object.keys(payload).filter((prop) => prop !== '_id');
|
|
42
39
|
const hasImmutableProps = whatPropKeyArray.some((prop) => !(mutableProperties.includes(prop)));
|
|
43
40
|
if (hasImmutableProps) {
|
|
44
|
-
return context.error(
|
|
45
|
-
code:
|
|
41
|
+
return context.error(HTTPStatus.Forbidden, {
|
|
42
|
+
code: ACError.TargetImmutable,
|
|
46
43
|
});
|
|
47
44
|
}
|
|
48
|
-
return (
|
|
45
|
+
return originalInsert({
|
|
49
46
|
what: {
|
|
50
47
|
...payload,
|
|
51
48
|
_id: context.token.sub,
|
|
52
49
|
},
|
|
53
50
|
}, context);
|
|
54
51
|
};
|
|
55
|
-
exports.editProfile = editProfile;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const types_1 = require("@aeriajs/types");
|
|
6
|
-
const activate_js_1 = require("./activate.js");
|
|
7
|
-
exports.getActivationLinkContract = (0, types_1.defineContract)({
|
|
1
|
+
import { signToken } from '@aeriajs/core';
|
|
2
|
+
import { Result, HTTPStatus, defineContract, resultSchema, endpointErrorSchema, functionSchemas } from '@aeriajs/types';
|
|
3
|
+
import { ActivationError } from './activate.js';
|
|
4
|
+
export const getActivationLinkContract = defineContract({
|
|
8
5
|
payload: {
|
|
9
6
|
type: 'object',
|
|
10
7
|
required: ['userId'],
|
|
@@ -19,18 +16,18 @@ exports.getActivationLinkContract = (0, types_1.defineContract)({
|
|
|
19
16
|
},
|
|
20
17
|
},
|
|
21
18
|
response: [
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
functionSchemas.getError(),
|
|
20
|
+
endpointErrorSchema({
|
|
24
21
|
httpStatus: [
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
HTTPStatus.BadRequest,
|
|
23
|
+
HTTPStatus.Forbidden,
|
|
27
24
|
],
|
|
28
25
|
code: [
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
ActivationError.InvalidLink,
|
|
27
|
+
ActivationError.AlreadyActiveUser,
|
|
31
28
|
],
|
|
32
29
|
}),
|
|
33
|
-
|
|
30
|
+
resultSchema({
|
|
34
31
|
type: 'object',
|
|
35
32
|
properties: {
|
|
36
33
|
url: {
|
|
@@ -40,25 +37,24 @@ exports.getActivationLinkContract = (0, types_1.defineContract)({
|
|
|
40
37
|
}),
|
|
41
38
|
],
|
|
42
39
|
});
|
|
43
|
-
const getActivationToken = async (userId, context) => {
|
|
40
|
+
export const getActivationToken = async (userId, context) => {
|
|
44
41
|
if (context.calledFunction === 'getActivationToken') {
|
|
45
42
|
throw new Error('cannot be called externally');
|
|
46
43
|
}
|
|
47
44
|
if (!context.config.secret) {
|
|
48
45
|
throw new Error('config.secret is not set');
|
|
49
46
|
}
|
|
50
|
-
const token = await
|
|
47
|
+
const token = await signToken({
|
|
51
48
|
data: userId,
|
|
52
49
|
}, context.config.secret, {
|
|
53
50
|
expiresIn: context.config.security.linkTokenExpiration,
|
|
54
51
|
});
|
|
55
52
|
return token;
|
|
56
53
|
};
|
|
57
|
-
|
|
58
|
-
const getActivationLink = async (payload, context) => {
|
|
54
|
+
export const getActivationLink = async (payload, context) => {
|
|
59
55
|
if (!context.config.webPublicUrl) {
|
|
60
|
-
return context.error(
|
|
61
|
-
code:
|
|
56
|
+
return context.error(HTTPStatus.BadRequest, {
|
|
57
|
+
code: ActivationError.InvalidLink,
|
|
62
58
|
});
|
|
63
59
|
}
|
|
64
60
|
const { error, result: user } = await context.collections.user.functions.get({
|
|
@@ -68,14 +64,14 @@ const getActivationLink = async (payload, context) => {
|
|
|
68
64
|
project: ['active'],
|
|
69
65
|
});
|
|
70
66
|
if (error) {
|
|
71
|
-
return
|
|
67
|
+
return Result.error(error);
|
|
72
68
|
}
|
|
73
69
|
if (user.active) {
|
|
74
|
-
return context.error(
|
|
75
|
-
code:
|
|
70
|
+
return context.error(HTTPStatus.Forbidden, {
|
|
71
|
+
code: ActivationError.AlreadyActiveUser,
|
|
76
72
|
});
|
|
77
73
|
}
|
|
78
|
-
const activationToken = await
|
|
74
|
+
const activationToken = await getActivationToken(payload.userId.toString(), context);
|
|
79
75
|
const url = new URL(`${context.config.webPublicUrl}/user/activation`);
|
|
80
76
|
url.searchParams.set('u', payload.userId.toString());
|
|
81
77
|
url.searchParams.set('t', activationToken);
|
|
@@ -85,8 +81,7 @@ const getActivationLink = async (payload, context) => {
|
|
|
85
81
|
if (payload.redirect) {
|
|
86
82
|
url.searchParams.set('next', payload.redirect);
|
|
87
83
|
}
|
|
88
|
-
return
|
|
84
|
+
return Result.result({
|
|
89
85
|
url: url.toString(),
|
|
90
86
|
});
|
|
91
87
|
};
|
|
92
|
-
exports.getActivationLink = getActivationLink;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const core_1 = require("@aeriajs/core");
|
|
6
|
-
const authentication_js_1 = require("../../authentication.js");
|
|
7
|
-
exports.ActivationError = {
|
|
1
|
+
import { Result, defineContract, resultSchema } from '@aeriajs/types';
|
|
2
|
+
import { get } from '@aeriajs/core';
|
|
3
|
+
import { defaultSuccessfulAuthentication } from '../../authentication.js';
|
|
4
|
+
export const ActivationError = {
|
|
8
5
|
UserNotFound: 'USER_NOT_FOUND',
|
|
9
6
|
AlreadyActiveUser: 'ALREADY_ACTIVE_USER',
|
|
10
7
|
InvalidLink: 'INVALID_LINK',
|
|
11
8
|
};
|
|
12
|
-
|
|
9
|
+
export const getCurrentUserContract = defineContract({
|
|
13
10
|
response: [
|
|
14
|
-
|
|
11
|
+
resultSchema({
|
|
15
12
|
$ref: 'user',
|
|
16
13
|
}),
|
|
17
|
-
|
|
14
|
+
resultSchema({
|
|
18
15
|
type: 'object',
|
|
19
16
|
properties: {
|
|
20
17
|
_id: {
|
|
@@ -39,15 +36,15 @@ exports.getCurrentUserContract = (0, types_1.defineContract)({
|
|
|
39
36
|
}),
|
|
40
37
|
],
|
|
41
38
|
});
|
|
42
|
-
const getCurrentUser = async (_payload, context) => {
|
|
39
|
+
export const getCurrentUser = async (_payload, context) => {
|
|
43
40
|
if (!context.token.authenticated) {
|
|
44
41
|
throw new Error();
|
|
45
42
|
}
|
|
46
43
|
if (!context.token.sub) {
|
|
47
|
-
const { user } = await
|
|
48
|
-
return
|
|
44
|
+
const { user } = await defaultSuccessfulAuthentication();
|
|
45
|
+
return Result.result(user);
|
|
49
46
|
}
|
|
50
|
-
const { error, result: user } = await
|
|
47
|
+
const { error, result: user } = await get({
|
|
51
48
|
filters: {
|
|
52
49
|
_id: context.token.sub,
|
|
53
50
|
},
|
|
@@ -55,6 +52,5 @@ const getCurrentUser = async (_payload, context) => {
|
|
|
55
52
|
if (error) {
|
|
56
53
|
throw new Error();
|
|
57
54
|
}
|
|
58
|
-
return
|
|
55
|
+
return Result.result(user);
|
|
59
56
|
};
|
|
60
|
-
exports.getCurrentUser = getCurrentUser;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const types_1 = require("@aeriajs/types");
|
|
5
|
-
const core_1 = require("@aeriajs/core");
|
|
6
|
-
exports.ActivationError = {
|
|
1
|
+
import { Result, HTTPStatus, defineContract, resultSchema, endpointErrorSchema } from '@aeriajs/types';
|
|
2
|
+
import { decodeToken, ObjectId } from '@aeriajs/core';
|
|
3
|
+
export const ActivationError = {
|
|
7
4
|
UserNotFound: 'USER_NOT_FOUND',
|
|
8
5
|
AlreadyActiveUser: 'ALREADY_ACTIVE_USER',
|
|
9
6
|
InvalidLink: 'INVALID_LINK',
|
|
10
7
|
InvalidToken: 'INVALID_TOKEN',
|
|
11
8
|
};
|
|
12
|
-
|
|
9
|
+
export const getInfoContract = defineContract({
|
|
13
10
|
payload: {
|
|
14
11
|
type: 'object',
|
|
15
12
|
required: [],
|
|
@@ -23,19 +20,19 @@ exports.getInfoContract = (0, types_1.defineContract)({
|
|
|
23
20
|
},
|
|
24
21
|
},
|
|
25
22
|
response: [
|
|
26
|
-
|
|
23
|
+
endpointErrorSchema({
|
|
27
24
|
httpStatus: [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
HTTPStatus.NotFound,
|
|
26
|
+
HTTPStatus.Unauthorized,
|
|
27
|
+
HTTPStatus.UnprocessableContent,
|
|
31
28
|
],
|
|
32
29
|
code: [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
ActivationError.InvalidLink,
|
|
31
|
+
ActivationError.InvalidToken,
|
|
32
|
+
ActivationError.UserNotFound,
|
|
36
33
|
],
|
|
37
34
|
}),
|
|
38
|
-
|
|
35
|
+
resultSchema({
|
|
39
36
|
type: 'object',
|
|
40
37
|
required: [
|
|
41
38
|
'name',
|
|
@@ -55,31 +52,30 @@ exports.getInfoContract = (0, types_1.defineContract)({
|
|
|
55
52
|
}),
|
|
56
53
|
],
|
|
57
54
|
});
|
|
58
|
-
const getInfo = async (payload, context) => {
|
|
55
|
+
export const getInfo = async (payload, context) => {
|
|
59
56
|
const { userId, token, } = payload;
|
|
60
57
|
if (!userId || !token) {
|
|
61
|
-
return context.error(
|
|
62
|
-
code:
|
|
58
|
+
return context.error(HTTPStatus.NotFound, {
|
|
59
|
+
code: ActivationError.InvalidLink,
|
|
63
60
|
});
|
|
64
61
|
}
|
|
65
62
|
const user = await context.collection.model.findOne({
|
|
66
|
-
_id: new
|
|
63
|
+
_id: new ObjectId(userId),
|
|
67
64
|
});
|
|
68
65
|
if (!user) {
|
|
69
|
-
return context.error(
|
|
70
|
-
code:
|
|
66
|
+
return context.error(HTTPStatus.NotFound, {
|
|
67
|
+
code: ActivationError.UserNotFound,
|
|
71
68
|
});
|
|
72
69
|
}
|
|
73
|
-
const decoded = await
|
|
70
|
+
const decoded = await decodeToken(token, context.config.secret).catch(console.trace);
|
|
74
71
|
if (!decoded) {
|
|
75
|
-
return context.error(
|
|
76
|
-
code:
|
|
72
|
+
return context.error(HTTPStatus.Unauthorized, {
|
|
73
|
+
code: ActivationError.InvalidToken,
|
|
77
74
|
});
|
|
78
75
|
}
|
|
79
|
-
return
|
|
76
|
+
return Result.result({
|
|
80
77
|
name: user.name,
|
|
81
78
|
email: user.email,
|
|
82
79
|
active: user.active,
|
|
83
80
|
});
|
|
84
81
|
};
|
|
85
|
-
exports.getInfo = getInfo;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const redefinePassword_js_1 = require("./redefinePassword.js");
|
|
6
|
-
const getActivationLink_js_1 = require("./getActivationLink.js");
|
|
7
|
-
exports.getRedefinePasswordLinkContract = (0, types_1.defineContract)({
|
|
1
|
+
import { Result, HTTPStatus, resultSchema, functionSchemas, endpointErrorSchema, defineContract } from '@aeriajs/types';
|
|
2
|
+
import { RedefinePasswordError } from './redefinePassword.js';
|
|
3
|
+
import { getActivationToken } from './getActivationLink.js';
|
|
4
|
+
export const getRedefinePasswordLinkContract = defineContract({
|
|
8
5
|
payload: {
|
|
9
6
|
type: 'object',
|
|
10
7
|
required: ['userId'],
|
|
@@ -19,12 +16,12 @@ exports.getRedefinePasswordLinkContract = (0, types_1.defineContract)({
|
|
|
19
16
|
},
|
|
20
17
|
},
|
|
21
18
|
response: [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
httpStatus: [
|
|
25
|
-
code: [
|
|
19
|
+
functionSchemas.getError(),
|
|
20
|
+
endpointErrorSchema({
|
|
21
|
+
httpStatus: [HTTPStatus.Forbidden],
|
|
22
|
+
code: [RedefinePasswordError.UserNotActive],
|
|
26
23
|
}),
|
|
27
|
-
|
|
24
|
+
resultSchema({
|
|
28
25
|
type: 'object',
|
|
29
26
|
properties: {
|
|
30
27
|
url: {
|
|
@@ -34,7 +31,7 @@ exports.getRedefinePasswordLinkContract = (0, types_1.defineContract)({
|
|
|
34
31
|
}),
|
|
35
32
|
],
|
|
36
33
|
});
|
|
37
|
-
const getRedefinePasswordLink = async (payload, context) => {
|
|
34
|
+
export const getRedefinePasswordLink = async (payload, context) => {
|
|
38
35
|
if (!context.config.webPublicUrl) {
|
|
39
36
|
throw new Error('config.webPublicUrl is not set');
|
|
40
37
|
}
|
|
@@ -45,14 +42,14 @@ const getRedefinePasswordLink = async (payload, context) => {
|
|
|
45
42
|
project: ['active'],
|
|
46
43
|
});
|
|
47
44
|
if (error) {
|
|
48
|
-
return
|
|
45
|
+
return Result.error(error);
|
|
49
46
|
}
|
|
50
47
|
if (!user.active) {
|
|
51
|
-
return context.error(
|
|
52
|
-
code:
|
|
48
|
+
return context.error(HTTPStatus.Forbidden, {
|
|
49
|
+
code: RedefinePasswordError.UserNotActive,
|
|
53
50
|
});
|
|
54
51
|
}
|
|
55
|
-
const redefineToken = await
|
|
52
|
+
const redefineToken = await getActivationToken(payload.userId.toString(), context);
|
|
56
53
|
const url = new URL(`${context.config.webPublicUrl}/user/redefine-password`);
|
|
57
54
|
url.searchParams.set('step', 'password'),
|
|
58
55
|
url.searchParams.set('u', payload.userId.toString());
|
|
@@ -60,8 +57,7 @@ const getRedefinePasswordLink = async (payload, context) => {
|
|
|
60
57
|
if (payload.redirect) {
|
|
61
58
|
url.searchParams.set('next', payload.redirect);
|
|
62
59
|
}
|
|
63
|
-
return
|
|
60
|
+
return Result.result({
|
|
64
61
|
url: url.toString(),
|
|
65
62
|
});
|
|
66
63
|
};
|
|
67
|
-
exports.getRedefinePasswordLink = getRedefinePasswordLink;
|
|
@@ -338,7 +338,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
338
338
|
email: string;
|
|
339
339
|
active: boolean;
|
|
340
340
|
phone_number: string;
|
|
341
|
-
picture_file: import("
|
|
341
|
+
picture_file: import("bson").ObjectId;
|
|
342
342
|
given_name: never;
|
|
343
343
|
family_name: never;
|
|
344
344
|
}, never>>, context: Omit<Context, "token">) => ({} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
|
|
@@ -1599,7 +1599,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
1599
1599
|
readonly format: "objectid";
|
|
1600
1600
|
};
|
|
1601
1601
|
}, {}>> & {
|
|
1602
|
-
userId: import("
|
|
1602
|
+
userId: import("bson").ObjectId;
|
|
1603
1603
|
}, never>;
|
|
1604
1604
|
error: undefined;
|
|
1605
1605
|
}, never>) | Promise<({} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
|
|
@@ -1696,7 +1696,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
1696
1696
|
readonly format: "objectid";
|
|
1697
1697
|
};
|
|
1698
1698
|
}, {}>> & {
|
|
1699
|
-
userId: import("
|
|
1699
|
+
userId: import("bson").ObjectId;
|
|
1700
1700
|
}, never>;
|
|
1701
1701
|
error: undefined;
|
|
1702
1702
|
}, never>)>;
|
|
@@ -2986,7 +2986,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
2986
2986
|
readonly type: "string";
|
|
2987
2987
|
};
|
|
2988
2988
|
}, {}>> & {
|
|
2989
|
-
userId: import("
|
|
2989
|
+
userId: import("bson").ObjectId;
|
|
2990
2990
|
redirect: string;
|
|
2991
2991
|
}, never>, "userId"> & Partial<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
|
|
2992
2992
|
readonly userId: {
|
|
@@ -2997,7 +2997,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
2997
2997
|
readonly type: "string";
|
|
2998
2998
|
};
|
|
2999
2999
|
}, {}>> & {
|
|
3000
|
-
userId: import("
|
|
3000
|
+
userId: import("bson").ObjectId;
|
|
3001
3001
|
redirect: string;
|
|
3002
3002
|
}, never>>, context: Omit<Context, "token">) => ({} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
|
|
3003
3003
|
readonly _tag: {
|
|
@@ -3337,7 +3337,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
3337
3337
|
readonly type: "string";
|
|
3338
3338
|
};
|
|
3339
3339
|
}, {}>> & {
|
|
3340
|
-
userId: import("
|
|
3340
|
+
userId: import("bson").ObjectId;
|
|
3341
3341
|
redirect: string;
|
|
3342
3342
|
}, never>, "userId"> & Partial<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
|
|
3343
3343
|
readonly userId: {
|
|
@@ -3348,7 +3348,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
3348
3348
|
readonly type: "string";
|
|
3349
3349
|
};
|
|
3350
3350
|
}, {}>> & {
|
|
3351
|
-
userId: import("
|
|
3351
|
+
userId: import("bson").ObjectId;
|
|
3352
3352
|
redirect: string;
|
|
3353
3353
|
}, never>>, context: Omit<Context, "token">) => ({} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
|
|
3354
3354
|
readonly _tag: {
|
|
@@ -3693,7 +3693,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
3693
3693
|
}, {}>> & {
|
|
3694
3694
|
password: string;
|
|
3695
3695
|
token: string;
|
|
3696
|
-
userId: import("
|
|
3696
|
+
userId: import("bson").ObjectId;
|
|
3697
3697
|
}, never>>, context: Omit<Context, "token">) => ({} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
|
|
3698
3698
|
readonly _tag: {
|
|
3699
3699
|
readonly const: "Error";
|
|
@@ -3857,7 +3857,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
3857
3857
|
readonly format: "objectid";
|
|
3858
3858
|
};
|
|
3859
3859
|
}, {}>> & {
|
|
3860
|
-
userId: import("
|
|
3860
|
+
userId: import("bson").ObjectId;
|
|
3861
3861
|
}, never>;
|
|
3862
3862
|
error: undefined;
|
|
3863
3863
|
}, never>) | Promise<({} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
|
|
@@ -4023,7 +4023,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
|
|
|
4023
4023
|
readonly format: "objectid";
|
|
4024
4024
|
};
|
|
4025
4025
|
}, {}>> & {
|
|
4026
|
-
userId: import("
|
|
4026
|
+
userId: import("bson").ObjectId;
|
|
4027
4027
|
}, never>;
|
|
4028
4028
|
error: undefined;
|
|
4029
4029
|
}, never>)>;
|