diff --git a/.changeset/many-wolves-sit.md b/.changeset/many-wolves-sit.md new file mode 100644 index 0000000000..66b8ab755d --- /dev/null +++ b/.changeset/many-wolves-sit.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +chores(medusa): Improve draft order creation perf flow diff --git a/docs/content/add-plugins/sendgrid.mdx b/docs/content/add-plugins/sendgrid.mdx index d524ab7cb4..fcfc25be87 100644 --- a/docs/content/add-plugins/sendgrid.mdx +++ b/docs/content/add-plugins/sendgrid.mdx @@ -3917,7 +3917,7 @@ Then, in your `.env` file add the API key you created earlier as well as the sen ```bash SENDGRID_API_KEY= -SENDGRID_FROM= +SENDGRID_FROM= ``` Make sure to replace the `` with the SendGrid API key and the `` with the email you’re using in SendGrid as the single sender. diff --git a/docs/content/advanced/backend/migrations/index.md b/docs/content/advanced/backend/migrations/index.md index 7f2ad29417..f82475a263 100644 --- a/docs/content/advanced/backend/migrations/index.md +++ b/docs/content/advanced/backend/migrations/index.md @@ -7,7 +7,7 @@ addHowToData: true In this document, you’ll learn how to create a [Migration](overview.md) using [Typeorm](https://typeorm.io) on your Medusa server. -## Create Migration File +## Step 1: Create Migration File To create a migration that makes changes to your Medusa schema, run the following command: @@ -19,15 +19,62 @@ This will create the migration file in the path you specify. You can use this wi The migration file must be inside the `src/migrations` directory. When you run the build command, it will be transpiled into the directory `dist/migrations`. The `migrations run` command can only pick up migrations under the `dist/migrations` directory on a Medusa server. This applies to migrations created in a Medusa server, and not in a Medusa plugin. For plugins, check out the [Plugin's Structure section](../plugins/create.md). -:::tip +
+ Generating Migrations for Entities -You can alternatively use Typeorm's `generate` command to generate a Migration file from existing database tables, which requires setting up a data source in Typeorm. Check out Typeorm's documentation to learn [how to create a data source](https://typeorm.io/data-source#creating-a-new-datasource), then use the [generate command](https://typeorm.io/using-cli#generate-a-migration-from-existing-table-schema). + You can alternatively use Typeorm's `generate` command to generate a Migration file from existing entity classes. As Medusa uses v0.2.45 of Typeorm, you have to create a `ormconfig.json` first before using the `generate` command. + +:::note + +Typeorm will be updated to the latest version in v1.8.0 of Medusa. ::: + For example, create the file `ormconfig.json` in the root of your Medusa server with the following content: + + ```json + { + "type": "postgres", + "host": "localhost", + "port": 5432, + "username": "", + "password": "", + "database": "", + "synchronize": true, + "logging": false, + "entities": [ + "dist/models/**/*.js" + ], + "migrations": [ + "dist/migrations/**/*.js" + ], + "cli": { + "entitiesDir": "src/models", + "migrationsDir": "src/migrations" + } + } + ``` + + Make sure to replace ``, ``, and `` with the necessary values for your database connection. + + Then, after creating your entity, run the `build` command: + + ```bash npm2yarn + npm run build + ``` + + Finally, run the following command to generate a Migration for your new entity: + + ```bash + npx typeorm@0.2.45 migration:generate -n PostCreate + ``` + + Where `PostCreate` is just an example of the name of the migration to generate. The migration will then be generated in `src/migrations/-PostCreate.ts`. You can then skip to step 3 of this guide. +
+ --- -## Write Migration File +## Step 2: Write Migration File The migration file contains the necessary commands to create the database columns, foreign keys, and more. @@ -35,7 +82,7 @@ You can learn more about writing the migration file in You can learn more about --- -## Build Files +## Step 3: Build Files Before you can run the migrations you need to run the build command to transpile the TypeScript files to JavaScript files: @@ -45,7 +92,7 @@ npm run build --- -## Run Migration +## Step 4: Run Migration The last step is to run the migration with the command detailed earlier diff --git a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-3-0.md b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-3-0.md index 3f678dc330..592787410d 100644 --- a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-3-0.md +++ b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-3-0.md @@ -1,5 +1,5 @@ --- -sidebar_position: 8 +sidebar_position: 9 description: 'Actions Required for v.1.3.0' --- diff --git a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-3-6.md b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-3-6.md index 7fadd7a320..0d2765a1ec 100644 --- a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-3-6.md +++ b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-3-6.md @@ -1,5 +1,5 @@ --- -sidebar_position: 7 +sidebar_position: 8 description: 'Actions Required for v.1.3.0' --- diff --git a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-3-8.md b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-3-8.md index 8e1ae46d1f..8cd5233fa0 100644 --- a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-3-8.md +++ b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-3-8.md @@ -1,5 +1,5 @@ --- -sidebar_position: 6 +sidebar_position: 7 description: 'Actions Required for v.1.3.0' --- diff --git a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-6-1.md b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-6-1.md index 484313cb47..5eea3bf2ad 100644 --- a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-6-1.md +++ b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-6-1.md @@ -1,5 +1,5 @@ --- -sidebar_position: 5 +sidebar_position: 6 description: 'Actions Required for v.1.6.1' --- diff --git a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-0.md b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-0.md index d4d8eae1fc..0d0124b5d0 100644 --- a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-0.md +++ b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-0.md @@ -1,5 +1,5 @@ --- -sidebar_position: 4 +sidebar_position: 5 description: 'Actions Required for v.1.7.0' --- diff --git a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-1.md b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-1.md index 537b8c79bb..e4e5423497 100644 --- a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-1.md +++ b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-1.md @@ -1,5 +1,5 @@ --- -sidebar_position: 3 +sidebar_position: 4 description: 'Actions Required for v.1.7.1' --- diff --git a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-12.md b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-12.md new file mode 100644 index 0000000000..5d463d4e59 --- /dev/null +++ b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-12.md @@ -0,0 +1,22 @@ +--- +sidebar_position: 1 +description: 'Actions Required for v.1.7.12' +--- + +# v1.7.12 + +Version 1.7.12 of Medusa introduces some database schema changes which require running the migrations command. + +## Overview + +This release contains a migration to ensure that the `product_variant_inventory` table is in its correct state. This is due to a mistake in a previous version where a column name was renamed in an already released migration. This could lead to errors if the migration was applied before the renaming of the column. + +## Actions Required + +### Run Migrations + +After updating your Medusa server and before running it, run the following command to run the latest migrations: + +```bash +medusa migrations run +``` diff --git a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-3.md b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-3.md index 72bba39c01..9262652e10 100644 --- a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-3.md +++ b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-3.md @@ -1,5 +1,5 @@ --- -sidebar_position: 2 +sidebar_position: 3 description: 'Actions Required for v.1.7.3' --- diff --git a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-6.md b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-6.md index 22239540fc..bd3711da3b 100644 --- a/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-6.md +++ b/docs/content/advanced/backend/upgrade-guides/medusa-core/1-7-6.md @@ -1,5 +1,5 @@ --- -sidebar_position: 1 +sidebar_position: 2 description: 'Actions Required for v.1.7.6' --- diff --git a/packages/inventory/CHANGELOG.md b/packages/inventory/CHANGELOG.md index d1b1269eac..ce78f5972b 100644 --- a/packages/inventory/CHANGELOG.md +++ b/packages/inventory/CHANGELOG.md @@ -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 diff --git a/packages/inventory/package.json b/packages/inventory/package.json index b47a187452..af179840bb 100644 --- a/packages/inventory/package.json +++ b/packages/inventory/package.json @@ -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" } } diff --git a/packages/medusa/CHANGELOG.md b/packages/medusa/CHANGELOG.md index 9b1b2e6b82..94bf7bb1cf 100644 --- a/packages/medusa/CHANGELOG.md +++ b/packages/medusa/CHANGELOG.md @@ -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 diff --git a/packages/medusa/package.json b/packages/medusa/package.json index b2a10232af..1d61ee3fdd 100644 --- a/packages/medusa/package.json +++ b/packages/medusa/package.json @@ -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", diff --git a/packages/medusa/src/migrations/1671711415179-multi_location.ts b/packages/medusa/src/migrations/1671711415179-multi_location.ts index 8f1d9e4464..7531c8fd1e 100644 --- a/packages/medusa/src/migrations/1671711415179-multi_location.ts +++ b/packages/medusa/src/migrations/1671711415179-multi_location.ts @@ -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") ` diff --git a/packages/medusa/src/migrations/1678093365811-ensure_required_quantity.ts b/packages/medusa/src/migrations/1678093365811-ensure_required_quantity.ts new file mode 100644 index 0000000000..b07fca4b3d --- /dev/null +++ b/packages/medusa/src/migrations/1678093365811-ensure_required_quantity.ts @@ -0,0 +1,31 @@ +import { MigrationInterface, QueryRunner } from "typeorm" + +export class ensureRequiredQuantity1678093365811 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + 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 { + await queryRunner.query(` + DO + $$ + BEGIN + ALTER TABLE product_variant_inventory_item + RENAME COLUMN required_quantity TO quantity; + EXCEPTION + WHEN undefined_column THEN + END; + $$; + `) + } +} diff --git a/packages/medusa/src/services/__tests__/custom-shipping-option.js b/packages/medusa/src/services/__tests__/custom-shipping-option.js index 002a12e3c7..39b77d9873 100644 --- a/packages/medusa/src/services/__tests__/custom-shipping-option.js +++ b/packages/medusa/src/services/__tests__/custom-shipping-option.js @@ -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", }) }) }) diff --git a/packages/medusa/src/services/__tests__/event-bus.js b/packages/medusa/src/services/__tests__/event-bus.js index 9501351941..0532cc8cba 100644 --- a/packages/medusa/src/services/__tests__/event-bus.js +++ b/packages/medusa/src/services/__tests__/event-bus.js @@ -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", () => { diff --git a/packages/medusa/src/services/cart.ts b/packages/medusa/src/services/cart.ts index 0d400a2a82..e6cccf0282 100644 --- a/packages/medusa/src/services/cart.ts +++ b/packages/medusa/src/services/cart.ts @@ -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 diff --git a/packages/medusa/src/services/custom-shipping-option.ts b/packages/medusa/src/services/custom-shipping-option.ts index 976f6f81a4..aea0bf92ce 100644 --- a/packages/medusa/src/services/custom-shipping-option.ts +++ b/packages/medusa/src/services/custom-shipping-option.ts @@ -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[] diff --git a/packages/medusa/src/services/draft-order.ts b/packages/medusa/src/services/draft-order.ts index 612bf29702..186fffff4a 100644 --- a/packages/medusa/src/services/draft-order.ts +++ b/packages/medusa/src/services/draft-order.ts @@ -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 diff --git a/packages/medusa/src/services/event-bus.ts b/packages/medusa/src/services/event-bus.ts index fc548c45af..758c76807e 100644 --- a/packages/medusa/src/services/event-bus.ts +++ b/packages/medusa/src/services/event-bus.ts @@ -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 & EmitOptions = { attempts: 1 } ): Promise { + 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, } diff --git a/packages/medusa/src/types/global.ts b/packages/medusa/src/types/global.ts index 54d270cf60..67c1332832 100644 --- a/packages/medusa/src/types/global.ts +++ b/packages/medusa/src/types/global.ts @@ -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 & EmitOptions + session_options?: SessionOptions jwt_secret?: string diff --git a/www/docs/announcement.json b/www/docs/announcement.json index 58400b37e3..9e26dfeeb6 100644 --- a/www/docs/announcement.json +++ b/www/docs/announcement.json @@ -1 +1 @@ -{"id":"https://github.com/medusajs/medusa/releases/tag/v1.7.11","content":"v1.7.11 is out","isCloseable":true} \ No newline at end of file +{} \ No newline at end of file diff --git a/www/docs/vercel-ignore.sh b/www/docs/vercel-ignore.sh new file mode 100644 index 0000000000..c82fcd1adb --- /dev/null +++ b/www/docs/vercel-ignore.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +current_branch=$(git branch --show-current) + +if [[ "$VERCEL_DEPLOY_BRANCHES" == *"$current_branch"* ]]; then + echo "Branch allowed to deploy" + exit 1; +else + echo "Branch not allowed to deploy" + exit 0; +fi \ No newline at end of file diff --git a/www/docs/vercel.json b/www/docs/vercel.json new file mode 100644 index 0000000000..2cbc8c3609 --- /dev/null +++ b/www/docs/vercel.json @@ -0,0 +1,120 @@ +{ + "redirects": [ + { + "source": "/api", + "destination": "/api/store" + }, + { + "source": "/api/store/auth/(.*)", + "destination": "/api/store/#tag/Auth" + }, + { + "source": "/api/store/cart/(.*)", + "destination": "/api/store/#tag/Cart" + }, + { + "source": "/api/store/collection/(.*)", + "destination": "/api/store/#tag/Collection" + }, + { + "source": "/api/store/product/(.*)", + "destination": "/api/store/#tag/Product" + }, + { + "source": "/api/admin/auth/(.*)", + "destination": "/api/admin/#tag/Auth" + }, + { + "source": "/api/admin/users/(.*)", + "destination": "/api/admin/#tag/User" + }, + { + "source": "/how-to/headless-ecommerce-store-with-gatsby-contentful-medusa", + "destination": "/add-plugins/contentful" + }, + { + "source": "/how-to/deploying-on-heroku", + "destination": "/deployments/server/deploying-on-heroku" + }, + { + "source": "/admin/introduction", + "destination": "/admin/quickstart" + }, + { + "source": "/admin/quickstart/quick-start", + "destination": "/admin/quickstart" + }, + { + "source": "/admin/quickstart", + "destination": "/admin/quickstart" + }, + { + "source": "/quickstart/starters/nextjs-medusa-starter", + "destination": "/starters/nextjs-medusa-starter" + }, + { + "source": "/quickstart/starters/gatsby-medusa-starter", + "destination": "/starters/gatsby-medusa-starter" + }, + { + "source": "/how-to/create-medusa-app", + "destination": "/usage/create-medusa-app" + }, + { + "source": "/guides/plugins", + "destination": "/advanced/backend/plugins/overview" + }, + { + "source": "/how-to/deploying-admin-on-netlify", + "destination": "/deployments/admin/deploying-on-netlify" + }, + { + "source": "/how-to/deploying-on-digital-ocean/", + "destination": "/deployments/server/deploying-on-digital-ocean" + }, + { + "source": "/how-to/deploying-on-qovery/", + "destination": "/deployments/server/deploying-on-qovery" + }, + { + "source": "/guides/fulfillment-api", + "destination": "/advanced/backend/shipping/add-fulfillment-provider" + }, + { + "source": "/guides/checkouts", + "destination": "/advanced/storefront/how-to-implement-checkout-flow" + }, + { + "source": "/guides/checkouts", + "destination": "/advanced/storefront/how-to-implement-checkout-flow" + }, + { + "source": "/advanced/backend/upgrade-guides/1-7-3", + "destination": "/advanced/backend/upgrade-guides/medusa-core/1-7-3" + }, + { + "source": "/advanced/backend/upgrade-guides/1-7-1", + "destination": "/advanced/backend/upgrade-guides/medusa-core/1-7-1" + }, + { + "source": "/advanced/backend/upgrade-guides/1-7-0", + "destination": "/advanced/backend/upgrade-guides/medusa-core/1-7-0" + }, + { + "source": "/advanced/backend/upgrade-guides/1-6-1", + "destination": "/advanced/backend/upgrade-guides/medusa-core/1-6-1" + }, + { + "source": "/advanced/backend/upgrade-guides/1-3-8", + "destination": "/advanced/backend/upgrade-guides/medusa-core/1-3-8" + }, + { + "source": "/advanced/backend/upgrade-guides/1-3-6", + "destination": "/advanced/backend/upgrade-guides/medusa-core/1-3-6" + }, + { + "source": "/advanced/backend/upgrade-guides/1-3-0", + "destination": "/advanced/backend/upgrade-guides/medusa-core/1-3-0" + } + ] +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index e35e4a2b5b..eb0a4fc05e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5734,7 +5734,7 @@ __metadata: typeorm: ^0.3.11 typescript: ^4.4.4 peerDependencies: - "@medusajs/medusa": 1.7.11 + "@medusajs/medusa": 1.7.12 typeorm: ^0.3.11 languageName: unknown linkType: soft