diff --git a/www/apps/resources/app/commerce-modules/api-key/page.mdx b/www/apps/resources/app/commerce-modules/api-key/page.mdx index 5f8c022b21..ea907b80b0 100644 --- a/www/apps/resources/app/commerce-modules/api-key/page.mdx +++ b/www/apps/resources/app/commerce-modules/api-key/page.mdx @@ -8,72 +8,6 @@ export const metadata = { The API Key Module is the `@medusajs/api-key` NPM package that provides API-key-related features in your Medusa and Node.js applications. -## Features - -### API Key Types and Management - -Store and manage API keys in your store. You can create both publishable and secret API keys for different use cases, such as: - -- Publishable API Key associated with resources like sales channels. -- Authentication token for admin users to access Admin API Routes. -- Password reset tokens when a user or customer requests to reset their password. - -```ts -const pubApiKey = await apiKeyModuleService.createApiKeys({ - title: "Publishable API key", - type: "publishable", - created_by: "user_123", -}) - -const secretApiKey = await apiKeyModuleService.createApiKeys({ - title: "Authentication Key", - type: "secret", - created_by: "user_123", -}) -``` - -### Token Verification - -Verify tokens of secret API keys to authenticate users or actions, such as verifying a password reset token. - -```ts -const authenticatedToken = await apiKeyModuleService.authenticate("sk_123") - -if (!authenticatedToken) { - console.error("Couldn't verify token") -} else { - console.log("Token verified successfully!") -} -``` - -### Revoke Keys - -Revoke keys to disable their use permenantly. - -```ts -const revokedKey = await apiKeyModuleService.revoke("apk_1", { - revoked_by: "user_123", -}) -``` - -### Roll API Keys - -Roll API keys by revoking a key then re-creating it. - -```ts -const revokedKey = await apiKeyModuleService.revoke("apk_1", { - revoked_by: "user_123", -}) - -const newKey = await apiKeyModuleService.createApiKeys({ - title: revokedKey.title, - type: revokedKey.type, - created_by: revokedKey.created_by, -}) -``` - ---- - ## How to Use API Key Module's Service You can use the API Key Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.API_KEY` imported from `@medusajs/utils`. @@ -138,3 +72,69 @@ const step1 = createStep("step-1", async (_, { container }) => { + +--- + +## Features + +### API Key Types and Management + +Store and manage API keys in your store. You can create both publishable and secret API keys for different use cases, such as: + +- Publishable API Key associated with resources like sales channels. +- Authentication token for admin users to access Admin API Routes. +- Password reset tokens when a user or customer requests to reset their password. + +```ts +const pubApiKey = await apiKeyModuleService.createApiKeys({ + title: "Publishable API key", + type: "publishable", + created_by: "user_123", +}) + +const secretApiKey = await apiKeyModuleService.createApiKeys({ + title: "Authentication Key", + type: "secret", + created_by: "user_123", +}) +``` + +### Token Verification + +Verify tokens of secret API keys to authenticate users or actions, such as verifying a password reset token. + +```ts +const authenticatedToken = await apiKeyModuleService.authenticate("sk_123") + +if (!authenticatedToken) { + console.error("Couldn't verify token") +} else { + console.log("Token verified successfully!") +} +``` + +### Revoke Keys + +Revoke keys to disable their use permenantly. + +```ts +const revokedKey = await apiKeyModuleService.revoke("apk_1", { + revoked_by: "user_123", +}) +``` + +### Roll API Keys + +Roll API keys by revoking a key then re-creating it. + +```ts +const revokedKey = await apiKeyModuleService.revoke("apk_1", { + revoked_by: "user_123", +}) + +const newKey = await apiKeyModuleService.createApiKeys({ + title: revokedKey.title, + type: revokedKey.type, + created_by: revokedKey.created_by, +}) +``` diff --git a/www/apps/resources/app/commerce-modules/auth/page.mdx b/www/apps/resources/app/commerce-modules/auth/page.mdx index 01f3833e4f..a79ff40cf2 100644 --- a/www/apps/resources/app/commerce-modules/auth/page.mdx +++ b/www/apps/resources/app/commerce-modules/auth/page.mdx @@ -8,6 +8,72 @@ export const metadata = { The Auth Module is the `@medusajs/auth` NPM package that provides authentication-related features in your Medusa and Node.js applications. +## How to Use Auth Module's Service + +You can use the Auth Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.AUTH` imported from `@medusajs/utils`. + +For example: + + + + +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IAuthModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" + +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const authModuleService: IAuthModuleService = req.scope.resolve( + ModuleRegistrationName.AUTH + ) + + res.json({ + authIdentitys: await authModuleService.listAuthIdentities(), + }) +} +``` + + + + +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { IAuthModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" + +export default async function subscriberHandler({ container }: SubscriberArgs) { + const authModuleService: IAuthModuleService = container.resolve( + ModuleRegistrationName.AUTH + ) + + const authIdentitys = await authModuleService.listAuthIdentities() +} +``` + + + + +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { IAuthModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" + +const step1 = createStep("step-1", async (_, { container }) => { + const authModuleService: IAuthModuleService = container.resolve( + ModuleRegistrationName.AUTH + ) + const authIdentitys = await authModuleService.listAuthIdentities() +}) +``` + + + + +--- + ## Features ### Basic User Authentication @@ -72,69 +138,3 @@ const { success, authIdentity } = await authModuleService.validateCallback( ## Configure Auth Module Refer to [this documentation](./module-options/page.mdx) for details on the module's options. - ---- - -## How to Use Auth Module's Service - -You can use the Auth Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.AUTH` imported from `@medusajs/utils`. - -For example: - - - - -```ts title="src/api/store/custom/route.ts" -import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" -import { IAuthModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/utils" - -export async function GET( - req: MedusaRequest, - res: MedusaResponse -): Promise { - const authModuleService: IAuthModuleService = req.scope.resolve( - ModuleRegistrationName.AUTH - ) - - res.json({ - authIdentitys: await authModuleService.listAuthIdentities(), - }) -} -``` - - - - -```ts title="src/subscribers/custom-handler.ts" -import { SubscriberArgs } from "@medusajs/medusa" -import { IAuthModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/utils" - -export default async function subscriberHandler({ container }: SubscriberArgs) { - const authModuleService: IAuthModuleService = container.resolve( - ModuleRegistrationName.AUTH - ) - - const authIdentitys = await authModuleService.listAuthIdentities() -} -``` - - - - -```ts title="src/workflows/hello-world/step1.ts" -import { createStep } from "@medusajs/workflows-sdk" -import { IAuthModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/utils" - -const step1 = createStep("step-1", async (_, { container }) => { - const authModuleService: IAuthModuleService = container.resolve( - ModuleRegistrationName.AUTH - ) - const authIdentitys = await authModuleService.listAuthIdentities() -}) -``` - - - diff --git a/www/apps/resources/app/commerce-modules/cart/page.mdx b/www/apps/resources/app/commerce-modules/cart/page.mdx index 5ac8c82c6c..14c62fa8a2 100644 --- a/www/apps/resources/app/commerce-modules/cart/page.mdx +++ b/www/apps/resources/app/commerce-modules/cart/page.mdx @@ -8,60 +8,6 @@ export const metadata = { The Cart Module is the `@medusajs/cart` NPM package that provides cart-related features in your Medusa and Node.js applications. -## Features - -### Cart Management - -Store and manage carts, including their addresses, line items, shipping methods, and more. - -```ts -const cart = await cartModuleService.createCarts({ - currency_code: "usd", - shipping_address: { - address_1: "1512 Barataria Blvd", - country_code: "us", - }, - items: [ - { - title: "Shirt", - unit_price: 1000, - quantity: 1, - }, - ], -}) -``` - -### Apply Promotions - -Apply promotions or discounts to line items and shipping methods by adding adjustment lines that are factored into their subtotals. - -```ts -const lineAdjustments = await cartModuleService.addLineItemAdjustments({ - item_id: "cali_123", - code: "50OFF", - amount: 500, -}) - -const shippingAdjustments = - await cartModuleService.addShippingMethodAdjustments({ - shipping_method_id: "casm_123", - code: "FREESHIPPING", - amount: 1000, - }) -``` - -### Cart Context and Scoping - -A cart is scoped to a sales channel, region, and a customer. - -When used with their respective modules and other commerce modules, you benefit from features like: - -- Checking product availability in a sales channel. -- Retrieving pricing per region. -- Applying promotions based on the customer's group. - ---- - ## How to Use Cart Module's Service You can use the Cart Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.CART` imported from `@medusajs/utils`. @@ -126,3 +72,57 @@ const step1 = createStep("step-1", async (_, { container }) => { + +--- + +## Features + +### Cart Management + +Store and manage carts, including their addresses, line items, shipping methods, and more. + +```ts +const cart = await cartModuleService.createCarts({ + currency_code: "usd", + shipping_address: { + address_1: "1512 Barataria Blvd", + country_code: "us", + }, + items: [ + { + title: "Shirt", + unit_price: 1000, + quantity: 1, + }, + ], +}) +``` + +### Apply Promotions + +Apply promotions or discounts to line items and shipping methods by adding adjustment lines that are factored into their subtotals. + +```ts +const lineAdjustments = await cartModuleService.addLineItemAdjustments({ + item_id: "cali_123", + code: "50OFF", + amount: 500, +}) + +const shippingAdjustments = + await cartModuleService.addShippingMethodAdjustments({ + shipping_method_id: "casm_123", + code: "FREESHIPPING", + amount: 1000, + }) +``` + +### Cart Context and Scoping + +A cart is scoped to a sales channel, region, and a customer. + +When used with their respective modules and other commerce modules, you benefit from features like: + +- Checking product availability in a sales channel. +- Retrieving pricing per region. +- Applying promotions based on the customer's group. diff --git a/www/apps/resources/app/commerce-modules/currency/page.mdx b/www/apps/resources/app/commerce-modules/currency/page.mdx index d881e42886..e1cc0d2d9f 100644 --- a/www/apps/resources/app/commerce-modules/currency/page.mdx +++ b/www/apps/resources/app/commerce-modules/currency/page.mdx @@ -8,31 +8,6 @@ export const metadata = { The Currency Module is the `@medusajs/currency` NPM package that provides currency-related features in your Medusa and Node.js applications. -## Features - -### Currency Retrieval - -List and retrieve currencies stored in your application. - -```ts -const currency = await currencyModuleService.retrieveCurrency("usd") -``` - -### Support Currencies in Modules - -Other commerce modules use currency codes in their data models or operations. You can use the Currency Module to retrieve a currency code and its details. - -An example with the Region Module: - -```ts -const region = await regionModuleService.retrieveCurrency("reg_123") -const currency = await currencyModuleService.retrieveCurrency( - region.currency_code -) -``` - ---- - ## How to Use Currency Module's Service You can use the Currency Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.CURRENCY` imported from `@medusajs/utils`. @@ -97,3 +72,28 @@ const step1 = createStep("step-1", async (_, { container }) => { + +--- + +## Features + +### Currency Retrieval + +List and retrieve currencies stored in your application. + +```ts +const currency = await currencyModuleService.retrieveCurrency("usd") +``` + +### Support Currencies in Modules + +Other commerce modules use currency codes in their data models or operations. You can use the Currency Module to retrieve a currency code and its details. + +An example with the Region Module: + +```ts +const region = await regionModuleService.retrieveCurrency("reg_123") +const currency = await currencyModuleService.retrieveCurrency( + region.currency_code +) +``` diff --git a/www/apps/resources/app/commerce-modules/customer/page.mdx b/www/apps/resources/app/commerce-modules/customer/page.mdx index 01626034ad..af341ceaf0 100644 --- a/www/apps/resources/app/commerce-modules/customer/page.mdx +++ b/www/apps/resources/app/commerce-modules/customer/page.mdx @@ -8,37 +8,6 @@ export const metadata = { The Customer Module is the `@medusajs/customer` NPM package that provides customer-related features in your Medusa and Node.js applications. -## Features - -### Customer Management - -With the Customer Module, store and manage customers in your store. - -```ts -const customer = await customerModuleService.createCustomers({ - first_name: "Peter", - last_name: "Hayes", - email: "peter.hayes@example.com", -}) -``` - -### Customer Organization - -You can organize customers into groups. This has a lot of benefits and supports more use cases, such as provide discounts for specific customer groups using the Promotion Module. - -```ts -const customerGroup = await customerModuleService.createCustomerGroups({ - name: "VIP", -}) - -await customerModuleService.addCustomerToGroup({ - customer_id: "cus_123", - customer_group_id: customerGroup.id, -}) -``` - ---- - ## How to Use Customer Module's Service You can use the Customer Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.CUSTOMER` imported from `@medusajs/utils`. @@ -100,3 +69,34 @@ const step1 = createStep("step-1", async (_, { container }) => { + +--- + +## Features + +### Customer Management + +With the Customer Module, store and manage customers in your store. + +```ts +const customer = await customerModuleService.createCustomers({ + first_name: "Peter", + last_name: "Hayes", + email: "peter.hayes@example.com", +}) +``` + +### Customer Organization + +You can organize customers into groups. This has a lot of benefits and supports more use cases, such as provide discounts for specific customer groups using the Promotion Module. + +```ts +const customerGroup = await customerModuleService.createCustomerGroups({ + name: "VIP", +}) + +await customerModuleService.addCustomerToGroup({ + customer_id: "cus_123", + customer_group_id: customerGroup.id, +}) +``` diff --git a/www/apps/resources/app/commerce-modules/fulfillment/page.mdx b/www/apps/resources/app/commerce-modules/fulfillment/page.mdx index 7e06eff731..35f9369ab5 100644 --- a/www/apps/resources/app/commerce-modules/fulfillment/page.mdx +++ b/www/apps/resources/app/commerce-modules/fulfillment/page.mdx @@ -8,6 +8,73 @@ export const metadata = { The Fulfillment Module is the `@medusajs/fulfillment` NPM package that provides fulfillment-related features in your Medusa and Node.js applications. +## How to Use Fulfillment Module's Service + +You can use the Fulfillment Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.API_KEY` imported from `@medusajs/utils`. + +For example: + + + + + ```ts title="src/api/store/custom/route.ts" + import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" + import { IFulfillmentModuleService } from "@medusajs/types" + import { ModuleRegistrationName } from "@medusajs/utils" + +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const fulfillmentModuleService: IFulfillmentModuleService = req.scope.resolve( + ModuleRegistrationName.FULFILLMENT + ) + + res.json({ + fulfillments: await fulfillmentModuleService.listFulfillments(), + }) +} +``` + + + + + ```ts title="src/subscribers/custom-handler.ts" + import { SubscriberArgs } from "@medusajs/medusa" + import { IFulfillmentModuleService } from "@medusajs/types" + import { ModuleRegistrationName } from "@medusajs/utils" + +export default async function subscriberHandler({ container }: SubscriberArgs) { + const fulfillmentModuleService: IFulfillmentModuleService = container.resolve( + ModuleRegistrationName.FULFILLMENT + ) + + const fulfillments = await fulfillmentModuleService.listFulfillments() +} +``` + + + + + ```ts title="src/workflows/hello-world/step1.ts" + import { createStep } from "@medusajs/workflows-sdk" + import { IFulfillmentModuleService } from "@medusajs/types" + import { ModuleRegistrationName } from "@medusajs/utils" + +const step1 = createStep("step-1", async (_, { container }) => { + const fulfillmentModuleService: IFulfillmentModuleService = container.resolve( + ModuleRegistrationName.FULFILLMENT + ) + + const fulfillments = await fulfillmentModuleService.listFulfillments() +}) +``` + + + + +--- + ## Features ### Fulfillment Management @@ -101,70 +168,3 @@ const fulfillmentSets = await fulfillmentModuleService.createFulfillmentSets([ ## Configure Fulfillment Module Refer to [this documentation](./module-options/page.mdx) for details on the module's options. - ---- - -## How to Use Fulfillment Module's Service - -You can use the Fulfillment Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.API_KEY` imported from `@medusajs/utils`. - -For example: - - - - - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IFulfillmentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/utils" - -export async function GET( - req: MedusaRequest, - res: MedusaResponse -): Promise { - const fulfillmentModuleService: IFulfillmentModuleService = req.scope.resolve( - ModuleRegistrationName.FULFILLMENT - ) - - res.json({ - fulfillments: await fulfillmentModuleService.listFulfillments(), - }) -} -``` - - - - - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IFulfillmentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/utils" - -export default async function subscriberHandler({ container }: SubscriberArgs) { - const fulfillmentModuleService: IFulfillmentModuleService = container.resolve( - ModuleRegistrationName.FULFILLMENT - ) - - const fulfillments = await fulfillmentModuleService.listFulfillments() -} -``` - - - - - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IFulfillmentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/utils" - -const step1 = createStep("step-1", async (_, { container }) => { - const fulfillmentModuleService: IFulfillmentModuleService = container.resolve( - ModuleRegistrationName.FULFILLMENT - ) - - const fulfillments = await fulfillmentModuleService.listFulfillments() -}) -``` - - - diff --git a/www/apps/resources/app/commerce-modules/inventory/page.mdx b/www/apps/resources/app/commerce-modules/inventory/page.mdx index 059fcc4d89..c92181cd2a 100644 --- a/www/apps/resources/app/commerce-modules/inventory/page.mdx +++ b/www/apps/resources/app/commerce-modules/inventory/page.mdx @@ -8,64 +8,6 @@ export const metadata = { The Inventory Module is the `@medusajs/inventory-next` NPM package that provides inventory-related features in your Medusa and Node.js applications. -## Features - -### Inventory Items Management - -Store and manage inventory of any stock-kept item, such as product variants. - -Inventory items hold details of the underlying stock-kept item, as well as inventory details such as whether the item requires shipping. - -```ts -const inventoryItem = await inventoryModuleService.createInventoryItems({ - sku: "SHIRT", - title: "Green Medusa Shirt", - requires_shipping: true, -}) -``` - -### Inventory Across Locations - -Inventory items' quantities are set per locations through inventory levels. This gives you more flexibility in managing the quantity of a stock-kept item across different locations, such as different warehouses. - -```ts -const inventoryLevel = await inventoryModuleService.createInventoryLevels([ - { - inventory_item_id: "iitem_123", - location_id: "sloc_123", - stocked_quantity: 20, - }, -]) -``` - -### Reservation Management - -Reserve quantities of inventory items at specific locations for orders or other purposes. The reserved quantity isn't considered for purchase, but can be deleted to revert the reservation. - -```ts -const reservationItem = await inventoryModuleService.createReservationItems([ - { - inventory_item_id: "iitem_123", - location_id: "sloc_123", - quantity: 10, - }, -]) -``` - -### Check Inventory Availability - -Check whether an inventory item has the necessary quantity for purchase. Any reserved quantity is considered unavailable. - -```ts -const isAvailable = await inventoryModuleService.confirmInventory( - inventoryItemId, - [locationId], - neededQuantity -) -``` - ---- - ## How to Use Inventory Module's Service You can use the Inventory Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.INVENTORY` imported from `@medusajs/utils`. @@ -130,3 +72,61 @@ const step1 = createStep("step-1", async (_, { container }) => { + +--- + +## Features + +### Inventory Items Management + +Store and manage inventory of any stock-kept item, such as product variants. + +Inventory items hold details of the underlying stock-kept item, as well as inventory details such as whether the item requires shipping. + +```ts +const inventoryItem = await inventoryModuleService.createInventoryItems({ + sku: "SHIRT", + title: "Green Medusa Shirt", + requires_shipping: true, +}) +``` + +### Inventory Across Locations + +Inventory items' quantities are set per locations through inventory levels. This gives you more flexibility in managing the quantity of a stock-kept item across different locations, such as different warehouses. + +```ts +const inventoryLevel = await inventoryModuleService.createInventoryLevels([ + { + inventory_item_id: "iitem_123", + location_id: "sloc_123", + stocked_quantity: 20, + }, +]) +``` + +### Reservation Management + +Reserve quantities of inventory items at specific locations for orders or other purposes. The reserved quantity isn't considered for purchase, but can be deleted to revert the reservation. + +```ts +const reservationItem = await inventoryModuleService.createReservationItems([ + { + inventory_item_id: "iitem_123", + location_id: "sloc_123", + quantity: 10, + }, +]) +``` + +### Check Inventory Availability + +Check whether an inventory item has the necessary quantity for purchase. Any reserved quantity is considered unavailable. + +```ts +const isAvailable = await inventoryModuleService.confirmInventory( + inventoryItemId, + [locationId], + neededQuantity +) +``` diff --git a/www/apps/resources/app/commerce-modules/order/page.mdx b/www/apps/resources/app/commerce-modules/order/page.mdx index b17fc7a912..6e952b1fb8 100644 --- a/www/apps/resources/app/commerce-modules/order/page.mdx +++ b/www/apps/resources/app/commerce-modules/order/page.mdx @@ -8,6 +8,72 @@ export const metadata = { The Order Module is the `@medusajs/order` NPM package that provides order-related features in your Medusa and Node.js applications. +## How to Use Order Module's Service + +You can use the Order Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.ORDER` imported from `@medusajs/utils`. + +For example: + + + + + ```ts title="src/api/store/custom/route.ts" + import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" + import { IOrderModuleService } from "@medusajs/types" + import { ModuleRegistrationName } from "@medusajs/utils" + +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const orderModuleService: IOrderModuleService = req.scope.resolve( + ModuleRegistrationName.ORDER + ) + + res.json({ + orders: await orderModuleService.listOrders(), + }) +} +``` + + + + + ```ts title="src/subscribers/custom-handler.ts" + import { SubscriberArgs } from "@medusajs/medusa" + import { IOrderModuleService } from "@medusajs/types" + import { ModuleRegistrationName } from "@medusajs/utils" + +export default async function subscriberHandler({ container }: SubscriberArgs) { + const orderModuleService: IOrderModuleService = container.resolve( + ModuleRegistrationName.ORDER + ) + + const orders = await orderModuleService.listOrders() +} +``` + + + + + ```ts title="src/workflows/hello-world/step1.ts" + import { createStep } from "@medusajs/workflows-sdk" + import { IOrderModuleService } from "@medusajs/types" + import { ModuleRegistrationName } from "@medusajs/utils" + +const step1 = createStep("step-1", async (_, { container }) => { + const orderModuleService: IOrderModuleService = container.resolve( + ModuleRegistrationName.ORDER + ) + const orders = await orderModuleService.listOrders() +}) +``` + + + + +--- + ## Features ### Order Management @@ -77,69 +143,3 @@ const orderReturn = await orderModuleService.createReturn({ }], }) ``` - ---- - -## How to Use Order Module's Service - -You can use the Order Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.ORDER` imported from `@medusajs/utils`. - -For example: - - - - - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IOrderModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/utils" - -export async function GET( - req: MedusaRequest, - res: MedusaResponse -): Promise { - const orderModuleService: IOrderModuleService = req.scope.resolve( - ModuleRegistrationName.ORDER - ) - - res.json({ - orders: await orderModuleService.listOrders(), - }) -} -``` - - - - - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IOrderModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/utils" - -export default async function subscriberHandler({ container }: SubscriberArgs) { - const orderModuleService: IOrderModuleService = container.resolve( - ModuleRegistrationName.ORDER - ) - - const orders = await orderModuleService.listOrders() -} -``` - - - - - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IOrderModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/utils" - -const step1 = createStep("step-1", async (_, { container }) => { - const orderModuleService: IOrderModuleService = container.resolve( - ModuleRegistrationName.ORDER - ) - const orders = await orderModuleService.listOrders() -}) -``` - - - diff --git a/www/apps/resources/app/commerce-modules/payment/page.mdx b/www/apps/resources/app/commerce-modules/payment/page.mdx index 9eaf2bace1..fb5b1d79fb 100644 --- a/www/apps/resources/app/commerce-modules/payment/page.mdx +++ b/www/apps/resources/app/commerce-modules/payment/page.mdx @@ -9,68 +9,6 @@ export const metadata = { The Payment Module is the `@medusajs/payment` NPM package that provides payment-related features in your Medusa and Node.js applications. -## Features - -### Add Payment Functionalities to Any Resource - -The Payment Module provides payment functionalities that allow you to process payment of any resource, such as a cart. - -All payment processing starts with creating a payment collection. - -```ts -const paymentCollection = await paymentModuleService.createPaymentCollections({ - region_id: "reg_123", - currency_code: "usd", - amount: 5000, -}) -``` - -### Authorize, Capture, and Refund Payment - -The Payment Module provides essential features to receive and handle payments, including authorizing, capturing, and refunding payment. - -```ts -await paymentModuleService.capturePayment({ - payment_id: "pay_1", -}) -``` - -### Integrate Third-Party Payment Providers - -Use payment providers like Stripe to handle and process payments. - -```ts -const payment = await paymentModuleService.createPaymentSession("pay_col_1", { - provider_id: "stripe", - amount: 1000, - currency_code: "usd", - data: { - // necessary data for the payment provider - }, -}) -``` - -### Handle Webhook Events - -The Payment Module allows you to handle webhook events from third-party providers and process the associated payment. - -```ts -await paymentModuleService.processEvent({ - provider: "stripe", - payload: { - // webhook payload - }, -}) -``` - ---- - -## Configure Payment Module - -Refer to [this documentation](./module-options/page.mdx) for details on the module's options. - ---- - ## How to Use Payment Module's Service You can use the Payment Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.PAYMENT` imported from `@medusajs/utils`. @@ -137,3 +75,65 @@ const step1 = createStep("step-1", async (_, { container }) => { + +--- + +## Features + +### Add Payment Functionalities to Any Resource + +The Payment Module provides payment functionalities that allow you to process payment of any resource, such as a cart. + +All payment processing starts with creating a payment collection. + +```ts +const paymentCollection = await paymentModuleService.createPaymentCollections({ + region_id: "reg_123", + currency_code: "usd", + amount: 5000, +}) +``` + +### Authorize, Capture, and Refund Payment + +The Payment Module provides essential features to receive and handle payments, including authorizing, capturing, and refunding payment. + +```ts +await paymentModuleService.capturePayment({ + payment_id: "pay_1", +}) +``` + +### Integrate Third-Party Payment Providers + +Use payment providers like Stripe to handle and process payments. + +```ts +const payment = await paymentModuleService.createPaymentSession("pay_col_1", { + provider_id: "stripe", + amount: 1000, + currency_code: "usd", + data: { + // necessary data for the payment provider + }, +}) +``` + +### Handle Webhook Events + +The Payment Module allows you to handle webhook events from third-party providers and process the associated payment. + +```ts +await paymentModuleService.processEvent({ + provider: "stripe", + payload: { + // webhook payload + }, +}) +``` + +--- + +## Configure Payment Module + +Refer to [this documentation](./module-options/page.mdx) for details on the module's options. diff --git a/www/apps/resources/app/commerce-modules/pricing/page.mdx b/www/apps/resources/app/commerce-modules/pricing/page.mdx index 01f35637cd..1df95f75d6 100644 --- a/www/apps/resources/app/commerce-modules/pricing/page.mdx +++ b/www/apps/resources/app/commerce-modules/pricing/page.mdx @@ -8,6 +8,73 @@ export const metadata = { The Pricing Module is the `@medusajs/pricing` NPM package that provides pricing-related features in your Medusa and Node.js applications. +## How to Use Pricing Module's Service + +You can use the Pricing Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.PRICING` imported from `@medusajs/utils`. + +For example: + + + + + ```ts title="src/api/store/custom/route.ts" + import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" + import { IPricingModuleService } from "@medusajs/types" + import { ModuleRegistrationName } from "@medusajs/utils" + +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const pricingModuleService: IPricingModuleService = request.scope.resolve( + ModuleRegistrationName.PRICING + ) + + res.json({ + price_sets: await pricingModuleService.listPriceSets(), + }) +} +``` + + + + + ```ts title="src/subscribers/custom-handler.ts" + import { SubscriberArgs } from "@medusajs/medusa" + import { IPricingModuleService } from "@medusajs/types" + import { ModuleRegistrationName } from "@medusajs/utils" + +export default async function subscriberHandler({ container }: SubscriberArgs) { + const pricingModuleService: IPricingModuleService = container.resolve( + ModuleRegistrationName.PRICING + ) + + const priceSets = await pricingModuleService.listPriceSets() +} +``` + + + + + ```ts title="src/workflows/hello-world/step1.ts" + import { createStep } from "@medusajs/workflows-sdk" + import { IPricingModuleService } from "@medusajs/types" + import { ModuleRegistrationName } from "@medusajs/utils" + +const step1 = createStep("step-1", async (_, { container }) => { + const pricingModuleService: IPricingModuleService = container.resolve( + ModuleRegistrationName.PRICING + ) + + const priceSets = await pricingModuleService.listPriceSets() +}) +``` + + + + +--- + ## Features ### Price Management @@ -94,70 +161,3 @@ const price = await pricingModuleService.calculatePrices( } ) ``` - ---- - -## How to Use Pricing Module's Service - -You can use the Pricing Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.PRICING` imported from `@medusajs/utils`. - -For example: - - - - - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPricingModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/utils" - -export async function GET( - request: MedusaRequest, - res: MedusaResponse -): Promise { - const pricingModuleService: IPricingModuleService = request.scope.resolve( - ModuleRegistrationName.PRICING - ) - - res.json({ - price_sets: await pricingModuleService.listPriceSets(), - }) -} -``` - - - - - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IPricingModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/utils" - -export default async function subscriberHandler({ container }: SubscriberArgs) { - const pricingModuleService: IPricingModuleService = container.resolve( - ModuleRegistrationName.PRICING - ) - - const priceSets = await pricingModuleService.listPriceSets() -} -``` - - - - - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IPricingModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/utils" - -const step1 = createStep("step-1", async (_, { container }) => { - const pricingModuleService: IPricingModuleService = container.resolve( - ModuleRegistrationName.PRICING - ) - - const priceSets = await pricingModuleService.listPriceSets() -}) -``` - - - diff --git a/www/apps/resources/app/commerce-modules/product/page.mdx b/www/apps/resources/app/commerce-modules/product/page.mdx index 2938b25ff0..9743852863 100644 --- a/www/apps/resources/app/commerce-modules/product/page.mdx +++ b/www/apps/resources/app/commerce-modules/product/page.mdx @@ -8,58 +8,6 @@ export const metadata = { The Product Module is the `@medusajs/product` NPM package that provides product-related features in your Medusa and Node.js applications. -## Features - -### Products Management - -Store and manage products. Products have custom options, such as color or size, and each variant in the product sets the value for these options. - -```ts -const products = await productService.createProducts([ - { - title: "Medusa Shirt", - options: [ - { - title: "Color", - }, - ], - variants: [ - { - title: "Black Shirt", - options: [ - { - value: "Black", - }, - ], - }, - ], - }, -]) -``` - -### Product Organization - -The Product Module provides different data models used to organize products, including categories, collections, tags, and more. - -```ts -const category = await productService.createProductCategories({ - name: "Shirts", -}) - -const products = await productService.updateProducts([ - { - id: product.id, - categories: [ - { - id: category.id, - }, - ], - }, -]) -``` - ---- - ## How to Use Product Module's Service You can use the Product Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.PRODUCT` imported from `@medusajs/utils`. @@ -121,3 +69,55 @@ const step1 = createStep("step-1", async (_, { container }) => { + +--- + +## Features + +### Products Management + +Store and manage products. Products have custom options, such as color or size, and each variant in the product sets the value for these options. + +```ts +const products = await productService.createProducts([ + { + title: "Medusa Shirt", + options: [ + { + title: "Color", + }, + ], + variants: [ + { + title: "Black Shirt", + options: [ + { + value: "Black", + }, + ], + }, + ], + }, +]) +``` + +### Product Organization + +The Product Module provides different data models used to organize products, including categories, collections, tags, and more. + +```ts +const category = await productService.createProductCategories({ + name: "Shirts", +}) + +const products = await productService.updateProducts([ + { + id: product.id, + categories: [ + { + id: category.id, + }, + ], + }, +]) +``` diff --git a/www/apps/resources/app/commerce-modules/promotion/page.mdx b/www/apps/resources/app/commerce-modules/promotion/page.mdx index 5f5f3bd8cd..06d2430b85 100644 --- a/www/apps/resources/app/commerce-modules/promotion/page.mdx +++ b/www/apps/resources/app/commerce-modules/promotion/page.mdx @@ -8,68 +8,6 @@ export const metadata = { The Promotion Module is the `@medusajs/promotion` NPM package that provides promotion-related features in your Medusa and Node.js applications. -## Features - -### Discount Functionalities - -A promotion discounts an amount or percentage of a cart's items, shipping methods, or the entire order. - -The Promotion Module allows you to store and manage promotions. - -```ts -const promotion = await promotionModuleService.createPromotions({ - code: "10%OFF", - type: "standard", - application_method: { - type: "percentage", - target_type: "order", - value: "10", - currency_code: "usd", - }, -}) -``` - -### Flexible Promotion Rules - -A promotion has rules that restricts when it's applied. For example, you can create a promotion that's only applied to VIP customers. - -```ts -const promotion = await promotionModuleService.createPromotions({ - code: "10%OFF", - type: "standard", - application_method: { - type: "percentage", - target_type: "order", - value: "10", - currency_code: "usd", - }, - rules: [ - { - attribute: "customer_group_id", - operator: "eq", - values: ["VIP"], - }, - ], -}) -``` - -### Campaign Management - -A campaign combines promotions under the same conditions, such as start and end dates. - -A campaign can also have an identifier for tracking purposes, such as tracking through tools like Google Analytics. - -```ts -const campaign = await promotionModuleService.createCampaigns({ - name: "Summer Discounts", - campaign_identifier: "G-123445", - starts_at: new Date("2024-05-02"), - ends_at: new Date("2024-07-20"), -}) -``` - ---- - ## How to Use the Promotion Module's Service You can use the Promotion Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.PROMOTION` imported from `@medusajs/utils`. @@ -134,3 +72,65 @@ const step1 = createStep("step-1", async (_, { container }) => { + +--- + +## Features + +### Discount Functionalities + +A promotion discounts an amount or percentage of a cart's items, shipping methods, or the entire order. + +The Promotion Module allows you to store and manage promotions. + +```ts +const promotion = await promotionModuleService.createPromotions({ + code: "10%OFF", + type: "standard", + application_method: { + type: "percentage", + target_type: "order", + value: "10", + currency_code: "usd", + }, +}) +``` + +### Flexible Promotion Rules + +A promotion has rules that restricts when it's applied. For example, you can create a promotion that's only applied to VIP customers. + +```ts +const promotion = await promotionModuleService.createPromotions({ + code: "10%OFF", + type: "standard", + application_method: { + type: "percentage", + target_type: "order", + value: "10", + currency_code: "usd", + }, + rules: [ + { + attribute: "customer_group_id", + operator: "eq", + values: ["VIP"], + }, + ], +}) +``` + +### Campaign Management + +A campaign combines promotions under the same conditions, such as start and end dates. + +A campaign can also have an identifier for tracking purposes, such as tracking through tools like Google Analytics. + +```ts +const campaign = await promotionModuleService.createCampaigns({ + name: "Summer Discounts", + campaign_identifier: "G-123445", + starts_at: new Date("2024-05-02"), + ends_at: new Date("2024-07-20"), +}) +``` diff --git a/www/apps/resources/app/commerce-modules/region/page.mdx b/www/apps/resources/app/commerce-modules/region/page.mdx index 15061fdf8c..0071259560 100644 --- a/www/apps/resources/app/commerce-modules/region/page.mdx +++ b/www/apps/resources/app/commerce-modules/region/page.mdx @@ -8,65 +8,6 @@ export const metadata = { The Region Module is the `@medusajs/region` NPM package that provides region-related features in your Medusa and Node.js applications. -## What is a Region? - -A region represents the area you sell products in. Each region can cover multiple countries, but uses a single currency. - ---- - -## Features - -### Region Management - -You can manage your regions to create, update, retrieve, or delete them. - -```ts -const region = await regionModuleService.createRegions({ - name: "Europe", - currency_code: "eur", -}) -``` - -### Multi-Currency Support - -As each region has a currency, you can support multiple currencies in your store by creating multiple regions. - -```ts -const regions = await regionModuleService.createRegions([ - { - name: "Europe", - currency_code: "eur", - }, - { - name: "United States of America", - currency_code: "usd", - }, -]) -``` - -### Different Settings Per Region - -Each region has its own settings, such as what countries belong to a region or its tax settings. Each region has different tax rates, payment providers, and more provided by other commerce modules. - -```ts -const regions = await regionModuleService.createRegions([ - { - name: "Europe", - currency_code: "eur", - countries: ["dk", "de", "fr", "it", "pt"], - automatic_taxes: true, - }, - { - name: "United States of America", - currency_code: "usd", - countries: ["us"], - payment_providers: ["stripe"], - }, -]) -``` - ---- - ## How to Use Region Module's Service You can use the Region Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.REGION` imported from `@medusajs/utils`. @@ -131,3 +72,62 @@ const step1 = createStep("step-1", async (_, { container }) => { + +--- + +## What is a Region? + +A region represents the area you sell products in. Each region can cover multiple countries, but uses a single currency. + +--- + +## Features + +### Region Management + +You can manage your regions to create, update, retrieve, or delete them. + +```ts +const region = await regionModuleService.createRegions({ + name: "Europe", + currency_code: "eur", +}) +``` + +### Multi-Currency Support + +As each region has a currency, you can support multiple currencies in your store by creating multiple regions. + +```ts +const regions = await regionModuleService.createRegions([ + { + name: "Europe", + currency_code: "eur", + }, + { + name: "United States of America", + currency_code: "usd", + }, +]) +``` + +### Different Settings Per Region + +Each region has its own settings, such as what countries belong to a region or its tax settings. Each region has different tax rates, payment providers, and more provided by other commerce modules. + +```ts +const regions = await regionModuleService.createRegions([ + { + name: "Europe", + currency_code: "eur", + countries: ["dk", "de", "fr", "it", "pt"], + automatic_taxes: true, + }, + { + name: "United States of America", + currency_code: "usd", + countries: ["us"], + payment_providers: ["stripe"], + }, +]) +``` diff --git a/www/apps/resources/app/commerce-modules/sales-channel/page.mdx b/www/apps/resources/app/commerce-modules/sales-channel/page.mdx index 5aab8825a6..f3b12e2ba3 100644 --- a/www/apps/resources/app/commerce-modules/sales-channel/page.mdx +++ b/www/apps/resources/app/commerce-modules/sales-channel/page.mdx @@ -8,49 +8,6 @@ export const metadata = { The Sales Channel Module is the `@medusajs/sales-channel` NPM package that provides sales-channel-related features in your Medusa and Node.js applications. -## What's a Sales Channel? - -A sales channel indicates an online or offline platform that you sell products on. - -Some use case examples for using a sales channel: - -- Implement a B2B Ecommerce Store. -- Specify different products for each channel you sell in. -- Support omnichannel in your ecommerce store. - ---- - -## Features - -### Sales Channel Management - -Manage sales channels in your store. Each sales channel has different meta information such as name or description, allowing you to easily differentiate between sales channels. - -```ts -const salesChannels = await salesChannelModuleService.createSalesChannels([ - { - name: "B2B", - }, - { - name: "Mobile App", - }, -]) -``` - -### Product Availability - -Medusa links the Product and Sales Channel modules, allowing merchants to specify a product's availability per sales channel. - -For example, B2B customers viewing products only see products in the B2B sales channel. - -### Cart and Order Scoping - -Carts, available through the Cart Module, are scoped to a sales channel. Paired with the product availability feature, you benefit from more features like allowing only products available in sales channel in a cart. - -Orders are also scoped to a sales channel due to the relation between the Sales Channel and Order modules. - ---- - ## How to Use Sales Channel Module's Service You can use the Sales Channel Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.SALES_CHANNEL` imported from `@medusajs/utils`. @@ -112,3 +69,46 @@ const step1 = createStep("step-1", async (_, { container }) => { + +--- + +## What's a Sales Channel? + +A sales channel indicates an online or offline platform that you sell products on. + +Some use case examples for using a sales channel: + +- Implement a B2B Ecommerce Store. +- Specify different products for each channel you sell in. +- Support omnichannel in your ecommerce store. + +--- + +## Features + +### Sales Channel Management + +Manage sales channels in your store. Each sales channel has different meta information such as name or description, allowing you to easily differentiate between sales channels. + +```ts +const salesChannels = await salesChannelModuleService.createSalesChannels([ + { + name: "B2B", + }, + { + name: "Mobile App", + }, +]) +``` + +### Product Availability + +Medusa links the Product and Sales Channel modules, allowing merchants to specify a product's availability per sales channel. + +For example, B2B customers viewing products only see products in the B2B sales channel. + +### Cart and Order Scoping + +Carts, available through the Cart Module, are scoped to a sales channel. Paired with the product availability feature, you benefit from more features like allowing only products available in sales channel in a cart. + +Orders are also scoped to a sales channel due to the relation between the Sales Channel and Order modules. diff --git a/www/apps/resources/app/commerce-modules/stock-location/page.mdx b/www/apps/resources/app/commerce-modules/stock-location/page.mdx index 6f22c69a2c..c7c0fdbcb7 100644 --- a/www/apps/resources/app/commerce-modules/stock-location/page.mdx +++ b/www/apps/resources/app/commerce-modules/stock-location/page.mdx @@ -8,36 +8,6 @@ export const metadata = { The Stock Location Module is the `@medusajs/stock-location-next` NPM package that provides stock-location-related features in your Medusa and Node.js applications. -## Features - -### Stock Location Management - -Store and manage stock locations. Stock locations are associated with data models of other modules that require a location, such as the [Inventory Module's InventoryLevel](../inventory/concepts/page.mdx#inventory-level). - -```ts -const stockLocation = await stockLocationModuleService.createStockLocations({ - name: "Warehouse 1", -}) -``` - -### Address Management - -Manage the address of each stock location. - -```ts -const stockLocation = await stockLocationModuleService.updateStockLocations({ - id: "sloc_123", - address: { - country_code: "us", - city: "New York City", - address_1: "52 Stone St", - postal_code: "10004", - }, -}) -``` - ---- - ## How to Use Stock Location Module's Service You can use the Stock Location Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.STOCK_LOCATION` imported from `@medusajs/utils`. @@ -101,3 +71,33 @@ const step1 = createStep("step-1", async (_, { container }) => { + +--- + +## Features + +### Stock Location Management + +Store and manage stock locations. Stock locations are associated with data models of other modules that require a location, such as the [Inventory Module's InventoryLevel](../inventory/concepts/page.mdx#inventory-level). + +```ts +const stockLocation = await stockLocationModuleService.createStockLocations({ + name: "Warehouse 1", +}) +``` + +### Address Management + +Manage the address of each stock location. + +```ts +const stockLocation = await stockLocationModuleService.updateStockLocations({ + id: "sloc_123", + address: { + country_code: "us", + city: "New York City", + address_1: "52 Stone St", + postal_code: "10004", + }, +}) +``` diff --git a/www/apps/resources/app/commerce-modules/store/page.mdx b/www/apps/resources/app/commerce-modules/store/page.mdx index 556b3301af..6157f2e8ec 100644 --- a/www/apps/resources/app/commerce-modules/store/page.mdx +++ b/www/apps/resources/app/commerce-modules/store/page.mdx @@ -8,38 +8,6 @@ export const metadata = { The Store Module is the `@medusajs/store` NPM package that provides store-related features in your Medusa and Node.js applications. -## Features - -### Store Management - -A store holds the main configurations of your commerce store, such as supported currencies, default region and sales channel, and more. - -```ts -const store = await storeModuleService.createStores({ - name: "My Store", - supported_currency_codes: ["usd"], -}) -``` - -### Multi-Tenancy Support - -You can create multiple stores, each having its own configurations. - -```ts -const stores = await storeModuleService.createStores([ - { - name: "USA Store", - supported_currency_codes: ["usd"], - }, - { - name: "Europe Store", - supported_currency_codes: ["eur"], - }, -]) -``` - ---- - ## How to Use Store Module's Service You can use the Store Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.STORE` imported from `@medusajs/utils`. @@ -104,3 +72,35 @@ const step1 = createStep("step-1", async (_, { container }) => { + +--- + +## Features + +### Store Management + +A store holds the main configurations of your commerce store, such as supported currencies, default region and sales channel, and more. + +```ts +const store = await storeModuleService.createStores({ + name: "My Store", + supported_currency_codes: ["usd"], +}) +``` + +### Multi-Tenancy Support + +You can create multiple stores, each having its own configurations. + +```ts +const stores = await storeModuleService.createStores([ + { + name: "USA Store", + supported_currency_codes: ["usd"], + }, + { + name: "Europe Store", + supported_currency_codes: ["eur"], + }, +]) +``` diff --git a/www/apps/resources/app/commerce-modules/tax/page.mdx b/www/apps/resources/app/commerce-modules/tax/page.mdx index 98a313611e..d1214cb70f 100644 --- a/www/apps/resources/app/commerce-modules/tax/page.mdx +++ b/www/apps/resources/app/commerce-modules/tax/page.mdx @@ -8,6 +8,73 @@ export const metadata = { The Tax Module is the `@medusajs/tax` NPM package that provides tax-related features in your Medusa and Node.js applications. +## How to Use Tax Module's Service + +You can use the Tax Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.TAX` imported from `@medusajs/utils`. + +For example: + + + + + ```ts title="src/api/store/custom/route.ts" + import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" + import { ITaxModuleService } from "@medusajs/types" + import { ModuleRegistrationName } from "@medusajs/utils" + +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const taxModuleService: ITaxModuleService = req.scope.resolve( + ModuleRegistrationName.TAX + ) + + res.json({ + tax_regions: await taxModuleService.listTaxRegions(), + }) +} +``` + + + + + ```ts title="src/subscribers/custom-handler.ts" + import { SubscriberArgs } from "@medusajs/medusa" + import { ITaxModuleService } from "@medusajs/types" + import { ModuleRegistrationName } from "@medusajs/utils" + +export default async function subscriberHandler({ container }: SubscriberArgs) { + const taxModuleService: ITaxModuleService = container.resolve( + ModuleRegistrationName.TAX + ) + + const taxRegions = await taxModuleService.listTaxRegions() +} +``` + + + + + ```ts title="src/workflows/hello-world/step1.ts" + import { createStep } from "@medusajs/workflows-sdk" + import { ITaxModuleService } from "@medusajs/types" + import { ModuleRegistrationName } from "@medusajs/utils" + +const step1 = createStep("step-1", async (_, { container }) => { + const taxModuleService: ITaxModuleService = container.resolve( + ModuleRegistrationName.TAX + ) + + const taxRegions = await taxModuleService.listTaxRegions() +}) +``` + + + + +--- + ## Features ### Tax Settings Per Region @@ -79,70 +146,3 @@ const taxLines = await taxModuleService.getTaxLines( ## Configure Tax Module Refer to [this documentation](./module-options/page.mdx) for details on the module's options. - ---- - -## How to Use Tax Module's Service - -You can use the Tax Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.TAX` imported from `@medusajs/utils`. - -For example: - - - - - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ITaxModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/utils" - -export async function GET( - req: MedusaRequest, - res: MedusaResponse -): Promise { - const taxModuleService: ITaxModuleService = req.scope.resolve( - ModuleRegistrationName.TAX - ) - - res.json({ - tax_regions: await taxModuleService.listTaxRegions(), - }) -} -``` - - - - - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { ITaxModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/utils" - -export default async function subscriberHandler({ container }: SubscriberArgs) { - const taxModuleService: ITaxModuleService = container.resolve( - ModuleRegistrationName.TAX - ) - - const taxRegions = await taxModuleService.listTaxRegions() -} -``` - - - - - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { ITaxModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/utils" - -const step1 = createStep("step-1", async (_, { container }) => { - const taxModuleService: ITaxModuleService = container.resolve( - ModuleRegistrationName.TAX - ) - - const taxRegions = await taxModuleService.listTaxRegions() -}) -``` - - - diff --git a/www/apps/resources/app/commerce-modules/user/page.mdx b/www/apps/resources/app/commerce-modules/user/page.mdx index 1534787f10..0b3a42c0c6 100644 --- a/www/apps/resources/app/commerce-modules/user/page.mdx +++ b/www/apps/resources/app/commerce-modules/user/page.mdx @@ -8,41 +8,6 @@ export const metadata = { The User Module is the `@medusajs/user` NPM package that provides user-related features in your Medusa and Node.js applications. -## Features - -### User Management - -Manage and store your users through Create, Read, Update, and Delete (CRUD) operations: - -```ts -const user = await userModuleService.createUsers({ - email: "user@example.com", - first_name: "John", - last_name: "Smith", -}) -``` - -### Invite Users - -Invite users to join your store and manage those invites, with expiry and revalidation features. - -```ts -const invite = await userModuleService.createInvites({ - email: "user2@example.com", -}) - -// refresh token later -await userModuleService.refreshInviteTokens([invite.id]) -``` - ---- - -## Configure User Module - -Refer to [this documentation](./module-options/page.mdx) for details on the module's options. - ---- - ## How to Use User Module's Service You can use the User Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.USER` imported from `@medusajs/utils`. @@ -107,3 +72,38 @@ const step1 = createStep("step-1", async (_, { container }) => { + +--- + +## Features + +### User Management + +Manage and store your users through Create, Read, Update, and Delete (CRUD) operations: + +```ts +const user = await userModuleService.createUsers({ + email: "user@example.com", + first_name: "John", + last_name: "Smith", +}) +``` + +### Invite Users + +Invite users to join your store and manage those invites, with expiry and revalidation features. + +```ts +const invite = await userModuleService.createInvites({ + email: "user2@example.com", +}) + +// refresh token later +await userModuleService.refreshInviteTokens([invite.id]) +``` + +--- + +## Configure User Module + +Refer to [this documentation](./module-options/page.mdx) for details on the module's options. diff --git a/www/apps/resources/app/storefront-development/products/price/page.mdx b/www/apps/resources/app/storefront-development/products/price/page.mdx index 379b7900f1..f6acb87451 100644 --- a/www/apps/resources/app/storefront-development/products/price/page.mdx +++ b/www/apps/resources/app/storefront-development/products/price/page.mdx @@ -14,10 +14,10 @@ When you retrieve products either with the [List Products](!api!/store#products_ You also must pass at least one of the following query parameters to retrieve the correct product variant price: -- `region_id`: The ID of the customer's region. This parameter must be included if you want to apply taxes on the product's price. -- `country_code`: The customer's country code. This parameter must be included if you want to apply taxes on the product's price. -- `customer_id`: The ID of the customer viewing the prices. This is useful when you have a promotion or price list overriding a product's price for specific customer groups. -- `customer_group_id`: The ID of the group of the customer viewing the prices. This is useful when you have a promotion or price list overriding a product's price for specific customer groups. +- `region_id`: The ID of the customer's region. This parameter must be included if you want to apply taxes on the product variant's price. +- `country_code`: The customer's country code. This parameter must be included if you want to apply taxes on the product variant's price. +- `province`: The province, which can be taken from a customer's address. This parameter helps further narrowing down the taxes applied on a the product variant's prices. +- `cart_id`: The ID of the customer's cart, if available. If set, the cart's region and shipping address's country code and province are used instead of the `region_id`, `country_code`, and `province` parameters. For example: @@ -42,6 +42,12 @@ fetch(`http://localhost:9000/store/products/${id}?${queryParams.toString()}`, { In this example, you pass the selected region's ID as a query parameter with the `fields` query parameter set to `*variants.calculated_price`. +### Prices for Authenticated Customer + +If you pass the customer's authentication token / session in the request, the customer and their group, if available, are used to retrieve more accurate prices. + +For example, if a promotion applies to the customer's group, the promotion's prices are used. + --- ## Product Variant's Price Properties diff --git a/www/apps/resources/generated/edit-dates.mjs b/www/apps/resources/generated/edit-dates.mjs index aabc1deaa0..10c6075e32 100644 --- a/www/apps/resources/generated/edit-dates.mjs +++ b/www/apps/resources/generated/edit-dates.mjs @@ -4,7 +4,7 @@ export const generatedEditDates = { "app/commerce-modules/auth/authentication-route/page.mdx": "2024-09-05T12:06:38.155Z", "app/commerce-modules/auth/examples/page.mdx": "2024-09-05T08:09:32.466Z", "app/commerce-modules/auth/module-options/page.mdx": "2024-07-04T17:26:03+03:00", - "app/commerce-modules/auth/page.mdx": "2024-09-05T08:08:28.782Z", + "app/commerce-modules/auth/page.mdx": "2024-09-05T14:59:56.146Z", "app/commerce-modules/cart/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/cart/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/cart/concepts/page.mdx": "2024-06-26T07:55:59+00:00", @@ -12,18 +12,18 @@ export const generatedEditDates = { "app/commerce-modules/cart/promotions/page.mdx": "2024-06-26T07:55:59+00:00", "app/commerce-modules/cart/relations-to-other-modules/page.mdx": "2024-05-29T11:08:06+00:00", "app/commerce-modules/cart/tax-lines/page.mdx": "2024-06-26T07:55:59+00:00", - "app/commerce-modules/cart/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/cart/page.mdx": "2024-09-05T15:00:13.786Z", "app/commerce-modules/currency/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/currency/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/currency/examples/page.mdx": "2024-07-04T17:26:03+03:00", "app/commerce-modules/currency/relations-to-other-modules/page.mdx": "2024-05-29T11:08:06+00:00", - "app/commerce-modules/currency/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/currency/page.mdx": "2024-09-05T15:00:24.903Z", "app/commerce-modules/customer/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/customer/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/customer/customer-accounts/page.mdx": "2024-06-26T07:55:59+00:00", "app/commerce-modules/customer/examples/page.mdx": "2024-07-04T17:26:03+03:00", "app/commerce-modules/customer/relations-to-other-modules/page.mdx": "2024-05-29T11:08:06+00:00", - "app/commerce-modules/customer/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/customer/page.mdx": "2024-09-05T15:00:39.831Z", "app/commerce-modules/fulfillment/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/fulfillment/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/fulfillment/concepts/page.mdx": "2024-06-19T13:02:16+00:00", @@ -32,14 +32,14 @@ export const generatedEditDates = { "app/commerce-modules/fulfillment/module-options/page.mdx": "2024-07-22T07:17:15+00:00", "app/commerce-modules/fulfillment/relations-to-other-modules/page.mdx": "2024-05-29T11:08:06+00:00", "app/commerce-modules/fulfillment/shipping-option/page.mdx": "2024-06-26T07:55:59+00:00", - "app/commerce-modules/fulfillment/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/fulfillment/page.mdx": "2024-09-05T15:00:57.269Z", "app/commerce-modules/inventory/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/inventory/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/inventory/concepts/page.mdx": "2024-06-26T07:55:59+00:00", "app/commerce-modules/inventory/examples/page.mdx": "2024-07-04T17:26:03+03:00", "app/commerce-modules/inventory/inventory-in-flows/page.mdx": "2024-06-26T07:55:59+00:00", "app/commerce-modules/inventory/relations-to-other-modules/page.mdx": "2024-06-26T07:55:59+00:00", - "app/commerce-modules/inventory/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/inventory/page.mdx": "2024-09-05T15:01:10.522Z", "app/commerce-modules/order/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/order/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/order/claim/page.mdx": "2024-07-09T18:14:30+03:00", @@ -51,7 +51,7 @@ export const generatedEditDates = { "app/commerce-modules/order/return/page.mdx": "2024-07-09T18:14:30+03:00", "app/commerce-modules/order/tax-lines/page.mdx": "2024-07-09T18:14:30+03:00", "app/commerce-modules/order/transactions/page.mdx": "2024-07-09T18:14:30+03:00", - "app/commerce-modules/order/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/order/page.mdx": "2024-09-05T15:01:23.809Z", "app/commerce-modules/payment/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/payment/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/payment/examples/page.mdx": "2024-07-04T17:26:03+03:00", @@ -64,7 +64,7 @@ export const generatedEditDates = { "app/commerce-modules/payment/payment-session/page.mdx": "2024-06-26T07:55:59+00:00", "app/commerce-modules/payment/relations-to-other-modules/page.mdx": "2024-05-29T11:08:06+00:00", "app/commerce-modules/payment/webhook-events/page.mdx": "2024-05-29T11:08:06+00:00", - "app/commerce-modules/payment/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/payment/page.mdx": "2024-09-05T15:01:36.073Z", "app/commerce-modules/pricing/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/pricing/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/pricing/concepts/page.mdx": "2024-07-01T16:34:13+00:00", @@ -73,14 +73,14 @@ export const generatedEditDates = { "app/commerce-modules/pricing/price-rules/page.mdx": "2024-07-01T16:34:13+00:00", "app/commerce-modules/pricing/relations-to-other-modules/page.mdx": "2024-05-29T11:08:06+00:00", "app/commerce-modules/pricing/tax-inclusive-pricing/page.mdx": "2024-07-18T19:03:37+02:00", - "app/commerce-modules/pricing/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/pricing/page.mdx": "2024-09-05T15:01:47.750Z", "app/commerce-modules/product/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/product/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/product/examples/page.mdx": "2024-07-04T17:26:03+03:00", "app/commerce-modules/product/guides/price/page.mdx": "2024-07-31T17:01:33+03:00", "app/commerce-modules/product/guides/price-with-taxes/page.mdx": "2024-08-01T15:32:54+00:00", "app/commerce-modules/product/relations-to-other-modules/page.mdx": "2024-06-26T07:55:59+00:00", - "app/commerce-modules/product/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/product/page.mdx": "2024-09-05T15:02:02.758Z", "app/commerce-modules/promotion/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/promotion/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/promotion/actions/page.mdx": "2024-06-26T07:55:59+00:00", @@ -89,29 +89,29 @@ export const generatedEditDates = { "app/commerce-modules/promotion/concepts/page.mdx": "2024-06-26T07:55:59+00:00", "app/commerce-modules/promotion/examples/page.mdx": "2024-07-04T17:26:03+03:00", "app/commerce-modules/promotion/relations-to-other-modules/page.mdx": "2024-05-29T11:08:06+00:00", - "app/commerce-modules/promotion/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/promotion/page.mdx": "2024-09-05T15:02:15.009Z", "app/commerce-modules/region/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/region/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/region/examples/page.mdx": "2024-07-04T17:26:03+03:00", "app/commerce-modules/region/relations-to-other-modules/page.mdx": "2024-05-29T11:08:06+00:00", - "app/commerce-modules/region/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/region/page.mdx": "2024-09-05T15:02:29.153Z", "app/commerce-modules/sales-channel/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/sales-channel/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/sales-channel/examples/page.mdx": "2024-07-04T17:26:03+03:00", "app/commerce-modules/sales-channel/publishable-api-keys/page.mdx": "2024-05-29T11:08:06+00:00", "app/commerce-modules/sales-channel/relations-to-other-modules/page.mdx": "2024-05-29T11:08:06+00:00", - "app/commerce-modules/sales-channel/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/sales-channel/page.mdx": "2024-09-05T15:02:40.658Z", "app/commerce-modules/stock-location/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/stock-location/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/stock-location/concepts/page.mdx": "2024-05-03T17:36:38+03:00", "app/commerce-modules/stock-location/examples/page.mdx": "2024-07-04T17:26:03+03:00", "app/commerce-modules/stock-location/relations-to-other-modules/page.mdx": "2024-05-29T11:08:06+00:00", - "app/commerce-modules/stock-location/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/stock-location/page.mdx": "2024-09-05T15:02:53.237Z", "app/commerce-modules/store/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/store/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/store/examples/page.mdx": "2024-07-04T17:26:03+03:00", "app/commerce-modules/store/relations-to-other-modules/page.mdx": "2024-05-29T11:08:06+00:00", - "app/commerce-modules/store/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/store/page.mdx": "2024-09-05T15:03:06.211Z", "app/commerce-modules/tax/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/tax/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/tax/examples/page.mdx": "2024-07-04T17:26:03+03:00", @@ -119,13 +119,13 @@ export const generatedEditDates = { "app/commerce-modules/tax/tax-calculation-with-provider/page.mdx": "2024-07-01T10:21:19+03:00", "app/commerce-modules/tax/tax-rates-and-rules/page.mdx": "2024-06-26T07:55:59+00:00", "app/commerce-modules/tax/tax-region/page.mdx": "2024-05-29T11:08:06+00:00", - "app/commerce-modules/tax/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/tax/page.mdx": "2024-09-05T15:03:18.495Z", "app/commerce-modules/user/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/user/_events/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/user/examples/page.mdx": "2024-07-04T17:26:03+03:00", "app/commerce-modules/user/module-options/page.mdx": "2024-07-04T17:26:03+03:00", "app/commerce-modules/user/user-creation-flows/page.mdx": "2024-06-26T07:55:59+00:00", - "app/commerce-modules/user/page.mdx": "2024-08-05T07:24:27+00:00", + "app/commerce-modules/user/page.mdx": "2024-09-05T15:03:30.835Z", "app/commerce-modules/page.mdx": "2024-05-03T17:36:38+03:00", "app/contribution-guidelines/_admin-translations/page.mdx": "2024-05-13T18:55:11+03:00", "app/contribution-guidelines/docs/page.mdx": "2024-05-13T18:55:11+03:00", @@ -199,7 +199,7 @@ export const generatedEditDates = { "app/storefront-development/products/price/examples/sale-price/page.mdx": "2024-07-30T12:52:21+03:00", "app/storefront-development/products/price/examples/show-price/page.mdx": "2024-07-30T12:52:21+03:00", "app/storefront-development/products/price/examples/tax-price/page.mdx": "2024-07-31T17:01:33+03:00", - "app/storefront-development/products/price/page.mdx": "2024-07-30T12:52:21+03:00", + "app/storefront-development/products/price/page.mdx": "2024-09-05T14:58:05.735Z", "app/storefront-development/products/retrieve/page.mdx": "2024-06-13T12:21:54+03:00", "app/storefront-development/products/variants/page.mdx": "2024-06-13T12:21:54+03:00", "app/storefront-development/products/page.mdx": "2024-06-11T19:55:56+02:00", @@ -225,6 +225,9 @@ export const generatedEditDates = { "app/commerce-modules/auth/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00", "app/commerce-modules/auth/auth-flows/page.mdx": "2024-09-05T08:50:11.671Z", "app/commerce-modules/auth/_events/page.mdx": "2024-07-03T19:27:13+03:00", + "app/commerce-modules/auth/auth-identity-and-actor-types/page.mdx": "2024-07-31T17:01:33+03:00", + "app/commerce-modules/api-key/page.mdx": "2024-09-05T14:59:37.604Z", + "app/commerce-modules/auth/create-actor-type/page.mdx": "2024-07-31T17:01:33+03:00", "app/commerce-modules/auth/auth-identity-and-actor-types/page.mdx": "2024-09-05T08:11:28.936Z", "app/commerce-modules/api-key/page.mdx": "2024-08-05T07:24:27+00:00", "app/commerce-modules/auth/create-actor-type/page.mdx": "2024-09-05T09:24:48.099Z",