@buildbase/sdk 0.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 +304 -0
- package/dist/index.d.ts +310 -0
- package/dist/index.esm.js +30 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/saas-os.css +3 -0
- package/dist/types/api/index.d.ts +1 -0
- package/dist/types/api/types.d.ts +49 -0
- package/dist/types/components/beta/BetaForm.d.ts +24 -0
- package/dist/types/components/beta/api.d.ts +49 -0
- package/dist/types/components/beta/hooks.d.ts +11 -0
- package/dist/types/components/beta/schema.d.ts +6 -0
- package/dist/types/components/beta/types.d.ts +8 -0
- package/dist/types/components/dropdowns/country/countries.d.ts +7 -0
- package/dist/types/components/dropdowns/country/selectCountry.d.ts +6 -0
- package/dist/types/components/dropdowns/currency/currencies.d.ts +6 -0
- package/dist/types/components/dropdowns/currency/selectCurrency.d.ts +6 -0
- package/dist/types/components/dropdowns/language/languages.d.ts +6 -0
- package/dist/types/components/dropdowns/language/selectLanguage.d.ts +6 -0
- package/dist/types/components/dropdowns/timezone/selectTimeZone.d.ts +6 -0
- package/dist/types/components/dropdowns/timezone/timezones.d.ts +8 -0
- package/dist/types/components/features/index.d.ts +7 -0
- package/dist/types/components/ui/accordion.d.ts +7 -0
- package/dist/types/components/ui/alert-dialog.d.ts +20 -0
- package/dist/types/components/ui/alert.d.ts +8 -0
- package/dist/types/components/ui/aspect-ratio.d.ts +3 -0
- package/dist/types/components/ui/avatar.d.ts +6 -0
- package/dist/types/components/ui/badge.d.ts +9 -0
- package/dist/types/components/ui/button.d.ts +18 -0
- package/dist/types/components/ui/buttonIcon.d.ts +9 -0
- package/dist/types/components/ui/calendar.d.ts +8 -0
- package/dist/types/components/ui/card.d.ts +8 -0
- package/dist/types/components/ui/checkbox.d.ts +4 -0
- package/dist/types/components/ui/collapsible.d.ts +5 -0
- package/dist/types/components/ui/command.d.ts +82 -0
- package/dist/types/components/ui/context-menu.d.ts +27 -0
- package/dist/types/components/ui/dateRangePicker.d.ts +9 -0
- package/dist/types/components/ui/dialog.d.ts +19 -0
- package/dist/types/components/ui/dropdown-menu.d.ts +27 -0
- package/dist/types/components/ui/form.d.ts +23 -0
- package/dist/types/components/ui/heading.d.ts +10 -0
- package/dist/types/components/ui/hover-card.d.ts +6 -0
- package/dist/types/components/ui/input.d.ts +5 -0
- package/dist/types/components/ui/label.d.ts +5 -0
- package/dist/types/components/ui/menubar.d.ts +33 -0
- package/dist/types/components/ui/navigation-menu.d.ts +12 -0
- package/dist/types/components/ui/popover.d.ts +6 -0
- package/dist/types/components/ui/progress.d.ts +4 -0
- package/dist/types/components/ui/radio-group.d.ts +5 -0
- package/dist/types/components/ui/scroll-area.d.ts +5 -0
- package/dist/types/components/ui/select.d.ts +11 -0
- package/dist/types/components/ui/separator.d.ts +4 -0
- package/dist/types/components/ui/sheet.d.ts +28 -0
- package/dist/types/components/ui/skeleton.d.ts +3 -0
- package/dist/types/components/ui/slider.d.ts +4 -0
- package/dist/types/components/ui/switch.d.ts +4 -0
- package/dist/types/components/ui/table.d.ts +10 -0
- package/dist/types/components/ui/tabs.d.ts +7 -0
- package/dist/types/components/ui/textarea.d.ts +5 -0
- package/dist/types/components/ui/toast.d.ts +15 -0
- package/dist/types/components/ui/toaster.d.ts +1 -0
- package/dist/types/components/ui/toggle.d.ts +12 -0
- package/dist/types/components/ui/tooltip.d.ts +7 -0
- package/dist/types/components/ui/use-toast.d.ts +44 -0
- package/dist/types/components/user/auth.d.ts +6 -0
- package/dist/types/components/user/role.d.ts +8 -0
- package/dist/types/contexts/AuthContext.d.ts +9 -0
- package/dist/types/contexts/OSContext.d.ts +9 -0
- package/dist/types/contexts/SDKContextProvider.d.ts +15 -0
- package/dist/types/contexts/WorkspaceContext.d.ts +8 -0
- package/dist/types/contexts/actionCreators.d.ts +29 -0
- package/dist/types/contexts/createContext.d.ts +27 -0
- package/dist/types/contexts/index.d.ts +10 -0
- package/dist/types/contexts/reducers/authReducer.d.ts +13 -0
- package/dist/types/contexts/reducers/index.d.ts +3 -0
- package/dist/types/contexts/reducers/osReducer.d.ts +11 -0
- package/dist/types/contexts/reducers/workspaceReducer.d.ts +10 -0
- package/dist/types/contexts/types.d.ts +74 -0
- package/dist/types/contexts/useAppDispatch.d.ts +28 -0
- package/dist/types/contexts/useAppSelector.d.ts +36 -0
- package/dist/types/contexts/utils/reducerHelpers.d.ts +11 -0
- package/dist/types/contexts/utils/storage.d.ts +23 -0
- package/dist/types/hooks/use-mobile.d.ts +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/lib/api-client.d.ts +29 -0
- package/dist/types/lib/utils.d.ts +2 -0
- package/dist/types/providers/ContextConfigProvider.d.ts +15 -0
- package/dist/types/providers/PortalContainer.d.ts +8 -0
- package/dist/types/providers/SaaSOSProvider.d.ts +7 -0
- package/dist/types/providers/auth/hooks.d.ts +10 -0
- package/dist/types/providers/auth/provider.d.ts +8 -0
- package/dist/types/providers/auth/types.d.ts +38 -0
- package/dist/types/providers/auth/utils.d.ts +10 -0
- package/dist/types/providers/os/types.d.ts +9 -0
- package/dist/types/providers/workspace/api.d.ts +33 -0
- package/dist/types/providers/workspace/hooks.d.ts +30 -0
- package/dist/types/providers/workspace/provider.d.ts +9 -0
- package/dist/types/providers/workspace/types.d.ts +38 -0
- package/dist/types/providers/workspace/ui/SettingsDialog.d.ts +8 -0
- package/dist/types/providers/workspace/ui/SettingsFeatures.d.ts +5 -0
- package/dist/types/providers/workspace/ui/SettingsGeneral.d.ts +6 -0
- package/dist/types/providers/workspace/ui/SettingsProfile.d.ts +6 -0
- package/dist/types/providers/workspace/ui/SettingsUsers.d.ts +6 -0
- package/dist/types/providers/workspace/ui/Sidebar.d.ts +10 -0
- package/dist/types/providers/workspace/ui/utils.d.ts +2 -0
- package/dist/types/providers/workspace/utils.d.ts +8 -0
- package/package.json +122 -0
package/README.md
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
# @buildbase/sdk
|
|
2
|
+
|
|
3
|
+
A React SDK for [BuildBase](https://www.buildbase.app/) that provides essential components to build SaaS applications faster. Skip the plumbing and focus on your core product with built-in authentication, workspace management, and user management.
|
|
4
|
+
|
|
5
|
+
## 🚀 Features
|
|
6
|
+
|
|
7
|
+
- **🔐 Authentication System** - Complete auth flow with sign-in/sign-out
|
|
8
|
+
- **🏢 Workspace Management** - Multi-workspace support with switching capabilities
|
|
9
|
+
- **👥 Role-Based Access Control** - User roles and workspace-specific permissions
|
|
10
|
+
- **🎯 Feature Flags** - Workspace-level feature toggles
|
|
11
|
+
|
|
12
|
+
## 📦 Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @buildbase/sdk
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Peer Dependencies
|
|
19
|
+
|
|
20
|
+
This package requires React 19 and React DOM 19:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install react@^19.0.0 react-dom@^19.0.0
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 🏗️ Quick Start
|
|
27
|
+
|
|
28
|
+
### 1. Import CSS
|
|
29
|
+
|
|
30
|
+
First, import the required CSS file in your app:
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import '@buildbase/sdk/dist/saas-os.css';
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. Create Client Provider
|
|
37
|
+
|
|
38
|
+
Create a client-side provider component:
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
'use client';
|
|
42
|
+
|
|
43
|
+
import { SaaSOSProvider } from '@buildbase/sdk';
|
|
44
|
+
import React from 'react';
|
|
45
|
+
|
|
46
|
+
export default function SaaSProvider(props: { children: React.ReactNode }) {
|
|
47
|
+
return (
|
|
48
|
+
<SaaSOSProvider
|
|
49
|
+
serverUrl="https://your-api-server.com"
|
|
50
|
+
version="v1"
|
|
51
|
+
orgId="your-org-id"
|
|
52
|
+
auth={{
|
|
53
|
+
clientId: 'your-client-id',
|
|
54
|
+
redirectUrl: 'http://localhost:3000',
|
|
55
|
+
callbacks: {
|
|
56
|
+
verifyToken: async token => {
|
|
57
|
+
return new Promise(resolve => {
|
|
58
|
+
fetch('/api/auth/verify', {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
body: JSON.stringify({ token }),
|
|
61
|
+
})
|
|
62
|
+
.then(response => response.json())
|
|
63
|
+
.then((data: { valid: boolean }) => {
|
|
64
|
+
resolve(data?.valid ?? false);
|
|
65
|
+
})
|
|
66
|
+
.catch(error => {
|
|
67
|
+
console.error(error);
|
|
68
|
+
resolve(false);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
handleAuthentication: async token => {
|
|
73
|
+
return new Promise(resolve => {
|
|
74
|
+
fetch('/api/auth/token', {
|
|
75
|
+
method: 'POST',
|
|
76
|
+
body: JSON.stringify({ token }),
|
|
77
|
+
})
|
|
78
|
+
.then(response => response.json())
|
|
79
|
+
.then((data: { token: string; decoded: { id: string } }) => {
|
|
80
|
+
localStorage.setItem('auth_token', data?.token ?? '');
|
|
81
|
+
resolve();
|
|
82
|
+
})
|
|
83
|
+
.catch(error => {
|
|
84
|
+
console.error(error);
|
|
85
|
+
resolve();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
}}
|
|
91
|
+
>
|
|
92
|
+
{props.children}
|
|
93
|
+
</SaaSOSProvider>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 3. Wrap Your App
|
|
99
|
+
|
|
100
|
+
Use the provider in your app layout:
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
import SaaSProvider from './components/SaaSProvider';
|
|
104
|
+
|
|
105
|
+
function App() {
|
|
106
|
+
return (
|
|
107
|
+
<SaaSProvider>
|
|
108
|
+
<YourAppContent />
|
|
109
|
+
</SaaSProvider>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export default App;
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 4. Workspace Management
|
|
117
|
+
|
|
118
|
+
The WorkspaceSwitcher component uses a render prop pattern, giving you full control over the UI:
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
import React from 'react';
|
|
122
|
+
import { WorkspaceSwitcher } from '@buildbase/sdk';
|
|
123
|
+
|
|
124
|
+
function WorkspaceExample() {
|
|
125
|
+
return (
|
|
126
|
+
<WorkspaceSwitcher
|
|
127
|
+
trigger={currentWorkspace => {
|
|
128
|
+
if (!currentWorkspace) {
|
|
129
|
+
return (
|
|
130
|
+
<div className="flex items-center gap-2 min-w-40 border rounded-md p-2 hover:bg-muted cursor-pointer">
|
|
131
|
+
<div className="bg-gray-200 flex aspect-square size-8 items-center justify-center rounded-lg"></div>
|
|
132
|
+
<div className="grid flex-1 text-left text-sm leading-tight">Choose a workspace</div>
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<div className="flex items-center gap-2 min-w-40 border rounded-md p-2 hover:bg-muted cursor-pointer">
|
|
139
|
+
<div className="flex items-center justify-center h-full w-full bg-muted rounded-lg max-h-8 max-w-8">
|
|
140
|
+
{currentWorkspace?.image && (
|
|
141
|
+
<img src={currentWorkspace?.image} alt={currentWorkspace?.name} />
|
|
142
|
+
)}
|
|
143
|
+
</div>
|
|
144
|
+
<div className="grid flex-1 text-left text-sm leading-tight">
|
|
145
|
+
<span className="truncate font-medium">{currentWorkspace?.name}</span>
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
);
|
|
149
|
+
}}
|
|
150
|
+
onWorkspaceChange={async workspace => {
|
|
151
|
+
// Handle workspace change
|
|
152
|
+
console.log('Workspace changed to:', workspace);
|
|
153
|
+
}}
|
|
154
|
+
/>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## 🔐 Authentication
|
|
160
|
+
|
|
161
|
+
### Authentication Hook
|
|
162
|
+
|
|
163
|
+
Use the `useSaaSAuth` hook to manage authentication state and actions:
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
import { useSaaSAuth } from '@buildbase/sdk';
|
|
167
|
+
|
|
168
|
+
function AuthExample() {
|
|
169
|
+
const { user, isAuthenticated, signIn, signOut, status } = useSaaSAuth();
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<div>
|
|
173
|
+
{!isAuthenticated ? (
|
|
174
|
+
<div>
|
|
175
|
+
<h1>Welcome! Please sign in</h1>
|
|
176
|
+
<button onClick={signIn} disabled={status === 'loading'}>
|
|
177
|
+
{status === 'loading' ? 'Signing in...' : 'Sign In'}
|
|
178
|
+
</button>
|
|
179
|
+
</div>
|
|
180
|
+
) : (
|
|
181
|
+
<div>
|
|
182
|
+
<h1>Welcome back, {user?.name}!</h1>
|
|
183
|
+
<p>Email: {user?.email}</p>
|
|
184
|
+
<p>Role: {user?.role}</p>
|
|
185
|
+
<button onClick={signOut}>Sign Out</button>
|
|
186
|
+
</div>
|
|
187
|
+
)}
|
|
188
|
+
</div>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Authentication Hook Properties
|
|
194
|
+
|
|
195
|
+
```tsx
|
|
196
|
+
const {
|
|
197
|
+
user, // Current user object (null if not authenticated)
|
|
198
|
+
isAuthenticated, // Boolean: true if user is authenticated
|
|
199
|
+
signIn, // Function: initiates sign-in flow
|
|
200
|
+
signOut, // Function: signs out the user
|
|
201
|
+
status, // String: 'idle' | 'loading' | 'authenticated' | 'error'
|
|
202
|
+
} = useSaaSAuth();
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Authentication Components
|
|
206
|
+
|
|
207
|
+
For declarative rendering, use the conditional components:
|
|
208
|
+
|
|
209
|
+
```tsx
|
|
210
|
+
import { WhenAuthenticated, WhenUnauthenticated } from '@buildbase/sdk';
|
|
211
|
+
|
|
212
|
+
function App() {
|
|
213
|
+
return (
|
|
214
|
+
<div>
|
|
215
|
+
<WhenUnauthenticated>
|
|
216
|
+
<LoginPage />
|
|
217
|
+
</WhenUnauthenticated>
|
|
218
|
+
|
|
219
|
+
<WhenAuthenticated>
|
|
220
|
+
<Dashboard />
|
|
221
|
+
</WhenAuthenticated>
|
|
222
|
+
</div>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## 👥 Role-Based Access Control
|
|
228
|
+
|
|
229
|
+
### Role Components
|
|
230
|
+
|
|
231
|
+
Control access based on user roles:
|
|
232
|
+
|
|
233
|
+
```tsx
|
|
234
|
+
import { WhenRoles, WhenWorkspaceRoles } from '@buildbase/sdk';
|
|
235
|
+
|
|
236
|
+
function AdminPanel() {
|
|
237
|
+
return (
|
|
238
|
+
<div>
|
|
239
|
+
{/* Global user roles */}
|
|
240
|
+
<WhenRoles roles={['admin', 'super-admin']}>
|
|
241
|
+
<AdminControls />
|
|
242
|
+
</WhenRoles>
|
|
243
|
+
|
|
244
|
+
{/* Workspace-specific roles */}
|
|
245
|
+
<WhenWorkspaceRoles roles={['owner', 'admin']}>
|
|
246
|
+
<WorkspaceSettings />
|
|
247
|
+
</WhenWorkspaceRoles>
|
|
248
|
+
|
|
249
|
+
{/* With fallback content */}
|
|
250
|
+
<WhenRoles roles={['admin']} fallback={<p>You need admin access to view this content</p>}>
|
|
251
|
+
<SensitiveData />
|
|
252
|
+
</WhenRoles>
|
|
253
|
+
</div>
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## 🎛️ Feature Flags
|
|
259
|
+
|
|
260
|
+
Control feature visibility based on workspace settings:
|
|
261
|
+
|
|
262
|
+
```tsx
|
|
263
|
+
import { WhenWorkspaceFeatureEnabled, WhenWorkspaceFeatureDisabled } from '@buildbase/sdk';
|
|
264
|
+
|
|
265
|
+
function FeatureExample() {
|
|
266
|
+
return (
|
|
267
|
+
<div>
|
|
268
|
+
<WhenWorkspaceFeatureEnabled slug="advanced-analytics">
|
|
269
|
+
<AdvancedAnalytics />
|
|
270
|
+
</WhenWorkspaceFeatureEnabled>
|
|
271
|
+
|
|
272
|
+
<WhenWorkspaceFeatureDisabled slug="beta-features">
|
|
273
|
+
<p>Beta features are not enabled for this workspace</p>
|
|
274
|
+
</WhenWorkspaceFeatureDisabled>
|
|
275
|
+
</div>
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## 🤝 Contributing
|
|
281
|
+
|
|
282
|
+
1. Fork the repository
|
|
283
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
284
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
285
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
286
|
+
5. Open a Pull Request
|
|
287
|
+
|
|
288
|
+
## 📄 License
|
|
289
|
+
|
|
290
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
291
|
+
|
|
292
|
+
## 🆘 Support
|
|
293
|
+
|
|
294
|
+
- 📧 Email: support@buildbase.app
|
|
295
|
+
- 📖 Documentation: [BuildBase Docs](https://docs.buildbase.app/)
|
|
296
|
+
|
|
297
|
+
## 🔗 Links
|
|
298
|
+
|
|
299
|
+
- **Homepage**: [BuildBase](https://www.buildbase.app/)
|
|
300
|
+
- **NPM Package**: [@buildbase/sdk](https://www.npmjs.com/package/@buildbase/sdk)
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
Made with ❤️ by the BuildBase team
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import react__default, { ReactNode } from 'react';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
declare enum AuthStatus {
|
|
6
|
+
loading = "loading",
|
|
7
|
+
authenticated = "authenticated",
|
|
8
|
+
unauthenticated = "unauthenticated",
|
|
9
|
+
authenticating = "authenticating"
|
|
10
|
+
}
|
|
11
|
+
interface AuthUser {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
org: string;
|
|
15
|
+
email: string;
|
|
16
|
+
emailVerified: boolean;
|
|
17
|
+
clientId: string;
|
|
18
|
+
role: string;
|
|
19
|
+
image?: string;
|
|
20
|
+
}
|
|
21
|
+
interface AuthSession {
|
|
22
|
+
user: AuthUser;
|
|
23
|
+
accessToken: string;
|
|
24
|
+
expires: string;
|
|
25
|
+
}
|
|
26
|
+
interface IAuthState {
|
|
27
|
+
user: AuthUser | null;
|
|
28
|
+
session: AuthSession | null;
|
|
29
|
+
isLoading: boolean;
|
|
30
|
+
isAuthenticated: boolean;
|
|
31
|
+
isRedirecting: boolean;
|
|
32
|
+
status: AuthStatus;
|
|
33
|
+
}
|
|
34
|
+
interface IAuthConfig {
|
|
35
|
+
clientId: string;
|
|
36
|
+
redirectUrl: string;
|
|
37
|
+
callbacks?: IAuthCallbacks;
|
|
38
|
+
}
|
|
39
|
+
interface IAuthCallbacks {
|
|
40
|
+
handleAuthentication: (token: string) => Promise<void>;
|
|
41
|
+
verifyToken: (token: string) => Promise<boolean>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface IOsConfig {
|
|
45
|
+
serverUrl: string;
|
|
46
|
+
version: string;
|
|
47
|
+
orgId: string;
|
|
48
|
+
}
|
|
49
|
+
interface IOsState extends IOsConfig {
|
|
50
|
+
auth?: IAuthConfig;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface SaaSOSProviderProps extends IOsState {
|
|
54
|
+
children: react__default.ReactNode;
|
|
55
|
+
}
|
|
56
|
+
declare const SaaSOSProvider: react__default.FC<SaaSOSProviderProps>;
|
|
57
|
+
|
|
58
|
+
type Language = 'en' | 'es' | 'fr' | 'de' | 'zh' | 'ja' | 'ko';
|
|
59
|
+
interface FormText {
|
|
60
|
+
nameLabel: string;
|
|
61
|
+
emailLabel: string;
|
|
62
|
+
submitText: string;
|
|
63
|
+
submittingText: string;
|
|
64
|
+
errorMessage: string;
|
|
65
|
+
}
|
|
66
|
+
interface BetaFormProps {
|
|
67
|
+
onSuccess?: () => void;
|
|
68
|
+
onError?: (error: string) => void;
|
|
69
|
+
className?: string;
|
|
70
|
+
fieldClassName?: string;
|
|
71
|
+
language?: Language;
|
|
72
|
+
customTexts?: Partial<FormText>;
|
|
73
|
+
autoFocus?: boolean;
|
|
74
|
+
showSuccessMessage?: boolean;
|
|
75
|
+
successMessageDuration?: number;
|
|
76
|
+
hideLogo?: boolean;
|
|
77
|
+
hideTitles?: boolean;
|
|
78
|
+
}
|
|
79
|
+
declare const BetaForm: react__default.FC<BetaFormProps>;
|
|
80
|
+
|
|
81
|
+
interface IProps$2 {
|
|
82
|
+
children: React.ReactNode;
|
|
83
|
+
}
|
|
84
|
+
declare const WhenAuthenticated: (props: IProps$2) => react.ReactNode;
|
|
85
|
+
declare const WhenUnauthenticated: (props: IProps$2) => react.ReactNode;
|
|
86
|
+
|
|
87
|
+
interface IProps$1 {
|
|
88
|
+
roles: string[];
|
|
89
|
+
children: React.ReactNode;
|
|
90
|
+
fallback?: React.ReactNode;
|
|
91
|
+
}
|
|
92
|
+
declare const WhenRoles: (props: IProps$1) => react.ReactNode;
|
|
93
|
+
declare const WhenWorkspaceRoles: (props: IProps$1) => react.ReactNode;
|
|
94
|
+
|
|
95
|
+
interface IProps {
|
|
96
|
+
slug: string;
|
|
97
|
+
children: React.ReactNode;
|
|
98
|
+
}
|
|
99
|
+
declare const WhenWorkspaceFeatureEnabled: (props: IProps) => react.ReactNode;
|
|
100
|
+
declare const WhenWorkspaceFeatureDisabled: (props: IProps) => react.ReactNode;
|
|
101
|
+
|
|
102
|
+
declare function useSaaSAuth(): {
|
|
103
|
+
user: AuthUser | null;
|
|
104
|
+
session: AuthSession | null;
|
|
105
|
+
isLoading: boolean;
|
|
106
|
+
isAuthenticated: boolean;
|
|
107
|
+
isRedirecting: boolean;
|
|
108
|
+
status: AuthStatus;
|
|
109
|
+
signIn: () => Promise<void>;
|
|
110
|
+
signOut: () => Promise<void>;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
interface IDocument {
|
|
114
|
+
_id: string;
|
|
115
|
+
id: string;
|
|
116
|
+
createdAt: string;
|
|
117
|
+
updatedAt: string;
|
|
118
|
+
deleted: boolean;
|
|
119
|
+
}
|
|
120
|
+
interface IUser extends IDocument {
|
|
121
|
+
_id: string;
|
|
122
|
+
name: string;
|
|
123
|
+
email: string;
|
|
124
|
+
image: string;
|
|
125
|
+
role: string;
|
|
126
|
+
country: string;
|
|
127
|
+
timezone: string;
|
|
128
|
+
language: string;
|
|
129
|
+
currency: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface IWorkspace {
|
|
133
|
+
_id: string;
|
|
134
|
+
name: string;
|
|
135
|
+
image?: string;
|
|
136
|
+
workspaceId: string;
|
|
137
|
+
users: IUser[];
|
|
138
|
+
roles: string[];
|
|
139
|
+
createdBy: string | IUser;
|
|
140
|
+
features: Record<string, boolean>;
|
|
141
|
+
}
|
|
142
|
+
interface IWorkspaceFeature {
|
|
143
|
+
_id: string;
|
|
144
|
+
name: string;
|
|
145
|
+
description: string;
|
|
146
|
+
userManaged: boolean;
|
|
147
|
+
defaultValue: boolean;
|
|
148
|
+
slug: string;
|
|
149
|
+
category: string;
|
|
150
|
+
createdAt: Date;
|
|
151
|
+
updatedAt: Date;
|
|
152
|
+
}
|
|
153
|
+
interface IWorkspaceUser {
|
|
154
|
+
_id: string;
|
|
155
|
+
workspace: string | IWorkspace;
|
|
156
|
+
user: string | IUser;
|
|
157
|
+
role: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
declare function WorkspaceSwitcher(props: {
|
|
161
|
+
trigger: (currentWorkspace: IWorkspace | null) => ReactNode;
|
|
162
|
+
onWorkspaceChange: (workspace: IWorkspace) => Promise<void>;
|
|
163
|
+
}): react_jsx_runtime.JSX.Element;
|
|
164
|
+
|
|
165
|
+
declare const useSaaSWorkspaces: () => {
|
|
166
|
+
workspaces: IWorkspace[];
|
|
167
|
+
loading: boolean;
|
|
168
|
+
error: string | null;
|
|
169
|
+
fetchWorkspaces: () => Promise<void>;
|
|
170
|
+
refreshWorkspaces: () => Promise<void>;
|
|
171
|
+
refreshing: boolean;
|
|
172
|
+
WorkspaceSwitcher: typeof WorkspaceSwitcher;
|
|
173
|
+
currentWorkspace: IWorkspace | null;
|
|
174
|
+
setCurrentWorkspace: (ws: IWorkspace) => void;
|
|
175
|
+
resetCurrentWorkspace: () => void;
|
|
176
|
+
createWorkspace: (name: string, image: string) => Promise<void>;
|
|
177
|
+
allFeatures: IWorkspaceFeature[];
|
|
178
|
+
getFeatures: () => Promise<IWorkspaceFeature[]>;
|
|
179
|
+
updateFeature: (workspaceId: string, key: string, value: boolean) => Promise<IWorkspace>;
|
|
180
|
+
getWorkspace: (workspaceId: string) => Promise<IWorkspace>;
|
|
181
|
+
switching: boolean;
|
|
182
|
+
updateWorkspace: (ws: IWorkspace, _data: Partial<IWorkspace>) => Promise<void>;
|
|
183
|
+
getUsers: (workspaceId: string) => Promise<IWorkspaceUser[]>;
|
|
184
|
+
addUser: (workspaceId: string, email: string, role: string) => Promise<IWorkspaceUser>;
|
|
185
|
+
removeUser: (workspaceId: string, userId: string) => Promise<{
|
|
186
|
+
success: boolean;
|
|
187
|
+
}>;
|
|
188
|
+
updateUser: (workspaceId: string, userId: string, config: Partial<IWorkspaceUser>) => Promise<IWorkspaceUser>;
|
|
189
|
+
getProfile: () => Promise<IUser>;
|
|
190
|
+
updateUserProfile: (config: Partial<IUser>) => Promise<IUser>;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
type AuthAction = {
|
|
194
|
+
type: 'AUTHENTICATION_STARTED';
|
|
195
|
+
} | {
|
|
196
|
+
type: 'AUTHENTICATION_FAILED';
|
|
197
|
+
} | {
|
|
198
|
+
type: 'SET_SESSION';
|
|
199
|
+
payload: AuthSession;
|
|
200
|
+
} | {
|
|
201
|
+
type: 'REMOVE_SESSION';
|
|
202
|
+
};
|
|
203
|
+
type WorkspaceAction = {
|
|
204
|
+
type: 'SET_WORKSPACES';
|
|
205
|
+
payload: IWorkspace[];
|
|
206
|
+
} | {
|
|
207
|
+
type: 'SET_ALL_FEATURES';
|
|
208
|
+
payload: IWorkspaceFeature[];
|
|
209
|
+
} | {
|
|
210
|
+
type: 'SET_CURRENT_WORKSPACE';
|
|
211
|
+
payload: IWorkspace;
|
|
212
|
+
} | {
|
|
213
|
+
type: 'RESET_CURRENT_WORKSPACE';
|
|
214
|
+
} | {
|
|
215
|
+
type: 'SET_IS_INITIALIZED';
|
|
216
|
+
payload: boolean;
|
|
217
|
+
} | {
|
|
218
|
+
type: 'SET_LOADING';
|
|
219
|
+
payload: boolean;
|
|
220
|
+
} | {
|
|
221
|
+
type: 'SET_ERROR';
|
|
222
|
+
payload: string | null;
|
|
223
|
+
} | {
|
|
224
|
+
type: 'SET_REFRESHING';
|
|
225
|
+
payload: boolean;
|
|
226
|
+
} | {
|
|
227
|
+
type: 'SET_SWITCHING';
|
|
228
|
+
payload: boolean;
|
|
229
|
+
};
|
|
230
|
+
interface WorkspaceState {
|
|
231
|
+
workspaces: IWorkspace[];
|
|
232
|
+
loading: boolean;
|
|
233
|
+
error: string | null;
|
|
234
|
+
currentWorkspace: IWorkspace | null;
|
|
235
|
+
refreshing: boolean;
|
|
236
|
+
switching: boolean;
|
|
237
|
+
isInitialized: boolean;
|
|
238
|
+
allFeatures: IWorkspaceFeature[];
|
|
239
|
+
}
|
|
240
|
+
type OSAction = {
|
|
241
|
+
type: 'SET_SAAS_OS_CONFIG';
|
|
242
|
+
payload: IOsState;
|
|
243
|
+
} | {
|
|
244
|
+
type: 'REMOVE_SAAS_OS_CONFIG';
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Combined SDK State
|
|
249
|
+
* Represents the complete state structure across all contexts
|
|
250
|
+
*/
|
|
251
|
+
interface SDKState {
|
|
252
|
+
os: IOsState;
|
|
253
|
+
auth: IAuthState;
|
|
254
|
+
workspaces: WorkspaceState;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Combined selector hook - select from all contexts at once
|
|
258
|
+
*
|
|
259
|
+
* @param selector Function that selects a value from the combined SDK state
|
|
260
|
+
* @param equalityFn Optional equality function for comparison (default: Object.is)
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```tsx
|
|
264
|
+
* // Get entire combined state
|
|
265
|
+
* const sdk = useAppSelector();
|
|
266
|
+
*
|
|
267
|
+
* // Get specific context
|
|
268
|
+
* const auth = useAppSelector(state => state.auth);
|
|
269
|
+
* const user = useAppSelector(state => state.auth.user);
|
|
270
|
+
*
|
|
271
|
+
* // Get multiple fields across contexts
|
|
272
|
+
* const { user, currentWorkspace, serverUrl } = useAppSelector(state => ({
|
|
273
|
+
* user: state.auth.user,
|
|
274
|
+
* currentWorkspace: state.workspaces.currentWorkspace,
|
|
275
|
+
* serverUrl: state.os.serverUrl,
|
|
276
|
+
* }));
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
declare function useAppSelector<Selected = SDKState>(selector?: (state: SDKState) => Selected, equalityFn?: (a: Selected, b: Selected) => boolean): Selected;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Combined SDK Dispatch
|
|
283
|
+
* Provides dispatch functions for all contexts
|
|
284
|
+
*/
|
|
285
|
+
interface SDKDispatch {
|
|
286
|
+
auth: (action: AuthAction) => void;
|
|
287
|
+
os: (action: OSAction) => void;
|
|
288
|
+
workspaces: (action: WorkspaceAction) => void;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Combined dispatch hook - dispatch actions to all contexts
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```tsx
|
|
295
|
+
* const dispatch = useAppDispatch();
|
|
296
|
+
*
|
|
297
|
+
* // Dispatch to auth context
|
|
298
|
+
* dispatch.auth(authActions.setSession(session));
|
|
299
|
+
*
|
|
300
|
+
* // Dispatch to workspace context
|
|
301
|
+
* dispatch.workspaces(workspaceActions.setCurrentWorkspace(workspace));
|
|
302
|
+
*
|
|
303
|
+
* // Dispatch to OS context
|
|
304
|
+
* dispatch.os(osActions.setSaaSOSConfig(config));
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
declare function useAppDispatch(): SDKDispatch;
|
|
308
|
+
|
|
309
|
+
export { BetaForm, SaaSOSProvider, WhenAuthenticated, WhenRoles, WhenUnauthenticated, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceSwitcher, useAppDispatch, useAppSelector, useSaaSAuth, useSaaSWorkspaces };
|
|
310
|
+
export type { SDKDispatch, SDKState, SaaSOSProviderProps };
|