@object-ui/tenant 2.0.0 → 3.0.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/README.md +117 -0
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# @object-ui/tenant
|
|
2
|
+
|
|
3
|
+
Multi-tenancy support for Object UI — tenant isolation, scoped queries, and per-tenant branding.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🏢 **TenantProvider** - Context provider for tenant-aware applications
|
|
8
|
+
- 🔒 **Tenant Isolation** - Row-level and schema-level isolation strategies
|
|
9
|
+
- 🎨 **Custom Branding** - Per-tenant logos, colors, and themes via `useTenantBranding`
|
|
10
|
+
- 🛡️ **TenantGuard** - Protect components based on tenant status and plan
|
|
11
|
+
- 🔍 **Scoped Queries** - Automatically scope data queries to the current tenant
|
|
12
|
+
- 🔗 **Tenant Resolver** - Pluggable resolution via subdomain, path, or header
|
|
13
|
+
- 🎯 **Type-Safe** - Full TypeScript support with exported types
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @object-ui/tenant
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Peer Dependencies:**
|
|
22
|
+
- `react` ^18.0.0 || ^19.0.0
|
|
23
|
+
- `react-dom` ^18.0.0 || ^19.0.0
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { TenantProvider, useTenant, useTenantBranding } from '@object-ui/tenant';
|
|
29
|
+
|
|
30
|
+
function App() {
|
|
31
|
+
return (
|
|
32
|
+
<TenantProvider
|
|
33
|
+
config={{
|
|
34
|
+
resolutionStrategy: 'subdomain',
|
|
35
|
+
isolationStrategy: 'row',
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
<TenantApp />
|
|
39
|
+
</TenantProvider>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function TenantApp() {
|
|
44
|
+
const { tenant } = useTenant();
|
|
45
|
+
const { logo, primaryColor } = useTenantBranding();
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div style={{ borderColor: primaryColor }}>
|
|
49
|
+
<img src={logo} alt={tenant?.name} />
|
|
50
|
+
<h1>Welcome to {tenant?.name}</h1>
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## API
|
|
57
|
+
|
|
58
|
+
### TenantProvider
|
|
59
|
+
|
|
60
|
+
Wraps your application with tenant context:
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
<TenantProvider config={{ resolutionStrategy: 'subdomain', isolationStrategy: 'row' }}>
|
|
64
|
+
<App />
|
|
65
|
+
</TenantProvider>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### useTenant
|
|
69
|
+
|
|
70
|
+
Hook for accessing the current tenant:
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
const { tenant, isLoading, error } = useTenant();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### useTenantBranding
|
|
77
|
+
|
|
78
|
+
Hook for accessing tenant-specific branding:
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
const { logo, primaryColor, theme } = useTenantBranding();
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### TenantGuard
|
|
85
|
+
|
|
86
|
+
Protects components based on tenant status or plan:
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
<TenantGuard requiredPlan="enterprise" fallback={<UpgradePrompt />}>
|
|
90
|
+
<EnterpriseFeature />
|
|
91
|
+
</TenantGuard>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### TenantScopedQuery
|
|
95
|
+
|
|
96
|
+
Automatically scopes data queries to the current tenant:
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
<TenantScopedQuery objectName="orders">
|
|
100
|
+
{({ data }) => <OrderList orders={data} />}
|
|
101
|
+
</TenantScopedQuery>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### createTenantResolver
|
|
105
|
+
|
|
106
|
+
Factory for custom tenant resolution logic:
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
const resolver = createTenantResolver({
|
|
110
|
+
strategy: 'subdomain',
|
|
111
|
+
fetchTenant: async (id) => api.getTenant(id),
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/tenant",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Multi-tenancy support for Object UI with tenant isolation, scoped queries, and custom branding.",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"react": "^18.0.0 || ^19.0.0"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@object-ui/types": "
|
|
29
|
+
"@object-ui/types": "3.0.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/react": "
|
|
33
|
-
"react": "
|
|
32
|
+
"@types/react": "19.2.13",
|
|
33
|
+
"react": "19.2.4",
|
|
34
34
|
"typescript": "^5.9.3",
|
|
35
35
|
"vitest": "^4.0.18"
|
|
36
36
|
},
|