@aeriajs/builtins 0.0.227 → 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.
@@ -38,4 +38,4 @@ export declare const activate: (payload: {
38
38
  readonly result: {
39
39
  readonly userId: ObjectId;
40
40
  };
41
- } | undefined>;
41
+ }>;
@@ -47,12 +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
- //
56
50
  return context.error(types_1.HTTPStatus.UnprocessableContent, {
57
51
  code: types_1.ACError.MalformedInput,
58
52
  });
@@ -65,15 +59,16 @@ const activate = async (payload, context) => {
65
59
  password: await bcrypt.hash(password, 10),
66
60
  },
67
61
  });
68
- return;
69
62
  }
70
- await context.collection.model.updateOne({
71
- _id: user._id,
72
- }, {
73
- $set: {
74
- active: true,
75
- },
76
- });
63
+ else {
64
+ await context.collection.model.updateOne({
65
+ _id: user._id,
66
+ }, {
67
+ $set: {
68
+ active: true,
69
+ },
70
+ });
71
+ }
77
72
  // if( context.request.method === 'GET' ) {
78
73
  // return context.response.writeHead(302, {
79
74
  // location: '/user/activation',
@@ -53,29 +53,23 @@ export const activate = async (payload, context) => {
53
53
  code: ACError.MalformedInput
54
54
  });
55
55
  }
56
- await context.collection.model.updateOne(
57
- {
58
- _id: user._id
59
- },
60
- {
61
- $set: {
62
- active: true,
63
- password: await bcrypt.hash(password, 10)
64
- }
56
+ await context.collection.model.updateOne({
57
+ _id: user._id
58
+ }, {
59
+ $set: {
60
+ active: true,
61
+ password: await bcrypt.hash(password, 10)
65
62
  }
66
- );
67
- return;
68
- }
69
- await context.collection.model.updateOne(
70
- {
63
+ });
64
+ } else {
65
+ await context.collection.model.updateOne({
71
66
  _id: user._id
72
- },
73
- {
67
+ }, {
74
68
  $set: {
75
69
  active: true
76
70
  }
77
- }
78
- );
71
+ });
72
+ }
79
73
  return Result.result({
80
74
  userId: user._id
81
75
  });
@@ -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.authenticated || !context.token.sub) {
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.authenticated || !context.token.sub) {
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
- what: {
39
- _id: payload._id,
40
- ...payload
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('step', 'password'),
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("step", "password"), url.searchParams.set("u", payload.userId.toString());
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;
@@ -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
- } | undefined>;
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;
@@ -994,7 +986,7 @@ export declare const collections: {
994
986
  readonly result: {
995
987
  readonly userId: import("mongodb").ObjectId;
996
988
  };
997
- } | undefined>;
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.227",
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.227",
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",