@nodestackapp/server 2.5.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -28
- package/dist/NodeStack.d.ts +5 -1
- package/dist/NodeStack.d.ts.map +1 -1
- package/dist/NodeStack.js +117 -18
- package/dist/NodeStack.js.map +1 -1
- package/dist/admin/AdminUIBundler.d.ts.map +1 -1
- package/dist/admin/AdminUIBundler.js +2 -0
- package/dist/admin/AdminUIBundler.js.map +1 -1
- package/dist/admin/ui/css/main.css +40 -3
- package/dist/admin/ui/css/webhooks.css +8 -0
- package/dist/admin/ui/index.html +21479 -17251
- package/dist/admin/ui/js/api-keys.js +1381 -0
- package/dist/admin/ui/js/api.js +8 -0
- package/dist/admin/ui/js/app.js +698 -641
- package/dist/admin/ui/js/apps.js +514 -489
- package/dist/admin/ui/js/collections.js +486 -484
- package/dist/admin/ui/js/command-palette.js +693 -673
- package/dist/admin/ui/js/cron.js +1706 -0
- package/dist/admin/ui/js/database.js +10 -0
- package/dist/admin/ui/js/flows-designer.js +1219 -1076
- package/dist/admin/ui/js/flows.js +947 -890
- package/dist/admin/ui/js/functions-tester.js +1 -1
- package/dist/admin/ui/js/functions-workbench.js +1162 -1101
- package/dist/admin/ui/js/functions.js +983 -979
- package/dist/admin/ui/js/rules.js +1080 -775
- package/dist/admin/ui/js/schema.js +346 -304
- package/dist/admin/ui/js/snapshots.js +338 -0
- package/dist/admin/ui/js/views.js +1 -1
- package/dist/apps/AppManager.d.ts +1 -1
- package/dist/apps/AppManager.d.ts.map +1 -1
- package/dist/apps/AppManager.js +11 -21
- package/dist/apps/AppManager.js.map +1 -1
- package/dist/apps/AppRegistry.d.ts +1 -0
- package/dist/apps/AppRegistry.d.ts.map +1 -1
- package/dist/apps/AppRegistry.js +78 -23
- package/dist/apps/AppRegistry.js.map +1 -1
- package/dist/apps/AppScope.d.ts +2 -1
- package/dist/apps/AppScope.d.ts.map +1 -1
- package/dist/apps/AppScope.js +27 -17
- package/dist/apps/AppScope.js.map +1 -1
- package/dist/auth/ApiKeyService.d.ts +63 -2
- package/dist/auth/ApiKeyService.d.ts.map +1 -1
- package/dist/auth/ApiKeyService.js +518 -8
- package/dist/auth/ApiKeyService.js.map +1 -1
- package/dist/auth/AuthService.d.ts +30 -1
- package/dist/auth/AuthService.d.ts.map +1 -1
- package/dist/auth/AuthService.js +468 -65
- package/dist/auth/AuthService.js.map +1 -1
- package/dist/auth/oauth/AppleProvider.d.ts +2 -0
- package/dist/auth/oauth/AppleProvider.d.ts.map +1 -1
- package/dist/auth/oauth/AppleProvider.js +40 -3
- package/dist/auth/oauth/AppleProvider.js.map +1 -1
- package/dist/auth/oauth/BaseOAuthProvider.d.ts +3 -2
- package/dist/auth/oauth/BaseOAuthProvider.d.ts.map +1 -1
- package/dist/auth/oauth/BaseOAuthProvider.js +29 -3
- package/dist/auth/oauth/BaseOAuthProvider.js.map +1 -1
- package/dist/auth/oauth/DiscordProvider.d.ts.map +1 -1
- package/dist/auth/oauth/DiscordProvider.js +4 -1
- package/dist/auth/oauth/DiscordProvider.js.map +1 -1
- package/dist/auth/oauth/GitHubProvider.d.ts.map +1 -1
- package/dist/auth/oauth/GitHubProvider.js +4 -1
- package/dist/auth/oauth/GitHubProvider.js.map +1 -1
- package/dist/auth/oauth/GoogleProvider.d.ts.map +1 -1
- package/dist/auth/oauth/GoogleProvider.js +4 -1
- package/dist/auth/oauth/GoogleProvider.js.map +1 -1
- package/dist/auth/oauth/MicrosoftProvider.d.ts.map +1 -1
- package/dist/auth/oauth/MicrosoftProvider.js +4 -1
- package/dist/auth/oauth/MicrosoftProvider.js.map +1 -1
- package/dist/auth/oauth/OAuthProviderRegistry.d.ts +6 -2
- package/dist/auth/oauth/OAuthProviderRegistry.d.ts.map +1 -1
- package/dist/auth/oauth/OAuthProviderRegistry.js +25 -10
- package/dist/auth/oauth/OAuthProviderRegistry.js.map +1 -1
- package/dist/auth/oauth/types.d.ts +4 -2
- package/dist/auth/oauth/types.d.ts.map +1 -1
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +228 -12
- package/dist/cli/cli.js.map +1 -1
- package/dist/core/config/ConfigService.d.ts.map +1 -1
- package/dist/core/config/ConfigService.js +5 -3
- package/dist/core/config/ConfigService.js.map +1 -1
- package/dist/core/config/EnvLoader.d.ts +14 -0
- package/dist/core/config/EnvLoader.d.ts.map +1 -1
- package/dist/core/config/EnvLoader.js +44 -0
- package/dist/core/config/EnvLoader.js.map +1 -1
- package/dist/core/container/Container.d.ts +14 -0
- package/dist/core/container/Container.d.ts.map +1 -1
- package/dist/core/container/Container.js +32 -0
- package/dist/core/container/Container.js.map +1 -1
- package/dist/core/container/Tokens.d.ts +2 -0
- package/dist/core/container/Tokens.d.ts.map +1 -1
- package/dist/core/container/Tokens.js +2 -0
- package/dist/core/container/Tokens.js.map +1 -1
- package/dist/core/errors/AppError.d.ts +7 -7
- package/dist/core/errors/AppError.d.ts.map +1 -1
- package/dist/core/errors/AppError.js +18 -14
- package/dist/core/errors/AppError.js.map +1 -1
- package/dist/core/events/EventBus.d.ts.map +1 -1
- package/dist/core/events/EventBus.js +36 -6
- package/dist/core/events/EventBus.js.map +1 -1
- package/dist/core/maintenance/MaintenanceGate.d.ts +47 -0
- package/dist/core/maintenance/MaintenanceGate.d.ts.map +1 -1
- package/dist/core/maintenance/MaintenanceGate.js +265 -7
- package/dist/core/maintenance/MaintenanceGate.js.map +1 -1
- package/dist/core/plugins/PluginManager.d.ts +20 -1
- package/dist/core/plugins/PluginManager.d.ts.map +1 -1
- package/dist/core/plugins/PluginManager.js +231 -146
- package/dist/core/plugins/PluginManager.js.map +1 -1
- package/dist/core/plugins/types.d.ts +48 -31
- package/dist/core/plugins/types.d.ts.map +1 -1
- package/dist/cron/CronParser.d.ts +83 -0
- package/dist/cron/CronParser.d.ts.map +1 -0
- package/dist/cron/CronParser.js +538 -0
- package/dist/cron/CronParser.js.map +1 -0
- package/dist/cron/CronService.d.ts +74 -0
- package/dist/cron/CronService.d.ts.map +1 -0
- package/dist/cron/CronService.js +1254 -0
- package/dist/cron/CronService.js.map +1 -0
- package/dist/cron/types.d.ts +98 -0
- package/dist/cron/types.d.ts.map +1 -0
- package/dist/cron/types.js +3 -0
- package/dist/cron/types.js.map +1 -0
- package/dist/database/DatabaseService.d.ts +4 -1
- package/dist/database/DatabaseService.d.ts.map +1 -1
- package/dist/database/DatabaseService.js +34 -9
- package/dist/database/DatabaseService.js.map +1 -1
- package/dist/database/config/DatabaseConfigService.d.ts +1 -0
- package/dist/database/config/DatabaseConfigService.d.ts.map +1 -1
- package/dist/database/config/DatabaseConfigService.js +4 -2
- package/dist/database/config/DatabaseConfigService.js.map +1 -1
- package/dist/database/drivers/DriverPackageLoader.d.ts +11 -0
- package/dist/database/drivers/DriverPackageLoader.d.ts.map +1 -0
- package/dist/database/drivers/DriverPackageLoader.js +112 -0
- package/dist/database/drivers/DriverPackageLoader.js.map +1 -0
- package/dist/database/drivers/DriverRegistry.d.ts +1 -0
- package/dist/database/drivers/DriverRegistry.d.ts.map +1 -1
- package/dist/database/drivers/DriverRegistry.js +29 -0
- package/dist/database/drivers/DriverRegistry.js.map +1 -1
- package/dist/database/drivers/IDatabaseDriver.d.ts +1 -0
- package/dist/database/drivers/IDatabaseDriver.d.ts.map +1 -1
- package/dist/database/drivers/MssqlDriver.d.ts.map +1 -1
- package/dist/database/drivers/MssqlDriver.js +10 -5
- package/dist/database/drivers/MssqlDriver.js.map +1 -1
- package/dist/database/drivers/NodeSqliteDriver.d.ts.map +1 -1
- package/dist/database/drivers/NodeSqliteDriver.js +15 -1
- package/dist/database/drivers/NodeSqliteDriver.js.map +1 -1
- package/dist/database/drivers/PostgresDriver.d.ts.map +1 -1
- package/dist/database/drivers/PostgresDriver.js +4 -5
- package/dist/database/drivers/PostgresDriver.js.map +1 -1
- package/dist/database/migration/DatabaseMigrationService.d.ts +1 -0
- package/dist/database/migration/DatabaseMigrationService.d.ts.map +1 -1
- package/dist/database/migration/DatabaseMigrationService.js +51 -0
- package/dist/database/migration/DatabaseMigrationService.js.map +1 -1
- package/dist/database/migrations/SystemMigrations.d.ts.map +1 -1
- package/dist/database/migrations/SystemMigrations.js +200 -5
- package/dist/database/migrations/SystemMigrations.js.map +1 -1
- package/dist/flows/FlowEngine.js.map +1 -1
- package/dist/flows/FlowService.d.ts +10 -1
- package/dist/flows/FlowService.d.ts.map +1 -1
- package/dist/flows/FlowService.js +227 -14
- package/dist/flows/FlowService.js.map +1 -1
- package/dist/flows/FlowValidator.d.ts +2 -1
- package/dist/flows/FlowValidator.d.ts.map +1 -1
- package/dist/flows/FlowValidator.js +89 -4
- package/dist/flows/FlowValidator.js.map +1 -1
- package/dist/flows/types.d.ts +20 -3
- package/dist/flows/types.d.ts.map +1 -1
- package/dist/functions/FunctionService.d.ts +10 -2
- package/dist/functions/FunctionService.d.ts.map +1 -1
- package/dist/functions/FunctionService.js +271 -37
- package/dist/functions/FunctionService.js.map +1 -1
- package/dist/functions/runtime/QuickJsWasmRuntime.d.ts.map +1 -1
- package/dist/functions/runtime/QuickJsWasmRuntime.js +189 -177
- package/dist/functions/runtime/QuickJsWasmRuntime.js.map +1 -1
- package/dist/functions/types.d.ts +31 -2
- package/dist/functions/types.d.ts.map +1 -1
- package/dist/http/HttpServer.d.ts +7 -1
- package/dist/http/HttpServer.d.ts.map +1 -1
- package/dist/http/HttpServer.js +187 -8
- package/dist/http/HttpServer.js.map +1 -1
- package/dist/http/controllers/ApiKeyController.d.ts +1 -0
- package/dist/http/controllers/ApiKeyController.d.ts.map +1 -1
- package/dist/http/controllers/ApiKeyController.js +47 -1
- package/dist/http/controllers/ApiKeyController.js.map +1 -1
- package/dist/http/controllers/AuthController.d.ts +12 -0
- package/dist/http/controllers/AuthController.d.ts.map +1 -1
- package/dist/http/controllers/AuthController.js +40 -2
- package/dist/http/controllers/AuthController.js.map +1 -1
- package/dist/http/controllers/CronController.d.ts +63 -0
- package/dist/http/controllers/CronController.d.ts.map +1 -0
- package/dist/http/controllers/CronController.js +92 -0
- package/dist/http/controllers/CronController.js.map +1 -0
- package/dist/http/controllers/DatabaseController.d.ts.map +1 -1
- package/dist/http/controllers/DatabaseController.js +53 -0
- package/dist/http/controllers/DatabaseController.js.map +1 -1
- package/dist/http/controllers/FlowController.d.ts.map +1 -1
- package/dist/http/controllers/FlowController.js +45 -4
- package/dist/http/controllers/FlowController.js.map +1 -1
- package/dist/http/controllers/FunctionController.d.ts.map +1 -1
- package/dist/http/controllers/FunctionController.js +16 -2
- package/dist/http/controllers/FunctionController.js.map +1 -1
- package/dist/http/controllers/HealthController.js +2 -2
- package/dist/http/middleware/AppResolutionMiddleware.d.ts +1 -1
- package/dist/http/middleware/AppResolutionMiddleware.d.ts.map +1 -1
- package/dist/http/middleware/AppResolutionMiddleware.js +2 -3
- package/dist/http/middleware/AppResolutionMiddleware.js.map +1 -1
- package/dist/http/middleware/AuthMiddleware.d.ts.map +1 -1
- package/dist/http/middleware/AuthMiddleware.js +6 -3
- package/dist/http/middleware/AuthMiddleware.js.map +1 -1
- package/dist/http/middleware/ChaosMiddleware.js +6 -6
- package/dist/http/middleware/ChaosMiddleware.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/queue/QueueService.d.ts +9 -0
- package/dist/queue/QueueService.d.ts.map +1 -1
- package/dist/queue/QueueService.js +143 -60
- package/dist/queue/QueueService.js.map +1 -1
- package/dist/queue/drivers/SqliteQueueDriver.d.ts +3 -0
- package/dist/queue/drivers/SqliteQueueDriver.d.ts.map +1 -1
- package/dist/queue/drivers/SqliteQueueDriver.js +315 -255
- package/dist/queue/drivers/SqliteQueueDriver.js.map +1 -1
- package/dist/records/FtsService.d.ts +7 -3
- package/dist/records/FtsService.d.ts.map +1 -1
- package/dist/records/FtsService.js +69 -5
- package/dist/records/FtsService.js.map +1 -1
- package/dist/records/QueryFilterParser.d.ts.map +1 -1
- package/dist/records/QueryFilterParser.js +58 -20
- package/dist/records/QueryFilterParser.js.map +1 -1
- package/dist/records/RecordSanitizer.d.ts.map +1 -1
- package/dist/records/RecordSanitizer.js +32 -4
- package/dist/records/RecordSanitizer.js.map +1 -1
- package/dist/records/RecordService.d.ts +6 -0
- package/dist/records/RecordService.d.ts.map +1 -1
- package/dist/records/RecordService.js +95 -14
- package/dist/records/RecordService.js.map +1 -1
- package/dist/records/RecordValidator.d.ts +10 -0
- package/dist/records/RecordValidator.d.ts.map +1 -1
- package/dist/records/RecordValidator.js +110 -2
- package/dist/records/RecordValidator.js.map +1 -1
- package/dist/records/fts/IFtsDriver.d.ts +7 -6
- package/dist/records/fts/IFtsDriver.d.ts.map +1 -1
- package/dist/records/fts/MssqlFtsDriver.d.ts +5 -1
- package/dist/records/fts/MssqlFtsDriver.d.ts.map +1 -1
- package/dist/records/fts/MssqlFtsDriver.js +35 -3
- package/dist/records/fts/MssqlFtsDriver.js.map +1 -1
- package/dist/records/fts/PostgresFtsDriver.d.ts +9 -2
- package/dist/records/fts/PostgresFtsDriver.d.ts.map +1 -1
- package/dist/records/fts/PostgresFtsDriver.js +116 -11
- package/dist/records/fts/PostgresFtsDriver.js.map +1 -1
- package/dist/records/fts/SqliteFts5Driver.d.ts +7 -1
- package/dist/records/fts/SqliteFts5Driver.d.ts.map +1 -1
- package/dist/records/fts/SqliteFts5Driver.js +66 -6
- package/dist/records/fts/SqliteFts5Driver.js.map +1 -1
- package/dist/schema/OpenApiGenerator.d.ts.map +1 -1
- package/dist/schema/OpenApiGenerator.js +103 -3
- package/dist/schema/OpenApiGenerator.js.map +1 -1
- package/dist/schema/models/Field.d.ts +1 -0
- package/dist/schema/models/Field.d.ts.map +1 -1
- package/dist/snapshots/SnapshotService.d.ts.map +1 -1
- package/dist/snapshots/SnapshotService.js +21 -9
- package/dist/snapshots/SnapshotService.js.map +1 -1
- package/dist/snapshots/drivers/LogicalSnapshotDriver.d.ts.map +1 -1
- package/dist/snapshots/drivers/LogicalSnapshotDriver.js +2 -0
- package/dist/snapshots/drivers/LogicalSnapshotDriver.js.map +1 -1
- package/dist/templates/definitions/ecommerce.js +6 -6
- package/dist/templates/definitions/ecommerce.js.map +1 -1
- package/dist/webhooks/WebhookService.js +1 -1
- package/package.json +5 -3
|
@@ -33,20 +33,25 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.FlowService = void 0;
|
|
36
|
+
exports.FlowService = exports.ALLOWED_FLOW_AUTH_POLICIES = void 0;
|
|
37
37
|
const crypto = __importStar(require("crypto"));
|
|
38
38
|
const FlowEngine_1 = require("./FlowEngine");
|
|
39
39
|
const FlowValidator_1 = require("./FlowValidator");
|
|
40
40
|
const ChoiceEvaluator_1 = require("./runtime/ChoiceEvaluator");
|
|
41
41
|
const AppError_1 = require("../core/errors/AppError");
|
|
42
|
+
const RuleEngine_1 = require("../rules/RuleEngine");
|
|
43
|
+
const ApiKeyService_1 = require("../auth/ApiKeyService");
|
|
44
|
+
exports.ALLOWED_FLOW_AUTH_POLICIES = ['public', 'auth', 'admin', 'apiKey', 'custom'];
|
|
42
45
|
class FlowService {
|
|
43
46
|
db;
|
|
44
47
|
functionService;
|
|
45
48
|
eventBus;
|
|
46
49
|
appScope;
|
|
47
50
|
engine;
|
|
51
|
+
ruleEngine;
|
|
48
52
|
recoveryStrategy;
|
|
49
53
|
queueService;
|
|
54
|
+
cronService;
|
|
50
55
|
activeAbortControllers = new Map();
|
|
51
56
|
activeExecutionClaims = new Set();
|
|
52
57
|
pendingExecutionAdmissions = new Set();
|
|
@@ -65,8 +70,10 @@ class FlowService {
|
|
|
65
70
|
this.eventBus = eventBus;
|
|
66
71
|
this.appScope = appScope;
|
|
67
72
|
this.engine = options.engine || new FlowEngine_1.FlowEngine();
|
|
73
|
+
this.ruleEngine = new RuleEngine_1.RuleEngine();
|
|
68
74
|
this.recoveryStrategy = options.recoveryStrategy || process.env.FLOW_RECOVERY_STRATEGY || 'abort';
|
|
69
75
|
this.queueService = options.queueService;
|
|
76
|
+
this.cronService = options.cronService;
|
|
70
77
|
this.initTables();
|
|
71
78
|
this.bindEvents();
|
|
72
79
|
this.syncAllFlowQueues();
|
|
@@ -76,6 +83,9 @@ class FlowService {
|
|
|
76
83
|
});
|
|
77
84
|
}
|
|
78
85
|
}
|
|
86
|
+
setCronService(cronService) {
|
|
87
|
+
this.cronService = cronService;
|
|
88
|
+
}
|
|
79
89
|
static generateExecutionId() {
|
|
80
90
|
return FlowEngine_1.FlowEngine.generateExecutionId();
|
|
81
91
|
}
|
|
@@ -104,13 +114,59 @@ class FlowService {
|
|
|
104
114
|
description ${textType} DEFAULT '',
|
|
105
115
|
enabled INTEGER NOT NULL DEFAULT 1,
|
|
106
116
|
triggerType VARCHAR(50) NOT NULL DEFAULT 'http',
|
|
117
|
+
authPolicy VARCHAR(50) NOT NULL DEFAULT 'public',
|
|
118
|
+
invokeRule ${textType},
|
|
107
119
|
eventTrigger VARCHAR(255),
|
|
108
120
|
maxConcurrentExecutions INTEGER DEFAULT NULL,
|
|
109
121
|
definition ${textType} NOT NULL,
|
|
110
122
|
created VARCHAR(50) NOT NULL,
|
|
111
123
|
updated VARCHAR(50) NOT NULL
|
|
112
124
|
`);
|
|
113
|
-
|
|
125
|
+
const ddlFlowsRes = this.db.exec(ddlFlows);
|
|
126
|
+
const ensureFlowColumns = () => {
|
|
127
|
+
const columnsToEnsure = [
|
|
128
|
+
{
|
|
129
|
+
pg: `ALTER TABLE "_flows" ADD COLUMN IF NOT EXISTS "authPolicy" VARCHAR(50) NOT NULL DEFAULT 'public'`,
|
|
130
|
+
generic: this.db.dialect.addColumnSql('_flows', `authPolicy VARCHAR(50) NOT NULL DEFAULT 'public'`),
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
pg: `ALTER TABLE "_flows" ADD COLUMN IF NOT EXISTS "invokeRule" ${textType}`,
|
|
134
|
+
generic: this.db.dialect.addColumnSql('_flows', `invokeRule ${textType}`),
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
pg: `ALTER TABLE "_flows" ADD COLUMN IF NOT EXISTS "cronSchedule" ${this.db.dialect.name === 'sqlite' ? 'TEXT' : 'VARCHAR(255)'}`,
|
|
138
|
+
generic: this.db.dialect.addColumnSql('_flows', `cronSchedule ${this.db.dialect.name === 'sqlite' ? 'TEXT' : 'VARCHAR(255)'}`),
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
pg: `ALTER TABLE "_flows" ADD COLUMN IF NOT EXISTS "cronTimezone" ${this.db.dialect.name === 'sqlite' ? 'TEXT' : 'VARCHAR(100)'}`,
|
|
142
|
+
generic: this.db.dialect.addColumnSql('_flows', `cronTimezone ${this.db.dialect.name === 'sqlite' ? 'TEXT' : 'VARCHAR(100)'}`),
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
pg: `ALTER TABLE "_flows" ADD COLUMN IF NOT EXISTS "cronMissedPolicy" ${this.db.dialect.name === 'sqlite' ? 'TEXT' : 'VARCHAR(50)'}`,
|
|
146
|
+
generic: this.db.dialect.addColumnSql('_flows', `cronMissedPolicy ${this.db.dialect.name === 'sqlite' ? 'TEXT' : 'VARCHAR(50)'}`),
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
pg: `ALTER TABLE "_flows" ADD COLUMN IF NOT EXISTS "cronInput" ${textType}`,
|
|
150
|
+
generic: this.db.dialect.addColumnSql('_flows', `cronInput ${textType}`),
|
|
151
|
+
},
|
|
152
|
+
];
|
|
153
|
+
for (const colDef of columnsToEnsure) {
|
|
154
|
+
try {
|
|
155
|
+
const sql = this.db.dialect.name === 'postgres' ? colDef.pg : colDef.generic;
|
|
156
|
+
const res = this.db.exec(sql);
|
|
157
|
+
if (res && typeof res.then === 'function') {
|
|
158
|
+
void res.catch(() => { });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch { }
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
if (ddlFlowsRes && typeof ddlFlowsRes.then === 'function') {
|
|
165
|
+
void ddlFlowsRes.then(ensureFlowColumns).catch(() => { });
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
ensureFlowColumns();
|
|
169
|
+
}
|
|
114
170
|
const ddlExecs = this.db.dialect.createTableIfNotExists('_flow_executions', `
|
|
115
171
|
id VARCHAR(255) PRIMARY KEY,
|
|
116
172
|
flowId VARCHAR(255) NOT NULL,
|
|
@@ -394,7 +450,7 @@ class FlowService {
|
|
|
394
450
|
};
|
|
395
451
|
// Asynchronous event trigger (single-path through executeFlow with wait: false)
|
|
396
452
|
const eventActor = actor || (flow.eventTrigger ? { id: `event:${flow.eventTrigger}` } : { id: 'system:event' });
|
|
397
|
-
this.executeFlow(flow.id, eventPayload, eventActor, { wait: false }).catch((err) => {
|
|
453
|
+
this.executeFlow(flow.id, eventPayload, eventActor, { wait: false, trusted: true }).catch((err) => {
|
|
398
454
|
console.error(`[FlowService] Event trigger failed for flow '${flow.name}':`, err);
|
|
399
455
|
});
|
|
400
456
|
}
|
|
@@ -470,6 +526,9 @@ class FlowService {
|
|
|
470
526
|
if (!dto.name || typeof dto.name !== 'string' || !dto.name.trim()) {
|
|
471
527
|
throw new AppError_1.AppError('Flow name is required', 400);
|
|
472
528
|
}
|
|
529
|
+
if (dto.authPolicy !== undefined && !exports.ALLOWED_FLOW_AUTH_POLICIES.includes(dto.authPolicy)) {
|
|
530
|
+
throw new AppError_1.ValidationError(`Invalid auth policy '${dto.authPolicy}'. Allowed policies are: ${exports.ALLOWED_FLOW_AUTH_POLICIES.join(', ')}`);
|
|
531
|
+
}
|
|
473
532
|
if (!dto.definition) {
|
|
474
533
|
throw new AppError_1.AppError('Flow definition is required', 400);
|
|
475
534
|
}
|
|
@@ -477,7 +536,9 @@ class FlowService {
|
|
|
477
536
|
FlowValidator_1.FlowValidator.validateConcurrency(dto.maxConcurrentExecutions);
|
|
478
537
|
const triggerType = dto.triggerType || 'http';
|
|
479
538
|
const eventTrigger = triggerType === 'event' ? (dto.eventTrigger ? dto.eventTrigger.trim() : null) : null;
|
|
480
|
-
|
|
539
|
+
const cronSchedule = triggerType === 'cron' ? (dto.cronSchedule ? dto.cronSchedule.trim() : null) : null;
|
|
540
|
+
const cronTimezone = triggerType === 'cron' ? (dto.cronTimezone ? dto.cronTimezone.trim() : 'UTC') : 'UTC';
|
|
541
|
+
FlowValidator_1.FlowValidator.validateTrigger(triggerType, eventTrigger, cronSchedule, cronTimezone);
|
|
481
542
|
const trimmedName = dto.name.trim();
|
|
482
543
|
const existing = this.getFlowByName(trimmedName);
|
|
483
544
|
if (existing instanceof Promise) {
|
|
@@ -497,26 +558,59 @@ class FlowService {
|
|
|
497
558
|
const now = new Date().toISOString();
|
|
498
559
|
const enabled = dto.enabled !== undefined ? (dto.enabled ? 1 : 0) : 1;
|
|
499
560
|
const description = dto.description || '';
|
|
561
|
+
const authPolicy = dto.authPolicy || 'public';
|
|
562
|
+
const invokeRule = dto.invokeRule !== undefined ? dto.invokeRule : null;
|
|
500
563
|
const maxConcurrentExecutions = dto.maxConcurrentExecutions !== undefined && dto.maxConcurrentExecutions !== null
|
|
501
564
|
? dto.maxConcurrentExecutions
|
|
502
565
|
: null;
|
|
503
566
|
const definition = JSON.stringify(dto.definition);
|
|
567
|
+
const cronSchedule = triggerType === 'cron' ? (dto.cronSchedule ? dto.cronSchedule.trim() : null) : null;
|
|
568
|
+
const cronTimezone = triggerType === 'cron' ? (dto.cronTimezone ? dto.cronTimezone.trim() : 'UTC') : 'UTC';
|
|
569
|
+
const cronMissedPolicy = triggerType === 'cron' ? (dto.cronMissedPolicy || 'skip') : 'skip';
|
|
570
|
+
let cronInputStr = null;
|
|
571
|
+
if (triggerType === 'cron' && dto.cronInput !== undefined && dto.cronInput !== null) {
|
|
572
|
+
cronInputStr = typeof dto.cronInput === 'string' ? dto.cronInput : JSON.stringify(dto.cronInput);
|
|
573
|
+
}
|
|
504
574
|
const res = this.db.run(`
|
|
505
|
-
INSERT INTO _flows (
|
|
506
|
-
|
|
507
|
-
|
|
575
|
+
INSERT INTO _flows (
|
|
576
|
+
id, name, description, enabled, triggerType, authPolicy, invokeRule, eventTrigger,
|
|
577
|
+
cronSchedule, cronTimezone, cronMissedPolicy, cronInput,
|
|
578
|
+
maxConcurrentExecutions, definition, created, updated
|
|
579
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
580
|
+
`, id, trimmedName, description, enabled, triggerType, authPolicy, invokeRule, eventTrigger, cronSchedule, cronTimezone, cronMissedPolicy, cronInputStr, maxConcurrentExecutions, definition, now, now);
|
|
508
581
|
if (res instanceof Promise) {
|
|
509
582
|
return res.then(async () => {
|
|
510
583
|
const created = await this.getFlowById(id);
|
|
511
584
|
this.syncFlowQueue(created);
|
|
585
|
+
if (this.cronService && created) {
|
|
586
|
+
await this.cronService.syncFlowSchedule(created);
|
|
587
|
+
}
|
|
512
588
|
return created;
|
|
513
589
|
});
|
|
514
590
|
}
|
|
515
591
|
const created = this.getFlowById(id);
|
|
516
592
|
this.syncFlowQueue(created);
|
|
593
|
+
if (this.cronService && created) {
|
|
594
|
+
if (created instanceof Promise) {
|
|
595
|
+
return created.then(async (c) => {
|
|
596
|
+
if (c)
|
|
597
|
+
await this.cronService.syncFlowSchedule(c);
|
|
598
|
+
return c;
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
const syncRes = this.cronService.syncFlowSchedule(created);
|
|
602
|
+
if (syncRes instanceof Promise) {
|
|
603
|
+
void syncRes.catch((err) => {
|
|
604
|
+
console.warn(`[FlowService] Failed to sync cron schedule for flow '${created.name}':`, err);
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
}
|
|
517
608
|
return created;
|
|
518
609
|
}
|
|
519
610
|
updateFlow(id, dto, actor) {
|
|
611
|
+
if (dto.authPolicy !== undefined && !exports.ALLOWED_FLOW_AUTH_POLICIES.includes(dto.authPolicy)) {
|
|
612
|
+
throw new AppError_1.ValidationError(`Invalid auth policy '${dto.authPolicy}'. Allowed policies are: ${exports.ALLOWED_FLOW_AUTH_POLICIES.join(', ')}`);
|
|
613
|
+
}
|
|
520
614
|
if (dto.definition !== undefined) {
|
|
521
615
|
FlowValidator_1.FlowValidator.validate(dto.definition);
|
|
522
616
|
}
|
|
@@ -569,9 +663,23 @@ class FlowService {
|
|
|
569
663
|
else if (eventTrigger) {
|
|
570
664
|
eventTrigger = eventTrigger.trim();
|
|
571
665
|
}
|
|
572
|
-
|
|
666
|
+
const cronSchedule = triggerType === 'cron' ? (dto.cronSchedule !== undefined ? (dto.cronSchedule ? dto.cronSchedule.trim() : null) : (current.cronSchedule ?? null)) : null;
|
|
667
|
+
const cronTimezone = triggerType === 'cron' ? (dto.cronTimezone !== undefined ? (dto.cronTimezone ? dto.cronTimezone.trim() : 'UTC') : (current.cronTimezone ?? 'UTC')) : 'UTC';
|
|
668
|
+
const cronMissedPolicy = triggerType === 'cron' ? (dto.cronMissedPolicy !== undefined ? dto.cronMissedPolicy : (current.cronMissedPolicy ?? 'skip')) : 'skip';
|
|
669
|
+
let cronInputStr = null;
|
|
670
|
+
if (triggerType === 'cron') {
|
|
671
|
+
if (dto.cronInput !== undefined) {
|
|
672
|
+
cronInputStr = dto.cronInput !== null ? (typeof dto.cronInput === 'string' ? dto.cronInput : JSON.stringify(dto.cronInput)) : null;
|
|
673
|
+
}
|
|
674
|
+
else if (current.cronInput !== undefined && current.cronInput !== null) {
|
|
675
|
+
cronInputStr = typeof current.cronInput === 'string' ? current.cronInput : JSON.stringify(current.cronInput);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
FlowValidator_1.FlowValidator.validateTrigger(triggerType, eventTrigger, cronSchedule, cronTimezone);
|
|
573
679
|
const description = dto.description !== undefined ? dto.description : current.description;
|
|
574
680
|
const enabled = dto.enabled !== undefined ? (dto.enabled ? 1 : 0) : (current.enabled ? 1 : 0);
|
|
681
|
+
const authPolicy = dto.authPolicy !== undefined ? dto.authPolicy : (current.authPolicy || 'public');
|
|
682
|
+
const invokeRule = dto.invokeRule !== undefined ? dto.invokeRule : (current.invokeRule ?? null);
|
|
575
683
|
const maxConcurrentExecutions = dto.maxConcurrentExecutions !== undefined
|
|
576
684
|
? dto.maxConcurrentExecutions
|
|
577
685
|
: (current.maxConcurrentExecutions ?? null);
|
|
@@ -579,18 +687,38 @@ class FlowService {
|
|
|
579
687
|
const now = new Date().toISOString();
|
|
580
688
|
const res = this.db.run(`
|
|
581
689
|
UPDATE _flows SET
|
|
582
|
-
name = ?, description = ?, enabled = ?, triggerType = ?,
|
|
690
|
+
name = ?, description = ?, enabled = ?, triggerType = ?, authPolicy = ?, invokeRule = ?,
|
|
691
|
+
eventTrigger = ?, cronSchedule = ?, cronTimezone = ?, cronMissedPolicy = ?, cronInput = ?,
|
|
692
|
+
maxConcurrentExecutions = ?, definition = ?, updated = ?
|
|
583
693
|
WHERE id = ?
|
|
584
|
-
`, name, description, enabled, triggerType, eventTrigger, maxConcurrentExecutions, definition, now, id);
|
|
694
|
+
`, name, description, enabled, triggerType, authPolicy, invokeRule, eventTrigger, cronSchedule, cronTimezone, cronMissedPolicy, cronInputStr, maxConcurrentExecutions, definition, now, id);
|
|
585
695
|
if (res instanceof Promise) {
|
|
586
696
|
return res.then(async () => {
|
|
587
697
|
const updated = await this.getFlowById(id);
|
|
588
698
|
this.syncFlowQueue(updated);
|
|
699
|
+
if (this.cronService && updated) {
|
|
700
|
+
await this.cronService.syncFlowSchedule(updated);
|
|
701
|
+
}
|
|
589
702
|
return updated;
|
|
590
703
|
});
|
|
591
704
|
}
|
|
592
705
|
const updated = this.getFlowById(id);
|
|
593
706
|
this.syncFlowQueue(updated);
|
|
707
|
+
if (this.cronService && updated) {
|
|
708
|
+
if (updated instanceof Promise) {
|
|
709
|
+
return updated.then(async (u) => {
|
|
710
|
+
if (u)
|
|
711
|
+
await this.cronService.syncFlowSchedule(u);
|
|
712
|
+
return u;
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
const syncRes = this.cronService.syncFlowSchedule(updated);
|
|
716
|
+
if (syncRes instanceof Promise) {
|
|
717
|
+
void syncRes.catch((err) => {
|
|
718
|
+
console.warn(`[FlowService] Failed to sync cron schedule for flow '${updated.name}':`, err);
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
}
|
|
594
722
|
return updated;
|
|
595
723
|
}
|
|
596
724
|
deleteFlow(id, actor) {
|
|
@@ -608,6 +736,9 @@ class FlowService {
|
|
|
608
736
|
return this.finishDeleteFlow(id);
|
|
609
737
|
}
|
|
610
738
|
finishDeleteFlow(id) {
|
|
739
|
+
if (this.cronService) {
|
|
740
|
+
void Promise.resolve(this.cronService.removeTargetSchedules('flow', id)).catch(() => { });
|
|
741
|
+
}
|
|
611
742
|
if (this.queueService) {
|
|
612
743
|
const queueName = FlowService.getFlowQueueName(id);
|
|
613
744
|
void this.queueService.deleteQueue(queueName).catch(() => { });
|
|
@@ -650,6 +781,59 @@ class FlowService {
|
|
|
650
781
|
return Number(row?.count || 0);
|
|
651
782
|
}
|
|
652
783
|
// ==========================================
|
|
784
|
+
// HTTP Flow Authorization Policy
|
|
785
|
+
// ==========================================
|
|
786
|
+
verifyHttpAuthPolicy(flow, auth, requestCtx) {
|
|
787
|
+
const policy = flow.authPolicy || 'public';
|
|
788
|
+
switch (policy) {
|
|
789
|
+
case 'public':
|
|
790
|
+
break;
|
|
791
|
+
case 'admin':
|
|
792
|
+
if (!auth?.isAdmin) {
|
|
793
|
+
throw new AppError_1.ForbiddenError(`Superuser authorization required to execute flow '${flow.name}'`);
|
|
794
|
+
}
|
|
795
|
+
break;
|
|
796
|
+
case 'auth':
|
|
797
|
+
if (auth?.isAdmin) {
|
|
798
|
+
break;
|
|
799
|
+
}
|
|
800
|
+
if (!auth || !auth.id) {
|
|
801
|
+
throw new AppError_1.UnauthorizedError(`Authentication token required to execute flow '${flow.name}'`);
|
|
802
|
+
}
|
|
803
|
+
if (auth.isApiKey && !(0, ApiKeyService_1.hasFlowScope)(auth, flow.name)) {
|
|
804
|
+
throw new AppError_1.ForbiddenError(`API Key missing required scope for flow execution (e.g. 'flows:execute', 'flows:invoke', or 'flows:${flow.name}')`);
|
|
805
|
+
}
|
|
806
|
+
break;
|
|
807
|
+
case 'apiKey':
|
|
808
|
+
if (!auth?.isApiKey && !auth?.isAdmin) {
|
|
809
|
+
throw new AppError_1.UnauthorizedError(`Valid API Key required to execute flow '${flow.name}'`);
|
|
810
|
+
}
|
|
811
|
+
if (!auth?.isAdmin && !(0, ApiKeyService_1.hasFlowScope)(auth, flow.name)) {
|
|
812
|
+
throw new AppError_1.ForbiddenError(`API Key missing required scope for flow execution (e.g. 'flows:execute', 'flows:invoke', or 'flows:*')`);
|
|
813
|
+
}
|
|
814
|
+
break;
|
|
815
|
+
case 'custom':
|
|
816
|
+
if (auth?.isAdmin) {
|
|
817
|
+
break;
|
|
818
|
+
}
|
|
819
|
+
if (auth?.isApiKey) {
|
|
820
|
+
if ((0, ApiKeyService_1.hasFlowScope)(auth, flow.name)) {
|
|
821
|
+
break;
|
|
822
|
+
}
|
|
823
|
+
throw new AppError_1.ForbiddenError(`API Key missing required scope for flow execution (e.g. 'flows:execute', 'flows:invoke', or 'flows:${flow.name}')`);
|
|
824
|
+
}
|
|
825
|
+
if (!flow.invokeRule || !flow.invokeRule.trim()) {
|
|
826
|
+
throw new AppError_1.ForbiddenError(`Flow '${flow.name}' requires a valid custom invokeRule`);
|
|
827
|
+
}
|
|
828
|
+
if (!this.ruleEngine.evaluate(flow.invokeRule, { auth, query: requestCtx?.query, data: requestCtx?.data })) {
|
|
829
|
+
throw new AppError_1.ForbiddenError(`You do not satisfy the access rule to execute flow '${flow.name}'`);
|
|
830
|
+
}
|
|
831
|
+
break;
|
|
832
|
+
default:
|
|
833
|
+
throw new AppError_1.ForbiddenError(`Unsupported auth policy '${policy}'`);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
// ==========================================
|
|
653
837
|
// Execution, Concurrency Admission & Checkpointing
|
|
654
838
|
// ==========================================
|
|
655
839
|
async executeFlow(flowIdOrName, input, actor, options = {}) {
|
|
@@ -660,6 +844,13 @@ class FlowService {
|
|
|
660
844
|
if (!flow.enabled) {
|
|
661
845
|
throw new AppError_1.AppError(`Flow '${flow.name}' is currently disabled`, 403);
|
|
662
846
|
}
|
|
847
|
+
// Enforce authorization policy at the service boundary unless explicitly running in trusted internal mode
|
|
848
|
+
if (!options.trusted && flow.triggerType === 'http') {
|
|
849
|
+
this.verifyHttpAuthPolicy(flow, actor, {
|
|
850
|
+
query: options.query || {},
|
|
851
|
+
data: input,
|
|
852
|
+
});
|
|
853
|
+
}
|
|
663
854
|
const executionId = options.executionId || FlowService.generateExecutionId();
|
|
664
855
|
if (this.activeExecutionClaims.has(executionId) || this.pendingExecutionAdmissions.has(executionId)) {
|
|
665
856
|
throw new AppError_1.ConflictError(`Flow execution '${executionId}' is currently running`);
|
|
@@ -675,16 +866,23 @@ class FlowService {
|
|
|
675
866
|
throw new AppError_1.ConflictError(`Flow execution '${options.executionId}' already exists`);
|
|
676
867
|
}
|
|
677
868
|
}
|
|
678
|
-
|
|
679
|
-
|
|
869
|
+
let authContext = null;
|
|
870
|
+
if (typeof actor === 'object' && actor !== null) {
|
|
871
|
+
const { tokenKey: _tk, exp: _exp, iat: _iat, ...actorRest } = actor;
|
|
872
|
+
authContext = {
|
|
873
|
+
...actorRest,
|
|
680
874
|
id: actor.id || actor.email || null,
|
|
681
875
|
email: actor.email,
|
|
682
876
|
isAdmin: Boolean(actor.isAdmin),
|
|
683
877
|
isApiKey: Boolean(actor.isApiKey),
|
|
878
|
+
scopes: Array.isArray(actor.scopes) ? actor.scopes : undefined,
|
|
684
879
|
role: actor.role,
|
|
685
880
|
collection: actor.collection,
|
|
686
|
-
}
|
|
687
|
-
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
else if (typeof actor === 'string') {
|
|
884
|
+
authContext = { id: actor };
|
|
885
|
+
}
|
|
688
886
|
const now = new Date().toISOString();
|
|
689
887
|
const initialCheckpoint = {
|
|
690
888
|
currentStateName: flow.definition.startAt,
|
|
@@ -1823,13 +2021,28 @@ class FlowService {
|
|
|
1823
2021
|
}
|
|
1824
2022
|
}
|
|
1825
2023
|
mapRowToConfig(row) {
|
|
2024
|
+
let cronInput = undefined;
|
|
2025
|
+
if (row.cronInput !== null && row.cronInput !== undefined) {
|
|
2026
|
+
try {
|
|
2027
|
+
cronInput = typeof row.cronInput === 'string' ? JSON.parse(row.cronInput) : row.cronInput;
|
|
2028
|
+
}
|
|
2029
|
+
catch {
|
|
2030
|
+
cronInput = row.cronInput;
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
1826
2033
|
return {
|
|
1827
2034
|
id: row.id,
|
|
1828
2035
|
name: row.name,
|
|
1829
2036
|
description: row.description || '',
|
|
1830
2037
|
enabled: row.enabled === 1,
|
|
1831
2038
|
triggerType: row.triggerType,
|
|
2039
|
+
authPolicy: row.authPolicy || 'public',
|
|
2040
|
+
invokeRule: row.invokeRule ?? null,
|
|
1832
2041
|
eventTrigger: row.eventTrigger,
|
|
2042
|
+
cronSchedule: row.cronSchedule ?? null,
|
|
2043
|
+
cronTimezone: row.cronTimezone ?? null,
|
|
2044
|
+
cronMissedPolicy: row.cronMissedPolicy ?? null,
|
|
2045
|
+
cronInput,
|
|
1833
2046
|
maxConcurrentExecutions: row.maxConcurrentExecutions !== null && row.maxConcurrentExecutions !== undefined
|
|
1834
2047
|
? Number(row.maxConcurrentExecutions)
|
|
1835
2048
|
: null,
|