Merge branch 'master' of github.com:medusajs/medusa

This commit is contained in:
--list
2021-06-28 12:42:38 +02:00
95 changed files with 1412 additions and 782 deletions
+24
View File
@@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.1.28](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.27...@medusajs/medusa@1.1.28) (2021-06-24)
**Note:** Version bump only for package @medusajs/medusa
## [1.1.27](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.26...@medusajs/medusa@1.1.27) (2021-06-22)
### Bug Fixes
* adds transformer to map field names to field_id names ([88d96a2](https://github.com/medusajs/medusa/commit/88d96a29fd8dbc44ed7ba25154850d417577acad))
* giftcard-order relation ([c88c407](https://github.com/medusajs/medusa/commit/c88c4070960ad1a8126e65b1e9f60d7ba929246a))
* lint ([5829550](https://github.com/medusajs/medusa/commit/58295505178209d511046089d736395d121b9732))
* mobile pay support ([91511cb](https://github.com/medusajs/medusa/commit/91511cbdf8bc66f5688a36ecf56edb16a220cc82))
* region sync ([8e29e6e](https://github.com/medusajs/medusa/commit/8e29e6e63c305b684a37d817b504b3e471d697bd))
* release assist ([668e8a7](https://github.com/medusajs/medusa/commit/668e8a740200847fc2a41c91d2979097f1392532))
## [1.1.26](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.25...@medusajs/medusa@1.1.26) (2021-06-10)
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@medusajs/medusa",
"version": "1.1.26",
"version": "1.1.28",
"description": "E-commerce for JAMstack",
"main": "dist/index.js",
"repository": {
@@ -17,11 +17,11 @@
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.3",
"@babel/preset-typescript": "^7.13.0",
"babel-preset-medusa-package": "^1.1.8",
"babel-preset-medusa-package": "^1.1.9",
"cross-env": "^5.2.1",
"eslint": "^6.8.0",
"jest": "^25.5.2",
"medusa-interfaces": "^1.1.15",
"medusa-interfaces": "^1.1.16",
"nodemon": "^2.0.1",
"prettier": "^1.19.1",
"supertest": "^4.0.2"
@@ -59,8 +59,8 @@
"joi": "^17.3.0",
"joi-objectid": "^3.0.1",
"jsonwebtoken": "^8.5.1",
"medusa-core-utils": "^1.1.14",
"medusa-test-utils": "^1.1.17",
"medusa-core-utils": "^1.1.15",
"medusa-test-utils": "^1.1.18",
"morgan": "^1.9.1",
"multer": "^1.4.2",
"passport": "^0.4.0",
@@ -78,5 +78,5 @@
"uuid": "^8.3.1",
"winston": "^3.2.1"
},
"gitHead": "245ccdc4774965cdd27d4dbdb5fbb084c8066c66"
"gitHead": "db9d6c0cf55ff60a90415b16bc7582cc4795768f"
}
@@ -1,4 +1,8 @@
import { MedusaError, Validator } from "medusa-core-utils"
import {
MedusaError,
Validator,
transformIdableFields,
} from "medusa-core-utils"
import { defaultFields, defaultRelations } from "."
/**
@@ -133,11 +137,13 @@ export default async (req, res) => {
metadata: Validator.object().optional(),
})
const { value, error } = schema.validate(req.body)
let { value, error } = schema.validate(req.body)
if (error) {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
value = transformIdableFields(value, ["shipping_address", "billing_address"])
try {
const draftOrderService = req.scope.resolve("draftOrderService")
let draftOrder = await draftOrderService.create(value)
@@ -10,10 +10,10 @@ describe("POST /store/carts/:id/payment-session/update", () => {
const cartId = IdMap.getId("cartWithPaySessions")
subject = await request(
"POST",
`/store/carts/${cartId}/payment-session/update`,
`/store/carts/${cartId}/payment-sessions/default_provider`,
{
payload: {
session: {
data: {
data: "Something",
},
},
@@ -26,6 +26,12 @@ describe("POST /store/carts/:id/payment-session/update", () => {
})
it("calls CartService updatePaymentSession", () => {
expect(CartServiceMock.setPaymentSession).toHaveBeenCalledTimes(1)
expect(CartServiceMock.setPaymentSession).toHaveBeenCalledWith(
IdMap.getId("cartWithPaySessions"),
"default_provider"
)
expect(CartServiceMock.updatePaymentSession).toHaveBeenCalledTimes(1)
expect(CartServiceMock.updatePaymentSession).toHaveBeenCalledWith(
IdMap.getId("cartWithPaySessions"),
@@ -1,7 +1,7 @@
import { MedusaError } from "medusa-core-utils"
/**
* @oas [post] /carts/{id}/complete-cart
* @oas [post] /carts/{id}/complete
* summary: "Complete a Cart"
* operationId: "PostCartsCartComplete"
* description: "Completes a cart. The following steps will be performed. Payment
@@ -24,6 +24,12 @@ export default (app, container) => {
route.post("/:id", middlewares.wrap(require("./update-cart").default))
route.post(
"/:id/complete",
middlewares.wrap(require("./complete-cart").default)
)
// DEPRECATION
route.post(
"/:id/complete-cart",
middlewares.wrap(require("./complete-cart").default)
@@ -55,7 +61,7 @@ export default (app, container) => {
)
route.post(
"/:id/payment-session/update",
"/:id/payment-sessions/:provider_id",
middlewares.wrap(require("./update-payment-session").default)
)
@@ -2,12 +2,13 @@ import { Validator, MedusaError } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
/**
* @oas [post] /carts/{id}/payment-session/update
* @oas [post] /carts/{id}/payment-sessions/{provider_id}
* operationId: PostCartsCartPaymentSessionUpdate
* summary: Update a Payment Session
* description: "Updates a Payment Session with additional data."
* parameters:
* - (path) id=* {string} The id of the Cart.
* - (path) provider_id=* {string} The id of the payment provider.
* - (body) provider_id=* {string} The id of the Payment Provider responsible for the Payment Session to update.
* - (body) data=* {object} The data to update the payment session with.
* tags:
@@ -23,10 +24,10 @@ import { defaultFields, defaultRelations } from "./"
* $ref: "#/components/schemas/cart"
*/
export default async (req, res) => {
const { id } = req.params
const { id, provider_id } = req.params
const schema = Validator.object().keys({
session: Validator.object().required(),
data: Validator.object().required(),
})
const { value, error } = schema.validate(req.body)
@@ -37,7 +38,8 @@ export default async (req, res) => {
try {
const cartService = req.scope.resolve("cartService")
await cartService.updatePaymentSession(id, value.session)
await cartService.setPaymentSession(id, provider_id)
await cartService.updatePaymentSession(id, value.data)
const cart = await cartService.retrieve(id, {
select: defaultFields,
@@ -0,0 +1,31 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class gcRemoveUniqueOrder1624287602631 implements MigrationInterface {
name = "gcRemoveUniqueOrder1624287602631"
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`
)
await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`)
await queryRunner.query(
`ALTER TABLE "gift_card" DROP CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb"`
)
await queryRunner.query(
`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "gift_card" DROP CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0"`
)
await queryRunner.query(
`ALTER TABLE "gift_card" ADD CONSTRAINT "REL_dfc1f02bb0552e79076aa58dbb" UNIQUE ("order_id")`
)
await queryRunner.query(`COMMENT ON COLUMN "gift_card"."order_id" IS NULL`)
await queryRunner.query(
`ALTER TABLE "gift_card" ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY ("order_id") REFERENCES "order"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
}
}
+1 -2
View File
@@ -8,7 +8,6 @@ import {
Column,
PrimaryColumn,
ManyToOne,
OneToOne,
JoinColumn,
} from "typeorm"
import { ulid } from "ulid"
@@ -43,7 +42,7 @@ export class GiftCard {
@Column({ nullable: true })
order_id: string
@OneToOne(() => Order)
@ManyToOne(() => Order)
@JoinColumn({ name: "order_id" })
order: Order
@@ -323,6 +323,9 @@ export const CartServiceMock = {
applyDiscount: jest.fn().mockImplementation((cartId, code) => {
return Promise.resolve()
}),
setPaymentSession: jest.fn().mockImplementation(cartId => {
return Promise.resolve()
}),
setPaymentSessions: jest.fn().mockImplementation(cartId => {
return Promise.resolve()
}),
@@ -1,6 +1,14 @@
import { IdMap, MockManager, MockRepository } from "medusa-test-utils"
import RegionService from "../region"
const eventBusService = {
emit: jest.fn(),
withTransaction: function() {
return this
},
}
describe("RegionService", () => {
describe("create", () => {
const regionRepository = MockRepository({})
@@ -58,6 +66,7 @@ describe("RegionService", () => {
const regionService = new RegionService({
manager: MockManager,
eventBusService,
fulfillmentProviderRepository: fpRepository,
paymentProviderRepository: ppRepository,
currencyRepository,
@@ -168,6 +177,7 @@ describe("RegionService", () => {
const regionService = new RegionService({
manager: MockManager,
eventBusService,
regionRepository,
})
@@ -237,6 +247,7 @@ describe("RegionService", () => {
const regionService = new RegionService({
manager: MockManager,
eventBusService,
fulfillmentProviderRepository: fpRepository,
paymentProviderRepository: ppRepository,
regionRepository,
@@ -335,6 +346,7 @@ describe("RegionService", () => {
const regionService = new RegionService({
manager: MockManager,
eventBusService,
fulfillmentProviderRepository: fpRepository,
paymentProviderRepository: ppRepository,
regionRepository,
@@ -380,6 +392,7 @@ describe("RegionService", () => {
const regionService = new RegionService({
manager: MockManager,
eventBusService,
regionRepository,
})
@@ -429,6 +442,7 @@ describe("RegionService", () => {
const regionService = new RegionService({
manager: MockManager,
eventBusService,
regionRepository,
countryRepository,
})
@@ -473,6 +487,7 @@ describe("RegionService", () => {
const regionService = new RegionService({
manager: MockManager,
eventBusService,
regionRepository,
})
@@ -522,6 +537,7 @@ describe("RegionService", () => {
const regionService = new RegionService({
manager: MockManager,
eventBusService,
fulfillmentProviderRepository: fpRepository,
paymentProviderRepository: ppRepository,
regionRepository,
@@ -582,6 +598,7 @@ describe("RegionService", () => {
const regionService = new RegionService({
manager: MockManager,
eventBusService,
fulfillmentProviderRepository: fpRepository,
regionRepository,
})
@@ -631,6 +648,7 @@ describe("RegionService", () => {
const regionService = new RegionService({
manager: MockManager,
eventBusService,
regionRepository,
})
@@ -665,6 +683,7 @@ describe("RegionService", () => {
const regionService = new RegionService({
manager: MockManager,
eventBusService,
regionRepository,
})
+8 -10
View File
@@ -306,8 +306,8 @@ class CartService extends BaseService {
const regCountries = region.countries.map(({ iso_2 }) => iso_2)
if (data.shipping_address && typeof data.shipping_address === `string`) {
const addr = await addressRepo.findOne(data.shipping_address)
if (data.shipping_address_id) {
const addr = await addressRepo.findOne(data.shipping_address_id)
data.shipping_address = addr
}
@@ -650,16 +650,14 @@ class CartService extends BaseService {
}
const addrRepo = manager.getCustomRepository(this.addressRepository_)
if ("shipping_address" in update) {
await this.updateShippingAddress_(
cart,
update.shipping_address,
addrRepo
)
if ("shipping_address_id" in update || "shipping_address" in update) {
const address = update.shipping_address_id || update.shipping_address
await this.updateShippingAddress_(cart, address, addrRepo)
}
if ("billing_address" in update) {
await this.updateBillingAddress_(cart, update.billing_address, addrRepo)
if ("billing_address_id" in update || "billing_address" in update) {
const address = update.billing_address_id || update.billing_address
await this.updateBillingAddress_(cart, address, addrRepo)
}
if ("discounts" in update) {
+1 -1
View File
@@ -162,7 +162,7 @@ class NotificationService extends BaseService {
handleEvent(eventName, data) {
const subs = this.subscribers_[eventName]
if (!subs) {
return
return Promise.resolve()
}
return Promise.all(
+6 -3
View File
@@ -110,10 +110,13 @@ class OrderService extends BaseService {
shippingOptionService: this.shippingOptionService_,
shippingProfileService: this.shippingProfileService_,
fulfillmentProviderService: this.fulfillmentProviderService_,
fulfillmentService: this.fulfillmentService_,
customerService: this.customerService_,
discountService: this.discountService_,
totalsService: this.totalsService_,
cartService: this.cartService_,
giftCardService: this.giftCardService_,
addressRepository: this.addressRepository_,
draftOrderService: this.draftOrderService_,
})
@@ -467,9 +470,9 @@ class OrderService extends BaseService {
)
}
const paymentStatus = await this.paymentProviderService_.getStatus(
payment
)
const paymentStatus = await this.paymentProviderService_
.withTransaction(manager)
.getStatus(payment)
// If payment status is not authorized, we throw
if (paymentStatus !== "authorized" && paymentStatus !== "succeeded") {
+65 -14
View File
@@ -8,11 +8,17 @@ import { countries } from "../utils/countries"
* @implements BaseService
*/
class RegionService extends BaseService {
static Events = {
UPDATED: "region.updated",
CREATED: "region.created",
}
constructor({
manager,
regionRepository,
countryRepository,
storeService,
eventBusService,
currencyRepository,
paymentProviderRepository,
fulfillmentProviderRepository,
@@ -33,6 +39,9 @@ class RegionService extends BaseService {
/** @private @const {StoreService} */
this.storeService_ = storeService
/** @private @const {EventBus} */
this.eventBus_ = eventBusService
/** @private @const {CurrencyRepository} */
this.currencyRepository_ = currencyRepository
@@ -60,6 +69,7 @@ class RegionService extends BaseService {
currencyRepository: this.currencyRepository_,
countryRepository: this.countryRepository_,
storeService: this.storeService_,
eventBusService: this.eventBus_,
paymentProviderRepository: this.paymentProviderRepository_,
paymentProviderService: this.paymentProviderService_,
fulfillmentProviderRepository: this.fulfillmentProviderRepository_,
@@ -117,6 +127,13 @@ class RegionService extends BaseService {
const created = regionRepository.create(regionObject)
const result = await regionRepository.save(created)
await this.eventBus_
.withTransaction(manager)
.emit(RegionService.Events.CREATED, {
id: result.id,
})
return result
})
}
@@ -168,6 +185,14 @@ class RegionService extends BaseService {
}
const result = await regionRepository.save(region)
await this.eventBus_
.withTransaction(manager)
.emit(RegionService.Events.UPDATED, {
id: result.id,
fields: Object.keys(update),
})
return result
})
}
@@ -390,6 +415,14 @@ class RegionService extends BaseService {
region.countries = [...(region.countries || []), country]
const updated = await regionRepo.save(region)
await this.eventBus_
.withTransaction(manager)
.emit(RegionService.Events.UPDATED, {
id: updated.id,
fields: ["countries"],
})
return updated
})
}
@@ -419,6 +452,12 @@ class RegionService extends BaseService {
)
const updated = await regionRepo.save(region)
await this.eventBus_
.withTransaction(manager)
.emit(RegionService.Events.UPDATED, {
id: updated.id,
fields: ["countries"],
})
return updated
})
}
@@ -458,6 +497,14 @@ class RegionService extends BaseService {
region.payment_providers = [...region.payment_providers, pp]
const updated = await regionRepo.save(region)
await this.eventBus_
.withTransaction(manager)
.emit(RegionService.Events.UPDATED, {
id: updated.id,
fields: ["payment_providers"],
})
return updated
})
}
@@ -497,6 +544,12 @@ class RegionService extends BaseService {
region.fulfillment_providers = [...region.fulfillment_providers, fp]
const updated = await regionRepo.save(region)
await this.eventBus_
.withTransaction(manager)
.emit(RegionService.Events.UPDATED, {
id: updated.id,
fields: ["fulfillment_providers"],
})
return updated
})
}
@@ -525,6 +578,12 @@ class RegionService extends BaseService {
)
const updated = await regionRepo.save(region)
await this.eventBus_
.withTransaction(manager)
.emit(RegionService.Events.UPDATED, {
id: updated.id,
fields: ["payment_providers"],
})
return updated
})
}
@@ -553,23 +612,15 @@ class RegionService extends BaseService {
)
const updated = await regionRepo.save(region)
await this.eventBus_
.withTransaction(manager)
.emit(RegionService.Events.UPDATED, {
id: updated.id,
fields: ["fulfillment_providers"],
})
return updated
})
}
/**
* Decorates a region
* @param {object} region - the region to decorate
* @param {[string]} fields - the fields to include
* @param {[string]} expandFields - the fields to expand
* @return {Region} the region
*/
async decorate(region, fields, expandFields = []) {
const requiredFields = ["id", "metadata"]
const decorated = _.pick(region, fields.concat(requiredFields))
const final = await this.runDecorators_(decorated)
return final
}
}
export default RegionService