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

This commit is contained in:
Shahed Nasser
2024-08-08 20:03:38 +03:00
committed by GitHub
parent 8ee3da4644
commit faa09d12f6
25 changed files with 95 additions and 24 deletions

View File

@@ -6,16 +6,19 @@ import {
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
interface StepInput {
export interface ListShippingOptionsForContextStepInput {
context: Record<string, unknown>
config?: FindConfig<ShippingOptionDTO>
}
export const listShippingOptionsForContextStepId =
"list-shipping-options-for-context"
/**
* This step retrieves shipping options that can be used in the specified context.
*/
export const listShippingOptionsForContextStep = createStep(
listShippingOptionsForContextStepId,
async (data: StepInput, { container }) => {
async (data: ListShippingOptionsForContextStepInput, { container }) => {
const fulfillmentService = container.resolve<IFulfillmentModuleService>(
ModuleRegistrationName.FULFILLMENT
)

View File

@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const deleteShippingProfilesStepId = "delete-shipping-profile"
/**
* This step deletes one or more shipping profiles.
*/
export const deleteShippingProfilesStep = createStep(
deleteShippingProfilesStepId,
async (ids: string[], { container }) => {

View File

@@ -6,6 +6,9 @@ import { Modules } from "@medusajs/utils"
export const deleteShippingProfileWorkflowId =
"delete-shipping-profile-workflow"
/**
* This workflow deletes one or more shipping profiles.
*/
export const deleteShippingProfileWorkflow = createWorkflow(
deleteShippingProfileWorkflowId,
(input: WorkflowData<{ ids: string[] }>) => {

View File

@@ -1,7 +1,7 @@
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
interface StepInput {
export interface AssociateFulfillmentSetsWithLocationStepInput {
input: {
location_id: string
fulfillment_set_ids: string[]
@@ -10,9 +10,12 @@ interface StepInput {
export const associateFulfillmentSetsWithLocationStepId =
"associate-fulfillment-sets-with-location-step"
/**
* This step creates links between location and fulfillment set records.
*/
export const associateFulfillmentSetsWithLocationStep = createStep(
associateFulfillmentSetsWithLocationStepId,
async (data: StepInput, { container }) => {
async (data: AssociateFulfillmentSetsWithLocationStepInput, { container }) => {
if (!data.input.length) {
return new StepResponse([], [])
}

View File

@@ -7,6 +7,9 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { ModuleRegistrationName } from "@medusajs/utils"
export const createStockLocationsStepId = "create-stock-locations"
/**
* This step creates one or more stock locations.
*/
export const createStockLocations = createStep(
createStockLocationsStepId,
async (data: CreateStockLocationInput[], { container }) => {

View File

@@ -3,6 +3,9 @@ import { ModuleRegistrationName, Modules } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
export const deleteStockLocationsStepId = "delete-stock-locations-step"
/**
* This step deletes one or more stock locations.
*/
export const deleteStockLocationsStep = createStep(
deleteStockLocationsStepId,
async (input: string[], { container }) => {

View File

@@ -14,6 +14,9 @@ interface StepInput {
}
export const updateStockLocationsStepId = "update-stock-locations-step"
/**
* This step updates stock locations matching the specified filters.
*/
export const updateStockLocationsStep = createStep(
updateStockLocationsStepId,
async (input: StepInput, { container }) => {

View File

@@ -9,6 +9,9 @@ import { associateFulfillmentSetsWithLocationStep } from "../steps/associate-loc
export const createLocationFulfillmentSetWorkflowId =
"create-location-fulfillment-set"
/**
* This workflow creates links between location and fulfillment set records.
*/
export const createLocationFulfillmentSetWorkflow = createWorkflow(
createLocationFulfillmentSetWorkflowId,
(input: WorkflowData<CreateLocationFulfillmentSetWorkflowInputDTO>) => {

View File

@@ -7,14 +7,17 @@ import {
import { CreateStockLocationInput } from "@medusajs/types"
import { createStockLocations } from "../steps"
interface WorkflowInput {
export interface CreateStockLocationsWorkflowInput {
locations: CreateStockLocationInput[]
}
export const createStockLocationsWorkflowId = "create-stock-locations-workflow"
/**
* This workflow creates one or more stock locations.
*/
export const createStockLocationsWorkflow = createWorkflow(
createStockLocationsWorkflowId,
(input: WorkflowData<WorkflowInput>) => {
(input: WorkflowData<CreateStockLocationsWorkflowInput>) => {
return new WorkflowResponse(createStockLocations(input.locations))
}
)

View File

@@ -3,14 +3,17 @@ import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { removeRemoteLinkStep } from "../../common/steps/remove-remote-links"
import { deleteStockLocationsStep } from "../steps"
interface WorkflowInput {
export interface DeleteStockLocationWorkflowInput {
ids: string[]
}
export const deleteStockLocationsWorkflowId = "delete-stock-locations-workflow"
/**
* This workflow deletes one or more stock locations.
*/
export const deleteStockLocationsWorkflow = createWorkflow(
deleteStockLocationsWorkflowId,
(input: WorkflowData<WorkflowInput>) => {
(input: WorkflowData<DeleteStockLocationWorkflowInput>) => {
const softDeletedEntities = deleteStockLocationsStep(input.ids)
removeRemoteLinkStep(softDeletedEntities)
}

View File

@@ -8,6 +8,9 @@ import {
export const linkSalesChannelsToStockLocationWorkflowId =
"link-sales-channels-to-stock-location"
/**
* This workflow creates and dismisses links between location and sales channel records.
*/
export const linkSalesChannelsToStockLocationWorkflow = createWorkflow(
linkSalesChannelsToStockLocationWorkflowId,
(input: WorkflowData<LinkWorkflowInput>): void => {

View File

@@ -11,15 +11,18 @@ import {
import { updateStockLocationsStep } from "../steps"
interface WorkflowInput {
export interface UpdateStockLocationsWorkflowInput {
selector: FilterableStockLocationProps
update: UpdateStockLocationInput
}
export const updateStockLocationsWorkflowId = "update-stock-locations-workflow"
/**
* This workflow updates stock locations matching the specified filters.
*/
export const updateStockLocationsWorkflow = createWorkflow(
updateStockLocationsWorkflowId,
(
input: WorkflowData<WorkflowInput>
input: WorkflowData<UpdateStockLocationsWorkflowInput>
): WorkflowResponse<StockLocationDTO[]> => {
return new WorkflowResponse(updateStockLocationsStep(input))
}

View File

@@ -2,12 +2,13 @@ import { CreateStoreDTO, IStoreModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
type CreateStoresStepInput = CreateStoreDTO[]
export const createStoresStepId = "create-stores"
/**
* This step creates one or more stores.
*/
export const createStoresStep = createStep(
createStoresStepId,
async (data: CreateStoresStepInput, { container }) => {
async (data: CreateStoreDTO[], { container }) => {
const service = container.resolve<IStoreModuleService>(
ModuleRegistrationName.STORE
)

View File

@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const deleteStoresStepId = "delete-stores"
/**
* This step deletes one or more stores.
*/
export const deleteStoresStep = createStep(
deleteStoresStepId,
async (ids: string[], { container }) => {

View File

@@ -9,15 +9,18 @@ import {
} from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
type WorkflowInputData = {
export type UpdateStoresStepInput = {
selector: FilterableStoreProps
update: UpdateStoreDTO
}
export const updateStoresStepId = "update-stores"
/**
* This step updates stores matching the specified filters.
*/
export const updateStoresStep = createStep(
updateStoresStepId,
async (data: WorkflowInputData, { container }) => {
async (data: UpdateStoresStepInput, { container }) => {
const service = container.resolve<IStoreModuleService>(
ModuleRegistrationName.STORE
)

View File

@@ -8,12 +8,15 @@ import {
import { createStoresStep } from "../steps"
import { updatePricePreferencesAsArrayStep } from "../../pricing"
type WorkflowInputData = { stores: StoreWorkflow.CreateStoreWorkflowInput[] }
type CreateStoresWorkflowInput = { stores: StoreWorkflow.CreateStoreWorkflowInput[] }
export const createStoresWorkflowId = "create-stores"
/**
* This workflow creates one or more stores.
*/
export const createStoresWorkflow = createWorkflow(
createStoresWorkflowId,
(input: WorkflowData<WorkflowInputData>): WorkflowResponse<StoreDTO[]> => {
(input: WorkflowData<CreateStoresWorkflowInput>): WorkflowResponse<StoreDTO[]> => {
const normalizedInput = transform({ input }, (data) => {
return data.input.stores.map((store) => {
return {

View File

@@ -1,12 +1,15 @@
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { deleteStoresStep } from "../steps"
type WorkflowInput = { ids: string[] }
export type DeleteStoresWorkflowInput = { ids: string[] }
export const deleteStoresWorkflowId = "delete-stores"
/**
* This workflow deletes one or more stores.
*/
export const deleteStoresWorkflow = createWorkflow(
deleteStoresWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowData<void> => {
(input: WorkflowData<DeleteStoresWorkflowInput>): WorkflowData<void> => {
return deleteStoresStep(input.ids)
}
)

View File

@@ -9,12 +9,13 @@ import {
import { updateStoresStep } from "../steps"
import { updatePricePreferencesAsArrayStep } from "../../pricing"
type WorkflowInputData = StoreWorkflow.UpdateStoreWorkflowInput
export const updateStoresWorkflowId = "update-stores"
/**
* This workflow updates stores matching the specified filters.
*/
export const updateStoresWorkflow = createWorkflow(
updateStoresWorkflowId,
(input: WorkflowData<WorkflowInputData>): WorkflowResponse<StoreDTO[]> => {
(input: WorkflowData<StoreWorkflow.UpdateStoreWorkflowInput>): WorkflowResponse<StoreDTO[]> => {
const normalizedInput = transform({ input }, (data) => {
if (!data.input.update.supported_currencies?.length) {
return data.input

View File

@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const createUsersStepId = "create-users-step"
/**
* This step creates one or more users.
*/
export const createUsersStep = createStep(
createUsersStepId,
async (input: CreateUserDTO[], { container }) => {

View File

@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const deleteUsersStepId = "delete-users-step"
/**
* This step deletes one or more stores.
*/
export const deleteUsersStep = createStep(
deleteUsersStepId,
async (input: string[], { container }) => {

View File

@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const updateUsersStepId = "update-users-step"
/**
* This step updates one or more stores.
*/
export const updateUsersStep = createStep(
updateUsersStepId,
async (input: UpdateUserDTO[], { container }) => {

View File

@@ -8,15 +8,18 @@ import {
import { createUsersStep } from "../steps"
import { setAuthAppMetadataStep } from "../../auth"
type WorkflowInput = {
export type CreateUserAccountWorkflowInput = {
authIdentityId: string
userData: CreateUserDTO
}
export const createUserAccountWorkflowId = "create-user-account"
/**
* This workflow creates an authentication identity for a user.
*/
export const createUserAccountWorkflow = createWorkflow(
createUserAccountWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowResponse<UserDTO> => {
(input: WorkflowData<CreateUserAccountWorkflowInput>): WorkflowResponse<UserDTO> => {
const users = createUsersStep([input.userData])
const user = transform(users, (users: UserDTO[]) => users[0])

View File

@@ -8,6 +8,9 @@ import { createUsersStep } from "../steps"
import { UserWorkflow } from "@medusajs/types"
export const createUsersWorkflowId = "create-users-workflow"
/**
* This workflow creates one or more users.
*/
export const createUsersWorkflow = createWorkflow(
createUsersWorkflowId,
(

View File

@@ -3,6 +3,9 @@ import { deleteUsersStep } from "../steps"
import { UserWorkflow } from "@medusajs/types"
export const deleteUsersWorkflowId = "delete-user"
/**
* This workflow deletes one or more users.
*/
export const deleteUsersWorkflow = createWorkflow(
deleteUsersWorkflowId,
(

View File

@@ -8,6 +8,9 @@ import { updateUsersStep } from "../steps"
import { UserWorkflow } from "@medusajs/types"
export const updateUsersWorkflowId = "update-users-workflow"
/**
* This workflow updates one or more users.
*/
export const updateUsersWorkflow = createWorkflow(
updateUsersWorkflowId,
(