@etohq/workflows-sdk 1.0.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/eto-workflow.d.ts +3 -0
  2. package/dist/eto-workflow.d.ts.map +1 -0
  3. package/dist/eto-workflow.js +19 -0
  4. package/dist/eto-workflow.js.map +1 -0
  5. package/dist/helper/index.d.ts +3 -0
  6. package/dist/helper/index.d.ts.map +1 -0
  7. package/dist/helper/index.js +19 -0
  8. package/dist/helper/index.js.map +1 -0
  9. package/dist/helper/type.d.ts +61 -0
  10. package/dist/helper/type.d.ts.map +1 -0
  11. package/dist/helper/type.js +3 -0
  12. package/dist/helper/type.js.map +1 -0
  13. package/dist/helper/workflow-export.d.ts +6 -0
  14. package/dist/helper/workflow-export.d.ts.map +1 -0
  15. package/dist/helper/workflow-export.js +250 -0
  16. package/dist/helper/workflow-export.js.map +1 -0
  17. package/dist/index.d.ts +5 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +34 -0
  20. package/dist/index.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 +74 -0
  25. package/dist/utils/_playground.js.map +1 -0
  26. package/dist/utils/composer/create-hook.d.ts +52 -0
  27. package/dist/utils/composer/create-hook.d.ts.map +1 -0
  28. package/dist/utils/composer/create-hook.js +70 -0
  29. package/dist/utils/composer/create-hook.js.map +1 -0
  30. package/dist/utils/composer/create-step.d.ts +131 -0
  31. package/dist/utils/composer/create-step.d.ts.map +1 -0
  32. package/dist/utils/composer/create-step.js +235 -0
  33. package/dist/utils/composer/create-step.js.map +1 -0
  34. package/dist/utils/composer/create-workflow.d.ts +73 -0
  35. package/dist/utils/composer/create-workflow.d.ts.map +1 -0
  36. package/dist/utils/composer/create-workflow.js +182 -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 +66 -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 +42 -0
  67. package/dist/utils/composer/parallelize.d.ts.map +1 -0
  68. package/dist/utils/composer/parallelize.js +56 -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 +214 -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 +66 -0
