@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.
@@ -81,6 +81,11 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
81
81
  readonly fetchItem: true;
82
82
  };
83
83
  };
84
+ readonly copyRedefinePasswordLink: {
85
+ readonly label: "copy_redefine_password_link";
86
+ readonly icon: "link";
87
+ readonly translate: true;
88
+ };
84
89
  readonly copyActivationLink: {
85
90
  readonly label: "copy_activation_link";
86
91
  readonly icon: "link";
@@ -182,6 +187,11 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
182
187
  readonly fetchItem: true;
183
188
  };
184
189
  };
190
+ readonly copyRedefinePasswordLink: {
191
+ readonly label: "copy_redefine_password_link";
192
+ readonly icon: "link";
193
+ readonly translate: true;
194
+ };
185
195
  readonly copyActivationLink: {
186
196
  readonly label: "copy_activation_link";
187
197
  readonly icon: "link";
@@ -280,7 +290,9 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
280
290
  httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
281
291
  }>>;
282
292
  readonly activate: (payload: {
283
- password: string;
293
+ password?: string;
294
+ userId?: string;
295
+ token?: string;
284
296
  }, context: Omit<Context, "token">) => Promise<import("@aeriajs/types").GenericResponse | import("@aeriajs/types").Result.Error<{
285
297
  readonly code: import("./activate.js").ActivationError.InvalidLink;
286
298
  } & {
@@ -293,6 +305,10 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
293
305
  readonly code: import("./activate.js").ActivationError.AlreadyActiveUser;
294
306
  } & {
295
307
  httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
308
+ }> | import("@aeriajs/types").Result.Error<{
309
+ readonly code: import("./activate.js").ActivationError.InvalidToken;
310
+ } & {
311
+ httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
296
312
  }> | import("@aeriajs/types").Result.Error<{
297
313
  readonly code: import("@aeriajs/types").ACError.MalformedInput;
298
314
  } & {
@@ -385,6 +401,11 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
385
401
  readonly fetchItem: true;
386
402
  };
387
403
  };
404
+ readonly copyRedefinePasswordLink: {
405
+ readonly label: "copy_redefine_password_link";
406
+ readonly icon: "link";
407
+ readonly translate: true;
408
+ };
388
409
  readonly copyActivationLink: {
389
410
  readonly label: "copy_activation_link";
390
411
  readonly icon: "link";
@@ -494,6 +515,11 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
494
515
  readonly fetchItem: true;
495
516
  };
496
517
  };
518
+ readonly copyRedefinePasswordLink: {
519
+ readonly label: "copy_redefine_password_link";
520
+ readonly icon: "link";
521
+ readonly translate: true;
522
+ };
497
523
  readonly copyActivationLink: {
498
524
  readonly label: "copy_activation_link";
499
525
  readonly icon: "link";
@@ -526,15 +552,16 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
526
552
  } & {
527
553
  httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
528
554
  }> | import("@aeriajs/types").Result.Error<{
529
- readonly code: import("./getInfo.js").ActivationError.AlreadyActiveUser;
555
+ readonly code: import("./getInfo.js").ActivationError.InvalidToken;
530
556
  } & {
531
- httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
557
+ httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
532
558
  }> | {
533
559
  readonly _tag: "Result";
534
560
  readonly error: undefined;
535
561
  readonly result: {
536
562
  readonly name: string;
537
563
  readonly email: string;
564
+ readonly active: boolean | undefined;
538
565
  };
539
566
  }>;
540
567
  readonly getCurrentUser: (payload: undefined, context: Omit<Context, "token">) => Promise<{
@@ -631,6 +658,11 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
631
658
  readonly fetchItem: true;
632
659
  };
633
660
  };
661
+ readonly copyRedefinePasswordLink: {
662
+ readonly label: "copy_redefine_password_link";
663
+ readonly icon: "link";
664
+ readonly translate: true;
665
+ };
634
666
  readonly copyActivationLink: {
635
667
  readonly label: "copy_activation_link";
636
668
  readonly icon: "link";
@@ -697,6 +729,10 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
697
729
  }, never>>;
698
730
  readonly result: undefined;
