@buildbase/sdk 0.0.3 → 0.0.5

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.
Files changed (57) hide show
  1. package/dist/index.d.ts +238 -55
  2. package/dist/index.esm.js +1 -29
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +1 -29
  5. package/dist/index.js.map +1 -1
  6. package/dist/saas-os.css +1 -1
  7. package/dist/types/contexts/AuthContext/index.d.ts +1 -1
  8. package/dist/types/contexts/AuthContext/reducer.d.ts +0 -1
  9. package/dist/types/contexts/OSContext/actions.d.ts +2 -0
  10. package/dist/types/contexts/OSContext/reducer.d.ts +1 -1
  11. package/dist/types/contexts/OSContext/types.d.ts +4 -0
  12. package/dist/types/contexts/index.d.ts +1 -1
  13. package/dist/types/contexts/shared/useAppSelector.d.ts +1 -1
  14. package/dist/types/index.d.ts +4 -0
  15. package/dist/types/lib/api-client.d.ts +0 -4
  16. package/dist/types/providers/auth/hooks.d.ts +1 -1
  17. package/dist/types/providers/auth/types.d.ts +12 -4
  18. package/dist/types/providers/auth/utils.d.ts +32 -7
  19. package/dist/types/providers/constants.d.ts +2 -0
  20. package/dist/types/providers/events/EventEmitter.d.ts +81 -0
  21. package/dist/types/providers/events/index.d.ts +2 -0
  22. package/dist/types/providers/events/types.d.ts +61 -0
  23. package/dist/types/providers/os/hooks.d.ts +5 -0
  24. package/dist/types/providers/os/types.d.ts +9 -1
  25. package/dist/types/providers/types.d.ts +9 -0
  26. package/dist/types/providers/workspace/api.d.ts +13 -3
  27. package/dist/types/providers/workspace/hooks.d.ts +16 -3
  28. package/dist/types/providers/workspace/ui/SettingsDanger.d.ts +6 -0
  29. package/dist/types/providers/workspace/ui/SettingsDialog.d.ts +1 -1
  30. package/package.json +3 -21
  31. package/dist/types/components/ui/accordion.d.ts +0 -7
  32. package/dist/types/components/ui/alert.d.ts +0 -8
  33. package/dist/types/components/ui/aspect-ratio.d.ts +0 -3
  34. package/dist/types/components/ui/badge.d.ts +0 -9
  35. package/dist/types/components/ui/buttonIcon.d.ts +0 -9
  36. package/dist/types/components/ui/calendar.d.ts +0 -8
  37. package/dist/types/components/ui/card.d.ts +0 -8
  38. package/dist/types/components/ui/checkbox.d.ts +0 -4
  39. package/dist/types/components/ui/collapsible.d.ts +0 -5
  40. package/dist/types/components/ui/context-menu.d.ts +0 -27
  41. package/dist/types/components/ui/dateRangePicker.d.ts +0 -9
  42. package/dist/types/components/ui/dropdown-menu.d.ts +0 -27
  43. package/dist/types/components/ui/heading.d.ts +0 -10
  44. package/dist/types/components/ui/hover-card.d.ts +0 -6
  45. package/dist/types/components/ui/menubar.d.ts +0 -33
  46. package/dist/types/components/ui/navigation-menu.d.ts +0 -12
  47. package/dist/types/components/ui/progress.d.ts +0 -4
  48. package/dist/types/components/ui/sheet.d.ts +0 -28
  49. package/dist/types/components/ui/slider.d.ts +0 -4
  50. package/dist/types/components/ui/table.d.ts +0 -10
  51. package/dist/types/components/ui/tabs.d.ts +0 -7
  52. package/dist/types/components/ui/textarea.d.ts +0 -5
  53. package/dist/types/components/ui/toast.d.ts +0 -15
  54. package/dist/types/components/ui/toaster.d.ts +0 -1
  55. package/dist/types/components/ui/toggle.d.ts +0 -12
  56. package/dist/types/components/ui/tooltip.d.ts +0 -7
  57. package/dist/types/components/ui/use-toast.d.ts +0 -44
package/dist/index.d.ts CHANGED
@@ -2,6 +2,113 @@ import * as react from 'react';
2
2
  import react__default, { ReactNode } from 'react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
 
