@aeriajs/builtins 0.0.217 → 0.0.219

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.
@@ -5,21 +5,14 @@ import { Result, ACError, HTTPStatus } from '@aeriajs/types';
5
5
  export declare enum ActivationError {
6
6
  UserNotFound = "USER_NOT_FOUND",
7
7
  AlreadyActiveUser = "ALREADY_ACTIVE_USER",
8
- InvalidLink = "INVALID_LINK"
8
+ InvalidLink = "INVALID_LINK",
9
+ InvalidToken = "INVALID_TOKEN"
9
10
  }
10
11
  export declare const activate: (payload: {
11
- password: string;
12
- }, context: Context<typeof description> & {
13
- request: {
14
- query: {
15
- u?: string;
16
- t?: string;
17
- };
18
- payload: {
19
- password?: string;
20
- };
21
- };
22
- }) => Promise<import("@aeriajs/types").GenericResponse | Result.Error<{
12
+ password?: string;
13
+ userId?: string;
14
+ token?: string;
15
+ }, context: Context<typeof description>) => Promise<import("@aeriajs/types").GenericResponse | Result.Error<{
23
16
  readonly code: ActivationError.InvalidLink;
24
17
  } & {
25
18
  httpStatus: HTTPStatus.NotFound;
@@ -31,6 +24,10 @@ export declare const activate: (payload: {
31
24
  readonly code: ActivationError.AlreadyActiveUser;
32
25
  } & {
33
26
  httpStatus: HTTPStatus.Forbidden;
27
+ }> | Result.Error<{
28
+ readonly code: ActivationError.InvalidToken;
29
+ } & {
30
+ httpStatus: HTTPStatus.Unauthorized;
34
31
  }> | Result.Error<{
35
32
  readonly code: ACError.MalformedInput;
36
33
  } & {
@@ -4,15 +4,18 @@ exports.activate = exports.ActivationError = void 0;
4
4
  const core_1 = require("@aeriajs/core");
5
5
  const types_1 = require("@aeriajs/types");
6
6
  const bcrypt = require("bcrypt");
7
- const getActivationLink_js_1 = require("./getActivationLink.js");
8
7
  var ActivationError;
9
8
  (function (ActivationError) {
10
9
  ActivationError["UserNotFound"] = "USER_NOT_FOUND";
11
10
  ActivationError["AlreadyActiveUser"] = "ALREADY_ACTIVE_USER";
12
11
  ActivationError["InvalidLink"] = "INVALID_LINK";
12
+ ActivationError["InvalidToken"] = "INVALID_TOKEN";
13
13
  })(ActivationError || (exports.ActivationError = ActivationError = {}));
14
14
  const activate = async (payload, context) => {
15
- const { u: userId, t: token, } = context.request.query;
15
+ const { userId, token, password, } = payload;
16
+ if (!context.config.secret) {
17
+ throw new Error('config.secret is not set');
18
+ }
16
19
  if (!userId || !token) {
17
20
  return context.error(types_1.HTTPStatus.NotFound, {
18
21
  code: ActivationError.InvalidLink,
@@ -23,6 +26,7 @@ const activate = async (payload, context) => {
23
26
  }, {
24
27
  projection: {
25
28
  password: 1,
29
+ active: 1,
26
30
  },
27
31
  });
28
32
  if (!user) {
@@ -35,15 +39,14 @@ const activate = async (payload, context) => {
35
39
  code: ActivationError.AlreadyActiveUser,
36
40
  });
37
41
  }
38
- const activationToken = await (0, getActivationLink_js_1.getActivationToken)(userId.toString(), context);
39
- const equal = await bcrypt.compare(activationToken, token);
40
- if (!equal) {
41
- return context.error(types_1.HTTPStatus.NotFound, {
42
- code: ActivationError.InvalidLink,
42
+ const decoded = await (0, core_1.decodeToken)(token, context.config.secret);
43
+ if (!decoded) {
44
+ return context.error(types_1.HTTPStatus.Unauthorized, {
45
+ code: ActivationError.InvalidToken,
43
46
  });
44
47
  }
45
48
  if (!user.password) {
46
- if (!payload.password) {
49
+ if (!password) {
47
50
  if (context.request.method === 'GET') {
48
51
  return context.response.writeHead(302, {
49
52
  location: `/user/activation?step=password&u=${userId}&t=${token}`,
@@ -58,7 +61,7 @@ const activate = async (payload, context) => {
58
61
  }, {
59
62
  $set: {
60
63
  active: true,
61
- password: await bcrypt.hash(payload.password, 10),
64
+ password: await bcrypt.hash(password, 10),
62
65
  },
63
66
  });
64
67
  return;
@@ -1,19 +1,23 @@
1
1
  "use strict";
2
- import { ObjectId } from "@aeriajs/core";
2
+ import { decodeToken, ObjectId } from "@aeriajs/core";
3
3
  import { Result, ACError, HTTPStatus } from "@aeriajs/types";
4
4
  import * as bcrypt from "bcrypt";
5
- import { getActivationToken } from "./getActivationLink.mjs";
6
5
  export var ActivationError = /* @__PURE__ */ ((ActivationError2) => {
7
6
  ActivationError2["UserNotFound"] = "USER_NOT_FOUND";
8
7
  ActivationError2["AlreadyActiveUser"] = "ALREADY_ACTIVE_USER";
9
8
  ActivationError2["InvalidLink"] = "INVALID_LINK";
9
+ ActivationError2["InvalidToken"] = "INVALID_TOKEN";
10
10
  return ActivationError2;
11
11
  })(ActivationError || {});
12
12
  export const activate = async (payload, context) => {
13
13
  const {
14
- u: userId,
15
- t: token
16
- } = context.request.query;
14
+ userId,
15
+ token,
16
+ password
17
+ } = payload;
18
+ if (!context.config.secret) {
19
+ throw new Error("config.secret is not set");
20
+ }
17
21
  if (!userId || !token) {
18
22
  return context.error(HTTPStatus.NotFound, {
19
23
  code: "INVALID_LINK" /* InvalidLink */
@@ -23,7 +27,8 @@ export const activate = async (payload, context) => {
23
27
  _id: new ObjectId(userId)
24
28
  }, {
25
29
  projection: {
26
- password: 1
30
+ password: 1,
31
+ active: 1
27
32
  }
28
33
  });
29
34
  if (!user) {
@@ -36,15 +41,14 @@ export const activate = async (payload, context) => {
36
41
  code: "ALREADY_ACTIVE_USER" /* AlreadyActiveUser */
37
42
  });
38
43
  }
39
- const activationToken = await getActivationToken(userId.toString(), context);
40
- const equal = await bcrypt.compare(activationToken, token);
41
- if (!equal) {
42
- return context.error(HTTPStatus.NotFound, {
43
- code: "INVALID_LINK" /* InvalidLink */
44
+ const decoded = await decodeToken(token, context.config.secret);
45
+ if (!decoded) {
46
+ return context.error(HTTPStatus.Unauthorized, {
47
+ code: "INVALID_TOKEN" /* InvalidToken */
44
48
  });
45
49
  }
46
50
  if (!user.password) {
47
- if (!payload.password) {
51
+ if (!password) {
48
52
  if (context.request.method === "GET") {
49
53
  return context.response.writeHead(302, {
50
54
  location: `/user/activation?step=password&u=${userId}&t=${token}`
@@ -61,7 +65,7 @@ export const activate = async (payload, context) => {
61
65
  {
62
66
  $set: {
63
67
  active: true,
64
- password: await bcrypt.hash(payload.password, 10)
68
+ password: await bcrypt.hash(password, 10)
65
69
  }
66
70
  }
67
71
  );
@@ -94,6 +94,11 @@ export declare const createAccount: (payload: Partial<PackReferences<SchemaWithI
94
94
  readonly fetchItem: true;
95
95
  };
96
96
  };
97
+ readonly copyRedefinePasswordLink: {
98
+ readonly label: "copy_redefine_password_link";
99
+ readonly icon: "link";
100
+ readonly translate: true;
101
+ };
97
102
  readonly copyActivationLink: {
98
103
  readonly label: "copy_activation_link";
99
104
  readonly icon: "link";
@@ -83,6 +83,11 @@ export declare const description: {
83
83
  readonly fetchItem: true;
84
84
  };
85
85
  };
86
+ readonly copyRedefinePasswordLink: {
87
+ readonly label: "copy_redefine_password_link";
88
+ readonly icon: "link";
89
+ readonly translate: true;
90
+ };
86
91
  readonly copyActivationLink: {
87
92
  readonly label: "copy_activation_link";
88
93
  readonly icon: "link";
@@ -114,6 +114,11 @@ exports.description = (0, core_1.defineDescription)({
114
114
  fetchItem: true,
115
115
  },
116
116
  },
117
+ 'copyRedefinePasswordLink': {
118
+ label: 'copy_redefine_password_link',
119
+ icon: 'link',
120
+ translate: true,
121
+ },
117
122
  'copyActivationLink': {
118
123
  label: 'copy_activation_link',
119
124
  icon: 'link',
@@ -108,6 +108,11 @@ export const description = defineDescription({
108
108
  fetchItem: true
109
109
  }
110
110
  },
111
+ "copyRedefinePasswordLink": {
112
+ label: "copy_redefine_password_link",
113
+ icon: "link",
114
+ translate: true
115
+ },
111
116
  "copyActivationLink": {
112
117
  label: "copy_activation_link",
113
118
  icon: "link",
@@ -1,5 +1,5 @@
1
1
  import type { Context } from '@aeriajs/types';
2
- import type { ObjectId } from '@aeriajs/core';
2
+ import { type ObjectId } from '@aeriajs/core';
3
3
  import { Result, HTTPStatus } from '@aeriajs/types';
4
4
  import { ActivationError } from './activate.js';
5
5
  export declare const getActivationToken: (strId: string, context: Context) => Promise<string>;
@@ -48,6 +48,10 @@ export declare const getActivationLink: (payload: {
48
48
  }, never>>;
49
49
  readonly result: undefined;
50
50
  } | Result.Error<{
51
+ readonly code: ActivationError.InvalidLink;
52
+ } & {
53
+ httpStatus: HTTPStatus.BadRequest;
54
+ }> | Result.Error<{
51
55
  readonly code: ActivationError.AlreadyActiveUser;
52
56
  } & {
53
57
  httpStatus: HTTPStatus.Forbidden;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getActivationLink = exports.getActivationToken = void 0;
4
+ const core_1 = require("@aeriajs/core");
4
5
  const types_1 = require("@aeriajs/types");
5
- const bcrypt = require("bcrypt");
6
6
  const activate_js_1 = require("./activate.js");
7
7
  const getActivationToken = async (strId, context) => {
8
8
  if (context.calledFunction === 'getActivationToken') {
@@ -11,10 +11,20 @@ const getActivationToken = async (strId, context) => {
11
11
  if (!context.config.secret) {
12
12
  throw new Error('config.secret is not set');
13
13
  }
14
- return `${context.config.secret}:${strId}`;
14
+ const token = await (0, core_1.signToken)({
15
+ data: strId,
16
+ }, context.config.secret, {
17
+ expiresIn: context.config.security.linkTokenExpiration,
18
+ });
19
+ return token;
15
20
  };
16
21
  exports.getActivationToken = getActivationToken;
17
22
  const getActivationLink = async (payload, context) => {
23
+ if (!context.config.webPublicUrl) {
24
+ return context.error(types_1.HTTPStatus.BadRequest, {
25
+ code: activate_js_1.ActivationError.InvalidLink,
26
+ });
27
+ }
18
28
  const { error, result: user } = await context.collections.user.functions.get({
19
29
  filters: {
20
30
  _id: payload.userId,
@@ -30,8 +40,7 @@ const getActivationLink = async (payload, context) => {
30
40
  });
31
41
  }
32
42
  const activationToken = await (0, exports.getActivationToken)(payload.userId.toString(), context);
33
- const encryptedActivationToken = await bcrypt.hash(activationToken, 10);
34
- const url = `${context.config.publicUrl}/user/activate?u=${payload.userId.toString()}&t=${encryptedActivationToken}`;
43
+ const url = `${context.config.webPublicUrl}/user/activation?step=password&u=${payload.userId.toString()}&t=${activationToken}`;
35
44
  return types_1.Result.result({
36
45
  url,
37
46
  });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
+ import { signToken } from "@aeriajs/core";
2
3
  import { Result, HTTPStatus } from "@aeriajs/types";
3
- import * as bcrypt from "bcrypt";
4
4
  import { ActivationError } from "./activate.mjs";
5
5
  export const getActivationToken = async (strId, context) => {
6
6
  if (context.calledFunction === "getActivationToken") {
@@ -9,9 +9,19 @@ export const getActivationToken = async (strId, context) => {
9
9
  if (!context.config.secret) {
10
10
  throw new Error("config.secret is not set");
11
11
  }
12
- return `${context.config.secret}:${strId}`;
12
+ const token = await signToken({
13
+ data: strId
14
+ }, context.config.secret, {
15
+ expiresIn: context.config.security.linkTokenExpiration
16
+ });
17
+ return token;
13
18
  };
14
19
  export const getActivationLink = async (payload, context) => {
20
+ if (!context.config.webPublicUrl) {
21
+ return context.error(HTTPStatus.BadRequest, {
22
+ code: ActivationError.InvalidLink
23
+ });
24
+ }
15
25
  const { error, result: user } = await context.collections.user.functions.get({
16
26
  filters: {
17
27
  _id: payload.userId
@@ -27,8 +37,7 @@ export const getActivationLink = async (payload, context) => {
27
37
  });
28
38
  }
29
39
  const activationToken = await getActivationToken(payload.userId.toString(), context);
30
- const encryptedActivationToken = await bcrypt.hash(activationToken, 10);
31
- const url = `${context.config.publicUrl}/user/activate?u=${payload.userId.toString()}&t=${encryptedActivationToken}`;
40
+ const url = `${context.config.webPublicUrl}/user/activation?step=password&u=${payload.userId.toString()}&t=${activationToken}`;
32
41
  return Result.result({
33
42
  url
34
43
  });
@@ -99,6 +99,11 @@ export declare const getCurrentUser: (_payload: undefined, context: Context<type
99
99
  readonly fetchItem: true;
100
100
  };
101
101
  };
102
+ readonly copyRedefinePasswordLink: {
103
+ readonly label: "copy_redefine_password_link";
104
+ readonly icon: "link";
105
+ readonly translate: true;
106
+ };
102
107
  readonly copyActivationLink: {
103
108
  readonly label: "copy_activation_link";
104
109
  readonly icon: "link";
@@ -4,7 +4,8 @@ import { Result, HTTPStatus } from '@aeriajs/types';
4
4
  export declare enum ActivationError {
5
5
  UserNotFound = "USER_NOT_FOUND",
6
6
  AlreadyActiveUser = "ALREADY_ACTIVE_USER",
7
- InvalidLink = "INVALID_LINK"
7
+ InvalidLink = "INVALID_LINK",
8
+ InvalidToken = "INVALID_TOKEN"
8
9
  }
9
10
  export declare const getInfo: (payload: {
10
11
  userId: string;
@@ -18,14 +19,15 @@ export declare const getInfo: (payload: {
18
19
  } & {
19
20
  httpStatus: HTTPStatus.NotFound;
20
21
  }> | Result.Error<{
21
- readonly code: ActivationError.AlreadyActiveUser;
22
+ readonly code: ActivationError.InvalidToken;
22
23
  } & {
23
- httpStatus: HTTPStatus.Forbidden;
24
+ httpStatus: HTTPStatus.Unauthorized;
24
25
  }> | {
25
26
  readonly _tag: "Result";
26
27
  readonly error: undefined;
27
28
  readonly result: {
28
29
  readonly name: string;
29
30
  readonly email: string;
31
+ readonly active: boolean | undefined;
30
32
  };
31
33
  }>;
@@ -1,15 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getInfo = exports.ActivationError = void 0;
4
- const bcrypt = require("bcrypt");
5
4
  const types_1 = require("@aeriajs/types");
6
5
  const core_1 = require("@aeriajs/core");
7
- const getActivationLink_js_1 = require("./getActivationLink.js");
8
6
  var ActivationError;
9
7
  (function (ActivationError) {
10
8
  ActivationError["UserNotFound"] = "USER_NOT_FOUND";
11
9
  ActivationError["AlreadyActiveUser"] = "ALREADY_ACTIVE_USER";
12
10
  ActivationError["InvalidLink"] = "INVALID_LINK";
11
+ ActivationError["InvalidToken"] = "INVALID_TOKEN";
13
12
  })(ActivationError || (exports.ActivationError = ActivationError = {}));
14
13
  const getInfo = async (payload, context) => {
15
14
  const { userId, token, } = payload;
@@ -26,21 +25,16 @@ const getInfo = async (payload, context) => {
26
25
  code: ActivationError.UserNotFound,
27
26
  });
28
27
  }
29
- if (user.active) {
30
- return context.error(types_1.HTTPStatus.Forbidden, {
31
- code: ActivationError.AlreadyActiveUser,
32
- });
33
- }
34
- const activationToken = await (0, getActivationLink_js_1.getActivationToken)(user._id.toString(), context);
35
- const equal = await bcrypt.compare(activationToken, token);
36
- if (!equal) {
37
- return context.error(types_1.HTTPStatus.NotFound, {
38
- code: ActivationError.InvalidLink,
28
+ const decoded = await (0, core_1.decodeToken)(token, context.config.secret).catch(console.trace);
29
+ if (!decoded) {
30
+ return context.error(types_1.HTTPStatus.Unauthorized, {
31
+ code: ActivationError.InvalidToken,
39
32
  });
40
33
  }
41
34
  return types_1.Result.result({
42
35
  name: user.name,
43
36
  email: user.email,
37
+ active: user.active,
44
38
  });
45
39
  };
46
40
  exports.getInfo = getInfo;
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
- import * as bcrypt from "bcrypt";
3
2
  import { Result, HTTPStatus } from "@aeriajs/types";
4
- import { ObjectId } from "@aeriajs/core";
5
- import { getActivationToken } from "./getActivationLink.mjs";
3
+ import { decodeToken, ObjectId } from "@aeriajs/core";
6
4
  export var ActivationError = /* @__PURE__ */ ((ActivationError2) => {
7
5
  ActivationError2["UserNotFound"] = "USER_NOT_FOUND";
8
6
  ActivationError2["AlreadyActiveUser"] = "ALREADY_ACTIVE_USER";
9
7
  ActivationError2["InvalidLink"] = "INVALID_LINK";
8
+ ActivationError2["InvalidToken"] = "INVALID_TOKEN";
10
9
  return ActivationError2;
11
10
  })(ActivationError || {});
12
11
  export const getInfo = async (payload, context) => {
@@ -27,20 +26,15 @@ export const getInfo = async (payload, context) => {
27
26
  code: "USER_NOT_FOUND" /* UserNotFound */
28
27
  });
29
28
  }
30
- if (user.active) {
31
- return context.error(HTTPStatus.Forbidden, {
32
- code: "ALREADY_ACTIVE_USER" /* AlreadyActiveUser */
33
- });
34
- }
35
- const activationToken = await getActivationToken(user._id.toString(), context);
36
- const equal = await bcrypt.compare(activationToken, token);
37
- if (!equal) {
38
- return context.error(HTTPStatus.NotFound, {
39
- code: "INVALID_LINK" /* InvalidLink */
29
+ const decoded = await decodeToken(token, context.config.secret).catch(console.trace);
30
+ if (!decoded) {
31
+ return context.error(HTTPStatus.Unauthorized, {
32
+ code: "INVALID_TOKEN" /* InvalidToken */
40
33
  });
41
34
  }
42
35
  return Result.result({
43
36
  name: user.name,
44
- email: user.email
37
+ email: user.email,
38
+ active: user.active
45
39
  });
46
40
  };
@@ -0,0 +1,59 @@
1
+ import type { Context } from '@aeriajs/types';
2
+ import { type ObjectId } from '@aeriajs/core';
3
+ import { Result, HTTPStatus } from '@aeriajs/types';
4
+ import { ActivationError } from './redefinePassword.js';
5
+ export declare const getRedefinePasswordLink: (payload: {
6
+ userId: ObjectId | string;
7
+ }, context: Context) => Promise<{
8
+ readonly _tag: "Error";
9
+ readonly error: Pick<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
10
+ readonly httpStatus: {
11
+ readonly enum: [HTTPStatus.Forbidden, HTTPStatus.NotFound, HTTPStatus.BadRequest];
12
+ };
13
+ readonly code: {
14
+ readonly enum: [import("@aeriajs/types").ACError.ResourceNotFound, import("@aeriajs/types").ACError.OwnershipError, import("@aeriajs/types").ACError.InsecureOperator, import("@aeriajs/types").ACError.MalformedInput];
15
+ };
16
+ readonly message: {
17
+ readonly type: "string";
18
+ };
19
+ readonly details: {
20
+ readonly type: "object";
21
+ readonly additionalProperties: true;
22
+ };
23
+ }>> & {
24
+ code: import("@aeriajs/types").ACError.OwnershipError | import("@aeriajs/types").ACError.ResourceNotFound | import("@aeriajs/types").ACError.InsecureOperator | import("@aeriajs/types").ACError.MalformedInput;
25
+ httpStatus: HTTPStatus.BadRequest | HTTPStatus.Forbidden | HTTPStatus.NotFound;
26
+ message: string;
27
+ details: any;
28
+ }, never>, "code" | "httpStatus"> & Partial<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
29
+ readonly httpStatus: {
30
+ readonly enum: [HTTPStatus.Forbidden, HTTPStatus.NotFound, HTTPStatus.BadRequest];
31
+ };
32
+ readonly code: {
33
+ readonly enum: [import("@aeriajs/types").ACError.ResourceNotFound, import("@aeriajs/types").ACError.OwnershipError, import("@aeriajs/types").ACError.InsecureOperator, import("@aeriajs/types").ACError.MalformedInput];
34
+ };
35
+ readonly message: {
36
+ readonly type: "string";
37
+ };
38
+ readonly details: {
39
+ readonly type: "object";
40
+ readonly additionalProperties: true;
41
+ };
42
+ }>> & {
43
+ code: import("@aeriajs/types").ACError.OwnershipError | import("@aeriajs/types").ACError.ResourceNotFound | import("@aeriajs/types").ACError.InsecureOperator | import("@aeriajs/types").ACError.MalformedInput;
44
+ httpStatus: HTTPStatus.BadRequest | HTTPStatus.Forbidden | HTTPStatus.NotFound;
45
+ message: string;
46
+ details: any;
47
+ }, never>>;
48
+ readonly result: undefined;
49
+ } | Result.Error<{
50
+ readonly code: ActivationError.UserNotActive;
51
+ } & {
52
+ httpStatus: HTTPStatus.Forbidden;
53
+ }> | {
54
+ readonly _tag: "Result";
55
+ readonly error: undefined;
56
+ readonly result: {
57
+ readonly url: string;
58
+ };
59
+ }>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRedefinePasswordLink = void 0;
4
+ const types_1 = require("@aeriajs/types");
5
+ const redefinePassword_js_1 = require("./redefinePassword.js");
6
+ const getActivationLink_js_1 = require("./getActivationLink.js");
7
+ const getRedefinePasswordLink = async (payload, context) => {
8
+ if (!context.config.webPublicUrl) {
9
+ throw new Error('config.webPublicUrl is not set');
10
+ }
11
+ const { error, result: user } = await context.collections.user.functions.get({
12
+ filters: {
13
+ _id: payload.userId,
14
+ },
15
+ project: ['active'],
16
+ });
17
+ if (error) {
18
+ return types_1.Result.error(error);
19
+ }
20
+ if (!user.active) {
21
+ return context.error(types_1.HTTPStatus.Forbidden, {
22
+ code: redefinePassword_js_1.ActivationError.UserNotActive,
23
+ });
24
+ }
25
+ const redefineToken = await (0, getActivationLink_js_1.getActivationToken)(payload.userId.toString(), context);
26
+ const url = `${context.config.webPublicUrl}/user/redefine-password?step=password&u=${payload.userId.toString()}&t=${redefineToken}`;
27
+ return types_1.Result.result({
28
+ url,
29
+ });
30
+ };
31
+ exports.getRedefinePasswordLink = getRedefinePasswordLink;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ import { Result, HTTPStatus } from "@aeriajs/types";
3
+ import { ActivationError } from "./redefinePassword.mjs";
4
+ import { getActivationToken } from "./getActivationLink.mjs";
5
+ export const getRedefinePasswordLink = async (payload, context) => {
6
+ if (!context.config.webPublicUrl) {
7
+ throw new Error("config.webPublicUrl is not set");
8
+ }
9
+ const { error, result: user } = await context.collections.user.functions.get({
10
+ filters: {
11
+ _id: payload.userId
12
+ },
13
+ project: ["active"]
14
+ });
15
+ if (error) {
16
+ return Result.error(error);
17
+ }
18
+ if (!user.active) {
19
+ return context.error(HTTPStatus.Forbidden, {
20
+ code: ActivationError.UserNotActive
21
+ });
22
+ }
23
+ const redefineToken = await getActivationToken(payload.userId.toString(), context);
24
+ const url = `${context.config.webPublicUrl}/user/redefine-password?step=password&u=${payload.userId.toString()}&t=${redefineToken}`;
25
+ return Result.result({
26
+ url
27
+ });
28
+ };