Skip to content

Commit

Permalink
chore(core-flows): [6] export types and types, add basic TSDocs (#8512)
Browse files Browse the repository at this point in the history
This PR exports types and steps from the core-flows package, and adds simple TSDocs for workflows / steps. This is essential for the workflows reference.

PR 6/n
  • Loading branch information
shahednasser authored Aug 8, 2024
1 parent 4af82aa commit 0bfe31e
Show file tree
Hide file tree
Showing 22 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { MathBN, ModuleRegistrationName } from "@medusajs/utils"

export const adjustInventoryLevelsStepId = "adjust-inventory-levels-step"
/**
* This step adjusts one or more inventory levels.
*/
export const adjustInventoryLevelsStep = createStep(
adjustInventoryLevelsStepId,
async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { InventoryItemDTO } from "@medusajs/types"

export const attachInventoryItemToVariantsStepId =
"attach-inventory-items-to-variants-step"
/**
* This step creates one or more links between variant and inventory item records.
*/
export const attachInventoryItemToVariants = createStep(
attachInventoryItemToVariantsStepId,
async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { IInventoryService, InventoryTypes } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"

export const createInventoryItemsStepId = "create-inventory-items"
/**
* This step creates one or more inventory items.
*/
export const createInventoryItemsStep = createStep(
createInventoryItemsStepId,
async (data: InventoryTypes.CreateInventoryItemInput[], { container }) => {
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 createInventoryLevelsStepId = "create-inventory-levels"
/**
* This step creates one or more inventory levels.
*/
export const createInventoryLevelsStep = createStep(
createInventoryLevelsStepId,
async (data: InventoryTypes.CreateInventoryLevelInput[], { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { ModuleRegistrationName } from "@medusajs/utils"

export const deleteInventoryItemStepId = "delete-inventory-item-step"
/**
* This step deletes one or more inventory items.
*/
export const deleteInventoryItemStep = createStep(
deleteInventoryItemStepId,
async (ids: string[], { container }) => {
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 deleteInventoryLevelsStepId = "delete-inventory-levels-step"
/**
* This step deletes one or more inventory levels.
*/
export const deleteInventoryLevelsStep = createStep(
deleteInventoryLevelsStepId,
async (ids: string[], { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { MedusaError } from "@medusajs/utils"

export const deleteInventoryLevelsFromItemAndLocationsStepId =
"delete-inventory-levels-from-item-and-location-step"
/**
* This step removes one or more inventory levels by their associated inventory item and location.
*/
export const deleteInventoryLevelsFromItemAndLocationsStep = createStep(
deleteInventoryLevelsFromItemAndLocationsStepId,
async (
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 updateInventoryItemsStepId = "update-inventory-items-step"
/**
* This step updates one or more inventory items.
*/
export const updateInventoryItemsStep = createStep(
updateInventoryItemsStepId,
async (input: InventoryTypes.UpdateInventoryItemInput[], { 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 updateInventoryLevelsStepId = "update-inventory-levels-step"
/**
* This step updates one or more inventory levels.
*/
export const updateInventoryLevelsStep = createStep(
updateInventoryLevelsStepId,
async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
import { createStep } from "@medusajs/workflows-sdk"

export const validateInventoryItemsId = "validate-inventory-items-step"
/**
* This step ensures that the inventory items with the specified IDs exist.
*/
export const validateInventoryItems = createStep(
validateInventoryItemsId,
async (id: string[], { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { InventoryTypes } from "@medusajs/types"
import { createStep } from "@medusajs/workflows-sdk"

export const validateInventoryLocationsStepId = "validate-inventory-levels-step"
/**
* This step ensures that the inventory levels exist for each specified pair of inventory item and location.
*/
export const validateInventoryLocationsStep = createStep(
validateInventoryLocationsStepId,
async (data: InventoryTypes.CreateInventoryLevelInput[], { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { createStep, StepResponse } from "@medusajs/workflows-sdk"

export const validateInventoryItemsForCreateStepId =
"validate-inventory-items-for-create-step"
/**
* This step checks whether a variant already has an inventory item.
*/
export const validateInventoryItemsForCreate = createStep(
validateInventoryItemsForCreateStepId,
async (
Expand Down
3 changes: 3 additions & 0 deletions packages/core/core-flows/src/invite/steps/create-invites.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 createInviteStepId = "create-invite-step"
/**
* This step creates one or more invites.
*/
export const createInviteStep = createStep(
createInviteStepId,
async (input: CreateInviteDTO[], { container }) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/core-flows/src/invite/steps/delete-invites.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 deleteInvitesStepId = "delete-invites-step"
/**
* This step deletes one or more invites.
*/
export const deleteInvitesStep = createStep(
deleteInvitesStepId,
async (input: string[], { container }) => {
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 refreshInviteTokensStepId = "refresh-invite-tokens-step"
/**
* This step refreshes the tokens of one or more invites.
*/
export const refreshInviteTokensStep = createStep(
refreshInviteTokensStepId,
async (input: string[], { container }) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/core-flows/src/invite/steps/validate-token.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 validateTokenStepId = "validate-invite-token-step"
/**
* This step validates a specified token and returns its associated invite.
*/
export const validateTokenStep = createStep(
validateTokenStepId,
async (input: string, { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { validateTokenStep } from "../steps/validate-token"
import { setAuthAppMetadataStep } from "../../auth"

export const acceptInviteWorkflowId = "accept-invite-workflow"
/**
* This workflow accepts an invite and creates a user.
*/
export const acceptInviteWorkflow = createWorkflow(
acceptInviteWorkflowId,
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { createInviteStep } from "../steps"
import { InviteDTO, InviteWorkflow } from "@medusajs/types"

export const createInvitesWorkflowId = "create-invite-step"
/**
* This workflow creates one or more invites.
*/
export const createInvitesWorkflow = createWorkflow(
createInvitesWorkflowId,
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { deleteInvitesStep } from "../steps"
import { InviteWorkflow, UserWorkflow } from "@medusajs/types"

export const deleteInvitesWorkflowId = "delete-invites-workflow"
/**
* This workflow deletes one or more invites.
*/
export const deleteInvitesWorkflow = createWorkflow(
deleteInvitesWorkflowId,
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
import { refreshInviteTokensStep } from "../steps/refresh-invite-tokens"

export const refreshInviteTokensWorkflowId = "refresh-invite-tokens-workflow"
/**
* This workflow refreshes the token of one or more invites.
*/
export const refreshInviteTokensWorkflow = createWorkflow(
refreshInviteTokensWorkflowId,
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { INotificationModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

type NotifyOnFailureStepInput = {
export type NotifyOnFailureStepInput = {
to: string
channel: string
template: string
Expand All @@ -16,6 +16,11 @@ type NotifyOnFailureStepInput = {
}[]

export const notifyOnFailureStepId = "notify-on-failure"
/**
* This step sends one or more notification when a workflow fails. This
* step can be used in a workflow for its compensation function. When the workflow fails,
* its compensation function is triggered to send the notification.
*/
export const notifyOnFailureStep = createStep(
notifyOnFailureStepId,
async (data: NotifyOnFailureStepInput) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { INotificationModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"

type SendNotificationsStepInput = {
export type SendNotificationsStepInput = {
to: string
channel: string
template: string
Expand All @@ -16,6 +16,9 @@ type SendNotificationsStepInput = {
}[]

export const sendNotificationsStepId = "send-notifications"
/**
* This step sends one or more notifications.
*/
export const sendNotificationsStep = createStep(
sendNotificationsStepId,
async (data: SendNotificationsStepInput, { container }) => {
Expand Down

0 comments on commit 0bfe31e

Please sign in to comment.