5
+ interface IDocument {
6
+ _id: string;
7
+ id: string;
8
+ createdAt: string;
9
+ updatedAt: string;
10
+ deleted: boolean;
11
+ }
12
+ interface IUser extends IDocument {
13
+ _id: string;
14
+ name: string;
15
+ email: string;
16
+ image: string;
17
+ role: string;
18
+ country: string;
19
+ timezone: string;
20
+ language: string;
21
+ currency: string;
22
+ }
23
+
24
+ interface IWorkspace {
25
+ _id: string;
26
+ name: string;
27
+ image?: string;
28
+ workspaceId: string;
29
+ users: IUser[];
30
+ roles: string[];
31
+ createdBy: string | IUser;
32
+ features: Record<string, boolean>;
33
+ }
34
+ interface IWorkspaceFeature {
35
+ _id: string;
36
+ name: string;
37
+ description: string;
38
+ userManaged: boolean;
39
+ defaultValue: boolean;
40
+ slug: string;
41
+ category: string;
42
+ createdAt: Date;
43
+ updatedAt: Date;
44
+ }
45
+ interface IWorkspaceUser {
46
+ _id: string;
47
+ workspace: string | IWorkspace;
48
+ user: string | IUser;
49
+ role: string;
50
+ }
51
+
52
+ /**
53
+ * Event types for all SDK events
54
+ */
55
+ type EventType = 'user:created' | 'user:updated' | 'workspace:changed' | 'workspace:updated' | 'workspace:user-added' | 'workspace:user-removed' | 'workspace:user-role-changed' | 'workspace:created' | 'workspace:deleted';
56
+ /**
57
+ * Event data types for each event
58
+ */
59
+ interface UserCreatedEventData {
60
+ user: IUser;
61
+ }
62
+ interface UserUpdatedEventData {
63
+ user: IUser;
64
+ previousUser?: IUser;
65
+ }
66
+ interface WorkspaceChangedEventData {
67
+ workspace: IWorkspace;
68
+ previousWorkspace?: IWorkspace | null;
69
+ }
70
+ interface WorkspaceUpdatedEventData {
71
+ workspace: IWorkspace;
72
+ }
73
+ interface WorkspaceUserAddedEventData {
74
+ userId: string;
75
+ workspace: IWorkspace;
76
+ role: string;
77
+ }
78
+ interface WorkspaceUserRemovedEventData {
79
+ userId: string;
80
+ workspace: IWorkspace;
81
+ role: string;
82
+ }
83
+ interface WorkspaceUserRoleChangedEventData {
84
+ userId: string;
85
+ workspace: IWorkspace;
86
+ previousRole: string;
87
+ newRole: string;
88
+ }
89
+ interface WorkspaceCreatedEventData {
90
+ workspace: IWorkspace;
91
+ }
92
+ interface WorkspaceDeletedEventData {
93
+ workspace: IWorkspace;
94
+ }
95
+ /**
96
+ * Union type for all event data
97
+ */
98
+ type EventData = UserCreatedEventData | UserUpdatedEventData | WorkspaceChangedEventData | WorkspaceUpdatedEventData | WorkspaceUserAddedEventData | WorkspaceUserRemovedEventData | WorkspaceUserRoleChangedEventData | WorkspaceCreatedEventData | WorkspaceDeletedEventData;
99
+ /**
100
+ * Single event callback function
101
+ * Handles all events with conditional logic based on event type
102
+ */
103
+ interface IEventCallbacks {
104
+ /**
105
+ * Called when any event occurs
106
+ * @param eventType - The type of event that occurred
107
+ * @param data - The event data (type varies based on eventType)
108
+ */
109
+ handleEvent?: (eventType: EventType, data: EventData) => void | Promise<void>;
110
+ }
111
+
5
112
  declare enum AuthStatus {
6
113
  loading = "loading",
7
114
  authenticated = "authenticated",
@@ -20,7 +127,7 @@ interface AuthUser {
20
127
  }
21
128
  interface AuthSession {
22
129
  user: AuthUser;
23
- accessToken: string;
130
+ sessionId: string;
24
131
  expires: string;
25
132
  }
26
133
  interface IAuthConfig {
@@ -29,17 +136,42 @@ interface IAuthConfig {
29
136
  callbacks?: IAuthCallbacks;
30
137
  }
31
138
  interface IAuthCallbacks {
32
- handleAuthentication: (token: string) => Promise<void>;
33
- verifyToken: (token: string) => Promise<boolean>;
139
+ handleAuthentication: (code: string) => Promise<{
140
+ sessionId: string;
141
+ }>;
142
+ onSignOut: () => Promise<void>;
143
+ /**
144
+ * Event handler for User and Workspace events
145
+ * @param eventType - The type of event that occurred
146
+ * @param data - The event data (type varies based on eventType)
147
+ */
148
+ handleEvent?: (eventType: EventType, data: EventData) => void | Promise<void>;
149
+ }
150
+
151
+ interface ISettings {
152
+ workspace: {
153
+ roles: string[];
154
+ defaultRole: string;
155
+ maxWorkspaces: number;
156
+ maxWorkspaceUsers: number;
157
+ };
158
+ [key: string]: any;
34
159
  }
35
160
 
161
+ /**
162
+ * Supported API versions
163
+ */
164
+ declare enum ApiVersion {
165
+ V1 = "v1"
166
+ }
36
167
  interface IOsConfig {
37
168
  serverUrl: string;
38
- version: string;
169
+ version: ApiVersion;
39
170
  orgId: string;
40
171
  }
41
172
  interface IOsState extends IOsConfig {
42
173
  auth?: IAuthConfig;
174
+ settings?: ISettings | null;
43
175
  }
44
176
 
45
177
  interface SaaSOSProviderProps extends IOsState {
@@ -92,7 +224,7 @@ declare const WhenWorkspaceFeatureEnabled: (props: IProps) => react.ReactNode;
92
224
  declare const WhenWorkspaceFeatureDisabled: (props: IProps) => react.ReactNode;
93
225
 
94
226
  declare function useSaaSAuth(): {
95
- user: AuthUser | null;
227
+ user: AuthUser | undefined;
96
228
  session: AuthSession | null;
97
229
  isLoading: boolean;
98
230
  isAuthenticated: boolean;
@@ -102,52 +234,10 @@ declare function useSaaSAuth(): {
102
234
  signOut: () => Promise<void>;
103
235
  };
104
236
 
105
- interface IDocument {
106
- _id: string;
107
- id: string;
108
- createdAt: string;
109
- updatedAt: string;
110
- deleted: boolean;
111
- }
112
- interface IUser extends IDocument {
113
- _id: string;
114
- name: string;
115
- email: string;
116
- image: string;
117
- role: string;
118
- country: string;
119
- timezone: string;
120
- language: string;
121
- currency: string;
122
- }
123
-
124
- interface IWorkspace {
125
- _id: string;
126
- name: string;
127
- image?: string;
128
- workspaceId: string;
129
- users: IUser[];
130
- roles: string[];
131
- createdBy: string | IUser;
132
- features: Record<string, boolean>;
133
- }
134
- interface IWorkspaceFeature {
135
- _id: string;
136
- name: string;
137
- description: string;
138
- userManaged: boolean;
139
- defaultValue: boolean;
140
- slug: string;
141
- category: string;
142
- createdAt: Date;
143
- updatedAt: Date;
144
- }
145
- interface IWorkspaceUser {
146
- _id: string;
147
- workspace: string | IWorkspace;
148
- user: string | IUser;
149
- role: string;
150
- }
237
+ declare function useSaaSSettings(): {
238
+ settings: ISettings | null | undefined;
239
+ getSettings: () => Promise<ISettings | null>;
240
+ };
151
241
 
152
242
  declare function WorkspaceSwitcher(props: {
153
243
  trigger: (isLoading: boolean, currentWorkspace: IWorkspace | null) => ReactNode;
@@ -173,13 +263,106 @@ declare const useSaaSWorkspaces: () => {
173
263
  switching: boolean;
174
264
  updateWorkspace: (ws: IWorkspace, _data: Partial<IWorkspace>) => Promise<void>;
175
265
  getUsers: (workspaceId: string) => Promise<IWorkspaceUser[]>;
176
- addUser: (workspaceId: string, email: string, role: string) => Promise<IWorkspaceUser>;
266
+ addUser: (workspaceId: string, email: string, role: string) => Promise<{
267
+ userId: string;
268
+ workspace: IWorkspace;
269
+ message: string;
270
+ }>;
177
271
  removeUser: (workspaceId: string, userId: string) => Promise<{
178
- success: boolean;
272
+ userId: string;
273
+ workspace: IWorkspace;
274
+ message: string;
275
+ }>;
276
+ updateUser: (workspaceId: string, userId: string, config: Partial<IWorkspaceUser>) => Promise<{
277
+ userId: string;
278
+ workspace: IWorkspace;
279
+ message: string;
179
280
  }>;
180
- updateUser: (workspaceId: string, userId: string, config: Partial<IWorkspaceUser>) => Promise<IWorkspaceUser>;
181
281
  getProfile: () => Promise<IUser>;
182
282
  updateUserProfile: (config: Partial<IUser>) => Promise<IUser>;
283
+ deleteWorkspace: (workspaceId: string) => Promise<{
284
+ success: boolean;
285
+ }>;
183
286
  };
184
287
 
185
- export { BetaForm, SaaSOSProvider, WhenAuthenticated, WhenRoles, WhenUnauthenticated, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceSwitcher, useSaaSAuth, useSaaSWorkspaces };
288
+ /**
289
+ * EventEmitter class to handle and trigger event callbacks
290
+ * This class manages all event listeners and provides methods to trigger events
291
+ */
292
+ declare class EventEmitter {
293
+ private callbacks;
294
+ /**
295
+ * Set the event callbacks
296
+ * @param callbacks - The event callbacks to register
297
+ */
298
+ setCallbacks(callbacks: IEventCallbacks | null): void;
299
+ /**
300
+ * Get the current event callbacks
301
+ * @returns The current event callbacks or null
302
+ */
303
+ getCallbacks(): IEventCallbacks | null;
304
+ /**
305
+ * Emit an event
306
+ * @param eventType - The type of event
307
+ * @param data - The event data
308
+ */
309
+ private emit;
310
+ /**
311
+ * Trigger user created event
312
+ * @param user - The newly created user
313
+ */
314
+ emitUserCreated(user: IUser): Promise<void>;
315
+ /**
316
+ * Trigger user updated event
317
+ * @param user - The updated user
318
+ * @param previousUser - The user data before the update (optional)
319
+ */
320
+ emitUserUpdated(user: IUser, previousUser?: IUser): Promise<void>;
321
+ /**
322
+ * Trigger workspace changed event
323
+ * @param workspace - The newly selected workspace
324
+ * @param previousWorkspace - The previously selected workspace (optional)
325
+ */
326
+ emitWorkspaceChanged(workspace: IWorkspace, previousWorkspace?: IWorkspace | null): Promise<void>;
327
+ /**
328
+ * Trigger workspace updated event
329
+ * @param workspace - The updated workspace
330
+ */
331
+ emitWorkspaceUpdated(workspace: IWorkspace): Promise<void>;
332
+ /**
333
+ * Trigger workspace user added event
334
+ * @param userId - The ID of the user that was added
335
+ * @param workspace - The workspace the user was added to
336
+ * @param role - The role assigned to the user
337
+ */
338
+ emitWorkspaceUserAdded(userId: string, workspace: IWorkspace, role: string): Promise<void>;
339
+ /**
340
+ * Trigger workspace user removed event
341
+ * @param userId - The ID of the user that was removed
342
+ * @param workspace - The workspace the user was removed from
343
+ * @param role - The role the user had in the workspace
344
+ */
345
+ emitWorkspaceUserRemoved(userId: string, workspace: IWorkspace, role: string): Promise<void>;
346
+ /**
347
+ * Trigger workspace user role changed event
348
+ * @param userId - The ID of the user whose role was changed
349
+ * @param workspace - The workspace where the role was changed
350
+ * @param previousRole - The previous role of the user
351
+ * @param newRole - The new role of the user
352
+ */
353
+ emitWorkspaceUserRoleChanged(userId: string, workspace: IWorkspace, previousRole: string, newRole: string): Promise<void>;
354
+ /**
355
+ * Trigger workspace created event
356
+ * @param workspace - The newly created workspace
357
+ */
358
+ emitWorkspaceCreated(workspace: IWorkspace): Promise<void>;
359
+ /**
360
+ * Trigger workspace deleted event
361
+ * @param workspace - The deleted workspace
362
+ */
363
+ emitWorkspaceDeleted(workspace: IWorkspace): Promise<void>;
364
+ }
365
+ declare const eventEmitter: EventEmitter;
366
+
367
+ export { ApiVersion, BetaForm, SaaSOSProvider, WhenAuthenticated, WhenRoles, WhenUnauthenticated, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceSwitcher, eventEmitter, useSaaSAuth, useSaaSSettings, useSaaSWorkspaces };
368
+ export type { EventData, EventType, IEventCallbacks, UserCreatedEventData, UserUpdatedEventData, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };