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): [18/18] export types and types, add basic TSDocs #8529

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
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 createTaxRateRulesStepId = "create-tax-rate-rules"
/**
* This step creates one or more tax rate rules.
*/
export const createTaxRateRulesStep = createStep(
createTaxRateRulesStepId,
async (data: CreateTaxRateRuleDTO[], { container }) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/core-flows/src/tax/steps/create-tax-rates.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 createTaxRatesStepId = "create-tax-rates"
/**
* This step creates one or more tax rates.
*/
export const createTaxRatesStep = createStep(
createTaxRatesStepId,
async (data: CreateTaxRateDTO[], { container }) => {
Expand Down
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 createTaxRegionsStepId = "create-tax-regions"
/**
* This step creates one or more tax regions.
*/
export const createTaxRegionsStep = createStep(
createTaxRegionsStepId,
async (data: CreateTaxRegionDTO[], { container }) => {
Expand Down
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 deleteTaxRateRulesStepId = "delete-tax-rate-rules"
/**
* This step deletes one or more tax rate rules.
*/
export const deleteTaxRateRulesStep = createStep(
deleteTaxRateRulesStepId,
async (ids: string[], { container }) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/core-flows/src/tax/steps/delete-tax-rates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { ModuleRegistrationName } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"

export const deleteTaxRatesStepId = "delete-tax-rates"
/**
* This step deletes one or more tax rates.
*/
export const deleteTaxRatesStep = createStep(
deleteTaxRatesStepId,
async (ids: string[], { container }) => {
Expand Down
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 deleteTaxRegionsStepId = "delete-tax-regions"
/**
* This step deletes one or more tax regions.
*/
export const deleteTaxRegionsStep = createStep(
deleteTaxRegionsStepId,
async (ids: string[], { container }) => {
Expand Down
7 changes: 5 additions & 2 deletions packages/core/core-flows/src/tax/steps/list-tax-rate-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { FilterableTaxRateProps, ITaxModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"

type StepInput = {
export type ListTaxRateIdsStepInput = {
selector: FilterableTaxRateProps
}

export const listTaxRateIdsStepId = "list-tax-rate-ids"
/**
* This step retrieves the IDs of tax rates matching the specified filters.
*/
export const listTaxRateIdsStep = createStep(
listTaxRateIdsStepId,
async (input: StepInput, { container }) => {
async (input: ListTaxRateIdsStepInput, { container }) => {
const service = container.resolve<ITaxModuleService>(
ModuleRegistrationName.TAX
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { FilterableTaxRateRuleProps, ITaxModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"

type StepInput = {
export type ListTaxRateRuleIdsStepInput = {
selector: FilterableTaxRateRuleProps
}

export const listTaxRateRuleIdsStepId = "list-tax-rate-rule-ids"
/**
* This step retrieves the IDs of tax rate rules matching the specified filters.
*/
export const listTaxRateRuleIdsStep = createStep(
listTaxRateRuleIdsStepId,
async (input: StepInput, { container }) => {
async (input: ListTaxRateRuleIdsStepInput, { container }) => {
const service = container.resolve<ITaxModuleService>(
ModuleRegistrationName.TAX
)
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 UpdateTaxRatesStepInput = {
export type UpdateTaxRatesStepInput = {
selector: FilterableTaxRateProps
update: UpdateTaxRateDTO
}

export const updateTaxRatesStepId = "update-tax-rates"
/**
* This step updates tax rates matching the specified filters.
*/
export const updateTaxRatesStep = createStep(
updateTaxRatesStepId,
async (data: UpdateTaxRatesStepInput, { container }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import {
} from "@medusajs/workflows-sdk"
import { createTaxRateRulesStep } from "../steps"

type WorkflowInput = {
export type CreateTaxRateRulesWorkflowInput = {
rules: CreateTaxRateRuleDTO[]
}

export const createTaxRateRulesWorkflowId = "create-tax-rate-rules"
/**
* This workflow creates one or more tax rate rules.
*/
export const createTaxRateRulesWorkflow = createWorkflow(
createTaxRateRulesWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowResponse<TaxRateRuleDTO[]> => {
(input: WorkflowData<CreateTaxRateRulesWorkflowInput>): WorkflowResponse<TaxRateRuleDTO[]> => {
return new WorkflowResponse(createTaxRateRulesStep(input.rules))
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import {
} from "@medusajs/workflows-sdk"
import { createTaxRatesStep } from "../steps"

type WorkflowInput = CreateTaxRateDTO[]

export const createTaxRatesWorkflowId = "create-tax-rates"
/**
* This workflow creates one or more tax rates.
*/
export const createTaxRatesWorkflow = createWorkflow(
createTaxRatesWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowResponse<TaxRateDTO[]> => {
(input: WorkflowData<CreateTaxRateDTO[]>): WorkflowResponse<TaxRateDTO[]> => {
return new WorkflowResponse(createTaxRatesStep(input))
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import {
} from "@medusajs/workflows-sdk"
import { createTaxRegionsStep } from "../steps"

type WorkflowInput = CreateTaxRegionDTO[]

export const createTaxRegionsWorkflowId = "create-tax-regions"
/**
* This workflow creates one or more tax regions.
*/
export const createTaxRegionsWorkflow = createWorkflow(
createTaxRegionsWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowResponse<TaxRegionDTO[]> => {
(input: WorkflowData<CreateTaxRegionDTO[]>): WorkflowResponse<TaxRegionDTO[]> => {
return new WorkflowResponse(createTaxRegionsStep(input))
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import {
} from "@medusajs/workflows-sdk"
import { deleteTaxRateRulesStep } from "../steps"

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

export const deleteTaxRateRulesWorkflowId = "delete-tax-rate-rules"
/**
* This workflow deletes one or more tax rate rules.
*/
export const deleteTaxRateRulesWorkflow = createWorkflow(
deleteTaxRateRulesWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowResponse<void> => {
(input: WorkflowData<DeleteTaxRateRulesWorkflowInput>): WorkflowResponse<void> => {
return new WorkflowResponse(deleteTaxRateRulesStep(input.ids))
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import {
} from "@medusajs/workflows-sdk"
import { deleteTaxRatesStep } from "../steps"

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

export const deleteTaxRatesWorkflowId = "delete-tax-rates"
/**
* This workflow deletes one or more tax rates.
*/
export const deleteTaxRatesWorkflow = createWorkflow(
deleteTaxRatesWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowResponse<void> => {
(input: WorkflowData<DeleteTaxRatesWorkflowInput>): WorkflowResponse<void> => {
return new WorkflowResponse(deleteTaxRatesStep(input.ids))
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import {
} from "@medusajs/workflows-sdk"
import { deleteTaxRegionsStep } from "../steps"

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

export const deleteTaxRegionsWorkflowId = "delete-tax-regions"
/**
* This workflow deletes one or more tax regions.
*/
export const deleteTaxRegionsWorkflow = createWorkflow(
deleteTaxRegionsWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowResponse<void> => {
(input: WorkflowData<DeleteTaxRegionsWorkflowInput>): WorkflowResponse<void> => {
return new WorkflowResponse(deleteTaxRegionsStep(input.ids))
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ import {
listTaxRateRuleIdsStep,
} from "../steps"

type WorkflowInput = {
export type SetTaxRatesRulesWorkflowInput = {
tax_rate_ids: string[]
rules: Omit<CreateTaxRateRuleDTO, "tax_rate_id">[]
}

export const setTaxRateRulesWorkflowId = "set-tax-rate-rules"
/**
* This workflow sets the rules of tax rates.
*/
export const setTaxRateRulesWorkflow = createWorkflow(
setTaxRateRulesWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowResponse<TaxRateRuleDTO[]> => {
(input: WorkflowData<SetTaxRatesRulesWorkflowInput>): WorkflowResponse<TaxRateRuleDTO[]> => {
const ruleIds = listTaxRateRuleIdsStep({
selector: { tax_rate_id: input.tax_rate_ids },
})
Expand Down
18 changes: 11 additions & 7 deletions packages/core/core-flows/src/tax/workflows/update-tax-rates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ import {
} from "../steps"
// import { setTaxRateRulesWorkflow } from "./set-tax-rate-rules"

type UpdateTaxRatesStepInput = {
export type UpdateTaxRatesWorkflowInput = {
selector: FilterableTaxRateProps
update: UpdateTaxRateDTO
}

type WorkflowInput = UpdateTaxRatesStepInput

type StepInput = {
export type MaybeListTaxRateRuleIdsStepInput = {
tax_rate_ids: string[]
update: UpdateTaxRateDTO
}
Expand Down Expand Up @@ -65,9 +63,12 @@ type StepInput = {
// )

const maybeListTaxRateRuleIdsStepId = "maybe-list-tax-rate-rule-ids"
const maybeListTaxRateRuleIdsStep = createStep(
/**
* This step lists the rules to update in a tax rate update object.
*/
export const maybeListTaxRateRuleIdsStep = createStep(
maybeListTaxRateRuleIdsStepId,
async (input: StepInput, { container }) => {
async (input: MaybeListTaxRateRuleIdsStepInput, { container }) => {
const { update, tax_rate_ids } = input

if (!update.rules) {
Expand All @@ -88,9 +89,12 @@ const maybeListTaxRateRuleIdsStep = createStep(
)

export const updateTaxRatesWorkflowId = "update-tax-rates"
/**
* This workflow updates tax rates matching specified filters.
*/
export const updateTaxRatesWorkflow = createWorkflow(
updateTaxRatesWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowResponse<TaxRateDTO[]> => {
(input: WorkflowData<UpdateTaxRatesWorkflowInput>): WorkflowResponse<TaxRateDTO[]> => {
const cleanedUpdateInput = transform(input, (data) => {
// Transform clones data so we can safely modify it
if (data.update.rules) {
Expand Down
Loading