Skip to content

Commit 4e49ceb

Browse files
authored
fix(core-flows, types): export steps and types related to credit lines (medusajs#12567)
- Export steps that are used in credit-line related workflows - Move workflow's input type to the `workflows.ts` type file - Add and update TSDocs
1 parent 32c89ab commit 4e49ceb

File tree

7 files changed

+122
-5
lines changed

7 files changed

+122
-5
lines changed

.changeset/old-dancers-retire.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@medusajs/core-flows": patch
3+
"@medusajs/types": patch
4+
---
5+
6+
fix(core-flows, types): export steps and types related to credit lines

packages/core/core-flows/src/cart/workflows/create-cart-credit-lines.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
CartCreditLineDTO,
3-
CreateCartCreditLineDTO,
3+
CreateCartCreditLinesWorkflowInput,
44
} from "@medusajs/framework/types"
55
import { Modules } from "@medusajs/framework/utils"
66
import {
@@ -11,10 +11,27 @@ import {
1111
import { createEntitiesStep } from "../../common/steps/create-entities"
1212

1313
export const createCartCreditLinesWorkflowId = "create-cart-credit-lines"
14+
/**
15+
* This workflow creates one or more credit lines for a cart.
16+
*
17+
* @example
18+
* const { result } = await createCartCreditLinesWorkflow(container)
19+
* .run({
20+
* input: {
21+
* cart_id: "cart_123",
22+
* amount: 10,
23+
* reference: "payment",
24+
* reference_id: "payment_123",
25+
* metadata: {
26+
* key: "value",
27+
* },
28+
* }
29+
* })
30+
*/
1431
export const createCartCreditLinesWorkflow = createWorkflow(
1532
createCartCreditLinesWorkflowId,
1633
(
17-
input: WorkflowData<CreateCartCreditLineDTO[]>
34+
input: WorkflowData<CreateCartCreditLinesWorkflowInput>
1835
): WorkflowResponse<CartCreditLineDTO[]> => {
1936
const creditLines = createEntitiesStep({
2037
moduleRegistrationName: Modules.CART,

packages/core/core-flows/src/cart/workflows/delete-cart-credit-lines.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ import {
77
import { deleteEntitiesStep } from "../../common/steps/delete-entities"
88

99
export const deleteCartCreditLinesWorkflowId = "delete-cart-credit-lines"
10+
/**
11+
* This workflow deletes one or more credit lines from a cart.
12+
*/
1013
export const deleteCartCreditLinesWorkflow = createWorkflow(
1114
deleteCartCreditLinesWorkflowId,
12-
(input: WorkflowData<{ id: string[] }>) => {
15+
(input: WorkflowData<{
16+
/**
17+
* The IDs of the credit lines to delete.
18+
*/
19+
id: string[]
20+
}>) => {
1321
deleteEntitiesStep({
1422
moduleRegistrationName: Modules.CART,
1523
invokeMethod: "softDeleteCreditLines",

packages/core/core-flows/src/common/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
export * from "./steps/create-entities"
12
export * from "./steps/create-remote-links"
23
export * from "./steps/dismiss-remote-links"
4+
export * from "./steps/delete-entities"
35
export * from "./steps/emit-event"
46
export * from "./steps/remove-remote-links"
57
export * from "./steps/update-remote-links"

packages/core/core-flows/src/common/steps/create-entities.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
11
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
22

33
export interface CreateEntitiesStepType {
4+
/**
5+
* The regitration name of the module that contains the method to be invoked.
6+
*/
47
moduleRegistrationName: string
8+
/**
9+
* The method to be invoked.
10+
*/
511
invokeMethod: string
12+
/**
13+
* The method to be invoked in case of compensation (when an error occurs).
14+
*/
615
compensateMethod: string
16+
/**
17+
* A string to pass to the compensate method.
18+
*/
719
entityIdentifier?: string
20+
/**
21+
* The data to pass to the invoke method.
22+
* For example, an array of objects to create.
23+
*/
824
data: any[]
925
}
1026

1127
export const createEntitiesStepId = "create-entities-step"
1228
/**
13-
* This step creates entities for any given module or resource
29+
* This step creates one or more entities using methods in a module's service.
30+
*
31+
* @example
32+
* createEntitiesStep({
33+
* moduleRegistrationName: Modules.CART,
34+
* invokeMethod: "createCreditLines",
35+
* compensateMethod: "deleteCreditLines",
36+
* data: {
37+
* cart_id: "cart_123",
38+
* amount: 10,
39+
* reference: "payment",
40+
* reference_id: "payment_123",
41+
* metadata: {
42+
* key: "value",
43+
* },
44+
* },
45+
* })
1446
*/
1547
export const createEntitiesStep = createStep(
1648
createEntitiesStepId,

packages/core/core-flows/src/common/steps/delete-entities.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,41 @@
11
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
22

33
export interface DeleteEntitiesStepType {
4+
/**
5+
* The regitration name of the module that contains the method to be invoked.
6+
*/
47
moduleRegistrationName: string
8+
/**
9+
* The method to be invoked.
10+
*/
511
invokeMethod: string
12+
/**
13+
* The method to be invoked in case of compensation (when an error occurs).
14+
*/
615
compensateMethod: string
16+
/**
17+
* A string to pass to the compensate method.
18+
* For example, an ID of the entity to be deleted.
19+
*/
720
entityIdentifier?: string
21+
/**
22+
* The data to pass to the invoke method.
23+
* For example, an array of IDs to delete.
24+
*/
825
data: any[]
926
}
1027

1128
export const deleteEntitiesStepId = "delete-entities-step"
1229
/**
13-
* This step deletes one or more entities.
30+
* This step deletes one or more entities using methods in a module's service.
31+
*
32+
* @example
33+
* deleteEntitiesStep({
34+
* moduleRegistrationName: Modules.CART,
35+
* invokeMethod: "softDeleteCreditLines",
36+
* compensateMethod: "restoreCreditLines",
37+
* data: input.id,
38+
* })
1439
*/
1540
export const deleteEntitiesStep = createStep(
1641
deleteEntitiesStepId,

packages/core/types/src/cart/workflows.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,30 @@ export interface CartWorkflowDTO {
527527
id: string
528528
payment_collection: PaymentCollectionDTO
529529
}
530+
531+
export type CreateCartCreditLinesWorkflowInput = {
532+
/**
533+
* The ID of the cart that the credit line belongs to.
534+
*/
535+
cart_id: string
536+
537+
/**
538+
* The amount of the credit line.
539+
*/
540+
amount: number
541+
542+
/**
543+
* The reference model name that the credit line is generated from
544+
*/
545+
reference: string | null
546+
547+
/**
548+
* The reference model id that the credit line is generated from
549+
*/
550+
reference_id: string | null
551+
552+
/**
553+
* The metadata of the cart detail
554+
*/
555+
metadata: Record<string, unknown> | null
556+
}[]

0 commit comments

Comments
 (0)