@brix-sdk/runtime-sdk-api-web 1.0.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 +160 -0
- package/dist/index.js +190 -0
- package/package.json +44 -0
- package/src/api-exports.test.ts +199 -0
- package/src/context/RuntimeContext.d.ts +69 -0
- package/src/context/RuntimeContext.d.ts.map +1 -0
- package/src/context/RuntimeContext.ts +75 -0
- package/src/context/index.d.ts +23 -0
- package/src/context/index.d.ts.map +1 -0
- package/src/context/index.ts +23 -0
- package/src/index.d.ts +52 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.ts +59 -0
- package/src/types/auth.d.ts +146 -0
- package/src/types/auth.d.ts.map +1 -0
- package/src/types/auth.ts +479 -0
- package/src/types/capability.d.ts +218 -0
- package/src/types/capability.d.ts.map +1 -0
- package/src/types/capability.ts +302 -0
- package/src/types/common.d.ts +99 -0
- package/src/types/common.d.ts.map +1 -0
- package/src/types/common.ts +115 -0
- package/src/types/config.d.ts +64 -0
- package/src/types/config.d.ts.map +1 -0
- package/src/types/config.ts +96 -0
- package/src/types/event.d.ts +206 -0
- package/src/types/event.d.ts.map +1 -0
- package/src/types/event.ts +776 -0
- package/src/types/http.d.ts +132 -0
- package/src/types/http.d.ts.map +1 -0
- package/src/types/http.ts +156 -0
- package/src/types/i18n.ts +420 -0
- package/src/types/index.d.ts +50 -0
- package/src/types/index.d.ts.map +1 -0
- package/src/types/index.ts +120 -0
- package/src/types/layout.ts +394 -0
- package/src/types/module.d.ts +78 -0
- package/src/types/module.d.ts.map +1 -0
- package/src/types/module.ts +92 -0
- package/src/types/navigation.d.ts +101 -0
- package/src/types/navigation.d.ts.map +1 -0
- package/src/types/navigation.ts +361 -0
- package/src/types/plugin-loader-capability.ts +159 -0
- package/src/types/plugin.d.ts +250 -0
- package/src/types/plugin.d.ts.map +1 -0
- package/src/types/plugin.ts +344 -0
- package/src/types/state.d.ts +119 -0
- package/src/types/state.d.ts.map +1 -0
- package/src/types/state.ts +366 -0
- package/src/types/theme.ts +378 -0
- package/src/types/ui/adapter.ts +222 -0
- package/src/types/ui/avatar.ts +113 -0
- package/src/types/ui/badge.ts +112 -0
- package/src/types/ui/button.ts +148 -0
- package/src/types/ui/card.ts +116 -0
- package/src/types/ui/common.ts +29 -0
- package/src/types/ui/icon.ts +85 -0
- package/src/types/ui/index.ts +78 -0
- package/src/types/ui/input.ts +225 -0
- package/src/types/ui/menu.ts +237 -0
- package/src/types/ui/message.ts +135 -0
- package/src/types/ui/modal.ts +188 -0
- package/src/types/ui/select.ts +239 -0
- package/src/types/ui/theme-tokens.ts +357 -0
- package/src/types/ui/tooltip.ts +120 -0
- package/src/types/ui.ts +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# brix-runtime-sdk-api-web
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/brix-runtime-sdk-api-web)
|
|
4
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
5
|
+
|
|
6
|
+
**Brix Runtime SDK Web API** - UI capability contracts and shared types for the [Brix Framework](https://github.com/brix-kit-dev/brix).
|
|
7
|
+
|
|
8
|
+
This package provides framework-agnostic TypeScript type definitions and contracts for building plugins in the Brix Runtime Shell architecture.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- 🔌 **Framework Agnostic** - No dependency on React, Vue, Angular, or any UI framework
|
|
13
|
+
- 📦 **Pure Type Definitions** - Contains only contracts, no runtime implementations
|
|
14
|
+
- 🎯 **Full TypeScript Support** - Complete type safety with IntelliSense
|
|
15
|
+
- 🏗�?**Modular Design** - Import only what you need
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install brix-runtime-sdk-api-web
|
|
21
|
+
# or
|
|
22
|
+
pnpm add brix-runtime-sdk-api-web
|
|
23
|
+
# or
|
|
24
|
+
yarn add brix-runtime-sdk-api-web
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Capability Categories
|
|
28
|
+
|
|
29
|
+
The SDK provides contracts for the following runtime capabilities:
|
|
30
|
+
|
|
31
|
+
| Capability | Description |
|
|
32
|
+
|------------|-------------|
|
|
33
|
+
| **Navigation** | Page navigation, router management, route contributions |
|
|
34
|
+
| **Auth** | User identity, authentication, permission verification |
|
|
35
|
+
| **State** | Plugin state management and persistence |
|
|
36
|
+
| **EventBus** | Cross-plugin communication and event handling |
|
|
37
|
+
| **Config** | Runtime configuration reading |
|
|
38
|
+
| **Http** | Unified HTTP request handling |
|
|
39
|
+
| **Theme** | Theme management and customization |
|
|
40
|
+
| **I18n** | Internationalization support |
|
|
41
|
+
| **Layout** | Layout management and contribution |
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
### Import Types
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import type {
|
|
49
|
+
// Capabilities
|
|
50
|
+
NavigationCapability,
|
|
51
|
+
AuthCapability,
|
|
52
|
+
StateCapability,
|
|
53
|
+
EventBusCapability,
|
|
54
|
+
ConfigCapability,
|
|
55
|
+
HttpCapability,
|
|
56
|
+
|
|
57
|
+
// Common types
|
|
58
|
+
PluginDefinition,
|
|
59
|
+
RouteContribution,
|
|
60
|
+
MenuItem,
|
|
61
|
+
|
|
62
|
+
// Context
|
|
63
|
+
RuntimeContext,
|
|
64
|
+
} from 'brix-runtime-sdk-api-web';
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### RuntimeContext
|
|
68
|
+
|
|
69
|
+
The `RuntimeContext` is the primary interface for plugins to access runtime capabilities:
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import type { RuntimeContext } from 'brix-runtime-sdk-api-web';
|
|
73
|
+
|
|
74
|
+
function initPlugin(context: RuntimeContext) {
|
|
75
|
+
// Access navigation capability
|
|
76
|
+
const navigation = context.getCapability('navigation');
|
|
77
|
+
navigation.navigateTo('/dashboard');
|
|
78
|
+
|
|
79
|
+
// Access auth capability
|
|
80
|
+
const auth = context.getCapability('auth');
|
|
81
|
+
const user = auth.getCurrentUser();
|
|
82
|
+
|
|
83
|
+
// Access event bus
|
|
84
|
+
const eventBus = context.getCapability('eventBus');
|
|
85
|
+
eventBus.emit('plugin:ready', { pluginId: 'my-plugin' });
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Plugin Definition
|
|
90
|
+
|
|
91
|
+
Define your plugin using the `PluginDefinition` type:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import type { PluginDefinition } from 'brix-runtime-sdk-api-web';
|
|
95
|
+
|
|
96
|
+
const myPlugin: PluginDefinition = {
|
|
97
|
+
id: 'my-plugin',
|
|
98
|
+
name: 'My Plugin',
|
|
99
|
+
version: '1.0.0',
|
|
100
|
+
routes: [
|
|
101
|
+
{
|
|
102
|
+
path: '/my-plugin',
|
|
103
|
+
component: MyComponent,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
menuItems: [
|
|
107
|
+
{
|
|
108
|
+
id: 'my-plugin-menu',
|
|
109
|
+
label: 'My Plugin',
|
|
110
|
+
path: '/my-plugin',
|
|
111
|
+
icon: 'plugin-icon',
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Module Structure
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
src/
|
|
121
|
+
├── index.ts # Main entry point
|
|
122
|
+
├── context/ # RuntimeContext definitions
|
|
123
|
+
�? └── RuntimeContext.ts
|
|
124
|
+
└── types/ # Type definitions
|
|
125
|
+
├── auth.ts # Authentication types
|
|
126
|
+
├── capability.ts # Capability contracts
|
|
127
|
+
├── common.ts # Common/shared types
|
|
128
|
+
├── config.ts # Configuration types
|
|
129
|
+
├── event.ts # Event bus types
|
|
130
|
+
├── http.ts # HTTP client types
|
|
131
|
+
├── i18n.ts # Internationalization types
|
|
132
|
+
├── layout.ts # Layout types
|
|
133
|
+
├── module.ts # Module types
|
|
134
|
+
├── navigation.ts # Navigation types
|
|
135
|
+
├── plugin.ts # Plugin definition types
|
|
136
|
+
├── state.ts # State management types
|
|
137
|
+
├── theme.ts # Theme types
|
|
138
|
+
└── ui/ # UI component types
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Framework Bindings
|
|
142
|
+
|
|
143
|
+
For React-specific bindings (hooks, providers), use `@brix-sdk/runtime-sdk-react` instead:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
npm install @brix-sdk/runtime-sdk-react
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Related Packages
|
|
150
|
+
|
|
151
|
+
- [`@brix-sdk/runtime-sdk-react`](https://github.com/brix-kit-dev/brix) - React bindings with hooks and providers
|
|
152
|
+
- [`@brix-sdk/runtime-host`](https://github.com/brix-kit-dev/brix) - Runtime host implementation
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
[Apache License 2.0](https://opensource.org/licenses/Apache-2.0)
|
|
157
|
+
|
|
158
|
+
## Contributing
|
|
159
|
+
|
|
160
|
+
We welcome contributions! Please see our [Contributing Guide](https://github.com/brix-kit-dev/brix/blob/main/CONTRIBUTING.md) for details.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// src/types/capability.ts
|
|
2
|
+
var CapabilityPriority = /* @__PURE__ */ ((CapabilityPriority2) => {
|
|
3
|
+
CapabilityPriority2[CapabilityPriority2["LOW"] = 0] = "LOW";
|
|
4
|
+
CapabilityPriority2[CapabilityPriority2["NORMAL"] = 50] = "NORMAL";
|
|
5
|
+
CapabilityPriority2[CapabilityPriority2["HIGH"] = 100] = "HIGH";
|
|
6
|
+
return CapabilityPriority2;
|
|
7
|
+
})(CapabilityPriority || {});
|
|
8
|
+
function createCapabilityType(meta) {
|
|
9
|
+
return {
|
|
10
|
+
...meta,
|
|
11
|
+
id: Symbol.for(meta.id)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/types/plugin.ts
|
|
16
|
+
var PluginLoadError = class extends Error {
|
|
17
|
+
constructor(message, pluginId, phase, cause) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.pluginId = pluginId;
|
|
20
|
+
this.phase = phase;
|
|
21
|
+
this.cause = cause;
|
|
22
|
+
this.name = "PluginLoadError";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/types/navigation.ts
|
|
27
|
+
var NavigationCapabilityType = /* @__PURE__ */ Symbol.for("NavigationCapability");
|
|
28
|
+
var RouterCapabilityType = NavigationCapabilityType;
|
|
29
|
+
|
|
30
|
+
// src/types/state.ts
|
|
31
|
+
var PluginStateCapabilityType = /* @__PURE__ */ Symbol.for("PluginStateCapability");
|
|
32
|
+
var StateStoreCapabilityType = PluginStateCapabilityType;
|
|
33
|
+
|
|
34
|
+
// src/types/event.ts
|
|
35
|
+
var EventBusCapabilityType = /* @__PURE__ */ Symbol.for("EventBusCapability");
|
|
36
|
+
var GovernedEventBusCapabilityType = /* @__PURE__ */ Symbol.for("GovernedEventBusCapability");
|
|
37
|
+
var BackpressureError = class extends Error {
|
|
38
|
+
eventType;
|
|
39
|
+
queueDepth;
|
|
40
|
+
maxQueueDepth;
|
|
41
|
+
constructor(eventType, queueDepth, maxQueueDepth) {
|
|
42
|
+
super(
|
|
43
|
+
`Backpressure limit reached for event type '${eventType}': queue depth ${queueDepth} >= max ${maxQueueDepth}`
|
|
44
|
+
);
|
|
45
|
+
this.name = "BackpressureError";
|
|
46
|
+
this.eventType = eventType;
|
|
47
|
+
this.queueDepth = queueDepth;
|
|
48
|
+
this.maxQueueDepth = maxQueueDepth;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// src/types/module.ts
|
|
53
|
+
var ModuleState = /* @__PURE__ */ ((ModuleState2) => {
|
|
54
|
+
ModuleState2["UNLOADED"] = "UNLOADED";
|
|
55
|
+
ModuleState2["LOADING"] = "LOADING";
|
|
56
|
+
ModuleState2["LOADED"] = "LOADED";
|
|
57
|
+
ModuleState2["ACTIVE"] = "ACTIVE";
|
|
58
|
+
ModuleState2["ERROR"] = "ERROR";
|
|
59
|
+
return ModuleState2;
|
|
60
|
+
})(ModuleState || {});
|
|
61
|
+
var ModuleLifecycleEvent = /* @__PURE__ */ ((ModuleLifecycleEvent2) => {
|
|
62
|
+
ModuleLifecycleEvent2["BEFORE_LOAD"] = "BEFORE_LOAD";
|
|
63
|
+
ModuleLifecycleEvent2["AFTER_LOAD"] = "AFTER_LOAD";
|
|
64
|
+
ModuleLifecycleEvent2["BEFORE_ACTIVATE"] = "BEFORE_ACTIVATE";
|
|
65
|
+
ModuleLifecycleEvent2["AFTER_ACTIVATE"] = "AFTER_ACTIVATE";
|
|
66
|
+
ModuleLifecycleEvent2["BEFORE_DEACTIVATE"] = "BEFORE_DEACTIVATE";
|
|
67
|
+
ModuleLifecycleEvent2["AFTER_DEACTIVATE"] = "AFTER_DEACTIVATE";
|
|
68
|
+
ModuleLifecycleEvent2["ERROR"] = "ERROR";
|
|
69
|
+
return ModuleLifecycleEvent2;
|
|
70
|
+
})(ModuleLifecycleEvent || {});
|
|
71
|
+
|
|
72
|
+
// src/types/http.ts
|
|
73
|
+
var HttpCapabilityType = /* @__PURE__ */ Symbol.for("HttpCapability");
|
|
74
|
+
|
|
75
|
+
// src/types/auth.ts
|
|
76
|
+
var AuthCapabilityType = /* @__PURE__ */ Symbol.for("AuthCapability");
|
|
77
|
+
|
|
78
|
+
// src/types/config.ts
|
|
79
|
+
var ConfigCapabilityType = /* @__PURE__ */ Symbol.for("ConfigCapability");
|
|
80
|
+
var ConfigStoreCapabilityType = /* @__PURE__ */ Symbol.for("ConfigStoreCapability");
|
|
81
|
+
|
|
82
|
+
// src/types/i18n.ts
|
|
83
|
+
var I18nCapabilityType = /* @__PURE__ */ Symbol.for("I18nCapability");
|
|
84
|
+
|
|
85
|
+
// src/types/theme.ts
|
|
86
|
+
var ThemeCapabilityType = /* @__PURE__ */ Symbol.for("ThemeCapability");
|
|
87
|
+
|
|
88
|
+
// src/types/layout.ts
|
|
89
|
+
var LayoutCapabilityType = /* @__PURE__ */ Symbol.for("LayoutCapability");
|
|
90
|
+
|
|
91
|
+
// src/types/ui/theme-tokens.ts
|
|
92
|
+
var MUI_THEME_TOKENS = {
|
|
93
|
+
// Brand Colors
|
|
94
|
+
primary: "#1976d2",
|
|
95
|
+
primaryLight: "#42a5f5",
|
|
96
|
+
primaryDark: "#1565c0",
|
|
97
|
+
primaryContrastText: "#ffffff",
|
|
98
|
+
secondary: "#9c27b0",
|
|
99
|
+
secondaryLight: "#ba68c8",
|
|
100
|
+
secondaryDark: "#7b1fa2",
|
|
101
|
+
secondaryContrastText: "#ffffff",
|
|
102
|
+
// Semantic Colors
|
|
103
|
+
error: "#d32f2f",
|
|
104
|
+
warning: "#ed6c02",
|
|
105
|
+
info: "#0288d1",
|
|
106
|
+
success: "#2e7d32",
|
|
107
|
+
// Neutral Colors
|
|
108
|
+
background: "#f5f5f5",
|
|
109
|
+
paper: "#ffffff",
|
|
110
|
+
textPrimary: "rgba(0, 0, 0, 0.87)",
|
|
111
|
+
textSecondary: "rgba(0, 0, 0, 0.6)",
|
|
112
|
+
textDisabled: "rgba(0, 0, 0, 0.38)",
|
|
113
|
+
divider: "rgba(0, 0, 0, 0.12)",
|
|
114
|
+
// Layout Colors
|
|
115
|
+
sidebarBackground: "#1e293b",
|
|
116
|
+
sidebarText: "rgba(255, 255, 255, 0.87)",
|
|
117
|
+
sidebarActiveBackground: "#3b82f6",
|
|
118
|
+
sidebarHoverBackground: "rgba(255, 255, 255, 0.08)",
|
|
119
|
+
headerBackground: "#ffffff",
|
|
120
|
+
headerText: "rgba(0, 0, 0, 0.87)",
|
|
121
|
+
// Shape Tokens
|
|
122
|
+
borderRadiusSmall: 4,
|
|
123
|
+
borderRadiusMedium: 8,
|
|
124
|
+
borderRadiusLarge: 12
|
|
125
|
+
};
|
|
126
|
+
var MUI_DARK_THEME_TOKENS = {
|
|
127
|
+
// Brand Colors (same as light)
|
|
128
|
+
primary: "#90caf9",
|
|
129
|
+
primaryLight: "#e3f2fd",
|
|
130
|
+
primaryDark: "#42a5f5",
|
|
131
|
+
primaryContrastText: "rgba(0, 0, 0, 0.87)",
|
|
132
|
+
secondary: "#ce93d8",
|
|
133
|
+
secondaryLight: "#f3e5f5",
|
|
134
|
+
secondaryDark: "#ab47bc",
|
|
135
|
+
secondaryContrastText: "rgba(0, 0, 0, 0.87)",
|
|
136
|
+
// Semantic Colors (adjusted for dark mode)
|
|
137
|
+
error: "#f44336",
|
|
138
|
+
warning: "#ffa726",
|
|
139
|
+
info: "#29b6f6",
|
|
140
|
+
success: "#66bb6a",
|
|
141
|
+
// Neutral Colors (inverted)
|
|
142
|
+
background: "#121212",
|
|
143
|
+
paper: "#1e1e1e",
|
|
144
|
+
textPrimary: "rgba(255, 255, 255, 0.87)",
|
|
145
|
+
textSecondary: "rgba(255, 255, 255, 0.6)",
|
|
146
|
+
textDisabled: "rgba(255, 255, 255, 0.38)",
|
|
147
|
+
divider: "rgba(255, 255, 255, 0.12)",
|
|
148
|
+
// Layout Colors (adjusted for dark mode)
|
|
149
|
+
sidebarBackground: "#0f172a",
|
|
150
|
+
sidebarText: "rgba(255, 255, 255, 0.87)",
|
|
151
|
+
sidebarActiveBackground: "#1e40af",
|
|
152
|
+
sidebarHoverBackground: "rgba(255, 255, 255, 0.08)",
|
|
153
|
+
headerBackground: "#1e1e1e",
|
|
154
|
+
headerText: "rgba(255, 255, 255, 0.87)",
|
|
155
|
+
// Shape Tokens (same as light)
|
|
156
|
+
borderRadiusSmall: 4,
|
|
157
|
+
borderRadiusMedium: 8,
|
|
158
|
+
borderRadiusLarge: 12
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// src/types/ui/adapter.ts
|
|
162
|
+
var UICapabilityType = /* @__PURE__ */ Symbol.for("UICapability");
|
|
163
|
+
|
|
164
|
+
// src/types/plugin-loader-capability.ts
|
|
165
|
+
var PluginLoaderCapabilityType = /* @__PURE__ */ Symbol.for("PluginLoaderCapability");
|
|
166
|
+
export {
|
|
167
|
+
AuthCapabilityType,
|
|
168
|
+
BackpressureError,
|
|
169
|
+
CapabilityPriority,
|
|
170
|
+
ConfigCapabilityType,
|
|
171
|
+
ConfigStoreCapabilityType,
|
|
172
|
+
EventBusCapabilityType,
|
|
173
|
+
GovernedEventBusCapabilityType,
|
|
174
|
+
HttpCapabilityType,
|
|
175
|
+
I18nCapabilityType,
|
|
176
|
+
LayoutCapabilityType,
|
|
177
|
+
MUI_DARK_THEME_TOKENS,
|
|
178
|
+
MUI_THEME_TOKENS,
|
|
179
|
+
ModuleLifecycleEvent,
|
|
180
|
+
ModuleState,
|
|
181
|
+
NavigationCapabilityType,
|
|
182
|
+
PluginLoadError,
|
|
183
|
+
PluginLoaderCapabilityType,
|
|
184
|
+
PluginStateCapabilityType,
|
|
185
|
+
RouterCapabilityType,
|
|
186
|
+
StateStoreCapabilityType,
|
|
187
|
+
ThemeCapabilityType,
|
|
188
|
+
UICapabilityType,
|
|
189
|
+
createCapabilityType
|
|
190
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@brix-sdk/runtime-sdk-api-web",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Brix Runtime SDK Web API - UI capability contracts and shared types for the Brix Framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup && tsc --declaration --emitDeclarationOnly",
|
|
22
|
+
"dev": "tsup --watch",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:update": "vitest run -u"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@types/react": "^18.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"tsup": "^8.0.0",
|
|
31
|
+
"typescript": "^5.7.3",
|
|
32
|
+
"vitest": "^1.2.0"
|
|
33
|
+
},
|
|
34
|
+
"author": "Brix Platform Authors",
|
|
35
|
+
"license": "Apache-2.0",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/brix-platform/runtime-sdk.git",
|
|
39
|
+
"directory": "runtime-sdk-api-web"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 Brix Platform Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @file Public API Snapshot Test (Golden File)
|
|
18
|
+
* @description Validates stability of public API exports to prevent accidental breaking changes
|
|
19
|
+
* @module @brix-sdk/runtime-sdk-api-web/test
|
|
20
|
+
* @version 3.2.0
|
|
21
|
+
*
|
|
22
|
+
* [Test Description]
|
|
23
|
+
* Golden File tests ensure the following by creating API export snapshots:
|
|
24
|
+
* 1. Public APIs are not accidentally modified
|
|
25
|
+
* 2. Type exports remain stable
|
|
26
|
+
* 3. Any API changes require explicit confirmation
|
|
27
|
+
*
|
|
28
|
+
* [Update Snapshot]
|
|
29
|
+
* When intentionally modifying the API, run:
|
|
30
|
+
* pnpm test -- -u
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import { describe, it, expect } from 'vitest';
|
|
34
|
+
import * as ApiExports from './index';
|
|
35
|
+
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// Public API Export List
|
|
38
|
+
// ============================================================================
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Expected capability type identifiers to be exported
|
|
42
|
+
*/
|
|
43
|
+
const EXPECTED_CAPABILITY_TYPES = [
|
|
44
|
+
'NavigationCapabilityType',
|
|
45
|
+
'EventBusCapabilityType',
|
|
46
|
+
'PluginStateCapabilityType',
|
|
47
|
+
'AuthCapabilityType',
|
|
48
|
+
'HttpCapabilityType',
|
|
49
|
+
'ConfigCapabilityType',
|
|
50
|
+
'I18nCapabilityType',
|
|
51
|
+
'ThemeCapabilityType',
|
|
52
|
+
'LayoutCapabilityType',
|
|
53
|
+
] as const;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Expected context-related exports
|
|
57
|
+
*/
|
|
58
|
+
const EXPECTED_CONTEXT_EXPORTS = [
|
|
59
|
+
'RuntimeContext',
|
|
60
|
+
'RuntimeContextProvider',
|
|
61
|
+
'createRuntimeContext',
|
|
62
|
+
] as const;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Expected plugin-related type exports
|
|
66
|
+
*/
|
|
67
|
+
const EXPECTED_PLUGIN_EXPORTS = [
|
|
68
|
+
'PluginEntry',
|
|
69
|
+
'PluginLifecycle',
|
|
70
|
+
'PluginContext',
|
|
71
|
+
'PluginStatus',
|
|
72
|
+
'PluginManifest',
|
|
73
|
+
] as const;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Expected navigation-related type exports
|
|
77
|
+
*/
|
|
78
|
+
const EXPECTED_NAVIGATION_EXPORTS = [
|
|
79
|
+
'NavigateResult',
|
|
80
|
+
'NavigateOptions',
|
|
81
|
+
'PageInfo',
|
|
82
|
+
'RouteContribution',
|
|
83
|
+
] as const;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Expected state-related type exports
|
|
87
|
+
*/
|
|
88
|
+
const EXPECTED_STATE_EXPORTS = [
|
|
89
|
+
'StatePersistenceOptions',
|
|
90
|
+
'PluginStateChangeEvent',
|
|
91
|
+
'PluginStateSubscribeOptions',
|
|
92
|
+
] as const;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Expected event-related type exports
|
|
96
|
+
*/
|
|
97
|
+
const EXPECTED_EVENT_EXPORTS = [
|
|
98
|
+
'EventHandler',
|
|
99
|
+
'EventSubscription',
|
|
100
|
+
'EventType',
|
|
101
|
+
'Unsubscribe',
|
|
102
|
+
] as const;
|
|
103
|
+
|
|
104
|
+
// ============================================================================
|
|
105
|
+
// Golden File Tests
|
|
106
|
+
// ============================================================================
|
|
107
|
+
|
|
108
|
+
describe('API Export Stability Tests (Golden File)', () => {
|
|
109
|
+
it('should export all expected modules', () => {
|
|
110
|
+
// Get actual exported keys
|
|
111
|
+
const actualExports = Object.keys(ApiExports);
|
|
112
|
+
|
|
113
|
+
// Snapshot verification
|
|
114
|
+
expect(actualExports.sort()).toMatchSnapshot('api-exports');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('Capability Type Identifiers', () => {
|
|
118
|
+
it('should export all capability type identifiers', () => {
|
|
119
|
+
for (const capType of EXPECTED_CAPABILITY_TYPES) {
|
|
120
|
+
expect(
|
|
121
|
+
ApiExports,
|
|
122
|
+
`Missing capability type identifier: ${capType}`
|
|
123
|
+
).toHaveProperty(capType);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('capability type identifier structure should remain stable', () => {
|
|
128
|
+
const capabilityTypes: Record<string, unknown> = {};
|
|
129
|
+
|
|
130
|
+
for (const capType of EXPECTED_CAPABILITY_TYPES) {
|
|
131
|
+
const exported = (ApiExports as Record<string, unknown>)[capType];
|
|
132
|
+
if (exported && typeof exported === 'object') {
|
|
133
|
+
capabilityTypes[capType] = {
|
|
134
|
+
id: (exported as { id?: string }).id,
|
|
135
|
+
name: (exported as { name?: string }).name,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
expect(capabilityTypes).toMatchSnapshot('capability-types');
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe('Context Exports', () => {
|
|
145
|
+
it('should export runtime context related modules', () => {
|
|
146
|
+
for (const contextExport of EXPECTED_CONTEXT_EXPORTS) {
|
|
147
|
+
// Context exports may be functions or components
|
|
148
|
+
const hasExport = contextExport in ApiExports;
|
|
149
|
+
if (!hasExport) {
|
|
150
|
+
// Some context exports may be type-only exports, skip check
|
|
151
|
+
console.warn(`Context export ${contextExport} may be a type-only export`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('Type Export Completeness', () => {
|
|
158
|
+
it('plugin-related types should be accessible', () => {
|
|
159
|
+
// Types only exist at compile time, cannot be directly verified at runtime
|
|
160
|
+
// This test is mainly for documentation purposes
|
|
161
|
+
const typeNames = EXPECTED_PLUGIN_EXPORTS;
|
|
162
|
+
expect(typeNames.length).toBeGreaterThan(0);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('navigation-related types should be accessible', () => {
|
|
166
|
+
const typeNames = EXPECTED_NAVIGATION_EXPORTS;
|
|
167
|
+
expect(typeNames.length).toBeGreaterThan(0);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('state-related types should be accessible', () => {
|
|
171
|
+
const typeNames = EXPECTED_STATE_EXPORTS;
|
|
172
|
+
expect(typeNames.length).toBeGreaterThan(0);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('event-related types should be accessible', () => {
|
|
176
|
+
const typeNames = EXPECTED_EVENT_EXPORTS;
|
|
177
|
+
expect(typeNames.length).toBeGreaterThan(0);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// ============================================================================
|
|
183
|
+
// API Signature Stability
|
|
184
|
+
// ============================================================================
|
|
185
|
+
|
|
186
|
+
describe('API Signature Stability', () => {
|
|
187
|
+
it('export count should not decrease (prevent accidental deletion)', () => {
|
|
188
|
+
const actualExportCount = Object.keys(ApiExports).length;
|
|
189
|
+
|
|
190
|
+
// Set minimum export count baseline (adjust based on actual situation)
|
|
191
|
+
// This number should be set after the API stabilizes
|
|
192
|
+
const MIN_EXPECTED_EXPORTS = 5;
|
|
193
|
+
|
|
194
|
+
expect(
|
|
195
|
+
actualExportCount,
|
|
196
|
+
`Export count (${actualExportCount}) is below expected minimum (${MIN_EXPECTED_EXPORTS})`
|
|
197
|
+
).toBeGreaterThanOrEqual(MIN_EXPECTED_EXPORTS);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 Brix Platform Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @file Runtime Context Abstract Definition
|
|
18
|
+
* @description Defines the core interface for runtime context (no React dependency)
|
|
19
|
+
* @module @brix-sdk/runtime-sdk-api-web/context/RuntimeContext
|
|
20
|
+
* @version 3.2.0
|
|
21
|
+
*
|
|
22
|
+
* [v3.2 Refactoring Notes]
|
|
23
|
+
* Extracted RuntimeContext abstraction from index.ts to keep the contract layer free of React dependencies.
|
|
24
|
+
* React-related Context and Hooks are migrated to @brix-sdk/runtime-sdk-react package.
|
|
25
|
+
*
|
|
26
|
+
* [Design Principles]
|
|
27
|
+
* - Pure abstract interface, no dependency on any UI framework
|
|
28
|
+
* - Can be used in React, Vue, native JS, and other environments
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Runtime Context Interface
|
|
32
|
+
*
|
|
33
|
+
* <p>Provides a unified entry point for plugins to access runtime capabilities.</p>
|
|
34
|
+
*
|
|
35
|
+
* <h3>Responsibilities</h3>
|
|
36
|
+
* <ul>
|
|
37
|
+
* <li>Provides module ID identification</li>
|
|
38
|
+
* <li>Provides tenant ID identification</li>
|
|
39
|
+
* <li>Provides capability retrieval method</li>
|
|
40
|
+
* </ul>
|
|
41
|
+
*
|
|
42
|
+
* <h3>Usage Example</h3>
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const http = context.getCapability<HttpCapability>(HttpCapabilityType);
|
|
45
|
+
* const nav = context.getCapability<NavigationCapability>(NavigationCapabilityType);
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export interface RuntimeContext {
|
|
49
|
+
/**
|
|
50
|
+
* Module/Plugin ID
|
|
51
|
+
*
|
|
52
|
+
* <p>Unique identifier for the current plugin.</p>
|
|
53
|
+
*/
|
|
54
|
+
readonly moduleId: string;
|
|
55
|
+
/**
|
|
56
|
+
* Tenant ID
|
|
57
|
+
*
|
|
58
|
+
* <p>Tenant identifier for the current runtime environment.</p>
|
|
59
|
+
*/
|
|
60
|
+
readonly tenantId: string;
|
|
61
|
+
/**
|
|
62
|
+
* Get capability instance
|
|
63
|
+
*
|
|
64
|
+
* @param capabilityType Capability type identifier (Symbol)
|
|
65
|
+
* @returns Capability instance, returns undefined if not found
|
|
66
|
+
*/
|
|
67
|
+
getCapability<T>(capabilityType: symbol): T | undefined;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=RuntimeContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RuntimeContext.d.ts","sourceRoot":"","sources":["RuntimeContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;;;;OAKG;IACH,aAAa,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;CACzD"}
|