@medusajs/workflows-sdk 0.1.6 → 0.1.7-next-20240505114610
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helper/index.d.ts +1 -0
- package/dist/helper/index.js +1 -0
- package/dist/helper/index.js.map +1 -1
- package/dist/helper/type.d.ts +58 -0
- package/dist/helper/type.js +3 -0
- package/dist/helper/type.js.map +1 -0
- package/dist/helper/workflow-export.d.ts +1 -61
- package/dist/helper/workflow-export.js +18 -12
- package/dist/helper/workflow-export.js.map +1 -1
- package/dist/utils/_playground.js +6 -6
- package/dist/utils/_playground.js.map +1 -1
- package/dist/utils/composer/create-workflow.d.ts +2 -65
- package/dist/utils/composer/create-workflow.js +22 -0
- package/dist/utils/composer/create-workflow.js.map +1 -1
- package/dist/utils/composer/helpers/step-response.d.ts +1 -1
- package/dist/utils/composer/helpers/step-response.js +3 -1
- package/dist/utils/composer/helpers/step-response.js.map +1 -1
- package/dist/utils/composer/type.d.ts +67 -2
- package/package.json +5 -5
package/dist/helper/index.d.ts
CHANGED
package/dist/helper/index.js
CHANGED
|
@@ -18,4 +18,5 @@ __exportStar(require("./merge-data"), exports);
|
|
|
18
18
|
__exportStar(require("./empty-handler"), exports);
|
|
19
19
|
__exportStar(require("./pipe"), exports);
|
|
20
20
|
__exportStar(require("./workflow-export"), exports);
|
|
21
|
+
__exportStar(require("./type"), exports);
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
package/dist/helper/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helper/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,kDAA+B;AAC/B,yCAAsB;AACtB,oDAAiC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helper/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,kDAA+B;AAC/B,yCAAsB;AACtB,oDAAiC;AACjC,yCAAsB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Context, LoadedModule, MedusaContainer } from "@medusajs/types";
|
|
2
|
+
import { DistributedTransaction, DistributedTransactionEvents, LocalWorkflow, TransactionStepError } from "@medusajs/orchestration";
|
|
3
|
+
export type FlowRunOptions<TData = unknown> = {
|
|
4
|
+
input?: TData;
|
|
5
|
+
context?: Context;
|
|
6
|
+
resultFrom?: string | string[] | Symbol;
|
|
7
|
+
throwOnError?: boolean;
|
|
8
|
+
events?: DistributedTransactionEvents;
|
|
9
|
+
container?: LoadedModule[] | MedusaContainer;
|
|
10
|
+
};
|
|
11
|
+
export type FlowRegisterStepSuccessOptions<TData = unknown> = {
|
|
12
|
+
idempotencyKey: string;
|
|
13
|
+
response?: TData;
|
|
14
|
+
context?: Context;
|
|
15
|
+
resultFrom?: string | string[] | Symbol;
|
|
16
|
+
throwOnError?: boolean;
|
|
17
|
+
events?: DistributedTransactionEvents;
|
|
18
|
+
container?: LoadedModule[] | MedusaContainer;
|
|
19
|
+
};
|
|
20
|
+
export type FlowRegisterStepFailureOptions<TData = unknown> = {
|
|
21
|
+
idempotencyKey: string;
|
|
22
|
+
response?: TData;
|
|
23
|
+
context?: Context;
|
|
24
|
+
resultFrom?: string | string[] | Symbol;
|
|
25
|
+
throwOnError?: boolean;
|
|
26
|
+
events?: DistributedTransactionEvents;
|
|
27
|
+
container?: LoadedModule[] | MedusaContainer;
|
|
28
|
+
};
|
|
29
|
+
export type FlowCancelOptions = {
|
|
30
|
+
transaction?: DistributedTransaction;
|
|
31
|
+
transactionId?: string;
|
|
32
|
+
context?: Context;
|
|
33
|
+
throwOnError?: boolean;
|
|
34
|
+
events?: DistributedTransactionEvents;
|
|
35
|
+
container?: LoadedModule[] | MedusaContainer;
|
|
36
|
+
};
|
|
37
|
+
export type WorkflowResult<TResult = unknown> = {
|
|
38
|
+
errors: TransactionStepError[];
|
|
39
|
+
transaction: DistributedTransaction;
|
|
40
|
+
result: TResult;
|
|
41
|
+
};
|
|
42
|
+
export type ExportedWorkflow<TData = unknown, TResult = unknown, TDataOverride = undefined, TResultOverride = undefined> = {
|
|
43
|
+
run: (args?: FlowRunOptions<TDataOverride extends undefined ? TData : TDataOverride>) => Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
|
|
44
|
+
registerStepSuccess: (args?: FlowRegisterStepSuccessOptions<TDataOverride extends undefined ? TData : TDataOverride>) => Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
|
|
45
|
+
registerStepFailure: (args?: FlowRegisterStepFailureOptions<TDataOverride extends undefined ? TData : TDataOverride>) => Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
|
|
46
|
+
cancel: (args?: FlowCancelOptions) => Promise<WorkflowResult>;
|
|
47
|
+
};
|
|
48
|
+
export type MainExportedWorkflow<TData = unknown, TResult = unknown> = {
|
|
49
|
+
<TDataOverride = undefined, TResultOverride = undefined>(container?: LoadedModule[] | MedusaContainer): Omit<LocalWorkflow, "run" | "registerStepSuccess" | "registerStepFailure" | "cancel"> & ExportedWorkflow<TData, TResult, TDataOverride, TResultOverride>;
|
|
50
|
+
} & {
|
|
51
|
+
/**
|
|
52
|
+
* You can also directly call run, registerStepSuccess, registerStepFailure and cancel on the exported workflow
|
|
53
|
+
*/
|
|
54
|
+
run<TDataOverride = undefined, TResultOverride = undefined>(args?: FlowRunOptions<TDataOverride extends undefined ? TData : TDataOverride>): Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
|
|
55
|
+
registerStepSuccess<TDataOverride = undefined, TResultOverride = undefined>(args?: FlowRegisterStepSuccessOptions<TDataOverride extends undefined ? TData : TDataOverride>): Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
|
|
56
|
+
registerStepFailure<TDataOverride = undefined, TResultOverride = undefined>(args?: FlowRegisterStepFailureOptions<TDataOverride extends undefined ? TData : TDataOverride>): Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
|
|
57
|
+
cancel(args?: FlowCancelOptions): Promise<WorkflowResult>;
|
|
58
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/helper/type.ts"],"names":[],"mappings":""}
|
|
@@ -1,64 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Context, LoadedModule, MedusaContainer } from "@medusajs/types";
|
|
3
|
-
export type FlowRunOptions<TData = unknown> = {
|
|
4
|
-
input?: TData;
|
|
5
|
-
context?: Context;
|
|
6
|
-
resultFrom?: string | string[] | Symbol;
|
|
7
|
-
throwOnError?: boolean;
|
|
8
|
-
events?: DistributedTransactionEvents;
|
|
9
|
-
};
|
|
10
|
-
export type FlowRegisterStepSuccessOptions<TData = unknown> = {
|
|
11
|
-
idempotencyKey: string;
|
|
12
|
-
response?: TData;
|
|
13
|
-
context?: Context;
|
|
14
|
-
resultFrom?: string | string[] | Symbol;
|
|
15
|
-
throwOnError?: boolean;
|
|
16
|
-
events?: DistributedTransactionEvents;
|
|
17
|
-
};
|
|
18
|
-
export type FlowRegisterStepFailureOptions<TData = unknown> = {
|
|
19
|
-
idempotencyKey: string;
|
|
20
|
-
response?: TData;
|
|
21
|
-
context?: Context;
|
|
22
|
-
resultFrom?: string | string[] | Symbol;
|
|
23
|
-
throwOnError?: boolean;
|
|
24
|
-
events?: DistributedTransactionEvents;
|
|
25
|
-
};
|
|
26
|
-
export type FlowCancelOptions = {
|
|
27
|
-
transaction?: DistributedTransaction;
|
|
28
|
-
transactionId?: string;
|
|
29
|
-
context?: Context;
|
|
30
|
-
throwOnError?: boolean;
|
|
31
|
-
events?: DistributedTransactionEvents;
|
|
32
|
-
};
|
|
33
|
-
export type WorkflowResult<TResult = unknown> = {
|
|
34
|
-
errors: TransactionStepError[];
|
|
35
|
-
transaction: DistributedTransaction;
|
|
36
|
-
result: TResult;
|
|
37
|
-
};
|
|
38
|
-
export type ExportedWorkflow<TData = unknown, TResult = unknown, TDataOverride = undefined, TResultOverride = undefined> = {
|
|
39
|
-
run: (args?: FlowRunOptions<TDataOverride extends undefined ? TData : TDataOverride>) => Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
|
|
40
|
-
registerStepSuccess: (args?: FlowRegisterStepSuccessOptions<TDataOverride extends undefined ? TData : TDataOverride>) => Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
|
|
41
|
-
registerStepFailure: (args?: FlowRegisterStepFailureOptions<TDataOverride extends undefined ? TData : TDataOverride>) => Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
|
|
42
|
-
cancel: (args?: FlowCancelOptions) => Promise<WorkflowResult>;
|
|
43
|
-
};
|
|
44
|
-
export type MainExportedWorkflow<TData = unknown, TResult = unknown> = {
|
|
45
|
-
<TDataOverride = undefined, TResultOverride = undefined>(container?: LoadedModule[] | MedusaContainer): Omit<LocalWorkflow, "run" | "registerStepSuccess" | "registerStepFailure" | "cancel"> & ExportedWorkflow<TData, TResult, TDataOverride, TResultOverride>;
|
|
46
|
-
/**
|
|
47
|
-
* You can also directly call run, registerStepSuccess, registerStepFailure and cancel on the exported workflow
|
|
48
|
-
*/
|
|
49
|
-
run<TDataOverride = undefined, TResultOverride = undefined>(args?: FlowRunOptions<TDataOverride extends undefined ? TData : TDataOverride> & {
|
|
50
|
-
container?: LoadedModule[] | MedusaContainer;
|
|
51
|
-
}): Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
|
|
52
|
-
registerStepSuccess<TDataOverride = undefined, TResultOverride = undefined>(args?: FlowRegisterStepSuccessOptions<TDataOverride extends undefined ? TData : TDataOverride> & {
|
|
53
|
-
container?: LoadedModule[] | MedusaContainer;
|
|
54
|
-
}): Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
|
|
55
|
-
registerStepFailure<TDataOverride = undefined, TResultOverride = undefined>(args?: FlowRegisterStepFailureOptions<TDataOverride extends undefined ? TData : TDataOverride> & {
|
|
56
|
-
container?: LoadedModule[] | MedusaContainer;
|
|
57
|
-
}): Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
|
|
58
|
-
cancel(args?: FlowCancelOptions & {
|
|
59
|
-
container?: LoadedModule[] | MedusaContainer;
|
|
60
|
-
}): Promise<WorkflowResult>;
|
|
61
|
-
};
|
|
1
|
+
import { MainExportedWorkflow } from "./type";
|
|
62
2
|
export declare const exportWorkflow: <TData = unknown, TResult = unknown>(workflowId: string, defaultResult?: string | Symbol, dataPreparation?: ((data: TData) => Promise<unknown>) | undefined, options?: {
|
|
63
3
|
wrappedInput?: boolean;
|
|
64
4
|
}) => MainExportedWorkflow<TData, TResult>;
|
|
@@ -9,15 +9,18 @@ const ulid_1 = require("ulid");
|
|
|
9
9
|
const medusa_workflow_1 = require("../medusa-workflow");
|
|
10
10
|
const composer_1 = require("../utils/composer");
|
|
11
11
|
function createContextualWorkflowRunner({ workflowId, defaultResult, dataPreparation, options, container, }) {
|
|
12
|
-
if (!container) {
|
|
13
|
-
container = modules_sdk_1.MedusaModule.getLoadedModules().map((mod) => Object.values(mod)[0]);
|
|
14
|
-
}
|
|
15
12
|
const flow = new orchestration_1.LocalWorkflow(workflowId, container);
|
|
16
13
|
const originalRun = flow.run.bind(flow);
|
|
17
14
|
const originalRegisterStepSuccess = flow.registerStepSuccess.bind(flow);
|
|
18
15
|
const originalRegisterStepFailure = flow.registerStepFailure.bind(flow);
|
|
19
16
|
const originalCancel = flow.cancel.bind(flow);
|
|
20
|
-
const originalExecution = async (method, { throwOnError, resultFrom, isCancel = false }, ...args) => {
|
|
17
|
+
const originalExecution = async (method, { throwOnError, resultFrom, isCancel = false, container: executionContainer, }, ...args) => {
|
|
18
|
+
if (!executionContainer && !flow.container) {
|
|
19
|
+
executionContainer = modules_sdk_1.MedusaModule.getLoadedModules().map((mod) => Object.values(mod)[0]);
|
|
20
|
+
}
|
|
21
|
+
if (!flow.container) {
|
|
22
|
+
flow.container = executionContainer;
|
|
23
|
+
}
|
|
21
24
|
const transaction = await method.apply(method, args);
|
|
22
25
|
let errors = transaction.getErrors(orchestration_1.TransactionHandlerType.INVOKE);
|
|
23
26
|
const failedStatus = [orchestration_1.TransactionState.FAILED, orchestration_1.TransactionState.REVERTED];
|
|
@@ -49,7 +52,7 @@ function createContextualWorkflowRunner({ workflowId, defaultResult, dataPrepara
|
|
|
49
52
|
result,
|
|
50
53
|
};
|
|
51
54
|
};
|
|
52
|
-
const newRun = async ({ input, context: outerContext, throwOnError, resultFrom, events, } = {
|
|
55
|
+
const newRun = async ({ input, context: outerContext, throwOnError, resultFrom, events, container, } = {
|
|
53
56
|
throwOnError: true,
|
|
54
57
|
resultFrom: defaultResult,
|
|
55
58
|
}) => {
|
|
@@ -74,10 +77,10 @@ function createContextualWorkflowRunner({ workflowId, defaultResult, dataPrepara
|
|
|
74
77
|
};
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
|
-
return await originalExecution(originalRun, { throwOnError, resultFrom }, context.transactionId, input, context, events);
|
|
80
|
+
return await originalExecution(originalRun, { throwOnError, resultFrom, container }, context.transactionId, input, context, events);
|
|
78
81
|
};
|
|
79
82
|
flow.run = newRun;
|
|
80
|
-
const newRegisterStepSuccess = async ({ response, idempotencyKey, context: outerContext, throwOnError, resultFrom, events, } = {
|
|
83
|
+
const newRegisterStepSuccess = async ({ response, idempotencyKey, context: outerContext, throwOnError, resultFrom, events, container, } = {
|
|
81
84
|
idempotencyKey: "",
|
|
82
85
|
throwOnError: true,
|
|
83
86
|
resultFrom: defaultResult,
|
|
@@ -90,10 +93,10 @@ function createContextualWorkflowRunner({ workflowId, defaultResult, dataPrepara
|
|
|
90
93
|
transactionId,
|
|
91
94
|
__type: utils_1.MedusaContextType,
|
|
92
95
|
};
|
|
93
|
-
return await originalExecution(originalRegisterStepSuccess, { throwOnError, resultFrom }, idempotencyKey, response, context, events);
|
|
96
|
+
return await originalExecution(originalRegisterStepSuccess, { throwOnError, resultFrom, container }, idempotencyKey, response, context, events);
|
|
94
97
|
};
|
|
95
98
|
flow.registerStepSuccess = newRegisterStepSuccess;
|
|
96
|
-
const newRegisterStepFailure = async ({ response, idempotencyKey, context: outerContext, throwOnError, resultFrom, events, } = {
|
|
99
|
+
const newRegisterStepFailure = async ({ response, idempotencyKey, context: outerContext, throwOnError, resultFrom, events, container, } = {
|
|
97
100
|
idempotencyKey: "",
|
|
98
101
|
throwOnError: true,
|
|
99
102
|
resultFrom: defaultResult,
|
|
@@ -106,10 +109,10 @@ function createContextualWorkflowRunner({ workflowId, defaultResult, dataPrepara
|
|
|
106
109
|
transactionId,
|
|
107
110
|
__type: utils_1.MedusaContextType,
|
|
108
111
|
};
|
|
109
|
-
return await originalExecution(originalRegisterStepFailure, { throwOnError, resultFrom }, idempotencyKey, response, context, events);
|
|
112
|
+
return await originalExecution(originalRegisterStepFailure, { throwOnError, resultFrom, container }, idempotencyKey, response, context, events);
|
|
110
113
|
};
|
|
111
114
|
flow.registerStepFailure = newRegisterStepFailure;
|
|
112
|
-
const newCancel = async ({ transaction, transactionId, context: outerContext, throwOnError, events, } = {
|
|
115
|
+
const newCancel = async ({ transaction, transactionId, context: outerContext, throwOnError, events, container, } = {
|
|
113
116
|
throwOnError: true,
|
|
114
117
|
}) => {
|
|
115
118
|
throwOnError ?? (throwOnError = true);
|
|
@@ -122,13 +125,16 @@ function createContextualWorkflowRunner({ workflowId, defaultResult, dataPrepara
|
|
|
122
125
|
throwOnError,
|
|
123
126
|
resultFrom: undefined,
|
|
124
127
|
isCancel: true,
|
|
128
|
+
container,
|
|
125
129
|
}, transaction ?? transactionId, context, events);
|
|
126
130
|
};
|
|
127
131
|
flow.cancel = newCancel;
|
|
128
132
|
return flow;
|
|
129
133
|
}
|
|
130
134
|
const exportWorkflow = (workflowId, defaultResult, dataPreparation, options) => {
|
|
131
|
-
function exportedWorkflow(
|
|
135
|
+
function exportedWorkflow(
|
|
136
|
+
// TODO: rm when all usage have been migrated
|
|
137
|
+
container) {
|
|
132
138
|
return createContextualWorkflowRunner({
|
|
133
139
|
workflowId,
|
|
134
140
|
defaultResult,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-export.js","sourceRoot":"","sources":["../../src/helper/workflow-export.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"workflow-export.js","sourceRoot":"","sources":["../../src/helper/workflow-export.ts"],"names":[],"mappings":";;;AAAA,2DAIgC;AAGhC,uDAAoD;AACpD,2CAAmD;AACnD,2BAAwB;AACxB,+BAA2B;AAC3B,wDAAmD;AACnD,gDAAgD;AAWhD,SAAS,8BAA8B,CAKrC,EACA,UAAU,EACV,aAAa,EACb,eAAe,EACf,OAAO,EACP,SAAS,GASV;IAKC,MAAM,IAAI,GAAG,IAAI,6BAAa,CAAC,UAAU,EAAE,SAAU,CAAC,CAAA;IAEtD,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvC,MAAM,2BAA2B,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvE,MAAM,2BAA2B,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvE,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAE7C,MAAM,iBAAiB,GAAG,KAAK,EAC7B,MAAM,EACN,EACE,YAAY,EACZ,UAAU,EACV,QAAQ,GAAG,KAAK,EAChB,SAAS,EAAE,kBAAkB,GAC9B,EACD,GAAG,IAAI,EACP,EAAE;QACF,IAAI,CAAC,kBAAkB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YAC1C,kBAAkB,GAAG,0BAAY,CAAC,gBAAgB,EAAE,CAAC,GAAG,CACtD,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAA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,QAAQ,EACR,SAAS,CACV,CAAC,SAAS,CAAC,CAAA;IACd,CAAC,CAAA;IAED,gCAAc,CAAC,gBAAgB,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAA;IAC7D,OAAO,gBAAwD,CAAA;AACjE,CAAC,CAAA;AAjKY,QAAA,cAAc,kBAiK1B"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const composer_1 = require("./composer");
|
|
4
4
|
const step1 = (0, composer_1.createStep)("step1", async (input, context) => {
|
|
5
|
-
return new composer_1.StepResponse({ step1:
|
|
5
|
+
return new composer_1.StepResponse({ step1: "step1" });
|
|
6
6
|
});
|
|
7
7
|
const step2 = (0, composer_1.createStep)("step2", async (input, context) => {
|
|
8
8
|
return new composer_1.StepResponse({ step2: input });
|
|
@@ -10,16 +10,16 @@ const step2 = (0, composer_1.createStep)("step2", async (input, context) => {
|
|
|
10
10
|
const step3 = (0, composer_1.createStep)("step3", async () => {
|
|
11
11
|
return new composer_1.StepResponse({ step3: "step3" });
|
|
12
12
|
});
|
|
13
|
-
const workflow = (0, composer_1.createWorkflow)("workflow", function () {
|
|
14
|
-
|
|
13
|
+
const workflow = (0, composer_1.createWorkflow)("sub-workflow", function (input) {
|
|
14
|
+
step1();
|
|
15
15
|
step3();
|
|
16
|
-
return step2({ filters: { id:
|
|
16
|
+
return step2({ filters: { id: input.outsideWorkflowData } });
|
|
17
17
|
});
|
|
18
18
|
const workflow2 = (0, composer_1.createWorkflow)("workflow", function () {
|
|
19
19
|
const step1Res = step1();
|
|
20
20
|
step3();
|
|
21
|
-
workflow();
|
|
22
|
-
return
|
|
21
|
+
const workflowRes = workflow.asStep({ outsideWorkflowData: step1Res.step1 });
|
|
22
|
+
return workflowRes;
|
|
23
23
|
});
|
|
24
24
|
workflow2()
|
|
25
25
|
.run({})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_playground.js","sourceRoot":"","sources":["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,SAAS,EAAE;KACR,GAAG,CAAC,EAAE,CAAC;KACP,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;IACZ,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AACzB,CAAC,CAAC,CAAA;AAEJ;;;;;;;;;;;;;;;;;;;;;;MAsBM"}
|
|
@@ -1,68 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { ExportedWorkflow } from "../../helper";
|
|
4
|
-
import { WorkflowData, WorkflowDataProperties } from "./type";
|
|
5
|
-
/**
|
|
6
|
-
* An exported workflow, which is the type of a workflow constructed by the {@link createWorkflow} function. The exported workflow can be invoked to create
|
|
7
|
-
* an executable workflow, optionally within a specified container. So, to execute the workflow, you must invoke the exported workflow, then run the
|
|
8
|
-
* `run` method of the exported workflow.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* To execute a workflow:
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* myWorkflow()
|
|
15
|
-
* .run({
|
|
16
|
-
* input: {
|
|
17
|
-
* name: "John"
|
|
18
|
-
* }
|
|
19
|
-
* })
|
|
20
|
-
* .then(({ result }) => {
|
|
21
|
-
* console.log(result)
|
|
22
|
-
* })
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* To specify the container of the workflow, you can pass it as an argument to the call of the exported workflow. This is necessary when executing the workflow
|
|
26
|
-
* within a Medusa resource such as an API Route or a Subscriber.
|
|
27
|
-
*
|
|
28
|
-
* For example:
|
|
29
|
-
*
|
|
30
|
-
* ```ts
|
|
31
|
-
* import type {
|
|
32
|
-
* MedusaRequest,
|
|
33
|
-
* MedusaResponse
|
|
34
|
-
* } from "@medusajs/medusa";
|
|
35
|
-
* import myWorkflow from "../../../workflows/hello-world";
|
|
36
|
-
*
|
|
37
|
-
* export async function GET(
|
|
38
|
-
* req: MedusaRequest,
|
|
39
|
-
* res: MedusaResponse
|
|
40
|
-
* ) {
|
|
41
|
-
* const { result } = await myWorkflow(req.scope)
|
|
42
|
-
* .run({
|
|
43
|
-
* input: {
|
|
44
|
-
* name: req.query.name as string
|
|
45
|
-
* }
|
|
46
|
-
* })
|
|
47
|
-
*
|
|
48
|
-
* res.send(result)
|
|
49
|
-
* }
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
export type ReturnWorkflow<TData, TResult, THooks extends Record<string, Function>> = {
|
|
53
|
-
<TDataOverride = undefined, TResultOverride = undefined>(container?: LoadedModule[] | MedusaContainer): Omit<LocalWorkflow, "run" | "registerStepSuccess" | "registerStepFailure" | "cancel"> & ExportedWorkflow<TData, TResult, TDataOverride, TResultOverride>;
|
|
54
|
-
} & THooks & {
|
|
55
|
-
getName: () => string;
|
|
56
|
-
} & {
|
|
57
|
-
config: (config: TransactionModelOptions) => void;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Extract the raw type of the expected input data of a workflow.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* type WorkflowInputData = UnwrapWorkflowInputDataType<typeof myWorkflow>
|
|
64
|
-
*/
|
|
65
|
-
export type UnwrapWorkflowInputDataType<T extends ReturnWorkflow<any, any, any>> = T extends ReturnWorkflow<infer TData, infer R, infer THooks> ? TData : never;
|
|
1
|
+
import { TransactionModelOptions } from "@medusajs/orchestration";
|
|
2
|
+
import { ReturnWorkflow, WorkflowData, WorkflowDataProperties } from "./type";
|
|
66
3
|
/**
|
|
67
4
|
* This function creates a workflow with the provided name and a constructor function.
|
|
68
5
|
* The constructor function builds the workflow from steps created by the {@link createStep} function.
|
|
@@ -5,6 +5,8 @@ const orchestration_1 = require("@medusajs/orchestration");
|
|
|
5
5
|
const utils_1 = require("@medusajs/utils");
|
|
6
6
|
const helper_1 = require("../../helper");
|
|
7
7
|
const proxy_1 = require("./helpers/proxy");
|
|
8
|
+
const create_step_1 = require("./create-step");
|
|
9
|
+
const helpers_1 = require("./helpers");
|
|
8
10
|
global[utils_1.OrchestrationUtils.SymbolMedusaWorkflowComposerContext] = null;
|
|
9
11
|
/**
|
|
10
12
|
* This function creates a workflow with the provided name and a constructor function.
|
|
@@ -132,6 +134,26 @@ composer) {
|
|
|
132
134
|
};
|
|
133
135
|
}
|
|
134
136
|
mainFlow.getName = () => name;
|
|
137
|
+
mainFlow.run = mainFlow().run;
|
|
138
|
+
mainFlow.runAsStep = ({ input, }) => {
|
|
139
|
+
// TODO: Async sub workflow is not supported yet
|
|
140
|
+
// Info: Once the export workflow can fire the execution through the engine if loaded, the async workflow can be executed,
|
|
141
|
+
// the step would inherit the async configuration and subscribe to the onFinish event of the sub worklow and mark itself as success or failure
|
|
142
|
+
return (0, create_step_1.createStep)(`${name}-as-step`, async (stepInput, stepContext) => {
|
|
143
|
+
const { container, ...sharedContext } = stepContext;
|
|
144
|
+
const transaction = await workflow.run({
|
|
145
|
+
input: stepInput,
|
|
146
|
+
container,
|
|
147
|
+
context: sharedContext,
|
|
148
|
+
});
|
|
149
|
+
return new helpers_1.StepResponse(transaction.result, transaction);
|
|
150
|
+
}, async (transaction, { container }) => {
|
|
151
|
+
if (!transaction) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
await workflow(container).cancel(transaction);
|
|
155
|
+
})(input);
|
|
156
|
+
};
|
|
135
157
|
return mainFlow;
|
|
136
158
|
}
|
|
137
159
|
exports.createWorkflow = createWorkflow;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-workflow.js","sourceRoot":"","sources":["../../../src/utils/composer/create-workflow.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"create-workflow.js","sourceRoot":"","sources":["../../../src/utils/composer/create-workflow.ts"],"names":[],"mappings":";;;AAAA,2DAIgC;AAEhC,2CAA8D;AAC9D,yCAA6C;AAC7C,2CAAyC;AAQzC,+CAA0C;AAC1C,uCAAwC;AAExC,MAAM,CAAC,0BAAkB,CAAC,mCAAmC,CAAC,GAAG,IAAI,CAA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|
|
22
22
|
*/
|
|
23
|
-
output
|
|
23
|
+
output?: TOutput,
|
|
24
24
|
/**
|
|
25
25
|
* The input to be passed as a parameter to the step's compensation function. If not provided, the `output` will be provided instead.
|
|
26
26
|
*/
|
|
@@ -44,7 +44,9 @@ class StepResponse {
|
|
|
44
44
|
_StepResponse___type.set(this, utils_1.OrchestrationUtils.SymbolWorkflowStepResponse);
|
|
45
45
|
_StepResponse_output.set(this, void 0);
|
|
46
46
|
_StepResponse_compensateInput.set(this, void 0);
|
|
47
|
-
|
|
47
|
+
if ((0, utils_1.isDefined)(output)) {
|
|
48
|
+
__classPrivateFieldSet(this, _StepResponse_output, output, "f");
|
|
49
|
+
}
|
|
48
50
|
__classPrivateFieldSet(this, _StepResponse_compensateInput, (compensateInput ?? output), "f");
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step-response.js","sourceRoot":"","sources":["../../../../src/utils/composer/helpers/step-response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2DAAmE;AACnE,
|
|
1
|
+
{"version":3,"file":"step-response.js","sourceRoot":"","sources":["../../../../src/utils/composer/helpers/step-response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2DAAmE;AACnE,2CAA+D;AAE/D;;;;;;;GAOG;AACH,MAAa,YAAY;IAKvB;;;;;;;OAOG;IACH;IACE;;OAEG;IACH,MAAgB;IAChB;;OAEG;IACH,eAAkC;QApB3B,+BAAU,0BAAkB,CAAC,0BAA0B,EAAA;QACvD,uCAAgB;QAChB,gDAAmC;QAoB1C,IAAI,IAAA,iBAAS,EAAC,MAAM,CAAC,EAAE;YACrB,uBAAA,IAAI,wBAAW,MAAM,MAAA,CAAA;SACtB;QACD,uBAAA,IAAI,iCAAoB,CAAC,eAAe,IAAI,MAAM,CAAqB,MAAA,CAAA;IACzE,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyEG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,GAAG,mBAAmB;QACnD,MAAM,IAAI,yCAAyB,CAAC,OAAO,CAAC,CAAA;IAC9C,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,uBAAA,IAAI,4BAAQ,CAAA;IACrB,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,uBAAA,IAAI,4BAAQ,CAAA;IACrB,CAAC;IAED;;OAEG;IACH,IAAI,eAAe;QACjB,OAAO,uBAAA,IAAI,qCAAqC,CAAA;IAClD,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,MAAM,EAAE,uBAAA,IAAI,4BAAQ;YACpB,MAAM,EAAE,uBAAA,IAAI,4BAAQ;YACpB,eAAe,EAAE,uBAAA,IAAI,qCAAiB;SACvC,CAAA;IACH,CAAC;CACF;AA1ID,oCA0IC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { OrchestratorBuilder, TransactionContext as OriginalWorkflowTransactionContext, TransactionPayload, TransactionStepsDefinition, WorkflowHandler } from "@medusajs/orchestration";
|
|
2
|
-
import { Context, MedusaContainer } from "@medusajs/types";
|
|
1
|
+
import { LocalWorkflow, OrchestratorBuilder, TransactionContext as OriginalWorkflowTransactionContext, TransactionModelOptions, TransactionPayload, TransactionStepsDefinition, WorkflowHandler } from "@medusajs/orchestration";
|
|
2
|
+
import { Context, LoadedModule, MedusaContainer } from "@medusajs/types";
|
|
3
|
+
import { ExportedWorkflow } from "../../helper";
|
|
3
4
|
export type StepFunctionResult<TOutput extends unknown | unknown[] = unknown> = (this: CreateWorkflowComposerContext) => WorkflowData<TOutput>;
|
|
4
5
|
type StepFunctionReturnConfig<TOutput> = {
|
|
5
6
|
config(config: {
|
|
@@ -88,4 +89,68 @@ export type WorkflowTransactionContext = StepExecutionContext & OriginalWorkflow
|
|
|
88
89
|
};
|
|
89
90
|
};
|
|
90
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* An exported workflow, which is the type of a workflow constructed by the {@link createWorkflow} function. The exported workflow can be invoked to create
|
|
94
|
+
* an executable workflow, optionally within a specified container. So, to execute the workflow, you must invoke the exported workflow, then run the
|
|
95
|
+
* `run` method of the exported workflow.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* To execute a workflow:
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* myWorkflow()
|
|
102
|
+
* .run({
|
|
103
|
+
* input: {
|
|
104
|
+
* name: "John"
|
|
105
|
+
* }
|
|
106
|
+
* })
|
|
107
|
+
* .then(({ result }) => {
|
|
108
|
+
* console.log(result)
|
|
109
|
+
* })
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* To specify the container of the workflow, you can pass it as an argument to the call of the exported workflow. This is necessary when executing the workflow
|
|
113
|
+
* within a Medusa resource such as an API Route or a Subscriber.
|
|
114
|
+
*
|
|
115
|
+
* For example:
|
|
116
|
+
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* import type {
|
|
119
|
+
* MedusaRequest,
|
|
120
|
+
* MedusaResponse
|
|
121
|
+
* } from "@medusajs/medusa";
|
|
122
|
+
* import myWorkflow from "../../../workflows/hello-world";
|
|
123
|
+
*
|
|
124
|
+
* export async function GET(
|
|
125
|
+
* req: MedusaRequest,
|
|
126
|
+
* res: MedusaResponse
|
|
127
|
+
* ) {
|
|
128
|
+
* const { result } = await myWorkflow(req.scope)
|
|
129
|
+
* .run({
|
|
130
|
+
* input: {
|
|
131
|
+
* name: req.query.name as string
|
|
132
|
+
* }
|
|
133
|
+
* })
|
|
134
|
+
*
|
|
135
|
+
* res.send(result)
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export type ReturnWorkflow<TData, TResult, THooks extends Record<string, Function>> = {
|
|
140
|
+
<TDataOverride = undefined, TResultOverride = undefined>(container?: LoadedModule[] | MedusaContainer): Omit<LocalWorkflow, "run" | "registerStepSuccess" | "registerStepFailure" | "cancel"> & ExportedWorkflow<TData, TResult, TDataOverride, TResultOverride>;
|
|
141
|
+
} & THooks & {
|
|
142
|
+
runAsStep: ({ input, }: {
|
|
143
|
+
input: TData;
|
|
144
|
+
}) => ReturnType<StepFunction<TData, TResult>>;
|
|
145
|
+
run: <TDataOverride = undefined, TResultOverride = undefined>(...args: Parameters<ExportedWorkflow<TData, TResult, TDataOverride, TResultOverride>["run"]>) => ReturnType<ExportedWorkflow<TData, TResult, TDataOverride, TResultOverride>["run"]>;
|
|
146
|
+
getName: () => string;
|
|
147
|
+
config: (config: TransactionModelOptions) => void;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Extract the raw type of the expected input data of a workflow.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* type WorkflowInputData = UnwrapWorkflowInputDataType<typeof myWorkflow>
|
|
154
|
+
*/
|
|
155
|
+
export type UnwrapWorkflowInputDataType<T extends ReturnWorkflow<any, any, any>> = T extends ReturnWorkflow<infer TData, infer R, infer THooks> ? TData : never;
|
|
91
156
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medusajs/workflows-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7-next-20240505114610",
|
|
4
4
|
"description": "Set of workflows tooling for Medusa",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"author": "Medusa",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@medusajs/types": "
|
|
24
|
+
"@medusajs/types": "1.11.17-next-20240505114610",
|
|
25
25
|
"cross-env": "^5.2.1",
|
|
26
26
|
"jest": "^29.6.3",
|
|
27
27
|
"rimraf": "^5.0.1",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"typescript": "^5.1.6"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@medusajs/modules-sdk": "
|
|
33
|
-
"@medusajs/orchestration": "
|
|
34
|
-
"@medusajs/utils": "
|
|
32
|
+
"@medusajs/modules-sdk": "1.12.12-next-20240505114610",
|
|
33
|
+
"@medusajs/orchestration": "0.5.8-next-20240505114610",
|
|
34
|
+
"@medusajs/utils": "1.11.10-next-20240505114610",
|
|
35
35
|
"awilix": "^8.0.1",
|
|
36
36
|
"ulid": "^2.3.0"
|
|
37
37
|
},
|