@buildbase/sdk 0.0.8 → 0.0.9
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 +75 -100
- package/dist/index.esm.js +6 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/saas-os.css +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -277,11 +277,11 @@ function AdminPanel() {
|
|
|
277
277
|
Control feature visibility based on workspace and user settings:
|
|
278
278
|
|
|
279
279
|
```tsx
|
|
280
|
-
import {
|
|
281
|
-
WhenWorkspaceFeatureEnabled,
|
|
280
|
+
import {
|
|
281
|
+
WhenWorkspaceFeatureEnabled,
|
|
282
282
|
WhenWorkspaceFeatureDisabled,
|
|
283
283
|
WhenUserFeatureEnabled,
|
|
284
|
-
WhenUserFeatureDisabled
|
|
284
|
+
WhenUserFeatureDisabled,
|
|
285
285
|
} from '@buildbase/sdk';
|
|
286
286
|
|
|
287
287
|
function FeatureExample() {
|
|
@@ -320,13 +320,7 @@ function FeatureCheck() {
|
|
|
320
320
|
const { features, isFeatureEnabled, refreshFeatures } = useUserFeatures();
|
|
321
321
|
|
|
322
322
|
return (
|
|
323
|
-
<div>
|
|
324
|
-
{isFeatureEnabled('premium-features') ? (
|
|
325
|
-
<PremiumContent />
|
|
326
|
-
) : (
|
|
327
|
-
<StandardContent />
|
|
328
|
-
)}
|
|
329
|
-
</div>
|
|
323
|
+
<div>{isFeatureEnabled('premium-features') ? <PremiumContent /> : <StandardContent />}</div>
|
|
330
324
|
);
|
|
331
325
|
}
|
|
332
326
|
```
|
|
@@ -341,23 +335,18 @@ Manage custom user attributes (key-value pairs):
|
|
|
341
335
|
import { useUserAttributes } from '@buildbase/sdk';
|
|
342
336
|
|
|
343
337
|
function UserProfile() {
|
|
344
|
-
const {
|
|
345
|
-
|
|
346
|
-
isLoading,
|
|
347
|
-
updateAttribute,
|
|
348
|
-
updateAttributes,
|
|
349
|
-
refreshAttributes
|
|
350
|
-
} = useUserAttributes();
|
|
338
|
+
const { attributes, isLoading, updateAttribute, updateAttributes, refreshAttributes } =
|
|
339
|
+
useUserAttributes();
|
|
351
340
|
|
|
352
341
|
const handleUpdate = async () => {
|
|
353
342
|
// Update single attribute
|
|
354
343
|
await updateAttribute('theme', 'dark');
|
|
355
|
-
|
|
344
|
+
|
|
356
345
|
// Or update multiple attributes
|
|
357
346
|
await updateAttributes({
|
|
358
347
|
theme: 'dark',
|
|
359
348
|
notifications: true,
|
|
360
|
-
language: 'en'
|
|
349
|
+
language: 'en',
|
|
361
350
|
});
|
|
362
351
|
};
|
|
363
352
|
|
|
@@ -379,25 +368,25 @@ import { useSaaSWorkspaces } from '@buildbase/sdk';
|
|
|
379
368
|
|
|
380
369
|
function WorkspaceManager() {
|
|
381
370
|
const {
|
|
382
|
-
workspaces,
|
|
383
|
-
currentWorkspace,
|
|
384
|
-
loading,
|
|
385
|
-
refreshing,
|
|
386
|
-
error,
|
|
387
|
-
fetchWorkspaces,
|
|
388
|
-
refreshWorkspaces,
|
|
389
|
-
setCurrentWorkspace,
|
|
390
|
-
createWorkspace,
|
|
391
|
-
updateWorkspace,
|
|
392
|
-
deleteWorkspace,
|
|
393
|
-
getUsers,
|
|
394
|
-
addUser,
|
|
395
|
-
removeUser,
|
|
396
|
-
updateUser,
|
|
397
|
-
getFeatures,
|
|
398
|
-
updateFeature,
|
|
399
|
-
getProfile,
|
|
400
|
-
updateUserProfile,
|
|
371
|
+
workspaces, // Array of all workspaces
|
|
372
|
+
currentWorkspace, // Currently selected workspace
|
|
373
|
+
loading, // Loading state
|
|
374
|
+
refreshing, // Refreshing state
|
|
375
|
+
error, // Error message
|
|
376
|
+
fetchWorkspaces, // Fetch all workspaces
|
|
377
|
+
refreshWorkspaces, // Background refresh
|
|
378
|
+
setCurrentWorkspace, // Switch workspace
|
|
379
|
+
createWorkspace, // Create new workspace
|
|
380
|
+
updateWorkspace, // Update workspace
|
|
381
|
+
deleteWorkspace, // Delete workspace
|
|
382
|
+
getUsers, // Get workspace users
|
|
383
|
+
addUser, // Add user to workspace
|
|
384
|
+
removeUser, // Remove user from workspace
|
|
385
|
+
updateUser, // Update user role/permissions
|
|
386
|
+
getFeatures, // Get all available features
|
|
387
|
+
updateFeature, // Toggle workspace feature
|
|
388
|
+
getProfile, // Get current user profile
|
|
389
|
+
updateUserProfile, // Update user profile
|
|
401
390
|
} = useSaaSWorkspaces();
|
|
402
391
|
|
|
403
392
|
// Example: Create a workspace
|
|
@@ -410,11 +399,7 @@ function WorkspaceManager() {
|
|
|
410
399
|
await addUser(currentWorkspace._id, 'user@example.com', 'member');
|
|
411
400
|
};
|
|
412
401
|
|
|
413
|
-
return
|
|
414
|
-
<div>
|
|
415
|
-
{/* Your workspace UI */}
|
|
416
|
-
</div>
|
|
417
|
-
);
|
|
402
|
+
return <div>{/* Your workspace UI */}</div>;
|
|
418
403
|
}
|
|
419
404
|
```
|
|
420
405
|
|
|
@@ -429,7 +414,7 @@ function SignupPage() {
|
|
|
429
414
|
return (
|
|
430
415
|
<BetaForm
|
|
431
416
|
onSuccess={() => console.log('Form submitted!')}
|
|
432
|
-
onError={
|
|
417
|
+
onError={error => console.error(error)}
|
|
433
418
|
language="en" // Optional: 'en' | 'es' | 'fr' | 'de' | 'zh' | 'ja' | 'ko'
|
|
434
419
|
showSuccessMessage={true}
|
|
435
420
|
hideLogo={false}
|
|
@@ -468,7 +453,7 @@ import { SaaSOSProvider, eventEmitter } from '@buildbase/sdk';
|
|
|
468
453
|
}}
|
|
469
454
|
>
|
|
470
455
|
{children}
|
|
471
|
-
</SaaSOSProvider
|
|
456
|
+
</SaaSOSProvider>;
|
|
472
457
|
```
|
|
473
458
|
|
|
474
459
|
### Available Events
|
|
@@ -488,12 +473,7 @@ import { SaaSOSProvider, eventEmitter } from '@buildbase/sdk';
|
|
|
488
473
|
The SDK provides comprehensive error handling:
|
|
489
474
|
|
|
490
475
|
```tsx
|
|
491
|
-
import {
|
|
492
|
-
ErrorBoundary,
|
|
493
|
-
SDKError,
|
|
494
|
-
handleError,
|
|
495
|
-
errorHandler
|
|
496
|
-
} from '@buildbase/sdk';
|
|
476
|
+
import { ErrorBoundary, SDKError, handleError, errorHandler } from '@buildbase/sdk';
|
|
497
477
|
|
|
498
478
|
// Wrap your app with ErrorBoundary
|
|
499
479
|
function App() {
|
|
@@ -558,20 +538,20 @@ All TypeScript types are exported for type safety. See the [TypeScript definitio
|
|
|
558
538
|
|
|
559
539
|
### SaaSOSProvider Props
|
|
560
540
|
|
|
561
|
-
| Prop | Type | Required | Description
|
|
562
|
-
|
|
|
563
|
-
| `serverUrl` | `string` | ✅ | API server URL (must be valid URL)
|
|
564
|
-
| `version` | `ApiVersion` | ✅ | API version (currently only `'v1'`)
|
|
565
|
-
| `orgId` | `string` | ✅ | Organization ID (must be valid MongoDB ObjectId - 24 hex characters)
|
|
566
|
-
| `auth` | `IAuthConfig` | ❌ | Authentication configuration
|
|
567
|
-
| `children` | `ReactNode` | ✅ | React children
|
|
541
|
+
| Prop | Type | Required | Description |
|
|
542
|
+
| ----------- | ------------- | -------- | -------------------------------------------------------------------- |
|
|
543
|
+
| `serverUrl` | `string` | ✅ | API server URL (must be valid URL) |
|
|
544
|
+
| `version` | `ApiVersion` | ✅ | API version (currently only `'v1'`) |
|
|
545
|
+
| `orgId` | `string` | ✅ | Organization ID (must be valid MongoDB ObjectId - 24 hex characters) |
|
|
546
|
+
| `auth` | `IAuthConfig` | ❌ | Authentication configuration |
|
|
547
|
+
| `children` | `ReactNode` | ✅ | React children |
|
|
568
548
|
|
|
569
549
|
### Auth Configuration
|
|
570
550
|
|
|
571
551
|
```tsx
|
|
572
552
|
interface IAuthConfig {
|
|
573
|
-
clientId: string;
|
|
574
|
-
redirectUrl: string;
|
|
553
|
+
clientId: string; // OAuth client ID
|
|
554
|
+
redirectUrl: string; // OAuth redirect URL
|
|
575
555
|
callbacks?: {
|
|
576
556
|
handleAuthentication: (code: string) => Promise<{ sessionId: string }>;
|
|
577
557
|
onSignOut?: () => Promise<void>;
|
|
@@ -588,19 +568,19 @@ interface IAuthConfig {
|
|
|
588
568
|
|
|
589
569
|
### BetaForm Props
|
|
590
570
|
|
|
591
|
-
| Prop
|
|
592
|
-
|
|
|
593
|
-
| `onSuccess`
|
|
594
|
-
| `onError`
|
|
595
|
-
| `className`
|
|
596
|
-
| `fieldClassName`
|
|
597
|
-
| `language`
|
|
598
|
-
| `customTexts`
|
|
599
|
-
| `autoFocus`
|
|
600
|
-
| `showSuccessMessage`
|
|
601
|
-
| `successMessageDuration` | `number`
|
|
602
|
-
| `hideLogo`
|
|
603
|
-
| `hideTitles`
|
|
571
|
+
| Prop | Type | Default | Description |
|
|
572
|
+
| ------------------------ | ------------------------------------------------------ | -------------------------------- | --------------------------------------- |
|
|
573
|
+
| `onSuccess` | `() => void` | - | Callback when form submits successfully |
|
|
574
|
+
| `onError` | `(error: string) => void` | - | Callback when form submission fails |
|
|
575
|
+
| `className` | `string` | `'w-full'` | CSS class for form container |
|
|
576
|
+
| `fieldClassName` | `string` | `'flex flex-col gap-1.5 w-full'` | CSS class for form fields |
|
|
577
|
+
| `language` | `'en' \| 'es' \| 'fr' \| 'de' \| 'zh' \| 'ja' \| 'ko'` | Auto-detect | Form language |
|
|
578
|
+
| `customTexts` | `Partial<FormText>` | `{}` | Custom text overrides |
|
|
579
|
+
| `autoFocus` | `boolean` | `true` | Auto-focus name field |
|
|
580
|
+
| `showSuccessMessage` | `boolean` | `true` | Show success message after submit |
|
|
581
|
+
| `successMessageDuration` | `number` | - | Duration to show success message (ms) |
|
|
582
|
+
| `hideLogo` | `boolean` | `false` | Hide logo |
|
|
583
|
+
| `hideTitles` | `boolean` | `false` | Hide titles |
|
|
604
584
|
|
|
605
585
|
## 🎯 Common Patterns
|
|
606
586
|
|
|
@@ -614,7 +594,7 @@ function App() {
|
|
|
614
594
|
<WhenUnauthenticated>
|
|
615
595
|
<LoginPage />
|
|
616
596
|
</WhenUnauthenticated>
|
|
617
|
-
|
|
597
|
+
|
|
618
598
|
<WhenAuthenticated>
|
|
619
599
|
<ProtectedRoutes />
|
|
620
600
|
</WhenAuthenticated>
|
|
@@ -641,11 +621,11 @@ function Navigation() {
|
|
|
641
621
|
<nav>
|
|
642
622
|
<Link to="/dashboard">Dashboard</Link>
|
|
643
623
|
<Link to="/projects">Projects</Link>
|
|
644
|
-
|
|
624
|
+
|
|
645
625
|
<WhenRoles roles={['admin', 'owner']}>
|
|
646
626
|
<Link to="/admin">Admin Panel</Link>
|
|
647
627
|
</WhenRoles>
|
|
648
|
-
|
|
628
|
+
|
|
649
629
|
<WhenRoles roles={['admin']}>
|
|
650
630
|
<Link to="/settings">Settings</Link>
|
|
651
631
|
</WhenRoles>
|
|
@@ -664,12 +644,8 @@ const WorkspaceContext = createContext(null);
|
|
|
664
644
|
|
|
665
645
|
export function WorkspaceProvider({ children }) {
|
|
666
646
|
const workspaceData = useSaaSWorkspaces();
|
|
667
|
-
|
|
668
|
-
return
|
|
669
|
-
<WorkspaceContext.Provider value={workspaceData}>
|
|
670
|
-
{children}
|
|
671
|
-
</WorkspaceContext.Provider>
|
|
672
|
-
);
|
|
647
|
+
|
|
648
|
+
return <WorkspaceContext.Provider value={workspaceData}>{children}</WorkspaceContext.Provider>;
|
|
673
649
|
}
|
|
674
650
|
|
|
675
651
|
export function useWorkspace() {
|
|
@@ -686,11 +662,11 @@ function Dashboard() {
|
|
|
686
662
|
return (
|
|
687
663
|
<div>
|
|
688
664
|
<StandardFeatures />
|
|
689
|
-
|
|
665
|
+
|
|
690
666
|
<WhenWorkspaceFeatureEnabled slug="advanced-analytics">
|
|
691
667
|
<AdvancedAnalytics />
|
|
692
668
|
</WhenWorkspaceFeatureEnabled>
|
|
693
|
-
|
|
669
|
+
|
|
694
670
|
<WhenWorkspaceFeatureEnabled slug="ai-assistant">
|
|
695
671
|
<AIAssistant />
|
|
696
672
|
</WhenWorkspaceFeatureEnabled>
|
|
@@ -707,7 +683,7 @@ import { useEffect } from 'react';
|
|
|
707
683
|
|
|
708
684
|
function App() {
|
|
709
685
|
const { currentWorkspace, setCurrentWorkspace } = useSaaSWorkspaces();
|
|
710
|
-
|
|
686
|
+
|
|
711
687
|
useEffect(() => {
|
|
712
688
|
if (currentWorkspace) {
|
|
713
689
|
// Update your app state when workspace changes
|
|
@@ -715,7 +691,7 @@ function App() {
|
|
|
715
691
|
// Reload data, update context, etc.
|
|
716
692
|
}
|
|
717
693
|
}, [currentWorkspace]);
|
|
718
|
-
|
|
694
|
+
|
|
719
695
|
return <YourApp />;
|
|
720
696
|
}
|
|
721
697
|
```
|
|
@@ -734,7 +710,7 @@ function CustomErrorFallback({ error, resetError }) {
|
|
|
734
710
|
</div>
|
|
735
711
|
);
|
|
736
712
|
}
|
|
737
|
-
|
|
713
|
+
|
|
738
714
|
return (
|
|
739
715
|
<div>
|
|
740
716
|
<h2>Something went wrong</h2>
|
|
@@ -764,10 +740,10 @@ function App() {
|
|
|
764
740
|
|
|
765
741
|
```tsx
|
|
766
742
|
// ❌ Wrong
|
|
767
|
-
orgId=
|
|
743
|
+
orgId = '123';
|
|
768
744
|
|
|
769
745
|
// ✅ Correct
|
|
770
|
-
orgId=
|
|
746
|
+
orgId = '507f1f77bcf86cd799439011'; // 24 hex characters
|
|
771
747
|
```
|
|
772
748
|
|
|
773
749
|
#### 2. "Invalid serverUrl" Error
|
|
@@ -778,12 +754,12 @@ orgId="507f1f77bcf86cd799439011" // 24 hex characters
|
|
|
778
754
|
|
|
779
755
|
```tsx
|
|
780
756
|
// ❌ Wrong
|
|
781
|
-
serverUrl=
|
|
782
|
-
serverUrl=
|
|
757
|
+
serverUrl = 'api.example.com';
|
|
758
|
+
serverUrl = 'not-a-url';
|
|
783
759
|
|
|
784
760
|
// ✅ Correct
|
|
785
|
-
serverUrl=
|
|
786
|
-
serverUrl=
|
|
761
|
+
serverUrl = 'https://api.example.com';
|
|
762
|
+
serverUrl = 'http://localhost:3000';
|
|
787
763
|
```
|
|
788
764
|
|
|
789
765
|
#### 3. Authentication Not Working
|
|
@@ -806,7 +782,7 @@ handleAuthentication: async (code: string) => {
|
|
|
806
782
|
});
|
|
807
783
|
const data = await response.json();
|
|
808
784
|
return { sessionId: data.sessionId }; // Must return sessionId
|
|
809
|
-
}
|
|
785
|
+
};
|
|
810
786
|
```
|
|
811
787
|
|
|
812
788
|
#### 4. Workspace Not Loading
|
|
@@ -916,7 +892,9 @@ function App() {
|
|
|
916
892
|
```tsx
|
|
917
893
|
// ❌ Bad
|
|
918
894
|
<SaaSOSProvider>
|
|
919
|
-
<SaaSOSProvider>
|
|
895
|
+
<SaaSOSProvider>
|
|
896
|
+
{' '}
|
|
897
|
+
{/* Don't nest */}
|
|
920
898
|
<App />
|
|
921
899
|
</SaaSOSProvider>
|
|
922
900
|
</SaaSOSProvider>
|
|
@@ -1003,7 +981,7 @@ if (isFeatureEnabled('premium')) {
|
|
|
1003
981
|
const { signIn, status } = useSaaSAuth();
|
|
1004
982
|
<button onClick={signIn} disabled={status === 'loading'}>
|
|
1005
983
|
{status === 'loading' ? 'Signing in...' : 'Sign In'}
|
|
1006
|
-
</button
|
|
984
|
+
</button>;
|
|
1007
985
|
```
|
|
1008
986
|
|
|
1009
987
|
### 6. Event Handling
|
|
@@ -1045,10 +1023,7 @@ function MyComponent({ workspace }: { workspace: IWorkspace }) {
|
|
|
1045
1023
|
|
|
1046
1024
|
```tsx
|
|
1047
1025
|
// ✅ Good
|
|
1048
|
-
const filteredWorkspaces = useMemo(
|
|
1049
|
-
() => workspaces.filter(w => w.active),
|
|
1050
|
-
[workspaces]
|
|
1051
|
-
);
|
|
1026
|
+
const filteredWorkspaces = useMemo(() => workspaces.filter(w => w.active), [workspaces]);
|
|
1052
1027
|
```
|
|
1053
1028
|
|
|
1054
1029
|
✅ **Do**: Use `refreshWorkspaces()` for background updates instead of `fetchWorkspaces()`.
|