File tree Expand file tree Collapse file tree 7 files changed +122
-5
lines changed
Expand file tree Collapse file tree 7 files changed +122
-5
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 11import {
22 CartCreditLineDTO ,
3- CreateCartCreditLineDTO ,
3+ CreateCartCreditLinesWorkflowInput ,
44} from "@medusajs/framework/types"
55import { Modules } from "@medusajs/framework/utils"
66import {
@@ -11,10 +11,27 @@ import {
1111import { createEntitiesStep } from "../../common/steps/create-entities"
1212
1313export 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+ */
1431export 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 ,
Original file line number Diff line number Diff line change @@ -7,9 +7,17 @@ import {
77import { deleteEntitiesStep } from "../../common/steps/delete-entities"
88
99export const deleteCartCreditLinesWorkflowId = "delete-cart-credit-lines"
10+ /**
11+ * This workflow deletes one or more credit lines from a cart.
12+ */
1013export 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" ,
Original file line number Diff line number Diff line change 1+ export * from "./steps/create-entities"
12export * from "./steps/create-remote-links"
23export * from "./steps/dismiss-remote-links"
4+ export * from "./steps/delete-entities"
35export * from "./steps/emit-event"
46export * from "./steps/remove-remote-links"
57export * from "./steps/update-remote-links"
Original file line number Diff line number Diff line change 11import { StepResponse , createStep } from "@medusajs/framework/workflows-sdk"
22
33export 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
1127export 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 */
1547export const createEntitiesStep = createStep (
1648 createEntitiesStepId ,
Original file line number Diff line number Diff line change 11import { StepResponse , createStep } from "@medusajs/framework/workflows-sdk"
22
33export 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
1128export 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 */
1540export const deleteEntitiesStep = createStep (
1641 deleteEntitiesStepId ,
Original file line number Diff line number Diff 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+ } [ ]
You can’t perform that action at this time.
0 commit comments