699
731
  } | import("@aeriajs/types").Result.Error<{
732
+ readonly code: import("./activate.js").ActivationError.InvalidLink;
733
+ } & {
734
+ httpStatus: import("@aeriajs/types").HTTPStatus.BadRequest;
735
+ }> | import("@aeriajs/types").Result.Error<{
700
736
  readonly code: import("./activate.js").ActivationError.AlreadyActiveUser;
701
737
  } & {
702
738
  httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
@@ -707,6 +743,92 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
707
743
  readonly url: string;
708
744
  };
709
745
  }>;
746
+ readonly getRedefinePasswordLink: (payload: {
747
+ userId: import("@aeriajs/core").ObjectId | string;
748
+ }, context: Omit<Context, "token">) => Promise<{
749
+ readonly _tag: "Error";
750
+ readonly error: Pick<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
751
+ readonly httpStatus: {
752
+ readonly enum: [import("@aeriajs/types").HTTPStatus.Forbidden, import("@aeriajs/types").HTTPStatus.NotFound, import("@aeriajs/types").HTTPStatus.BadRequest];
753
+ };
754
+ readonly code: {
755
+ readonly enum: [import("@aeriajs/types").ACError.ResourceNotFound, import("@aeriajs/types").ACError.OwnershipError, import("@aeriajs/types").ACError.InsecureOperator, import("@aeriajs/types").ACError.MalformedInput];
756
+ };
757
+ readonly message: {
758
+ readonly type: "string";
759
+ };
760
+ readonly details: {
761
+ readonly type: "object";
762
+ readonly additionalProperties: true;
763
+ };
764
+ }>> & {
765
+ code: import("@aeriajs/types").ACError.OwnershipError | import("@aeriajs/types").ACError.ResourceNotFound | import("@aeriajs/types").ACError.InsecureOperator | import("@aeriajs/types").ACError.MalformedInput;
766
+ httpStatus: import("@aeriajs/types").HTTPStatus.BadRequest | import("@aeriajs/types").HTTPStatus.Forbidden | import("@aeriajs/types").HTTPStatus.NotFound;
767
+ message: string;
768
+ details: any;
769
+ }, never>, "code" | "httpStatus"> & Partial<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
770
+ readonly httpStatus: {
771
+ readonly enum: [import("@aeriajs/types").HTTPStatus.Forbidden, import("@aeriajs/types").HTTPStatus.NotFound, import("@aeriajs/types").HTTPStatus.BadRequest];
772
+ };
773
+ readonly code: {
774
+ readonly enum: [import("@aeriajs/types").ACError.ResourceNotFound, import("@aeriajs/types").ACError.OwnershipError, import("@aeriajs/types").ACError.InsecureOperator, import("@aeriajs/types").ACError.MalformedInput];
775
+ };
776
+ readonly message: {
777
+ readonly type: "string";
778
+ };
779
+ readonly details: {
780
+ readonly type: "object";
781
+ readonly additionalProperties: true;
782
+ };
783
+ }>> & {
784
+ code: import("@aeriajs/types").ACError.OwnershipError | import("@aeriajs/types").ACError.ResourceNotFound | import("@aeriajs/types").ACError.InsecureOperator | import("@aeriajs/types").ACError.MalformedInput;
785
+ httpStatus: import("@aeriajs/types").HTTPStatus.BadRequest | import("@aeriajs/types").HTTPStatus.Forbidden | import("@aeriajs/types").HTTPStatus.NotFound;
786
+ message: string;
787
+ details: any;
788
+ }, never>>;
789
+ readonly result: undefined;
790
+ } | import("@aeriajs/types").Result.Error<{
791
+ readonly code: import("./redefinePassword.js").ActivationError.UserNotActive;
792
+ } & {
793
+ httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
794
+ }> | {
795
+ readonly _tag: "Result";
796
+ readonly error: undefined;
797
+ readonly result: {
798
+ readonly url: string;
799
+ };
800
+ }>;
801
+ readonly redefinePassword: (payload: {
802
+ password?: string;
803
+ userId?: string;
804
+ token?: string;
805
+ }, context: Omit<Context, "token">) => Promise<import("@aeriajs/types").Result.Error<{
806
+ readonly code: import("./redefinePassword.js").ActivationError.InvalidLink;
807
+ } & {
808
+ httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
809
+ }> | import("@aeriajs/types").Result.Error<{
810
+ readonly code: import("./redefinePassword.js").ActivationError.UserNotFound;
811
+ } & {
812
+ httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
813
+ }> | import("@aeriajs/types").Result.Error<{
814
+ readonly code: import("./redefinePassword.js").ActivationError.UserNotActive;
815
+ } & {
816
+ httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
817
+ }> | import("@aeriajs/types").Result.Error<{
818
+ readonly code: import("./redefinePassword.js").ActivationError.InvalidToken;
819
+ } & {
820
+ httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
821
+ }> | import("@aeriajs/types").Result.Error<{
822
+ readonly code: import("@aeriajs/types").ACError.MalformedInput;
823
+ } & {
824
+ httpStatus: import("@aeriajs/types").HTTPStatus.UnprocessableContent;
825
+ }> | {
826
+ readonly _tag: "Result";
827
+ readonly error: undefined;
828
+ readonly result: {
829
+ readonly userId: import("@aeriajs/core").ObjectId;
830
+ };
831
+ }>;
710
832
  };
