@intranefr/superbackend 1.4.4 → 1.5.1
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/.env.example +5 -0
- package/README.md +11 -0
- package/index.js +39 -1
- package/package.json +11 -3
- package/public/sdk/ui-components.iife.js +191 -0
- package/sdk/ui-components/browser/src/index.js +228 -0
- package/src/admin/endpointRegistry.js +120 -0
- package/src/controllers/admin.controller.js +111 -5
- package/src/controllers/adminBlockDefinitions.controller.js +127 -0
- package/src/controllers/adminBlockDefinitionsAi.controller.js +54 -0
- package/src/controllers/adminCache.controller.js +342 -0
- package/src/controllers/adminContextBlockDefinitions.controller.js +141 -0
- package/src/controllers/adminCrons.controller.js +388 -0
- package/src/controllers/adminDbBrowser.controller.js +124 -0
- package/src/controllers/adminEjsVirtual.controller.js +13 -3
- package/src/controllers/adminHeadless.controller.js +91 -2
- package/src/controllers/adminHealthChecks.controller.js +570 -0
- package/src/controllers/adminI18n.controller.js +51 -29
- package/src/controllers/adminLlm.controller.js +126 -2
- package/src/controllers/adminPages.controller.js +720 -0
- package/src/controllers/adminPagesContextBlocksAi.controller.js +54 -0
- package/src/controllers/adminProxy.controller.js +113 -0
- package/src/controllers/adminRateLimits.controller.js +138 -0
- package/src/controllers/adminRbac.controller.js +803 -0
- package/src/controllers/adminScripts.controller.js +320 -0
- package/src/controllers/adminSeoConfig.controller.js +71 -48
- package/src/controllers/adminTerminals.controller.js +39 -0
- package/src/controllers/adminUiComponents.controller.js +315 -0
- package/src/controllers/adminUiComponentsAi.controller.js +34 -0
- package/src/controllers/blogAdmin.controller.js +279 -0
- package/src/controllers/blogAiAdmin.controller.js +224 -0
- package/src/controllers/blogAutomationAdmin.controller.js +141 -0
- package/src/controllers/blogInternal.controller.js +26 -0
- package/src/controllers/blogPublic.controller.js +89 -0
- package/src/controllers/fileManager.controller.js +190 -0
- package/src/controllers/fileManagerStoragePolicy.controller.js +23 -0
- package/src/controllers/healthChecksPublic.controller.js +196 -0
- package/src/controllers/metrics.controller.js +64 -4
- package/src/controllers/orgAdmin.controller.js +366 -0
- package/src/controllers/uiComponentsPublic.controller.js +118 -0
- package/src/middleware/auth.js +7 -0
- package/src/middleware/internalCronAuth.js +29 -0
- package/src/middleware/rbac.js +62 -0
- package/src/middleware.js +879 -56
- package/src/models/BlockDefinition.js +27 -0
- package/src/models/BlogAutomationLock.js +14 -0
- package/src/models/BlogAutomationRun.js +39 -0
- package/src/models/BlogPost.js +42 -0
- package/src/models/CacheEntry.js +26 -0
- package/src/models/ConsoleEntry.js +32 -0
- package/src/models/ConsoleLog.js +23 -0
- package/src/models/ContextBlockDefinition.js +33 -0
- package/src/models/CronExecution.js +47 -0
- package/src/models/CronJob.js +70 -0
- package/src/models/ExternalDbConnection.js +49 -0
- package/src/models/FileEntry.js +22 -0
- package/src/models/HeadlessModelDefinition.js +10 -0
- package/src/models/HealthAutoHealAttempt.js +57 -0
- package/src/models/HealthCheck.js +132 -0
- package/src/models/HealthCheckRun.js +51 -0
- package/src/models/HealthIncident.js +49 -0
- package/src/models/Page.js +95 -0
- package/src/models/PageCollection.js +42 -0
- package/src/models/ProxyEntry.js +66 -0
- package/src/models/RateLimitCounter.js +19 -0
- package/src/models/RateLimitMetricBucket.js +20 -0
- package/src/models/RbacGrant.js +25 -0
- package/src/models/RbacGroup.js +16 -0
- package/src/models/RbacGroupMember.js +13 -0
- package/src/models/RbacGroupRole.js +13 -0
- package/src/models/RbacRole.js +25 -0
- package/src/models/RbacUserRole.js +13 -0
- package/src/models/ScriptDefinition.js +42 -0
- package/src/models/ScriptRun.js +22 -0
- package/src/models/UiComponent.js +29 -0
- package/src/models/UiComponentProject.js +26 -0
- package/src/models/UiComponentProjectComponent.js +18 -0
- package/src/routes/admin.routes.js +1 -0
- package/src/routes/adminBlog.routes.js +21 -0
- package/src/routes/adminBlogAi.routes.js +16 -0
- package/src/routes/adminBlogAutomation.routes.js +27 -0
- package/src/routes/adminCache.routes.js +20 -0
- package/src/routes/adminConsoleManager.routes.js +302 -0
- package/src/routes/adminCrons.routes.js +25 -0
- package/src/routes/adminDbBrowser.routes.js +65 -0
- package/src/routes/adminEjsVirtual.routes.js +2 -1
- package/src/routes/adminHeadless.routes.js +8 -1
- package/src/routes/adminHealthChecks.routes.js +28 -0
- package/src/routes/adminI18n.routes.js +4 -3
- package/src/routes/adminLlm.routes.js +4 -2
- package/src/routes/adminPages.routes.js +55 -0
- package/src/routes/adminProxy.routes.js +15 -0
- package/src/routes/adminRateLimits.routes.js +17 -0
- package/src/routes/adminRbac.routes.js +38 -0
- package/src/routes/adminScripts.routes.js +21 -0
- package/src/routes/adminSeoConfig.routes.js +5 -4
- package/src/routes/adminTerminals.routes.js +13 -0
- package/src/routes/adminUiComponents.routes.js +30 -0
- package/src/routes/blogInternal.routes.js +14 -0
- package/src/routes/blogPublic.routes.js +9 -0
- package/src/routes/fileManager.routes.js +62 -0
- package/src/routes/fileManagerStoragePolicy.routes.js +9 -0
- package/src/routes/healthChecksPublic.routes.js +9 -0
- package/src/routes/log.routes.js +43 -60
- package/src/routes/metrics.routes.js +4 -2
- package/src/routes/orgAdmin.routes.js +6 -0
- package/src/routes/pages.routes.js +123 -0
- package/src/routes/proxy.routes.js +46 -0
- package/src/routes/rbac.routes.js +47 -0
- package/src/routes/uiComponentsPublic.routes.js +9 -0
- package/src/routes/webhook.routes.js +2 -1
- package/src/routes/workflows.routes.js +4 -0
- package/src/services/blockDefinitionsAi.service.js +247 -0
- package/src/services/blog.service.js +99 -0
- package/src/services/blogAutomation.service.js +978 -0
- package/src/services/blogCronsBootstrap.service.js +184 -0
- package/src/services/blogPublishing.service.js +58 -0
- package/src/services/cacheLayer.service.js +696 -0
- package/src/services/consoleManager.service.js +700 -0
- package/src/services/consoleOverride.service.js +6 -1
- package/src/services/cronScheduler.service.js +350 -0
- package/src/services/dbBrowser.service.js +536 -0
- package/src/services/ejsVirtual.service.js +102 -32
- package/src/services/fileManager.service.js +475 -0
- package/src/services/fileManagerStoragePolicy.service.js +285 -0
- package/src/services/headlessExternalModels.service.js +292 -0
- package/src/services/headlessModels.service.js +26 -6
- package/src/services/healthChecks.service.js +650 -0
- package/src/services/healthChecksBootstrap.service.js +109 -0
- package/src/services/healthChecksScheduler.service.js +106 -0
- package/src/services/llmDefaults.service.js +190 -0
- package/src/services/migrationAssets/s3.js +2 -2
- package/src/services/pages.service.js +602 -0
- package/src/services/pagesContext.service.js +331 -0
- package/src/services/pagesContextBlocksAi.service.js +349 -0
- package/src/services/proxy.service.js +535 -0
- package/src/services/rateLimiter.service.js +623 -0
- package/src/services/rbac.service.js +212 -0
- package/src/services/scriptsRunner.service.js +259 -0
- package/src/services/terminals.service.js +152 -0
- package/src/services/terminalsWs.service.js +100 -0
- package/src/services/uiComponentsAi.service.js +299 -0
- package/src/services/uiComponentsCrypto.service.js +39 -0
- package/src/services/workflow.service.js +23 -8
- package/src/utils/orgRoles.js +14 -0
- package/src/utils/rbac/engine.js +60 -0
- package/src/utils/rbac/rightsRegistry.js +29 -0
- package/views/admin-blog-automation.ejs +877 -0
- package/views/admin-blog-edit.ejs +542 -0
- package/views/admin-blog.ejs +399 -0
- package/views/admin-cache.ejs +681 -0
- package/views/admin-console-manager.ejs +680 -0
- package/views/admin-crons.ejs +645 -0
- package/views/admin-db-browser.ejs +445 -0
- package/views/admin-ejs-virtual.ejs +16 -10
- package/views/admin-file-manager.ejs +942 -0
- package/views/admin-headless.ejs +294 -24
- package/views/admin-health-checks.ejs +725 -0
- package/views/admin-i18n.ejs +59 -5
- package/views/admin-llm.ejs +99 -1
- package/views/admin-organizations.ejs +528 -10
- package/views/admin-pages.ejs +2424 -0
- package/views/admin-proxy.ejs +491 -0
- package/views/admin-rate-limiter.ejs +625 -0
- package/views/admin-rbac.ejs +1331 -0
- package/views/admin-scripts.ejs +497 -0
- package/views/admin-seo-config.ejs +61 -7
- package/views/admin-terminals.ejs +328 -0
- package/views/admin-ui-components.ejs +741 -0
- package/views/admin-users.ejs +261 -4
- package/views/admin-workflows.ejs +7 -7
- package/views/file-manager.ejs +866 -0
- package/views/pages/blocks/contact.ejs +27 -0
- package/views/pages/blocks/cta.ejs +18 -0
- package/views/pages/blocks/faq.ejs +20 -0
- package/views/pages/blocks/features.ejs +19 -0
- package/views/pages/blocks/hero.ejs +13 -0
- package/views/pages/blocks/html.ejs +5 -0
- package/views/pages/blocks/image.ejs +14 -0
- package/views/pages/blocks/testimonials.ejs +26 -0
- package/views/pages/blocks/text.ejs +10 -0
- package/views/pages/layouts/default.ejs +51 -0
- package/views/pages/layouts/minimal.ejs +42 -0
- package/views/pages/layouts/sidebar.ejs +54 -0
- package/views/pages/partials/footer.ejs +13 -0
- package/views/pages/partials/header.ejs +12 -0
- package/views/pages/partials/sidebar.ejs +8 -0
- package/views/pages/runtime/page.ejs +10 -0
- package/views/pages/templates/article.ejs +20 -0
- package/views/pages/templates/default.ejs +12 -0
- package/views/pages/templates/landing.ejs +14 -0
- package/views/pages/templates/listing.ejs +15 -0
- package/views/partials/admin-image-upload-modal.ejs +221 -0
- package/views/partials/dashboard/nav-items.ejs +14 -0
- package/views/partials/llm-provider-model-picker.ejs +183 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const blockDefinitionSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
code: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: true,
|
|
8
|
+
unique: true,
|
|
9
|
+
index: true,
|
|
10
|
+
trim: true,
|
|
11
|
+
lowercase: true,
|
|
12
|
+
match: [/^[a-z][a-z0-9_-]{1,63}$/, 'Invalid block code'],
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
label: { type: String, required: true, trim: true },
|
|
16
|
+
description: { type: String, default: '' },
|
|
17
|
+
|
|
18
|
+
// Fields schema (server-side validation happens in services)
|
|
19
|
+
fields: { type: mongoose.Schema.Types.Mixed, default: {} },
|
|
20
|
+
|
|
21
|
+
version: { type: Number, default: 1 },
|
|
22
|
+
isActive: { type: Boolean, default: true, index: true },
|
|
23
|
+
},
|
|
24
|
+
{ timestamps: true, collection: 'page_builder_block_definitions' },
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
module.exports = mongoose.models.BlockDefinition || mongoose.model('BlockDefinition', blockDefinitionSchema);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const blogAutomationLockSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
key: { type: String, required: true, unique: true, index: true },
|
|
6
|
+
lockedUntil: { type: Date, required: true },
|
|
7
|
+
ownerId: { type: String, required: true },
|
|
8
|
+
},
|
|
9
|
+
{ timestamps: true, collection: 'blog_automation_locks' },
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
module.exports =
|
|
13
|
+
mongoose.models.BlogAutomationLock ||
|
|
14
|
+
mongoose.model('BlogAutomationLock', blogAutomationLockSchema);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const blogAutomationRunSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
status: {
|
|
6
|
+
type: String,
|
|
7
|
+
enum: ['queued', 'running', 'succeeded', 'failed', 'partial', 'skipped'],
|
|
8
|
+
default: 'queued',
|
|
9
|
+
index: true,
|
|
10
|
+
},
|
|
11
|
+
configId: {
|
|
12
|
+
type: String,
|
|
13
|
+
default: '',
|
|
14
|
+
index: true,
|
|
15
|
+
},
|
|
16
|
+
trigger: {
|
|
17
|
+
type: String,
|
|
18
|
+
enum: ['scheduled', 'manual'],
|
|
19
|
+
required: true,
|
|
20
|
+
index: true,
|
|
21
|
+
},
|
|
22
|
+
startedAt: { type: Date },
|
|
23
|
+
finishedAt: { type: Date },
|
|
24
|
+
configSnapshot: { type: mongoose.Schema.Types.Mixed, default: {} },
|
|
25
|
+
topic: { type: mongoose.Schema.Types.Mixed, default: {} },
|
|
26
|
+
results: { type: mongoose.Schema.Types.Mixed, default: {} },
|
|
27
|
+
steps: { type: [mongoose.Schema.Types.Mixed], default: [] },
|
|
28
|
+
error: { type: String, default: '' },
|
|
29
|
+
},
|
|
30
|
+
{ timestamps: true, collection: 'blog_automation_runs' },
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
blogAutomationRunSchema.index({ createdAt: -1 });
|
|
34
|
+
blogAutomationRunSchema.index({ trigger: 1, createdAt: -1 });
|
|
35
|
+
blogAutomationRunSchema.index({ configId: 1, createdAt: -1 });
|
|
36
|
+
|
|
37
|
+
module.exports =
|
|
38
|
+
mongoose.models.BlogAutomationRun ||
|
|
39
|
+
mongoose.model('BlogAutomationRun', blogAutomationRunSchema);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const blogPostSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
title: { type: String, required: true },
|
|
6
|
+
slug: { type: String, required: true, index: true },
|
|
7
|
+
status: {
|
|
8
|
+
type: String,
|
|
9
|
+
enum: ['draft', 'scheduled', 'published', 'archived'],
|
|
10
|
+
default: 'draft',
|
|
11
|
+
index: true,
|
|
12
|
+
},
|
|
13
|
+
excerpt: { type: String, default: '' },
|
|
14
|
+
markdown: { type: String, default: '' },
|
|
15
|
+
html: { type: String, default: '' },
|
|
16
|
+
coverImageUrl: { type: String, default: '' },
|
|
17
|
+
category: { type: String, default: '' },
|
|
18
|
+
tags: { type: [String], default: [] },
|
|
19
|
+
authorName: { type: String, default: '' },
|
|
20
|
+
seoTitle: { type: String, default: '' },
|
|
21
|
+
seoDescription: { type: String, default: '' },
|
|
22
|
+
scheduledAt: { type: Date },
|
|
23
|
+
publishedAt: { type: Date },
|
|
24
|
+
},
|
|
25
|
+
{ timestamps: true, collection: 'blog_posts' },
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
blogPostSchema.index({ status: 1, publishedAt: -1 });
|
|
29
|
+
blogPostSchema.index({ status: 1, scheduledAt: 1 });
|
|
30
|
+
|
|
31
|
+
// Enforce slug uniqueness among non-archived posts. Archived posts free up slugs.
|
|
32
|
+
blogPostSchema.index(
|
|
33
|
+
{ slug: 1 },
|
|
34
|
+
{
|
|
35
|
+
unique: true,
|
|
36
|
+
partialFilterExpression: {
|
|
37
|
+
status: { $in: ['draft', 'scheduled', 'published'] },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
module.exports = mongoose.models.BlogPost || mongoose.model('BlogPost', blogPostSchema);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const cacheEntrySchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
namespace: { type: String, required: true, index: true },
|
|
6
|
+
key: { type: String, required: true, index: true },
|
|
7
|
+
|
|
8
|
+
value: { type: String, required: true },
|
|
9
|
+
atRestFormat: { type: String, enum: ['string', 'base64'], default: 'string', index: true },
|
|
10
|
+
|
|
11
|
+
sizeBytes: { type: Number, default: 0 },
|
|
12
|
+
|
|
13
|
+
expiresAt: { type: Date, default: null, index: true },
|
|
14
|
+
|
|
15
|
+
hits: { type: Number, default: 0 },
|
|
16
|
+
lastAccessAt: { type: Date, default: null },
|
|
17
|
+
|
|
18
|
+
source: { type: String, enum: ['offloaded', 'manual'], default: 'manual', index: true },
|
|
19
|
+
},
|
|
20
|
+
{ timestamps: true, collection: 'cache_entries' },
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
cacheEntrySchema.index({ namespace: 1, key: 1 }, { unique: true });
|
|
24
|
+
cacheEntrySchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
|
|
25
|
+
|
|
26
|
+
module.exports = mongoose.models.CacheEntry || mongoose.model('CacheEntry', cacheEntrySchema);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const consoleEntrySchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
hash: { type: String, required: true, unique: true, index: true },
|
|
6
|
+
method: { type: String, enum: ['debug', 'log', 'info', 'warn', 'error'], required: true, index: true },
|
|
7
|
+
|
|
8
|
+
messageTemplate: { type: String, default: '', maxlength: 500 },
|
|
9
|
+
topFrame: { type: String, default: '' },
|
|
10
|
+
|
|
11
|
+
enabled: { type: Boolean, default: true, index: true },
|
|
12
|
+
enabledExplicit: { type: Boolean, default: false, index: true },
|
|
13
|
+
|
|
14
|
+
persistToCache: { type: Boolean, default: false },
|
|
15
|
+
persistToDb: { type: Boolean, default: false },
|
|
16
|
+
persistExplicit: { type: Boolean, default: false, index: true },
|
|
17
|
+
|
|
18
|
+
tags: { type: [String], default: [], index: true },
|
|
19
|
+
|
|
20
|
+
countTotal: { type: Number, default: 0 },
|
|
21
|
+
firstSeenAt: { type: Date, default: Date.now },
|
|
22
|
+
lastSeenAt: { type: Date, default: Date.now, index: true },
|
|
23
|
+
|
|
24
|
+
lastSample: { type: mongoose.Schema.Types.Mixed, default: null },
|
|
25
|
+
},
|
|
26
|
+
{ timestamps: true, collection: 'console_entries' },
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
consoleEntrySchema.index({ method: 1, lastSeenAt: -1 });
|
|
30
|
+
consoleEntrySchema.index({ enabled: 1, lastSeenAt: -1 });
|
|
31
|
+
|
|
32
|
+
module.exports = mongoose.models.ConsoleEntry || mongoose.model('ConsoleEntry', consoleEntrySchema);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const consoleLogSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
entryHash: { type: String, required: true, index: true },
|
|
6
|
+
method: { type: String, enum: ['debug', 'log', 'info', 'warn', 'error'], required: true, index: true },
|
|
7
|
+
|
|
8
|
+
message: { type: String, default: '', maxlength: 2000 },
|
|
9
|
+
argsPreview: { type: String, default: '', maxlength: 5000 },
|
|
10
|
+
|
|
11
|
+
tagsSnapshot: { type: [String], default: [], index: true },
|
|
12
|
+
requestId: { type: String, default: '', index: true },
|
|
13
|
+
|
|
14
|
+
createdAt: { type: Date, default: Date.now, index: true },
|
|
15
|
+
expiresAt: { type: Date, default: null, index: true },
|
|
16
|
+
},
|
|
17
|
+
{ timestamps: false, collection: 'console_logs' },
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
consoleLogSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
|
|
21
|
+
consoleLogSchema.index({ entryHash: 1, createdAt: -1 });
|
|
22
|
+
|
|
23
|
+
module.exports = mongoose.models.ConsoleLog || mongoose.model('ConsoleLog', consoleLogSchema);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const contextBlockDefinitionSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
code: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: true,
|
|
8
|
+
unique: true,
|
|
9
|
+
index: true,
|
|
10
|
+
trim: true,
|
|
11
|
+
lowercase: true,
|
|
12
|
+
match: [/^[a-z][a-z0-9_-]{1,63}$/, 'Invalid context block code'],
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
label: { type: String, required: true, trim: true },
|
|
16
|
+
description: { type: String, default: '' },
|
|
17
|
+
|
|
18
|
+
type: {
|
|
19
|
+
type: String,
|
|
20
|
+
required: true,
|
|
21
|
+
enum: ['context.db_query', 'context.service_invoke'],
|
|
22
|
+
index: true,
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
props: { type: mongoose.Schema.Types.Mixed, default: {} },
|
|
26
|
+
|
|
27
|
+
version: { type: Number, default: 1 },
|
|
28
|
+
isActive: { type: Boolean, default: true, index: true },
|
|
29
|
+
},
|
|
30
|
+
{ timestamps: true, collection: 'page_builder_context_block_definitions' },
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
module.exports = mongoose.models.ContextBlockDefinition || mongoose.model('ContextBlockDefinition', contextBlockDefinitionSchema);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const cronExecutionSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
cronJobId: { type: mongoose.Schema.Types.ObjectId, ref: 'CronJob', required: true, index: true },
|
|
6
|
+
|
|
7
|
+
// Execution details
|
|
8
|
+
status: {
|
|
9
|
+
type: String,
|
|
10
|
+
enum: ['running', 'succeeded', 'failed', 'timed_out'],
|
|
11
|
+
default: 'running',
|
|
12
|
+
index: true
|
|
13
|
+
},
|
|
14
|
+
startedAt: { type: Date, default: Date.now, index: true },
|
|
15
|
+
finishedAt: { type: Date },
|
|
16
|
+
durationMs: { type: Number },
|
|
17
|
+
|
|
18
|
+
// Results
|
|
19
|
+
output: { type: String },
|
|
20
|
+
error: { type: String },
|
|
21
|
+
|
|
22
|
+
// HTTP specific
|
|
23
|
+
httpStatusCode: { type: Number },
|
|
24
|
+
httpResponseHeaders: { type: mongoose.Schema.Types.Mixed },
|
|
25
|
+
|
|
26
|
+
// Metadata
|
|
27
|
+
triggeredAt: { type: Date, required: true }, // When it was supposed to run
|
|
28
|
+
actualRunAt: { type: Date, default: Date.now }, // When it actually started
|
|
29
|
+
},
|
|
30
|
+
{ timestamps: true, collection: 'cron_executions' },
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
// Index for efficient queries
|
|
34
|
+
cronExecutionSchema.index({ cronJobId: 1, startedAt: -1 });
|
|
35
|
+
cronExecutionSchema.index({ status: 1, startedAt: -1 });
|
|
36
|
+
|
|
37
|
+
// Calculate duration before saving
|
|
38
|
+
cronExecutionSchema.pre('save', function preSave(next) {
|
|
39
|
+
if (this.isModified('finishedAt') && this.finishedAt && this.startedAt) {
|
|
40
|
+
this.durationMs = this.finishedAt.getTime() - this.startedAt.getTime();
|
|
41
|
+
}
|
|
42
|
+
next();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
module.exports =
|
|
46
|
+
mongoose.models.CronExecution ||
|
|
47
|
+
mongoose.model('CronExecution', cronExecutionSchema);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const envVarSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
key: { type: String, required: true },
|
|
6
|
+
value: { type: String, required: true },
|
|
7
|
+
},
|
|
8
|
+
{ _id: false },
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const httpHeaderSchema = new mongoose.Schema(
|
|
12
|
+
{
|
|
13
|
+
key: { type: String, required: true },
|
|
14
|
+
value: { type: String, required: true },
|
|
15
|
+
},
|
|
16
|
+
{ _id: false },
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const httpAuthSchema = new mongoose.Schema(
|
|
20
|
+
{
|
|
21
|
+
type: { type: String, enum: ['bearer', 'basic', 'none'], default: 'none' },
|
|
22
|
+
token: { type: String },
|
|
23
|
+
username: { type: String },
|
|
24
|
+
password: { type: String },
|
|
25
|
+
},
|
|
26
|
+
{ _id: false },
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const cronJobSchema = new mongoose.Schema(
|
|
30
|
+
{
|
|
31
|
+
name: { type: String, required: true },
|
|
32
|
+
description: { type: String, default: '' },
|
|
33
|
+
|
|
34
|
+
// Schedule configuration
|
|
35
|
+
cronExpression: { type: String, required: true },
|
|
36
|
+
timezone: { type: String, default: 'UTC' },
|
|
37
|
+
enabled: { type: Boolean, default: true, index: true },
|
|
38
|
+
nextRunAt: { type: Date, index: true },
|
|
39
|
+
|
|
40
|
+
// Task configuration
|
|
41
|
+
taskType: { type: String, enum: ['script', 'http'], required: true },
|
|
42
|
+
|
|
43
|
+
// Script task fields
|
|
44
|
+
scriptId: { type: mongoose.Schema.Types.ObjectId, ref: 'ScriptDefinition' },
|
|
45
|
+
scriptEnv: { type: [envVarSchema], default: [] },
|
|
46
|
+
|
|
47
|
+
// HTTP task fields
|
|
48
|
+
httpMethod: { type: String, enum: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'], default: 'GET' },
|
|
49
|
+
httpUrl: { type: String, required: function() { return this.taskType === 'http'; } },
|
|
50
|
+
httpHeaders: { type: [httpHeaderSchema], default: [] },
|
|
51
|
+
httpBody: { type: String },
|
|
52
|
+
httpBodyType: { type: String, enum: ['json', 'raw', 'form'], default: 'raw' },
|
|
53
|
+
httpAuth: { type: httpAuthSchema, default: () => ({}) },
|
|
54
|
+
|
|
55
|
+
// Common fields
|
|
56
|
+
timeoutMs: { type: Number, default: 300000 }, // 5 minutes
|
|
57
|
+
|
|
58
|
+
// Metadata
|
|
59
|
+
createdBy: { type: String, required: true },
|
|
60
|
+
},
|
|
61
|
+
{ timestamps: true, collection: 'cron_jobs' },
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// Index for efficient queries
|
|
65
|
+
cronJobSchema.index({ taskType: 1, enabled: 1 });
|
|
66
|
+
cronJobSchema.index({ nextRunAt: 1, enabled: 1 });
|
|
67
|
+
|
|
68
|
+
module.exports =
|
|
69
|
+
mongoose.models.CronJob ||
|
|
70
|
+
mongoose.model('CronJob', cronJobSchema);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const externalDbConnectionSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
name: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: true,
|
|
8
|
+
unique: true,
|
|
9
|
+
trim: true,
|
|
10
|
+
index: true,
|
|
11
|
+
},
|
|
12
|
+
type: {
|
|
13
|
+
type: String,
|
|
14
|
+
required: true,
|
|
15
|
+
enum: ['mongo', 'mysql'],
|
|
16
|
+
index: true,
|
|
17
|
+
},
|
|
18
|
+
enabled: {
|
|
19
|
+
type: Boolean,
|
|
20
|
+
default: true,
|
|
21
|
+
index: true,
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
// Non-secret (safe to return)
|
|
25
|
+
uriMasked: {
|
|
26
|
+
type: String,
|
|
27
|
+
default: null,
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
// Encrypted at rest (NEVER return decrypted)
|
|
31
|
+
uriEncrypted: {
|
|
32
|
+
type: mongoose.Schema.Types.Mixed,
|
|
33
|
+
required: true,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
timestamps: true,
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
externalDbConnectionSchema.set('toJSON', {
|
|
42
|
+
transform: (_doc, ret) => {
|
|
43
|
+
delete ret.uriEncrypted;
|
|
44
|
+
delete ret.__v;
|
|
45
|
+
return ret;
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
module.exports = mongoose.model('ExternalDbConnection', externalDbConnectionSchema);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const fileEntrySchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
orgId: { type: mongoose.Schema.Types.ObjectId, ref: 'Organization', required: true, index: true },
|
|
6
|
+
driveType: { type: String, enum: ['user', 'group', 'org'], required: true, index: true },
|
|
7
|
+
driveId: { type: mongoose.Schema.Types.ObjectId, required: true, index: true },
|
|
8
|
+
parentPath: { type: String, required: true, default: '/', index: true },
|
|
9
|
+
name: { type: String, required: true },
|
|
10
|
+
assetId: { type: mongoose.Schema.Types.ObjectId, ref: 'Asset', required: true, index: true },
|
|
11
|
+
visibility: { type: String, enum: ['public', 'private'], required: true, default: 'private', index: true },
|
|
12
|
+
deletedAt: { type: Date, default: null, index: true },
|
|
13
|
+
},
|
|
14
|
+
{ timestamps: true, collection: 'file_entries' },
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
fileEntrySchema.index(
|
|
18
|
+
{ orgId: 1, driveType: 1, driveId: 1, parentPath: 1, name: 1 },
|
|
19
|
+
{ unique: true, partialFilterExpression: { deletedAt: null } },
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
module.exports = mongoose.models.FileEntry || mongoose.model('FileEntry', fileEntrySchema);
|
|
@@ -28,6 +28,16 @@ const headlessModelDefinitionSchema = new mongoose.Schema(
|
|
|
28
28
|
description: { type: String, default: '' },
|
|
29
29
|
fields: { type: [headlessFieldSchema], default: [] },
|
|
30
30
|
indexes: { type: [headlessIndexSchema], default: [] },
|
|
31
|
+
sourceType: { type: String, enum: ['internal', 'external'], default: 'internal', index: true },
|
|
32
|
+
sourceCollectionName: { type: String, default: null, index: true },
|
|
33
|
+
isExternal: { type: Boolean, default: false, index: true },
|
|
34
|
+
inference: {
|
|
35
|
+
enabled: { type: Boolean, default: false },
|
|
36
|
+
lastInferredAt: { type: Date, default: null },
|
|
37
|
+
sampleSize: { type: Number, default: null },
|
|
38
|
+
warnings: { type: [String], default: [] },
|
|
39
|
+
stats: { type: mongoose.Schema.Types.Mixed, default: null },
|
|
40
|
+
},
|
|
31
41
|
isActive: { type: Boolean, default: true, index: true },
|
|
32
42
|
version: { type: Number, default: 1 },
|
|
33
43
|
fieldsHash: { type: String, default: null },
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const actionResultSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
actionType: { type: String, default: '' },
|
|
6
|
+
status: { type: String, enum: ['succeeded', 'failed'], required: true },
|
|
7
|
+
output: { type: String, default: '' },
|
|
8
|
+
error: { type: String, default: '' },
|
|
9
|
+
},
|
|
10
|
+
{ _id: false },
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const healthAutoHealAttemptSchema = new mongoose.Schema(
|
|
14
|
+
{
|
|
15
|
+
healthCheckId: {
|
|
16
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
17
|
+
ref: 'HealthCheck',
|
|
18
|
+
required: true,
|
|
19
|
+
index: true,
|
|
20
|
+
},
|
|
21
|
+
incidentId: {
|
|
22
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
23
|
+
ref: 'HealthIncident',
|
|
24
|
+
required: true,
|
|
25
|
+
index: true,
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
attemptNumber: { type: Number, required: true },
|
|
29
|
+
|
|
30
|
+
status: {
|
|
31
|
+
type: String,
|
|
32
|
+
enum: ['running', 'succeeded', 'failed'],
|
|
33
|
+
default: 'running',
|
|
34
|
+
index: true,
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
startedAt: { type: Date, default: Date.now, index: true },
|
|
38
|
+
finishedAt: { type: Date },
|
|
39
|
+
durationMs: { type: Number },
|
|
40
|
+
|
|
41
|
+
actionResults: { type: [actionResultSchema], default: [] },
|
|
42
|
+
},
|
|
43
|
+
{ timestamps: true, collection: 'health_autoheal_attempts' },
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
healthAutoHealAttemptSchema.index({ incidentId: 1, startedAt: -1 });
|
|
47
|
+
|
|
48
|
+
healthAutoHealAttemptSchema.pre('save', function preSave(next) {
|
|
49
|
+
if (this.isModified('finishedAt') && this.finishedAt && this.startedAt) {
|
|
50
|
+
this.durationMs = this.finishedAt.getTime() - this.startedAt.getTime();
|
|
51
|
+
}
|
|
52
|
+
next();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
module.exports =
|
|
56
|
+
mongoose.models.HealthAutoHealAttempt ||
|
|
57
|
+
mongoose.model('HealthAutoHealAttempt', healthAutoHealAttemptSchema);
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const envVarSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
key: { type: String, required: true },
|
|
6
|
+
value: { type: String, required: true },
|
|
7
|
+
},
|
|
8
|
+
{ _id: false },
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const httpHeaderSchema = new mongoose.Schema(
|
|
12
|
+
{
|
|
13
|
+
key: { type: String, required: true },
|
|
14
|
+
value: { type: String, required: true },
|
|
15
|
+
},
|
|
16
|
+
{ _id: false },
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const httpAuthRefSchema = new mongoose.Schema(
|
|
20
|
+
{
|
|
21
|
+
type: { type: String, enum: ['bearer', 'basic', 'none'], default: 'none' },
|
|
22
|
+
|
|
23
|
+
// For basic auth we store the username in the HealthCheck doc,
|
|
24
|
+
// but keep sensitive values in encrypted GlobalSettings.
|
|
25
|
+
username: { type: String },
|
|
26
|
+
|
|
27
|
+
// References to GlobalSetting keys (type='encrypted')
|
|
28
|
+
tokenSettingKey: { type: String },
|
|
29
|
+
passwordSettingKey: { type: String },
|
|
30
|
+
},
|
|
31
|
+
{ _id: false },
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const autoHealActionSchema = new mongoose.Schema(
|
|
35
|
+
{
|
|
36
|
+
type: { type: String, enum: ['http', 'script', 'notify_only'], required: true },
|
|
37
|
+
name: { type: String, default: '' },
|
|
38
|
+
|
|
39
|
+
// http action
|
|
40
|
+
httpMethod: { type: String, enum: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'], default: 'POST' },
|
|
41
|
+
httpUrl: { type: String },
|
|
42
|
+
httpHeaders: { type: [httpHeaderSchema], default: [] },
|
|
43
|
+
httpBody: { type: String, default: '' },
|
|
44
|
+
httpBodyType: { type: String, enum: ['json', 'raw', 'form'], default: 'raw' },
|
|
45
|
+
httpAuth: { type: httpAuthRefSchema, default: () => ({}) },
|
|
46
|
+
timeoutMs: { type: Number },
|
|
47
|
+
|
|
48
|
+
// script action
|
|
49
|
+
scriptId: { type: mongoose.Schema.Types.ObjectId, ref: 'ScriptDefinition' },
|
|
50
|
+
scriptEnv: { type: [envVarSchema], default: [] },
|
|
51
|
+
},
|
|
52
|
+
{ _id: false },
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const healthCheckSchema = new mongoose.Schema(
|
|
56
|
+
{
|
|
57
|
+
name: { type: String, required: true },
|
|
58
|
+
description: { type: String, default: '' },
|
|
59
|
+
|
|
60
|
+
enabled: { type: Boolean, default: true, index: true },
|
|
61
|
+
|
|
62
|
+
cronExpression: { type: String, required: true },
|
|
63
|
+
timezone: { type: String, default: 'UTC' },
|
|
64
|
+
nextRunAt: { type: Date, index: true },
|
|
65
|
+
|
|
66
|
+
checkType: { type: String, enum: ['http', 'script', 'internal'], required: true },
|
|
67
|
+
|
|
68
|
+
// Common
|
|
69
|
+
timeoutMs: { type: Number, default: 30000 },
|
|
70
|
+
|
|
71
|
+
// HTTP check
|
|
72
|
+
httpMethod: { type: String, enum: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'], default: 'GET' },
|
|
73
|
+
httpUrl: { type: String, required: function requiredHttpUrl() { return this.checkType === 'http'; } },
|
|
74
|
+
httpHeaders: { type: [httpHeaderSchema], default: [] },
|
|
75
|
+
httpBody: { type: String, default: '' },
|
|
76
|
+
httpBodyType: { type: String, enum: ['json', 'raw', 'form'], default: 'raw' },
|
|
77
|
+
httpAuth: { type: httpAuthRefSchema, default: () => ({}) },
|
|
78
|
+
|
|
79
|
+
// Script check
|
|
80
|
+
scriptId: { type: mongoose.Schema.Types.ObjectId, ref: 'ScriptDefinition' },
|
|
81
|
+
scriptEnv: { type: [envVarSchema], default: [] },
|
|
82
|
+
|
|
83
|
+
// Evaluation
|
|
84
|
+
expectedStatusCodes: { type: [Number], default: [200] },
|
|
85
|
+
maxLatencyMs: { type: Number },
|
|
86
|
+
bodyMustMatch: { type: String },
|
|
87
|
+
bodyMustNotMatch: { type: String },
|
|
88
|
+
|
|
89
|
+
consecutiveFailuresToOpen: { type: Number, default: 3 },
|
|
90
|
+
consecutiveSuccessesToResolve: { type: Number, default: 2 },
|
|
91
|
+
|
|
92
|
+
retries: { type: Number, default: 0 },
|
|
93
|
+
retryDelayMs: { type: Number, default: 0 },
|
|
94
|
+
|
|
95
|
+
// Alerting
|
|
96
|
+
notifyOnOpen: { type: Boolean, default: true },
|
|
97
|
+
notifyOnResolve: { type: Boolean, default: true },
|
|
98
|
+
notifyOnEscalation: { type: Boolean, default: false },
|
|
99
|
+
notificationChannel: { type: String, enum: ['in_app', 'email', 'both'], default: 'in_app' },
|
|
100
|
+
notifyUserIds: { type: [mongoose.Schema.Types.ObjectId], ref: 'User', default: [] },
|
|
101
|
+
suppressNotificationsWhenAcknowledged: { type: Boolean, default: true },
|
|
102
|
+
|
|
103
|
+
// Auto-heal
|
|
104
|
+
autoHealEnabled: { type: Boolean, default: false },
|
|
105
|
+
autoHealWaitMs: { type: Number, default: 0 },
|
|
106
|
+
autoHealCooldownMs: { type: Number, default: 5 * 60 * 1000 },
|
|
107
|
+
autoHealMaxAttemptsPerIncident: { type: Number, default: 3 },
|
|
108
|
+
autoHealBackoffPolicy: { type: String, enum: ['fixed', 'exponential'], default: 'fixed' },
|
|
109
|
+
autoHealBackoffMs: { type: Number, default: 60 * 1000 },
|
|
110
|
+
autoHealActions: { type: [autoHealActionSchema], default: [] },
|
|
111
|
+
|
|
112
|
+
// Operational
|
|
113
|
+
lastRunAt: { type: Date },
|
|
114
|
+
lastStatus: { type: String, enum: ['healthy', 'unhealthy', 'unknown'], default: 'unknown' },
|
|
115
|
+
lastLatencyMs: { type: Number },
|
|
116
|
+
currentIncidentId: { type: mongoose.Schema.Types.ObjectId, ref: 'HealthIncident' },
|
|
117
|
+
|
|
118
|
+
// Streaks (persisted to avoid expensive queries when deciding to open/resolve incidents)
|
|
119
|
+
consecutiveFailureCount: { type: Number, default: 0 },
|
|
120
|
+
consecutiveSuccessCount: { type: Number, default: 0 },
|
|
121
|
+
|
|
122
|
+
createdBy: { type: String, required: true },
|
|
123
|
+
},
|
|
124
|
+
{ timestamps: true, collection: 'health_checks' },
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
healthCheckSchema.index({ enabled: 1, nextRunAt: 1 });
|
|
128
|
+
healthCheckSchema.index({ checkType: 1, enabled: 1 });
|
|
129
|
+
|
|
130
|
+
module.exports =
|
|
131
|
+
mongoose.models.HealthCheck ||
|
|
132
|
+
mongoose.model('HealthCheck', healthCheckSchema);
|