@buildbase/sdk 0.0.6 → 0.0.8

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import react__default, { ReactNode } from 'react';
2
+ import react__default, { ReactNode, Component } from 'react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
 
5
5
  interface IDocument {
@@ -19,6 +19,7 @@ interface IUser extends IDocument {
19
19
  timezone: string;
20
20
  language: string;
21
21
  currency: string;
22
+ attributes?: Record<string, string | number | boolean>;
22
23
  }
23
24
 
24
25
  interface IWorkspace {
@@ -222,6 +223,8 @@ interface IProps {
222
223
  }
223
224
  declare const WhenWorkspaceFeatureEnabled: (props: IProps) => react.ReactNode;
224
225
  declare const WhenWorkspaceFeatureDisabled: (props: IProps) => react.ReactNode;
226
+ declare const WhenUserFeatureEnabled: (props: IProps) => react.ReactNode;
227
+ declare const WhenUserFeatureDisabled: (props: IProps) => react.ReactNode;
225
228
 
226
229
  declare function useSaaSAuth(): {
227
230
  user: AuthUser | undefined;
@@ -232,6 +235,7 @@ declare function useSaaSAuth(): {
232
235
  status: AuthStatus;
233
236
  signIn: () => Promise<void>;
234
237
  signOut: () => Promise<void>;
238
+ openWorkspaceSettings: (section?: "profile" | "general" | "users" | "features" | "danger") => void;
235
239
  };
236
240
 
237
241
  declare function useSaaSSettings(): {
@@ -239,6 +243,31 @@ declare function useSaaSSettings(): {
239
243
  getSettings: () => Promise<ISettings | null>;
240
244
  };
241
245
 
246
+ interface UserContextValue {
247
+ attributes: Record<string, string | number | boolean>;
248
+ features: Record<string, boolean>;
249
+ isLoading: boolean;
250
+ error: Error | null;
251
+ updateAttributes: (updates: Record<string, string | number | boolean>) => Promise<IUser>;
252
+ updateAttribute: (attributeKey: string, value: string | number | boolean) => Promise<IUser>;
253
+ refreshAttributes: () => Promise<void>;
254
+ refreshFeatures: () => Promise<void>;
255
+ }
256
+
257
+ declare function useUserAttributes(): UserContextValue;
258
+ declare function useUserFeatures(): {
259
+ features: Record<string, boolean>;
260
+ isLoading: boolean;
261
+ error: Error | null;
262
+ refreshFeatures: () => Promise<void>;
263
+ isFeatureEnabled: (featureId: string) => boolean;
264
+ };
265
+
266
+ declare function WorkspaceSwitcher(props: {
267
+ trigger: (isLoading: boolean, currentWorkspace: IWorkspace | null) => ReactNode;
268
+ onWorkspaceChange: (workspace: IWorkspace) => Promise<void>;
269
+ }): react_jsx_runtime.JSX.Element;
270
+
242
271
  declare const useSaaSWorkspaces: () => {
243
272
  workspaces: IWorkspace[];
244
273
  loading: boolean;
@@ -246,6 +275,7 @@ declare const useSaaSWorkspaces: () => {
246
275
  fetchWorkspaces: () => Promise<void>;
247
276
  refreshWorkspaces: () => Promise<void>;
248
277
  refreshing: boolean;
278
+ WorkspaceSwitcher: typeof WorkspaceSwitcher;
249
279
  currentWorkspace: IWorkspace | null;
250
280
  setCurrentWorkspace: (ws: IWorkspace) => void;
251
281
  resetCurrentWorkspace: () => void;
@@ -279,11 +309,6 @@ declare const useSaaSWorkspaces: () => {
279
309
  }>;
280
310
  };
281
311
 
282
- declare function WorkspaceSwitcher(props: {
283
- trigger: (isLoading: boolean, currentWorkspace: IWorkspace | null) => ReactNode;
284
- onWorkspaceChange: (workspace: IWorkspace) => Promise<void>;
285
- }): react_jsx_runtime.JSX.Element;
286
-
287
312
  /**
288
313
  * EventEmitter class to handle and trigger event callbacks
289
314
  * This class manages all event listeners and provides methods to trigger events
@@ -363,5 +388,98 @@ declare class EventEmitter {
363
388
  }
364
389
  declare const eventEmitter: EventEmitter;
365
390
 
366
- export { ApiVersion, BetaForm, SaaSOSProvider, WhenAuthenticated, WhenRoles, WhenUnauthenticated, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceSwitcher, eventEmitter, useSaaSAuth, useSaaSSettings, useSaaSWorkspaces };
367
- export type { EventData, EventType, IEventCallbacks, UserCreatedEventData, UserUpdatedEventData, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };
391
+ interface ErrorBoundaryProps {
392
+ children: ReactNode;
393
+ /**
394
+ * Fallback UI to render when an error occurs
395
+ */
396
+ fallback?: ReactNode | ((error: Error, resetError: () => void) => ReactNode);
397
+ /**
398
+ * Called when an error is caught
399
+ */
400
+ onError?: (error: Error, errorInfo: react__default.ErrorInfo) => void;
401
+ /**
402
+ * Whether to reset error state when children change
403
+ * @default true
404
+ */
405
+ resetOnPropsChange?: boolean;
406
+ }
407
+ interface ErrorBoundaryState {
408
+ hasError: boolean;
409
+ error: Error | null;
410
+ }
411
+ /**
412
+ * Error Boundary component for catching React component errors
413
+ * Wraps SDK components to prevent crashes from propagating
414
+ */
415
+ declare class SDKErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
416
+ constructor(props: ErrorBoundaryProps);
417
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState;
418
+ componentDidCatch(error: Error, errorInfo: react__default.ErrorInfo): void;
419
+ componentDidUpdate(prevProps: ErrorBoundaryProps): void;
420
+ resetError: () => void;
421
+ render(): ReactNode;
422
+ }
423
+
424
+ /**
425
+ * Centralized Error Handler for SDK
426
+ * Provides consistent error handling, logging, and user-facing error management
427
+ */
428
+ interface SDKErrorContext {
429
+ component?: string;
430
+ action?: string;
431
+ metadata?: Record<string, unknown>;
432
+ }
433
+ declare class SDKError extends Error {
434
+ readonly code?: string | undefined;
435
+ readonly context?: SDKErrorContext | undefined;
436
+ readonly originalError?: Error | undefined;
437
+ constructor(message: string, code?: string | undefined, context?: SDKErrorContext | undefined, originalError?: Error | undefined);
438
+ }
439
+ interface ErrorHandlerConfig {
440
+ /**
441
+ * Custom error callback for handling errors
442
+ * @param error - The error that occurred
443
+ * @param context - Additional context about where the error occurred
444
+ */
445
+ onError?: (error: Error, context: SDKErrorContext) => void;
446
+ /**
447
+ * Whether to log errors to console in development
448
+ * @default true
449
+ */
450
+ enableConsoleLogging?: boolean;
451
+ /**
452
+ * Whether to show user-facing error notifications
453
+ * @default false
454
+ */
455
+ showUserNotifications?: boolean;
456
+ }
457
+ declare class ErrorHandler {
458
+ private config;
459
+ /**
460
+ * Configure the error handler
461
+ */
462
+ configure(config: Partial<ErrorHandlerConfig>): void;
463
+ /**
464
+ * Handle an error with context
465
+ */
466
+ handleError(error: Error | unknown, context?: SDKErrorContext): void;
467
+ /**
468
+ * Notify user of error (placeholder for notification system)
469
+ */
470
+ private notifyUser;
471
+ /**
472
+ * Create a safe error handler wrapper for async functions
473
+ */
474
+ wrapAsync<T extends (...args: any[]) => Promise<any>>(fn: T, context: SDKErrorContext): T;
475
+ /**
476
+ * Create a safe error handler wrapper for sync functions
477
+ */
478
+ wrapSync<T extends (...args: any[]) => any>(fn: T, context: SDKErrorContext): T;
479
+ }
480
+ declare const errorHandler: ErrorHandler;
481
+ declare function handleError(error: Error | unknown, context?: SDKErrorContext): void;
482
+ declare function createSDKError(message: string, code?: string, context?: SDKErrorContext, originalError?: Error): SDKError;
483
+
484
+ export { ApiVersion, BetaForm, SDKErrorBoundary as ErrorBoundary, SDKError, SDKErrorBoundary, SaaSOSProvider, WhenAuthenticated, WhenRoles, WhenUnauthenticated, WhenUserFeatureDisabled, WhenUserFeatureEnabled, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceSwitcher, createSDKError, errorHandler, eventEmitter, handleError, useSaaSAuth, useSaaSSettings, useSaaSWorkspaces, useUserAttributes, useUserFeatures };
485
+ export type { ErrorHandlerConfig, EventData, EventType, IEventCallbacks, SDKErrorContext, UserCreatedEventData, UserUpdatedEventData, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };