@aeriajs/builtins 0.0.218 → 0.0.220

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";
@@ -654,6 +686,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
654
686
  }>;
655
687
  readonly getActivationLink: (payload: {
656
688
  userId: import("@aeriajs/core").ObjectId | string;
689
+ redirect?: string;
657
690
  }, context: Omit<Context, "token">) => Promise<{
658
691
  readonly _tag: "Error";
659
692
  readonly error: Pick<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
@@ -697,6 +730,10 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
697
730
  }, never>>;
698
731
  readonly result: undefined;
699
732
  } | import("@aeriajs/types").Result.Error<{
733
+ readonly code: import("./activate.js").ActivationError.InvalidLink;
734
+ } & {
735
+ httpStatus: import("@aeriajs/types").HTTPStatus.BadRequest;
736
+ }> | import("@aeriajs/types").Result.Error<{
700
737
  readonly code: import("./activate.js").ActivationError.AlreadyActiveUser;
701
738
  } & {
702
739
  httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
@@ -704,7 +741,94 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
704
741
  readonly _tag: "Result";
705
742
  readonly error: undefined;
706
743
  readonly result: {
707
- readonly url: string;
744
+ readonly url: URL;
745
+ };
746
+ }>;
747
+ readonly getRedefinePasswordLink: (payload: {
748
+ userId: import("@aeriajs/core").ObjectId | string;
749
+ redirect?: string;
750
+ }, context: Omit<Context, "token">) => Promise<{
751
+ readonly _tag: "Error";
752
+ readonly error: Pick<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
753
+ readonly httpStatus: {
754
+ readonly enum: [import("@aeriajs/types").HTTPStatus.Forbidden, import("@aeriajs/types").HTTPStatus.NotFound, import("@aeriajs/types").HTTPStatus.BadRequest];
755
+ };
756
+ readonly code: {
757
+ readonly enum: [import("@aeriajs/types").ACError.ResourceNotFound, import("@aeriajs/types").ACError.OwnershipError, import("@aeriajs/types").ACError.InsecureOperator, import("@aeriajs/types").ACError.MalformedInput];
758
+ };
759
+ readonly message: {
760
+ readonly type: "string";
761
+ };
762
+ readonly details: {
763
+ readonly type: "object";
764
+ readonly additionalProperties: true;
765
+ };
766
+ }>> & {
767
+ code: import("@aeriajs/types").ACError.OwnershipError | import("@aeriajs/types").ACError.ResourceNotFound | import("@aeriajs/types").ACError.InsecureOperator | import("@aeriajs/types").ACError.MalformedInput;
768
+ httpStatus: import("@aeriajs/types").HTTPStatus.BadRequest | import("@aeriajs/types").HTTPStatus.Forbidden | import("@aeriajs/types").HTTPStatus.NotFound;
769
+ message: string;
770
+ details: any;
771
+ }, never>, "code" | "httpStatus"> & Partial<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
772
+ readonly httpStatus: {
773
+ readonly enum: [import("@aeriajs/types").HTTPStatus.Forbidden, import("@aeriajs/types").HTTPStatus.NotFound, import("@aeriajs/types").HTTPStatus.BadRequest];
774
+ };
775
+ readonly code: {
776
+ readonly enum: [import("@aeriajs/types").ACError.ResourceNotFound, import("@aeriajs/types").ACError.OwnershipError, import("@aeriajs/types").ACError.InsecureOperator, import("@aeriajs/types").ACError.MalformedInput];
777
+ };
778
+ readonly message: {
779
+ readonly type: "string";
780
+ };
781
+ readonly details: {
782
+ readonly type: "object";
783
+ readonly additionalProperties: true;
784
+ };
785
+ }>> & {
786
+ code: import("@aeriajs/types").ACError.OwnershipError | import("@aeriajs/types").ACError.ResourceNotFound | import("@aeriajs/types").ACError.InsecureOperator | import("@aeriajs/types").ACError.MalformedInput;
787
+ httpStatus: import("@aeriajs/types").HTTPStatus.BadRequest | import("@aeriajs/types").HTTPStatus.Forbidden | import("@aeriajs/types").HTTPStatus.NotFound;
788
+ message: string;
789
+ details: any;
790
+ }, never>>;
791
+ readonly result: undefined;
792
+ } | import("@aeriajs/types").Result.Error<{
793
+ readonly code: import("./redefinePassword.js").ActivationError.UserNotActive;
794
+ } & {
795
+ httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
796
+ }> | {
797
+ readonly _tag: "Result";
798
+ readonly error: undefined;
799
+ readonly result: {
800
+ readonly url: URL;
801
+ };
802
+ }>;
803
+ readonly redefinePassword: (payload: {
804
+ password?: string;
805
+ userId?: string;
806
+ token?: string;
807
+ }, context: Omit<Context, "token">) => Promise<import("@aeriajs/types").Result.Error<{
808
+ readonly code: import("./redefinePassword.js").ActivationError.InvalidLink;
809
+ } & {
810
+ httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
811
+ }> | import("@aeriajs/types").Result.Error<{
812
+ readonly code: import("./redefinePassword.js").ActivationError.UserNotFound;
813
+ } & {
814
+ httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
815
+ }> | import("@aeriajs/types").Result.Error<{
816
+ readonly code: import("./redefinePassword.js").ActivationError.UserNotActive;
817
+ } & {
818
+ httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
819
+ }> | import("@aeriajs/types").Result.Error<{
820
+ readonly code: import("./redefinePassword.js").ActivationError.InvalidToken;
821
+ } & {
822
+ httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
823
+ }> | import("@aeriajs/types").Result.Error<{
824
+ readonly code: import("@aeriajs/types").ACError.MalformedInput;
825
+ } & {
826
+ httpStatus: import("@aeriajs/types").HTTPStatus.UnprocessableContent;
827
+ }> | {
828
+ readonly _tag: "Result";
829
+ readonly error: undefined;
830
+ readonly result: {
831
+ readonly userId: import("@aeriajs/core").ObjectId;
708
832
  };
709
833
  }>;
710
834
  };
@@ -721,5 +845,7 @@ export declare const user: Omit<Collection<never>, "functions" | "description" |
721
845
  readonly getInfo?: import("@aeriajs/types").Contract | undefined;
722
846
  readonly getCurrentUser?: import("@aeriajs/types").Contract | undefined;
723
847
  readonly getActivationLink?: import("@aeriajs/types").Contract | undefined;
848
+ readonly getRedefinePasswordLink?: import("@aeriajs/types").Contract | undefined;
849
+ readonly redefinePassword?: import("@aeriajs/types").Contract | undefined;
724
850
  };
725
851
  };
@@ -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
+ };