@@ -0,0 +1,3 @@
1
+ declare const GlobalEtoWorkflow: any;
2
+ export { GlobalEtoWorkflow as EtoWorkflow };
3
+ //# sourceMappingURL=eto-workflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eto-workflow.d.ts","sourceRoot":"","sources":["../src/eto-workflow.ts"],"names":[],"mappings":"AA8BA,QAAA,MAAM,iBAAiB,KAAqB,CAAA;AAE5C,OAAO,EAAE,iBAAiB,IAAI,WAAW,EAAE,CAAA"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EtoWorkflow = void 0;
4
+ class EtoWorkflow {
5
+ static registerWorkflow(workflowId, exportedWorkflow) {
6
+ if (workflowId in EtoWorkflow.workflows) {
7
+ return;
8
+ }
9
+ EtoWorkflow.workflows[workflowId] = exportedWorkflow;
10
+ }
11
+ static getWorkflow(workflowId) {
12
+ return EtoWorkflow.workflows[workflowId];
13
+ }
14
+ }
15
+ EtoWorkflow.workflows = {};
16
+ global.EtoWorkflow ??= EtoWorkflow;
17
+ const GlobalEtoWorkflow = global.EtoWorkflow;
18
+ exports.EtoWorkflow = GlobalEtoWorkflow;
19
+ //# sourceMappingURL=eto-workflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eto-workflow.js","sourceRoot":"","sources":["../src/eto-workflow.ts"],"names":[],"mappings":";;;AAIA,MAAM,WAAW;IAYf,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,gBAAgB;QAClD,IAAI,UAAU,IAAI,WAAW,CAAC,SAAS,EAAE,CAAC;YACxC,OAAM;QACR,CAAC;QAED,WAAW,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,gBAAgB,CAAA;IACtD,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,UAAU;QAC3B,OAAO,WAAW,CAAC,SAAS,CAAC,UAAU,CAAgC,CAAA;IACzE,CAAC;;AArBM,qBAAS,GASZ,EAAE,CAAA;AAeR,MAAM,CAAC,WAAW,KAAK,WAAW,CAAA;AAClC,MAAM,iBAAiB,GAAG,MAAM,CAAC,WAAW,CAAA;AAEd,wCAAW"}
@@ -0,0 +1,3 @@
1
+ export * from "./type";
2
+ export * from "./workflow-export";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helper/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,mBAAmB,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("./type"), exports);
18
+ __exportStar(require("./workflow-export"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helper/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAsB;AACtB,oDAAiC"}
@@ -0,0 +1,61 @@
1
+ import { DistributedTransactionEvents, DistributedTransactionType, LocalWorkflow, TransactionStepError } from "@etohq/orchestration";
2
+ import { Context, LoadedModule, EtoContainer } from "@etohq/types";
3
+ type BaseFlowRunOptions = {
4
+ context?: Context;
5
+ resultFrom?: string | string[] | Symbol;
6
+ throwOnError?: boolean;
7
+ logOnError?: boolean;
8
+ events?: DistributedTransactionEvents;
9
+ container?: LoadedModule[] | EtoContainer;
10
+ };
11
+ export type FlowRunOptions<TData = unknown> = BaseFlowRunOptions & {
12
+ input?: TData;
13
+ };
14
+ export type FlowRegisterStepSuccessOptions<TData = unknown> = BaseFlowRunOptions & {
15
+ idempotencyKey: string;
16
+ response?: TData;
17
+ };
18
+ export type FlowRegisterStepFailureOptions<TData = unknown> = BaseFlowRunOptions & {
19
+ idempotencyKey: string;
20
+ response?: TData;
21
+ };
22
+ export type FlowCancelOptions = BaseFlowRunOptions & {
23
+ transaction?: DistributedTransactionType;
24
+ transactionId?: string;
25
+ };
26
+ /**
27
+ * The details of a workflow's execution.
28
+ */
29
+ export type WorkflowResult<TResult = unknown> = {
30
+ /**
31
+ * Any errors that occured in the workflow.
32
+ */
33
+ errors: TransactionStepError[];
34
+ /**
35
+ * The transaction details of the workflow's execution.
36
+ */
37
+ transaction: DistributedTransactionType;
38
+ /**
39
+ * The result returned by the workflow.
40
+ */
41
+ result: TResult;
42
+ };
43
+ export type ExportedWorkflow<TData = unknown, TResult = unknown, TDataOverride = undefined, TResultOverride = undefined> = {
44
+ run: (args?: FlowRunOptions<TDataOverride extends undefined ? TData : TDataOverride>) => Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
45
+ registerStepSuccess: (args?: FlowRegisterStepSuccessOptions<TDataOverride extends undefined ? TData : TDataOverride>) => Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
46
+ registerStepFailure: (args?: FlowRegisterStepFailureOptions<TDataOverride extends undefined ? TData : TDataOverride>) => Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
47
+ cancel: (args?: FlowCancelOptions) => Promise<WorkflowResult>;
48
+ };
49
+ export type MainExportedWorkflow<TData = unknown, TResult = unknown> = {
50
+ <TDataOverride = undefined, TResultOverride = undefined>(container?: LoadedModule[] | EtoContainer): Omit<LocalWorkflow, "run" | "registerStepSuccess" | "registerStepFailure" | "cancel"> & ExportedWorkflow<TData, TResult, TDataOverride, TResultOverride>;
51
+ } & {
52
+ /**
53
+ * You can also directly call run, registerStepSuccess, registerStepFailure and cancel on the exported workflow
54
+ */
55
+ run<TDataOverride = undefined, TResultOverride = undefined>(args?: FlowRunOptions<TDataOverride extends undefined ? TData : TDataOverride>): Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
56
+ registerStepSuccess<TDataOverride = undefined, TResultOverride = undefined>(args?: FlowRegisterStepSuccessOptions<TDataOverride extends undefined ? TData : TDataOverride>): Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
57
+ registerStepFailure<TDataOverride = undefined, TResultOverride = undefined>(args?: FlowRegisterStepFailureOptions<TDataOverride extends undefined ? TData : TDataOverride>): Promise<WorkflowResult<TResultOverride extends undefined ? TResult : TResultOverride>>;
58
+ cancel(args?: FlowCancelOptions): Promise<WorkflowResult>;
59
+ };
60
+ export {};
61
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/helper/type.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,aAAa,EACb,oBAAoB,EACrB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,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,CAC9D,CACF,CAAA;IAED,mBAAmB,CAAC,aAAa,GAAG,SAAS,EAAE,eAAe,GAAG,SAAS,EACxE,IAAI,CAAC,EAAE,8BAA8B,CACnC,aAAa,SAAS,SAAS,GAAG,KAAK,GAAG,aAAa,CACxD,GACA,OAAO,CACR,cAAc,CACZ,eAAe,SAAS,SAAS,GAAG,OAAO,GAAG,eAAe,CAC9D,CACF,CAAA;IAED,mBAAmB,CAAC,aAAa,GAAG,SAAS,EAAE,eAAe,GAAG,SAAS,EACxE,IAAI,CAAC,EAAE,8BAA8B,CACnC,aAAa,SAAS,SAAS,GAAG,KAAK,GAAG,aAAa,CACxD,GACA,OAAO,CACR,cAAc,CACZ,eAAe,SAAS,SAAS,GAAG,OAAO,GAAG,eAAe,CAC9D,CACF,CAAA;IAED,MAAM,CAAC,IAAI,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;CAC1D,CAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/helper/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import { MainExportedWorkflow } from "./type";
2
+ export declare const exportWorkflow: <TData = unknown, TResult = unknown>(workflowId: string, defaultResult?: string | Symbol, options?: {
3
+ wrappedInput?: boolean;
4
+ sourcePath?: string;
5
+ }) => MainExportedWorkflow<TData, TResult>;
6
+ //# sourceMappingURL=workflow-export.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-export.d.ts","sourceRoot":"","sources":["../../src/helper/workflow-export.ts"],"names":[],"mappings":"AAyBA,OAAO,EAML,oBAAoB,EAErB,MAAM,QAAQ,CAAA;AA6Sf,eAAO,MAAM,cAAc,GAAI,KAAK,YAAY,OAAO,wBACzC,MAAM,kBACF,MAAM,GAAG,MAAM,YACrB;IACR,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,KACA,oBAAoB,CAAC,KAAK,EAAE,OAAO,CAwJrC,CAAA"}
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exportWorkflow = void 0;
4
+ const modules_sdk_1 = require("@etohq/modules-sdk");
5
+ const orchestration_1 = require("@etohq/orchestration");
6
+ const utils_1 = require("@etohq/utils");
7
+ const os_1 = require("os");
8
+ const ulid_1 = require("ulid");
9
+ const eto_workflow_1 = require("../eto-workflow");
10
+ const resolve_value_1 = require("../utils/composer/helpers/resolve-value");
11
+ function createContextualWorkflowRunner({ workflowId, defaultResult, options, container, }) {
12
+ const flow = new orchestration_1.LocalWorkflow(workflowId, container);
13
+ const originalRun = flow.run.bind(flow);
14
+ const originalRegisterStepSuccess = flow.registerStepSuccess.bind(flow);
15
+ const originalRegisterStepFailure = flow.registerStepFailure.bind(flow);
16
+ const originalCancel = flow.cancel.bind(flow);
17
+ const originalExecution = async (method, { throwOnError, logOnError = false, resultFrom, isCancel = false, container: executionContainer, }, transactionOrIdOrIdempotencyKey, input, context, events = {}) => {
18
+ if (!executionContainer) {
19
+ const container_ = flow.container;
20
+ if (!container_ || !(0, utils_1.isPresent)(container_?.registrations)) {
21
+ executionContainer = modules_sdk_1.EtoModule.getLoadedModules().map((mod) => Object.values(mod)[0]);
22
+ }
23
+ }
24
+ if (executionContainer) {
25
+ flow.container = executionContainer;
26
+ }
27
+ const { eventGroupId, parentStepIdempotencyKey } = context;
28
+ attachOnFinishReleaseEvents(events, flow, { logOnError });
29
+ const flowMetadata = {
30
+ eventGroupId,
31
+ parentStepIdempotencyKey,
32
+ sourcePath: options?.sourcePath,
33
+ };
34
+ const args = [
35
+ transactionOrIdOrIdempotencyKey,
36
+ input,
37
+ context,
38
+ events,
39
+ flowMetadata,
40
+ ];
41
+ const transaction = (await method.apply(method, args));
42
+ let errors = transaction.getErrors(utils_1.TransactionHandlerType.INVOKE);
43
+ const failedStatus = [orchestration_1.TransactionState.FAILED, orchestration_1.TransactionState.REVERTED];
44
+ const isCancelled = isCancel && transaction.getState() === orchestration_1.TransactionState.REVERTED;
45
+ const isRegisterStepFailure = method === originalRegisterStepFailure &&
46
+ transaction.getState() === orchestration_1.TransactionState.REVERTED;
47
+ let thrownError = null;
48
+ if (failedStatus.includes(transaction.getState()) &&
49
+ !isCancelled &&
50
+ !isRegisterStepFailure) {
51
+ const firstError = errors?.[0]?.error ?? new Error("Unknown error");
52
+ thrownError = firstError;
53
+ if (throwOnError) {
54
+ throw firstError;
55
+ }
56
+ }
57
+ let result;
58
+ if (options?.wrappedInput) {
59
+ result = (0, resolve_value_1.resolveValue)(resultFrom, transaction.getContext());
60
+ if (result instanceof Promise) {
61
+ result = await result.catch((e) => {
62
+ thrownError = e;
63
+ if (throwOnError) {
64
+ throw e;
65
+ }
66
+ errors ??= [];
67
+ errors.push(e);
68
+ });
69
+ }
70
+ }
71
+ else {
72
+ result = transaction.getContext().invoke?.[resultFrom];
73
+ }
74
+ return {
75
+ errors,
76
+ transaction,
77
+ result,
78
+ thrownError,
79
+ };
80
+ };
81
+ const newRun = async ({ input, context: outerContext, throwOnError, logOnError, resultFrom, events, container, } = {}) => {
82
+ resultFrom ??= defaultResult;
83
+ throwOnError ??= true;
84
+ logOnError ??= false;
85
+ const context = {
86
+ ...outerContext,
87
+ __type: utils_1.EtoContextType,
88
+ };
89
+ context.transactionId ??= (0, ulid_1.ulid)();
90
+ context.eventGroupId ??= (0, ulid_1.ulid)();
91
+ return await originalExecution(originalRun, {
92
+ throwOnError,
93
+ resultFrom,
94
+ container,
95
+ logOnError,
96
+ }, context.transactionId, input, context, events);
97
+ };
98
+ flow.run = newRun;
99
+ const newRegisterStepSuccess = async ({ response, idempotencyKey, context: outerContext, throwOnError, logOnError, resultFrom, events, container, } = {
100
+ idempotencyKey: "",
101
+ }) => {
102
+ idempotencyKey ??= "";
103
+ resultFrom ??= defaultResult;
104
+ throwOnError ??= true;
105
+ logOnError ??= false;
106
+ const [, transactionId] = idempotencyKey.split(":");
107
+ const context = {
108
+ ...outerContext,
109
+ transactionId,
110
+ __type: utils_1.EtoContextType,
111
+ };
112
+ context.eventGroupId ??= (0, ulid_1.ulid)();
113
+ return await originalExecution(originalRegisterStepSuccess, {
114
+ throwOnError,
115
+ resultFrom,
116
+ container,
117
+ logOnError,
118
+ }, idempotencyKey, response, context, events);
119
+ };
120
+ flow.registerStepSuccess = newRegisterStepSuccess;
121
+ const newRegisterStepFailure = async ({ response, idempotencyKey, context: outerContext, throwOnError, logOnError, resultFrom, events, container, } = {
122
+ idempotencyKey: "",
123
+ }) => {
124
+ idempotencyKey ??= "";
125
+ resultFrom ??= defaultResult;
126
+ throwOnError ??= true;
127
+ logOnError ??= false;
128
+ const [, transactionId] = idempotencyKey.split(":");
129
+ const context = {
130
+ ...outerContext,
131
+ transactionId,
132
+ __type: utils_1.EtoContextType,
133
+ };
134
+ context.eventGroupId ??= (0, ulid_1.ulid)();
135
+ return await originalExecution(originalRegisterStepFailure, {
136
+ throwOnError,
137
+ resultFrom,
138
+ container,
139
+ logOnError,
140
+ }, idempotencyKey, response, context, events);
141
+ };
142
+ flow.registerStepFailure = newRegisterStepFailure;
143
+ const newCancel = async ({ transaction, transactionId, context: outerContext, throwOnError, logOnError, events, container, } = {}) => {
144
+ throwOnError ??= true;
145
+ logOnError ??= false;
146
+ const context = {
147
+ ...outerContext,
148
+ transactionId,
149
+ __type: utils_1.EtoContextType,
150
+ };
151
+ context.eventGroupId ??= (0, ulid_1.ulid)();
152
+ return await originalExecution(originalCancel, {
153
+ throwOnError,
154
+ resultFrom: undefined,
155
+ isCancel: true,
156
+ container,
157
+ logOnError,
158
+ }, transaction ?? transactionId, undefined, context, events);
159
+ };
160
+ flow.cancel = newCancel;
161
+ return flow;
162
+ }
163
+ const exportWorkflow = (workflowId, defaultResult, options) => {
164
+ function exportedWorkflow(
165
+ // TODO: rm when all usage have been migrated
166
+ container) {
167
+ return createContextualWorkflowRunner({
168
+ workflowId,
169
+ defaultResult,
170
+ options,
171
+ container,
172
+ });
173
+ }
174
+ const buildRunnerFn = (action, container) => {
175
+ const contextualRunner = createContextualWorkflowRunner({
176
+ workflowId,
177
+ defaultResult,
178
+ options,
179
+ container,
180
+ });
181
+ return contextualRunner[action];
182
+ };
183
+ exportedWorkflow.run = async (args) => {
184
+ const container = args?.container;
185
+ delete args?.container;
186
+ const inputArgs = { ...args };
187
+ return await buildRunnerFn("run", container)(inputArgs);
188
+ };
189
+ exportedWorkflow.registerStepSuccess = async (args) => {
190
+ const container = args?.container;
191
+ delete args?.container;
192
+ const inputArgs = { ...args };
193
+ return await buildRunnerFn("registerStepSuccess", container)(inputArgs);
194
+ };
195
+ exportedWorkflow.registerStepFailure = async (args) => {
196
+ const container = args?.container;
197
+ delete args?.container;
198
+ const inputArgs = { ...args };
199
+ return await buildRunnerFn("registerStepFailure", container)(inputArgs);
200
+ };
201
+ exportedWorkflow.cancel = async (args) => {
202
+ const container = args?.container;
203
+ delete args?.container;
204
+ const inputArgs = { ...args };
205
+ return await buildRunnerFn("cancel", container)(inputArgs);
206
+ };
207
+ eto_workflow_1.EtoWorkflow.registerWorkflow(workflowId, exportedWorkflow);
208
+ return exportedWorkflow;
209
+ };
210
+ exports.exportWorkflow = exportWorkflow;
211
+ function attachOnFinishReleaseEvents(events = {}, flow, { logOnError, } = {}) {
212
+ const onFinish = events.onFinish;
213
+ const wrappedOnFinish = async (args) => {
214
+ const { transaction } = args;
215
+ const flowEventGroupId = transaction.getFlow().metadata?.eventGroupId;
216
+ const logger = flow.container.resolve(utils_1.ContainerRegistrationKeys.LOGGER, { allowUnregistered: true }) || console;
217
+ if (logOnError) {
218
+ const workflowName = transaction.getFlow().modelId;
219
+ transaction
220
+ .getErrors()
221
+ .forEach((err) => logger.error(`${workflowName}:${err?.action}:${err?.handlerType} - ${err?.error?.message}${os_1.EOL}${err?.error?.stack}`));
222
+ }
223
+ const eventBusService = flow.container.resolve(utils_1.Modules.EVENT_BUS, {
224
+ allowUnregistered: true,
225
+ });
226
+ if (!eventBusService || !flowEventGroupId) {
227
+ await onFinish?.(args);
228
+ return;
229
+ }
230
+ const failedStatus = [orchestration_1.TransactionState.FAILED, orchestration_1.TransactionState.REVERTED];
231
+ if (failedStatus.includes(transaction.getState())) {
232
+ return await eventBusService
233
+ .clearGroupedEvents(flowEventGroupId)
234
+ .catch(() => {
235
+ logger.warn(`Failed to clear events for eventGroupId - ${flowEventGroupId}`);
236
+ });
237
+ }
238
+ await eventBusService
239
+ .releaseGroupedEvents(flowEventGroupId)
240
+ .then(async () => {
241
+ await onFinish?.(args);
242
+ })
243
+ .catch((e) => {
244
+ logger.error(`Failed to release grouped events for eventGroupId: ${flowEventGroupId}`, e);
245
+ return flow.cancel(transaction);
246
+ });
247
+ };
248
+ events.onFinish = wrappedOnFinish;
249
+ }
250
+ //# sourceMappingURL=workflow-export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-export.js","sourceRoot":"","sources":["../../src/helper/workflow-export.ts"],"names":[],"mappings":";;;AAAA,oDAA8C;AAC9C,wDAK6B;AAQ7B,wCAMqB;AACrB,2BAAwB;AACxB,+BAA2B;AAC3B,kDAA6C;AAC7C,2EAAsE;AAWtE,SAAS,8BAA8B,CAKrC,EACA,UAAU,EACV,aAAa,EACb,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,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;QACN,CAAC;QAED,MAAM,eAAe;aAClB,oBAAoB,CAAC,gBAAgB,CAAC;aACtC,IAAI,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAA;QACxB,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;YACX,MAAM,CAAC,KAAK,CACV,sDAAsD,gBAAgB,EAAE,EACxE,CAAC,CACF,CAAA;YAED,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;QACjC,CAAC,CAAC,CAAA;IACN,CAAC,CAAA;IAED,MAAM,CAAC,QAAQ,GAAG,eAAe,CAAA;AACnC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "./helper";
2
+ export * from "./eto-workflow";
3
+ export * from "./utils/composer";
4
+ export * as Composer from "./utils/composer";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.Composer = void 0;
30
+ __exportStar(require("./helper"), exports);
31
+ __exportStar(require("./eto-workflow"), exports);
32
+ __exportStar(require("./utils/composer"), exports);
33
+ exports.Composer = __importStar(require("./utils/composer"));
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,iDAA8B;AAC9B,mDAAgC;AAChC,6DAA4C"}
@@ -0,0 +1 @@
1
+ {"root":["../src/eto-workflow.ts","../src/index.ts","../src/helper/index.ts","../src/helper/type.ts","../src/helper/workflow-export.ts","../src/utils/_playground.ts","../src/utils/composer/create-hook.ts","../src/utils/composer/create-step.ts","../src/utils/composer/create-workflow.ts","../src/utils/composer/index.ts","../src/utils/composer/parallelize.ts","../src/utils/composer/transform.ts","../src/utils/composer/type.ts","../src/utils/composer/when.ts","../src/utils/composer/__tests__/compose.ts","../src/utils/composer/__tests__/index.spec.ts","../src/utils/composer/helpers/create-step-handler.ts","../src/utils/composer/helpers/index.ts","../src/utils/composer/helpers/proxy.ts","../src/utils/composer/helpers/resolve-value.ts","../src/utils/composer/helpers/step-response.ts","../src/utils/composer/helpers/workflow-response.ts"],"version":"5.6.2"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=_playground.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_playground.d.ts","sourceRoot":"","sources":["../../src/utils/_playground.ts"],"names":[],"mappings":""}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const composer_1 = require("./composer");
4
+ const create_hook_1 = require("./composer/create-hook");
5
+ const workflow_response_1 = require("./composer/helpers/workflow-response");
6
+ const step1 = (0, composer_1.createStep)("step1", async (input, context) => {
7
+ return new composer_1.StepResponse({ step1: "step1" });
8
+ });
9
+ const step2 = (0, composer_1.createStep)("step2", async (input, context) => {
10
+ return new composer_1.StepResponse({ step2: input });
11
+ });
12
+ const step3 = (0, composer_1.createStep)("step3", async () => {
13
+ return new composer_1.StepResponse({ step3: "step3" });
14
+ });
15
+ const workflow = (0, composer_1.createWorkflow)("sub-workflow", function (input) {
16
+ step1();
17
+ step2({ filters: { id: [] } });
18
+ const somethingHook = (0, create_hook_1.createHook)("something", { id: "1" });
19
+ step3();
20
+ return new workflow_response_1.WorkflowResponse({ id: 1 }, { hooks: [somethingHook] });
21
+ });
22
+ workflow.hooks.something((input, context) => {
23
+ console.log("input>", input);
24
+ console.log("context>", context);
25
+ });
26
+ workflow.run().then((res) => {
27
+ console.log("res", res);
28
+ });
29
+ /*const workflow2 = createWorkflow("workflow", function () {
30
+ const step1Res = step1()
31
+
32
+ const step3Res = when({ value: true }, ({ value }) => {
33
+ return value
34
+ }).then(() => {
35
+ return step3()
36
+ })
37
+
38
+ transform({ step3Res }, ({ step3Res }) => {
39
+ console.log(step3Res)
40
+ })
41
+
42
+ const workflowRes = workflow.asStep({ outsideWorkflowData: step1Res.step1 })
43
+
44
+ return workflowRes
45
+ })*/
46
+ // workflow()
47
+ // .run({})
48
+ // .then((res) => {
49
+ // console.log(res.result)
50
+ // })
51
+ /*const step1 = createStep("step1", async (input: {}, context) => {
52
+ return new StepResponse({ step1: ["step1"] })
53
+ })
54
+
55
+ const step2 = createStep("step2", async (input: string[], context) => {
56
+ return new StepResponse({ step2: input })
57
+ })
58
+
59
+ const step3 = createStep("step3", async () => {
60
+ return new StepResponse({ step3: "step3" })
61
+ })
62
+
63
+ const workflow = createWorkflow("workflow", function () {
64
+ const step1Res = step1()
65
+ step3()
66
+ return step2(step1Res.step1)
67
+ })
68
+
69
+ workflow()
70
+ .run({})
71
+ .then((res) => {
72
+ console.log(res.result)
73
+ })*/
74
+ //# sourceMappingURL=_playground.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_playground.js","sourceRoot":"","sources":["../../src/utils/_playground.ts"],"names":[],"mappings":";;AAAA,yCAKmB;AACnB,wDAAmD;AACnD,4EAAuE;AAEvE,MAAM,KAAK,GAAG,IAAA,qBAAU,EAAC,OAAO,EAAE,KAAK,EAAE,KAAS,EAAE,OAAO,EAAE,EAAE;IAC7D,OAAO,IAAI,uBAAY,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAA;AAC7C,CAAC,CAAC,CAAA;AAGF,MAAM,KAAK,GAAG,IAAA,qBAAU,EAAC,OAAO,EAAE,KAAK,EAAE,KAAiB,EAAE,OAAO,EAAE,EAAE;IACrE,OAAO,IAAI,uBAAY,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;AAC3C,CAAC,CAAC,CAAA;AAEF,MAAM,KAAK,GAAG,IAAA,qBAAU,EAAC,OAAO,EAAE,KAAK,IAAI,EAAE;IAC3C,OAAO,IAAI,uBAAY,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAA;AAC7C,CAAC,CAAC,CAAA;AAEF,MAAM,QAAQ,GAAG,IAAA,yBAAc,EAC7B,cAAc,EACd,UAAU,KAAoD;IAC5D,KAAK,EAAE,CAAA;IACP,KAAK,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;IAC9B,MAAM,aAAa,GAAG,IAAA,wBAAU,EAAC,WAAW,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAA;IAC1D,KAAK,EAAE,CAAA;IACP,OAAO,IAAI,oCAAgB,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,CAAA;AACpE,CAAC,CACF,CAAA;AAED,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IAC1C,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;IAC5B,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;AAClC,CAAC,CAAC,CAAA;AAEF,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;IAC1B,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AACzB,CAAC,CAAC,CAAA;AAEF;;;;;;;;;;;;;;;;IAgBI;AAEJ,aAAa;AACb,aAAa;AACb,qBAAqB;AACrB,8BAA8B;AAC9B,OAAO;AAEP;;;;;;;;;;;;;;;;;;;;;;MAsBM"}
@@ -0,0 +1,52 @@
1
+ import { OrchestrationUtils } from "@etohq/utils";
2
+ /**
3
+ * Representation of a hook definition.
4
+ */
5
+ export type Hook<Name extends string, Input> = {
6
+ __type: typeof OrchestrationUtils.SymbolWorkflowHook;
7
+ name: Name;
8
+ /**
9
+ * By prefixing a key with a space, we remove it from the
10
+ * intellisense of TypeScript. This is needed because
11
+ * input is not set at runtime. It is a type-only
12
+ * property to infer input data type of a hook
13
+ */
14
+ " input": Input;
15
+ };
16
+ /**
17
+ * Expose a hook in your workflow where you can inject custom functionality as a step function.
18
+ *
19
+ * A handler hook can later be registered to consume the hook and perform custom functionality.
20
+ *
21
+ * Learn more in [this documentation](https://docs.etohq.com/learn/fundamentals/workflows/workflow-hooks).
22
+ *
23
+ * @param name - The hook's name. This is used when the hook handler is registered to consume the workflow.
24
+ * @param input - The input to pass to the hook handler.
25
+ * @returns A workflow hook.
26
+ *
27
+ * @example
28
+ * import {
29
+ * createStep,
30
+ * createHook,
31
+ * createWorkflow,
32
+ * WorkflowResponse,
33
+ * } from "@etohq/framework/workflows-sdk"
34
+ * import { createProductStep } from "./steps/create-product"
35
+ *
36
+ * export const myWorkflow = createWorkflow(
37
+ * "my-workflow",
38
+ * function (input) {
39
+ * const product = createProductStep(input)
40
+ * const productCreatedHook = createHook(
41
+ * "productCreated",
42
+ * { productId: product.id }
43
+ * )
44
+ *
45
+ * return new WorkflowResponse(product, {
46
+ * hooks: [productCreatedHook],
47
+ * })
48
+ * }
49
+ * )
50
+ */
51
+ export declare function createHook<Name extends string, TInvokeInput>(name: Name, input: TInvokeInput): Hook<Name, TInvokeInput>;
52
+ //# sourceMappingURL=create-hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-hook.d.ts","sourceRoot":"","sources":["../../../src/utils/composer/create-hook.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAIjD;;GAEG;AACH,MAAM,MAAM,IAAI,CAAC,IAAI,SAAS,MAAM,EAAE,KAAK,IAAI;IAC7C,MAAM,EAAE,OAAO,kBAAkB,CAAC,kBAAkB,CAAA;IACpD,IAAI,EAAE,IAAI,CAAA;IACV;;;;;OAKG;IACH,QAAQ,EAAE,KAAK,CAAA;CAChB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,UAAU,CAAC,IAAI,SAAS,MAAM,EAAE,YAAY,EAC1D,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,YAAY,GAClB,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CA2C1B"}