@buildbase/sdk 0.0.24 → 0.0.25
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.esm.js +0 -1
- package/dist/index.js +0 -1
- package/package.json +3 -2
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types/api/currency-utils.d.ts +0 -44
- package/dist/types/api/index.d.ts +0 -12
- package/dist/types/api/pricing-variant-utils.d.ts +0 -66
- package/dist/types/api/quota-utils.d.ts +0 -24
- package/dist/types/api/types.d.ts +0 -495
- package/dist/types/components/ErrorBoundary.d.ts +0 -81
- package/dist/types/components/beta/BetaForm.d.ts +0 -24
- package/dist/types/components/beta/api.d.ts +0 -48
- package/dist/types/components/beta/hooks.d.ts +0 -11
- package/dist/types/components/beta/schema.d.ts +0 -6
- package/dist/types/components/beta/types.d.ts +0 -8
- package/dist/types/components/dropdowns/country/countries.d.ts +0 -7
- package/dist/types/components/dropdowns/country/selectCountry.d.ts +0 -6
- package/dist/types/components/dropdowns/currency/currencies.d.ts +0 -6
- package/dist/types/components/dropdowns/currency/selectCurrency.d.ts +0 -6
- package/dist/types/components/dropdowns/language/languages.d.ts +0 -6
- package/dist/types/components/dropdowns/language/selectLanguage.d.ts +0 -6
- package/dist/types/components/dropdowns/timezone/selectTimeZone.d.ts +0 -6
- package/dist/types/components/dropdowns/timezone/timezones.d.ts +0 -8
- package/dist/types/components/features/index.d.ts +0 -130
- package/dist/types/components/pricing/PricingPage.d.ts +0 -49
- package/dist/types/components/pricing/index.d.ts +0 -2
- package/dist/types/components/quota/index.d.ts +0 -121
- package/dist/types/components/subscription/index.d.ts +0 -182
- package/dist/types/components/ui/alert-dialog.d.ts +0 -20
- package/dist/types/components/ui/avatar.d.ts +0 -6
- package/dist/types/components/ui/button.d.ts +0 -18
- package/dist/types/components/ui/command-select.d.ts +0 -13
- package/dist/types/components/ui/command.d.ts +0 -82
- package/dist/types/components/ui/dialog.d.ts +0 -19
- package/dist/types/components/ui/form.d.ts +0 -23
- package/dist/types/components/ui/input.d.ts +0 -5
- package/dist/types/components/ui/label.d.ts +0 -5
- package/dist/types/components/ui/popover.d.ts +0 -6
- package/dist/types/components/ui/radio-group.d.ts +0 -5
- package/dist/types/components/ui/scroll-area.d.ts +0 -5
- package/dist/types/components/ui/select.d.ts +0 -11
- package/dist/types/components/ui/separator.d.ts +0 -4
- package/dist/types/components/ui/skeleton.d.ts +0 -3
- package/dist/types/components/ui/switch.d.ts +0 -4
- package/dist/types/components/user/auth.d.ts +0 -76
- package/dist/types/components/user/role.d.ts +0 -84
- package/dist/types/contexts/AuthContext/AuthContext.d.ts +0 -9
- package/dist/types/contexts/AuthContext/actions.d.ts +0 -12
- package/dist/types/contexts/AuthContext/index.d.ts +0 -4
- package/dist/types/contexts/AuthContext/reducer.d.ts +0 -19
- package/dist/types/contexts/AuthContext/types.d.ts +0 -18
- package/dist/types/contexts/OSContext/OSContext.d.ts +0 -9
- package/dist/types/contexts/OSContext/actions.d.ts +0 -11
- package/dist/types/contexts/OSContext/index.d.ts +0 -4
- package/dist/types/contexts/OSContext/reducer.d.ts +0 -11
- package/dist/types/contexts/OSContext/types.d.ts +0 -16
- package/dist/types/contexts/QuotaUsageContext/QuotaUsageContext.d.ts +0 -22
- package/dist/types/contexts/QuotaUsageContext/index.d.ts +0 -2
- package/dist/types/contexts/QuotaUsageContext/quotaUsageInvalidation.d.ts +0 -21
- package/dist/types/contexts/QuotaUsageContext/types.d.ts +0 -14
- package/dist/types/contexts/SDKContext/SDKContextProvider.d.ts +0 -18
- package/dist/types/contexts/SDKContext/index.d.ts +0 -2
- package/dist/types/contexts/SDKContext/types.d.ts +0 -12
- package/dist/types/contexts/SubscriptionContext/SubscriptionContext.d.ts +0 -22
- package/dist/types/contexts/SubscriptionContext/index.d.ts +0 -2
- package/dist/types/contexts/SubscriptionContext/subscriptionInvalidation.d.ts +0 -21
- package/dist/types/contexts/SubscriptionContext/types.d.ts +0 -14
- package/dist/types/contexts/WorkspaceContext/WorkspaceContext.d.ts +0 -8
- package/dist/types/contexts/WorkspaceContext/actions.d.ts +0 -19
- package/dist/types/contexts/WorkspaceContext/index.d.ts +0 -4
- package/dist/types/contexts/WorkspaceContext/reducer.d.ts +0 -10
- package/dist/types/contexts/WorkspaceContext/types.d.ts +0 -52
- package/dist/types/contexts/index.d.ts +0 -14
- package/dist/types/contexts/shared/createContext.d.ts +0 -27
- package/dist/types/contexts/shared/types.d.ts +0 -21
- package/dist/types/contexts/shared/useAppDispatch.d.ts +0 -20
- package/dist/types/contexts/shared/useAppSelector.d.ts +0 -26
- package/dist/types/contexts/shared/useSelectWithEquality.d.ts +0 -10
- package/dist/types/contexts/shared/utils/reducerHelpers.d.ts +0 -11
- package/dist/types/contexts/shared/utils/storage.d.ts +0 -25
- package/dist/types/hooks/use-seat-status.d.ts +0 -42
- package/dist/types/hooks/use-trial-status.d.ts +0 -28
- package/dist/types/index.d.ts +0 -39
- package/dist/types/lib/api-base.d.ts +0 -49
- package/dist/types/lib/api-client.d.ts +0 -25
- package/dist/types/lib/api-utils.d.ts +0 -182
- package/dist/types/lib/error-handler.d.ts +0 -118
- package/dist/types/lib/logger.d.ts +0 -27
- package/dist/types/lib/useAsyncEffect.d.ts +0 -29
- package/dist/types/lib/utils.d.ts +0 -7
- package/dist/types/providers/ContextConfigProvider.d.ts +0 -15
- package/dist/types/providers/PortalContainer.d.ts +0 -9
- package/dist/types/providers/SaaSOSProvider.d.ts +0 -7
- package/dist/types/providers/auth/api.d.ts +0 -12
- package/dist/types/providers/auth/hooks.d.ts +0 -75
- package/dist/types/providers/auth/provider.d.ts +0 -13
- package/dist/types/providers/auth/types.d.ts +0 -62
- package/dist/types/providers/auth/utils.d.ts +0 -40
- package/dist/types/providers/constants.d.ts +0 -3
- package/dist/types/providers/events/EventEmitter.d.ts +0 -81
- package/dist/types/providers/events/index.d.ts +0 -2
- package/dist/types/providers/events/types.d.ts +0 -61
- package/dist/types/providers/os/api.d.ts +0 -11
- package/dist/types/providers/os/hooks.d.ts +0 -50
- package/dist/types/providers/os/types.d.ts +0 -19
- package/dist/types/providers/types.d.ts +0 -9
- package/dist/types/providers/user/api.d.ts +0 -16
- package/dist/types/providers/user/hooks.d.ts +0 -80
- package/dist/types/providers/user/provider.d.ts +0 -17
- package/dist/types/providers/workspace/WorkspaceSettingsProvider.d.ts +0 -9
- package/dist/types/providers/workspace/api.d.ts +0 -155
- package/dist/types/providers/workspace/hooks.d.ts +0 -161
- package/dist/types/providers/workspace/provider.d.ts +0 -8
- package/dist/types/providers/workspace/settings-manager.d.ts +0 -36
- package/dist/types/providers/workspace/subscription-hooks.d.ts +0 -741
- package/dist/types/providers/workspace/types.d.ts +0 -61
- package/dist/types/providers/workspace/ui/SettingsDanger.d.ts +0 -6
- package/dist/types/providers/workspace/ui/SettingsDialog.d.ts +0 -17
- package/dist/types/providers/workspace/ui/SettingsFeatures.d.ts +0 -5
- package/dist/types/providers/workspace/ui/SettingsGeneral.d.ts +0 -6
- package/dist/types/providers/workspace/ui/SettingsInvoices.d.ts +0 -12
- package/dist/types/providers/workspace/ui/SettingsProfile.d.ts +0 -6
- package/dist/types/providers/workspace/ui/SettingsSubscription.d.ts +0 -6
- package/dist/types/providers/workspace/ui/SettingsUsage.d.ts +0 -3
- package/dist/types/providers/workspace/ui/SettingsUsers.d.ts +0 -6
- package/dist/types/providers/workspace/ui/Sidebar.d.ts +0 -10
- package/dist/types/providers/workspace/ui/Skeleton.d.ts +0 -1
- package/dist/types/providers/workspace/ui/SubscriptionDialog.d.ts +0 -21
- package/dist/types/providers/workspace/ui/utils.d.ts +0 -2
- package/dist/types/providers/workspace/utils.d.ts +0 -28
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base API client for SDK endpoints.
|
|
3
|
-
* All domain API classes (WorkspaceApi, UserApi, etc.) extend this to share
|
|
4
|
-
* URL building, auth headers, and request/response handling.
|
|
5
|
-
*/
|
|
6
|
-
import type { ApiVersion } from '../providers/os/types';
|
|
7
|
-
export interface IBaseApiConfig {
|
|
8
|
-
serverUrl: string;
|
|
9
|
-
version: ApiVersion;
|
|
10
|
-
orgId?: string;
|
|
11
|
-
/** When true, ensureReady() also requires orgId. Used by WorkspaceApi and SettingsApi. */
|
|
12
|
-
requireOrgId?: boolean;
|
|
13
|
-
/** API path segment after version (default 'public'). e.g. 'public' => .../v1/public, 'beta' => .../v1/beta */
|
|
14
|
-
basePath?: string;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Base class for SDK API clients.
|
|
18
|
-
* Provides:
|
|
19
|
-
* - baseUrl: `${serverUrl}/api/${version}/public`
|
|
20
|
-
* - getAuthHeaders()
|
|
21
|
-
* - fetchJson<T>(path, init, errorMessage): GET/POST/etc. with handleApiResponse
|
|
22
|
-
* - fetchResponse(path, init): raw Response for custom parsing (e.g. non-JSON or custom error handling)
|
|
23
|
-
*/
|
|
24
|
-
export declare abstract class BaseApi {
|
|
25
|
-
protected readonly serverUrl: string;
|
|
26
|
-
protected readonly version: ApiVersion;
|
|
27
|
-
protected readonly orgId: string | undefined;
|
|
28
|
-
private readonly requireOrgId;
|
|
29
|
-
private readonly basePath;
|
|
30
|
-
constructor(config: IBaseApiConfig);
|
|
31
|
-
/** Throws if config is not ready for API calls. Called automatically by fetchJson/fetchResponse. */
|
|
32
|
-
protected ensureReady(): void;
|
|
33
|
-
/** Base URL: ${serverUrl}/api/${version}/${basePath} */
|
|
34
|
-
protected get baseUrl(): string;
|
|
35
|
-
/** Auth headers (x-session-id). Subclasses can override to add more. */
|
|
36
|
-
protected getAuthHeaders(): Record<string, string>;
|
|
37
|
-
/** Build full URL from path (path can be "workspaces" or "/workspaces"). */
|
|
38
|
-
protected url(path: string): string;
|
|
39
|
-
/**
|
|
40
|
-
* Execute request and parse JSON with handleApiResponse (throws on !response.ok).
|
|
41
|
-
* Use for standard JSON APIs.
|
|
42
|
-
*/
|
|
43
|
-
protected fetchJson<T>(path: string, init?: RequestInit, errorMessage?: string): Promise<T>;
|
|
44
|
-
/**
|
|
45
|
-
* Execute request and return raw Response (for custom parsing or error handling).
|
|
46
|
-
* Caller is responsible for checking response.ok and parsing body.
|
|
47
|
-
*/
|
|
48
|
-
protected fetchResponse(path: string, init?: RequestInit): Promise<Response>;
|
|
49
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
export interface ApiClientConfig {
|
|
3
|
-
baseURL?: string;
|
|
4
|
-
timeout?: number;
|
|
5
|
-
headers?: Record<string, string>;
|
|
6
|
-
}
|
|
7
|
-
export interface ApiResponse<T = unknown> {
|
|
8
|
-
data: T;
|
|
9
|
-
status: number;
|
|
10
|
-
statusText: string;
|
|
11
|
-
headers: Record<string, string | string[]> | Record<string, unknown>;
|
|
12
|
-
}
|
|
13
|
-
export declare class ApiClient {
|
|
14
|
-
private client;
|
|
15
|
-
constructor(config?: ApiClientConfig);
|
|
16
|
-
get<T = unknown>(url: string, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
|
|
17
|
-
post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
|
|
18
|
-
put<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
|
|
19
|
-
delete<T = unknown>(url: string, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
|
|
20
|
-
patch<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
|
|
21
|
-
setBaseURL(baseURL: string): void;
|
|
22
|
-
setHeader(key: string, value: string): void;
|
|
23
|
-
removeHeader(key: string): void;
|
|
24
|
-
}
|
|
25
|
-
export declare const defaultApiClient: ApiClient;
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API utility functions for consistent error handling and request management
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Check if an error is from AbortController (request was cancelled).
|
|
6
|
-
* Useful for ignoring abort errors when components unmount or requests are cancelled.
|
|
7
|
-
*
|
|
8
|
-
* @param error - The error to check
|
|
9
|
-
* @returns True if the error is an AbortError, false otherwise
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```tsx
|
|
13
|
-
* try {
|
|
14
|
-
* await safeFetch(url, { signal });
|
|
15
|
-
* } catch (error) {
|
|
16
|
-
* if (isAbortError(error)) {
|
|
17
|
-
* // Request was cancelled, ignore
|
|
18
|
-
* return;
|
|
19
|
-
* }
|
|
20
|
-
* // Handle other errors
|
|
21
|
-
* console.error('Request failed:', error);
|
|
22
|
-
* }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export declare function isAbortError(error: unknown): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Safely execute a fetch request with network error handling.
|
|
28
|
-
* Wraps native fetch to provide better error messages for network failures.
|
|
29
|
-
* Supports AbortSignal - when aborted, throws with name 'AbortError' (caller can use isAbortError()).
|
|
30
|
-
* In development mode, automatically logs request/response for debugging (prefixed with [SDK API]).
|
|
31
|
-
* Sensitive data (tokens, passwords) is automatically redacted from logs.
|
|
32
|
-
*
|
|
33
|
-
* @param url - The URL to fetch
|
|
34
|
-
* @param options - Optional fetch options (RequestInit), including AbortSignal
|
|
35
|
-
* @returns Promise resolving to Response object
|
|
36
|
-
* @throws {Error} Network errors with descriptive messages, or AbortError if request was aborted
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```tsx
|
|
40
|
-
* // Basic usage
|
|
41
|
-
* const response = await safeFetch('/api/users');
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```tsx
|
|
46
|
-
* // With abort signal
|
|
47
|
-
* const controller = new AbortController();
|
|
48
|
-
* const response = await safeFetch('/api/users', {
|
|
49
|
-
* signal: controller.signal,
|
|
50
|
-
* method: 'POST',
|
|
51
|
-
* body: JSON.stringify({ name: 'John' }),
|
|
52
|
-
* });
|
|
53
|
-
*
|
|
54
|
-
* // Cancel request
|
|
55
|
-
* controller.abort();
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```tsx
|
|
60
|
-
* // Handle network errors
|
|
61
|
-
* try {
|
|
62
|
-
* const response = await safeFetch('/api/users');
|
|
63
|
-
* } catch (error) {
|
|
64
|
-
* if (isAbortError(error)) {
|
|
65
|
-
* // Request was cancelled
|
|
66
|
-
* return;
|
|
67
|
-
* }
|
|
68
|
-
* // Network error: "Network error: Please check your internet connection"
|
|
69
|
-
* console.error(error.message);
|
|
70
|
-
* }
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
export declare function safeFetch(url: string, options?: RequestInit): Promise<Response>;
|
|
74
|
-
/**
|
|
75
|
-
* Extract error message from a failed response.
|
|
76
|
-
* Parses JSON body and returns message/error field, or defaultMsg if not available.
|
|
77
|
-
*
|
|
78
|
-
* @param response - The Response object (typically from a failed request)
|
|
79
|
-
* @param defaultMsg - Default message if parsing fails or no message in body
|
|
80
|
-
* @returns Promise resolving to the error message string
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```tsx
|
|
84
|
-
* const response = await safeFetch('/api/users');
|
|
85
|
-
* if (!response.ok) {
|
|
86
|
-
* const msg = await getErrorMessage(response, 'Failed to fetch users');
|
|
87
|
-
* throw new Error(msg);
|
|
88
|
-
* }
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
export declare function getErrorMessage(response: Response, defaultMsg: string): Promise<string>;
|
|
92
|
-
/**
|
|
93
|
-
* Parse JSON response with error handling.
|
|
94
|
-
* Provides better error messages if response is not valid JSON.
|
|
95
|
-
*
|
|
96
|
-
* @param response - The Response object to parse
|
|
97
|
-
* @returns Promise resolving to parsed JSON data
|
|
98
|
-
* @throws {Error} If response body is empty or not valid JSON
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```tsx
|
|
102
|
-
* const response = await safeFetch('/api/users');
|
|
103
|
-
* const users = await parseJsonResponse<User[]>(response);
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
export declare function parseJsonResponse<T>(response: Response): Promise<T>;
|
|
107
|
-
/**
|
|
108
|
-
* Create a standardized API error from a response.
|
|
109
|
-
* Provides user-friendly error messages based on HTTP status codes.
|
|
110
|
-
*
|
|
111
|
-
* @param response - The Response object with error status
|
|
112
|
-
* @param defaultMessage - Default error message if status-specific message not available
|
|
113
|
-
* @returns Error instance with descriptive message
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```tsx
|
|
117
|
-
* const response = await safeFetch('/api/users');
|
|
118
|
-
* if (!response.ok) {
|
|
119
|
-
* throw createApiError(response, 'Failed to fetch users');
|
|
120
|
-
* // Error message: "Failed to fetch users (401: Unauthorized - Please check your session)"
|
|
121
|
-
* }
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
export declare function createApiError(response: Response, defaultMessage: string): Error;
|
|
125
|
-
/**
|
|
126
|
-
* Handle API response with consistent error handling.
|
|
127
|
-
* Checks response status, parses JSON, and provides standardized error messages.
|
|
128
|
-
* This is the recommended way to handle API responses in the SDK.
|
|
129
|
-
*
|
|
130
|
-
* @param response - The Response object to handle
|
|
131
|
-
* @param defaultErrorMessage - Default error message if response is not ok
|
|
132
|
-
* @returns Promise resolving to parsed JSON data
|
|
133
|
-
* @throws {Error} If response is not ok or JSON parsing fails
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* ```tsx
|
|
137
|
-
* const response = await safeFetch('/api/users');
|
|
138
|
-
* const users = await handleApiResponse<User[]>(response, 'Failed to fetch users');
|
|
139
|
-
* ```
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* ```tsx
|
|
143
|
-
* // With error handling
|
|
144
|
-
* try {
|
|
145
|
-
* const response = await safeFetch('/api/users');
|
|
146
|
-
* const users = await handleApiResponse<User[]>(response);
|
|
147
|
-
* } catch (error) {
|
|
148
|
-
* // Error message includes status code and descriptive text
|
|
149
|
-
* console.error(error.message);
|
|
150
|
-
* }
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
export declare function handleApiResponse<T>(response: Response, defaultErrorMessage?: string): Promise<T>;
|
|
154
|
-
/**
|
|
155
|
-
* Fetch with timeout support.
|
|
156
|
-
* Automatically cancels request if it takes longer than specified timeout.
|
|
157
|
-
*
|
|
158
|
-
* @param url - The URL to fetch
|
|
159
|
-
* @param options - Optional fetch options (RequestInit)
|
|
160
|
-
* @param timeout - Timeout in milliseconds (default: 10000ms / 10 seconds)
|
|
161
|
-
* @returns Promise resolving to Response object
|
|
162
|
-
* @throws {Error} If request times out: "Request timeout after {timeout}ms"
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* ```tsx
|
|
166
|
-
* // 5 second timeout
|
|
167
|
-
* const response = await fetchWithTimeout('/api/users', {}, 5000);
|
|
168
|
-
* ```
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* ```tsx
|
|
172
|
-
* // Handle timeout
|
|
173
|
-
* try {
|
|
174
|
-
* const response = await fetchWithTimeout('/api/users', {}, 5000);
|
|
175
|
-
* } catch (error) {
|
|
176
|
-
* if (error.message.includes('timeout')) {
|
|
177
|
-
* console.error('Request took too long');
|
|
178
|
-
* }
|
|
179
|
-
* }
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
export declare function fetchWithTimeout(url: string, options?: RequestInit, timeout?: number): Promise<Response>;
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Centralized Error Handler for SDK
|
|
3
|
-
* Provides consistent error handling, logging, and user-facing error management
|
|
4
|
-
*/
|
|
5
|
-
export interface SDKErrorContext {
|
|
6
|
-
component?: string;
|
|
7
|
-
action?: string;
|
|
8
|
-
metadata?: Record<string, unknown>;
|
|
9
|
-
}
|
|
10
|
-
export declare class SDKError extends Error {
|
|
11
|
-
readonly code?: string | undefined;
|
|
12
|
-
readonly context?: SDKErrorContext | undefined;
|
|
13
|
-
readonly originalError?: Error | undefined;
|
|
14
|
-
constructor(message: string, code?: string | undefined, context?: SDKErrorContext | undefined, originalError?: Error | undefined);
|
|
15
|
-
}
|
|
16
|
-
export interface ErrorHandlerConfig {
|
|
17
|
-
/**
|
|
18
|
-
* Custom error callback for handling errors
|
|
19
|
-
* @param error - The error that occurred
|
|
20
|
-
* @param context - Additional context about where the error occurred
|
|
21
|
-
*/
|
|
22
|
-
onError?: (error: Error, context: SDKErrorContext) => void;
|
|
23
|
-
/**
|
|
24
|
-
* Whether to log errors to console in development
|
|
25
|
-
* @default true
|
|
26
|
-
*/
|
|
27
|
-
enableConsoleLogging?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Whether to show user-facing error notifications
|
|
30
|
-
* @default false
|
|
31
|
-
*/
|
|
32
|
-
showUserNotifications?: boolean;
|
|
33
|
-
}
|
|
34
|
-
declare class ErrorHandler {
|
|
35
|
-
private config;
|
|
36
|
-
/**
|
|
37
|
-
* Configure the error handler
|
|
38
|
-
*/
|
|
39
|
-
configure(config: Partial<ErrorHandlerConfig>): void;
|
|
40
|
-
/**
|
|
41
|
-
* Handle an error with context
|
|
42
|
-
*/
|
|
43
|
-
handleError(error: Error | unknown, context?: SDKErrorContext): void;
|
|
44
|
-
/**
|
|
45
|
-
* Notify user of error (placeholder for notification system)
|
|
46
|
-
*/
|
|
47
|
-
private notifyUser;
|
|
48
|
-
/**
|
|
49
|
-
* Create a safe error handler wrapper for async functions
|
|
50
|
-
*/
|
|
51
|
-
wrapAsync<T extends (...args: any[]) => Promise<any>>(fn: T, context: SDKErrorContext): T;
|
|
52
|
-
/**
|
|
53
|
-
* Create a safe error handler wrapper for sync functions
|
|
54
|
-
*/
|
|
55
|
-
wrapSync<T extends (...args: any[]) => any>(fn: T, context: SDKErrorContext): T;
|
|
56
|
-
}
|
|
57
|
-
export declare const errorHandler: ErrorHandler;
|
|
58
|
-
/**
|
|
59
|
-
* Convenience function to handle an error with context.
|
|
60
|
-
* Uses the global error handler instance.
|
|
61
|
-
*
|
|
62
|
-
* @param error - The error to handle (Error instance, string, or unknown)
|
|
63
|
-
* @param context - Optional context about where the error occurred
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```tsx
|
|
67
|
-
* try {
|
|
68
|
-
* await someOperation();
|
|
69
|
-
* } catch (error) {
|
|
70
|
-
* handleError(error, {
|
|
71
|
-
* component: 'MyComponent',
|
|
72
|
-
* action: 'someOperation',
|
|
73
|
-
* metadata: { userId: '123' },
|
|
74
|
-
* });
|
|
75
|
-
* }
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
export declare function handleError(error: Error | unknown, context?: SDKErrorContext): void;
|
|
79
|
-
/**
|
|
80
|
-
* Handle an error only if it is not an AbortError.
|
|
81
|
-
* Convenience for async code that uses AbortSignal - call this in catch and abort errors are ignored.
|
|
82
|
-
*
|
|
83
|
-
* @param error - The error that occurred
|
|
84
|
-
* @param context - Optional context about where the error occurred
|
|
85
|
-
* @returns true if error was handled, false if it was an abort error (ignored)
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```tsx
|
|
89
|
-
* try {
|
|
90
|
-
* await safeFetch(url, { signal });
|
|
91
|
-
* } catch (error) {
|
|
92
|
-
* handleErrorUnlessAborted(error, { component: 'MyComponent', action: 'fetch' });
|
|
93
|
-
* }
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
export declare function handleErrorUnlessAborted(error: Error | unknown, context?: SDKErrorContext): boolean;
|
|
97
|
-
/**
|
|
98
|
-
* Creates a new SDKError instance with optional code and context.
|
|
99
|
-
* Useful for creating standardized errors throughout the SDK.
|
|
100
|
-
*
|
|
101
|
-
* @param message - Error message
|
|
102
|
-
* @param code - Optional error code (e.g., 'AUTH_FAILED', 'NETWORK_ERROR')
|
|
103
|
-
* @param context - Optional context about where the error occurred
|
|
104
|
-
* @param originalError - Optional original error that caused this error
|
|
105
|
-
* @returns A new SDKError instance
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* ```tsx
|
|
109
|
-
* throw createSDKError(
|
|
110
|
-
* 'Failed to authenticate user',
|
|
111
|
-
* 'AUTH_FAILED',
|
|
112
|
-
* { component: 'AuthProvider', action: 'signIn' },
|
|
113
|
-
* originalError
|
|
114
|
-
* );
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
export declare function createSDKError(message: string, code?: string, context?: SDKErrorContext, originalError?: Error): SDKError;
|
|
118
|
-
export {};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Centralized logger for SDK
|
|
3
|
-
* All console output should go through this for consistency and configurable behavior
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Configure the SDK logger
|
|
7
|
-
*/
|
|
8
|
-
export declare function configureLogger(config: {
|
|
9
|
-
enableLogging?: boolean;
|
|
10
|
-
}): void;
|
|
11
|
-
/**
|
|
12
|
-
* Log info (dev only, respects enableLogging)
|
|
13
|
-
*/
|
|
14
|
-
export declare function sdkLog(message: string, ...args: unknown[]): void;
|
|
15
|
-
/**
|
|
16
|
-
* Log warning (dev only, respects enableLogging)
|
|
17
|
-
*/
|
|
18
|
-
export declare function sdkWarn(message: string, ...args: unknown[]): void;
|
|
19
|
-
/**
|
|
20
|
-
* Log error (dev only, respects enableLogging)
|
|
21
|
-
*/
|
|
22
|
-
export declare function sdkLogError(message: string, ...args: unknown[]): void;
|
|
23
|
-
/**
|
|
24
|
-
* Log internal/critical error - always logs.
|
|
25
|
-
* Use when the error handling system itself fails (e.g. user's onError callback throws).
|
|
26
|
-
*/
|
|
27
|
-
export declare function sdkError(message: string, ...args: unknown[]): void;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { DependencyList } from 'react';
|
|
2
|
-
export interface UseAsyncEffectOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Called when the effect promise rejects (except for AbortError which is ignored).
|
|
5
|
-
*/
|
|
6
|
-
onError?: (err: unknown) => void;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Encapsulates the AbortController + async effect pattern.
|
|
10
|
-
* Provides cancellation on cleanup and optional error handling.
|
|
11
|
-
*
|
|
12
|
-
* @param effect - Async function that receives AbortSignal for cancellation
|
|
13
|
-
* @param deps - Dependency array (same as useEffect)
|
|
14
|
-
* @param options - Optional onError callback for unhandled rejections
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* useAsyncEffect(
|
|
19
|
-
* async (signal) => {
|
|
20
|
-
* const response = await safeFetch(url, { signal });
|
|
21
|
-
* const data = await response.json();
|
|
22
|
-
* setData(data);
|
|
23
|
-
* },
|
|
24
|
-
* [url],
|
|
25
|
-
* { onError: (err) => handleError(err, { component: 'MyComponent', action: 'fetch' }) }
|
|
26
|
-
* );
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export declare function useAsyncEffect(effect: (signal: AbortSignal) => Promise<void>, deps: DependencyList, options?: UseAsyncEffectOptions): void;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type ClassValue } from 'clsx';
|
|
2
|
-
/**
|
|
3
|
-
* Check if running in development mode.
|
|
4
|
-
* Safe for browser bundles where process may be undefined.
|
|
5
|
-
*/
|
|
6
|
-
export declare function isDevelopment(): boolean;
|
|
7
|
-
export declare function cn(...inputs: ClassValue[]): string;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { IAuthConfig } from './auth/types';
|
|
3
|
-
import { type IOsState } from './os/types';
|
|
4
|
-
interface ContextConfigProviderProps {
|
|
5
|
-
config: IOsState;
|
|
6
|
-
auth?: IAuthConfig;
|
|
7
|
-
children: React.ReactNode;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Context Config Provider
|
|
11
|
-
* Initializes OS configuration in Context API mode
|
|
12
|
-
* Similar to SaaSConfigProvider but for Context API
|
|
13
|
-
*/
|
|
14
|
-
export declare const ContextConfigProvider: React.FC<ContextConfigProviderProps>;
|
|
15
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export declare const PortalContext: React.Context<{
|
|
3
|
-
container: HTMLDivElement | null;
|
|
4
|
-
setContainer: (container: HTMLDivElement | null) => void;
|
|
5
|
-
}>;
|
|
6
|
-
declare const PortalProvider: React.MemoExoticComponent<({ children }: {
|
|
7
|
-
children: React.ReactNode;
|
|
8
|
-
}) => import("react/jsx-runtime").JSX.Element>;
|
|
9
|
-
export default PortalProvider;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Centralized API client for auth (profile).
|
|
3
|
-
* Extends BaseApi; uses explicit sessionId for profile (e.g. after redirect or hydration).
|
|
4
|
-
*/
|
|
5
|
-
import { IUser } from '../../api/types';
|
|
6
|
-
import { BaseApi } from '../../lib/api-base';
|
|
7
|
-
import type { IOsConfig } from '../os/types';
|
|
8
|
-
export declare class AuthApi extends BaseApi {
|
|
9
|
-
constructor(config: Pick<IOsConfig, 'serverUrl' | 'version'>);
|
|
10
|
-
/** Fetch user profile with the given session ID (used after OAuth redirect or from storage). */
|
|
11
|
-
getProfile(sessionId: string, signal?: AbortSignal): Promise<IUser>;
|
|
12
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { WorkspaceSettingsSection } from '../workspace/ui/SettingsDialog';
|
|
2
|
-
/**
|
|
3
|
-
* Main authentication hook for the SDK.
|
|
4
|
-
* Provides authentication state, user session, and auth actions.
|
|
5
|
-
*
|
|
6
|
-
* @returns An object containing:
|
|
7
|
-
* - `user`: Current authenticated user object (null if not authenticated)
|
|
8
|
-
* - `session`: Full session object with user and token (null if not authenticated)
|
|
9
|
-
* - `status`: Current authentication status (loading, redirecting, authenticating, authenticated, unauthenticated)
|
|
10
|
-
* - `isLoading`: Boolean indicating if auth state is being determined
|
|
11
|
-
* - `isAuthenticated`: Boolean indicating if user is authenticated
|
|
12
|
-
* - `isRedirecting`: Boolean indicating if redirecting to OAuth provider
|
|
13
|
-
* - `signIn()`: Function to initiate OAuth sign-in flow
|
|
14
|
-
* - `signOut()`: Function to sign out the current user
|
|
15
|
-
* - `openWorkspaceSettings(section?)`: Function to open workspace settings dialog
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* function MyComponent() {
|
|
20
|
-
* const { user, isAuthenticated, signIn, signOut } = useSaaSAuth();
|
|
21
|
-
*
|
|
22
|
-
* if (!isAuthenticated) {
|
|
23
|
-
* return <button onClick={signIn}>Sign In</button>;
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
* return (
|
|
27
|
-
* <div>
|
|
28
|
-
* <p>Welcome, {user?.name}</p>
|
|
29
|
-
* <button onClick={signOut}>Sign Out</button>
|
|
30
|
-
* </div>
|
|
31
|
-
* );
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```tsx
|
|
37
|
-
* // Handle loading state
|
|
38
|
-
* function App() {
|
|
39
|
-
* const { status, isLoading } = useSaaSAuth();
|
|
40
|
-
*
|
|
41
|
-
* if (isLoading) {
|
|
42
|
-
* return <LoadingSpinner />;
|
|
43
|
-
* }
|
|
44
|
-
*
|
|
45
|
-
* return <MainContent />;
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```tsx
|
|
51
|
-
* // Open workspace settings
|
|
52
|
-
* function SettingsButton() {
|
|
53
|
-
* const { openWorkspaceSettings } = useSaaSAuth();
|
|
54
|
-
*
|
|
55
|
-
* return (
|
|
56
|
-
* <button onClick={() => openWorkspaceSettings('general')}>
|
|
57
|
-
* Open Settings
|
|
58
|
-
* </button>
|
|
59
|
-
* );
|
|
60
|
-
* }
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
/** Internal: select auth slice. Used by AuthProviderWrapper and useSaaSAuth. */
|
|
64
|
-
export declare function useAuthState(): import("./types").IAuthState;
|
|
65
|
-
export declare function useSaaSAuth(): {
|
|
66
|
-
signIn: () => Promise<void>;
|
|
67
|
-
signOut: () => Promise<void>;
|
|
68
|
-
openWorkspaceSettings: (section?: WorkspaceSettingsSection) => void;
|
|
69
|
-
isAuthenticated: boolean;
|
|
70
|
-
isLoading: boolean;
|
|
71
|
-
isRedirecting: boolean;
|
|
72
|
-
user: import("./types").AuthUser | undefined;
|
|
73
|
-
session: import("./types").AuthSession | null;
|
|
74
|
-
status: import("./types").AuthStatus;
|
|
75
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react';
|
|
2
|
-
import { IAuthCallbacks } from './types';
|
|
3
|
-
interface IProps {
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
callbacks?: IAuthCallbacks;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* AuthProvider wrapper that adds authentication logic
|
|
9
|
-
* This wraps the AuthContextProvider and adds token handling, callbacks, etc.
|
|
10
|
-
*/
|
|
11
|
-
export declare const AuthProviderWrapper: React.MemoExoticComponent<({ children, callbacks }: IProps) => import("react/jsx-runtime").JSX.Element>;
|
|
12
|
-
export declare const AuthProvider: React.MemoExoticComponent<({ children, callbacks }: IProps) => import("react/jsx-runtime").JSX.Element>;
|
|
13
|
-
export {};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { EventData, EventType } from '../events/types';
|
|
2
|
-
import type { IWorkspace } from '../workspace/types';
|
|
3
|
-
export declare enum AuthStatus {
|
|
4
|
-
loading = "loading",
|
|
5
|
-
redirecting = "redirecting",
|
|
6
|
-
authenticated = "authenticated",
|
|
7
|
-
unauthenticated = "unauthenticated",
|
|
8
|
-
authenticating = "authenticating"
|
|
9
|
-
}
|
|
10
|
-
/** Derive booleans from status (single source of truth) */
|
|
11
|
-
export declare function getAuthFlags(status: AuthStatus): {
|
|
12
|
-
isAuthenticated: boolean;
|
|
13
|
-
isLoading: boolean;
|
|
14
|
-
isRedirecting: boolean;
|
|
15
|
-
};
|
|
16
|
-
export interface AuthUser {
|
|
17
|
-
id: string;
|
|
18
|
-
name: string;
|
|
19
|
-
org: string;
|
|
20
|
-
email: string;
|
|
21
|
-
emailVerified: boolean;
|
|
22
|
-
clientId: string;
|
|
23
|
-
role: string;
|
|
24
|
-
image?: string;
|
|
25
|
-
}
|
|
26
|
-
export interface AuthSession {
|
|
27
|
-
user: AuthUser;
|
|
28
|
-
sessionId: string;
|
|
29
|
-
expires: string;
|
|
30
|
-
}
|
|
31
|
-
export interface IAuthState {
|
|
32
|
-
session: AuthSession | null;
|
|
33
|
-
status: AuthStatus;
|
|
34
|
-
}
|
|
35
|
-
export interface IAuthConfig {
|
|
36
|
-
clientId: string;
|
|
37
|
-
redirectUrl: string;
|
|
38
|
-
callbacks?: IAuthCallbacks;
|
|
39
|
-
}
|
|
40
|
-
export interface IAuthCallbacks {
|
|
41
|
-
handleAuthentication: (code: string) => Promise<{
|
|
42
|
-
sessionId: string;
|
|
43
|
-
}>;
|
|
44
|
-
onSignOut: () => Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Event handler for User and Workspace events
|
|
47
|
-
* @param eventType - The type of event that occurred
|
|
48
|
-
* @param data - The event data (type varies based on eventType)
|
|
49
|
-
*/
|
|
50
|
-
handleEvent?: (eventType: EventType, data: EventData) => void | Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Called before switching workspace (e.g. generate token, save state).
|
|
53
|
-
* Used when user clicks "Switch to" and when restoring from storage on page refresh.
|
|
54
|
-
* Switch proceeds only when this resolves; reject to abort.
|
|
55
|
-
*/
|
|
56
|
-
onWorkspaceChange?: (params: OnWorkspaceChangeParams) => Promise<void>;
|
|
57
|
-
}
|
|
58
|
-
export interface OnWorkspaceChangeParams {
|
|
59
|
-
workspace: IWorkspace;
|
|
60
|
-
user: AuthUser | null;
|
|
61
|
-
role: string | null;
|
|
62
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { IUser } from '../../api/types';
|
|
2
|
-
import type { AuthSession, AuthUser } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Map IUser from API to AuthUser for session
|
|
5
|
-
* @throws Error if user data is missing required ID or email fields
|
|
6
|
-
*/
|
|
7
|
-
export declare function mapIUserToAuthUser(userData: IUser, orgId: string, clientId: string): AuthUser;
|
|
8
|
-
/**
|
|
9
|
-
* Centralized Session Management
|
|
10
|
-
* Only stores sessionId in localStorage - user data is kept in context only
|
|
11
|
-
* This ensures we always fetch fresh user data on page refresh
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Save sessionId to localStorage
|
|
15
|
-
* Note: Only sessionId is stored, user data is kept in context state only
|
|
16
|
-
* @param sessionId - The sessionId string to save
|
|
17
|
-
*/
|
|
18
|
-
export declare function setSessionId(sessionId: string): void;
|
|
19
|
-
/**
|
|
20
|
-
* Remove sessionId from localStorage
|
|
21
|
-
*/
|
|
22
|
-
export declare function removeSession(): void;
|
|
23
|
-
/**
|
|
24
|
-
* Get sessionId from localStorage
|
|
25
|
-
* @returns The sessionId string or null if not found
|
|
26
|
-
*/
|
|
27
|
-
export declare function getSessionId(): string | null;
|
|
28
|
-
/**
|
|
29
|
-
* Get sessionId (alias for getSessionId for backward compatibility)
|
|
30
|
-
* @returns The sessionId string or null if not found
|
|
31
|
-
*/
|
|
32
|
-
export declare function getAccessToken(): string | null;
|
|
33
|
-
/**
|
|
34
|
-
* Get authentication headers with x-session-id
|
|
35
|
-
* Centralized function for all API requests
|
|
36
|
-
*/
|
|
37
|
-
export declare function getAuthHeaders(): Record<string, string>;
|
|
38
|
-
export declare function getTokenFromUrl(): string | null;
|
|
39
|
-
export declare function removeTokenFromUrl(): void;
|
|
40
|
-
export declare function createSession(user: AuthUser, sessionId: string): AuthSession;
|