@colabo-flow/sa-flowchestra 0.0.0-stage → 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.
@@ -0,0 +1,678 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __esm = (fn, res) => function __init() {
5
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
6
+ };
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __decorateClass = (decorators, target, key, kind) => {
12
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
13
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
14
+ if (decorator = decorators[i])
15
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
16
+ if (kind && result) __defProp(target, key, result);
17
+ return result;
18
+ };
19
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
20
+
21
+ // src/app.controller.ts
22
+ import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from "@nestjs/common";
23
+ import { ApiTags } from "@nestjs/swagger";
24
+ import { addSecurityPrefix } from "@colabo-knalledge/i-core-services";
25
+ import { ServerData } from "@colabo-knalledge/i-core";
26
+ import { EFlowExecutionStatus } from "@colabo-flow/i-core";
27
+ var AppController;
28
+ var init_app_controller = __esm({
29
+ "src/app.controller.ts"() {
30
+ AppController = class {
31
+ constructor(appService) {
32
+ this.appService = appService;
33
+ }
34
+ accessId = 0;
35
+ getNextAccessId() {
36
+ return this.accessId++;
37
+ }
38
+ getHello() {
39
+ return this.appService.getHello();
40
+ }
41
+ async instantiateFlow(flowId, body) {
42
+ const { flowInput, flowInstancePartial } = body;
43
+ const result = await this.appService.instantiateFlow(flowId, flowInput, flowInstancePartial);
44
+ const resultServer = new ServerData(true, result, this.getNextAccessId());
45
+ const resultString = addSecurityPrefix(resultServer);
46
+ return resultString;
47
+ }
48
+ async deleteFlowInstance(flowInstanceId) {
49
+ await this.appService.deleteFlowInstance(flowInstanceId);
50
+ return new ServerData(true, `Flow instance ${flowInstanceId} deleted`, this.getNextAccessId());
51
+ }
52
+ async setFlowInstanceStatus(flowInstanceKnodeId, status) {
53
+ const result = await this.appService.setFlowInstanceStatus(flowInstanceKnodeId, status);
54
+ const resultServer = new ServerData(true, result, this.getNextAccessId());
55
+ const resultString = addSecurityPrefix(resultServer);
56
+ return resultString;
57
+ }
58
+ async depersistFlowInstance(flowInstanceKnodeId) {
59
+ return await this.appService.depersistFlowInstance(flowInstanceKnodeId);
60
+ }
61
+ async joinAgentToFlowInstance(flowInstanceKnodeId, placeId, whoAmI, agentType) {
62
+ const result = await this.appService.joinAgentToFlowInstance(flowInstanceKnodeId, placeId, whoAmI, agentType);
63
+ const resultServer = new ServerData(true, result, this.getNextAccessId());
64
+ const resultString = addSecurityPrefix(resultServer);
65
+ return resultString;
66
+ }
67
+ async getAgentTokenForFlowInstance(flowInstanceKnodeId, whoAmI) {
68
+ const result = await this.appService.getAgentTokenForFlowInstance(flowInstanceKnodeId, whoAmI);
69
+ const resultServer = new ServerData(true, result, this.getNextAccessId());
70
+ const resultString = addSecurityPrefix(resultServer);
71
+ return resultString;
72
+ }
73
+ async loadToken(tokenId) {
74
+ const result = await this.appService.loadToken(tokenId);
75
+ const resultServer = new ServerData(true, result, this.getNextAccessId());
76
+ const resultString = addSecurityPrefix(resultServer);
77
+ return resultString;
78
+ }
79
+ async loadTokens(flowInstanceId) {
80
+ const result = await this.appService.loadTokens(flowInstanceId);
81
+ const resultServer = new ServerData(true, result, this.getNextAccessId());
82
+ const resultString = addSecurityPrefix(resultServer);
83
+ return resultString;
84
+ }
85
+ async moveAllTokens(flowInstanceId, body) {
86
+ const { placeId } = body;
87
+ const result = this.appService.moveAllTokens(flowInstanceId, placeId);
88
+ const resultServer = new ServerData(true, result, this.getNextAccessId());
89
+ const resultString = addSecurityPrefix(resultServer);
90
+ return resultString;
91
+ }
92
+ async moveToken(tokenId, body) {
93
+ const { placeId } = body;
94
+ const result = this.appService.moveToken(tokenId, placeId);
95
+ const resultServer = new ServerData(true, result, this.getNextAccessId());
96
+ const resultString = addSecurityPrefix(resultServer);
97
+ return resultString;
98
+ }
99
+ async loadFlow(flowId) {
100
+ const result = this.appService.loadFlow(flowId);
101
+ const resultServer = new ServerData(true, result, this.getNextAccessId());
102
+ const resultString = addSecurityPrefix(resultServer);
103
+ return resultString;
104
+ }
105
+ async getFlow(flowId) {
106
+ return await this.appService.getFlow(flowId);
107
+ }
108
+ async loadFlows() {
109
+ return await this.appService.loadFlows();
110
+ }
111
+ async loadFlowInstances(flowId, flowInstanceId, statusesStr) {
112
+ let statuses = statusesStr?.split(",").map((status) => {
113
+ return EFlowExecutionStatus[status];
114
+ });
115
+ const result = await this.appService.loadFlowInstances(flowId, flowInstanceId, statuses);
116
+ const resultServer = new ServerData(true, result, this.getNextAccessId());
117
+ const resultString = addSecurityPrefix(resultServer);
118
+ return resultString;
119
+ }
120
+ };
121
+ __decorateClass([
122
+ Get("hello")
123
+ ], AppController.prototype, "getHello", 1);
124
+ __decorateClass([
125
+ Post("flows/:flowId/instances"),
126
+ __decorateParam(0, Param("flowId")),
127
+ __decorateParam(1, Body())
128
+ ], AppController.prototype, "instantiateFlow", 1);
129
+ __decorateClass([
130
+ Delete("flowInstances/:flowInstanceId"),
131
+ __decorateParam(0, Param("flowInstanceId"))
132
+ ], AppController.prototype, "deleteFlowInstance", 1);
133
+ __decorateClass([
134
+ Patch("flowInstances/:flowInstanceKnodeId/status"),
135
+ __decorateParam(0, Param("flowInstanceKnodeId")),
136
+ __decorateParam(1, Body("status"))
137
+ ], AppController.prototype, "setFlowInstanceStatus", 1);
138
+ __decorateClass([
139
+ Get("depersistFlowInstance/flowInstanceKnodeId/:flowInstanceKnodeId"),
140
+ __decorateParam(0, Param("flowInstanceKnodeId"))
141
+ ], AppController.prototype, "depersistFlowInstance", 1);
142
+ __decorateClass([
143
+ Get("joinAgentToFlowInstance"),
144
+ __decorateParam(0, Query("flowInstanceKnodeId")),
145
+ __decorateParam(1, Query("placeId")),
146
+ __decorateParam(2, Query("whoAmI")),
147
+ __decorateParam(3, Query("agentType"))
148
+ ], AppController.prototype, "joinAgentToFlowInstance", 1);
149
+ __decorateClass([
150
+ Get("getAgentTokenForFlowInstance"),
151
+ __decorateParam(0, Query("flowInstanceKnodeId")),
152
+ __decorateParam(1, Query("whoAmI"))
153
+ ], AppController.prototype, "getAgentTokenForFlowInstance", 1);
154
+ __decorateClass([
155
+ Get("loadToken/tokenId/:tokenId"),
156
+ __decorateParam(0, Param("tokenId"))
157
+ ], AppController.prototype, "loadToken", 1);
158
+ __decorateClass([
159
+ Get("flowInstances/:flowInstanceId/tokens"),
160
+ __decorateParam(0, Param("flowInstanceId"))
161
+ ], AppController.prototype, "loadTokens", 1);
162
+ __decorateClass([
163
+ Patch("flowInstances/:flowInstanceId/tokens/move"),
164
+ __decorateParam(0, Param("flowInstanceId")),
165
+ __decorateParam(1, Body())
166
+ ], AppController.prototype, "moveAllTokens", 1);
167
+ __decorateClass([
168
+ Patch("flowInstanceTokens/:tokenId/move"),
169
+ __decorateParam(0, Param("tokenId")),
170
+ __decorateParam(1, Body())
171
+ ], AppController.prototype, "moveToken", 1);
172
+ __decorateClass([
173
+ Get("loadFlow/flowId/:flowId"),
174
+ __decorateParam(0, Param("flowId"))
175
+ ], AppController.prototype, "loadFlow", 1);
176
+ __decorateClass([
177
+ Get("getFlow/flowId/:flowId"),
178
+ __decorateParam(0, Param("flowId"))
179
+ ], AppController.prototype, "getFlow", 1);
180
+ __decorateClass([
181
+ Get("loadFlows")
182
+ ], AppController.prototype, "loadFlows", 1);
183
+ __decorateClass([
184
+ Get("loadFlowInstances"),
185
+ __decorateParam(0, Query("flowId")),
186
+ __decorateParam(1, Query("flowInstanceId")),
187
+ __decorateParam(2, Query("statuses"))
188
+ ], AppController.prototype, "loadFlowInstances", 1);
189
+ AppController = __decorateClass([
190
+ ApiTags("flowchestrator"),
191
+ Controller("flowchestrator")
192
+ ], AppController);
193
+ }
194
+ });
195
+
196
+ // src/app.constants.ts
197
+ var APP_TITLE, APP_TITLE_VALUE;
198
+ var init_app_constants = __esm({
199
+ "src/app.constants.ts"() {
200
+ APP_TITLE = "APP_TITLE";
201
+ APP_TITLE_VALUE = "ColaboFlow.NestApp";
202
+ }
203
+ });
204
+
205
+ // src/store.provider.ts
206
+ import { useGlobalStore } from "@colabo-flow/s-go";
207
+ import { ColaboKnAllEdgeNodeServiceExtended } from "@colabo-knalledge/i-core-services";
208
+ var GLOBAL_STORE, kNodeService, useGlobalStoreOptions, GlobalStoreProvider;
209
+ var init_store_provider = __esm({
210
+ "src/store.provider.ts"() {
211
+ init_app_constants();
212
+ GLOBAL_STORE = "GLOBAL_STORE";
213
+ kNodeService = new ColaboKnAllEdgeNodeServiceExtended(
214
+ null,
215
+ null
216
+ );
217
+ useGlobalStoreOptions = {
218
+ appNameText: `${APP_TITLE_VALUE}[GlobalStore]`,
219
+ kNodeService,
220
+ useDefaultKNodeService: false
221
+ };
222
+ GlobalStoreProvider = {
223
+ provide: GLOBAL_STORE,
224
+ useValue: useGlobalStore(useGlobalStoreOptions)
225
+ };
226
+ }
227
+ });
228
+
229
+ // src/app.service.ts
230
+ import { Inject, Injectable } from "@nestjs/common";
231
+ var DEBUG_VERBOSE, AppService;
232
+ var init_app_service = __esm({
233
+ "src/app.service.ts"() {
234
+ init_store_provider();
235
+ init_app_constants();
236
+ DEBUG_VERBOSE = false;
237
+ AppService = class {
238
+ constructor(store2, appTitle) {
239
+ this.store = store2;
240
+ this.appTitle = appTitle;
241
+ }
242
+ get appNameText() {
243
+ return `${this.appTitle}[Flowchestrator-API]`;
244
+ }
245
+ getHello() {
246
+ return "Hello From Flowchestra API!";
247
+ }
248
+ /** Instantiates flow from flow (identified by flowId) by creating a flow instance
249
+ * and persisting it in the flow store.
250
+ * @param {string} flowId Flow id
251
+ * @param {any} flowInput Flow input
252
+ * @param {Partial<IFlowInstance>} flowInstancePartial Flow instance details
253
+ * @returns {string} Flow instance id
254
+ */
255
+ async instantiateFlow(flowId, flowInput, flowInstancePartial) {
256
+ const flow = await this.store.modules.flow.loadFlow(flowId);
257
+ if (DEBUG_VERBOSE) console.log(`${this.appNameText} flow loaded with flow store: ${JSON.stringify(flow, null, 4)}`);
258
+ const payload = {
259
+ flow,
260
+ flowInput,
261
+ flowInstancePartial
262
+ };
263
+ const flowInstance = await this.store.modules.flow.modules.flowchestrator.createFlowInstance(payload);
264
+ console.log(`${this.appNameText} flow instance created within flow store (id: ${flowInstance.id}, name: ${flowInstance.name})`);
265
+ const persistFlowInstancePayload = {
266
+ flowInstanceId: flowInstance.id
267
+ };
268
+ const flowInstancePersisted = await this.store.modules.flow.modules.flowchestrator.persistFlowInstance(persistFlowInstancePayload);
269
+ console.log(`${this.appNameText} flow instance persisted with flow knode ID: ${flowInstancePersisted.id}`);
270
+ return flowInstancePersisted;
271
+ }
272
+ /**
273
+ * Deletes flow instance from the persistent store
274
+ * @param flowInstanceId Flow instance id
275
+ * @returns Flow instance as JSON
276
+ */
277
+ async deleteFlowInstance(flowInstanceId) {
278
+ const payload = {
279
+ flowInstanceId
280
+ };
281
+ await this.store.modules.flow.modules.flowchestrator.deleteFlowInstance(payload);
282
+ }
283
+ /**
284
+ * Sets flow instance status
285
+ * @param flowInstanceKnodeId Flow instance knode id
286
+ * @param status Flow instance status
287
+ * @returns Flow instance as JSON
288
+ */
289
+ async setFlowInstanceStatus(flowInstanceKnodeId, status) {
290
+ const payload = {
291
+ flowInstanceKnodeId,
292
+ status
293
+ };
294
+ const finalStatus = await this.store.modules.flow.modules.flowchestrator.setFlowInstanceStatus(payload);
295
+ console.log(`${this.appNameText} flow instance status set with flow instance ID ${flowInstanceKnodeId}. status: ${finalStatus}`);
296
+ return finalStatus;
297
+ }
298
+ /**
299
+ * Retrieves flow instance from the persistent store and loads it into the flow store.
300
+ * @param flowInstanceKnodeId Flow instance knode id
301
+ * @returns Flow instance as JSON
302
+ */
303
+ async depersistFlowInstance(flowInstanceKnodeId) {
304
+ const depersistFlowInstancePayload = {
305
+ flowInstanceId: flowInstanceKnodeId
306
+ };
307
+ const flowInstance = await this.store.modules.flow.modules.flowchestrator.depersistFlowInstance(depersistFlowInstancePayload);
308
+ console.log(`${this.appNameText} flow instance depersisted with flow instance ID ${flowInstanceKnodeId}: ${JSON.stringify(flowInstance, null, 4)}`);
309
+ return flowInstance;
310
+ }
311
+ /**
312
+ * Joins flow instance by creating a new token
313
+ * @param flowInstanceKnodeId Flow instance knode id
314
+ * @param placeId Place id within the flow instance where the token is created. If undefined, the token is created in the start place of the flow instance.
315
+ * @param whoAmI agent id of the agent (represented as token) who is joining the flow instance
316
+ * @param agentType agent type (user, group, service) of the agent (represented as token) who is joining the flow instance
317
+ * @returns Token id
318
+ * TODO: Should we return the token knode id or the token id?
319
+ */
320
+ async joinAgentToFlowInstance(flowInstanceKnodeId, placeId, whoAmI, agentType) {
321
+ const payload = {
322
+ flowInstanceKnodeId,
323
+ placeId,
324
+ whoAmI,
325
+ agentType
326
+ };
327
+ const tokenId = await this.store.modules.flow.modules.flowchestrator.joinAgentToFlowInstance(payload);
328
+ return tokenId;
329
+ }
330
+ /**
331
+ * Gets agent token for flow instance
332
+ * @param flowInstanceKnodeId Flow instance knode id
333
+ * @param whoAmI agent id of the agent which presence (represented as token) in the flow instance we want to get
334
+ * @returns Token as JSON or undefined if not found
335
+ */
336
+ async getAgentTokenForFlowInstance(flowInstanceKnodeId, whoAmI) {
337
+ const payload = {
338
+ flowInstanceId: flowInstanceKnodeId,
339
+ whoAmI
340
+ };
341
+ const token = await this.store.modules.flow.modules.flowchestrator.getAgentTokenForFlowInstance(payload);
342
+ return token;
343
+ }
344
+ /**
345
+ * Loads token by ID from the persistent store into the flow store.
346
+ * @param tokenId Token id
347
+ * @returns Token as JSON
348
+ */
349
+ async loadToken(tokenId) {
350
+ const token = await this.store.modules.flow.modules.flowchestrator.loadToken(tokenId);
351
+ console.log(`${this.appNameText} token loaded: ${JSON.stringify(token, null, 4)}`);
352
+ return token;
353
+ }
354
+ /**
355
+ * Loads tokens by flow instance knode id from the persistent store
356
+ * @param flowInstanceId Flow instance id
357
+ * @returns Array of Tokens
358
+ */
359
+ async loadTokens(flowInstanceId) {
360
+ const payload = {
361
+ flowInstanceKnodeId: flowInstanceId
362
+ };
363
+ const tokens = await this.store.modules.flow.modules.flowchestrator.loadTokens(payload);
364
+ return tokens;
365
+ }
366
+ /** Moves token to a new place */
367
+ async moveToken(tokenId, placeId) {
368
+ const moveTokenPayload = {
369
+ tokenId,
370
+ placeId
371
+ };
372
+ return this.store.modules.flow.modules.flowchestrator.moveToken(moveTokenPayload);
373
+ }
374
+ /** Moves all the tokens from a flow instance to a new place */
375
+ async moveAllTokens(flowInstanceId, placeId) {
376
+ const moveAllTokensPayload = {
377
+ flowInstanceId,
378
+ placeId
379
+ };
380
+ return this.store.modules.flow.modules.flowchestrator.moveAllTokens(moveAllTokensPayload);
381
+ }
382
+ /**
383
+ * Loads Flow by ID from the persistent store into the flow store.
384
+ * @param flowId Flow id
385
+ * @returns Flow as JSON
386
+ */
387
+ async loadFlow(flowId) {
388
+ const flow = await this.store.modules.flow.loadFlow(flowId);
389
+ if (DEBUG_VERBOSE) console.log(`${this.appNameText} flow loaded with flow store: ${JSON.stringify(flow, null, 4)}`);
390
+ return flow;
391
+ }
392
+ /**
393
+ * Gets Flow by ID
394
+ * @param flowId Flow id
395
+ * @returns Flow as JSON
396
+ */
397
+ async getFlow(flowId) {
398
+ const flow = await this.store.modules.flow.getFlow(flowId);
399
+ if (DEBUG_VERBOSE) console.log(`${this.appNameText} flow loaded with flow store: ${JSON.stringify(flow, null, 4)}`);
400
+ return flow;
401
+ }
402
+ /**
403
+ * Loads and gets List of Flows
404
+ * @returns List of Flows as JSON
405
+ */
406
+ async loadFlows() {
407
+ const flows = await this.store.modules.flow.loadFlows();
408
+ flows.push({ id: "mockup-from-flowchestrator", name: "Mockup Flow (from FlowCheStrator)", tasksOrder: "sequential", tasks: [{ id: "mockup-task-a", name: "Mockup Task A", placeType: "TASK", inputPlaces: ["colabo.flow.special:event.start"], executorRef: { id: "LOCAL_TIER:mockup-task-a", environment: "ISOMORPHIC" } }, { id: "mockup-task-b", name: "Mockup Task B", placeType: "TASK", executorRef: { id: "LOCAL_TIER:mockup-task-b", environment: "ISOMORPHIC" } }] });
409
+ const flowNames = flows.map((flow) => flow.name);
410
+ console.log(`${this.appNameText} flows loaded (${flows.length} incl mockup): ${JSON.stringify(flowNames, null, 4)}`);
411
+ return flows;
412
+ }
413
+ /**
414
+ * Loads and gets List of Flow Instances
415
+ * @param flowId Flow id which instances we want to load
416
+ * @param flowInstanceNodeId Flow instance node id which we want to load
417
+ * @param statuses Optional status filter for flow instances
418
+ * @returns List of Flow Instances as JSON
419
+ */
420
+ async loadFlowInstances(flowId, flowInstanceNodeId, statuses) {
421
+ const flowInstances = await this.store.modules.flow.modules.flowchestrator.loadFlowInstances(flowId, flowInstanceNodeId, statuses);
422
+ const flowInstanceIds = flowInstances.map((flowInstance) => flowInstance.id);
423
+ if (!flowId) {
424
+ console.log(`${this.appNameText} all flow instances loaded: ${JSON.stringify(flowInstanceIds, null, 4)}`);
425
+ } else {
426
+ console.log(`${this.appNameText} flow instances loaded for flow ID ${flowId}: ${JSON.stringify(flowInstanceIds, null, 4)}`);
427
+ }
428
+ return flowInstances;
429
+ }
430
+ };
431
+ AppService = __decorateClass([
432
+ Injectable(),
433
+ __decorateParam(0, Inject(GLOBAL_STORE)),
434
+ __decorateParam(1, Inject(APP_TITLE))
435
+ ], AppService);
436
+ }
437
+ });
438
+
439
+ // src/execution/execution.controller.ts
440
+ import { Controller as Controller2, Param as Param2, Post as Post2 } from "@nestjs/common";
441
+ var ExecutionController;
442
+ var init_execution_controller = __esm({
443
+ "src/execution/execution.controller.ts"() {
444
+ ExecutionController = class {
445
+ constructor(executionService) {
446
+ this.executionService = executionService;
447
+ }
448
+ async executeFlowInstance(flowInstanceId) {
449
+ return this.executionService.executeFlowInstance(flowInstanceId);
450
+ }
451
+ };
452
+ __decorateClass([
453
+ Post2("execute/:flowInstanceId"),
454
+ __decorateParam(0, Param2("flowInstanceId"))
455
+ ], ExecutionController.prototype, "executeFlowInstance", 1);
456
+ ExecutionController = __decorateClass([
457
+ Controller2("flowchestra")
458
+ ], ExecutionController);
459
+ }
460
+ });
461
+
462
+ // src/execution/execution.service.ts
463
+ import { Injectable as Injectable2 } from "@nestjs/common";
464
+ var ExecutionService;
465
+ var init_execution_service = __esm({
466
+ "src/execution/execution.service.ts"() {
467
+ ExecutionService = class {
468
+ async executeFlowInstance(flowInstanceId, flowInput) {
469
+ console.log(`[ExecutionService] executing: ${flowInstanceId}`);
470
+ const cfCore = await import("@colabo-flow/i-core");
471
+ const store2 = globalThis.__flowchestraStore;
472
+ if (!store2) return { status: "ERROR", message: "Store not initialized" };
473
+ return { status: "STUB_WITH_STORE", flowInstanceId, storeAvailable: !!store2 };
474
+ }
475
+ };
476
+ ExecutionService = __decorateClass([
477
+ Injectable2()
478
+ ], ExecutionService);
479
+ }
480
+ });
481
+
482
+ // src/execution/execution.module.ts
483
+ import { Module } from "@nestjs/common";
484
+ var ExecutionModule;
485
+ var init_execution_module = __esm({
486
+ "src/execution/execution.module.ts"() {
487
+ init_execution_controller();
488
+ init_execution_service();
489
+ ExecutionModule = class {
490
+ };
491
+ ExecutionModule = __decorateClass([
492
+ Module({
493
+ controllers: [ExecutionController],
494
+ providers: [ExecutionService]
495
+ })
496
+ ], ExecutionModule);
497
+ }
498
+ });
499
+
500
+ // src/app.module.ts
501
+ var app_module_exports = {};
502
+ __export(app_module_exports, {
503
+ AppModule: () => AppModule
504
+ });
505
+ import { Module as Module2 } from "@nestjs/common";
506
+ var AppModule;
507
+ var init_app_module = __esm({
508
+ "src/app.module.ts"() {
509
+ init_app_controller();
510
+ init_app_service();
511
+ init_store_provider();
512
+ init_app_constants();
513
+ init_execution_module();
514
+ AppModule = class {
515
+ };
516
+ AppModule = __decorateClass([
517
+ Module2({
518
+ imports: [
519
+ // RoutesParserModule, ApiModule, PureModule
520
+ ExecutionModule
521
+ ],
522
+ controllers: [AppController],
523
+ providers: [
524
+ AppService,
525
+ GlobalStoreProvider,
526
+ { provide: APP_TITLE, useValue: APP_TITLE_VALUE }
527
+ ]
528
+ })
529
+ ], AppModule);
530
+ console.log(`[AppModule] Module loaded...`);
531
+ }
532
+ });
533
+
534
+ // src/main.ts
535
+ import "reflect-metadata";
536
+ import path from "path";
537
+ import chalk from "chalk";
538
+ import { init } from "@colabo-utils/i-config";
539
+ import express from "../../node_modules/express/index.js";
540
+
541
+ // src/bootstrap.nestjs.ts
542
+ var bootstrapNestJs = async (expressApp, portHttp2, hostname2) => {
543
+ console.log("Top server is NestJS");
544
+ const { NestFactory } = await import("@nestjs/core");
545
+ const { ExpressAdapter } = await import("@nestjs/platform-express");
546
+ const { AppModule: AppModule2 } = await Promise.resolve().then(() => (init_app_module(), app_module_exports));
547
+ const { DocumentBuilder, SwaggerModule } = await import("@nestjs/swagger");
548
+ const origins = [
549
+ "http://localhost",
550
+ "https://localhost",
551
+ "https://colabo.space"
552
+ ];
553
+ const ports = [
554
+ 3e3,
555
+ 3001,
556
+ 3050,
557
+ // FlowChestra
558
+ 3080,
559
+ // Colabo.Go!
560
+ 5050,
561
+ 443,
562
+ 5173,
563
+ 5174,
564
+ 8081
565
+ ];
566
+ const ORIGIN_PORT_PROD = "https://colabo.space:3000";
567
+ const cors = {
568
+ origin: (origin, callback) => {
569
+ const env = process.env.ENV || "DEV";
570
+ console.log("[app::index.ts] env", env);
571
+ let isOriginAllowed = false;
572
+ let isPortAllowed = false;
573
+ if (env === "PROD") {
574
+ if (origin === ORIGIN_PORT_PROD) {
575
+ isOriginAllowed = isPortAllowed = true;
576
+ }
577
+ } else {
578
+ if (env === "DEV" && !origin) {
579
+ console.log(`[app::index.ts] CORS-ALLOWED for origin='${origin}': env === "DEV" && !origin`);
580
+ return callback(null, true);
581
+ }
582
+ if (!origin) {
583
+ return callback(new Error(`Origin 'undefined' Not allowed by CORS`));
584
+ }
585
+ isOriginAllowed = origins.some(
586
+ (allowedOrigin) => origin && origin.startsWith(allowedOrigin)
587
+ );
588
+ isPortAllowed = ports.some(
589
+ (allowedPort) => origin && origin.includes(`:${allowedPort}`)
590
+ );
591
+ }
592
+ if (isOriginAllowed && isPortAllowed) {
593
+ console.log(`[app::index.ts] CORS-ALLOWED for origin='${origin}'`);
594
+ callback(null, true);
595
+ } else {
596
+ console.log(`[app::index.ts] CORS-NOT-ALLOWED for origin='${origin}': isOriginAllowed=${isOriginAllowed}; isPortAllowed=${isPortAllowed}`);
597
+ callback(new Error(`Origin '${origin}' Not allowed by CORS`));
598
+ }
599
+ }
600
+ };
601
+ const nestApplicationOptions = {
602
+ // TODO: httpsOptions,
603
+ cors
604
+ };
605
+ const nestJsApp = await NestFactory.create(AppModule2, new ExpressAdapter(expressApp), nestApplicationOptions);
606
+ const swaggerConfig = new DocumentBuilder().setTitle("Colabo").setDescription("The Colabo clean-architecture-nestJS API description").setVersion("0.1").addTag("colabo").build();
607
+ const document = SwaggerModule.createDocument(nestJsApp, swaggerConfig);
608
+ SwaggerModule.setup("api", nestJsApp, document);
609
+ if (hostname2) await nestJsApp.listen(portHttp2, hostname2);
610
+ else await nestJsApp.listen(portHttp2);
611
+ };
612
+
613
+ // src/main.ts
614
+ import "express-resource";
615
+ import { useGlobalStore as useGlobalStore2 } from "@colabo-flow/s-go";
616
+ import { ColaboKnAllEdgeNodeServiceExtended as ColaboKnAllEdgeNodeServiceExtended2 } from "@colabo-knalledge/i-core-services";
617
+ var DEBUG_VERBOSE2 = false;
618
+ console.log("process.argv: %s", JSON.stringify(process.argv));
619
+ var portHttp = parseInt(process.argv[2] || process.env.API_LISTEN_PORT || "8008");
620
+ var hostname = process.env.API_LISTEN_HOSTNAME || "0.0.0.0";
621
+ var configFilePath = process.argv[3] || "./config/global";
622
+ process.title = "ColaboFlow.Go.FlowCheStrator";
623
+ var appNameText = `[${chalk.red.bold("Colabo")}${chalk.blue.bold("Flow")}${chalk.green.bold(".Go")}${chalk.yellow.bold(".")}${chalk.blue.bold("Flow")}${chalk.blueBright.bold("Che")}${chalk.blue.bold("Strator")}]`;
624
+ console.log(`${appNameText} Starting ...`);
625
+ console.log(`${appNameText} Backend API is configuring to listen on (<host>:<port>): ${hostname}:${portHttp}"`);
626
+ var configFile;
627
+ function supportCrossOriginScript(req, res, next) {
628
+ let allowedHeaders = "Content-Type";
629
+ allowedHeaders += ", x-user-id, x-access-token";
630
+ res.header("Access-Control-Allow-Headers", allowedHeaders);
631
+ console.log("[supportCrossOriginScript] allowedHeaders: ", allowedHeaders);
632
+ res.header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT, HEAD");
633
+ res.header("Allow", "POST, GET, OPTIONS, DELETE, PUT, HEAD");
634
+ const origin = req.headers.origin;
635
+ console.log("[supportCrossOriginScript] Access-Control-Allow-Origin: %s", origin);
636
+ res.header("Access-Control-Allow-Origin", origin);
637
+ res.header("Access-Control-Allow-Credentials", true.toString());
638
+ console.log("[supportCrossOriginScript] setting up headers");
639
+ res.status(200);
640
+ next();
641
+ }
642
+ var injectEnvVariablesIntoConfig = (globalSet) => {
643
+ if (process.env["DB_CONFIG__DB_NAME"]) globalSet.dbConfig.dbName = process.env["DB_CONFIG__DB_NAME"];
644
+ if (process.env["DB_CONFIG__DOMAIN"]) globalSet.dbConfig.domain = process.env["DB_CONFIG__DOMAIN"];
645
+ if (process.env["DB_CONFIG__PORT"]) globalSet.dbConfig.port = process.env["DB_CONFIG__PORT"];
646
+ if (process.env["DB_CONFIG__USER"]) globalSet.dbConfig.user = process.env["DB_CONFIG__USER"];
647
+ if (process.env["DB_CONFIG__PASS"]) globalSet.dbConfig.pass = process.env["DB_CONFIG__PASS"];
648
+ };
649
+ var main = async () => {
650
+ const configFilePathAbs = path.resolve(process.cwd(), configFilePath);
651
+ console.log(`[${appNameText}] is importing (await import) configFilePath from "${configFilePath}" (resolved to "${configFilePathAbs}")`);
652
+ configFile = await import(configFilePathAbs);
653
+ if (DEBUG_VERBOSE2) console.log(`[${appNameText}] configFile: "${JSON.stringify(configFile, null, 4)}"`);
654
+ const globalSet = configFile.globalSet;
655
+ console.log("[Colabo.Space:index] globalSet.paths: %s", JSON.stringify(globalSet.paths));
656
+ init(globalSet);
657
+ injectEnvVariablesIntoConfig(globalSet);
658
+ const expressApp = express();
659
+ expressApp.set("port", portHttp);
660
+ expressApp.use(supportCrossOriginScript);
661
+ await bootstrapNestJs(expressApp, portHttp, hostname);
662
+ };
663
+ await main();
664
+ console.log(appNameText + " started ...");
665
+ console.log(`${appNameText} Backend API is configuring to listen on (<host>:<port>): ${hostname}:${portHttp}"`);
666
+ var kNodeService2 = new ColaboKnAllEdgeNodeServiceExtended2(
667
+ null,
668
+ null
669
+ );
670
+ var useGlobalStoreOptions2 = {
671
+ appNameText,
672
+ kNodeService: kNodeService2,
673
+ useDefaultKNodeService: false
674
+ };
675
+ var store = useGlobalStore2(useGlobalStoreOptions2);
676
+ globalThis.__flowchestraStore = store;
677
+ console.log(`${appNameText} Started`);
678
+ //# sourceMappingURL=index.js.map