Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/core-flows/src/region/steps/create-regions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

export const createRegionsStepId = "create-regions"
/**
* This step creates one or more regions.
*/
export const createRegionsStep = createStep(
createRegionsStepId,
async (data: CreateRegionDTO[], { container }) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/core-flows/src/region/steps/delete-regions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

export const deleteRegionsStepId = "delete-regions"
/**
* This step deletes one or more regions.
*/
export const deleteRegionsStep = createStep(
deleteRegionsStepId,
async (ids: string[], { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ async function getCurrentRegionPaymentProvidersLinks(

export const setRegionsPaymentProvidersStepId =
"add-region-payment-providers-step"
/**
* This step sets the payment providers in regions.
*/
export const setRegionsPaymentProvidersStep = createStep(
setRegionsPaymentProvidersStepId,
async (data: SetRegionsPaymentProvidersStepInput, { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import {
} from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

type UpdateRegionsStepInput = {
export type UpdateRegionsStepInput = {
selector: FilterableRegionProps
update: UpdateRegionDTO
}

export const updateRegionsStepId = "update-region"
/**
* This step updates regions matching the specified filters.
*/
export const updateRegionsStep = createStep(
updateRegionsStepId,
async (data: UpdateRegionsStepInput, { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { setRegionsPaymentProvidersStep } from "../steps/set-regions-payment-pro
import { createPricePreferencesWorkflow } from "../../pricing"

export const createRegionsWorkflowId = "create-regions"
/**
* This workflow creates one or more regions.
*/
export const createRegionsWorkflow = createWorkflow(
createRegionsWorkflowId,
(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { deleteRegionsStep } from "../steps"

type WorkflowInput = { ids: string[] }
export type DeleteRegionsWorkflowInput = { ids: string[] }

export const deleteRegionsWorkflowId = "delete-regions"
/**
* This workflow deletes one or more regions.
*/
export const deleteRegionsWorkflow = createWorkflow(
deleteRegionsWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowData<void> => {
(input: WorkflowData<DeleteRegionsWorkflowInput>): WorkflowData<void> => {
return deleteRegionsStep(input.ids)
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { setRegionsPaymentProvidersStep } from "../steps/set-regions-payment-pro
import { updatePricePreferencesWorkflow } from "../../pricing"

export const updateRegionsWorkflowId = "update-regions"
/**
* This workflow updates regions matching the specified filters.
*/
export const updateRegionsWorkflow = createWorkflow(
updateRegionsWorkflowId,
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { ModuleRegistrationName } from "@medusajs/utils"

export const createReservationsStepId = "create-reservations-step"
/**
* This step creates one or more reservations.
*/
export const createReservationsStep = createStep(
createReservationsStepId,
async (data: InventoryTypes.CreateReservationItemInput[], { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"

export const deleteReservationsByLineItemsStepId =
"delete-reservations-by-line-items"
/**
* This step deletes reservations by their associated line items.
*/
export const deleteReservationsByLineItemsStep = createStep(
deleteReservationsByLineItemsStepId,
async (ids: string[], { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { IInventoryService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"

export const deleteReservationsStepId = "delete-reservations"
/**
* This step deletes one or more reservations.
*/
export const deleteReservationsStep = createStep(
deleteReservationsStepId,
async (ids: string[], { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { ModuleRegistrationName } from "@medusajs/utils"

export const updateReservationsStepId = "update-reservations-step"
/**
* This step updates one or more reservations.
*/
export const updateReservationsStep = createStep(
updateReservationsStepId,
async (data: InventoryTypes.UpdateReservationItemInput[], { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { WorkflowTypes } from "@medusajs/types"
import { createReservationsStep } from "../steps"

export const createReservationsWorkflowId = "create-reservations-workflow"
/**
* This workflow creates one or more reservations.
*/
export const createReservationsWorkflow = createWorkflow(
createReservationsWorkflowId,
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"

import { deleteReservationsByLineItemsStep } from "../steps"

type WorkflowInput = { ids: string[] }
export type DeleteReservationByLineItemsWorkflowInput = { ids: string[] }

export const deleteReservationsByLineItemsWorkflowId =
"delete-reservations-by-line-items"
/**
* This workflow deletes reservations by their associated line items.
*/
export const deleteReservationsByLineItemsWorkflow = createWorkflow(
deleteReservationsByLineItemsWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowData<void> => {
(input: WorkflowData<DeleteReservationByLineItemsWorkflowInput>): WorkflowData<void> => {
return deleteReservationsByLineItemsStep(input.ids)
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { deleteReservationsStep } from "../steps"
type WorkflowInput = { ids: string[] }

export const deleteReservationsWorkflowId = "delete-reservations"
/**
* This workflow deletes one or more reservations.
*/
export const deleteReservationsWorkflow = createWorkflow(
deleteReservationsWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowData<void> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { WorkflowTypes } from "@medusajs/types"
import { updateReservationsStep } from "../steps"

export const updateReservationsWorkflowId = "update-reservations-workflow"
/**
* This workflow updates one or more reservations.
*/
export const updateReservationsWorkflow = createWorkflow(
updateReservationsWorkflowId,
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

export const createReturnReasonsStepId = "create-return-reasons"
/**
* This step creates one or more return reasons.
*/
export const createReturnReasonsStep = createStep(
createReturnReasonsStepId,
async (data: CreateOrderReturnReasonDTO[], { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { IOrderModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"

type DeleteReturnReasonStepInput = string[]

export const deleteReturnReasonStepId = "delete-return-reasons"
/**
* This step deletes one or more return reasons.
*/
export const deleteReturnReasonStep = createStep(
deleteReturnReasonStepId,
async (ids: DeleteReturnReasonStepInput, { container }) => {
async (ids: string[], { container }) => {
const service = container.resolve<IOrderModuleService>(
ModuleRegistrationName.ORDER
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ type UpdateReturnReasonStepInput = {
}

export const updateReturnReasonStepId = "update-return-reasons"
/**
* This step updates return reasons matching the specified filters.
*/
export const updateReturnReasonsStep = createStep(
updateReturnReasonStepId,
async (data: UpdateReturnReasonStepInput, { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import {
} from "@medusajs/workflows-sdk"
import { createReturnReasonsStep } from "../steps"

type WorkflowInput = { data: CreateOrderReturnReasonDTO[] }
export type CreateReturnReasonsWorkflowInput = { data: CreateOrderReturnReasonDTO[] }

export const createReturnReasonsWorkflowId = "create-return-reasons"
/**
* This workflow creates one or more return reasons.
*/
export const createReturnReasonsWorkflow = createWorkflow(
createReturnReasonsWorkflowId,
(
input: WorkflowData<WorkflowInput>
input: WorkflowData<CreateReturnReasonsWorkflowInput>
): WorkflowResponse<OrderReturnReasonDTO[]> => {
return new WorkflowResponse(createReturnReasonsStep(input.data))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { deleteReturnReasonStep } from "../steps"

type WorkflowInput = { ids: string[] }
export type DeleteReturnReasonsWorkflowInput = { ids: string[] }

export const deleteReturnReasonsWorkflowId = "delete-return-reasons"
/**
* This workflow deletes one or more return reasons.
*/
export const deleteReturnReasonsWorkflow = createWorkflow(
deleteReturnReasonsWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowData<void> => {
(input: WorkflowData<DeleteReturnReasonsWorkflowInput>): WorkflowData<void> => {
return deleteReturnReasonStep(input.ids)
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ import {
} from "@medusajs/workflows-sdk"
import { updateReturnReasonsStep } from "../steps"

type WorkflowInput = {
export type UpdateReturnReasonsWorkflowInput = {
selector: FilterableOrderReturnReasonProps
update: ReturnReasonUpdatableFields
}

export const updateReturnReasonsWorkflowId = "update-return-reasons"
/**
* This workflow updates return reasons matching the specified filters.
*/
export const updateReturnReasonsWorkflow = createWorkflow(
updateReturnReasonsWorkflowId,
(
input: WorkflowData<WorkflowInput>
input: WorkflowData<UpdateReturnReasonsWorkflowInput>
): WorkflowResponse<OrderReturnReasonDTO[]> => {
return new WorkflowResponse(updateReturnReasonsStep(input))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createStep, StepResponse } from "@medusajs/workflows-sdk"

import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"

interface StepInput {
export interface AssociateLocationsWithSalesChannelsStepInput {
links: {
sales_channel_id: string
location_id: string
Expand All @@ -11,9 +11,12 @@ interface StepInput {

export const associateLocationsWithSalesChannelsStepId =
"associate-locations-with-sales-channels-step"
/**
* This step creates links between locations and sales channel records.
*/
export const associateLocationsWithSalesChannelsStep = createStep(
associateLocationsWithSalesChannelsStepId,
async (data: StepInput, { container }) => {
async (data: AssociateLocationsWithSalesChannelsStepInput, { container }) => {
if (!data.links?.length) {
return new StepResponse([], [])
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"

interface StepInput {
export interface AssociateProductsWithSalesChannelsStepInput {
links: {
sales_channel_id: string
product_id: string
Expand All @@ -10,9 +10,12 @@ interface StepInput {

export const associateProductsWithSalesChannelsStepId =
"associate-products-with-channels"
/**
* This step creates links between products and sales channel records.
*/
export const associateProductsWithSalesChannelsStep = createStep(
associateProductsWithSalesChannelsStepId,
async (input: StepInput, { container }) => {
async (input: AssociateProductsWithSalesChannelsStepInput, { container }) => {
if (!input.links?.length) {
return new StepResponse([], [])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import {
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface CreateDefaultSalesChannelStepInput {
data: CreateSalesChannelDTO
}

export const createDefaultSalesChannelStepId = "create-default-sales-channel"
/**
* This step creates a default sales channel.
*/
export const createDefaultSalesChannelStep = createStep(
createDefaultSalesChannelStepId,
async (input: StepInput, { container }) => {
async (input: CreateDefaultSalesChannelStepInput, { container }) => {
const salesChannelService = container.resolve<ISalesChannelModuleService>(
ModuleRegistrationName.SALES_CHANNEL
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import {
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

interface StepInput {
export interface CreateSalesChannelsStepInput {
data: CreateSalesChannelDTO[]
}

export const createSalesChannelsStepId = "create-sales-channels"
/**
* This step creates one or more sales channels.
*/
export const createSalesChannelsStep = createStep(
createSalesChannelsStepId,
async (input: StepInput, { container }) => {
async (input: CreateSalesChannelsStepInput, { container }) => {
const salesChannelService = container.resolve<ISalesChannelModuleService>(
ModuleRegistrationName.SALES_CHANNEL
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { ISalesChannelModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

type DeleteSalesChannelsInput = string[]

export const deleteSalesChannelsStepId = "delete-sales-channels"
/**
* This step deletes one or more sales channels.
*/
export const deleteSalesChannelsStep = createStep(
deleteSalesChannelsStepId,
async (ids: DeleteSalesChannelsInput, { container }) => {
async (ids: string[], { container }) => {
const service = container.resolve<ISalesChannelModuleService>(
ModuleRegistrationName.SALES_CHANNEL
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createStep, StepResponse } from "@medusajs/workflows-sdk"

import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"

interface StepInput {
export interface DetachLocationsFromSalesChannelsStepInput {
links: {
sales_channel_id: string
location_id: string
Expand All @@ -12,9 +12,12 @@ interface StepInput {

export const detachLocationsFromSalesChannelsStepId =
"detach-locations-from-sales-channels"
/**
* This step dismisses links between location and sales channel records.
*/
export const detachLocationsFromSalesChannelsStep = createStep(
detachLocationsFromSalesChannelsStepId,
async (data: StepInput, { container }) => {
async (data: DetachLocationsFromSalesChannelsStepInput, { container }) => {
if (!data.links?.length) {
return new StepResponse([], [])
}
Expand Down
Loading
Loading