@8medusa/workflows-sdk 2.7.0

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.
Files changed (82) hide show
  1. package/dist/helper/index.d.ts +3 -0
  2. package/dist/helper/index.d.ts.map +1 -0
  3. package/dist/helper/index.js +19 -0
  4. package/dist/helper/index.js.map +1 -0
  5. package/dist/helper/type.d.ts +66 -0
  6. package/dist/helper/type.d.ts.map +1 -0
  7. package/dist/helper/type.js +3 -0
  8. package/dist/helper/type.js.map +1 -0
  9. package/dist/helper/workflow-export.d.ts +6 -0
  10. package/dist/helper/workflow-export.d.ts.map +1 -0
  11. package/dist/helper/workflow-export.js +253 -0
  12. package/dist/helper/workflow-export.js.map +1 -0
  13. package/dist/index.d.ts +5 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +34 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/medusa-workflow.d.ts +3 -0
  18. package/dist/medusa-workflow.d.ts.map +1 -0
  19. package/dist/medusa-workflow.js +19 -0
  20. package/dist/medusa-workflow.js.map +1 -0
  21. package/dist/tsconfig.tsbuildinfo +1 -0
  22. package/dist/utils/_playground.d.ts +2 -0
  23. package/dist/utils/_playground.d.ts.map +1 -0
  24. package/dist/utils/_playground.js +79 -0
  25. package/dist/utils/_playground.js.map +1 -0
  26. package/dist/utils/composer/create-hook.d.ts +60 -0
  27. package/dist/utils/composer/create-hook.d.ts.map +1 -0
  28. package/dist/utils/composer/create-hook.js +93 -0
  29. package/dist/utils/composer/create-hook.js.map +1 -0
  30. package/dist/utils/composer/create-step.d.ts +134 -0
  31. package/dist/utils/composer/create-step.d.ts.map +1 -0
  32. package/dist/utils/composer/create-step.js +237 -0
  33. package/dist/utils/composer/create-step.js.map +1 -0
  34. package/dist/utils/composer/create-workflow.d.ts +71 -0
  35. package/dist/utils/composer/create-workflow.d.ts.map +1 -0
  36. package/dist/utils/composer/create-workflow.js +209 -0
  37. package/dist/utils/composer/create-workflow.js.map +1 -0
  38. package/dist/utils/composer/helpers/create-step-handler.d.ts +20 -0
  39. package/dist/utils/composer/helpers/create-step-handler.d.ts.map +1 -0
  40. package/dist/utils/composer/helpers/create-step-handler.js +70 -0
  41. package/dist/utils/composer/helpers/create-step-handler.js.map +1 -0
  42. package/dist/utils/composer/helpers/index.d.ts +3 -0
  43. package/dist/utils/composer/helpers/index.d.ts.map +1 -0
  44. package/dist/utils/composer/helpers/index.js +19 -0
  45. package/dist/utils/composer/helpers/index.js.map +1 -0
  46. package/dist/utils/composer/helpers/proxy.d.ts +3 -0
  47. package/dist/utils/composer/helpers/proxy.d.ts.map +1 -0
  48. package/dist/utils/composer/helpers/proxy.js +25 -0
  49. package/dist/utils/composer/helpers/proxy.js.map +1 -0
  50. package/dist/utils/composer/helpers/resolve-value.d.ts +5 -0
  51. package/dist/utils/composer/helpers/resolve-value.d.ts.map +1 -0
  52. package/dist/utils/composer/helpers/resolve-value.js +64 -0
  53. package/dist/utils/composer/helpers/resolve-value.js.map +1 -0
  54. package/dist/utils/composer/helpers/step-response.d.ts +126 -0
  55. package/dist/utils/composer/helpers/step-response.d.ts.map +1 -0
  56. package/dist/utils/composer/helpers/step-response.js +166 -0
  57. package/dist/utils/composer/helpers/step-response.js.map +1 -0
  58. package/dist/utils/composer/helpers/workflow-response.d.ts +20 -0
  59. package/dist/utils/composer/helpers/workflow-response.d.ts.map +1 -0
  60. package/dist/utils/composer/helpers/workflow-response.js +16 -0
  61. package/dist/utils/composer/helpers/workflow-response.js.map +1 -0
  62. package/dist/utils/composer/index.d.ts +11 -0
  63. package/dist/utils/composer/index.d.ts.map +1 -0
  64. package/dist/utils/composer/index.js +27 -0
  65. package/dist/utils/composer/index.js.map +1 -0
  66. package/dist/utils/composer/parallelize.d.ts +43 -0
  67. package/dist/utils/composer/parallelize.d.ts.map +1 -0
  68. package/dist/utils/composer/parallelize.js +57 -0
  69. package/dist/utils/composer/parallelize.js.map +1 -0
  70. package/dist/utils/composer/transform.d.ts +79 -0
  71. package/dist/utils/composer/transform.d.ts.map +1 -0
  72. package/dist/utils/composer/transform.js +40 -0
  73. package/dist/utils/composer/transform.js.map +1 -0
  74. package/dist/utils/composer/type.d.ts +227 -0
  75. package/dist/utils/composer/type.d.ts.map +1 -0
  76. package/dist/utils/composer/type.js +3 -0
  77. package/dist/utils/composer/type.js.map +1 -0
  78. package/dist/utils/composer/when.d.ts +58 -0
  79. package/dist/utils/composer/when.d.ts.map +1 -0
  80. package/dist/utils/composer/when.js +56 -0
  81. package/dist/utils/composer/when.js.map +1 -0
  82. package/package.json +67 -0
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createWorkflow = createWorkflow;
4
+ const orchestration_1 = require("@8medusa/orchestration");
5
+ const utils_1 = require("@8medusa/utils");
6
+ const ulid_1 = require("ulid");
7
+ const helper_1 = require("../../helper");
8
+ const create_step_1 = require("./create-step");
9
+ const proxy_1 = require("./helpers/proxy");
10
+ const step_response_1 = require("./helpers/step-response");
11
+ global[utils_1.OrchestrationUtils.SymbolMedusaWorkflowComposerContext] = null;
12
+ /**
13
+ * This function creates a workflow with the provided name and a constructor function.
14
+ * The constructor function builds the workflow from steps created by the {@link createStep} function.
15
+ * The returned workflow is an exported workflow of type {@link ReturnWorkflow}, meaning it's not executed right away. To execute it,
16
+ * invoke the exported workflow, then run its `run` method.
17
+ *
18
+ * @typeParam TData - The type of the input passed to the composer function.
19
+ * @typeParam TResult - The type of the output returned by the composer function.
20
+ * @typeParam THooks - The type of hooks defined in the workflow.
21
+ *
22
+ * @returns The created workflow. You can later execute the workflow by invoking it, then using its `run` method.
23
+ *
24
+ * @example
25
+ * import {
26
+ * createWorkflow,
27
+ * WorkflowResponse
28
+ * } from "@8medusa/framework/workflows-sdk"
29
+ * import { MedusaRequest, MedusaResponse } from "@8medusa/framework/http"
30
+ * import {
31
+ * createProductStep,
32
+ * getProductStep,
33
+ * } from "./steps"
34
+ *
35
+ * interface WorkflowInput {
36
+ * title: string
37
+ * }
38
+ *
39
+ * const myWorkflow = createWorkflow(
40
+ * "my-workflow",
41
+ * (input: WorkflowInput) => {
42
+ * // Everything here will be executed and resolved later
43
+ * // during the execution. Including the data access.
44
+ *
45
+ * const product = createProductStep(input)
46
+ * return new WorkflowResponse(getProductStep(product.id))
47
+ * }
48
+ * )
49
+ *
50
+ * export async function GET(
51
+ * req: MedusaRequest,
52
+ * res: MedusaResponse
53
+ * ) {
54
+ * const { result: product } = await myWorkflow(req.scope)
55
+ * .run({
56
+ * input: {
57
+ * title: "Shirt"
58
+ * }
59
+ * })
60
+ *
61
+ * res.json({
62
+ * product
63
+ * })
64
+ * }
65
+ */
66
+ function createWorkflow(
67
+ /**
68
+ * The name of the workflow or its configuration.
69
+ */
70
+ nameOrConfig,
71
+ /**
72
+ * The constructor function that is executed when the `run` method in {@link ReturnWorkflow} is used.
73
+ * The function can't be an arrow function or an asynchronus function. It also can't directly manipulate data.
74
+ * You'll have to use the {@link transform} function if you need to directly manipulate data.
75
+ */
76
+ composer) {
77
+ const fileSourcePath = (0, utils_1.getCallerFilePath)();
78
+ const name = (0, utils_1.isString)(nameOrConfig) ? nameOrConfig : nameOrConfig.name;
79
+ const options = (0, utils_1.isString)(nameOrConfig) ? {} : nameOrConfig;
80
+ const handlers = new Map();
81
+ let newWorkflow = false;
82
+ if (!orchestration_1.WorkflowManager.getWorkflow(name)) {
83
+ newWorkflow = true;
84
+ orchestration_1.WorkflowManager.register(name, undefined, handlers, options);
85
+ }
86
+ const context = {
87
+ __type: utils_1.OrchestrationUtils.SymbolMedusaWorkflowComposerContext,
88
+ workflowId: name,
89
+ flow: orchestration_1.WorkflowManager.getEmptyTransactionDefinition(),
90
+ isAsync: false,
91
+ handlers,
92
+ hooks_: {
93
+ declared: [],
94
+ registered: [],
95
+ },
96
+ hooksCallback_: {},
97
+ hookBinder: (name, fn) => {
98
+ context.hooks_.declared.push(name);
99
+ context.hooksCallback_[name] = fn.bind(context)();
100
+ },
101
+ stepBinder: (fn) => {
102
+ return fn.bind(context)();
103
+ },
104
+ parallelizeBinder: (fn) => {
105
+ return fn.bind(context)();
106
+ },
107
+ };
108
+ global[utils_1.OrchestrationUtils.SymbolMedusaWorkflowComposerContext] = context;
109
+ const inputPlaceHolder = (0, proxy_1.proxify)({
110
+ __type: utils_1.OrchestrationUtils.SymbolInputReference,
111
+ __step__: "",
112
+ config: () => {
113
+ // TODO: config default value?
114
+ throw new Error("Config is not available for the input object.");
115
+ },
116
+ });
117
+ const returnedStep = composer.apply(context, [inputPlaceHolder]);
118
+ delete global[utils_1.OrchestrationUtils.SymbolMedusaWorkflowComposerContext];
119
+ if (newWorkflow) {
120
+ orchestration_1.WorkflowManager.update(name, context.flow, handlers, options);
121
+ }
122
+ else {
123
+ orchestration_1.WorkflowManager.register(name, context.flow, handlers, options);
124
+ }
125
+ const workflow = (0, helper_1.exportWorkflow)(name, returnedStep, {
126
+ wrappedInput: true,
127
+ sourcePath: fileSourcePath,
128
+ });
129
+ const mainFlow = (container) => {
130
+ const workflow_ = workflow(container);
131
+ const expandedFlow = workflow_;
132
+ expandedFlow.config = (config) => {
133
+ workflow_.setOptions(config);
134
+ };
135
+ return expandedFlow;
136
+ };
137
+ mainFlow.hooks = {};
138
+ for (const hook of context.hooks_.declared) {
139
+ mainFlow.hooks[hook] = context.hooksCallback_[hook].bind(context);
140
+ }
141
+ mainFlow.getName = () => name;
142
+ mainFlow.run = mainFlow().run;
143
+ mainFlow.runAsStep = ({ input, }) => {
144
+ const step = (0, create_step_1.createStep)({
145
+ name: `${name}-as-step`,
146
+ async: context.isAsync,
147
+ nested: context.isAsync, // if async we flag this is a nested transaction
148
+ }, async (stepInput, stepContext) => {
149
+ const { container, ...sharedContext } = stepContext;
150
+ const workflowEngine = container.resolve(utils_1.Modules.WORKFLOW_ENGINE, {
151
+ allowUnregistered: true,
152
+ });
153
+ const executionContext = {
154
+ ...(sharedContext?.context ?? {}),
155
+ transactionId: step.__step__ + "-" + (stepContext.transactionId ?? (0, ulid_1.ulid)()),
156
+ parentStepIdempotencyKey: stepContext.idempotencyKey,
157
+ preventReleaseEvents: true,
158
+ };
159
+ let transaction;
160
+ if (workflowEngine && context.isAsync) {
161
+ transaction = await workflowEngine.run(name, {
162
+ input: stepInput,
163
+ context: executionContext,
164
+ });
165
+ }
166
+ else {
167
+ transaction = await workflow.run({
168
+ input: stepInput,
169
+ container,
170
+ context: executionContext,
171
+ });
172
+ }
173
+ return new step_response_1.StepResponse(transaction.result, context.isAsync ? stepContext.transactionId : transaction);
174
+ }, async (transaction, stepContext) => {
175
+ // The step itself has failed, there is nothing to revert
176
+ if (!transaction) {
177
+ return;
178
+ }
179
+ const { container, ...sharedContext } = stepContext;
180
+ const workflowEngine = container.resolve(utils_1.Modules.WORKFLOW_ENGINE, {
181
+ allowUnregistered: true,
182
+ });
183
+ const executionContext = {
184
+ ...(sharedContext?.context ?? {}),
185
+ transactionId: step.__step__ + "-" + (stepContext.transactionId ?? (0, ulid_1.ulid)()),
186
+ parentStepIdempotencyKey: stepContext.idempotencyKey,
187
+ preventReleaseEvents: true,
188
+ };
189
+ const transactionId = step.__step__ + "-" + stepContext.transactionId;
190
+ if (workflowEngine && context.isAsync) {
191
+ await workflowEngine.cancel(name, {
192
+ transactionId: transactionId,
193
+ context: executionContext,
194
+ });
195
+ }
196
+ else {
197
+ await workflow(container).cancel({
198
+ transaction: transaction?.transaction,
199
+ transactionId,
200
+ container,
201
+ context: executionContext,
202
+ });
203
+ }
204
+ })(input);
205
+ return step;
206
+ };
207
+ return mainFlow;
208
+ }
209
+ //# sourceMappingURL=create-workflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-workflow.js","sourceRoot":"","sources":["../../../src/utils/composer/create-workflow.ts"],"names":[],"mappings":";;AAuFA,wCAqLC;AA5QD,0DAI+B;AAM/B,0CAKuB;AACvB,+BAA2B;AAC3B,yCAA6D;AAC7D,+CAA0C;AAC1C,2CAAyC;AACzC,2DAAsD;AAU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;aAC3B,CAAA;YAED,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,GAAG,GAAG,GAAG,WAAW,CAAC,aAAa,CAAA;YAErE,IAAI,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;gBACtC,MAAM,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE;oBAChC,aAAa,EAAE,aAAa;oBAC5B,OAAO,EAAE,gBAAgB;iBAC1B,CAAC,CAAA;YACJ,CAAC;iBAAM,CAAC;gBACN,MAAM,QAAQ,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;oBAC/B,WAAW,EAAG,WAAmC,EAAE,WAAW;oBAC9D,aAAa;oBACb,SAAS;oBACT,OAAO,EAAE,gBAAgB;iBAC1B,CAAC,CAAA;YACJ,CAAC;QACH,CAAC,CACF,CAAC,KAAK,CAA6C,CAAA;QAEpD,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;IAED,OAAO,QAAkD,CAAA;AAC3D,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { WorkflowStepHandlerArguments } from "@8medusa/orchestration";
2
+ import { ApplyStepOptions } from "../create-step";
3
+ import { CreateWorkflowComposerContext, WorkflowData } from "../type";
4
+ import { StepResponse } from "./step-response";
5
+ export declare function createStepHandler<TInvokeInput, TStepInput extends {
6
+ [K in keyof TInvokeInput]: WorkflowData<TInvokeInput[K]>;
7
+ }, TInvokeResultOutput, TInvokeResultCompensateInput>(this: CreateWorkflowComposerContext, { stepName, input, invokeFn, compensateFn, }: ApplyStepOptions<TStepInput, TInvokeInput, TInvokeResultOutput, TInvokeResultCompensateInput>): {
8
+ invoke: (stepArguments: WorkflowStepHandlerArguments) => Promise<{
9
+ __type: string;
10
+ output: StepResponse<any, any> | {
11
+ __type: string;
12
+ output: any;
13
+ compensateInput: any;
14
+ };
15
+ }>;
16
+ compensate: ((stepArguments: WorkflowStepHandlerArguments) => Promise<{
17
+ output: any;
18
+ }>) | undefined;
19
+ };
20
+ //# sourceMappingURL=create-step-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-step-handler.d.ts","sourceRoot":"","sources":["../../../../src/utils/composer/helpers/create-step-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AAErE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EACL,6BAA6B,EAE7B,YAAY,EACb,MAAM,SAAS,CAAA;AAEhB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAwC9C,wBAAgB,iBAAiB,CAC/B,YAAY,EACZ,UAAU,SAAS;KAChB,CAAC,IAAI,MAAM,YAAY,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CACzD,EACD,mBAAmB,EACnB,4BAA4B,EAE5B,IAAI,EAAE,6BAA6B,EACnC,EACE,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,YAAY,GACb,EAAE,gBAAgB,CACjB,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,4BAA4B,CAC7B;4BAG+B,4BAA4B;;;;;;;;iCAuBhC,4BAA4B;;;EAsBzD"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStepHandler = createStepHandler;
4
+ const utils_1 = require("@8medusa/utils");
5
+ const resolve_value_1 = require("./resolve-value");
6
+ function buildStepContext({ action, stepArguments, }) {
7
+ const metadata = stepArguments.metadata;
8
+ const idempotencyKey = metadata.idempotency_key;
9
+ stepArguments.context.idempotencyKey = idempotencyKey;
10
+ const flowMetadata = stepArguments.transaction.getFlow()?.metadata;
11
+ const executionContext = {
12
+ workflowId: metadata.model_id,
13
+ stepName: metadata.action,
14
+ action,
15
+ idempotencyKey,
16
+ attempt: metadata.attempt,
17
+ container: stepArguments.container,
18
+ metadata,
19
+ eventGroupId: flowMetadata?.eventGroupId ?? stepArguments.context.eventGroupId,
20
+ parentStepIdempotencyKey: flowMetadata?.parentStepIdempotencyKey,
21
+ preventReleaseEvents: flowMetadata?.preventReleaseEvents ?? false,
22
+ transactionId: stepArguments.context.transactionId,
23
+ context: stepArguments.context,
24
+ " getStepResult"(stepId, action = "invoke") {
25
+ return stepArguments[action][stepId]?.output?.output;
26
+ },
27
+ };
28
+ return executionContext;
29
+ }
30
+ function createStepHandler({ stepName, input, invokeFn, compensateFn, }) {
31
+ const handler = {
32
+ invoke: async (stepArguments) => {
33
+ const executionContext = buildStepContext({
34
+ action: "invoke",
35
+ stepArguments,
36
+ });
37
+ const argInput = input ? await (0, resolve_value_1.resolveValue)(input, stepArguments) : {};
38
+ const stepResponse = await invokeFn.apply(this, [
39
+ argInput,
40
+ executionContext,
41
+ ]);
42
+ const stepResponseJSON = stepResponse?.__type === utils_1.OrchestrationUtils.SymbolWorkflowStepResponse
43
+ ? stepResponse.toJSON()
44
+ : stepResponse;
45
+ return {
46
+ __type: utils_1.OrchestrationUtils.SymbolWorkflowWorkflowData,
47
+ output: stepResponseJSON,
48
+ };
49
+ },
50
+ compensate: compensateFn
51
+ ? async (stepArguments) => {
52
+ const executionContext = buildStepContext({
53
+ action: "compensate",
54
+ stepArguments,
55
+ });
56
+ const stepOutput = stepArguments.invoke[stepName]?.output;
57
+ const invokeResult = stepOutput?.__type === utils_1.OrchestrationUtils.SymbolWorkflowStepResponse
58
+ ? stepOutput.compensateInput
59
+ : stepOutput;
60
+ const args = [invokeResult, executionContext];
61
+ const output = await compensateFn.apply(this, args);
62
+ return {
63
+ output,
64
+ };
65
+ }
66
+ : undefined,
67
+ };
68
+ return handler;
69
+ }
70
+ //# sourceMappingURL=create-step-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-step-handler.js","sourceRoot":"","sources":["../../../../src/utils/composer/helpers/create-step-handler.ts"],"names":[],"mappings":";;AAiDA,8CAmEC;AAnHD,0CAAmD;AAOnD,mDAA8C;AAG9C,SAAS,gBAAgB,CAAC,EACxB,MAAM,EACN,aAAa,GAId;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,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;YACtE,MAAM,YAAY,GAA2B,MAAM,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE;gBACtE,QAAQ;gBACR,gBAAgB;aACjB,CAAC,CAAA;YAEF,MAAM,gBAAgB,GACpB,YAAY,EAAE,MAAM,KAAK,0BAAkB,CAAC,0BAA0B;gBACpE,CAAC,CAAC,YAAY,CAAC,MAAM,EAAE;gBACvB,CAAC,CAAC,YAAY,CAAA;YAElB,OAAO;gBACL,MAAM,EAAE,0BAAkB,CAAC,0BAA0B;gBACrD,MAAM,EAAE,gBAAgB;aACzB,CAAA;QACH,CAAC;QACD,UAAU,EAAE,YAAY;YACtB,CAAC,CAAC,KAAK,EAAE,aAA2C,EAAE,EAAE;gBACpD,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;oBACxC,MAAM,EAAE,YAAY;oBACpB,aAAa;iBACd,CAAC,CAAA;gBAEF,MAAM,UAAU,GAAI,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAS,EAAE,MAAM,CAAA;gBAClE,MAAM,YAAY,GAChB,UAAU,EAAE,MAAM,KAAK,0BAAkB,CAAC,0BAA0B;oBAClE,CAAC,CAAC,UAAU,CAAC,eAAe;oBAC5B,CAAC,CAAC,UAAU,CAAA;gBAEhB,MAAM,IAAI,GAAG,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAA;gBAC7C,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;gBACnD,OAAO;oBACL,MAAM;iBACP,CAAA;YACH,CAAC;YACH,CAAC,CAAC,SAAS;KACd,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./step-response";
2
+ export * from "./resolve-value";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/composer/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./step-response"), exports);
18
+ __exportStar(require("./resolve-value"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/composer/helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,kDAA+B"}
@@ -0,0 +1,3 @@
1
+ import { WorkflowData } from "../type";
2
+ export declare function proxify<T>(obj: WorkflowData<any>): T;
3
+ //# sourceMappingURL=proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../../src/utils/composer/helpers/proxy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAA8B,MAAM,SAAS,CAAA;AAIlE,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAqBpD"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.proxify = proxify;
4
+ const transform_1 = require("../transform");
5
+ const utils_1 = require("@8medusa/utils");
6
+ const resolve_value_1 = require("./resolve-value");
7
+ function proxify(obj) {
8
+ return new Proxy(obj, {
9
+ get(target, prop) {
10
+ if (prop in target) {
11
+ return target[prop];
12
+ }
13
+ return (0, transform_1.transform)({}, async function (_, context) {
14
+ const { invoke } = context;
15
+ let output = target.__type === utils_1.OrchestrationUtils.SymbolInputReference ||
16
+ target.__type === utils_1.OrchestrationUtils.SymbolWorkflowStepTransformer
17
+ ? target
18
+ : invoke?.[obj.__step__]?.output;
19
+ output = await (0, resolve_value_1.resolveValue)(output, context);
20
+ return output?.[prop];
21
+ });
22
+ },
23
+ });
24
+ }
25
+ //# sourceMappingURL=proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../../src/utils/composer/helpers/proxy.ts"],"names":[],"mappings":";;AAKA,0BAqBC;AA1BD,4CAAwC;AAExC,0CAAmD;AACnD,mDAA8C;AAE9C,SAAgB,OAAO,CAAI,GAAsB;IAC/C,OAAO,IAAI,KAAK,CAAC,GAAG,EAAE;QACpB,GAAG,CAAC,MAAW,EAAE,IAAqB;YACpC,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACnB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAA;YACrB,CAAC;YAED,OAAO,IAAA,qBAAS,EAAC,EAAE,EAAE,KAAK,WAAW,CAAC,EAAE,OAAO;gBAC7C,MAAM,EAAE,MAAM,EAAE,GAAG,OAAqC,CAAA;gBACxD,IAAI,MAAM,GACR,MAAM,CAAC,MAAM,KAAK,0BAAkB,CAAC,oBAAoB;oBACzD,MAAM,CAAC,MAAM,KAAK,0BAAkB,CAAC,6BAA6B;oBAChE,CAAC,CAAC,MAAM;oBACR,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;gBAEpC,MAAM,GAAG,MAAM,IAAA,4BAAY,EAAC,MAAM,EAAE,OAAO,CAAC,CAAA;gBAE5C,OAAO,MAAM,EAAE,CAAC,IAAI,CAAC,CAAA;YACvB,CAAC,CAAC,CAAA;QACJ,CAAC;KACF,CAAiB,CAAA;AACpB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @internal
3
+ */
4
+ export declare function resolveValue(input: any, transactionContext: any): any;
5
+ //# sourceMappingURL=resolve-value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-value.d.ts","sourceRoot":"","sources":["../../../../src/utils/composer/helpers/resolve-value.ts"],"names":[],"mappings":"AAoCA;;GAEG;AACH,wBAAsB,YAAY,CAAC,KAAK,KAAA,EAAE,kBAAkB,KAAA,OA0C3D"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveValue = resolveValue;
4
+ const utils_1 = require("@8medusa/utils");
5
+ async function resolveProperty(property, transactionContext) {
6
+ const { invoke: invokeRes } = transactionContext;
7
+ let res;
8
+ if (property?.__type === utils_1.OrchestrationUtils.SymbolInputReference) {
9
+ res = transactionContext.payload;
10
+ }
11
+ else if (property?.__type === utils_1.OrchestrationUtils.SymbolMedusaWorkflowResponse) {
12
+ res = await resolveValue(property.$result, transactionContext);
13
+ }
14
+ else if (property?.__type === utils_1.OrchestrationUtils.SymbolWorkflowStepTransformer) {
15
+ res = await property.__resolver(transactionContext);
16
+ }
17
+ else if (property?.__type === utils_1.OrchestrationUtils.SymbolWorkflowStep) {
18
+ const output = invokeRes[property.__step__]?.output ?? invokeRes[property.__step__];
19
+ if (output?.__type === utils_1.OrchestrationUtils.SymbolWorkflowStepResponse) {
20
+ res = output.output;
21
+ }
22
+ else {
23
+ res = output;
24
+ }
25
+ }
26
+ else if (property?.__type === utils_1.OrchestrationUtils.SymbolWorkflowStepResponse) {
27
+ res = property.output;
28
+ }
29
+ else {
30
+ res = property;
31
+ }
32
+ return res;
33
+ }
34
+ /**
35
+ * @internal
36
+ */
37
+ async function resolveValue(input, transactionContext) {
38
+ const unwrapInput = async (inputTOUnwrap, parentRef) => {
39
+ if (inputTOUnwrap == null) {
40
+ return inputTOUnwrap;
41
+ }
42
+ if (Array.isArray(inputTOUnwrap)) {
43
+ return await (0, utils_1.promiseAll)(inputTOUnwrap.map((i) => resolveValue(i, transactionContext)));
44
+ }
45
+ if (typeof inputTOUnwrap !== "object") {
46
+ return inputTOUnwrap;
47
+ }
48
+ for (const key of Object.keys(inputTOUnwrap)) {
49
+ parentRef[key] = (0, utils_1.deepCopy)(await resolveProperty(inputTOUnwrap[key], transactionContext));
50
+ if (typeof parentRef[key] === "object") {
51
+ parentRef[key] = await unwrapInput(parentRef[key], parentRef[key]);
52
+ }
53
+ }
54
+ return parentRef;
55
+ };
56
+ const copiedInput = input?.__type === utils_1.OrchestrationUtils.SymbolWorkflowWorkflowData
57
+ ? input.output
58
+ : input;
59
+ const result = copiedInput?.__type
60
+ ? await resolveProperty(copiedInput, transactionContext)
61
+ : await unwrapInput(copiedInput, {});
62
+ return result && JSON.parse(JSON.stringify(result));
63
+ }
64
+ //# sourceMappingURL=resolve-value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-value.js","sourceRoot":"","sources":["../../../../src/utils/composer/helpers/resolve-value.ts"],"names":[],"mappings":";;AAuCA,oCA0CC;AAjFD,0CAAyE;AAEzE,KAAK,UAAU,eAAe,CAAC,QAAQ,EAAE,kBAAkB;IACzD,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,kBAAkB,CAAA;IAEhD,IAAI,GAAG,CAAA;IAEP,IAAI,QAAQ,EAAE,MAAM,KAAK,0BAAkB,CAAC,oBAAoB,EAAE,CAAC;QACjE,GAAG,GAAG,kBAAkB,CAAC,OAAO,CAAA;IAClC,CAAC;SAAM,IACL,QAAQ,EAAE,MAAM,KAAK,0BAAkB,CAAC,4BAA4B,EACpE,CAAC;QACD,GAAG,GAAG,MAAM,YAAY,CAAC,QAAQ,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AAI,OAAO,aAAa,KAAK,QAAQ,EAAE,CAAC;YACtC,OAAO,aAAa,CAAA;QACtB,CAAC;QAED,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YAC7C,SAAS,CAAC,GAAG,CAAC,GAAG,IAAA,gBAAQ,EACvB,MAAM,eAAe,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,kBAAkB,CAAC,CAC9D,CAAA;YAED,IAAI,OAAO,SAAS,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;gBACvC,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;YACpE,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAA;IAClB,CAAC,CAAA;IAED,MAAM,WAAW,GACf,KAAK,EAAE,MAAM,KAAK,0BAAkB,CAAC,0BAA0B;QAC7D,CAAC,CAAC,KAAK,CAAC,MAAM;QACd,CAAC,CAAC,KAAK,CAAA;IAEX,MAAM,MAAM,GAAG,WAAW,EAAE,MAAM;QAChC,CAAC,CAAC,MAAM,eAAe,CAAC,WAAW,EAAE,kBAAkB,CAAC;QACxD,CAAC,CAAC,MAAM,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;IAEtC,OAAO,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;AACrD,CAAC"}
@@ -0,0 +1,126 @@
1
+ import { SkipStepResponse } from "@8medusa/orchestration";
2
+ /**
3
+ * This class is used to create the response returned by a step. A step return its data by returning an instance of `StepResponse`.
4
+ *
5
+ * @typeParam TOutput - The type of the output of the step.
6
+ * @typeParam TCompensateInput -
7
+ * The type of the compensation input. If the step doesn't specify any compensation input, then the type of `TCompensateInput` is the same
8
+ * as that of `TOutput`.
9
+ */
10
+ export declare class StepResponse<TOutput, TCompensateInput = TOutput> {
11
+ #private;
12
+ /**
13
+ * The constructor of the StepResponse
14
+ *
15
+ * @typeParam TOutput - The type of the output of the step.
16
+ * @typeParam TCompensateInput -
17
+ * The type of the compensation input. If the step doesn't specify any compensation input, then the type of `TCompensateInput` is the same
18
+ * as that of `TOutput`.
19
+ */
20
+ constructor(
21
+ /**
22
+ * The output of the step.
23
+ */
24
+ output?: TOutput,
25
+ /**
26
+ * The input to be passed as a parameter to the step's compensation function. If not provided, the `output` will be provided instead.
27
+ */
28
+ compensateInput?: TCompensateInput);
29
+ /**
30
+ * Creates a StepResponse that indicates that the step has failed and the retry mechanism should not kick in anymore.
31
+ *
32
+ * @param message - An optional message to be logged.
33
+ *
34
+ * @example
35
+ * import { Product } from "@8medusa/medusa"
36
+ * import {
37
+ * createStep,
38
+ * StepResponse,
39
+ * createWorkflow
40
+ * } from "@8medusa/workflows-sdk"
41
+ *
42
+ * interface CreateProductInput {
43
+ * title: string
44
+ * }
45
+ *
46
+ * export const createProductStep = createStep(
47
+ * "createProductStep",
48
+ * async function (
49
+ * input: CreateProductInput,
50
+ * context
51
+ * ) {
52
+ * const productService = context.container.resolve(
53
+ * "productService"
54
+ * )
55
+ *
56
+ * try {
57
+ * const product = await productService.createProducts(input)
58
+ * return new StepResponse({
59
+ * product
60
+ * }, {
61
+ * product_id: product.id
62
+ * })
63
+ * } catch (e) {
64
+ * return StepResponse.permanentFailure(`Couldn't create the product: ${e}`)
65
+ * }
66
+ * }
67
+ * )
68
+ *
69
+ * interface WorkflowInput {
70
+ * title: string
71
+ * }
72
+ *
73
+ * const myWorkflow = createWorkflow<
74
+ * WorkflowInput,
75
+ * Product
76
+ * >("my-workflow", (input) => {
77
+ * // Everything here will be executed and resolved later
78
+ * // during the execution. Including the data access.
79
+ *
80
+ * const product = createProductStep(input)
81
+ * }
82
+ * )
83
+ *
84
+ * myWorkflow()
85
+ * .run({
86
+ * input: {
87
+ * title: "Shirt"
88
+ * }
89
+ * })
90
+ * .then(({ errors, result }) => {
91
+ * if (errors.length) {
92
+ * errors.forEach((err) => {
93
+ * if (typeof err.error === "object" && "message" in err.error) {
94
+ * console.error(err.error.message)
95
+ * } else {
96
+ * console.error(err.error)
97
+ * }
98
+ * })
99
+ * }
100
+ * console.log(result)
101
+ * })
102
+ */
103
+ static permanentFailure(message?: string, compensateInput?: unknown): never;
104
+ static skip(): SkipStepResponse;
105
+ /**
106
+ * @internal
107
+ */
108
+ get __type(): string;
109
+ /**
110
+ * @internal
111
+ */
112
+ get output(): TOutput;
113
+ /**
114
+ * @internal
115
+ */
116
+ get compensateInput(): TCompensateInput;
117
+ /**
118
+ * @internal
119
+ */
120
+ toJSON(): {
121
+ __type: string;
122
+ output: TOutput;
123
+ compensateInput: TCompensateInput | undefined;
124
+ };
125
+ }
126
+ //# sourceMappingURL=step-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-response.d.ts","sourceRoot":"","sources":["../../../../src/utils/composer/helpers/step-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EACjB,MAAM,wBAAwB,CAAA;AAG/B;;;;;;;GAOG;AACH,qBAAa,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO;;IAK3D;;;;;;;OAOG;;IAED;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO;IAChB;;OAEG;IACH,eAAe,CAAC,EAAE,gBAAgB;IAQpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyEG;IACH,MAAM,CAAC,gBAAgB,CACrB,OAAO,SAAsB,EAC7B,eAAe,CAAC,EAAE,OAAO,GACxB,KAAK;IAOR,MAAM,CAAC,IAAI,IAAI,gBAAgB;IAI/B;;OAEG;IACH,IAAI,MAAM,WAET;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED;;OAEG;IACH,IAAI,eAAe,IAAI,gBAAgB,CAEtC;IAED;;OAEG;IACH,MAAM;;;;;CAOP"}