chore(core-flows): [11] export types and types, add basic TSDocs (#8521)
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
interface StepInput {
|
||||
export interface CreatePaymentSessionStepInput {
|
||||
payment_collection_id: string
|
||||
provider_id: string
|
||||
amount: BigNumberInput
|
||||
@@ -16,9 +16,12 @@ interface StepInput {
|
||||
}
|
||||
|
||||
export const createPaymentSessionStepId = "create-payment-session"
|
||||
/**
|
||||
* This step creates a payment session.
|
||||
*/
|
||||
export const createPaymentSessionStep = createStep(
|
||||
createPaymentSessionStepId,
|
||||
async (input: StepInput, { container }) => {
|
||||
async (input: CreatePaymentSessionStepInput, { container }) => {
|
||||
const service = container.resolve<IPaymentModuleService>(
|
||||
ModuleRegistrationName.PAYMENT
|
||||
)
|
||||
|
||||
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const createRefundReasonStepId = "create-refund-reason"
|
||||
/**
|
||||
* This step creates one or more refund reasons.
|
||||
*/
|
||||
export const createRefundReasonStep = createStep(
|
||||
createRefundReasonStepId,
|
||||
async (data: CreateRefundReasonDTO[], { container }) => {
|
||||
|
||||
@@ -9,16 +9,20 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
interface StepInput {
|
||||
export interface DeletePaymentSessionStepInput {
|
||||
ids: string[]
|
||||
}
|
||||
|
||||
// Note: This step should not be used alone as it doesn't consider a revert
|
||||
// Use deletePaymentSessionsWorkflow instead that uses this step
|
||||
export const deletePaymentSessionsStepId = "delete-payment-sessions"
|
||||
/**
|
||||
* This step deletes one or more payment sessions.
|
||||
*
|
||||
* Note: This step should not be used alone as it doesn't consider a revert
|
||||
* Use deletePaymentSessionsWorkflow instead that uses this step
|
||||
*/
|
||||
export const deletePaymentSessionsStep = createStep(
|
||||
deletePaymentSessionsStepId,
|
||||
async (input: StepInput, { container }) => {
|
||||
async (input: DeletePaymentSessionStepInput, { container }) => {
|
||||
const { ids = [] } = input
|
||||
const deleted: PaymentSessionDTO[] = []
|
||||
const logger = container.resolve<Logger>(ContainerRegistrationKeys.LOGGER)
|
||||
|
||||
@@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const deleteRefundReasonsStepId = "delete-refund-reasons"
|
||||
/**
|
||||
* This step deletes one or more refund reasons.
|
||||
*/
|
||||
export const deleteRefundReasonsStep = createStep(
|
||||
deleteRefundReasonsStepId,
|
||||
async (ids: string[], { container }) => {
|
||||
|
||||
@@ -10,15 +10,18 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
interface StepInput {
|
||||
export interface UpdatePaymentCollectionStepInput {
|
||||
selector: FilterablePaymentCollectionProps
|
||||
update: PaymentCollectionUpdatableFields
|
||||
}
|
||||
|
||||
export const updatePaymentCollectionStepId = "update-payment-collection"
|
||||
/**
|
||||
* This step updates payment collections matching the specified filters.
|
||||
*/
|
||||
export const updatePaymentCollectionStep = createStep(
|
||||
updatePaymentCollectionStepId,
|
||||
async (data: StepInput, { container }) => {
|
||||
async (data: UpdatePaymentCollectionStepInput, { container }) => {
|
||||
if (!isPresent(data) || !isPresent(data.selector)) {
|
||||
return new StepResponse([], [])
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ import {
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const updateRefundReasonStepId = "update-refund-reasons"
|
||||
/**
|
||||
* This step updates one or more refund reasons.
|
||||
*/
|
||||
export const updateRefundReasonsStep = createStep(
|
||||
updateRefundReasonStepId,
|
||||
async (data: UpdateRefundReasonDTO[], { container }) => {
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
interface StepInput {
|
||||
export interface ValidateDeletedPaymentSessionsStepInput {
|
||||
idsToDelete: string[]
|
||||
idsDeleted: string[]
|
||||
}
|
||||
|
||||
export const validateDeletedPaymentSessionsStepId =
|
||||
"validate-deleted-payment-sessions"
|
||||
/**
|
||||
* This step validates that the specified payment session IDs were deleted.
|
||||
*/
|
||||
export const validateDeletedPaymentSessionsStep = createStep(
|
||||
validateDeletedPaymentSessionsStepId,
|
||||
async (input: StepInput) => {
|
||||
async (input: ValidateDeletedPaymentSessionsStepInput) => {
|
||||
const { idsToDelete = [], idsDeleted = [] } = input
|
||||
|
||||
if (idsToDelete.length !== idsDeleted.length) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import { useRemoteQueryStep } from "../../common"
|
||||
import { createPaymentSessionStep } from "../steps"
|
||||
import { deletePaymentSessionsWorkflow } from "./delete-payment-sessions"
|
||||
|
||||
interface WorkflowInput {
|
||||
export interface CreatePaymentSessionsWorkflowInput {
|
||||
payment_collection_id: string
|
||||
provider_id: string
|
||||
data?: Record<string, unknown>
|
||||
@@ -18,9 +18,12 @@ interface WorkflowInput {
|
||||
}
|
||||
|
||||
export const createPaymentSessionsWorkflowId = "create-payment-sessions"
|
||||
/**
|
||||
* This workflow creates payment sessions.
|
||||
*/
|
||||
export const createPaymentSessionsWorkflow = createWorkflow(
|
||||
createPaymentSessionsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>): WorkflowResponse<PaymentSessionDTO> => {
|
||||
(input: WorkflowData<CreatePaymentSessionsWorkflowInput>): WorkflowResponse<PaymentSessionDTO> => {
|
||||
const paymentCollection = useRemoteQueryStep({
|
||||
entry_point: "payment_collection",
|
||||
fields: ["id", "amount", "currency_code", "payment_sessions.*"],
|
||||
|
||||
@@ -7,6 +7,9 @@ import {
|
||||
import { createRefundReasonStep } from "../steps/create-refund-reasons"
|
||||
|
||||
export const createRefundReasonsWorkflowId = "create-refund-reasons-workflow"
|
||||
/**
|
||||
* This workflow creates one or more refund reasons.
|
||||
*/
|
||||
export const createRefundReasonsWorkflow = createWorkflow(
|
||||
createRefundReasonsWorkflowId,
|
||||
(
|
||||
|
||||
@@ -8,14 +8,17 @@ import {
|
||||
validateDeletedPaymentSessionsStep,
|
||||
} from "../steps"
|
||||
|
||||
interface WorkflowInput {
|
||||
export interface DeletePaymentSessionsWorkflowInput {
|
||||
ids: string[]
|
||||
}
|
||||
|
||||
export const deletePaymentSessionsWorkflowId = "delete-payment-sessions"
|
||||
/**
|
||||
* This workflow deletes one or more payment sessions.
|
||||
*/
|
||||
export const deletePaymentSessionsWorkflow = createWorkflow(
|
||||
deletePaymentSessionsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<DeletePaymentSessionsWorkflowInput>) => {
|
||||
const idsDeleted = deletePaymentSessionsStep({ ids: input.ids })
|
||||
|
||||
validateDeletedPaymentSessionsStep({
|
||||
|
||||
@@ -6,6 +6,9 @@ import {
|
||||
import { deleteRefundReasonsStep } from "../steps"
|
||||
|
||||
export const deleteRefundReasonsWorkflowId = "delete-refund-reasons-workflow"
|
||||
/**
|
||||
* This workflow deletes one or more refund reasons.
|
||||
*/
|
||||
export const deleteRefundReasonsWorkflow = createWorkflow(
|
||||
deleteRefundReasonsWorkflowId,
|
||||
(input: WorkflowData<{ ids: string[] }>): WorkflowResponse<void> => {
|
||||
|
||||
@@ -7,6 +7,9 @@ import {
|
||||
import { updateRefundReasonsStep } from "../steps"
|
||||
|
||||
export const updateRefundReasonsWorkflowId = "update-refund-reasons"
|
||||
/**
|
||||
* This workflow updates one or more refund reasons.
|
||||
*/
|
||||
export const updateRefundReasonsWorkflow = createWorkflow(
|
||||
updateRefundReasonsWorkflowId,
|
||||
(
|
||||
|
||||
@@ -7,15 +7,18 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
type StepInput = {
|
||||
export type AuthorizePaymentSessionStepInput = {
|
||||
id: string
|
||||
context: Record<string, unknown>
|
||||
}
|
||||
|
||||
export const authorizePaymentSessionStepId = "authorize-payment-session-step"
|
||||
/**
|
||||
* This step authorizes a payment session.
|
||||
*/
|
||||
export const authorizePaymentSessionStep = createStep(
|
||||
authorizePaymentSessionStepId,
|
||||
async (input: StepInput, { container }) => {
|
||||
async (input: AuthorizePaymentSessionStepInput, { container }) => {
|
||||
let payment: PaymentDTO | undefined
|
||||
const logger = container.resolve<Logger>(ContainerRegistrationKeys.LOGGER)
|
||||
const paymentModule = container.resolve<IPaymentModuleService>(
|
||||
|
||||
@@ -6,14 +6,17 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
type StepInput = {
|
||||
export type CancelPaymentStepInput = {
|
||||
paymentIds: string | string[]
|
||||
}
|
||||
|
||||
export const cancelPaymentStepId = "cancel-payment-step"
|
||||
/**
|
||||
* This step cancels one or more payments.
|
||||
*/
|
||||
export const cancelPaymentStep = createStep(
|
||||
cancelPaymentStepId,
|
||||
async (input: StepInput, { container }) => {
|
||||
async (input: CancelPaymentStepInput, { container }) => {
|
||||
const logger = container.resolve<Logger>(ContainerRegistrationKeys.LOGGER)
|
||||
const paymentModule = container.resolve<IPaymentModuleService>(
|
||||
ModuleRegistrationName.PAYMENT
|
||||
|
||||
@@ -2,16 +2,19 @@ import { BigNumberInput, IPaymentModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
type StepInput = {
|
||||
export type CapturePaymentStepInput = {
|
||||
payment_id: string
|
||||
captured_by?: string
|
||||
amount?: BigNumberInput
|
||||
}
|
||||
|
||||
export const capturePaymentStepId = "capture-payment-step"
|
||||
/**
|
||||
* This step captures a payment.
|
||||
*/
|
||||
export const capturePaymentStep = createStep(
|
||||
capturePaymentStepId,
|
||||
async (input: StepInput, { container }) => {
|
||||
async (input: CapturePaymentStepInput, { container }) => {
|
||||
const paymentModule = container.resolve<IPaymentModuleService>(
|
||||
ModuleRegistrationName.PAYMENT
|
||||
)
|
||||
|
||||
@@ -2,16 +2,19 @@ import { BigNumberInput, IPaymentModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
type StepInput = {
|
||||
export type RefundPaymentStepInput = {
|
||||
payment_id: string
|
||||
created_by?: string
|
||||
amount?: BigNumberInput
|
||||
}
|
||||
|
||||
export const refundPaymentStepId = "refund-payment-step"
|
||||
/**
|
||||
* This step refunds a payment.
|
||||
*/
|
||||
export const refundPaymentStep = createStep(
|
||||
refundPaymentStepId,
|
||||
async (input: StepInput, { container }) => {
|
||||
async (input: RefundPaymentStepInput, { container }) => {
|
||||
const paymentModule = container.resolve<IPaymentModuleService>(
|
||||
ModuleRegistrationName.PAYMENT
|
||||
)
|
||||
|
||||
@@ -9,6 +9,9 @@ import { emitEventStep } from "../../common"
|
||||
import { capturePaymentStep } from "../steps/capture-payment"
|
||||
|
||||
export const capturePaymentWorkflowId = "capture-payment-workflow"
|
||||
/**
|
||||
* This workflow captures a payment.
|
||||
*/
|
||||
export const capturePaymentWorkflow = createWorkflow(
|
||||
capturePaymentWorkflowId,
|
||||
(
|
||||
|
||||
@@ -9,6 +9,9 @@ import { emitEventStep } from "../../common"
|
||||
import { refundPaymentStep } from "../steps/refund-payment"
|
||||
|
||||
export const refundPaymentWorkflowId = "refund-payment-workflow"
|
||||
/**
|
||||
* This workflow refunds a payment.
|
||||
*/
|
||||
export const refundPaymentWorkflow = createWorkflow(
|
||||
refundPaymentWorkflowId,
|
||||
(
|
||||
|
||||
@@ -14,6 +14,9 @@ import { removePriceListPricesWorkflowStep } from "../steps/remove-price-list-pr
|
||||
import { updatePriceListPricesWorkflowStep } from "../steps/update-price-list-prices-workflow"
|
||||
|
||||
export const batchPriceListPricesWorkflowId = "batch-price-list-prices"
|
||||
/**
|
||||
* This workflow manages price lists' prices by creating, updating, or removing them.
|
||||
*/
|
||||
export const batchPriceListPricesWorkflow = createWorkflow(
|
||||
batchPriceListPricesWorkflowId,
|
||||
(
|
||||
|
||||
@@ -10,6 +10,9 @@ import { validatePriceListsStep } from "../steps/validate-price-lists"
|
||||
import { validateVariantPriceLinksStep } from "../steps/validate-variant-price-links"
|
||||
|
||||
export const createPriceListPricesWorkflowId = "create-price-list-prices"
|
||||
/**
|
||||
* This workflow creates prices in price lists.
|
||||
*/
|
||||
export const createPriceListPricesWorkflow = createWorkflow(
|
||||
createPriceListPricesWorkflowId,
|
||||
(
|
||||
|
||||
@@ -6,12 +6,15 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { createPriceListsStep, validateVariantPriceLinksStep } from "../steps"
|
||||
|
||||
type WorkflowInput = { price_lists_data: CreatePriceListWorkflowInputDTO[] }
|
||||
export type CreatePriceListsWorkflowInput = { price_lists_data: CreatePriceListWorkflowInputDTO[] }
|
||||
|
||||
export const createPriceListsWorkflowId = "create-price-lists"
|
||||
/**
|
||||
* This workflow creates one or more price lists.
|
||||
*/
|
||||
export const createPriceListsWorkflow = createWorkflow(
|
||||
createPriceListsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>): WorkflowResponse<PriceListDTO[]> => {
|
||||
(input: WorkflowData<CreatePriceListsWorkflowInput>): WorkflowResponse<PriceListDTO[]> => {
|
||||
const variantPriceMap = validateVariantPriceLinksStep(
|
||||
input.price_lists_data
|
||||
)
|
||||
|
||||
@@ -2,6 +2,9 @@ import { createWorkflow, WorkflowData } from "@medusajs/workflows-sdk"
|
||||
import { deletePriceListsStep } from "../steps"
|
||||
|
||||
export const deletePriceListsWorkflowId = "delete-price-lists"
|
||||
/**
|
||||
* This workflow deletes one or more price lists.
|
||||
*/
|
||||
export const deletePriceListsWorkflow = createWorkflow(
|
||||
deletePriceListsWorkflowId,
|
||||
(input: WorkflowData<{ ids: string[] }>): WorkflowData<void> => {
|
||||
|
||||
@@ -6,6 +6,9 @@ import {
|
||||
import { removePriceListPricesStep } from "../steps/remove-price-list-prices"
|
||||
|
||||
export const removePriceListPricesWorkflowId = "remove-price-list-prices"
|
||||
/**
|
||||
* This workflow removes price lists' prices.
|
||||
*/
|
||||
export const removePriceListPricesWorkflow = createWorkflow(
|
||||
removePriceListPricesWorkflowId,
|
||||
(input: WorkflowData<{ ids: string[] }>): WorkflowResponse<string[]> => {
|
||||
|
||||
@@ -10,6 +10,9 @@ import { validatePriceListsStep } from "../steps/validate-price-lists"
|
||||
import { validateVariantPriceLinksStep } from "../steps/validate-variant-price-links"
|
||||
|
||||
export const updatePriceListPricesWorkflowId = "update-price-list-prices"
|
||||
/**
|
||||
* This workflow update price lists' prices.
|
||||
*/
|
||||
export const updatePriceListPricesWorkflow = createWorkflow(
|
||||
updatePriceListPricesWorkflowId,
|
||||
(
|
||||
|
||||
@@ -3,6 +3,9 @@ import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { updatePriceListsStep, validatePriceListsStep } from "../steps"
|
||||
|
||||
export const updatePriceListsWorkflowId = "update-price-lists"
|
||||
/**
|
||||
* This workflow updates one or more price lists.
|
||||
*/
|
||||
export const updatePriceListsWorkflow = createWorkflow(
|
||||
updatePriceListsWorkflowId,
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user