@nodestackapp/server 2.6.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 +3 -1
- package/dist/NodeStack.d.ts +4 -0
- package/dist/NodeStack.d.ts.map +1 -1
- package/dist/NodeStack.js +44 -6
- package/dist/NodeStack.js.map +1 -1
- package/dist/admin/AdminUIBundler.d.ts.map +1 -1
- package/dist/admin/AdminUIBundler.js +1 -0
- package/dist/admin/AdminUIBundler.js.map +1 -1
- package/dist/admin/ui/css/main.css +6 -3
- package/dist/admin/ui/index.html +2345 -55
- package/dist/admin/ui/js/api.js +8 -0
- package/dist/admin/ui/js/app.js +38 -7
- package/dist/admin/ui/js/apps.js +18 -0
- package/dist/admin/ui/js/command-palette.js +10 -0
- 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 +94 -0
- package/dist/admin/ui/js/flows.js +43 -4
- package/dist/admin/ui/js/functions-workbench.js +18 -0
- package/dist/admin/ui/js/functions.js +6 -3
- package/dist/admin/ui/js/snapshots.js +338 -0
- package/dist/admin/ui/js/views.js +1 -1
- package/dist/apps/AppManager.d.ts.map +1 -1
- package/dist/apps/AppManager.js +7 -3
- package/dist/apps/AppManager.js.map +1 -1
- package/dist/apps/AppScope.d.ts +2 -0
- package/dist/apps/AppScope.d.ts.map +1 -1
- package/dist/apps/AppScope.js +22 -2
- package/dist/apps/AppScope.js.map +1 -1
- package/dist/auth/ApiKeyService.d.ts +1 -0
- package/dist/auth/ApiKeyService.d.ts.map +1 -1
- package/dist/auth/ApiKeyService.js +16 -1
- package/dist/auth/ApiKeyService.js.map +1 -1
- package/dist/cli/cli.js +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/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 +3 -1
- package/dist/database/DatabaseService.d.ts.map +1 -1
- package/dist/database/DatabaseService.js +10 -3
- 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/MssqlDriver.d.ts.map +1 -1
- package/dist/database/drivers/MssqlDriver.js +5 -6
- package/dist/database/drivers/MssqlDriver.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 +138 -0
- package/dist/database/migrations/SystemMigrations.js.map +1 -1
- package/dist/flows/FlowService.d.ts +3 -0
- package/dist/flows/FlowService.d.ts.map +1 -1
- package/dist/flows/FlowService.js +106 -7
- package/dist/flows/FlowService.js.map +1 -1
- package/dist/flows/FlowValidator.d.ts +1 -1
- package/dist/flows/FlowValidator.d.ts.map +1 -1
- package/dist/flows/FlowValidator.js +13 -3
- package/dist/flows/FlowValidator.js.map +1 -1
- package/dist/flows/types.d.ts +6 -1
- package/dist/flows/types.d.ts.map +1 -1
- package/dist/functions/FunctionService.d.ts +5 -1
- package/dist/functions/FunctionService.d.ts.map +1 -1
- package/dist/functions/FunctionService.js +190 -7
- package/dist/functions/FunctionService.js.map +1 -1
- package/dist/functions/runtime/QuickJsWasmRuntime.d.ts.map +1 -1
- package/dist/functions/runtime/QuickJsWasmRuntime.js +183 -180
- package/dist/functions/runtime/QuickJsWasmRuntime.js.map +1 -1
- package/dist/functions/types.d.ts +15 -0
- package/dist/functions/types.d.ts.map +1 -1
- package/dist/http/HttpServer.d.ts +4 -1
- package/dist/http/HttpServer.d.ts.map +1 -1
- package/dist/http/HttpServer.js +34 -2
- package/dist/http/HttpServer.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/HealthController.js +2 -2
- package/dist/schema/OpenApiGenerator.js +3 -3
- 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/webhooks/WebhookService.js +1 -1
- package/package.json +3 -2
|
@@ -4,7 +4,7 @@ import { RecordService } from '../records/RecordService';
|
|
|
4
4
|
import { RuleEngine } from '../rules/RuleEngine';
|
|
5
5
|
import { EventBus } from '../core/events/EventBus';
|
|
6
6
|
import { SandboxedRunner } from './runtime/SandboxedRunner';
|
|
7
|
-
import { FunctionConfig, CreateFunctionDto, UpdateFunctionDto, FunctionRequestContext, FunctionExecutionResult, FunctionAuthPolicy } from './types';
|
|
7
|
+
import { FunctionConfig, CreateFunctionDto, UpdateFunctionDto, FunctionRequestContext, FunctionCronContext, FunctionExecutionResult, FunctionAuthPolicy } from './types';
|
|
8
8
|
export declare const ALLOWED_AUTH_POLICIES: readonly FunctionAuthPolicy[];
|
|
9
9
|
import { AppError } from '../core/errors/AppError';
|
|
10
10
|
import type { FlowService } from '../flows/FlowService';
|
|
@@ -22,6 +22,7 @@ export interface FunctionServiceOptions {
|
|
|
22
22
|
queueService?: QueueService;
|
|
23
23
|
authService?: AuthService;
|
|
24
24
|
apiKeyService?: ApiKeyService;
|
|
25
|
+
cronService?: any;
|
|
25
26
|
}
|
|
26
27
|
export declare class FunctionService {
|
|
27
28
|
private db;
|
|
@@ -39,11 +40,13 @@ export declare class FunctionService {
|
|
|
39
40
|
private queueService?;
|
|
40
41
|
private authService?;
|
|
41
42
|
private apiKeyService?;
|
|
43
|
+
private cronService?;
|
|
42
44
|
constructor(db: DatabaseService, schemaService?: SchemaService | undefined, recordService?: RecordService | undefined, ruleEngine?: RuleEngine | undefined, eventBus?: EventBus | undefined, appScope?: {
|
|
43
45
|
id: string;
|
|
44
46
|
slug: string;
|
|
45
47
|
name?: string;
|
|
46
48
|
}, options?: FunctionServiceOptions);
|
|
49
|
+
setCronService(cronService: any): void;
|
|
47
50
|
getActiveExecutions(): number;
|
|
48
51
|
getMaxConcurrent(): number;
|
|
49
52
|
getAvailableCapacity(): number;
|
|
@@ -101,6 +104,7 @@ export declare class FunctionService {
|
|
|
101
104
|
maxAttempts: number;
|
|
102
105
|
groupKey?: string | null;
|
|
103
106
|
}, actor?: any): Promise<FunctionExecutionResult>;
|
|
107
|
+
executeScheduledFunction(functionIdOrName: string, cronCtx: FunctionCronContext, payload?: any): Promise<FunctionExecutionResult>;
|
|
104
108
|
setAuthServices(authService?: AuthService, apiKeyService?: ApiKeyService): void;
|
|
105
109
|
hasAuthServices(): boolean;
|
|
106
110
|
resolveAuthFromHeaders(headers?: Record<string, any>): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionService.d.ts","sourceRoot":"","sources":["../../src/functions/FunctionService.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"FunctionService.d.ts","sourceRoot":"","sources":["../../src/functions/FunctionService.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EAEtB,mBAAmB,EAEnB,uBAAuB,EAGvB,kBAAkB,EACnB,MAAM,SAAS,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AAS,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,GAAG,CAQzC;IAEM,QAAQ,IAAI,GAAG,CAcrB;IAED,OAAO,CAAC,sBAAsB;IAoB9B,OAAO,CAAC,oBAAoB;IAsN5B,OAAO,CAAC,SAAS;IA6BjB,OAAO,CAAC,cAAc;CA2CvB"}
|
|
@@ -42,6 +42,7 @@ const SsrfGuard_1 = require("./security/SsrfGuard");
|
|
|
42
42
|
exports.ALLOWED_AUTH_POLICIES = ['public', 'auth', 'admin', 'apiKey', 'custom'];
|
|
43
43
|
const AppError_1 = require("../core/errors/AppError");
|
|
44
44
|
const FlowValidator_1 = require("../flows/FlowValidator");
|
|
45
|
+
const CronParser_1 = require("../cron/CronParser");
|
|
45
46
|
const ApiKeyService_1 = require("../auth/ApiKeyService");
|
|
46
47
|
class FunctionConcurrencyLimitError extends AppError_1.AppError {
|
|
47
48
|
constructor(message = 'Serverless function concurrency limit reached. Please retry shortly.') {
|
|
@@ -65,6 +66,7 @@ class FunctionService {
|
|
|
65
66
|
queueService;
|
|
66
67
|
authService;
|
|
67
68
|
apiKeyService;
|
|
69
|
+
cronService;
|
|
68
70
|
constructor(db, schemaService, recordService, ruleEngine, eventBus, appScope = { id: 'default', slug: 'default' }, options = {}) {
|
|
69
71
|
this.db = db;
|
|
70
72
|
this.schemaService = schemaService;
|
|
@@ -79,8 +81,12 @@ class FunctionService {
|
|
|
79
81
|
this.queueService = options.queueService;
|
|
80
82
|
this.authService = options.authService;
|
|
81
83
|
this.apiKeyService = options.apiKeyService;
|
|
84
|
+
this.cronService = options.cronService;
|
|
82
85
|
this.initTables();
|
|
83
86
|
}
|
|
87
|
+
setCronService(cronService) {
|
|
88
|
+
this.cronService = cronService;
|
|
89
|
+
}
|
|
84
90
|
getActiveExecutions() {
|
|
85
91
|
return this.activeExecutions;
|
|
86
92
|
}
|
|
@@ -138,6 +144,25 @@ class FunctionService {
|
|
|
138
144
|
}
|
|
139
145
|
}
|
|
140
146
|
catch { }
|
|
147
|
+
try {
|
|
148
|
+
const cols = [
|
|
149
|
+
`cronSchedule ${this.db.dialect.name === 'sqlite' ? 'TEXT' : 'VARCHAR(255)'}`,
|
|
150
|
+
`cronTimezone ${this.db.dialect.name === 'sqlite' ? 'TEXT' : 'VARCHAR(100)'}`,
|
|
151
|
+
`cronMissedPolicy ${this.db.dialect.name === 'sqlite' ? 'TEXT' : 'VARCHAR(50)'}`,
|
|
152
|
+
`cronPayload ${textType}`,
|
|
153
|
+
];
|
|
154
|
+
for (const col of cols) {
|
|
155
|
+
const cName = col.split(' ')[0];
|
|
156
|
+
const sql = this.db.dialect.name === 'postgres'
|
|
157
|
+
? `ALTER TABLE "_functions" ADD COLUMN IF NOT EXISTS "${cName}" ${col.substring(cName.length + 1)}`
|
|
158
|
+
: this.db.dialect.addColumnSql('_functions', col);
|
|
159
|
+
const r = this.db.exec(sql);
|
|
160
|
+
if (r && typeof r.then === 'function') {
|
|
161
|
+
void r.catch(() => { });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch { }
|
|
141
166
|
};
|
|
142
167
|
if (ddlResult && typeof ddlResult.then === 'function') {
|
|
143
168
|
void ddlResult.then(ensureInvokeRuleColumn).catch(() => { });
|
|
@@ -211,6 +236,16 @@ class FunctionService {
|
|
|
211
236
|
throw new AppError_1.ValidationError(`Invalid auth policy '${dto.authPolicy}'. Allowed policies are: ${exports.ALLOWED_AUTH_POLICIES.join(', ')}`);
|
|
212
237
|
}
|
|
213
238
|
}
|
|
239
|
+
if (dto.cronSchedule !== undefined && dto.cronSchedule !== null && String(dto.cronSchedule).trim() !== '') {
|
|
240
|
+
const tz = dto.cronTimezone?.trim() || 'UTC';
|
|
241
|
+
const validation = CronParser_1.CronParser.validate(dto.cronSchedule.trim(), tz);
|
|
242
|
+
if (!validation.valid) {
|
|
243
|
+
throw new AppError_1.ValidationError(validation.error || 'Invalid cron expression');
|
|
244
|
+
}
|
|
245
|
+
if (dto.cronMissedPolicy !== undefined && dto.cronMissedPolicy !== null && !['skip', 'catch_up_once', 'catch_up_all'].includes(dto.cronMissedPolicy)) {
|
|
246
|
+
throw new AppError_1.ValidationError(`Invalid missedRunPolicy '${dto.cronMissedPolicy}'`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
214
249
|
const cleanName = dto.name.trim().toLowerCase().replace(/[^a-z0-9_-]/g, '-');
|
|
215
250
|
const existing = this.getFunctionByName(cleanName);
|
|
216
251
|
if (existing instanceof Promise) {
|
|
@@ -232,20 +267,46 @@ class FunctionService {
|
|
|
232
267
|
const allowedDomains = JSON.stringify(dto.allowedDomains || []);
|
|
233
268
|
const env = JSON.stringify(dto.env || {});
|
|
234
269
|
const invokeRule = dto.invokeRule !== undefined ? dto.invokeRule : null;
|
|
270
|
+
const cronSchedule = dto.cronSchedule || null;
|
|
271
|
+
const cronTimezone = dto.cronTimezone || 'UTC';
|
|
272
|
+
const cronMissedPolicy = dto.cronMissedPolicy || 'skip';
|
|
273
|
+
let cronPayloadStr = null;
|
|
274
|
+
if (dto.cronPayload !== undefined && dto.cronPayload !== null) {
|
|
275
|
+
cronPayloadStr = typeof dto.cronPayload === 'string' ? dto.cronPayload : JSON.stringify(dto.cronPayload);
|
|
276
|
+
}
|
|
235
277
|
const res = this.db.run(`
|
|
236
278
|
INSERT INTO _functions (
|
|
237
279
|
id, name, description, code, enabled, authPolicy, invokeRule, methods,
|
|
238
|
-
eventTrigger,
|
|
280
|
+
eventTrigger, cronSchedule, cronTimezone, cronMissedPolicy, cronPayload,
|
|
281
|
+
timeoutMs, memoryLimitMb, allowedDomains,
|
|
239
282
|
elevated, env, created, updated
|
|
240
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
241
|
-
`, id, cleanName, dto.description || '', dto.code || 'export default async function(core, context) {\n return { status: 200, body: { message: "Hello from " + context.app.slug } };\n}', dto.enabled === false ? 0 : 1, dto.authPolicy || 'public', invokeRule, methods, dto.eventTrigger || null, dto.timeoutMs || 1000, dto.memoryLimitMb || 32, allowedDomains, dto.elevated ? 1 : 0, env, now, now);
|
|
283
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
284
|
+
`, id, cleanName, dto.description || '', dto.code || 'export default async function(core, context) {\n return { status: 200, body: { message: "Hello from " + context.app.slug } };\n}', dto.enabled === false ? 0 : 1, dto.authPolicy || 'public', invokeRule, methods, dto.eventTrigger || null, cronSchedule, cronTimezone, cronMissedPolicy, cronPayloadStr, dto.timeoutMs || 1000, dto.memoryLimitMb || 32, allowedDomains, dto.elevated ? 1 : 0, env, now, now);
|
|
242
285
|
if (res instanceof Promise) {
|
|
243
286
|
return res.then(async () => {
|
|
244
287
|
const created = await this.getFunctionById(id);
|
|
288
|
+
if (this.cronService && created) {
|
|
289
|
+
await this.cronService.syncFunctionSchedule(created);
|
|
290
|
+
}
|
|
245
291
|
return created;
|
|
246
292
|
});
|
|
247
293
|
}
|
|
248
294
|
const created = this.getFunctionById(id);
|
|
295
|
+
if (this.cronService && created) {
|
|
296
|
+
if (created instanceof Promise) {
|
|
297
|
+
return created.then(async (c) => {
|
|
298
|
+
if (c)
|
|
299
|
+
await this.cronService.syncFunctionSchedule(c);
|
|
300
|
+
return c;
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
const syncRes = this.cronService.syncFunctionSchedule(created);
|
|
304
|
+
if (syncRes instanceof Promise) {
|
|
305
|
+
void syncRes.catch((err) => {
|
|
306
|
+
console.warn(`[FunctionService] Failed to sync cron schedule for function '${created.name}':`, err);
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
249
310
|
return created;
|
|
250
311
|
}
|
|
251
312
|
updateFunction(id, dto, actor) {
|
|
@@ -254,6 +315,16 @@ class FunctionService {
|
|
|
254
315
|
throw new AppError_1.ValidationError(`Invalid auth policy '${dto.authPolicy}'. Allowed policies are: ${exports.ALLOWED_AUTH_POLICIES.join(', ')}`);
|
|
255
316
|
}
|
|
256
317
|
}
|
|
318
|
+
if (dto.cronSchedule !== undefined && dto.cronSchedule !== null && String(dto.cronSchedule).trim() !== '') {
|
|
319
|
+
const tz = dto.cronTimezone?.trim() || 'UTC';
|
|
320
|
+
const validation = CronParser_1.CronParser.validate(dto.cronSchedule.trim(), tz);
|
|
321
|
+
if (!validation.valid) {
|
|
322
|
+
throw new AppError_1.ValidationError(validation.error || 'Invalid cron expression');
|
|
323
|
+
}
|
|
324
|
+
if (dto.cronMissedPolicy !== undefined && dto.cronMissedPolicy !== null && !['skip', 'catch_up_once', 'catch_up_all'].includes(dto.cronMissedPolicy)) {
|
|
325
|
+
throw new AppError_1.ValidationError(`Invalid missedRunPolicy '${dto.cronMissedPolicy}'`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
257
328
|
const current = this.getFunctionById(id);
|
|
258
329
|
if (current instanceof Promise) {
|
|
259
330
|
return current.then((curr) => {
|
|
@@ -294,6 +365,26 @@ class FunctionService {
|
|
|
294
365
|
const invokeRule = dto.invokeRule !== undefined ? dto.invokeRule : (current.invokeRule ?? null);
|
|
295
366
|
const methods = dto.methods ? dto.methods.join(',') : current.methods.join(',');
|
|
296
367
|
const eventTrigger = dto.eventTrigger !== undefined ? dto.eventTrigger : current.eventTrigger;
|
|
368
|
+
const cronSchedule = dto.cronSchedule !== undefined ? dto.cronSchedule : (current.cronSchedule ?? null);
|
|
369
|
+
const cronTimezone = dto.cronTimezone !== undefined ? dto.cronTimezone : (current.cronTimezone ?? 'UTC');
|
|
370
|
+
const cronMissedPolicy = dto.cronMissedPolicy !== undefined ? dto.cronMissedPolicy : (current.cronMissedPolicy ?? 'skip');
|
|
371
|
+
if (cronSchedule && cronSchedule.trim() !== '') {
|
|
372
|
+
const tz = (cronTimezone || 'UTC').trim();
|
|
373
|
+
const validation = CronParser_1.CronParser.validate(cronSchedule.trim(), tz);
|
|
374
|
+
if (!validation.valid) {
|
|
375
|
+
throw new AppError_1.ValidationError(validation.error || 'Invalid cron expression');
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (cronMissedPolicy && !['skip', 'catch_up_once', 'catch_up_all'].includes(cronMissedPolicy)) {
|
|
379
|
+
throw new AppError_1.ValidationError(`Invalid missedRunPolicy '${cronMissedPolicy}'`);
|
|
380
|
+
}
|
|
381
|
+
let cronPayloadStr = null;
|
|
382
|
+
if (dto.cronPayload !== undefined) {
|
|
383
|
+
cronPayloadStr = dto.cronPayload !== null ? (typeof dto.cronPayload === 'string' ? dto.cronPayload : JSON.stringify(dto.cronPayload)) : null;
|
|
384
|
+
}
|
|
385
|
+
else if (current.cronPayload !== undefined && current.cronPayload !== null) {
|
|
386
|
+
cronPayloadStr = typeof current.cronPayload === 'string' ? current.cronPayload : JSON.stringify(current.cronPayload);
|
|
387
|
+
}
|
|
297
388
|
const timeoutMs = dto.timeoutMs !== undefined ? dto.timeoutMs : current.timeoutMs;
|
|
298
389
|
const memoryLimitMb = dto.memoryLimitMb !== undefined ? dto.memoryLimitMb : current.memoryLimitMb;
|
|
299
390
|
const allowedDomains = dto.allowedDomains ? JSON.stringify(dto.allowedDomains) : JSON.stringify(current.allowedDomains);
|
|
@@ -303,18 +394,36 @@ class FunctionService {
|
|
|
303
394
|
const res = this.db.run(`
|
|
304
395
|
UPDATE _functions SET
|
|
305
396
|
name = ?, description = ?, code = ?, enabled = ?, authPolicy = ?, invokeRule = ?,
|
|
306
|
-
methods = ?, eventTrigger = ?,
|
|
307
|
-
allowedDomains = ?, elevated = ?, env = ?, updated = ?
|
|
397
|
+
methods = ?, eventTrigger = ?, cronSchedule = ?, cronTimezone = ?, cronMissedPolicy = ?, cronPayload = ?,
|
|
398
|
+
timeoutMs = ?, memoryLimitMb = ?, allowedDomains = ?, elevated = ?, env = ?, updated = ?
|
|
308
399
|
WHERE id = ?
|
|
309
|
-
`, name, description, code, enabled, authPolicy, invokeRule, methods, eventTrigger, timeoutMs, memoryLimitMb, allowedDomains, elevated, env, now, id);
|
|
400
|
+
`, name, description, code, enabled, authPolicy, invokeRule, methods, eventTrigger, cronSchedule, cronTimezone, cronMissedPolicy, cronPayloadStr, timeoutMs, memoryLimitMb, allowedDomains, elevated, env, now, id);
|
|
310
401
|
const cascadeRes = this.cascadeRenames(current.name, name, now);
|
|
311
402
|
if (res instanceof Promise || cascadeRes instanceof Promise) {
|
|
312
403
|
return Promise.all([res, cascadeRes]).then(async () => {
|
|
313
404
|
const updated = await this.getFunctionById(id);
|
|
405
|
+
if (this.cronService && updated) {
|
|
406
|
+
await this.cronService.syncFunctionSchedule(updated);
|
|
407
|
+
}
|
|
314
408
|
return updated;
|
|
315
409
|
});
|
|
316
410
|
}
|
|
317
411
|
const updated = this.getFunctionById(id);
|
|
412
|
+
if (this.cronService && updated) {
|
|
413
|
+
if (updated instanceof Promise) {
|
|
414
|
+
return updated.then(async (u) => {
|
|
415
|
+
if (u)
|
|
416
|
+
await this.cronService.syncFunctionSchedule(u);
|
|
417
|
+
return u;
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
const syncRes = this.cronService.syncFunctionSchedule(updated);
|
|
421
|
+
if (syncRes instanceof Promise) {
|
|
422
|
+
void syncRes.catch((err) => {
|
|
423
|
+
console.warn(`[FunctionService] Failed to sync cron schedule for function '${updated.name}':`, err);
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}
|
|
318
427
|
return updated;
|
|
319
428
|
}
|
|
320
429
|
cascadeRenames(currentName, newName, now) {
|
|
@@ -458,6 +567,9 @@ class FunctionService {
|
|
|
458
567
|
}
|
|
459
568
|
finishDeleteFunction(current, actor, options) {
|
|
460
569
|
const doDelete = () => {
|
|
570
|
+
if (this.cronService) {
|
|
571
|
+
void Promise.resolve(this.cronService.removeTargetSchedules('function', current.id)).catch(() => { });
|
|
572
|
+
}
|
|
461
573
|
const del1 = this.db.run('DELETE FROM _function_logs WHERE functionId = ?', current.id);
|
|
462
574
|
const del2 = this.db.run('DELETE FROM _functions WHERE id = ?', current.id);
|
|
463
575
|
if (del1 instanceof Promise || del2 instanceof Promise) {
|
|
@@ -679,6 +791,63 @@ class FunctionService {
|
|
|
679
791
|
this.queueService?.wakeAllWorkers();
|
|
680
792
|
}
|
|
681
793
|
}
|
|
794
|
+
async executeScheduledFunction(functionIdOrName, cronCtx, payload) {
|
|
795
|
+
const fn = (await this.getFunctionById(functionIdOrName)) || (await this.getFunctionByName(functionIdOrName));
|
|
796
|
+
if (!fn) {
|
|
797
|
+
throw new AppError_1.NotFoundError(`Function '${functionIdOrName}' not found`);
|
|
798
|
+
}
|
|
799
|
+
if (!fn.enabled) {
|
|
800
|
+
throw new AppError_1.AppError(`Function '${fn.name}' is currently disabled`, 403);
|
|
801
|
+
}
|
|
802
|
+
if (this.activeExecutions >= this.maxConcurrent) {
|
|
803
|
+
throw new FunctionConcurrencyLimitError();
|
|
804
|
+
}
|
|
805
|
+
const parentStore = this.executionStorage.getStore();
|
|
806
|
+
const currentDepth = (parentStore?.depth || 0) + 1;
|
|
807
|
+
const activeFns = parentStore?.activeFns ? new Set(parentStore.activeFns) : new Set();
|
|
808
|
+
if (currentDepth > this.maxRecursionDepth || activeFns.has(fn.id)) {
|
|
809
|
+
const errorMsg = activeFns.has(fn.id)
|
|
810
|
+
? `Circular recursion detected: function '${fn.name}' already active in call stack`
|
|
811
|
+
: `Maximum function recursion depth of ${this.maxRecursionDepth} exceeded`;
|
|
812
|
+
throw new AppError_1.AppError(errorMsg, 508);
|
|
813
|
+
}
|
|
814
|
+
this.activeExecutions++;
|
|
815
|
+
const nextActiveFns = new Set(activeFns);
|
|
816
|
+
nextActiveFns.add(fn.id);
|
|
817
|
+
const requestCtx = {
|
|
818
|
+
method: 'POST',
|
|
819
|
+
path: `/api/cron/${cronCtx.scheduleId}`,
|
|
820
|
+
query: {},
|
|
821
|
+
headers: { 'x-nodestack-trigger': 'cron' },
|
|
822
|
+
body: payload,
|
|
823
|
+
auth: { id: `cron:${cronCtx.scheduleId}`, role: 'admin', isAdmin: true },
|
|
824
|
+
};
|
|
825
|
+
try {
|
|
826
|
+
const context = this.buildFunctionContext(fn, requestCtx, undefined, { id: `cron:${cronCtx.scheduleId}`, isAdmin: true }, cronCtx);
|
|
827
|
+
const result = await this.executionStorage.run({ depth: currentDepth, activeFns: nextActiveFns }, () => this.runner.execute(fn.code, context, {
|
|
828
|
+
timeoutMs: fn.timeoutMs,
|
|
829
|
+
memoryLimitMb: fn.memoryLimitMb,
|
|
830
|
+
}));
|
|
831
|
+
this.recordLog({
|
|
832
|
+
functionId: fn.id,
|
|
833
|
+
functionName: fn.name,
|
|
834
|
+
trigger: 'cron',
|
|
835
|
+
status: result.status,
|
|
836
|
+
statusCode: result.statusCode,
|
|
837
|
+
durationMs: result.durationMs,
|
|
838
|
+
requestPayload: payload !== undefined ? JSON.stringify(payload) : undefined,
|
|
839
|
+
responsePayload: JSON.stringify(result.body ?? null),
|
|
840
|
+
logs: result.logs.join('\n'),
|
|
841
|
+
error: result.error,
|
|
842
|
+
actorId: `cron:${cronCtx.scheduleId}`,
|
|
843
|
+
});
|
|
844
|
+
return result;
|
|
845
|
+
}
|
|
846
|
+
finally {
|
|
847
|
+
this.activeExecutions = Math.max(0, this.activeExecutions - 1);
|
|
848
|
+
this.queueService?.wakeAllWorkers();
|
|
849
|
+
}
|
|
850
|
+
}
|
|
682
851
|
setAuthServices(authService, apiKeyService) {
|
|
683
852
|
if (authService)
|
|
684
853
|
this.authService = authService;
|
|
@@ -1064,7 +1233,7 @@ class FunctionService {
|
|
|
1064
1233
|
// ==========================================
|
|
1065
1234
|
// Context Builder & Helpers
|
|
1066
1235
|
// ==========================================
|
|
1067
|
-
buildFunctionContext(fn, requestCtx, eventCtx, actor) {
|
|
1236
|
+
buildFunctionContext(fn, requestCtx, eventCtx, actor, cronCtx) {
|
|
1068
1237
|
// If elevated is true, run as service-role (bypassing user rules)
|
|
1069
1238
|
const effectiveAuth = fn.elevated
|
|
1070
1239
|
? { isAdmin: true, id: 'service-role' }
|
|
@@ -1257,6 +1426,7 @@ class FunctionService {
|
|
|
1257
1426
|
app: this.appScope,
|
|
1258
1427
|
request: requestCtx,
|
|
1259
1428
|
event: eventCtx,
|
|
1429
|
+
cron: cronCtx,
|
|
1260
1430
|
env: fn.env || {},
|
|
1261
1431
|
auth: (requestCtx && requestCtx.auth !== undefined) ? requestCtx.auth : (effectiveAuth || null),
|
|
1262
1432
|
},
|
|
@@ -1288,6 +1458,15 @@ class FunctionService {
|
|
|
1288
1458
|
env = row.env ? JSON.parse(row.env) : {};
|
|
1289
1459
|
}
|
|
1290
1460
|
catch { }
|
|
1461
|
+
let cronPayload = undefined;
|
|
1462
|
+
if (row.cronPayload !== null && row.cronPayload !== undefined) {
|
|
1463
|
+
try {
|
|
1464
|
+
cronPayload = typeof row.cronPayload === 'string' ? JSON.parse(row.cronPayload) : row.cronPayload;
|
|
1465
|
+
}
|
|
1466
|
+
catch {
|
|
1467
|
+
cronPayload = row.cronPayload;
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1291
1470
|
return {
|
|
1292
1471
|
id: row.id,
|
|
1293
1472
|
name: row.name,
|
|
@@ -1298,6 +1477,10 @@ class FunctionService {
|
|
|
1298
1477
|
invokeRule: row.invokeRule ?? null,
|
|
1299
1478
|
methods: row.methods ? row.methods.split(',').map((m) => m.trim()) : ['GET', 'POST'],
|
|
1300
1479
|
eventTrigger: row.eventTrigger || null,
|
|
1480
|
+
cronSchedule: row.cronSchedule ?? null,
|
|
1481
|
+
cronTimezone: row.cronTimezone ?? null,
|
|
1482
|
+
cronMissedPolicy: row.cronMissedPolicy ?? null,
|
|
1483
|
+
cronPayload,
|
|
1301
1484
|
timeoutMs: row.timeoutMs || 1000,
|
|
1302
1485
|
memoryLimitMb: row.memoryLimitMb || 32,
|
|
1303
1486
|
allowedDomains,
|