@medusajs/workflow-engine-inmemory 0.0.2-next-20240124093206
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/README.md +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/initialize/index.d.ts +6 -0
- package/dist/initialize/index.d.ts.map +1 -0
- package/dist/initialize/index.js +18 -0
- package/dist/joiner-config.d.ts +8 -0
- package/dist/joiner-config.d.ts.map +1 -0
- package/dist/joiner-config.js +34 -0
- package/dist/loaders/connection.d.ts +5 -0
- package/dist/loaders/connection.d.ts.map +1 -0
- package/dist/loaders/connection.js +41 -0
- package/dist/loaders/container.d.ts +3 -0
- package/dist/loaders/container.d.ts.map +1 -0
- package/dist/loaders/container.js +33 -0
- package/dist/loaders/index.d.ts +4 -0
- package/dist/loaders/index.d.ts.map +1 -0
- package/dist/loaders/index.js +19 -0
- package/dist/loaders/utils.d.ts +5 -0
- package/dist/loaders/utils.d.ts.map +1 -0
- package/dist/loaders/utils.js +9 -0
- package/dist/migrations/Migration20231228143900.d.ts +6 -0
- package/dist/migrations/Migration20231228143900.d.ts.map +1 -0
- package/dist/migrations/Migration20231228143900.js +39 -0
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +8 -0
- package/dist/models/workflow-execution.d.ts +19 -0
- package/dist/models/workflow-execution.d.ts.map +1 -0
- package/dist/models/workflow-execution.js +97 -0
- package/dist/module-definition.d.ts +3 -0
- package/dist/module-definition.d.ts.map +1 -0
- package/dist/module-definition.js +16 -0
- package/dist/repositories/index.d.ts +3 -0
- package/dist/repositories/index.d.ts.map +1 -0
- package/dist/repositories/index.js +7 -0
- package/dist/repositories/workflow-execution.d.ts +35 -0
- package/dist/repositories/workflow-execution.d.ts.map +1 -0
- package/dist/repositories/workflow-execution.js +9 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +28 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +19 -0
- package/dist/services/workflow-execution.d.ts +16 -0
- package/dist/services/workflow-execution.d.ts.map +1 -0
- package/dist/services/workflow-execution.js +13 -0
- package/dist/services/workflow-orchestrator.d.ts +66 -0
- package/dist/services/workflow-orchestrator.d.ts.map +1 -0
- package/dist/services/workflow-orchestrator.js +352 -0
- package/dist/services/workflows-module.d.ts +43 -0
- package/dist/services/workflows-module.d.ts.map +1 -0
- package/dist/services/workflows-module.js +128 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/workflow-orchestrator-storage.d.ts +25 -0
- package/dist/utils/workflow-orchestrator-storage.d.ts.map +1 -0
- package/dist/utils/workflow-orchestrator-storage.js +135 -0
- package/package.json +59 -0
|
@@ -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("./workflow-execution"), exports);
|
|
18
|
+
__exportStar(require("./workflow-orchestrator"), exports);
|
|
19
|
+
__exportStar(require("./workflows-module"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DAL } from "@medusajs/types";
|
|
2
|
+
import { ModulesSdkUtils } from "@medusajs/utils";
|
|
3
|
+
import { WorkflowExecution } from "../models";
|
|
4
|
+
type InjectedDependencies = {
|
|
5
|
+
workflowExecutionRepository: DAL.RepositoryService;
|
|
6
|
+
};
|
|
7
|
+
declare const WorkflowExecutionService_base: new <TEntity_1 extends object = any>(container: InjectedDependencies) => ModulesSdkUtils.AbstractService<TEntity_1, InjectedDependencies, {}, {
|
|
8
|
+
list?: any;
|
|
9
|
+
listAndCount?: any;
|
|
10
|
+
}>;
|
|
11
|
+
export declare class WorkflowExecutionService<TEntity extends WorkflowExecution = WorkflowExecution> extends WorkflowExecutionService_base<TEntity> {
|
|
12
|
+
protected workflowExecutionRepository_: DAL.RepositoryService<TEntity>;
|
|
13
|
+
constructor({ workflowExecutionRepository }: InjectedDependencies);
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=workflow-execution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-execution.d.ts","sourceRoot":"","sources":["../../src/services/workflow-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAE3C,KAAK,oBAAoB,GAAG;IAC1B,2BAA2B,EAAE,GAAG,CAAC,iBAAiB,CAAA;CACnD,CAAA;;;;;AAED,qBAAa,wBAAwB,CACnC,OAAO,SAAS,iBAAiB,GAAG,iBAAiB,CACrD,SAAQ,8BAER,OAAO,CAAC;IACR,SAAS,CAAC,4BAA4B,EAAE,GAAG,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;gBAE1D,EAAE,2BAA2B,EAAE,EAAE,oBAAoB;CAKlE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkflowExecutionService = void 0;
|
|
4
|
+
const utils_1 = require("@medusajs/utils");
|
|
5
|
+
const _models_1 = require("../models");
|
|
6
|
+
class WorkflowExecutionService extends utils_1.ModulesSdkUtils.abstractServiceFactory(_models_1.WorkflowExecution) {
|
|
7
|
+
constructor({ workflowExecutionRepository }) {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.workflowExecutionRepository_ = workflowExecutionRepository;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.WorkflowExecutionService = WorkflowExecutionService;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { DistributedTransaction, DistributedTransactionEvents, TransactionStep } from "@medusajs/orchestration";
|
|
2
|
+
import { ContainerLike, Context } from "@medusajs/types";
|
|
3
|
+
import { type FlowRunOptions, ReturnWorkflow } from "@medusajs/workflows-sdk";
|
|
4
|
+
import { InMemoryDistributedTransactionStorage } from "../utils";
|
|
5
|
+
export type WorkflowOrchestratorRunOptions<T> = FlowRunOptions<T> & {
|
|
6
|
+
transactionId?: string;
|
|
7
|
+
container?: ContainerLike;
|
|
8
|
+
};
|
|
9
|
+
type RegisterStepSuccessOptions<T> = Omit<WorkflowOrchestratorRunOptions<T>, "transactionId" | "input">;
|
|
10
|
+
type IdempotencyKeyParts = {
|
|
11
|
+
workflowId: string;
|
|
12
|
+
transactionId: string;
|
|
13
|
+
stepId: string;
|
|
14
|
+
action: "invoke" | "compensate";
|
|
15
|
+
};
|
|
16
|
+
type NotifyOptions = {
|
|
17
|
+
eventType: keyof DistributedTransactionEvents;
|
|
18
|
+
workflowId: string;
|
|
19
|
+
transactionId?: string;
|
|
20
|
+
step?: TransactionStep;
|
|
21
|
+
response?: unknown;
|
|
22
|
+
result?: unknown;
|
|
23
|
+
errors?: unknown[];
|
|
24
|
+
};
|
|
25
|
+
type SubscriberHandler = {
|
|
26
|
+
(input: NotifyOptions): void;
|
|
27
|
+
} & {
|
|
28
|
+
_id?: string;
|
|
29
|
+
};
|
|
30
|
+
type SubscribeOptions = {
|
|
31
|
+
workflowId: string;
|
|
32
|
+
transactionId?: string;
|
|
33
|
+
subscriber: SubscriberHandler;
|
|
34
|
+
subscriberId?: string;
|
|
35
|
+
};
|
|
36
|
+
type UnsubscribeOptions = {
|
|
37
|
+
workflowId: string;
|
|
38
|
+
transactionId?: string;
|
|
39
|
+
subscriberOrId: string | SubscriberHandler;
|
|
40
|
+
};
|
|
41
|
+
export declare class WorkflowOrchestratorService {
|
|
42
|
+
private subscribers;
|
|
43
|
+
constructor({ inMemoryDistributedTransactionStorage, }: {
|
|
44
|
+
inMemoryDistributedTransactionStorage: InMemoryDistributedTransactionStorage;
|
|
45
|
+
workflowOrchestratorService: WorkflowOrchestratorService;
|
|
46
|
+
});
|
|
47
|
+
run<T = unknown>(workflowIdOrWorkflow: string | ReturnWorkflow<any, any, any>, options?: WorkflowOrchestratorRunOptions<T>, sharedContext?: Context): Promise<any>;
|
|
48
|
+
getRunningTransaction(workflowId: string, transactionId: string, options?: WorkflowOrchestratorRunOptions<undefined>, sharedContext?: Context): Promise<DistributedTransaction>;
|
|
49
|
+
setStepSuccess<T = unknown>({ idempotencyKey, stepResponse, options, }: {
|
|
50
|
+
idempotencyKey: string | IdempotencyKeyParts;
|
|
51
|
+
stepResponse: unknown;
|
|
52
|
+
options?: RegisterStepSuccessOptions<T>;
|
|
53
|
+
}, sharedContext?: Context): Promise<any>;
|
|
54
|
+
setStepFailure<T = unknown>({ idempotencyKey, stepResponse, options, }: {
|
|
55
|
+
idempotencyKey: string | IdempotencyKeyParts;
|
|
56
|
+
stepResponse: unknown;
|
|
57
|
+
options?: RegisterStepSuccessOptions<T>;
|
|
58
|
+
}, sharedContext?: Context): Promise<any>;
|
|
59
|
+
subscribe({ workflowId, transactionId, subscriber, subscriberId }: SubscribeOptions, sharedContext?: Context): void;
|
|
60
|
+
unsubscribe({ workflowId, transactionId, subscriberOrId }: UnsubscribeOptions, sharedContext?: Context): void;
|
|
61
|
+
private notify;
|
|
62
|
+
private buildWorkflowEvents;
|
|
63
|
+
private buildIdempotencyKeyAndParts;
|
|
64
|
+
}
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=workflow-orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-orchestrator.d.ts","sourceRoot":"","sources":["../../src/services/workflow-orchestrator.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.WorkflowOrchestratorService = void 0;
|
|
16
|
+
const orchestration_1 = require("@medusajs/orchestration");
|
|
17
|
+
const utils_1 = require("@medusajs/utils");
|
|
18
|
+
const workflows_sdk_1 = require("@medusajs/workflows-sdk");
|
|
19
|
+
const ulid_1 = require("ulid");
|
|
20
|
+
const AnySubscriber = "any";
|
|
21
|
+
class WorkflowOrchestratorService {
|
|
22
|
+
constructor({ inMemoryDistributedTransactionStorage, }) {
|
|
23
|
+
this.subscribers = new Map();
|
|
24
|
+
inMemoryDistributedTransactionStorage.setWorkflowOrchestratorService(this);
|
|
25
|
+
orchestration_1.DistributedTransaction.setStorage(inMemoryDistributedTransactionStorage);
|
|
26
|
+
}
|
|
27
|
+
async run(workflowIdOrWorkflow, options, sharedContext = {}) {
|
|
28
|
+
let { input, context, transactionId, resultFrom, throwOnError, events: eventHandlers, container, } = options ?? {};
|
|
29
|
+
const workflowId = (0, utils_1.isString)(workflowIdOrWorkflow)
|
|
30
|
+
? workflowIdOrWorkflow
|
|
31
|
+
: workflowIdOrWorkflow.getName();
|
|
32
|
+
if (!workflowId) {
|
|
33
|
+
throw new Error("Workflow ID is required");
|
|
34
|
+
}
|
|
35
|
+
context ?? (context = {});
|
|
36
|
+
context.transactionId ?? (context.transactionId = transactionId ?? (0, ulid_1.ulid)());
|
|
37
|
+
const events = this.buildWorkflowEvents({
|
|
38
|
+
customEventHandlers: eventHandlers,
|
|
39
|
+
workflowId,
|
|
40
|
+
transactionId: context.transactionId,
|
|
41
|
+
});
|
|
42
|
+
const exportedWorkflow = workflows_sdk_1.MedusaWorkflow.getWorkflow(workflowId);
|
|
43
|
+
if (!exportedWorkflow) {
|
|
44
|
+
throw new Error(`Workflow with id "${workflowId}" not found.`);
|
|
45
|
+
}
|
|
46
|
+
const flow = exportedWorkflow(container);
|
|
47
|
+
const ret = await flow.run({
|
|
48
|
+
input,
|
|
49
|
+
throwOnError,
|
|
50
|
+
resultFrom,
|
|
51
|
+
context,
|
|
52
|
+
events,
|
|
53
|
+
});
|
|
54
|
+
// TODO: temporary
|
|
55
|
+
const acknowledgement = {
|
|
56
|
+
transactionId: context.transactionId,
|
|
57
|
+
workflowId: workflowId,
|
|
58
|
+
};
|
|
59
|
+
if (ret.transaction.hasFinished()) {
|
|
60
|
+
const { result, errors } = ret;
|
|
61
|
+
this.notify({
|
|
62
|
+
eventType: "onFinish",
|
|
63
|
+
workflowId,
|
|
64
|
+
transactionId: context.transactionId,
|
|
65
|
+
result,
|
|
66
|
+
errors,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return { acknowledgement, ...ret };
|
|
70
|
+
}
|
|
71
|
+
async getRunningTransaction(workflowId, transactionId, options, sharedContext = {}) {
|
|
72
|
+
let { context, container } = options ?? {};
|
|
73
|
+
if (!workflowId) {
|
|
74
|
+
throw new Error("Workflow ID is required");
|
|
75
|
+
}
|
|
76
|
+
if (!transactionId) {
|
|
77
|
+
throw new Error("TransactionId ID is required");
|
|
78
|
+
}
|
|
79
|
+
context ?? (context = {});
|
|
80
|
+
context.transactionId ?? (context.transactionId = transactionId);
|
|
81
|
+
const exportedWorkflow = workflows_sdk_1.MedusaWorkflow.getWorkflow(workflowId);
|
|
82
|
+
if (!exportedWorkflow) {
|
|
83
|
+
throw new Error(`Workflow with id "${workflowId}" not found.`);
|
|
84
|
+
}
|
|
85
|
+
const flow = exportedWorkflow(container);
|
|
86
|
+
const transaction = await flow.getRunningTransaction(transactionId, context);
|
|
87
|
+
return transaction;
|
|
88
|
+
}
|
|
89
|
+
async setStepSuccess({ idempotencyKey, stepResponse, options, }, sharedContext = {}) {
|
|
90
|
+
const { context, throwOnError, resultFrom, container, events: eventHandlers, } = options ?? {};
|
|
91
|
+
const [idempotencyKey_, { workflowId, transactionId }] = this.buildIdempotencyKeyAndParts(idempotencyKey);
|
|
92
|
+
const exportedWorkflow = workflows_sdk_1.MedusaWorkflow.getWorkflow(workflowId);
|
|
93
|
+
if (!exportedWorkflow) {
|
|
94
|
+
throw new Error(`Workflow with id "${workflowId}" not found.`);
|
|
95
|
+
}
|
|
96
|
+
const flow = exportedWorkflow(container);
|
|
97
|
+
const events = this.buildWorkflowEvents({
|
|
98
|
+
customEventHandlers: eventHandlers,
|
|
99
|
+
transactionId,
|
|
100
|
+
workflowId,
|
|
101
|
+
});
|
|
102
|
+
const ret = await flow.registerStepSuccess({
|
|
103
|
+
idempotencyKey: idempotencyKey_,
|
|
104
|
+
context,
|
|
105
|
+
resultFrom,
|
|
106
|
+
throwOnError,
|
|
107
|
+
events,
|
|
108
|
+
response: stepResponse,
|
|
109
|
+
});
|
|
110
|
+
if (ret.transaction.hasFinished()) {
|
|
111
|
+
const { result, errors } = ret;
|
|
112
|
+
this.notify({
|
|
113
|
+
eventType: "onFinish",
|
|
114
|
+
workflowId,
|
|
115
|
+
transactionId,
|
|
116
|
+
result,
|
|
117
|
+
errors,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return ret;
|
|
121
|
+
}
|
|
122
|
+
async setStepFailure({ idempotencyKey, stepResponse, options, }, sharedContext = {}) {
|
|
123
|
+
const { context, throwOnError, resultFrom, container, events: eventHandlers, } = options ?? {};
|
|
124
|
+
const [idempotencyKey_, { workflowId, transactionId }] = this.buildIdempotencyKeyAndParts(idempotencyKey);
|
|
125
|
+
const exportedWorkflow = workflows_sdk_1.MedusaWorkflow.getWorkflow(workflowId);
|
|
126
|
+
if (!exportedWorkflow) {
|
|
127
|
+
throw new Error(`Workflow with id "${workflowId}" not found.`);
|
|
128
|
+
}
|
|
129
|
+
const flow = exportedWorkflow(container);
|
|
130
|
+
const events = this.buildWorkflowEvents({
|
|
131
|
+
customEventHandlers: eventHandlers,
|
|
132
|
+
transactionId,
|
|
133
|
+
workflowId,
|
|
134
|
+
});
|
|
135
|
+
const ret = await flow.registerStepFailure({
|
|
136
|
+
idempotencyKey: idempotencyKey_,
|
|
137
|
+
context,
|
|
138
|
+
resultFrom,
|
|
139
|
+
throwOnError,
|
|
140
|
+
events,
|
|
141
|
+
response: stepResponse,
|
|
142
|
+
});
|
|
143
|
+
if (ret.transaction.hasFinished()) {
|
|
144
|
+
const { result, errors } = ret;
|
|
145
|
+
this.notify({
|
|
146
|
+
eventType: "onFinish",
|
|
147
|
+
workflowId,
|
|
148
|
+
transactionId,
|
|
149
|
+
result,
|
|
150
|
+
errors,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return ret;
|
|
154
|
+
}
|
|
155
|
+
subscribe({ workflowId, transactionId, subscriber, subscriberId }, sharedContext = {}) {
|
|
156
|
+
subscriber._id = subscriberId;
|
|
157
|
+
const subscribers = this.subscribers.get(workflowId) ?? new Map();
|
|
158
|
+
const handlerIndex = (handlers) => {
|
|
159
|
+
return handlers.indexOf((s) => s === subscriber || s._id === subscriberId);
|
|
160
|
+
};
|
|
161
|
+
if (transactionId) {
|
|
162
|
+
const transactionSubscribers = subscribers.get(transactionId) ?? [];
|
|
163
|
+
const subscriberIndex = handlerIndex(transactionSubscribers);
|
|
164
|
+
if (subscriberIndex !== -1) {
|
|
165
|
+
transactionSubscribers.slice(subscriberIndex, 1);
|
|
166
|
+
}
|
|
167
|
+
transactionSubscribers.push(subscriber);
|
|
168
|
+
subscribers.set(transactionId, transactionSubscribers);
|
|
169
|
+
this.subscribers.set(workflowId, subscribers);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const workflowSubscribers = subscribers.get(AnySubscriber) ?? [];
|
|
173
|
+
const subscriberIndex = handlerIndex(workflowSubscribers);
|
|
174
|
+
if (subscriberIndex !== -1) {
|
|
175
|
+
workflowSubscribers.slice(subscriberIndex, 1);
|
|
176
|
+
}
|
|
177
|
+
workflowSubscribers.push(subscriber);
|
|
178
|
+
subscribers.set(AnySubscriber, workflowSubscribers);
|
|
179
|
+
this.subscribers.set(workflowId, subscribers);
|
|
180
|
+
}
|
|
181
|
+
unsubscribe({ workflowId, transactionId, subscriberOrId }, sharedContext = {}) {
|
|
182
|
+
const subscribers = this.subscribers.get(workflowId) ?? new Map();
|
|
183
|
+
const filterSubscribers = (handlers) => {
|
|
184
|
+
return handlers.filter((handler) => {
|
|
185
|
+
return handler._id
|
|
186
|
+
? handler._id !== subscriberOrId
|
|
187
|
+
: handler !== subscriberOrId;
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
if (transactionId) {
|
|
191
|
+
const transactionSubscribers = subscribers.get(transactionId) ?? [];
|
|
192
|
+
const newTransactionSubscribers = filterSubscribers(transactionSubscribers);
|
|
193
|
+
subscribers.set(transactionId, newTransactionSubscribers);
|
|
194
|
+
this.subscribers.set(workflowId, subscribers);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const workflowSubscribers = subscribers.get(AnySubscriber) ?? [];
|
|
198
|
+
const newWorkflowSubscribers = filterSubscribers(workflowSubscribers);
|
|
199
|
+
subscribers.set(AnySubscriber, newWorkflowSubscribers);
|
|
200
|
+
this.subscribers.set(workflowId, subscribers);
|
|
201
|
+
}
|
|
202
|
+
notify(options) {
|
|
203
|
+
const { eventType, workflowId, transactionId, errors, result, step, response, } = options;
|
|
204
|
+
const subscribers = this.subscribers.get(workflowId) ?? new Map();
|
|
205
|
+
const notifySubscribers = (handlers) => {
|
|
206
|
+
handlers.forEach((handler) => {
|
|
207
|
+
handler({
|
|
208
|
+
eventType,
|
|
209
|
+
workflowId,
|
|
210
|
+
transactionId,
|
|
211
|
+
step,
|
|
212
|
+
response,
|
|
213
|
+
result,
|
|
214
|
+
errors,
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
if (transactionId) {
|
|
219
|
+
const transactionSubscribers = subscribers.get(transactionId) ?? [];
|
|
220
|
+
notifySubscribers(transactionSubscribers);
|
|
221
|
+
}
|
|
222
|
+
const workflowSubscribers = subscribers.get(AnySubscriber) ?? [];
|
|
223
|
+
notifySubscribers(workflowSubscribers);
|
|
224
|
+
}
|
|
225
|
+
buildWorkflowEvents({ customEventHandlers, workflowId, transactionId, }) {
|
|
226
|
+
const notify = ({ eventType, step, result, response, errors, }) => {
|
|
227
|
+
this.notify({
|
|
228
|
+
workflowId,
|
|
229
|
+
transactionId,
|
|
230
|
+
eventType,
|
|
231
|
+
response,
|
|
232
|
+
step,
|
|
233
|
+
result,
|
|
234
|
+
errors,
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
return {
|
|
238
|
+
onTimeout: ({ transaction }) => {
|
|
239
|
+
customEventHandlers?.onTimeout?.({ transaction });
|
|
240
|
+
notify({ eventType: "onTimeout" });
|
|
241
|
+
},
|
|
242
|
+
onBegin: ({ transaction }) => {
|
|
243
|
+
customEventHandlers?.onBegin?.({ transaction });
|
|
244
|
+
notify({ eventType: "onBegin" });
|
|
245
|
+
},
|
|
246
|
+
onResume: ({ transaction }) => {
|
|
247
|
+
customEventHandlers?.onResume?.({ transaction });
|
|
248
|
+
notify({ eventType: "onResume" });
|
|
249
|
+
},
|
|
250
|
+
onCompensateBegin: ({ transaction }) => {
|
|
251
|
+
customEventHandlers?.onCompensateBegin?.({ transaction });
|
|
252
|
+
notify({ eventType: "onCompensateBegin" });
|
|
253
|
+
},
|
|
254
|
+
onFinish: ({ transaction, result, errors }) => {
|
|
255
|
+
// TODO: unsubscribe transaction handlers on finish
|
|
256
|
+
customEventHandlers?.onFinish?.({ transaction, result, errors });
|
|
257
|
+
},
|
|
258
|
+
onStepBegin: ({ step, transaction }) => {
|
|
259
|
+
customEventHandlers?.onStepBegin?.({ step, transaction });
|
|
260
|
+
notify({ eventType: "onStepBegin", step });
|
|
261
|
+
},
|
|
262
|
+
onStepSuccess: ({ step, transaction }) => {
|
|
263
|
+
const response = transaction.getContext().invoke[step.id];
|
|
264
|
+
customEventHandlers?.onStepSuccess?.({ step, transaction, response });
|
|
265
|
+
notify({ eventType: "onStepSuccess", step, response });
|
|
266
|
+
},
|
|
267
|
+
onStepFailure: ({ step, transaction }) => {
|
|
268
|
+
const errors = transaction.getErrors(orchestration_1.TransactionHandlerType.INVOKE)[step.id];
|
|
269
|
+
customEventHandlers?.onStepFailure?.({ step, transaction, errors });
|
|
270
|
+
notify({ eventType: "onStepFailure", step, errors });
|
|
271
|
+
},
|
|
272
|
+
onCompensateStepSuccess: ({ step, transaction }) => {
|
|
273
|
+
const response = transaction.getContext().compensate[step.id];
|
|
274
|
+
customEventHandlers?.onStepSuccess?.({ step, transaction, response });
|
|
275
|
+
notify({ eventType: "onCompensateStepSuccess", step, response });
|
|
276
|
+
},
|
|
277
|
+
onCompensateStepFailure: ({ step, transaction }) => {
|
|
278
|
+
const errors = transaction.getErrors(orchestration_1.TransactionHandlerType.COMPENSATE)[step.id];
|
|
279
|
+
customEventHandlers?.onStepFailure?.({ step, transaction, errors });
|
|
280
|
+
notify({ eventType: "onCompensateStepFailure", step, errors });
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
buildIdempotencyKeyAndParts(idempotencyKey) {
|
|
285
|
+
const parts = {
|
|
286
|
+
workflowId: "",
|
|
287
|
+
transactionId: "",
|
|
288
|
+
stepId: "",
|
|
289
|
+
action: "invoke",
|
|
290
|
+
};
|
|
291
|
+
let idempotencyKey_ = idempotencyKey;
|
|
292
|
+
const setParts = (workflowId, transactionId, stepId, action) => {
|
|
293
|
+
parts.workflowId = workflowId;
|
|
294
|
+
parts.transactionId = transactionId;
|
|
295
|
+
parts.stepId = stepId;
|
|
296
|
+
parts.action = action;
|
|
297
|
+
};
|
|
298
|
+
if (!(0, utils_1.isString)(idempotencyKey)) {
|
|
299
|
+
const { workflowId, transactionId, stepId, action } = idempotencyKey;
|
|
300
|
+
idempotencyKey_ = [workflowId, transactionId, stepId, action].join(":");
|
|
301
|
+
setParts(workflowId, transactionId, stepId, action);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
const [workflowId, transactionId, stepId, action] = idempotencyKey_.split(":");
|
|
305
|
+
setParts(workflowId, transactionId, stepId, action);
|
|
306
|
+
}
|
|
307
|
+
return [idempotencyKey_, parts];
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
exports.WorkflowOrchestratorService = WorkflowOrchestratorService;
|
|
311
|
+
__decorate([
|
|
312
|
+
(0, utils_1.InjectSharedContext)(),
|
|
313
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
314
|
+
__metadata("design:type", Function),
|
|
315
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
316
|
+
__metadata("design:returntype", Promise)
|
|
317
|
+
], WorkflowOrchestratorService.prototype, "run", null);
|
|
318
|
+
__decorate([
|
|
319
|
+
(0, utils_1.InjectSharedContext)(),
|
|
320
|
+
__param(3, (0, utils_1.MedusaContext)()),
|
|
321
|
+
__metadata("design:type", Function),
|
|
322
|
+
__metadata("design:paramtypes", [String, String, Object, Object]),
|
|
323
|
+
__metadata("design:returntype", Promise)
|
|
324
|
+
], WorkflowOrchestratorService.prototype, "getRunningTransaction", null);
|
|
325
|
+
__decorate([
|
|
326
|
+
(0, utils_1.InjectSharedContext)(),
|
|
327
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
328
|
+
__metadata("design:type", Function),
|
|
329
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
330
|
+
__metadata("design:returntype", Promise)
|
|
331
|
+
], WorkflowOrchestratorService.prototype, "setStepSuccess", null);
|
|
332
|
+
__decorate([
|
|
333
|
+
(0, utils_1.InjectSharedContext)(),
|
|
334
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
335
|
+
__metadata("design:type", Function),
|
|
336
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
337
|
+
__metadata("design:returntype", Promise)
|
|
338
|
+
], WorkflowOrchestratorService.prototype, "setStepFailure", null);
|
|
339
|
+
__decorate([
|
|
340
|
+
(0, utils_1.InjectSharedContext)(),
|
|
341
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
342
|
+
__metadata("design:type", Function),
|
|
343
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
344
|
+
__metadata("design:returntype", void 0)
|
|
345
|
+
], WorkflowOrchestratorService.prototype, "subscribe", null);
|
|
346
|
+
__decorate([
|
|
347
|
+
(0, utils_1.InjectSharedContext)(),
|
|
348
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
349
|
+
__metadata("design:type", Function),
|
|
350
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
351
|
+
__metadata("design:returntype", void 0)
|
|
352
|
+
], WorkflowOrchestratorService.prototype, "unsubscribe", null);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Context, DAL, FindConfig, InternalModuleDeclaration, ModuleJoinerConfig } from "@medusajs/types";
|
|
2
|
+
import type { ReturnWorkflow, UnwrapWorkflowInputDataType, WorkflowOrchestratorTypes } from "@medusajs/workflows-sdk";
|
|
3
|
+
import { WorkflowExecutionService, WorkflowOrchestratorService } from ".";
|
|
4
|
+
type InjectedDependencies = {
|
|
5
|
+
baseRepository: DAL.RepositoryService;
|
|
6
|
+
workflowExecutionService: WorkflowExecutionService;
|
|
7
|
+
workflowOrchestratorService: WorkflowOrchestratorService;
|
|
8
|
+
};
|
|
9
|
+
export declare class WorkflowsModuleService implements WorkflowOrchestratorTypes.IWorkflowsModuleService {
|
|
10
|
+
protected readonly moduleDeclaration: InternalModuleDeclaration;
|
|
11
|
+
protected baseRepository_: DAL.RepositoryService;
|
|
12
|
+
protected workflowExecutionService_: WorkflowExecutionService;
|
|
13
|
+
protected workflowOrchestratorService_: WorkflowOrchestratorService;
|
|
14
|
+
constructor({ baseRepository, workflowExecutionService, workflowOrchestratorService, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
|
|
15
|
+
__joinerConfig(): ModuleJoinerConfig;
|
|
16
|
+
listWorkflowExecution(filters?: WorkflowOrchestratorTypes.FilterableWorkflowExecutionProps, config?: FindConfig<WorkflowOrchestratorTypes.WorkflowExecutionDTO>, sharedContext?: Context): Promise<WorkflowOrchestratorTypes.WorkflowExecutionDTO[]>;
|
|
17
|
+
listAndCountWorkflowExecution(filters?: WorkflowOrchestratorTypes.FilterableWorkflowExecutionProps, config?: FindConfig<WorkflowOrchestratorTypes.WorkflowExecutionDTO>, sharedContext?: Context): Promise<[WorkflowOrchestratorTypes.WorkflowExecutionDTO[], number]>;
|
|
18
|
+
run<TWorkflow extends string | ReturnWorkflow<any, any, any>>(workflowIdOrWorkflow: TWorkflow, options?: WorkflowOrchestratorTypes.WorkflowOrchestratorRunDTO<TWorkflow extends ReturnWorkflow<any, any, any> ? UnwrapWorkflowInputDataType<TWorkflow> : unknown>, context?: Context): Promise<any>;
|
|
19
|
+
getRunningTransaction(workflowId: string, transactionId: string, context?: Context): Promise<import("@medusajs/orchestration").DistributedTransaction>;
|
|
20
|
+
setStepSuccess({ idempotencyKey, stepResponse, options, }: {
|
|
21
|
+
idempotencyKey: string | object;
|
|
22
|
+
stepResponse: unknown;
|
|
23
|
+
options?: Record<string, any>;
|
|
24
|
+
}, context?: Context): Promise<any>;
|
|
25
|
+
setStepFailure({ idempotencyKey, stepResponse, options, }: {
|
|
26
|
+
idempotencyKey: string | object;
|
|
27
|
+
stepResponse: unknown;
|
|
28
|
+
options?: Record<string, any>;
|
|
29
|
+
}, context?: Context): Promise<any>;
|
|
30
|
+
subscribe(args: {
|
|
31
|
+
workflowId: string;
|
|
32
|
+
transactionId?: string;
|
|
33
|
+
subscriber: Function;
|
|
34
|
+
subscriberId?: string;
|
|
35
|
+
}, context?: Context): Promise<void>;
|
|
36
|
+
unsubscribe(args: {
|
|
37
|
+
workflowId: string;
|
|
38
|
+
transactionId?: string;
|
|
39
|
+
subscriberOrId: string | Function;
|
|
40
|
+
}, context?: Context): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=workflows-module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflows-module.d.ts","sourceRoot":"","sources":["../../src/services/workflows-module.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var _a;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.WorkflowsModuleService = void 0;
|
|
17
|
+
const utils_1 = require("@medusajs/utils");
|
|
18
|
+
const joiner_config_1 = require("../joiner-config");
|
|
19
|
+
class WorkflowsModuleService {
|
|
20
|
+
constructor({ baseRepository, workflowExecutionService, workflowOrchestratorService, }, moduleDeclaration) {
|
|
21
|
+
this.moduleDeclaration = moduleDeclaration;
|
|
22
|
+
this.baseRepository_ = baseRepository;
|
|
23
|
+
this.workflowExecutionService_ = workflowExecutionService;
|
|
24
|
+
this.workflowOrchestratorService_ = workflowOrchestratorService;
|
|
25
|
+
}
|
|
26
|
+
__joinerConfig() {
|
|
27
|
+
return joiner_config_1.joinerConfig;
|
|
28
|
+
}
|
|
29
|
+
async listWorkflowExecution(filters = {}, config = {}, sharedContext = {}) {
|
|
30
|
+
const wfExecutions = await this.workflowExecutionService_.list(filters, config, sharedContext);
|
|
31
|
+
return this.baseRepository_.serialize(wfExecutions, {
|
|
32
|
+
populate: true,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
async listAndCountWorkflowExecution(filters = {}, config = {}, sharedContext = {}) {
|
|
36
|
+
const [wfExecutions, count] = await this.workflowExecutionService_.listAndCount(filters, config, sharedContext);
|
|
37
|
+
return [
|
|
38
|
+
await this.baseRepository_.serialize(wfExecutions, {
|
|
39
|
+
populate: true,
|
|
40
|
+
}),
|
|
41
|
+
count,
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
async run(workflowIdOrWorkflow, options = {}, context = {}) {
|
|
45
|
+
const ret = await this.workflowOrchestratorService_.run(workflowIdOrWorkflow, options, context);
|
|
46
|
+
return ret;
|
|
47
|
+
}
|
|
48
|
+
async getRunningTransaction(workflowId, transactionId, context = {}) {
|
|
49
|
+
return this.workflowOrchestratorService_.getRunningTransaction(workflowId, transactionId, context);
|
|
50
|
+
}
|
|
51
|
+
async setStepSuccess({ idempotencyKey, stepResponse, options, }, context = {}) {
|
|
52
|
+
return this.workflowOrchestratorService_.setStepSuccess({
|
|
53
|
+
idempotencyKey,
|
|
54
|
+
stepResponse,
|
|
55
|
+
options,
|
|
56
|
+
}, context);
|
|
57
|
+
}
|
|
58
|
+
async setStepFailure({ idempotencyKey, stepResponse, options, }, context = {}) {
|
|
59
|
+
return this.workflowOrchestratorService_.setStepFailure({
|
|
60
|
+
idempotencyKey,
|
|
61
|
+
stepResponse,
|
|
62
|
+
options,
|
|
63
|
+
}, context);
|
|
64
|
+
}
|
|
65
|
+
async subscribe(args, context = {}) {
|
|
66
|
+
return this.workflowOrchestratorService_.subscribe(args, context);
|
|
67
|
+
}
|
|
68
|
+
async unsubscribe(args, context = {}) {
|
|
69
|
+
return this.workflowOrchestratorService_.unsubscribe(args, context);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.WorkflowsModuleService = WorkflowsModuleService;
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, utils_1.InjectManager)("baseRepository_"),
|
|
75
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
76
|
+
__metadata("design:type", Function),
|
|
77
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
78
|
+
__metadata("design:returntype", Promise)
|
|
79
|
+
], WorkflowsModuleService.prototype, "listWorkflowExecution", null);
|
|
80
|
+
__decorate([
|
|
81
|
+
(0, utils_1.InjectManager)("baseRepository_"),
|
|
82
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
83
|
+
__metadata("design:type", Function),
|
|
84
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
85
|
+
__metadata("design:returntype", Promise)
|
|
86
|
+
], WorkflowsModuleService.prototype, "listAndCountWorkflowExecution", null);
|
|
87
|
+
__decorate([
|
|
88
|
+
(0, utils_1.InjectSharedContext)(),
|
|
89
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
90
|
+
__metadata("design:type", Function),
|
|
91
|
+
__metadata("design:paramtypes", [typeof (_a = typeof TWorkflow !== "undefined" && TWorkflow) === "function" ? _a : Object, Object, Object]),
|
|
92
|
+
__metadata("design:returntype", Promise)
|
|
93
|
+
], WorkflowsModuleService.prototype, "run", null);
|
|
94
|
+
__decorate([
|
|
95
|
+
(0, utils_1.InjectSharedContext)(),
|
|
96
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
97
|
+
__metadata("design:type", Function),
|
|
98
|
+
__metadata("design:paramtypes", [String, String, Object]),
|
|
99
|
+
__metadata("design:returntype", Promise)
|
|
100
|
+
], WorkflowsModuleService.prototype, "getRunningTransaction", null);
|
|
101
|
+
__decorate([
|
|
102
|
+
(0, utils_1.InjectSharedContext)(),
|
|
103
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
104
|
+
__metadata("design:type", Function),
|
|
105
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
106
|
+
__metadata("design:returntype", Promise)
|
|
107
|
+
], WorkflowsModuleService.prototype, "setStepSuccess", null);
|
|
108
|
+
__decorate([
|
|
109
|
+
(0, utils_1.InjectSharedContext)(),
|
|
110
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
111
|
+
__metadata("design:type", Function),
|
|
112
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
113
|
+
__metadata("design:returntype", Promise)
|
|
114
|
+
], WorkflowsModuleService.prototype, "setStepFailure", null);
|
|
115
|
+
__decorate([
|
|
116
|
+
(0, utils_1.InjectSharedContext)(),
|
|
117
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
118
|
+
__metadata("design:type", Function),
|
|
119
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
120
|
+
__metadata("design:returntype", Promise)
|
|
121
|
+
], WorkflowsModuleService.prototype, "subscribe", null);
|
|
122
|
+
__decorate([
|
|
123
|
+
(0, utils_1.InjectSharedContext)(),
|
|
124
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
125
|
+
__metadata("design:type", Function),
|
|
126
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
127
|
+
__metadata("design:returntype", Promise)
|
|
128
|
+
], WorkflowsModuleService.prototype, "unsubscribe", null);
|