-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobjectstack.config.ts
More file actions
150 lines (141 loc) · 5.04 KB
/
objectstack.config.ts
File metadata and controls
150 lines (141 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { defineStack } from '@objectstack/spec';
import { AppPlugin, DriverPlugin } from '@objectstack/runtime';
import { ObjectQLPlugin } from '@objectstack/objectql';
import { InMemoryDriver } from '@objectstack/driver-memory';
import { TursoDriver } from '@objectstack/driver-turso';
import { AuthPlugin } from '@objectstack/plugin-auth';
import CrmApp from '../../examples/app-crm/objectstack.config';
import TodoApp from '../../examples/app-todo/objectstack.config';
import BiPluginManifest from '../../examples/plugin-bi/objectstack.config';
// Production Server
// This project acts as a "Platform Server" that loads multiple apps and plugins.
// It effectively replaces the manual composition in `src/index.ts`.
// Shared authentication plugin — reads secrets from environment variables so the
// same config works both locally and on Vercel (where VERCEL_URL is injected).
const authPlugin = new AuthPlugin({
secret: process.env.AUTH_SECRET ?? 'dev-secret-please-change-in-production-min-32-chars',
baseUrl: process.env.NEXT_PUBLIC_BASE_URL ?? (process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: 'http://localhost:3000'),
});
export default defineStack({
manifest: {
id: 'com.objectstack.server',
namespace: 'server',
name: 'ObjectStack Server',
version: '1.0.0',
description: 'Production server aggregating CRM, Todo and BI plugins',
type: 'app',
},
// Datasource Mapping Configuration
// Routes different namespaces to different datasources for optimal performance
datasourceMapping: [
// Example apps use in-memory driver for fast, ephemeral data
{ namespace: 'crm', datasource: 'memory' },
{ namespace: 'todo', datasource: 'memory' },
{ namespace: 'bi', datasource: 'memory' },
// System objects use Turso for persistent, production-grade storage
{ namespace: 'sys', datasource: 'turso' },
// Default fallback to memory driver
{ default: true, datasource: 'memory' },
],
// Explicitly Load Plugins and Apps
// The Runtime CLI will iterate this list and call kernel.use()
plugins: [
new ObjectQLPlugin(),
// Register Memory Driver for example apps (volatile, fast)
new DriverPlugin(new InMemoryDriver(), { name: 'memory' }),
// Register Turso Driver for system objects (persistent, production)
new DriverPlugin(
new TursoDriver({
url: process.env.TURSO_DATABASE_URL ?? 'file:./data/server.db',
authToken: process.env.TURSO_AUTH_TOKEN,
}),
{ name: 'turso' }
),
// Authentication — required for production (Vercel) deployments
authPlugin,
// Wrap Manifests/Stacks in AppPlugin adapter
new AppPlugin(CrmApp),
new AppPlugin(TodoApp),
new AppPlugin(BiPluginManifest)
]
});
/**
* Preview Mode Host Example
*
* Demonstrates how to run the platform in "preview" mode.
* When `mode` is set to `'preview'`, the kernel signals the frontend to:
* - Skip login/registration screens
* - Automatically simulate an admin identity
* - Display a preview-mode banner to the user
*
* Use this for marketplace demos, app showcases, or onboarding
* tours where visitors should explore the system without signing up.
*
* ## Usage
*
* Set the `OS_MODE` environment variable to `preview` at boot:
*
* ```bash
* OS_MODE=preview pnpm dev
* ```
*
* Or use this stack definition directly as a starting point.
*
* ## KernelContext (created by the Runtime at boot)
*
* ```ts
* import { KernelContextSchema } from '@objectstack/spec/kernel';
*
* const ctx = KernelContextSchema.parse({
* instanceId: '550e8400-e29b-41d4-a716-446655440000',
* mode: 'preview',
* version: '1.0.0',
* cwd: process.cwd(),
* startTime: Date.now(),
* previewMode: {
* autoLogin: true,
* simulatedRole: 'admin',
* simulatedUserName: 'Demo Admin',
* readOnly: false,
* bannerMessage: 'You are exploring a demo — data will be reset periodically.',
* },
* });
* ```
*/
export const PreviewHostExample = defineStack({
manifest: {
id: 'com.objectstack.server-preview',
namespace: 'server',
name: 'ObjectStack Server Preview',
version: '1.0.0',
description: 'Production server in preview/demo mode — bypasses login, simulates admin user',
type: 'app',
},
// Same datasource mapping as standard server
datasourceMapping: [
{ namespace: 'crm', datasource: 'memory' },
{ namespace: 'todo', datasource: 'memory' },
{ namespace: 'bi', datasource: 'memory' },
{ namespace: 'sys', datasource: 'turso' },
{ default: true, datasource: 'memory' },
],
// Same plugins as the standard host
plugins: [
new ObjectQLPlugin(),
new DriverPlugin(new InMemoryDriver(), { name: 'memory' }),
new DriverPlugin(
new TursoDriver({
url: process.env.TURSO_DATABASE_URL ?? 'file:./data/server.db',
authToken: process.env.TURSO_AUTH_TOKEN,
}),
{ name: 'turso' }
),
authPlugin,
new AppPlugin(CrmApp),
new AppPlugin(TodoApp),
new AppPlugin(BiPluginManifest)
]
});