chore(medusa): Remove deprecated dependency @hapi/joi (#2069)

This commit is contained in:
Oliver Windall Juhl
2022-09-05 16:03:06 +02:00
committed by GitHub
parent ba6416f095
commit ad717b9533
16 changed files with 91 additions and 23109 deletions
-1
View File
@@ -36,7 +36,6 @@
"fs-extra": "^10.0.0",
"hosted-git-info": "^4.0.2",
"is-valid-path": "^0.1.1",
"joi": "^17.4.2",
"microbundle": "^0.13.3",
"node-fetch": "^2.6.1",
"prettier": "^2.3.2",
-2
View File
@@ -37,7 +37,6 @@
"dependencies": {
"@babel/polyfill": "^7.8.7",
"@babel/runtime": "^7.9.6",
"@hapi/joi": "^16.1.8",
"axios": "^0.21.1",
"chalk": "^4.0.0",
"configstore": "5.0.1",
@@ -49,7 +48,6 @@
"hosted-git-info": "^4.0.2",
"inquirer": "^8.0.0",
"is-valid-path": "^0.1.1",
"joi-objectid": "^3.0.1",
"meant": "^1.0.1",
"medusa-core-utils": "^0.1.27",
"medusa-telemetry": "0.0.13",
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-3
View File
@@ -47,7 +47,6 @@
"typeorm": "0.2.x"
},
"dependencies": {
"@hapi/joi": "^16.1.8",
"@medusajs/medusa-cli": "^1.3.1",
"@types/ioredis": "^4.28.10",
"@types/lodash": "^4.14.168",
@@ -69,8 +68,6 @@
"ioredis": "^4.17.3",
"ioredis-mock": "^5.6.0",
"iso8601-duration": "^1.3.0",
"joi": "^17.3.0",
"joi-objectid": "^3.0.1",
"jsonwebtoken": "^8.5.1",
"medusa-core-utils": "^1.1.31",
"medusa-test-utils": "^1.1.37",
@@ -55,7 +55,6 @@ describe("POST /invites", () => {
})
it("calls InviteService create", () => {
console.log(subject.error)
expect(InviteServiceMock.create).toHaveBeenCalledTimes(1)
expect(InviteServiceMock.create).toHaveBeenCalledWith(
"lebron@james.com",
@@ -77,7 +77,6 @@ describe("GET /admin/regions", () => {
})
it("returns 200", () => {
console.log(subject)
expect(subject.status).toEqual(200)
})
@@ -138,7 +138,6 @@ describe("InviteService", () => {
it("fails to accept an with an invalid token", async () => {
expect.assertions(2)
await inviteService.accept("totally.valid.token", {}).catch((err) => {
console.log(err)
expect(err.message).toEqual("Token is not valid")
expect(err.type).toEqual("invalid_data")
})
@@ -90,7 +90,7 @@ describe("SalesChannelService", () => {
}),
}
describe("create default", async () => {
describe("create default", () => {
const salesChannelService = new SalesChannelService({
manager: MockManager,
eventBusService: EventBusServiceMock as unknown as EventBusService,
+5 -11
View File
@@ -1,5 +1,5 @@
import { isEmpty, isEqual } from "lodash"
import { MedusaError, Validator } from "medusa-core-utils"
import { MedusaError } from "medusa-core-utils"
import { DeepPartial, EntityManager, In } from "typeorm"
import { TransactionBaseService } from "../interfaces"
import { IPriceSelectionStrategy } from "../interfaces/price-selection-strategy"
@@ -30,6 +30,7 @@ import {
import { AddressPayload, FindConfig, TotalField } from "../types/common"
import { buildQuery, isDefined, setMetadata, validateId } from "../utils"
import { FlagRouter } from "../utils/flag-router"
import { validateEmail } from "../utils/is-email"
import CustomShippingOptionService from "./custom-shipping-option"
import CustomerService from "./customer"
import DiscountService from "./discount"
@@ -1049,24 +1050,17 @@ class CartService extends TransactionBaseService {
protected async createOrFetchUserFromEmail_(
email: string
): Promise<Customer> {
const schema = Validator.string().email().required()
const { value, error } = schema.validate(email.toLowerCase())
if (error) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"The email is not valid"
)
}
const validatedEmail = validateEmail(email)
let customer = await this.customerService_
.withTransaction(this.transactionManager_)
.retrieveByEmail(value)
.retrieveByEmail(validatedEmail)
.catch(() => undefined)
if (!customer) {
customer = await this.customerService_
.withTransaction(this.transactionManager_)
.create({ email: value })
.create({ email: validatedEmail })
}
return customer
+5 -22
View File
@@ -1,7 +1,8 @@
import jwt from "jsonwebtoken"
import { MedusaError } from "medusa-core-utils"
import Scrypt from "scrypt-kdf"
import { MedusaError, Validator } from "medusa-core-utils"
import { EntityManager } from "typeorm"
import { TransactionBaseService } from "../interfaces"
import { User } from "../models"
import { UserRepository } from "../repositories/user"
import { FindConfig } from "../types/common"
@@ -10,9 +11,9 @@ import {
FilterableUserProps,
UpdateUserInput,
} from "../types/user"
import EventBusService from "./event-bus"
import { TransactionBaseService } from "../interfaces"
import { buildQuery, setMetadata } from "../utils"
import { validateEmail } from "../utils/is-email"
import EventBusService from "./event-bus"
type UserServiceProps = {
userRepository: typeof UserRepository
@@ -45,24 +46,6 @@ class UserService extends TransactionBaseService {
this.manager_ = manager
}
/**
* Used to validate user email.
* @param {string} email - email to validate
* @return {string} the validated email
*/
validateEmail_(email: string): string {
const schema = Validator.string().email().required()
const { value, error } = schema.validate(email)
if (error) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"The email is not valid"
)
}
return value.toLowerCase()
}
/**
* @param {FilterableUserProps} selector - the query object for find
* @param {Object} config - the configuration object for the query
@@ -179,7 +162,7 @@ class UserService extends TransactionBaseService {
password_hash: string
}
const validatedEmail = this.validateEmail_(user.email)
const validatedEmail = validateEmail(user.email)
if (password) {
const hashedPassword = await this.hashPassword_(password)
createData.password_hash = hashedPassword
+20
View File
@@ -0,0 +1,20 @@
import { isEmail } from "class-validator"
import { MedusaError } from "medusa-core-utils"
/**
* Used to validate user email.
* @param {string} email - email to validate
* @return {string} the validated email
*/
export function validateEmail(email: string): string {
const validatedEmail = isEmail(email)
if (!validatedEmail) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"The email is not valid"
)
}
return email.toLowerCase()
}