Skip to main content

v1.7.1

Version 1.7.1Copy to Clipboard of Medusa introduces the JobSchedulerServiceCopy to Clipboard which changes how scheduled/cron jobs are created.

Overview

Version 1.7.1Copy to Clipboard of Medusa introduces a new service JobSchedulerServiceCopy to Clipboard that handles all logic and functionality related to created scheduled (previously named cron jobs).

With this introduction, the previous use of EventBusCopy to Clipboard to create a cron job has been deprecated of using the JobSchedulerServiceCopy to Clipboard.

In addition, this version features some fixes to gift cards that requires running migrations, and changes to how payment providers are implemented.


Actions Required

Run Migrations

In the directory of your Medusa server, run the following command after updating the server:

medusa migrations run
Report Incorrect CodeReport Incorrect CodeCopy to ClipboardCopy to Clipboard

Run Migration Script

Following the fix gift cards calculation, you also need to run a migration script after updating the server.

Start by adding the following environment variables in .envCopy to Clipboard:

TYPEORM_CONNECTION=postgres
TYPEORM_URL=<DATABASE_URL>
TYPEORM_USERNAME=<DATABASE_USERNAME>
TYPEORM_PASSWORD=<DATABASE_PASSWORD>
TYPEORM_DATABASE=<DATABASE_DATABASE>
TYPEORM_ENTITIES=./node_modules/@medusajs/medusa/dist/models/*.js
TYPEORM_MIGRATIONS=./node_modules/@medusajs/medusa/dist/migrations/*.js
Report Incorrect CodeReport Incorrect CodeCopy to ClipboardCopy to Clipboard

Make sure to replace <DATABASE_URL>Copy to Clipboard, <DATABASE_USERNAME>Copy to Clipboard, <DATABASE_PASSWORD>Copy to Clipboard, and <DATABASE_DATABASE>Copy to Clipboard with your database connection details.

Then, run the following command in the root directory of your Medusa server:

node ./node_modules/@medusajs/medusa/dist/scripts/gift-card-tax-rate-migration.js
Report Incorrect CodeReport Incorrect CodeCopy to ClipboardCopy to Clipboard

Change to JobSchedulerService

In your loader file that creates a cron job, replace the use of eventBusCopy to Clipboard to jobSchedulerServiceCopy to Clipboard:

const myJob = async (container, options) => {
const jobSchedulerService = container.resolve("jobSchedulerService")
jobSchedulerService.create("my-job", {}, "0 0 * * *", async () => {
// ...
})
}

export default myJob
Report Incorrect CodeReport Incorrect CodeCopy to ClipboardCopy to Clipboard

You can learn more in the How to Create a Scheduled Job documentation.

Change to Payment Provider

This version of Medusa introduces a change in how payment providers are implemented. Mainly, the signature of the createPaymentCopy to Clipboard and updatePaymentCopy to Clipboard methods have changed, and the old signature is now deprecated.

Although this change is currently backwards compatible, it is recommended to change the signature of these methods to the following:

import { Cart, PaymentSessionData, PaymentContext, PaymentSessionResponse } from "@medusajs/medusa"
// ...

class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
// ...
async createPayment(
context: Cart & PaymentContext
): Promise<PaymentSessionResponse> {
// ...
}

async updatePayment(
paymentSessionData: PaymentSessionData,
context: Cart & PaymentContext
): Promise<PaymentSessionResponse> {
// ...
}
}
Report Incorrect CodeReport Incorrect CodeCopy to ClipboardCopy to Clipboard

Where contextCopy to Clipboard in both createPaymentCopy to Clipboard and updatePaymentCopy to Clipboard is made up of the following properties:

type PaymentContext = {
cart: {
context: Record<string, unknown>
id: string
email: string
shipping_address: Address | null
shipping_methods: ShippingMethod[]
}
currency_code: string
amount: number
resource_id?: string
customer?: Customer
}
Report Incorrect CodeReport Incorrect CodeCopy to ClipboardCopy to Clipboard

So, you can pass the previous cartCopy to Clipboard parameter inside the new contextCopy to Clipboard paramter.

Furthermore, these methods are now expected to return PaymentSessionResponseCopy to Clipboard. It is made up of the following properties:

type PaymentSessionResponse = {
update_requests: { customer_metadata: Record<string, unknown> }
session_data: Record<string, unknown>
}
Report Incorrect CodeReport Incorrect CodeCopy to ClipboardCopy to Clipboard

Where session_dataCopy to Clipboard would include the previously returned data from these methods. The property update_requestsCopy to Clipboard allows you to pass data from the payment provider plugin to the core to update internal resources. Currently, it can only be used to update the metadataCopy to Clipboard field of the customer entity.