chore(core-flows): [14] export types and steps, add basic TSDocs (#8524)

This commit is contained in:
Shahed Nasser
2024-08-08 20:03:13 +03:00
committed by GitHub
parent 288ed2747b
commit e386216512
28 changed files with 97 additions and 13 deletions
@@ -4,6 +4,9 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const batchLinkProductsToCollectionStepId = export const batchLinkProductsToCollectionStepId =
"batch-link-products-to-collection" "batch-link-products-to-collection"
/**
* This step creates links between product and collection records.
*/
export const batchLinkProductsToCollectionStep = createStep( export const batchLinkProductsToCollectionStep = createStep(
batchLinkProductsToCollectionStepId, batchLinkProductsToCollectionStepId,
async (data: LinkWorkflowInput, { container }) => { async (data: LinkWorkflowInput, { container }) => {
@@ -4,6 +4,9 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const batchLinkProductsToCategoryStepId = export const batchLinkProductsToCategoryStepId =
"batch-link-products-to-category" "batch-link-products-to-category"
/**
* This step creates links between product and category records.
*/
export const batchLinkProductsToCategoryStep = createStep( export const batchLinkProductsToCategoryStep = createStep(
batchLinkProductsToCategoryStepId, batchLinkProductsToCategoryStepId,
async ( async (
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const createCollectionsStepId = "create-collections" export const createCollectionsStepId = "create-collections"
/**
* This step creates one or more collection.
*/
export const createCollectionsStep = createStep( export const createCollectionsStep = createStep(
createCollectionsStepId, createCollectionsStepId,
async (data: ProductTypes.CreateProductCollectionDTO[], { container }) => { async (data: ProductTypes.CreateProductCollectionDTO[], { container }) => {
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const createProductOptionsStepId = "create-product-options" export const createProductOptionsStepId = "create-product-options"
/**
* This step creates one or more product options.
*/
export const createProductOptionsStep = createStep( export const createProductOptionsStep = createStep(
createProductOptionsStepId, createProductOptionsStepId,
async (data: ProductTypes.CreateProductOptionDTO[], { container }) => { async (data: ProductTypes.CreateProductOptionDTO[], { container }) => {
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const createProductTagsStepId = "create-product-tags" export const createProductTagsStepId = "create-product-tags"
/**
* This step creates one or more product tags.
*/
export const createProductTagsStep = createStep( export const createProductTagsStep = createStep(
createProductTagsStepId, createProductTagsStepId,
async (data: ProductTypes.CreateProductTagDTO[], { container }) => { async (data: ProductTypes.CreateProductTagDTO[], { container }) => {
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const createProductTypesStepId = "create-product-types" export const createProductTypesStepId = "create-product-types"
/**
* This step creates one or more product types.
*/
export const createProductTypesStep = createStep( export const createProductTypesStep = createStep(
createProductTypesStepId, createProductTypesStepId,
async (data: ProductTypes.CreateProductTypeDTO[], { container }) => { async (data: ProductTypes.CreateProductTypeDTO[], { container }) => {
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const createProductVariantsStepId = "create-product-variants" export const createProductVariantsStepId = "create-product-variants"
/**
* This step creates one or more product variants.
*/
export const createProductVariantsStep = createStep( export const createProductVariantsStep = createStep(
createProductVariantsStepId, createProductVariantsStepId,
async (data: ProductTypes.CreateProductVariantDTO[], { container }) => { async (data: ProductTypes.CreateProductVariantDTO[], { container }) => {
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const createProductsStepId = "create-products" export const createProductsStepId = "create-products"
/**
* This step creates one or more products.
*/
export const createProductsStep = createStep( export const createProductsStep = createStep(
createProductsStepId, createProductsStepId,
async (data: ProductTypes.CreateProductDTO[], { container }) => { async (data: ProductTypes.CreateProductDTO[], { container }) => {
@@ -1,7 +1,7 @@
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils" import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk" import { createStep, StepResponse } from "@medusajs/workflows-sdk"
type StepInput = { export type CreateVariantPricingLinkStepInput = {
links: { links: {
variant_id: string variant_id: string
price_set_id: string price_set_id: string
@@ -9,9 +9,12 @@ type StepInput = {
} }
export const createVariantPricingLinkStepId = "create-variant-pricing-link" export const createVariantPricingLinkStepId = "create-variant-pricing-link"
/**
* This step creates links between variant and price set records.
*/
export const createVariantPricingLinkStep = createStep( export const createVariantPricingLinkStep = createStep(
createVariantPricingLinkStepId, createVariantPricingLinkStepId,
async (data: StepInput, { container }) => { async (data: CreateVariantPricingLinkStepInput, { container }) => {
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK) const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
await remoteLink.create( await remoteLink.create(
data.links.map((entry) => ({ data.links.map((entry) => ({
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const deleteCollectionsStepId = "delete-collections" export const deleteCollectionsStepId = "delete-collections"
/**
* This step deletes one or more collections.
*/
export const deleteCollectionsStep = createStep( export const deleteCollectionsStep = createStep(
deleteCollectionsStepId, deleteCollectionsStepId,
async (ids: string[], { container }) => { async (ids: string[], { container }) => {
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const deleteProductOptionsStepId = "delete-product-options" export const deleteProductOptionsStepId = "delete-product-options"
/**
* This step deletes one or more product options.
*/
export const deleteProductOptionsStep = createStep( export const deleteProductOptionsStep = createStep(
deleteProductOptionsStepId, deleteProductOptionsStepId,
async (ids: string[], { container }) => { async (ids: string[], { container }) => {
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const deleteProductTagsStepId = "delete-product-tags" export const deleteProductTagsStepId = "delete-product-tags"
/**
* This step deletes one or more product tags.
*/
export const deleteProductTagsStep = createStep( export const deleteProductTagsStep = createStep(
deleteProductTagsStepId, deleteProductTagsStepId,
async (ids: string[], { container }) => { async (ids: string[], { container }) => {
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const deleteProductTypesStepId = "delete-product-types" export const deleteProductTypesStepId = "delete-product-types"
/**
* This step deletes one or more product types.
*/
export const deleteProductTypesStep = createStep( export const deleteProductTypesStep = createStep(
deleteProductTypesStepId, deleteProductTypesStepId,
async (ids: string[], { container }) => { async (ids: string[], { container }) => {
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const deleteProductVariantsStepId = "delete-product-variants" export const deleteProductVariantsStepId = "delete-product-variants"
/**
* This step deletes one or more product variants.
*/
export const deleteProductVariantsStep = createStep( export const deleteProductVariantsStep = createStep(
deleteProductVariantsStepId, deleteProductVariantsStepId,
async (ids: string[], { container }) => { async (ids: string[], { container }) => {
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const deleteProductsStepId = "delete-products" export const deleteProductsStepId = "delete-products"
/**
* This step deletes one or more products.
*/
export const deleteProductsStep = createStep( export const deleteProductsStep = createStep(
deleteProductsStepId, deleteProductsStepId,
async (ids: string[], { container }) => { async (ids: string[], { container }) => {
@@ -58,6 +58,9 @@ const csvSortFunction = (a: string, b: string) => {
} }
export const generateProductCsvStepId = "generate-product-csv" export const generateProductCsvStepId = "generate-product-csv"
/**
* This step generates a CSV file to be exported.
*/
export const generateProductCsvStep = createStep( export const generateProductCsvStep = createStep(
generateProductCsvStepId, generateProductCsvStepId,
async (products: HttpTypes.AdminProduct[], { container }) => { async (products: HttpTypes.AdminProduct[], { container }) => {
@@ -5,15 +5,18 @@ import {
} from "@medusajs/utils" } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk" import { createStep, StepResponse } from "@medusajs/workflows-sdk"
type StepInput = { export type GetAllProductsStepInput = {
select: string[] select: string[]
filter?: FilterableProductProps filter?: FilterableProductProps
} }
export const getAllProductsStepId = "get-all-products" export const getAllProductsStepId = "get-all-products"
/**
* This step retrieves all products.
*/
export const getAllProductsStep = createStep( export const getAllProductsStep = createStep(
getAllProductsStepId, getAllProductsStepId,
async (data: StepInput, { container }) => { async (data: GetAllProductsStepInput, { container }) => {
const remoteQuery: RemoteQueryFunction = container.resolve( const remoteQuery: RemoteQueryFunction = container.resolve(
ContainerRegistrationKeys.REMOTE_QUERY ContainerRegistrationKeys.REMOTE_QUERY
) )
@@ -2,14 +2,17 @@ import { IProductModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils" import { ModuleRegistrationName } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk" import { createStep, StepResponse } from "@medusajs/workflows-sdk"
type StepInput = { export type GetProductsStepInput = {
ids?: string[] ids?: string[]
} }
export const getProductsStepId = "get-products" export const getProductsStepId = "get-products"
/**
* This step retrieves products.
*/
export const getProductsStep = createStep( export const getProductsStep = createStep(
getProductsStepId, getProductsStepId,
async (data: StepInput, { container }) => { async (data: GetProductsStepInput, { container }) => {
const service = container.resolve<IProductModuleService>( const service = container.resolve<IProductModuleService>(
ModuleRegistrationName.PRODUCT ModuleRegistrationName.PRODUCT
) )
@@ -6,14 +6,17 @@ import {
} from "@medusajs/utils" } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk" import { createStep, StepResponse } from "@medusajs/workflows-sdk"
type StepInput = { export type GetVariantPricingLinkStepInput = {
ids: string[] ids: string[]
} }
export const getVariantPricingLinkStepId = "get-variant-pricing-link" export const getVariantPricingLinkStepId = "get-variant-pricing-link"
/**
* This step retrieves links between a product variant and its linked price sets.
*/
export const getVariantPricingLinkStep = createStep( export const getVariantPricingLinkStep = createStep(
getVariantPricingLinkStepId, getVariantPricingLinkStepId,
async (data: StepInput, { container }) => { async (data: GetVariantPricingLinkStepInput, { container }) => {
if (!data.ids.length) { if (!data.ids.length) {
return new StepResponse([]) return new StepResponse([])
} }
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const groupProductsForBatchStepId = "group-products-for-batch" export const groupProductsForBatchStepId = "group-products-for-batch"
/**
* This step groups products to be created and updated.
*/
export const groupProductsForBatchStep = createStep( export const groupProductsForBatchStep = createStep(
groupProductsForBatchStepId, groupProductsForBatchStepId,
async ( async (
@@ -13,6 +13,9 @@ import {
import { normalizeV1Products } from "../helpers/normalize-v1-import" import { normalizeV1Products } from "../helpers/normalize-v1-import"
export const parseProductCsvStepId = "parse-product-csv" export const parseProductCsvStepId = "parse-product-csv"
/**
* This step parses a CSV file holding products to import.
*/
export const parseProductCsvStep = createStep( export const parseProductCsvStep = createStep(
parseProductCsvStepId, parseProductCsvStepId,
async (fileContent: string, { container }) => { async (fileContent: string, { container }) => {
@@ -5,12 +5,15 @@ import {
} from "@medusajs/utils" } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
type UpdateCollectionsStepInput = { export type UpdateCollectionsStepInput = {
selector: ProductTypes.FilterableProductCollectionProps selector: ProductTypes.FilterableProductCollectionProps
update: ProductTypes.UpdateProductCollectionDTO update: ProductTypes.UpdateProductCollectionDTO
} }
export const updateCollectionsStepId = "update-collections" export const updateCollectionsStepId = "update-collections"
/**
* This step updates collections matching the specified filters.
*/
export const updateCollectionsStep = createStep( export const updateCollectionsStep = createStep(
updateCollectionsStepId, updateCollectionsStepId,
async (data: UpdateCollectionsStepInput, { container }) => { async (data: UpdateCollectionsStepInput, { container }) => {
@@ -5,12 +5,15 @@ import {
} from "@medusajs/utils" } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
type UpdateProductOptionsStepInput = { export type UpdateProductOptionsStepInput = {
selector: ProductTypes.FilterableProductOptionProps selector: ProductTypes.FilterableProductOptionProps
update: ProductTypes.UpdateProductOptionDTO update: ProductTypes.UpdateProductOptionDTO
} }
export const updateProductOptionsStepId = "update-product-options" export const updateProductOptionsStepId = "update-product-options"
/**
* This step updates product options matching the specified filters.
*/
export const updateProductOptionsStep = createStep( export const updateProductOptionsStep = createStep(
updateProductOptionsStepId, updateProductOptionsStepId,
async (data: UpdateProductOptionsStepInput, { container }) => { async (data: UpdateProductOptionsStepInput, { container }) => {
@@ -5,12 +5,15 @@ import {
} from "@medusajs/utils" } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
type UpdateProductTagsStepInput = { export type UpdateProductTagsStepInput = {
selector: ProductTypes.FilterableProductTagProps selector: ProductTypes.FilterableProductTagProps
update: ProductTypes.UpdateProductTagDTO update: ProductTypes.UpdateProductTagDTO
} }
export const updateProductTagsStepId = "update-product-tags" export const updateProductTagsStepId = "update-product-tags"
/**
* This step updates product tags matching the specified filters.
*/
export const updateProductTagsStep = createStep( export const updateProductTagsStep = createStep(
updateProductTagsStepId, updateProductTagsStepId,
async (data: UpdateProductTagsStepInput, { container }) => { async (data: UpdateProductTagsStepInput, { container }) => {
@@ -5,12 +5,15 @@ import {
} from "@medusajs/utils" } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
type UpdateProductTypesStepInput = { export type UpdateProductTypesStepInput = {
selector: ProductTypes.FilterableProductTypeProps selector: ProductTypes.FilterableProductTypeProps
update: ProductTypes.UpdateProductTypeDTO update: ProductTypes.UpdateProductTypeDTO
} }
export const updateProductTypesStepId = "update-product-types" export const updateProductTypesStepId = "update-product-types"
/**
* This step updates product types matching the specified filters.
*/
export const updateProductTypesStep = createStep( export const updateProductTypesStep = createStep(
updateProductTypesStepId, updateProductTypesStepId,
async (data: UpdateProductTypesStepInput, { container }) => { async (data: UpdateProductTypesStepInput, { container }) => {
@@ -6,7 +6,7 @@ import {
} from "@medusajs/utils" } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { StepResponse, createStep } from "@medusajs/workflows-sdk"
type UpdateProductVariantsStepInput = export type UpdateProductVariantsStepInput =
| { | {
selector: ProductTypes.FilterableProductVariantProps selector: ProductTypes.FilterableProductVariantProps
update: ProductTypes.UpdateProductVariantDTO update: ProductTypes.UpdateProductVariantDTO
@@ -16,6 +16,9 @@ type UpdateProductVariantsStepInput =
} }
export const updateProductVariantsStepId = "update-product-variants" export const updateProductVariantsStepId = "update-product-variants"
/**
* This step updates one or more product variants.
*/
export const updateProductVariantsStep = createStep( export const updateProductVariantsStep = createStep(
updateProductVariantsStepId, updateProductVariantsStepId,
async (data: UpdateProductVariantsStepInput, { container }) => { async (data: UpdateProductVariantsStepInput, { container }) => {
@@ -16,6 +16,9 @@ export type UpdateProductsStepInput =
} }
export const updateProductsStepId = "update-products" export const updateProductsStepId = "update-products"
/**
* This step updates one or more products.
*/
export const updateProductsStep = createStep( export const updateProductsStep = createStep(
updateProductsStepId, updateProductsStepId,
async (data: UpdateProductsStepInput, { container }) => { async (data: UpdateProductsStepInput, { container }) => {
@@ -2,6 +2,9 @@ import { createStep } from "@medusajs/workflows-sdk"
export const waitConfirmationProductImportStepId = export const waitConfirmationProductImportStepId =
"wait-confirmation-product-import" "wait-confirmation-product-import"
/**
* This step waits until a product import is confirmed.
*/
export const waitConfirmationProductImportStep = createStep( export const waitConfirmationProductImportStep = createStep(
{ {
name: waitConfirmationProductImportStepId, name: waitConfirmationProductImportStepId,