@aeriajs/builtins 0.0.285 → 0.0.287

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.
@@ -136,7 +136,7 @@ export const authenticate = async (props, context) => {
136
136
  }
137
137
  }
138
138
  const user = await context.collection.model.findOne({
139
- email: props.email,
139
+ email: props.email.toLowerCase(),
140
140
  }, {
141
141
  projection: {
142
142
  password: 1,
@@ -1,5 +1,4 @@
1
1
  import { defineContract, HTTPStatus, ACError, functionSchemas, endpointErrorSchema, resultSchema } from '@aeriajs/types';
2
- import { validate } from '@aeriajs/validation';
3
2
  import * as bcrypt from 'bcryptjs';
4
3
  import { insert as originalInsert } from '@aeriajs/core';
5
4
  import { description } from './description.js';
@@ -32,36 +31,13 @@ export const createAccountContract = defineContract({
32
31
  ],
33
32
  });
34
33
  export const createAccount = async (payload, context) => {
35
- const userCandidate = Object.assign({}, payload);
36
34
  if (!context.config.security.signup) {
37
35
  return context.error(HTTPStatus.Forbidden, {
38
36
  code: CreateAccountError.SignupDisallowed,
39
37
  });
40
38
  }
41
- const { error, result: user } = validate(userCandidate, {
42
- type: 'object',
43
- required: [
44
- 'name',
45
- 'email',
46
- ],
47
- properties: {
48
- name: {
49
- type: 'string',
50
- },
51
- email: {
52
- type: 'string',
53
- },
54
- password: {
55
- type: 'string',
56
- },
57
- },
58
- });
59
- if (error) {
60
- return context.error(HTTPStatus.UnprocessableContent, {
61
- code: ACError.MalformedInput,
62
- details: error,
63
- });
64
- }
39
+ const user = payload;
40
+ user.email = user.email.toLowerCase();
65
41
  const { roles, ...defaults } = context.config.security.signup;
66
42
  if (user.password) {
67
43
  user.password = await bcrypt.hash(user.password, 10);
@@ -26,6 +26,9 @@ export const insert = async (payload, context) => {
26
26
  if (!context.token.authenticated) {
27
27
  throw new Error;
28
28
  }
29
+ if ('email' in payload.what && typeof payload.what.email === 'string') {
30
+ payload.what.email = payload.what.email.toLowerCase();
31
+ }
29
32
  if ('roles' in payload.what) {
30
33
  if (context.config.security.rolesHierarchy) {
31
34
  if (!arraysIntersect(context.token.roles, Object.keys(context.config.security.rolesHierarchy))) {
@@ -32,7 +32,7 @@ export declare const describe: (contextOrPayload: RouteContext | typeof Payload)
32
32
  readonly error: {
33
33
  readonly httpStatus: 422;
34
34
  readonly code: "MALFORMED_INPUT";
35
- readonly details: import("@aeriajs/types").PropertyValidationError | import("@aeriajs/types").ValidationError;
35
+ readonly details: import("@aeriajs/types").ValidationError | import("@aeriajs/types").PropertyValidationError;
36
36
  };
37
37
  readonly result: undefined;
38
38
  } | {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aeriajs/builtins",
3
3
  "type": "module",
4
- "version": "0.0.285",
4
+ "version": "0.0.287",
5
5
  "description": "## Installation",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@aeriajs/common": "^0.0.161",
45
- "@aeriajs/core": "^0.0.285",
45
+ "@aeriajs/core": "^0.0.287",
46
46
  "@aeriajs/entrypoint": "^0.0.169",
47
47
  "@aeriajs/types": "^0.0.137",
48
48
  "@aeriajs/validation": "^0.0.185"