711
833
  contracts: {
712
834
  readonly get?: import("@aeriajs/types").Contract | undefined;
@@ -721,5 +843,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
721
843
  readonly getInfo?: import("@aeriajs/types").Contract | undefined;
722
844
  readonly getCurrentUser?: import("@aeriajs/types").Contract | undefined;
723
845
  readonly getActivationLink?: import("@aeriajs/types").Contract | undefined;
846
+ readonly getRedefinePasswordLink?: import("@aeriajs/types").Contract | undefined;
847
+ readonly redefinePassword?: import("@aeriajs/types").Contract | undefined;
724
848
  };
725
849
  };
@@ -10,6 +10,8 @@ const createAccount_js_1 = require("./createAccount.js");
10
10
  const getInfo_js_1 = require("./getInfo.js");
11
11
  const getCurrentUser_js_1 = require("./getCurrentUser.js");
12
12
  const getActivationLink_js_1 = require("./getActivationLink.js");
13
+ const redefinePassword_js_1 = require("./redefinePassword.js");
14
+ const getRedefinePasswordLink_js_1 = require("./getRedefinePasswordLink.js");
13
15
  const functions = {
14
16
  get: core_1.get,
15
17
  getAll: core_1.getAll,
@@ -23,6 +25,8 @@ const functions = {
23
25
  getInfo: getInfo_js_1.getInfo,
24
26
  getCurrentUser: getCurrentUser_js_1.getCurrentUser,
25
27
  getActivationLink: getActivationLink_js_1.getActivationLink,
28
+ getRedefinePasswordLink: getRedefinePasswordLink_js_1.getRedefinePasswordLink,
29
+ redefinePassword: redefinePassword_js_1.redefinePassword,
26
30
  };
27
31
  const exposedFunctions = {
28
32
  get: true,
@@ -32,11 +36,19 @@ const exposedFunctions = {
32
36
  removeFile: true,
33
37
  insert: true,
34
38
  authenticate: 'unauthenticated',
35
- activate: 'unauthenticated',
39
+ activate: [
40
+ 'unauthenticated',
41
+ 'root',
42
+ ],
36
43
  createAccount: 'unauthenticated',
37
44
  getInfo: 'unauthenticated',
38
45
  getCurrentUser: true,
39
46
  getActivationLink: ['root'],
47
+ getRedefinePasswordLink: ['root'],
48
+ redefinePassword: [
49
+ 'unauthenticated',
50
+ 'root',
51
+ ],
40
52
  };
41
53
  exports.user = (0, core_1.defineCollection)({
42
54
  description: description_js_1.description,
@@ -8,6 +8,8 @@ import { createAccount } from "./createAccount.mjs";
8
8
  import { getInfo } from "./getInfo.mjs";
9
9
  import { getCurrentUser } from "./getCurrentUser.mjs";
10
10
  import { getActivationLink } from "./getActivationLink.mjs";
11
+ import { redefinePassword } from "./redefinePassword.mjs";
12
+ import { getRedefinePasswordLink } from "./getRedefinePasswordLink.mjs";
11
13
  const functions = {
12
14
  get,
13
15
  getAll,
@@ -20,7 +22,9 @@ const functions = {
20
22
  createAccount,
21
23
  getInfo,
22
24
  getCurrentUser,
23
- getActivationLink
25
+ getActivationLink,
26
+ getRedefinePasswordLink,
27
+ redefinePassword
24
28
  };
25
29
  const exposedFunctions = {
26
30
  get: true,
@@ -30,11 +34,19 @@ const exposedFunctions = {
30
34
  removeFile: true,
31
35
  insert: true,
32
36
  authenticate: "unauthenticated",
33
- activate: "unauthenticated",
37
+ activate: [
38
+ "unauthenticated",
39
+ "root"
40
+ ],
34
41
  createAccount: "unauthenticated",
35
42
  getInfo: "unauthenticated",
36
43
  getCurrentUser: true,
37
- getActivationLink: ["root"]
44
+ getActivationLink: ["root"],
45
+ getRedefinePasswordLink: ["root"],
46
+ redefinePassword: [
47
+ "unauthenticated",
48
+ "root"
49
+ ]
38
50
  };
39
51
  export const user = defineCollection({
40
52
  description,
@@ -0,0 +1,41 @@
1
+ import type { Context } from '@aeriajs/types';
2
+ import type { description } from './description.js';
3
+ import { ObjectId } from '@aeriajs/core';
4
+ import { Result, ACError, HTTPStatus } from '@aeriajs/types';
5
+ export declare enum ActivationError {
6
+ UserNotFound = "USER_NOT_FOUND",
7
+ UserNotActive = "USER_NOT_ACTIVE",
8
+ InvalidLink = "INVALID_LINK",
9
+ InvalidToken = "INVALID_TOKEN"
10
+ }
11
+ export declare const redefinePassword: (payload: {
12
+ password?: string;
13
+ userId?: string;
14
+ token?: string;
15
+ }, context: Context<typeof description>) => Promise<Result.Error<{
16
+ readonly code: ActivationError.InvalidLink;
17
+ } & {
18
+ httpStatus: HTTPStatus.NotFound;
19
+ }> | Result.Error<{
20
+ readonly code: ActivationError.UserNotFound;
21
+ } & {
22
+ httpStatus: HTTPStatus.NotFound;
23
+ }> | Result.Error<{
24
+ readonly code: ActivationError.UserNotActive;
25
+ } & {
26
+ httpStatus: HTTPStatus.Forbidden;
27
+ }> | Result.Error<{
28
+ readonly code: ActivationError.InvalidToken;
29
+ } & {
30
+ httpStatus: HTTPStatus.Unauthorized;
31
+ }> | Result.Error<{
32
+ readonly code: ACError.MalformedInput;
33
+ } & {
34
+ httpStatus: HTTPStatus.UnprocessableContent;
35
+ }> | {
36
+ readonly _tag: "Result";
37
+ readonly error: undefined;
38
+ readonly result: {
39
+ readonly userId: ObjectId;
40
+ };
41
+ }>;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.redefinePassword = exports.ActivationError = void 0;
4
+ const core_1 = require("@aeriajs/core");
5
+ const types_1 = require("@aeriajs/types");
6
+ const bcrypt = require("bcrypt");
7
+ var ActivationError;
8
+ (function (ActivationError) {
9
+ ActivationError["UserNotFound"] = "USER_NOT_FOUND";
10
+ ActivationError["UserNotActive"] = "USER_NOT_ACTIVE";
11
+ ActivationError["InvalidLink"] = "INVALID_LINK";
12
+ ActivationError["InvalidToken"] = "INVALID_TOKEN";
13
+ })(ActivationError || (exports.ActivationError = ActivationError = {}));
14
+ const redefinePassword = async (payload, context) => {
15
+ const { userId, token, password, } = payload;
16
+ if (!context.config.secret) {
17
+ throw new Error('config.secret is not set');
18
+ }
19
+ if (!userId || !token) {
20
+ return context.error(types_1.HTTPStatus.NotFound, {
21
+ code: ActivationError.InvalidLink,
22
+ });
23
+ }
24
+ const user = await context.collection.model.findOne({
25
+ _id: new core_1.ObjectId(userId),
26
+ }, {
27
+ projection: {
28
+ password: 1,
29
+ active: 1,
30
+ },
31
+ });
32
+ if (!user) {
33
+ return context.error(types_1.HTTPStatus.NotFound, {
34
+ code: ActivationError.UserNotFound,
35
+ });
36
+ }
37
+ if (!user.active) {
38
+ return context.error(types_1.HTTPStatus.Forbidden, {
39
+ code: ActivationError.UserNotActive,
40
+ });
41
+ }
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,
46
+ });
47
+ }
48
+ if (!password) {
49
+ /* if( context.request.method === 'GET' ) {
50
+ return context.response.writeHead(302, {
51
+ location: `/user/activation?step=password&u=${userId}&t=${token}`,
52
+ }).end()
53
+ } */
54
+ return context.error(types_1.HTTPStatus.UnprocessableContent, {
55
+ code: types_1.ACError.MalformedInput,
56
+ });
57
+ }
58
+ await context.collection.model.updateOne({
59
+ _id: user._id,
60
+ }, {
61
+ $set: {
62
+ active: true,
63
+ password: await bcrypt.hash(password, 10),
64
+ },
65
+ });
66
+ return types_1.Result.result({
67
+ userId: user._id,
68
+ });
69
+ };
70
+ exports.redefinePassword = redefinePassword;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ import { decodeToken, ObjectId } from "@aeriajs/core";
3
+ import { Result, ACError, HTTPStatus } from "@aeriajs/types";
4
+ import * as bcrypt from "bcrypt";
5
+ export var ActivationError = /* @__PURE__ */ ((ActivationError2) => {
6
+ ActivationError2["UserNotFound"] = "USER_NOT_FOUND";
7
+ ActivationError2["UserNotActive"] = "USER_NOT_ACTIVE";
8
+ ActivationError2["InvalidLink"] = "INVALID_LINK";
9
+ ActivationError2["InvalidToken"] = "INVALID_TOKEN";
10
+ return ActivationError2;
11
+ })(ActivationError || {});
12
+ export const redefinePassword = async (payload, context) => {
13
+ const {
14
+ userId,
15
+ token,
16
+ password
17
+ } = payload;
18
+ if (!context.config.secret) {
19
+ throw new Error("config.secret is not set");
20
+ }
21
+ if (!userId || !token) {
22
+ return context.error(HTTPStatus.NotFound, {
23
+ code: "INVALID_LINK" /* InvalidLink */
24
+ });
25
+ }
26
+ const user = await context.collection.model.findOne({
27
+ _id: new ObjectId(userId)
28
+ }, {
29
+ projection: {
30
+ password: 1,
31
+ active: 1
32
+ }
33
+ });
34
+ if (!user) {
35
+ return context.error(HTTPStatus.NotFound, {
36
+ code: "USER_NOT_FOUND" /* UserNotFound */
37
+ });
38
+ }
39
+ if (!user.active) {
40
+ return context.error(HTTPStatus.Forbidden, {
41
+ code: "USER_NOT_ACTIVE" /* UserNotActive */
42
+ });
43
+ }
44
+ const decoded = await decodeToken(token, context.config.secret);
45
+ if (!decoded) {
46
+ return context.error(HTTPStatus.Unauthorized, {
47
+ code: "INVALID_TOKEN" /* InvalidToken */
48
+ });
49
+ }
50
+ if (!password) {
51
+ return context.error(HTTPStatus.UnprocessableContent, {
52
+ code: ACError.MalformedInput
53
+ });
54
+ }
55
+ await context.collection.model.updateOne(
56
+ {
57
+ _id: user._id
58
+ },
59
+ {
60
+ $set: {
61
+ active: true,
62
+ password: await bcrypt.hash(password, 10)
63
+ }
64
+ }
65
+ );
66
+ return Result.result({
67
+ userId: user._id
68
+ });
69
+ };