@baasix/sdk 0.1.1 → 0.1.2

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 CHANGED
@@ -1081,6 +1081,44 @@ try {
1081
1081
 
1082
1082
  ## TypeScript Support
1083
1083
 
1084
+ ### Shared Types from @baasix/types
1085
+
1086
+ The SDK uses shared types from `@baasix/types`. Import common types directly:
1087
+
1088
+ ```typescript
1089
+ import type {
1090
+ // Auth types
1091
+ User,
1092
+ Role,
1093
+ Permission,
1094
+ AuthMode,
1095
+
1096
+ // Query types
1097
+ Filter,
1098
+ FilterOperator,
1099
+ Sort,
1100
+ QueryParams,
1101
+ PaginationMetadata,
1102
+
1103
+ // Response types
1104
+ PaginatedResponse,
1105
+
1106
+ // File types
1107
+ FileMetadata,
1108
+ UploadOptions,
1109
+
1110
+ // Schema types
1111
+ SchemaDefinition,
1112
+ FieldDefinition,
1113
+
1114
+ // Spatial types
1115
+ GeoJSONPoint,
1116
+ GeoJSONGeometry,
1117
+ } from '@baasix/types';
1118
+ ```
1119
+
1120
+ ### Using Generics
1121
+
1084
1122
  Use generics for type-safe operations:
1085
1123
 
1086
1124
  ```typescript
@@ -0,0 +1,95 @@
1
+ import { S as StorageAdapter } from './types-BdjsGANq.cjs';
2
+ import { AuthMode, AuthTokens } from '@baasix/types';
3
+
4
+ interface RequestOptions extends RequestInit {
5
+ params?: Record<string, unknown>;
6
+ timeout?: number;
7
+ skipAuth?: boolean;
8
+ rawResponse?: boolean;
9
+ }
10
+ interface HttpClientConfig {
11
+ baseUrl: string;
12
+ authMode: AuthMode;
13
+ storage: StorageAdapter;
14
+ timeout: number;
15
+ autoRefresh: boolean;
16
+ credentials: RequestCredentials;
17
+ headers: Record<string, string>;
18
+ token?: string;
19
+ tenantId?: string;
20
+ onAuthError?: () => void;
21
+ onTokenRefresh?: (tokens: AuthTokens) => void;
22
+ }
23
+ /**
24
+ * Core HTTP client for making API requests.
25
+ * Handles authentication, token refresh, and error handling.
26
+ */
27
+ declare class HttpClient {
28
+ private config;
29
+ private refreshPromise;
30
+ constructor(config: HttpClientConfig);
31
+ /**
32
+ * Update client configuration
33
+ */
34
+ updateConfig(config: Partial<HttpClientConfig>): void;
35
+ /**
36
+ * Get the current base URL
37
+ */
38
+ getBaseUrl(): string;
39
+ /**
40
+ * Build the full URL with query parameters
41
+ */
42
+ private buildUrl;
43
+ /**
44
+ * Get the current access token
45
+ */
46
+ private getAccessToken;
47
+ /**
48
+ * Check if token is expired or about to expire (within 60 seconds)
49
+ */
50
+ private isTokenExpired;
51
+ /**
52
+ * Refresh the access token
53
+ */
54
+ private refreshToken;
55
+ /**
56
+ * Build request headers
57
+ */
58
+ private buildHeaders;
59
+ /**
60
+ * Parse error response
61
+ */
62
+ private parseError;
63
+ /**
64
+ * Make an HTTP request
65
+ */
66
+ request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
67
+ /**
68
+ * GET request
69
+ */
70
+ get<T>(path: string, options?: RequestOptions): Promise<T>;
71
+ /**
72
+ * POST request
73
+ */
74
+ post<T>(path: string, data?: unknown, options?: RequestOptions): Promise<T>;
75
+ /**
76
+ * PATCH request
77
+ */
78
+ patch<T>(path: string, data?: unknown, options?: RequestOptions): Promise<T>;
79
+ /**
80
+ * PUT request
81
+ */
82
+ put<T>(path: string, data?: unknown, options?: RequestOptions): Promise<T>;
83
+ /**
84
+ * DELETE request
85
+ */
86
+ delete<T>(path: string, options?: RequestOptions): Promise<T>;
87
+ /**
88
+ * Upload file with multipart/form-data
89
+ */
90
+ upload<T>(path: string, formData: FormData, options?: Omit<RequestOptions, "body"> & {
91
+ onProgress?: (progress: number) => void;
92
+ }): Promise<T>;
93
+ }
94
+
95
+ export { HttpClient as H, type RequestOptions as R, type HttpClientConfig as a };
@@ -0,0 +1,95 @@
1
+ import { S as StorageAdapter } from './types-BdjsGANq.js';
2
+ import { AuthMode, AuthTokens } from '@baasix/types';
3
+
4
+ interface RequestOptions extends RequestInit {
5
+ params?: Record<string, unknown>;
6
+ timeout?: number;
7
+ skipAuth?: boolean;
8
+ rawResponse?: boolean;
9
+ }
10
+ interface HttpClientConfig {
11
+ baseUrl: string;
12
+ authMode: AuthMode;
13
+ storage: StorageAdapter;
14
+ timeout: number;
15
+ autoRefresh: boolean;
16
+ credentials: RequestCredentials;
17
+ headers: Record<string, string>;
18
+ token?: string;
19
+ tenantId?: string;
20
+ onAuthError?: () => void;
21
+ onTokenRefresh?: (tokens: AuthTokens) => void;
22
+ }
23
+ /**
24
+ * Core HTTP client for making API requests.
25
+ * Handles authentication, token refresh, and error handling.
26
+ */
27
+ declare class HttpClient {
28
+ private config;
29
+ private refreshPromise;
30
+ constructor(config: HttpClientConfig);
31
+ /**
32
+ * Update client configuration
33
+ */
34
+ updateConfig(config: Partial<HttpClientConfig>): void;
35
+ /**
36
+ * Get the current base URL
37
+ */
38
+ getBaseUrl(): string;
39
+ /**
40
+ * Build the full URL with query parameters
41
+ */
42
+ private buildUrl;
43
+ /**
44
+ * Get the current access token
45
+ */
46
+ private getAccessToken;
47
+ /**
48
+ * Check if token is expired or about to expire (within 60 seconds)
49
+ */
50
+ private isTokenExpired;
51
+ /**
52
+ * Refresh the access token
53
+ */
54
+ private refreshToken;
55
+ /**
56
+ * Build request headers
57
+ */
58
+ private buildHeaders;
59
+ /**
60
+ * Parse error response
61
+ */
62
+ private parseError;
63
+ /**
64
+ * Make an HTTP request
65
+ */
66
+ request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
67
+ /**
68
+ * GET request
69
+ */
70
+ get<T>(path: string, options?: RequestOptions): Promise<T>;
71
+ /**
72
+ * POST request
73
+ */
74
+ post<T>(path: string, data?: unknown, options?: RequestOptions): Promise<T>;
75
+ /**
76
+ * PATCH request
77
+ */
78
+ patch<T>(path: string, data?: unknown, options?: RequestOptions): Promise<T>;
79
+ /**
80
+ * PUT request
81
+ */
82
+ put<T>(path: string, data?: unknown, options?: RequestOptions): Promise<T>;
83
+ /**
84
+ * DELETE request
85
+ */
86
+ delete<T>(path: string, options?: RequestOptions): Promise<T>;
87
+ /**
88
+ * Upload file with multipart/form-data
89
+ */
90
+ upload<T>(path: string, formData: FormData, options?: Omit<RequestOptions, "body"> & {
91
+ onProgress?: (progress: number) => void;
92
+ }): Promise<T>;
93
+ }
94
+
95
+ export { HttpClient as H, type RequestOptions as R, type HttpClientConfig as a };