-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobjectstack.config.ts
More file actions
112 lines (105 loc) · 3.59 KB
/
objectstack.config.ts
File metadata and controls
112 lines (105 loc) · 3.59 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
// 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 { 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',
},
// Explicitly Load Plugins and Apps
// The Runtime CLI will iterate this list and call kernel.use()
plugins: [
new ObjectQLPlugin(),
// Register Default Driver (Memory)
new DriverPlugin(new InMemoryDriver()),
// 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 plugins as the standard host
plugins: [
new ObjectQLPlugin(),
new DriverPlugin(new InMemoryDriver()),
authPlugin,
new AppPlugin(CrmApp),
new AppPlugin(TodoApp),
new AppPlugin(BiPluginManifest)
]
});