@aeriajs/builtins 0.0.283 → 0.0.285

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.
@@ -1,3 +1,4 @@
1
+ import { throwIfError } from '@aeriajs/common';
1
2
  import { signToken } from '@aeriajs/core';
2
3
  export const AuthenticationError = {
3
4
  InvalidCredentials: 'INVALID_CREDENTIALS',
@@ -27,7 +28,7 @@ export const successfulAuthentication = async (user, context) => {
27
28
  }
28
29
  tokenContent.userinfo = userinfo;
29
30
  }
30
- const token = await signToken(tokenContent);
31
+ const token = throwIfError(await signToken(tokenContent));
31
32
  return {
32
33
  user,
33
34
  token: {
@@ -37,11 +38,11 @@ export const successfulAuthentication = async (user, context) => {
37
38
  };
38
39
  };
39
40
  export const defaultSuccessfulAuthentication = async () => {
40
- const token = await signToken({
41
+ const token = throwIfError(await signToken({
41
42
  sub: null,
42
43
  roles: ['root'],
43
44
  userinfo: {},
44
- });
45
+ }));
45
46
  return {
46
47
  user: {
47
48
  _id: null,
@@ -79,8 +79,8 @@ export const activate = async (payload, context) => {
79
79
  code: ActivationError.AlreadyActiveUser,
80
80
  });
81
81
  }
82
- const decoded = await decodeToken(token, context.config.secret);
83
- if (!decoded) {
82
+ const { error } = await decodeToken(token, context.config.secret);
83
+ if (error) {
84
84
  return context.error(HTTPStatus.Unauthorized, {
85
85
  code: ActivationError.InvalidToken,
86
86
  });
@@ -108,7 +108,7 @@ export const authenticate = async (props, context) => {
108
108
  });
109
109
  }
110
110
  const decodedToken = token
111
- ? await decodeToken(token.content)
111
+ ? throwIfError(await decodeToken(token.content))
112
112
  : context.token;
113
113
  if (!decodedToken.sub) {
114
114
  return Result.result(await defaultSuccessfulAuthentication());
@@ -33,7 +33,7 @@ export const createAccountContract = defineContract({
33
33
  });
34
34
  export const createAccount = async (payload, context) => {
35
35
  const userCandidate = Object.assign({}, payload);
36
- if (!context.config.security.allowSignup) {
36
+ if (!context.config.security.signup) {
37
37
  return context.error(HTTPStatus.Forbidden, {
38
38
  code: CreateAccountError.SignupDisallowed,
39
39
  });
@@ -62,10 +62,7 @@ export const createAccount = async (payload, context) => {
62
62
  details: error,
63
63
  });
64
64
  }
65
- let roles = [], defaults = {};
66
- if (context.config.security.signupDefaults) {
67
- ({ roles = [], ...defaults } = context.config.security.signupDefaults);
68
- }
65
+ const { roles, ...defaults } = context.config.security.signup;
69
66
  if (user.password) {
70
67
  user.password = await bcrypt.hash(user.password, 10);
71
68
  }
@@ -1,3 +1,4 @@
1
+ import { throwIfError } from '@aeriajs/common';
1
2
  import { signToken } from '@aeriajs/core';
2
3
  import { Result, HTTPStatus, defineContract, resultSchema, endpointErrorSchema, functionSchemas } from '@aeriajs/types';
3
4
  import { ActivationError } from './activate.js';
@@ -44,11 +45,11 @@ export const getActivationToken = async (userId, context) => {
44
45
  if (!context.config.secret) {
45
46
  throw new Error('config.secret is not set');
46
47
  }
47
- const token = await signToken({
48
+ const token = throwIfError(await signToken({
48
49
  data: userId,
49
50
  }, context.config.secret, {
50
51
  expiresIn: context.config.security.linkTokenExpiration,
51
- });
52
+ }));
52
53
  return token;
53
54
  };
54
55
  export const getActivationLink = async (payload, context) => {
@@ -80,8 +80,8 @@ export const redefinePassword = async (payload, context) => {
80
80
  code: RedefinePasswordError.UserNotActive,
81
81
  });
82
82
  }
83
- const decoded = await decodeToken(token, context.config.secret);
84
- if (!decoded) {
83
+ const { error } = await decodeToken(token, context.config.secret);
84
+ if (error) {
85
85
  return context.error(HTTPStatus.Unauthorized, {
86
86
  code: RedefinePasswordError.InvalidToken,
87
87
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aeriajs/builtins",
3
3
  "type": "module",
4
- "version": "0.0.283",
4
+ "version": "0.0.285",
5
5
  "description": "## Installation",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -41,11 +41,11 @@
41
41
  "mongodb": "^6.18.0"
42
42
  },
43
43
  "peerDependencies": {
44
- "@aeriajs/common": "^0.0.160",
45
- "@aeriajs/core": "^0.0.283",
46
- "@aeriajs/entrypoint": "^0.0.168",
47
- "@aeriajs/types": "^0.0.136",
48
- "@aeriajs/validation": "^0.0.184"
44
+ "@aeriajs/common": "^0.0.161",
45
+ "@aeriajs/core": "^0.0.285",
46
+ "@aeriajs/entrypoint": "^0.0.169",
47
+ "@aeriajs/types": "^0.0.137",
48
+ "@aeriajs/validation": "^0.0.185"
49
49
  },
50
50
  "scripts": {
51
51
  "test": "echo skipping",