chore: Fix merge conflicts with master

This commit is contained in:
olivermrbl committed 2023-03-12 12:53:07 +01:00
commit 6d928628a9
29 files changed
+471 -56

No files matched your search

+7
View File
@@ -1,5 +1,12 @@
# @medusajs/inventory
## 1.0.9
### Patch Changes
- Updated dependencies [[`ce577f269`](https://github.com/medusajs/medusa/commit/ce577f2696aa2181bef8f3096b1a639feabe2714), [`aa0d1f321`](https://github.com/medusajs/medusa/commit/aa0d1f32153f82c6219efe5cfc08862db5e5a129), [`9f508c8bd`](https://github.com/medusajs/medusa/commit/9f508c8bd8bee63677504cc8b86f1643579945d8)]:
- @medusajs/medusa@1.7.12
## 1.0.8
### Patch Changes
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@medusajs/inventory",
"version": "1.0.8",
"version": "1.0.9",
"description": "Inventory Module for Medusa",
"main": "dist/index.js",
"repository": {
@@ -35,7 +35,7 @@
"test:unit": "jest --passWithNoTests"
},
"peerDependencies": {
"@medusajs/medusa": "1.7.11",
"@medusajs/medusa": "1.7.12",
"typeorm": "^0.3.11"
}
}
+10
View File
@@ -1,5 +1,15 @@
# Change Log
## 1.7.12
### Patch Changes
- [#3394](https://github.com/medusajs/medusa/pull/3394) [`ce577f269`](https://github.com/medusajs/medusa/commit/ce577f2696aa2181bef8f3096b1a639feabe2714) Thanks [@olivermrbl](https://github.com/olivermrbl)! - feat(medusa): Add global job options for events
- [#3388](https://github.com/medusajs/medusa/pull/3388) [`aa0d1f321`](https://github.com/medusajs/medusa/commit/aa0d1f32153f82c6219efe5cfc08862db5e5a129) Thanks [@olivermrbl](https://github.com/olivermrbl)! - fix(medusa): Remove default job age option from EventBus
- [#3384](https://github.com/medusajs/medusa/pull/3384) [`9f508c8bd`](https://github.com/medusajs/medusa/commit/9f508c8bd8bee63677504cc8b86f1643579945d8) Thanks [@pKorsholm](https://github.com/pKorsholm)! - Fix(medusa): Column naming on migrations
## 1.7.11
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@medusajs/medusa",
"version": "1.7.11",
"version": "1.7.12",
"description": "E-commerce for JAMstack",
"main": "dist/index.js",
"bin": "./cli.js",
@@ -14,7 +14,7 @@ export class multiLocation1671711415179 implements MigrationInterface {
`CREATE INDEX "IDX_c2203162ca946a71aeb98390b0" ON "sales_channel_location" ("location_id") `
)
await queryRunner.query(
`CREATE TABLE "product_variant_inventory_item" ("id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "inventory_item_id" text NOT NULL, "variant_id" text NOT NULL, "required_quantity" integer NOT NULL DEFAULT '1', CONSTRAINT "UQ_c9be7c1b11a1a729eb51d1b6bca" UNIQUE ("variant_id", "inventory_item_id"), CONSTRAINT "PK_9a1188b8d36f4d198303b4f7efa" PRIMARY KEY ("id"))`
`CREATE TABLE "product_variant_inventory_item" ("id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "inventory_item_id" text NOT NULL, "variant_id" text NOT NULL, "quantity" integer NOT NULL DEFAULT '1', CONSTRAINT "UQ_c9be7c1b11a1a729eb51d1b6bca" UNIQUE ("variant_id", "inventory_item_id"), CONSTRAINT "PK_9a1188b8d36f4d198303b4f7efa" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_c74e8c2835094a37dead376a3b" ON "product_variant_inventory_item" ("inventory_item_id") `
@@ -0,0 +1,31 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class ensureRequiredQuantity1678093365811 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DO
$$
BEGIN
ALTER TABLE product_variant_inventory_item
RENAME COLUMN quantity TO required_quantity;
EXCEPTION
WHEN undefined_column THEN
END;
$$;
`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DO
$$
BEGIN
ALTER TABLE product_variant_inventory_item
RENAME COLUMN required_quantity TO quantity;
EXCEPTION
WHEN undefined_column THEN
END;
$$;
`)
}
}
@@ -1,5 +1,5 @@
import CustomShippingOptionService from "../custom-shipping-option"
import { MockManager, MockRepository } from "medusa-test-utils"
import CustomShippingOptionService from "../custom-shipping-option"
describe("CustomShippingOptionService", () => {
describe("list", () => {
@@ -118,19 +118,17 @@ describe("CustomShippingOptionService", () => {
cart_id: "test-cso-cart",
shipping_option_id: "test-so",
price: 30,
metadata: undefined,
},
])
expect(customShippingOptionRepository.save).toHaveBeenCalledTimes(1)
expect(customShippingOptionRepository.save).toHaveBeenCalledWith({
id: "test-cso",
0: {
cart_id: "test-cso-cart",
shipping_option_id: "test-so",
price: 30,
metadata: undefined,
},
id: "test-cso",
})
})
})
@@ -141,6 +141,149 @@ describe("EventBusService", () => {
expect(eventBus.queue_.add).toHaveBeenCalled()
})
})
describe("successfully adds job to queue with local options", () => {
beforeAll(() => {
jest.resetAllMocks()
const stagedJobRepository = MockRepository({
find: () => Promise.resolve([]),
})
eventBus = new EventBusService({
logger: loggerMock,
manager: MockManager,
stagedJobRepository,
})
eventBus.queue_.add.mockImplementationOnce(() => "hi")
job = eventBus.emit(
"eventName",
{ hi: "1234" },
{ removeOnComplete: 100 }
)
})
afterAll(async () => {
await eventBus.stopEnqueuer()
})
it("calls queue.add", () => {
expect(eventBus.queue_.add).toHaveBeenCalled()
expect(eventBus.queue_.add).toHaveBeenCalledWith(
{ eventName: "eventName", data: { hi: "1234" } },
{ removeOnComplete: 100 }
)
})
})
describe("successfully adds job to queue with global options", () => {
beforeAll(() => {
jest.resetAllMocks()
const stagedJobRepository = MockRepository({
find: () => Promise.resolve([]),
})
eventBus = new EventBusService(
{
logger: loggerMock,
manager: MockManager,
stagedJobRepository,
},
{
projectConfig: { event_options: { removeOnComplete: 10 } },
}
)
eventBus.queue_.add.mockImplementationOnce(() => "hi")
job = eventBus.emit("eventName", { hi: "1234" })
})
afterAll(async () => {
await eventBus.stopEnqueuer()
})
it("calls queue.add", () => {
expect(eventBus.queue_.add).toHaveBeenCalled()
expect(eventBus.queue_.add).toHaveBeenCalledWith(
{ eventName: "eventName", data: { hi: "1234" } },
{ removeOnComplete: 10, attempts: 1 }
)
})
})
describe("successfully adds job to queue with default options", () => {
beforeAll(() => {
jest.resetAllMocks()
const stagedJobRepository = MockRepository({
find: () => Promise.resolve([]),
})
eventBus = new EventBusService({
logger: loggerMock,
manager: MockManager,
stagedJobRepository,
})
eventBus.queue_.add.mockImplementationOnce(() => "hi")
job = eventBus.emit("eventName", { hi: "1234" })
})
afterAll(async () => {
await eventBus.stopEnqueuer()
})
it("calls queue.add", () => {
expect(eventBus.queue_.add).toHaveBeenCalled()
expect(eventBus.queue_.add).toHaveBeenCalledWith(
{ eventName: "eventName", data: { hi: "1234" } },
{ removeOnComplete: true, attempts: 1 }
)
})
})
describe("successfully adds job to queue with local options and global options merged", () => {
beforeAll(() => {
jest.resetAllMocks()
const stagedJobRepository = MockRepository({
find: () => Promise.resolve([]),
})
eventBus = new EventBusService(
{
logger: loggerMock,
manager: MockManager,
stagedJobRepository,
},
{
projectConfig: { event_options: { removeOnComplete: 10 } },
}
)
eventBus.queue_.add.mockImplementationOnce(() => "hi")
job = eventBus.emit(
"eventName",
{ hi: "1234" },
{ attempts: 10, delay: 1000, backoff: { type: "exponential" } }
)
})
afterAll(async () => {
await eventBus.stopEnqueuer()
})
it("calls queue.add", () => {
expect(eventBus.queue_.add).toHaveBeenCalled()
expect(eventBus.queue_.add).toHaveBeenCalledWith(
{ eventName: "eventName", data: { hi: "1234" } },
{
removeOnComplete: 10, // global option
attempts: 10, // local option
delay: 1000, // local option
backoff: { type: "exponential" }, // local option
}
)
})
})
})
describe("worker", () => {
+21 -21
View File
@@ -1,6 +1,26 @@
import { isEmpty, isEqual } from "lodash"
import { isDefined, MedusaError } from "medusa-core-utils"
import { DeepPartial, EntityManager, In, IsNull, Not } from "typeorm"
import {
CustomerService,
CustomShippingOptionService,
DiscountService,
EventBusService,
GiftCardService,
LineItemAdjustmentService,
LineItemService,
NewTotalsService,
PaymentProviderService,
ProductService,
ProductVariantInventoryService,
ProductVariantService,
RegionService,
SalesChannelService,
ShippingOptionService,
StoreService,
TaxProviderService,
TotalsService,
} from "."
import { IPriceSelectionStrategy, TransactionBaseService } from "../interfaces"
import SalesChannelFeatureFlag from "../loaders/feature-flags/sales-channels"
import {
@@ -36,30 +56,10 @@ import {
TotalField,
WithRequiredProperty,
} from "../types/common"
import { PaymentSessionInput } from "../types/payment"
import { buildQuery, isString, setMetadata } from "../utils"
import { FlagRouter } from "../utils/flag-router"
import { validateEmail } from "../utils/is-email"
import { PaymentSessionInput } from "../types/payment"
import {
CustomerService,
CustomShippingOptionService,
DiscountService,
EventBusService,
GiftCardService,
LineItemAdjustmentService,
LineItemService,
NewTotalsService,
PaymentProviderService,
ProductService,
ProductVariantInventoryService,
ProductVariantService,
RegionService,
SalesChannelService,
ShippingOptionService,
StoreService,
TaxProviderService,
TotalsService,
} from "."
type InjectedDependencies = {
manager: EntityManager
@@ -1,12 +1,11 @@
import { MedusaError } from "medusa-core-utils"
import { EntityManager } from "typeorm"
import { DeepPartial, EntityManager } from "typeorm"
import { TransactionBaseService } from "../interfaces"
import { CustomShippingOption } from "../models"
import { CustomShippingOptionRepository } from "../repositories/custom-shipping-option"
import { FindConfig, Selector } from "../types/common"
import { CreateCustomShippingOptionInput } from "../types/shipping-options"
import { buildQuery } from "../utils"
import { DeepPartial } from "typeorm/common/DeepPartial"
type InjectedDependencies = {
manager: EntityManager
@@ -87,7 +86,6 @@ class CustomShippingOptionService extends TransactionBaseService {
const customShippingOptionRepo = this.activeManager_.withRepository(
this.customShippingOptionRepository_
)
const data_ = (
Array.isArray(data) ? data : [data]
) as DeepPartial<CustomShippingOption>[]
+2 -2
View File
@@ -21,6 +21,7 @@ import { OrderRepository } from "../repositories/order"
import { PaymentRepository } from "../repositories/payment"
import { FindConfig } from "../types/common"
import { DraftOrderCreateProps } from "../types/draft-orders"
import { GenerateInputData } from "../types/line-item"
import { buildQuery } from "../utils"
import CartService from "./cart"
import CustomShippingOptionService from "./custom-shipping-option"
@@ -28,7 +29,6 @@ import EventBusService from "./event-bus"
import LineItemService from "./line-item"
import ProductVariantService from "./product-variant"
import ShippingOptionService from "./shipping-option"
import { GenerateInputData } from "../types/line-item"
type InjectedDependencies = {
manager: EntityManager
@@ -352,7 +352,7 @@ class DraftOrderService extends TransactionBaseService {
cart_id: createdCart.id,
}))
itemsToCreate.push(...toCreate)
promises.push(lineItemServiceTx.create(toCreate))
}
// custom line items can be added to a draft order
+8 -5
View File
@@ -49,8 +49,6 @@ export type EmitOptions = {
}
} & JobOptions
const COMPLETED_JOB_TTL = 10000
/**
* Can keep track of multiple subscribers to different events and run the
* subscribers when events happen. Events will run asynchronously.
@@ -227,10 +225,15 @@ export default class EventBusService {
data: T,
options: Record<string, unknown> & EmitOptions = { attempts: 1 }
): Promise<StagedJob | void> {
const globalEventOptions = this.config_?.projectConfig?.event_options ?? {}
// The order of precedence for job options is:
// 1. local options
// 2. global options
// 3. default options
const opts: EmitOptions = {
removeOnComplete: {
age: COMPLETED_JOB_TTL,
},
removeOnComplete: true,
...globalEventOptions,
...options,
}
+20
View File
@@ -7,6 +7,7 @@ import { Request } from "express"
import { LoggerOptions } from "typeorm"
import { Logger as _Logger } from "winston"
import { Customer, User } from "../models"
import { EmitOptions } from "../services/event-bus"
import { FindConfig, RequestQueryFields } from "./common"
declare global {
@@ -58,6 +59,25 @@ export type ConfigModule = {
projectConfig: {
redis_url?: string
/**
* Global options passed to all `EventBusService.emit` in the core as well as your own emitters. The options are forwarded to Bull's `Queue.add` method.
*
* The global options can be overridden by passing options to `EventBusService.emit` directly.
*
* Note: This will be deprecated as we move to Event Bus module in 1.8
*
*
* Example
* ```js
* {
* removeOnComplete: { age: 10 },
* }
* ```
*
* @see https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queueadd
*/
event_options?: Record<string, unknown> & EmitOptions
session_options?: SessionOptions
jwt_secret?: string