@snackbase/sdk 0.1.0 → 0.2.0
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.cjs +2635 -0
- package/dist/{index-Dr6K4PMl.d.mts → index.d.cts} +199 -28
- package/dist/index.d.mts +2289 -2
- package/dist/index.mjs +135 -21
- package/package.json +30 -38
- package/CHANGELOG.md +0 -61
- package/README.md +0 -287
- package/dist/react/index.d.mts +0 -63
- package/dist/react/index.mjs +0 -271
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2289 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/types/config.d.ts
|
|
2
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
3
|
+
type StorageBackend = 'localStorage' | 'sessionStorage' | 'memory' | 'asyncStorage';
|
|
4
|
+
interface SnackBaseConfig {
|
|
5
|
+
/**
|
|
6
|
+
* API base URL (required)
|
|
7
|
+
*/
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
/**
|
|
10
|
+
* Request timeout in milliseconds (default: 30000)
|
|
11
|
+
*/
|
|
12
|
+
timeout?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Optional API key for service authentication
|
|
15
|
+
*/
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Enable automatic token refresh (default: true)
|
|
19
|
+
*/
|
|
20
|
+
enableAutoRefresh?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Refresh tokens N seconds before expiry (default: 300)
|
|
23
|
+
*/
|
|
24
|
+
refreshBeforeExpiry?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Maximum retry attempts for failed requests (default: 3)
|
|
27
|
+
*/
|
|
28
|
+
maxRetries?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Delay between retries in milliseconds (default: 1000)
|
|
31
|
+
*/
|
|
32
|
+
retryDelay?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Token storage backend.
|
|
35
|
+
* 'localStorage' or 'sessionStorage' for web,
|
|
36
|
+
* 'asyncStorage' for React Native.
|
|
37
|
+
* Default: auto-detect based on platform.
|
|
38
|
+
*/
|
|
39
|
+
storageBackend?: StorageBackend;
|
|
40
|
+
/**
|
|
41
|
+
* Enable request/response logging (default: false in production)
|
|
42
|
+
*/
|
|
43
|
+
enableLogging?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Logging level (default: 'error')
|
|
46
|
+
*/
|
|
47
|
+
logLevel?: LogLevel;
|
|
48
|
+
/**
|
|
49
|
+
* Callback for 401 authentication errors
|
|
50
|
+
*/
|
|
51
|
+
onAuthError?: (error: any) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Callback for network failures
|
|
54
|
+
*/
|
|
55
|
+
onNetworkError?: (error: any) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Callback for 429 rate limit errors
|
|
58
|
+
*/
|
|
59
|
+
onRateLimitError?: (error: any) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Default account slug/ID for single-tenant mode (optional)
|
|
62
|
+
*/
|
|
63
|
+
defaultAccount?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Maximum reconnection attempts for real-time (default: 10)
|
|
66
|
+
*/
|
|
67
|
+
maxRealTimeRetries?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Initial delay for real-time reconnection in milliseconds (default: 1000)
|
|
70
|
+
*/
|
|
71
|
+
realTimeReconnectionDelay?: number;
|
|
72
|
+
}
|
|
73
|
+
declare const DEFAULT_CONFIG: Partial<SnackBaseConfig>;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/core/logger.d.ts
|
|
76
|
+
declare enum LogLevel$1 {
|
|
77
|
+
NONE = 0,
|
|
78
|
+
ERROR = 1,
|
|
79
|
+
WARN = 2,
|
|
80
|
+
INFO = 3,
|
|
81
|
+
DEBUG = 4
|
|
82
|
+
}
|
|
83
|
+
interface LogEntry {
|
|
84
|
+
timestamp: string;
|
|
85
|
+
level: LogLevel$1;
|
|
86
|
+
message: string;
|
|
87
|
+
data?: any;
|
|
88
|
+
}
|
|
89
|
+
declare class Logger {
|
|
90
|
+
private level;
|
|
91
|
+
private handlers;
|
|
92
|
+
private logs;
|
|
93
|
+
private maxLogs;
|
|
94
|
+
constructor(level?: LogLevel$1);
|
|
95
|
+
setLevel(level: LogLevel$1): void;
|
|
96
|
+
getLogs(): LogEntry[];
|
|
97
|
+
clearLogs(): void;
|
|
98
|
+
private log;
|
|
99
|
+
error(message: string, data?: any): void;
|
|
100
|
+
warn(message: string, data?: any): void;
|
|
101
|
+
info(message: string, data?: any): void;
|
|
102
|
+
debug(message: string, data?: any): void;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/core/http-client.d.ts
|
|
106
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
107
|
+
interface HttpRequest {
|
|
108
|
+
url: string;
|
|
109
|
+
method: HttpMethod;
|
|
110
|
+
headers: Record<string, string>;
|
|
111
|
+
body?: any;
|
|
112
|
+
params?: Record<string, string | number | boolean | undefined>;
|
|
113
|
+
timeout?: number;
|
|
114
|
+
signal?: AbortSignal;
|
|
115
|
+
}
|
|
116
|
+
interface HttpResponse<T = any> {
|
|
117
|
+
data: T;
|
|
118
|
+
status: number;
|
|
119
|
+
headers: Headers;
|
|
120
|
+
request: HttpRequest;
|
|
121
|
+
}
|
|
122
|
+
type RequestInterceptor = (request: HttpRequest) => HttpRequest | Promise<HttpRequest>;
|
|
123
|
+
type ResponseInterceptor = (response: HttpResponse) => HttpResponse | Promise<HttpResponse>;
|
|
124
|
+
type ErrorInterceptor = (error: any) => any | Promise<any>;
|
|
125
|
+
interface HttpClientConfig {
|
|
126
|
+
baseUrl: string;
|
|
127
|
+
timeout?: number;
|
|
128
|
+
maxRetries?: number;
|
|
129
|
+
retryDelay?: number;
|
|
130
|
+
logger?: Logger;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Robust HTTP client wrapping the fetch API.
|
|
134
|
+
*/
|
|
135
|
+
declare class HttpClient {
|
|
136
|
+
private config;
|
|
137
|
+
private requestInterceptors;
|
|
138
|
+
private responseInterceptors;
|
|
139
|
+
private errorInterceptors;
|
|
140
|
+
constructor(config: HttpClientConfig);
|
|
141
|
+
addRequestInterceptor(interceptor: RequestInterceptor): void;
|
|
142
|
+
addResponseInterceptor(interceptor: ResponseInterceptor): void;
|
|
143
|
+
addErrorInterceptor(interceptor: ErrorInterceptor): void;
|
|
144
|
+
request<T = any>(req: Partial<HttpRequest>): Promise<HttpResponse<T>>;
|
|
145
|
+
get<T = any>(url: string, config?: Partial<HttpRequest>): Promise<HttpResponse<T>>;
|
|
146
|
+
post<T = any>(url: string, body?: any, config?: Partial<HttpRequest>): Promise<HttpResponse<T>>;
|
|
147
|
+
put<T = any>(url: string, body?: any, config?: Partial<HttpRequest>): Promise<HttpResponse<T>>;
|
|
148
|
+
patch<T = any>(url: string, body?: any, config?: Partial<HttpRequest>): Promise<HttpResponse<T>>;
|
|
149
|
+
delete<T = any>(url: string, config?: Partial<HttpRequest>): Promise<HttpResponse<T>>;
|
|
150
|
+
private resolveUrl;
|
|
151
|
+
private shouldRetry;
|
|
152
|
+
private calculateRetryDelay;
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/types/account.d.ts
|
|
156
|
+
interface Account {
|
|
157
|
+
id: string;
|
|
158
|
+
slug: string;
|
|
159
|
+
name: string;
|
|
160
|
+
created_at: string;
|
|
161
|
+
}
|
|
162
|
+
interface AccountCreate {
|
|
163
|
+
name: string;
|
|
164
|
+
slug?: string;
|
|
165
|
+
}
|
|
166
|
+
interface AccountUpdate {
|
|
167
|
+
name: string;
|
|
168
|
+
}
|
|
169
|
+
interface AccountListParams {
|
|
170
|
+
page?: number;
|
|
171
|
+
page_size?: number;
|
|
172
|
+
search?: string;
|
|
173
|
+
is_active?: boolean;
|
|
174
|
+
sort_by?: string;
|
|
175
|
+
sort_order?: 'asc' | 'desc';
|
|
176
|
+
[key: string]: string | number | boolean | undefined;
|
|
177
|
+
}
|
|
178
|
+
interface AccountListResponse {
|
|
179
|
+
items: Account[];
|
|
180
|
+
total: number;
|
|
181
|
+
}
|
|
182
|
+
interface AccountUserListParams {
|
|
183
|
+
page?: number;
|
|
184
|
+
page_size?: number;
|
|
185
|
+
[key: string]: string | number | boolean | undefined;
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/types/user.d.ts
|
|
189
|
+
interface User {
|
|
190
|
+
id: string;
|
|
191
|
+
email: string;
|
|
192
|
+
role: string;
|
|
193
|
+
groups: string[];
|
|
194
|
+
is_active: boolean;
|
|
195
|
+
created_at: string;
|
|
196
|
+
last_login: string | null;
|
|
197
|
+
}
|
|
198
|
+
interface UserCreate {
|
|
199
|
+
email: string;
|
|
200
|
+
password?: string;
|
|
201
|
+
account_id: string;
|
|
202
|
+
role?: string;
|
|
203
|
+
}
|
|
204
|
+
interface UserUpdate {
|
|
205
|
+
email?: string;
|
|
206
|
+
role?: string;
|
|
207
|
+
is_active?: boolean;
|
|
208
|
+
}
|
|
209
|
+
interface UserListParams {
|
|
210
|
+
page?: number;
|
|
211
|
+
page_size?: number;
|
|
212
|
+
account_id?: string;
|
|
213
|
+
role_id?: string;
|
|
214
|
+
is_active?: boolean;
|
|
215
|
+
search?: string;
|
|
216
|
+
sort_by?: string;
|
|
217
|
+
sort_order?: 'asc' | 'desc';
|
|
218
|
+
[key: string]: string | number | boolean | undefined;
|
|
219
|
+
}
|
|
220
|
+
interface UserListResponse {
|
|
221
|
+
items: User[];
|
|
222
|
+
total: number;
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/types/auth.d.ts
|
|
226
|
+
interface AuthState {
|
|
227
|
+
user: User | null;
|
|
228
|
+
account: Account | null;
|
|
229
|
+
token: string | null;
|
|
230
|
+
refreshToken: string | null;
|
|
231
|
+
isAuthenticated: boolean;
|
|
232
|
+
expiresAt: string | null;
|
|
233
|
+
}
|
|
234
|
+
type AuthEvent = 'auth:login' | 'auth:logout' | 'auth:refresh' | 'auth:error';
|
|
235
|
+
interface AuthEvents {
|
|
236
|
+
'auth:login': (state: AuthState) => void;
|
|
237
|
+
'auth:logout': () => void;
|
|
238
|
+
'auth:refresh': (state: AuthState) => void;
|
|
239
|
+
'auth:error': (error: Error) => void;
|
|
240
|
+
}
|
|
241
|
+
interface LoginCredentials {
|
|
242
|
+
account?: string;
|
|
243
|
+
email: string;
|
|
244
|
+
password: string;
|
|
245
|
+
}
|
|
246
|
+
interface RegisterData {
|
|
247
|
+
email: string;
|
|
248
|
+
password: string;
|
|
249
|
+
account_name?: string;
|
|
250
|
+
account_slug?: string;
|
|
251
|
+
}
|
|
252
|
+
interface AuthResponse {
|
|
253
|
+
user?: User;
|
|
254
|
+
account?: Account;
|
|
255
|
+
token?: string;
|
|
256
|
+
refresh_token?: string;
|
|
257
|
+
refreshToken?: string;
|
|
258
|
+
expires_in?: number;
|
|
259
|
+
expiresAt?: string;
|
|
260
|
+
user_id?: string;
|
|
261
|
+
account_id?: string;
|
|
262
|
+
email?: string;
|
|
263
|
+
role?: string;
|
|
264
|
+
}
|
|
265
|
+
interface PasswordResetRequest {
|
|
266
|
+
account?: string;
|
|
267
|
+
email: string;
|
|
268
|
+
}
|
|
269
|
+
interface PasswordResetConfirm {
|
|
270
|
+
token: string;
|
|
271
|
+
newPassword: string;
|
|
272
|
+
}
|
|
273
|
+
type OAuthProvider = 'google' | 'github' | 'microsoft' | 'apple';
|
|
274
|
+
interface OAuthUrlResponse {
|
|
275
|
+
url: string;
|
|
276
|
+
state: string;
|
|
277
|
+
}
|
|
278
|
+
interface OAuthCallbackParams {
|
|
279
|
+
provider: OAuthProvider;
|
|
280
|
+
code: string;
|
|
281
|
+
redirectUri: string;
|
|
282
|
+
state: string;
|
|
283
|
+
}
|
|
284
|
+
interface OAuthResponse extends AuthResponse {
|
|
285
|
+
isNewUser: boolean;
|
|
286
|
+
isNewAccount: boolean;
|
|
287
|
+
}
|
|
288
|
+
type SAMLProvider = 'okta' | 'azure_ad' | 'generic_saml';
|
|
289
|
+
interface SAMLUrlResponse {
|
|
290
|
+
url: string;
|
|
291
|
+
}
|
|
292
|
+
interface SAMLCallbackParams {
|
|
293
|
+
SAMLResponse: string;
|
|
294
|
+
relayState?: string;
|
|
295
|
+
}
|
|
296
|
+
interface SAMLResponse extends AuthResponse {
|
|
297
|
+
isNewUser: boolean;
|
|
298
|
+
isNewAccount: boolean;
|
|
299
|
+
}
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/core/storage.d.ts
|
|
302
|
+
interface AuthStorage {
|
|
303
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
304
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
305
|
+
removeItem(key: string): void | Promise<void>;
|
|
306
|
+
}
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region src/core/auth.d.ts
|
|
309
|
+
interface AuthManagerOptions {
|
|
310
|
+
storage: AuthStorage;
|
|
311
|
+
storageKey?: string;
|
|
312
|
+
}
|
|
313
|
+
declare class AuthManager {
|
|
314
|
+
private state;
|
|
315
|
+
private storage;
|
|
316
|
+
private storageKey;
|
|
317
|
+
private events;
|
|
318
|
+
constructor(options: AuthManagerOptions);
|
|
319
|
+
initialize(): Promise<void>;
|
|
320
|
+
getState(): AuthState;
|
|
321
|
+
get user(): User | null;
|
|
322
|
+
get account(): Account | null;
|
|
323
|
+
get token(): string | null;
|
|
324
|
+
get refreshToken(): string | null;
|
|
325
|
+
get isAuthenticated(): boolean;
|
|
326
|
+
setState(newState: Partial<AuthState>): Promise<void>;
|
|
327
|
+
clear(): Promise<void>;
|
|
328
|
+
on<K extends keyof AuthEvents>(event: K, listener: AuthEvents[K]): () => void;
|
|
329
|
+
private hydrate;
|
|
330
|
+
private persist;
|
|
331
|
+
private validateSession;
|
|
332
|
+
}
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/core/auth-service.d.ts
|
|
335
|
+
/**
|
|
336
|
+
* Service for handling authentication operations.
|
|
337
|
+
*/
|
|
338
|
+
declare class AuthService {
|
|
339
|
+
private http;
|
|
340
|
+
private auth;
|
|
341
|
+
private apiKey?;
|
|
342
|
+
private defaultAccount?;
|
|
343
|
+
private oauthStates;
|
|
344
|
+
private readonly STATE_EXPIRY_MS;
|
|
345
|
+
constructor(http: HttpClient, auth: AuthManager, apiKey?: string | undefined, defaultAccount?: string | undefined);
|
|
346
|
+
/**
|
|
347
|
+
* Helper to ensure API key is not used for user-specific operations.
|
|
348
|
+
*/
|
|
349
|
+
private checkApiKeyRestriction;
|
|
350
|
+
/**
|
|
351
|
+
* Authenticate a user with email and password.
|
|
352
|
+
*/
|
|
353
|
+
login(credentials: LoginCredentials): Promise<AuthResponse>;
|
|
354
|
+
/**
|
|
355
|
+
* Register a new user and account.
|
|
356
|
+
*/
|
|
357
|
+
register(data: RegisterData): Promise<AuthResponse>;
|
|
358
|
+
/**
|
|
359
|
+
* Refresh the access token using the refresh token.
|
|
360
|
+
*/
|
|
361
|
+
refreshToken(): Promise<AuthResponse>;
|
|
362
|
+
/**
|
|
363
|
+
* Log out the current user.
|
|
364
|
+
*/
|
|
365
|
+
logout(): Promise<{
|
|
366
|
+
success: boolean;
|
|
367
|
+
}>;
|
|
368
|
+
/**
|
|
369
|
+
* Get the current authenticated user profile.
|
|
370
|
+
*/
|
|
371
|
+
getCurrentUser(): Promise<AuthResponse>;
|
|
372
|
+
/**
|
|
373
|
+
* Initiate password reset flow.
|
|
374
|
+
*/
|
|
375
|
+
forgotPassword(data: PasswordResetRequest): Promise<{
|
|
376
|
+
message: string;
|
|
377
|
+
}>;
|
|
378
|
+
/**
|
|
379
|
+
* Reset password using a token.
|
|
380
|
+
*/
|
|
381
|
+
resetPassword(data: PasswordResetConfirm): Promise<{
|
|
382
|
+
message: string;
|
|
383
|
+
}>;
|
|
384
|
+
/**
|
|
385
|
+
* Verify email using a token.
|
|
386
|
+
*/
|
|
387
|
+
verifyEmail(token: string): Promise<{
|
|
388
|
+
message: string;
|
|
389
|
+
}>;
|
|
390
|
+
/**
|
|
391
|
+
* Resend the verification email to the current user.
|
|
392
|
+
*/
|
|
393
|
+
resendVerificationEmail(): Promise<{
|
|
394
|
+
message: string;
|
|
395
|
+
}>;
|
|
396
|
+
/**
|
|
397
|
+
* Send a verification email to a specific email address.
|
|
398
|
+
* This can be used by admins to send verification emails to users.
|
|
399
|
+
*/
|
|
400
|
+
sendVerification(email: string): Promise<{
|
|
401
|
+
message: string;
|
|
402
|
+
}>;
|
|
403
|
+
/**
|
|
404
|
+
* Verify a password reset token is valid.
|
|
405
|
+
* Returns the email associated with the token if valid.
|
|
406
|
+
*/
|
|
407
|
+
verifyResetToken(token: string): Promise<{
|
|
408
|
+
email: string;
|
|
409
|
+
}>;
|
|
410
|
+
/**
|
|
411
|
+
* Generate OAuth authorization URL for the specified provider.
|
|
412
|
+
*/
|
|
413
|
+
getOAuthUrl(provider: OAuthProvider, redirectUri: string, state?: string): Promise<OAuthUrlResponse>;
|
|
414
|
+
/**
|
|
415
|
+
* Handle OAuth callback and authenticate user.
|
|
416
|
+
*/
|
|
417
|
+
handleOAuthCallback(params: OAuthCallbackParams): Promise<OAuthResponse>;
|
|
418
|
+
/**
|
|
419
|
+
* Generate SAML SSO authorization URL for the specified provider and account.
|
|
420
|
+
*/
|
|
421
|
+
getSAMLUrl(provider: SAMLProvider, account: string, relayState?: string): Promise<SAMLUrlResponse>;
|
|
422
|
+
/**
|
|
423
|
+
* Handle SAML callback (ACS) and authenticate user.
|
|
424
|
+
*/
|
|
425
|
+
handleSAMLCallback(params: SAMLCallbackParams): Promise<SAMLResponse>;
|
|
426
|
+
/**
|
|
427
|
+
* Get SAML metadata for the specified provider and account.
|
|
428
|
+
*/
|
|
429
|
+
getSAMLMetadata(provider: SAMLProvider, account: string): Promise<string>;
|
|
430
|
+
/**
|
|
431
|
+
* Cleanup expired state tokens.
|
|
432
|
+
*/
|
|
433
|
+
private cleanupExpiredStates;
|
|
434
|
+
}
|
|
435
|
+
//#endregion
|
|
436
|
+
//#region src/core/account-service.d.ts
|
|
437
|
+
/**
|
|
438
|
+
* Service for managing accounts and their users.
|
|
439
|
+
* Requires superadmin authentication.
|
|
440
|
+
*/
|
|
441
|
+
declare class AccountService {
|
|
442
|
+
private http;
|
|
443
|
+
constructor(http: HttpClient);
|
|
444
|
+
/**
|
|
445
|
+
* List all accounts with pagination, filtering, and sorting.
|
|
446
|
+
*/
|
|
447
|
+
list(params?: AccountListParams): Promise<AccountListResponse>;
|
|
448
|
+
/**
|
|
449
|
+
* Get details for a specific account.
|
|
450
|
+
*/
|
|
451
|
+
get(accountId: string): Promise<Account>;
|
|
452
|
+
/**
|
|
453
|
+
* Create a new account.
|
|
454
|
+
*/
|
|
455
|
+
create(data: AccountCreate): Promise<Account>;
|
|
456
|
+
/**
|
|
457
|
+
* Update an existing account.
|
|
458
|
+
*/
|
|
459
|
+
update(accountId: string, data: AccountUpdate): Promise<Account>;
|
|
460
|
+
/**
|
|
461
|
+
* Delete an account and all its associated data.
|
|
462
|
+
*/
|
|
463
|
+
delete(accountId: string): Promise<{
|
|
464
|
+
success: boolean;
|
|
465
|
+
}>;
|
|
466
|
+
/**
|
|
467
|
+
* Get all users belonging to a specific account.
|
|
468
|
+
*/
|
|
469
|
+
getUsers(accountId: string, params?: AccountUserListParams): Promise<UserListResponse>;
|
|
470
|
+
}
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region src/core/user-service.d.ts
|
|
473
|
+
/**
|
|
474
|
+
* Service for managing users.
|
|
475
|
+
* Requires superadmin authentication for most operations.
|
|
476
|
+
*/
|
|
477
|
+
declare class UserService {
|
|
478
|
+
private http;
|
|
479
|
+
constructor(http: HttpClient);
|
|
480
|
+
/**
|
|
481
|
+
* List all users with pagination, filtering, and sorting.
|
|
482
|
+
*/
|
|
483
|
+
list(params?: UserListParams): Promise<UserListResponse>;
|
|
484
|
+
/**
|
|
485
|
+
* Get details for a specific user.
|
|
486
|
+
*/
|
|
487
|
+
get(userId: string): Promise<User>;
|
|
488
|
+
/**
|
|
489
|
+
* Create a new user in a specific account.
|
|
490
|
+
*/
|
|
491
|
+
create(data: UserCreate): Promise<User>;
|
|
492
|
+
/**
|
|
493
|
+
* Update an existing user.
|
|
494
|
+
*/
|
|
495
|
+
update(userId: string, data: UserUpdate): Promise<User>;
|
|
496
|
+
/**
|
|
497
|
+
* Soft delete (deactivate) a user.
|
|
498
|
+
*/
|
|
499
|
+
delete(userId: string): Promise<{
|
|
500
|
+
success: boolean;
|
|
501
|
+
}>;
|
|
502
|
+
/**
|
|
503
|
+
* Manually set a new password for a user.
|
|
504
|
+
*/
|
|
505
|
+
setPassword(userId: string, password: string): Promise<{
|
|
506
|
+
success: boolean;
|
|
507
|
+
}>;
|
|
508
|
+
/**
|
|
509
|
+
* Manually verify a user's email address.
|
|
510
|
+
*/
|
|
511
|
+
verifyEmail(userId: string): Promise<{
|
|
512
|
+
success: boolean;
|
|
513
|
+
}>;
|
|
514
|
+
/**
|
|
515
|
+
* Resend the verification email to a user.
|
|
516
|
+
*/
|
|
517
|
+
resendVerification(userId: string): Promise<{
|
|
518
|
+
success: boolean;
|
|
519
|
+
}>;
|
|
520
|
+
}
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/types/collection.d.ts
|
|
523
|
+
type FieldType = 'text' | 'number' | 'boolean' | 'date' | 'datetime' | 'email' | 'url' | 'phone' | 'select' | 'multi_select' | 'relation' | 'json';
|
|
524
|
+
interface FieldDefinition {
|
|
525
|
+
name: string;
|
|
526
|
+
type: FieldType;
|
|
527
|
+
required?: boolean;
|
|
528
|
+
default?: any;
|
|
529
|
+
unique?: boolean;
|
|
530
|
+
options?: string[];
|
|
531
|
+
collection?: string;
|
|
532
|
+
}
|
|
533
|
+
interface Collection {
|
|
534
|
+
id: string;
|
|
535
|
+
name: string;
|
|
536
|
+
fields: FieldDefinition[];
|
|
537
|
+
record_count: number;
|
|
538
|
+
field_count: number;
|
|
539
|
+
created_at: string;
|
|
540
|
+
updated_at: string;
|
|
541
|
+
}
|
|
542
|
+
interface CollectionCreate {
|
|
543
|
+
name: string;
|
|
544
|
+
fields: FieldDefinition[];
|
|
545
|
+
list_rule?: string | null;
|
|
546
|
+
view_rule?: string | null;
|
|
547
|
+
create_rule?: string | null;
|
|
548
|
+
update_rule?: string | null;
|
|
549
|
+
delete_rule?: string | null;
|
|
550
|
+
}
|
|
551
|
+
interface CollectionUpdate {
|
|
552
|
+
name?: string;
|
|
553
|
+
fields?: FieldDefinition[];
|
|
554
|
+
list_rule?: string | null;
|
|
555
|
+
view_rule?: string | null;
|
|
556
|
+
create_rule?: string | null;
|
|
557
|
+
update_rule?: string | null;
|
|
558
|
+
delete_rule?: string | null;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Comprehensive field definition for export including all metadata
|
|
562
|
+
*/
|
|
563
|
+
interface CollectionExportFieldDefinition {
|
|
564
|
+
name: string;
|
|
565
|
+
type: FieldType;
|
|
566
|
+
required?: boolean;
|
|
567
|
+
default?: any;
|
|
568
|
+
unique?: boolean;
|
|
569
|
+
options?: Record<string, any> | null;
|
|
570
|
+
collection?: string | null;
|
|
571
|
+
on_delete?: string | null;
|
|
572
|
+
pii?: boolean;
|
|
573
|
+
mask_type?: string | null;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Access control rules structure for Permission System V2
|
|
577
|
+
* Rule values:
|
|
578
|
+
* - null = locked (access denied)
|
|
579
|
+
* - "" (empty string) = public (all users can access)
|
|
580
|
+
* - Expression string = conditional access (RLS rule)
|
|
581
|
+
*/
|
|
582
|
+
interface CollectionExportRules {
|
|
583
|
+
list_rule: string | null;
|
|
584
|
+
view_rule: string | null;
|
|
585
|
+
create_rule: string | null;
|
|
586
|
+
update_rule: string | null;
|
|
587
|
+
delete_rule: string | null;
|
|
588
|
+
list_fields: string;
|
|
589
|
+
view_fields: string;
|
|
590
|
+
create_fields: string;
|
|
591
|
+
update_fields: string;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Single collection in export bundle
|
|
595
|
+
*/
|
|
596
|
+
interface CollectionExportItem {
|
|
597
|
+
name: string;
|
|
598
|
+
schema: CollectionExportFieldDefinition[];
|
|
599
|
+
rules: CollectionExportRules;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Complete export file structure
|
|
603
|
+
*/
|
|
604
|
+
interface CollectionExportData {
|
|
605
|
+
version: string;
|
|
606
|
+
exported_at: string;
|
|
607
|
+
exported_by: string;
|
|
608
|
+
collections: CollectionExportItem[];
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Import conflict handling strategies
|
|
612
|
+
*/
|
|
613
|
+
type ImportStrategy = 'error' | 'skip' | 'update';
|
|
614
|
+
/**
|
|
615
|
+
* Import request payload
|
|
616
|
+
*/
|
|
617
|
+
interface CollectionImportRequest {
|
|
618
|
+
data: CollectionExportData;
|
|
619
|
+
strategy?: ImportStrategy;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Import result for a single collection
|
|
623
|
+
*/
|
|
624
|
+
interface CollectionImportItemResult {
|
|
625
|
+
name: string;
|
|
626
|
+
status: 'imported' | 'skipped' | 'updated' | 'error';
|
|
627
|
+
message: string;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Complete import operation result
|
|
631
|
+
*/
|
|
632
|
+
interface CollectionImportResult {
|
|
633
|
+
success: boolean;
|
|
634
|
+
imported_count: number;
|
|
635
|
+
skipped_count: number;
|
|
636
|
+
updated_count: number;
|
|
637
|
+
failed_count: number;
|
|
638
|
+
collections: CollectionImportItemResult[];
|
|
639
|
+
migrations_created: string[];
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Export query parameters
|
|
643
|
+
*/
|
|
644
|
+
interface CollectionExportParams {
|
|
645
|
+
collection_ids?: string[];
|
|
646
|
+
}
|
|
647
|
+
//#endregion
|
|
648
|
+
//#region src/core/collection-service.d.ts
|
|
649
|
+
/**
|
|
650
|
+
* Service for managing collections and their schemas.
|
|
651
|
+
* Requires superadmin authentication.
|
|
652
|
+
*/
|
|
653
|
+
declare class CollectionService {
|
|
654
|
+
private http;
|
|
655
|
+
constructor(http: HttpClient);
|
|
656
|
+
/**
|
|
657
|
+
* List all collections.
|
|
658
|
+
*/
|
|
659
|
+
list(): Promise<Collection[]>;
|
|
660
|
+
/**
|
|
661
|
+
* List collection names only.
|
|
662
|
+
*/
|
|
663
|
+
listNames(): Promise<string[]>;
|
|
664
|
+
/**
|
|
665
|
+
* Get schema details for a specific collection.
|
|
666
|
+
*/
|
|
667
|
+
get(collectionId: string): Promise<Collection>;
|
|
668
|
+
/**
|
|
669
|
+
* Create a new collection and its physical table.
|
|
670
|
+
*/
|
|
671
|
+
create(data: CollectionCreate): Promise<Collection>;
|
|
672
|
+
/**
|
|
673
|
+
* Update an existing collection schema.
|
|
674
|
+
* Note: Field types cannot be changed for data safety.
|
|
675
|
+
*/
|
|
676
|
+
update(collectionId: string, data: CollectionUpdate): Promise<Collection>;
|
|
677
|
+
/**
|
|
678
|
+
* Delete a collection and drop its physical table.
|
|
679
|
+
*/
|
|
680
|
+
delete(collectionId: string): Promise<{
|
|
681
|
+
success: boolean;
|
|
682
|
+
}>;
|
|
683
|
+
/**
|
|
684
|
+
* Export collections to JSON format.
|
|
685
|
+
* Returns collection schemas and rules for backup or migration.
|
|
686
|
+
*
|
|
687
|
+
* @param params Optional filter by collection IDs
|
|
688
|
+
* @returns Complete export data structure with collections, schemas, and rules
|
|
689
|
+
* @throws {AuthorizationError} If user is not a superadmin
|
|
690
|
+
*
|
|
691
|
+
* @example
|
|
692
|
+
* // Export all collections
|
|
693
|
+
* const exportData = await client.collections.export();
|
|
694
|
+
*
|
|
695
|
+
* @example
|
|
696
|
+
* // Export specific collections
|
|
697
|
+
* const exportData = await client.collections.export({
|
|
698
|
+
* collection_ids: ['col-123', 'col-456']
|
|
699
|
+
* });
|
|
700
|
+
*/
|
|
701
|
+
export(params?: CollectionExportParams): Promise<CollectionExportData>;
|
|
702
|
+
/**
|
|
703
|
+
* Import collections from JSON export.
|
|
704
|
+
*
|
|
705
|
+
* @param request Import request with data and conflict strategy
|
|
706
|
+
* @returns Import result with per-collection status and migration IDs
|
|
707
|
+
* @throws {ValidationError} If import data is invalid
|
|
708
|
+
* @throws {ConflictError} If collection exists and strategy is 'error'
|
|
709
|
+
* @throws {AuthorizationError} If user is not a superadmin
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* // Import with error strategy (fail on conflicts)
|
|
713
|
+
* const result = await client.collections.import({
|
|
714
|
+
* data: exportData,
|
|
715
|
+
* strategy: 'error'
|
|
716
|
+
* });
|
|
717
|
+
*
|
|
718
|
+
* @example
|
|
719
|
+
* // Import with skip strategy (skip existing collections)
|
|
720
|
+
* const result = await client.collections.import({
|
|
721
|
+
* data: exportData,
|
|
722
|
+
* strategy: 'skip'
|
|
723
|
+
* });
|
|
724
|
+
*
|
|
725
|
+
* @example
|
|
726
|
+
* // Import with update strategy (update existing collections)
|
|
727
|
+
* const result = await client.collections.import({
|
|
728
|
+
* data: exportData,
|
|
729
|
+
* strategy: 'update'
|
|
730
|
+
* });
|
|
731
|
+
*/
|
|
732
|
+
import(request: CollectionImportRequest): Promise<CollectionImportResult>;
|
|
733
|
+
}
|
|
734
|
+
//#endregion
|
|
735
|
+
//#region src/types/record.d.ts
|
|
736
|
+
/**
|
|
737
|
+
* Base record fields managed by the system.
|
|
738
|
+
*/
|
|
739
|
+
interface BaseRecord {
|
|
740
|
+
id: string;
|
|
741
|
+
account_id: string;
|
|
742
|
+
created_at: string;
|
|
743
|
+
updated_at: string;
|
|
744
|
+
created_by?: string;
|
|
745
|
+
updated_by?: string;
|
|
746
|
+
[key: string]: any;
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Parameters for listing records.
|
|
750
|
+
*/
|
|
751
|
+
interface RecordListParams {
|
|
752
|
+
/**
|
|
753
|
+
* Number of records to skip.
|
|
754
|
+
*/
|
|
755
|
+
skip?: number;
|
|
756
|
+
/**
|
|
757
|
+
* Maximum number of records to return.
|
|
758
|
+
*/
|
|
759
|
+
limit?: number;
|
|
760
|
+
/**
|
|
761
|
+
* Sort expression (e.g., 'created_at' or '-created_at' for descending).
|
|
762
|
+
*/
|
|
763
|
+
sort?: string;
|
|
764
|
+
/**
|
|
765
|
+
* Fields to include in the response.
|
|
766
|
+
*/
|
|
767
|
+
fields?: string[] | string;
|
|
768
|
+
/**
|
|
769
|
+
* Filter parameters.
|
|
770
|
+
*/
|
|
771
|
+
filter?: any;
|
|
772
|
+
/**
|
|
773
|
+
* Related collections to expand.
|
|
774
|
+
*/
|
|
775
|
+
expand?: string[] | string;
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Paginated response for records.
|
|
779
|
+
*/
|
|
780
|
+
interface RecordListResponse<T> {
|
|
781
|
+
items: (T & BaseRecord)[];
|
|
782
|
+
total: number;
|
|
783
|
+
skip: number;
|
|
784
|
+
limit: number;
|
|
785
|
+
}
|
|
786
|
+
//#endregion
|
|
787
|
+
//#region src/types/query.d.ts
|
|
788
|
+
/**
|
|
789
|
+
* Supported filter operators.
|
|
790
|
+
*/
|
|
791
|
+
type FilterOperator = '=' | '!=' | '>' | '>=' | '<' | '<=' | '~' | '!~' | '?=' | '?!=';
|
|
792
|
+
/**
|
|
793
|
+
* Filter expression object.
|
|
794
|
+
*/
|
|
795
|
+
interface FilterExpression {
|
|
796
|
+
field: string;
|
|
797
|
+
operator: FilterOperator;
|
|
798
|
+
value?: any;
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Sort direction.
|
|
802
|
+
*/
|
|
803
|
+
type SortDirection = 'asc' | 'desc';
|
|
804
|
+
/**
|
|
805
|
+
* Sort expression object.
|
|
806
|
+
*/
|
|
807
|
+
interface SortExpression {
|
|
808
|
+
field: string;
|
|
809
|
+
direction: SortDirection;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Query parameters interface matching the backend expectations.
|
|
813
|
+
* This is similar to RecordListParams but used internally by the builder.
|
|
814
|
+
*/
|
|
815
|
+
interface QueryParams {
|
|
816
|
+
page?: number;
|
|
817
|
+
perPage?: number;
|
|
818
|
+
sort?: string;
|
|
819
|
+
filter?: string;
|
|
820
|
+
expand?: string;
|
|
821
|
+
fields?: string;
|
|
822
|
+
skip?: number;
|
|
823
|
+
limit?: number;
|
|
824
|
+
}
|
|
825
|
+
//#endregion
|
|
826
|
+
//#region src/core/query-builder.d.ts
|
|
827
|
+
/**
|
|
828
|
+
* Fluent interface for building complex queries.
|
|
829
|
+
*/
|
|
830
|
+
declare class QueryBuilder<T = any> {
|
|
831
|
+
private service;
|
|
832
|
+
private collection;
|
|
833
|
+
private _fields;
|
|
834
|
+
private _expand;
|
|
835
|
+
private _filterParts;
|
|
836
|
+
private _sortParts;
|
|
837
|
+
private _page;
|
|
838
|
+
private _perPage;
|
|
839
|
+
private _skip;
|
|
840
|
+
private _limit;
|
|
841
|
+
private _useLegacyPagination;
|
|
842
|
+
constructor(service: RecordService, collection: string);
|
|
843
|
+
/**
|
|
844
|
+
* Specify fields to return.
|
|
845
|
+
* @param fields Array of field names or comma-separated string
|
|
846
|
+
*/
|
|
847
|
+
select(fields: string | string[]): this;
|
|
848
|
+
/**
|
|
849
|
+
* Expand related records.
|
|
850
|
+
* @param relations Array of relation names or comma-separated string
|
|
851
|
+
*/
|
|
852
|
+
expand(relations: string | string[]): this;
|
|
853
|
+
/**
|
|
854
|
+
* Add a filter condition.
|
|
855
|
+
* @param field Field name
|
|
856
|
+
* @param operator Filter operator
|
|
857
|
+
* @param value Value to compare against
|
|
858
|
+
*/
|
|
859
|
+
filter(field: string, operator: FilterOperator, value?: any): this;
|
|
860
|
+
/**
|
|
861
|
+
* Add a raw filter string.
|
|
862
|
+
* @param filterString Raw filter string (e.g., "age > 21")
|
|
863
|
+
*/
|
|
864
|
+
filter(filterString: string): this;
|
|
865
|
+
/**
|
|
866
|
+
* Add sorting.
|
|
867
|
+
* @param field Field name
|
|
868
|
+
* @param direction 'asc' or 'desc' (default: 'asc')
|
|
869
|
+
*/
|
|
870
|
+
sort(field: string, direction?: SortDirection): this;
|
|
871
|
+
/**
|
|
872
|
+
* Set limit (and optionally skip).
|
|
873
|
+
* Note: Using limit/skip switches to manual offset pagination.
|
|
874
|
+
* @param limit Max records
|
|
875
|
+
* @param skip Records to skip
|
|
876
|
+
*/
|
|
877
|
+
limit(limit: number): this;
|
|
878
|
+
/**
|
|
879
|
+
* Set skip.
|
|
880
|
+
* Note: Using limit/skip switches to manual offset pagination.
|
|
881
|
+
* @param skip Records to skip
|
|
882
|
+
*/
|
|
883
|
+
skip(skip: number): this;
|
|
884
|
+
/**
|
|
885
|
+
* Set page number and page size.
|
|
886
|
+
* @param page Page number (1-based)
|
|
887
|
+
* @param perPage Records per page
|
|
888
|
+
*/
|
|
889
|
+
page(page: number, perPage?: number): this;
|
|
890
|
+
/**
|
|
891
|
+
* Execute query and get list of records.
|
|
892
|
+
*/
|
|
893
|
+
get(): Promise<RecordListResponse<T>>;
|
|
894
|
+
/**
|
|
895
|
+
* Execute query and get the first matching record.
|
|
896
|
+
*/
|
|
897
|
+
first(): Promise<(T & BaseRecord) | null>;
|
|
898
|
+
private formatValue;
|
|
899
|
+
}
|
|
900
|
+
//#endregion
|
|
901
|
+
//#region src/core/record-service.d.ts
|
|
902
|
+
/**
|
|
903
|
+
* Service for performing CRUD operations on dynamic collections.
|
|
904
|
+
*/
|
|
905
|
+
declare class RecordService {
|
|
906
|
+
private http;
|
|
907
|
+
constructor(http: HttpClient);
|
|
908
|
+
/**
|
|
909
|
+
* List records from a collection with pagination, filtering, and sorting.
|
|
910
|
+
* @template T The record type
|
|
911
|
+
* @param collection Collection name
|
|
912
|
+
* @param params Query parameters
|
|
913
|
+
*/
|
|
914
|
+
list<T = any>(collection: string, params?: RecordListParams): Promise<RecordListResponse<T>>;
|
|
915
|
+
/**
|
|
916
|
+
* Create a query builder for the collection.
|
|
917
|
+
* @template T The record type
|
|
918
|
+
* @param collection Collection name
|
|
919
|
+
*/
|
|
920
|
+
query<T = any>(collection: string): QueryBuilder<T>;
|
|
921
|
+
/**
|
|
922
|
+
* Get a single record by ID.
|
|
923
|
+
* @template T The record type
|
|
924
|
+
* @param collection Collection name
|
|
925
|
+
* @param recordId Record ID
|
|
926
|
+
* @param params Optional query parameters (e.g., fields)
|
|
927
|
+
*/
|
|
928
|
+
get<T = any>(collection: string, recordId: string, params?: {
|
|
929
|
+
fields?: string[] | string;
|
|
930
|
+
expand?: string[] | string;
|
|
931
|
+
}): Promise<T & BaseRecord>;
|
|
932
|
+
/**
|
|
933
|
+
* Create a new record in a collection.
|
|
934
|
+
* @template T The record type
|
|
935
|
+
* @param collection Collection name
|
|
936
|
+
* @param data Record data
|
|
937
|
+
*/
|
|
938
|
+
create<T = any>(collection: string, data: Partial<T>): Promise<T & BaseRecord>;
|
|
939
|
+
/**
|
|
940
|
+
* Full update of an existing record (PUT).
|
|
941
|
+
* @template T The record type
|
|
942
|
+
* @param collection Collection name
|
|
943
|
+
* @param recordId Record ID
|
|
944
|
+
* @param data Record data
|
|
945
|
+
*/
|
|
946
|
+
update<T = any>(collection: string, recordId: string, data: Partial<T>): Promise<T & BaseRecord>;
|
|
947
|
+
/**
|
|
948
|
+
* Partial update of an existing record (PATCH).
|
|
949
|
+
* @template T The record type
|
|
950
|
+
* @param collection Collection name
|
|
951
|
+
* @param recordId Record ID
|
|
952
|
+
* @param data Partial record data
|
|
953
|
+
*/
|
|
954
|
+
patch<T = any>(collection: string, recordId: string, data: Partial<T>): Promise<T & BaseRecord>;
|
|
955
|
+
/**
|
|
956
|
+
* Delete a record from a collection.
|
|
957
|
+
* @param collection Collection name
|
|
958
|
+
* @param recordId Record ID
|
|
959
|
+
*/
|
|
960
|
+
delete(collection: string, recordId: string): Promise<{
|
|
961
|
+
success: boolean;
|
|
962
|
+
}>;
|
|
963
|
+
}
|
|
964
|
+
//#endregion
|
|
965
|
+
//#region src/types/group.d.ts
|
|
966
|
+
interface Group {
|
|
967
|
+
id: string;
|
|
968
|
+
account_id: string;
|
|
969
|
+
name: string;
|
|
970
|
+
description?: string;
|
|
971
|
+
is_system: boolean;
|
|
972
|
+
created_at: string;
|
|
973
|
+
updated_at: string;
|
|
974
|
+
}
|
|
975
|
+
interface GroupCreate {
|
|
976
|
+
name: string;
|
|
977
|
+
description?: string;
|
|
978
|
+
}
|
|
979
|
+
interface GroupUpdate {
|
|
980
|
+
name?: string;
|
|
981
|
+
description?: string;
|
|
982
|
+
}
|
|
983
|
+
interface GroupListParams {
|
|
984
|
+
page?: number;
|
|
985
|
+
page_size?: number;
|
|
986
|
+
search?: string;
|
|
987
|
+
[key: string]: string | number | boolean | undefined;
|
|
988
|
+
}
|
|
989
|
+
interface GroupListResponse {
|
|
990
|
+
items: Group[];
|
|
991
|
+
total: number;
|
|
992
|
+
page: number;
|
|
993
|
+
page_size: number;
|
|
994
|
+
}
|
|
995
|
+
//#endregion
|
|
996
|
+
//#region src/core/group-service.d.ts
|
|
997
|
+
/**
|
|
998
|
+
* Service for managing groups.
|
|
999
|
+
*/
|
|
1000
|
+
declare class GroupsService {
|
|
1001
|
+
private http;
|
|
1002
|
+
constructor(http: HttpClient);
|
|
1003
|
+
/**
|
|
1004
|
+
* List all groups in the current account.
|
|
1005
|
+
*/
|
|
1006
|
+
list(params?: GroupListParams): Promise<GroupListResponse>;
|
|
1007
|
+
/**
|
|
1008
|
+
* Get details for a specific group.
|
|
1009
|
+
*/
|
|
1010
|
+
get(groupId: string): Promise<Group>;
|
|
1011
|
+
/**
|
|
1012
|
+
* Create a new group in the current account.
|
|
1013
|
+
*/
|
|
1014
|
+
create(data: GroupCreate): Promise<Group>;
|
|
1015
|
+
/**
|
|
1016
|
+
* Update a group's name or description.
|
|
1017
|
+
*/
|
|
1018
|
+
update(groupId: string, data: GroupUpdate): Promise<Group>;
|
|
1019
|
+
/**
|
|
1020
|
+
* Delete a group.
|
|
1021
|
+
*/
|
|
1022
|
+
delete(groupId: string): Promise<{
|
|
1023
|
+
success: boolean;
|
|
1024
|
+
}>;
|
|
1025
|
+
/**
|
|
1026
|
+
* Add a user to a group.
|
|
1027
|
+
*/
|
|
1028
|
+
addMember(groupId: string, userId: string): Promise<{
|
|
1029
|
+
success: boolean;
|
|
1030
|
+
}>;
|
|
1031
|
+
/**
|
|
1032
|
+
* Remove a user from a group.
|
|
1033
|
+
*/
|
|
1034
|
+
removeMember(groupId: string, userId: string): Promise<{
|
|
1035
|
+
success: boolean;
|
|
1036
|
+
}>;
|
|
1037
|
+
}
|
|
1038
|
+
//#endregion
|
|
1039
|
+
//#region src/types/invitation.d.ts
|
|
1040
|
+
interface Invitation {
|
|
1041
|
+
id: string;
|
|
1042
|
+
email: string;
|
|
1043
|
+
account_id: string;
|
|
1044
|
+
role_id?: string;
|
|
1045
|
+
status: 'pending' | 'accepted' | 'expired' | 'cancelled';
|
|
1046
|
+
token?: string;
|
|
1047
|
+
expires_at: string;
|
|
1048
|
+
created_at: string;
|
|
1049
|
+
updated_at: string;
|
|
1050
|
+
}
|
|
1051
|
+
interface InvitationCreate {
|
|
1052
|
+
email: string;
|
|
1053
|
+
role_id?: string;
|
|
1054
|
+
}
|
|
1055
|
+
interface InvitationListParams {
|
|
1056
|
+
status?: 'pending' | 'accepted' | 'expired' | 'cancelled';
|
|
1057
|
+
page?: number;
|
|
1058
|
+
page_size?: number;
|
|
1059
|
+
[key: string]: string | number | boolean | undefined;
|
|
1060
|
+
}
|
|
1061
|
+
//#endregion
|
|
1062
|
+
//#region src/core/invitation-service.d.ts
|
|
1063
|
+
/**
|
|
1064
|
+
* Service for managing user invitations.
|
|
1065
|
+
* Allows admins to invite users and tracks invitation status.
|
|
1066
|
+
*/
|
|
1067
|
+
declare class InvitationService {
|
|
1068
|
+
private http;
|
|
1069
|
+
constructor(http: HttpClient);
|
|
1070
|
+
/**
|
|
1071
|
+
* List all invitations in the current account.
|
|
1072
|
+
*/
|
|
1073
|
+
list(params?: InvitationListParams): Promise<Invitation[]>;
|
|
1074
|
+
/**
|
|
1075
|
+
* Create a new invitation for a user.
|
|
1076
|
+
*/
|
|
1077
|
+
create(data: InvitationCreate): Promise<Invitation>;
|
|
1078
|
+
/**
|
|
1079
|
+
* Resend an invitation email.
|
|
1080
|
+
*/
|
|
1081
|
+
resend(invitationId: string): Promise<{
|
|
1082
|
+
success: boolean;
|
|
1083
|
+
}>;
|
|
1084
|
+
/**
|
|
1085
|
+
* Get public details of an invitation using a token.
|
|
1086
|
+
* No authentication required.
|
|
1087
|
+
*/
|
|
1088
|
+
getPublic(token: string): Promise<Invitation>;
|
|
1089
|
+
/**
|
|
1090
|
+
* Accept an invitation using a token and password.
|
|
1091
|
+
* Creates the user account and returns authentication tokens.
|
|
1092
|
+
*/
|
|
1093
|
+
accept(token: string, password: string): Promise<AuthResponse>;
|
|
1094
|
+
/**
|
|
1095
|
+
* Cancel a pending invitation.
|
|
1096
|
+
*/
|
|
1097
|
+
cancel(invitationId: string): Promise<{
|
|
1098
|
+
success: boolean;
|
|
1099
|
+
}>;
|
|
1100
|
+
}
|
|
1101
|
+
//#endregion
|
|
1102
|
+
//#region src/types/api-key.d.ts
|
|
1103
|
+
interface ApiKey {
|
|
1104
|
+
id: string;
|
|
1105
|
+
name: string;
|
|
1106
|
+
/**
|
|
1107
|
+
* The full API key. Only returned once during creation.
|
|
1108
|
+
*/
|
|
1109
|
+
key?: string;
|
|
1110
|
+
/**
|
|
1111
|
+
* The masked version of the key (e.g., "sk_...42").
|
|
1112
|
+
*/
|
|
1113
|
+
masked_key: string;
|
|
1114
|
+
/**
|
|
1115
|
+
* The last 4 characters of the key.
|
|
1116
|
+
*/
|
|
1117
|
+
last_4: string;
|
|
1118
|
+
expires_at: string | null;
|
|
1119
|
+
created_at: string;
|
|
1120
|
+
updated_at: string;
|
|
1121
|
+
revoked_at: string | null;
|
|
1122
|
+
}
|
|
1123
|
+
interface ApiKeyCreate {
|
|
1124
|
+
name: string;
|
|
1125
|
+
expires_at?: string;
|
|
1126
|
+
}
|
|
1127
|
+
//#endregion
|
|
1128
|
+
//#region src/core/api-key-service.d.ts
|
|
1129
|
+
/**
|
|
1130
|
+
* Service for managing API keys.
|
|
1131
|
+
* API keys are used for service-to-service communication.
|
|
1132
|
+
*/
|
|
1133
|
+
declare class ApiKeyService {
|
|
1134
|
+
private http;
|
|
1135
|
+
constructor(http: HttpClient);
|
|
1136
|
+
/**
|
|
1137
|
+
* List all API keys for the current user.
|
|
1138
|
+
* Keys are masked except for the last 4 characters.
|
|
1139
|
+
*/
|
|
1140
|
+
list(): Promise<ApiKey[]>;
|
|
1141
|
+
/**
|
|
1142
|
+
* Get details for a specific API key.
|
|
1143
|
+
* The key itself is masked.
|
|
1144
|
+
*/
|
|
1145
|
+
get(keyId: string): Promise<ApiKey>;
|
|
1146
|
+
/**
|
|
1147
|
+
* Create a new API key.
|
|
1148
|
+
* The response includes the full key, which is shown only once.
|
|
1149
|
+
*/
|
|
1150
|
+
create(data: ApiKeyCreate): Promise<ApiKey>;
|
|
1151
|
+
/**
|
|
1152
|
+
* Revoke an existing API key.
|
|
1153
|
+
* Once revoked, the key can no longer be used.
|
|
1154
|
+
*/
|
|
1155
|
+
revoke(keyId: string): Promise<{
|
|
1156
|
+
success: boolean;
|
|
1157
|
+
}>;
|
|
1158
|
+
}
|
|
1159
|
+
//#endregion
|
|
1160
|
+
//#region src/types/audit-log.d.ts
|
|
1161
|
+
interface AuditLog {
|
|
1162
|
+
id: string;
|
|
1163
|
+
account_id: string;
|
|
1164
|
+
table_name: string;
|
|
1165
|
+
record_id: string;
|
|
1166
|
+
user_id: string;
|
|
1167
|
+
operation: 'create' | 'update' | 'delete' | 'login' | 'logout' | string;
|
|
1168
|
+
before: Record<string, any> | null;
|
|
1169
|
+
after: Record<string, any> | null;
|
|
1170
|
+
created_at: string;
|
|
1171
|
+
}
|
|
1172
|
+
interface AuditLogFilters {
|
|
1173
|
+
account_id?: string;
|
|
1174
|
+
table_name?: string;
|
|
1175
|
+
record_id?: string;
|
|
1176
|
+
user_id?: string;
|
|
1177
|
+
operation?: string;
|
|
1178
|
+
from_date?: string;
|
|
1179
|
+
to_date?: string;
|
|
1180
|
+
page?: number;
|
|
1181
|
+
skip?: number;
|
|
1182
|
+
limit?: number;
|
|
1183
|
+
sort?: string;
|
|
1184
|
+
}
|
|
1185
|
+
type AuditLogExportFormat = 'csv' | 'json' | 'pdf';
|
|
1186
|
+
interface AuditLogListResponse {
|
|
1187
|
+
items: AuditLog[];
|
|
1188
|
+
total: number;
|
|
1189
|
+
page: number;
|
|
1190
|
+
limit: number;
|
|
1191
|
+
audit_logging_enabled: boolean;
|
|
1192
|
+
}
|
|
1193
|
+
//#endregion
|
|
1194
|
+
//#region src/core/audit-log-service.d.ts
|
|
1195
|
+
declare class AuditLogService {
|
|
1196
|
+
private httpClient;
|
|
1197
|
+
constructor(httpClient: HttpClient);
|
|
1198
|
+
/**
|
|
1199
|
+
* Lists audit logs with optional filtering, pagination, and sorting.
|
|
1200
|
+
*/
|
|
1201
|
+
list(params?: AuditLogFilters): Promise<AuditLogListResponse>;
|
|
1202
|
+
/**
|
|
1203
|
+
* Retrieves a single audit log entry by ID.
|
|
1204
|
+
*/
|
|
1205
|
+
get(logId: string): Promise<AuditLog>;
|
|
1206
|
+
/**
|
|
1207
|
+
* Exports audit logs in the specified format (JSON, CSV, or PDF).
|
|
1208
|
+
*
|
|
1209
|
+
* @param params Optional filters (account_id, table_name, operation, date range, etc.)
|
|
1210
|
+
* @param format Export format: 'json', 'csv', or 'pdf' (default: 'json')
|
|
1211
|
+
* @returns Exported data as string (base64-encoded for PDF format)
|
|
1212
|
+
* @throws {AuthorizationError} If user is not a superadmin
|
|
1213
|
+
*
|
|
1214
|
+
* @example
|
|
1215
|
+
* // Export as JSON
|
|
1216
|
+
* const jsonData = await client.auditLogs.export({ table_name: 'users' }, 'json');
|
|
1217
|
+
*
|
|
1218
|
+
* @example
|
|
1219
|
+
* // Export as CSV
|
|
1220
|
+
* const csvData = await client.auditLogs.export({ table_name: 'users' }, 'csv');
|
|
1221
|
+
*
|
|
1222
|
+
* @example
|
|
1223
|
+
* // Export as PDF
|
|
1224
|
+
* const pdfBase64 = await client.auditLogs.export({ table_name: 'users' }, 'pdf');
|
|
1225
|
+
* // pdfBase64 is a base64-encoded PDF string
|
|
1226
|
+
*/
|
|
1227
|
+
export(params?: AuditLogFilters, format?: AuditLogExportFormat): Promise<string>;
|
|
1228
|
+
}
|
|
1229
|
+
//#endregion
|
|
1230
|
+
//#region src/types/role.d.ts
|
|
1231
|
+
interface Role {
|
|
1232
|
+
id: string;
|
|
1233
|
+
name: string;
|
|
1234
|
+
description: string;
|
|
1235
|
+
created_at: string;
|
|
1236
|
+
updated_at: string;
|
|
1237
|
+
}
|
|
1238
|
+
interface RoleCreate {
|
|
1239
|
+
name: string;
|
|
1240
|
+
description?: string;
|
|
1241
|
+
}
|
|
1242
|
+
interface RoleUpdate {
|
|
1243
|
+
name?: string;
|
|
1244
|
+
description?: string;
|
|
1245
|
+
}
|
|
1246
|
+
interface RoleListResponse {
|
|
1247
|
+
items: Role[];
|
|
1248
|
+
total: number;
|
|
1249
|
+
}
|
|
1250
|
+
interface CollectionRule {
|
|
1251
|
+
list_rule: string | null;
|
|
1252
|
+
view_rule: string | null;
|
|
1253
|
+
create_rule: string | null;
|
|
1254
|
+
update_rule: string | null;
|
|
1255
|
+
delete_rule: string | null;
|
|
1256
|
+
list_fields: string;
|
|
1257
|
+
view_fields: string;
|
|
1258
|
+
create_fields: string;
|
|
1259
|
+
update_fields: string;
|
|
1260
|
+
}
|
|
1261
|
+
interface CollectionRuleUpdate {
|
|
1262
|
+
list_rule?: string | null;
|
|
1263
|
+
view_rule?: string | null;
|
|
1264
|
+
create_rule?: string | null;
|
|
1265
|
+
update_rule?: string | null;
|
|
1266
|
+
delete_rule?: string | null;
|
|
1267
|
+
list_fields?: string;
|
|
1268
|
+
view_fields?: string;
|
|
1269
|
+
create_fields?: string;
|
|
1270
|
+
update_fields?: string;
|
|
1271
|
+
}
|
|
1272
|
+
interface RuleValidationResult {
|
|
1273
|
+
valid: boolean;
|
|
1274
|
+
errors?: string[];
|
|
1275
|
+
}
|
|
1276
|
+
interface RuleTestResult {
|
|
1277
|
+
result: boolean;
|
|
1278
|
+
}
|
|
1279
|
+
interface RuleValidationParams {
|
|
1280
|
+
rule: string;
|
|
1281
|
+
operation: 'list' | 'view' | 'create' | 'update' | 'delete';
|
|
1282
|
+
collectionFields: string[];
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Permission type alias for CollectionRule (Permission System V2).
|
|
1286
|
+
*/
|
|
1287
|
+
type Permission = CollectionRule;
|
|
1288
|
+
//#endregion
|
|
1289
|
+
//#region src/core/role-service.d.ts
|
|
1290
|
+
/**
|
|
1291
|
+
* Service for managing roles.
|
|
1292
|
+
* Requires superadmin authentication.
|
|
1293
|
+
*/
|
|
1294
|
+
declare class RoleService {
|
|
1295
|
+
private http;
|
|
1296
|
+
constructor(http: HttpClient);
|
|
1297
|
+
/**
|
|
1298
|
+
* List all roles with pagination.
|
|
1299
|
+
*/
|
|
1300
|
+
list(): Promise<RoleListResponse>;
|
|
1301
|
+
/**
|
|
1302
|
+
* Get details for a specific role.
|
|
1303
|
+
*/
|
|
1304
|
+
get(roleId: string): Promise<Role>;
|
|
1305
|
+
/**
|
|
1306
|
+
* Create a new role.
|
|
1307
|
+
*/
|
|
1308
|
+
create(data: RoleCreate): Promise<Role>;
|
|
1309
|
+
/**
|
|
1310
|
+
* Update an existing role.
|
|
1311
|
+
*/
|
|
1312
|
+
update(roleId: string, data: RoleUpdate): Promise<Role>;
|
|
1313
|
+
/**
|
|
1314
|
+
* Delete a role.
|
|
1315
|
+
* Fails if the role is currently in use.
|
|
1316
|
+
*/
|
|
1317
|
+
delete(roleId: string): Promise<{
|
|
1318
|
+
success: boolean;
|
|
1319
|
+
}>;
|
|
1320
|
+
}
|
|
1321
|
+
//#endregion
|
|
1322
|
+
//#region src/core/collection-rule-service.d.ts
|
|
1323
|
+
/**
|
|
1324
|
+
* Service for managing collection-level access rules and field permissions.
|
|
1325
|
+
* Requires superadmin authentication.
|
|
1326
|
+
*/
|
|
1327
|
+
declare class CollectionRuleService {
|
|
1328
|
+
private http;
|
|
1329
|
+
constructor(http: HttpClient);
|
|
1330
|
+
/**
|
|
1331
|
+
* Get access rules and field permissions for a specific collection.
|
|
1332
|
+
*/
|
|
1333
|
+
get(collectionName: string): Promise<CollectionRule>;
|
|
1334
|
+
/**
|
|
1335
|
+
* Update access rules and field permissions for a specific collection.
|
|
1336
|
+
*/
|
|
1337
|
+
update(collectionName: string, data: CollectionRuleUpdate): Promise<CollectionRule>;
|
|
1338
|
+
/**
|
|
1339
|
+
* Validate a rule expression against a collection schema.
|
|
1340
|
+
*/
|
|
1341
|
+
validateRule(rule: string, operation: 'list' | 'view' | 'create' | 'update' | 'delete', collectionFields: string[]): Promise<RuleValidationResult>;
|
|
1342
|
+
/**
|
|
1343
|
+
* Test a rule evaluation with a sample context.
|
|
1344
|
+
*/
|
|
1345
|
+
testRule(rule: string, context: any): Promise<RuleTestResult>;
|
|
1346
|
+
}
|
|
1347
|
+
//#endregion
|
|
1348
|
+
//#region src/types/macro.d.ts
|
|
1349
|
+
interface Macro {
|
|
1350
|
+
id: string;
|
|
1351
|
+
name: string;
|
|
1352
|
+
description: string;
|
|
1353
|
+
sql_query: string;
|
|
1354
|
+
parameters: string[];
|
|
1355
|
+
is_builtin: boolean;
|
|
1356
|
+
created_at: string;
|
|
1357
|
+
updated_at: string;
|
|
1358
|
+
}
|
|
1359
|
+
interface MacroCreate {
|
|
1360
|
+
name: string;
|
|
1361
|
+
description: string;
|
|
1362
|
+
sql_query: string;
|
|
1363
|
+
parameters: string[];
|
|
1364
|
+
}
|
|
1365
|
+
interface MacroUpdate {
|
|
1366
|
+
name?: string;
|
|
1367
|
+
description?: string;
|
|
1368
|
+
sql_query?: string;
|
|
1369
|
+
parameters?: string[];
|
|
1370
|
+
}
|
|
1371
|
+
interface MacroTestResult {
|
|
1372
|
+
success: boolean;
|
|
1373
|
+
result: any;
|
|
1374
|
+
}
|
|
1375
|
+
interface MacroListResponse {
|
|
1376
|
+
items: Macro[];
|
|
1377
|
+
total: number;
|
|
1378
|
+
}
|
|
1379
|
+
//#endregion
|
|
1380
|
+
//#region src/core/macro-service.d.ts
|
|
1381
|
+
/**
|
|
1382
|
+
* Service for managing SQL macros.
|
|
1383
|
+
* Macros can be used in permission rules.
|
|
1384
|
+
* Requires superadmin authentication for most operations.
|
|
1385
|
+
*/
|
|
1386
|
+
declare class MacroService {
|
|
1387
|
+
private http;
|
|
1388
|
+
constructor(http: HttpClient);
|
|
1389
|
+
/**
|
|
1390
|
+
* List all macros, including built-in ones.
|
|
1391
|
+
*/
|
|
1392
|
+
list(): Promise<MacroListResponse>;
|
|
1393
|
+
/**
|
|
1394
|
+
* Get details for a specific macro.
|
|
1395
|
+
*/
|
|
1396
|
+
get(macroId: string): Promise<Macro>;
|
|
1397
|
+
/**
|
|
1398
|
+
* Create a new custom macro.
|
|
1399
|
+
*/
|
|
1400
|
+
create(data: MacroCreate): Promise<Macro>;
|
|
1401
|
+
/**
|
|
1402
|
+
* Update an existing custom macro.
|
|
1403
|
+
* Built-in macros cannot be updated.
|
|
1404
|
+
*/
|
|
1405
|
+
update(macroId: string, data: MacroUpdate): Promise<Macro>;
|
|
1406
|
+
/**
|
|
1407
|
+
* Delete a macro.
|
|
1408
|
+
* Fails if the macro is built-in or currently in use.
|
|
1409
|
+
*/
|
|
1410
|
+
delete(macroId: string): Promise<{
|
|
1411
|
+
success: boolean;
|
|
1412
|
+
}>;
|
|
1413
|
+
/**
|
|
1414
|
+
* Test a macro with parameters.
|
|
1415
|
+
*/
|
|
1416
|
+
test(macroId: string, params: Record<string, any>): Promise<MacroTestResult>;
|
|
1417
|
+
}
|
|
1418
|
+
//#endregion
|
|
1419
|
+
//#region src/types/dashboard.d.ts
|
|
1420
|
+
/**
|
|
1421
|
+
* Dashboard statistics and metrics for superadmins.
|
|
1422
|
+
*/
|
|
1423
|
+
interface DashboardStats {
|
|
1424
|
+
/** Total number of accounts in the system */
|
|
1425
|
+
total_accounts: number;
|
|
1426
|
+
/** Total number of users across all accounts */
|
|
1427
|
+
total_users: number;
|
|
1428
|
+
/** Total number of collections defined */
|
|
1429
|
+
total_collections: number;
|
|
1430
|
+
/** Total number of records across all collections */
|
|
1431
|
+
total_records: number;
|
|
1432
|
+
/** Number of new accounts created in the last 7 days */
|
|
1433
|
+
new_accounts_7d: number;
|
|
1434
|
+
/** Number of new users registered in the last 7 days */
|
|
1435
|
+
new_users_7d: number;
|
|
1436
|
+
/** List of the most recent user registrations */
|
|
1437
|
+
recent_registrations: User[];
|
|
1438
|
+
/** Overview of current system health and status */
|
|
1439
|
+
system_health: SystemHealth;
|
|
1440
|
+
/** Number of currently active user sessions */
|
|
1441
|
+
active_sessions: number;
|
|
1442
|
+
/** List of the most recent audit log entries */
|
|
1443
|
+
recent_audit_logs: AuditLog[];
|
|
1444
|
+
}
|
|
1445
|
+
/**
|
|
1446
|
+
* System health information.
|
|
1447
|
+
*/
|
|
1448
|
+
interface SystemHealth {
|
|
1449
|
+
/** overall status of the system */
|
|
1450
|
+
status: 'healthy' | 'degraded' | 'unhealthy' | string;
|
|
1451
|
+
/** System uptime (e.g., "7 days, 4 hours") */
|
|
1452
|
+
uptime?: string;
|
|
1453
|
+
/** Current version of the SnackBase server */
|
|
1454
|
+
version?: string;
|
|
1455
|
+
/** Additional health metrics */
|
|
1456
|
+
[key: string]: any;
|
|
1457
|
+
}
|
|
1458
|
+
//#endregion
|
|
1459
|
+
//#region src/core/dashboard-service.d.ts
|
|
1460
|
+
/**
|
|
1461
|
+
* Service for interacting with the Dashboard API.
|
|
1462
|
+
* Provides statistics and metrics for system monitoring.
|
|
1463
|
+
*/
|
|
1464
|
+
declare class DashboardService {
|
|
1465
|
+
private httpClient;
|
|
1466
|
+
constructor(httpClient: HttpClient);
|
|
1467
|
+
/**
|
|
1468
|
+
* Retrieves dashboard statistics including counts for accounts, users,
|
|
1469
|
+
* collections, and records, as well as recent activity and health metrics.
|
|
1470
|
+
*
|
|
1471
|
+
* @returns {Promise<DashboardStats>} A promise that resolves to dashboard statistics.
|
|
1472
|
+
* @throws {AuthenticationError} If not authenticated.
|
|
1473
|
+
* @throws {AuthorizationError} If the user is not a superadmin.
|
|
1474
|
+
*/
|
|
1475
|
+
getStats(): Promise<DashboardStats>;
|
|
1476
|
+
}
|
|
1477
|
+
//#endregion
|
|
1478
|
+
//#region src/types/admin.d.ts
|
|
1479
|
+
/**
|
|
1480
|
+
* Configuration record representing a system or account level setting.
|
|
1481
|
+
*/
|
|
1482
|
+
interface Configuration {
|
|
1483
|
+
id: string;
|
|
1484
|
+
name: string;
|
|
1485
|
+
category: string;
|
|
1486
|
+
provider_name: string;
|
|
1487
|
+
is_system: boolean;
|
|
1488
|
+
account_id?: string;
|
|
1489
|
+
enabled: boolean;
|
|
1490
|
+
created_at: string;
|
|
1491
|
+
updated_at: string;
|
|
1492
|
+
}
|
|
1493
|
+
/**
|
|
1494
|
+
* Statistics for configurations by category.
|
|
1495
|
+
*/
|
|
1496
|
+
interface ConfigurationStats {
|
|
1497
|
+
system_count: number;
|
|
1498
|
+
account_count: number;
|
|
1499
|
+
by_category: Record<string, {
|
|
1500
|
+
system: number;
|
|
1501
|
+
account: number;
|
|
1502
|
+
}>;
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
* Available provider definition.
|
|
1506
|
+
*/
|
|
1507
|
+
interface ProviderDefinition {
|
|
1508
|
+
name: string;
|
|
1509
|
+
display_name: string;
|
|
1510
|
+
category: string;
|
|
1511
|
+
description?: string;
|
|
1512
|
+
is_built_in: boolean;
|
|
1513
|
+
icon?: string;
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* Connection test result.
|
|
1517
|
+
*/
|
|
1518
|
+
interface ConnectionTestResult {
|
|
1519
|
+
success: boolean;
|
|
1520
|
+
message: string;
|
|
1521
|
+
details?: Record<string, any>;
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Request data for creating a configuration.
|
|
1525
|
+
*/
|
|
1526
|
+
interface ConfigurationCreate {
|
|
1527
|
+
name: string;
|
|
1528
|
+
category: string;
|
|
1529
|
+
provider_name: string;
|
|
1530
|
+
values: Record<string, any>;
|
|
1531
|
+
is_system?: boolean;
|
|
1532
|
+
account_id?: string;
|
|
1533
|
+
enabled?: boolean;
|
|
1534
|
+
}
|
|
1535
|
+
/**
|
|
1536
|
+
* Recent configuration summary.
|
|
1537
|
+
*/
|
|
1538
|
+
interface RecentConfiguration extends Configuration {
|
|
1539
|
+
last_modified_by?: {
|
|
1540
|
+
id: string;
|
|
1541
|
+
email: string;
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1544
|
+
//#endregion
|
|
1545
|
+
//#region src/core/admin-service.d.ts
|
|
1546
|
+
/**
|
|
1547
|
+
* Service for superadmin operations and system configuration management.
|
|
1548
|
+
*/
|
|
1549
|
+
declare class AdminService {
|
|
1550
|
+
private http;
|
|
1551
|
+
constructor(http: HttpClient);
|
|
1552
|
+
/**
|
|
1553
|
+
* Returns configuration statistics by category.
|
|
1554
|
+
*/
|
|
1555
|
+
getConfigurationStats(): Promise<ConfigurationStats>;
|
|
1556
|
+
/**
|
|
1557
|
+
* Returns recently modified configurations.
|
|
1558
|
+
* @param limit Number of configurations to return
|
|
1559
|
+
*/
|
|
1560
|
+
getRecentConfigurations(limit?: number): Promise<RecentConfiguration[]>;
|
|
1561
|
+
/**
|
|
1562
|
+
* Returns all system-level configurations.
|
|
1563
|
+
* @param category Optional category filter
|
|
1564
|
+
*/
|
|
1565
|
+
listSystemConfigurations(category?: string): Promise<Configuration[]>;
|
|
1566
|
+
/**
|
|
1567
|
+
* Returns configurations for specific account.
|
|
1568
|
+
* @param accountId Account ID
|
|
1569
|
+
* @param category Optional category filter
|
|
1570
|
+
*/
|
|
1571
|
+
listAccountConfigurations(accountId: string, category?: string): Promise<Configuration[]>;
|
|
1572
|
+
/**
|
|
1573
|
+
* Returns decrypted configuration values with secrets masked.
|
|
1574
|
+
* @param configId Configuration ID
|
|
1575
|
+
*/
|
|
1576
|
+
getConfigurationValues(configId: string): Promise<Record<string, any>>;
|
|
1577
|
+
/**
|
|
1578
|
+
* Updates configuration values.
|
|
1579
|
+
* @param configId Configuration ID
|
|
1580
|
+
* @param values New configuration values
|
|
1581
|
+
*/
|
|
1582
|
+
updateConfigurationValues(configId: string, values: Record<string, any>): Promise<Record<string, any>>;
|
|
1583
|
+
/**
|
|
1584
|
+
* Enables or disables configuration.
|
|
1585
|
+
* @param configId Configuration ID
|
|
1586
|
+
* @param enabled Enabled status
|
|
1587
|
+
*/
|
|
1588
|
+
updateConfigurationStatus(configId: string, enabled: boolean): Promise<Configuration>;
|
|
1589
|
+
/**
|
|
1590
|
+
* Creates new configuration record.
|
|
1591
|
+
* @param data Configuration data
|
|
1592
|
+
*/
|
|
1593
|
+
createConfiguration(data: ConfigurationCreate): Promise<Configuration>;
|
|
1594
|
+
/**
|
|
1595
|
+
* Deletes configuration.
|
|
1596
|
+
* @param configId Configuration ID
|
|
1597
|
+
*/
|
|
1598
|
+
deleteConfiguration(configId: string): Promise<{
|
|
1599
|
+
success: boolean;
|
|
1600
|
+
}>;
|
|
1601
|
+
/**
|
|
1602
|
+
* Lists all available provider definitions.
|
|
1603
|
+
* @param category Optional category filter
|
|
1604
|
+
*/
|
|
1605
|
+
listProviders(category?: string): Promise<ProviderDefinition[]>;
|
|
1606
|
+
/**
|
|
1607
|
+
* Returns JSON schema for provider configuration.
|
|
1608
|
+
* @param category Provider category
|
|
1609
|
+
* @param providerName Provider name
|
|
1610
|
+
*/
|
|
1611
|
+
getProviderSchema(category: string, providerName: string): Promise<Record<string, any>>;
|
|
1612
|
+
/**
|
|
1613
|
+
* Tests provider connection.
|
|
1614
|
+
* @param category Provider category
|
|
1615
|
+
* @param providerName Provider name
|
|
1616
|
+
* @param config Configuration values to test
|
|
1617
|
+
*/
|
|
1618
|
+
testConnection(category: string, providerName: string, config: Record<string, any>): Promise<ConnectionTestResult>;
|
|
1619
|
+
}
|
|
1620
|
+
//#endregion
|
|
1621
|
+
//#region src/types/email-template.d.ts
|
|
1622
|
+
/**
|
|
1623
|
+
* Email template type.
|
|
1624
|
+
*/
|
|
1625
|
+
type EmailTemplateType = 'verification' | 'reset_password' | 'invitation' | string;
|
|
1626
|
+
/**
|
|
1627
|
+
* Email template interface.
|
|
1628
|
+
*/
|
|
1629
|
+
interface EmailTemplate {
|
|
1630
|
+
id: string;
|
|
1631
|
+
template_type: EmailTemplateType;
|
|
1632
|
+
locale: string;
|
|
1633
|
+
subject: string;
|
|
1634
|
+
html_body: string;
|
|
1635
|
+
text_body: string;
|
|
1636
|
+
enabled: boolean;
|
|
1637
|
+
account_id?: string;
|
|
1638
|
+
created_at: string;
|
|
1639
|
+
updated_at: string;
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Data for updating an email template.
|
|
1643
|
+
*/
|
|
1644
|
+
interface EmailTemplateUpdate {
|
|
1645
|
+
subject?: string;
|
|
1646
|
+
html_body?: string;
|
|
1647
|
+
text_body?: string;
|
|
1648
|
+
enabled?: boolean;
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
* Filters for listing email templates.
|
|
1652
|
+
*/
|
|
1653
|
+
interface EmailTemplateFilters {
|
|
1654
|
+
[key: string]: string | number | boolean | undefined;
|
|
1655
|
+
template_type?: EmailTemplateType;
|
|
1656
|
+
locale?: string;
|
|
1657
|
+
account_id?: string;
|
|
1658
|
+
enabled?: boolean;
|
|
1659
|
+
}
|
|
1660
|
+
/**
|
|
1661
|
+
* Request for rendering an email template.
|
|
1662
|
+
*/
|
|
1663
|
+
interface EmailTemplateRenderRequest {
|
|
1664
|
+
template_type: EmailTemplateType;
|
|
1665
|
+
locale: string;
|
|
1666
|
+
variables: Record<string, any>;
|
|
1667
|
+
subject_override?: string;
|
|
1668
|
+
html_body_override?: string;
|
|
1669
|
+
text_body_override?: string;
|
|
1670
|
+
}
|
|
1671
|
+
/**
|
|
1672
|
+
* Response from rendering an email template.
|
|
1673
|
+
*/
|
|
1674
|
+
interface EmailTemplateRenderResponse {
|
|
1675
|
+
subject: string;
|
|
1676
|
+
html_body: string;
|
|
1677
|
+
text_body: string;
|
|
1678
|
+
}
|
|
1679
|
+
/**
|
|
1680
|
+
* Email log interface.
|
|
1681
|
+
*/
|
|
1682
|
+
interface EmailLog {
|
|
1683
|
+
id: string;
|
|
1684
|
+
account_id: string;
|
|
1685
|
+
template_type: EmailTemplateType;
|
|
1686
|
+
recipient: string;
|
|
1687
|
+
subject: string;
|
|
1688
|
+
status: 'sent' | 'failed' | 'pending';
|
|
1689
|
+
provider: string;
|
|
1690
|
+
error?: string;
|
|
1691
|
+
sent_at: string;
|
|
1692
|
+
metadata?: Record<string, any>;
|
|
1693
|
+
}
|
|
1694
|
+
/**
|
|
1695
|
+
* Filters for listing email logs.
|
|
1696
|
+
*/
|
|
1697
|
+
interface EmailLogFilters {
|
|
1698
|
+
[key: string]: string | number | boolean | undefined;
|
|
1699
|
+
status?: string;
|
|
1700
|
+
template_type?: EmailTemplateType;
|
|
1701
|
+
start_date?: string;
|
|
1702
|
+
end_date?: string;
|
|
1703
|
+
page?: number;
|
|
1704
|
+
limit?: number;
|
|
1705
|
+
}
|
|
1706
|
+
/**
|
|
1707
|
+
* Paginated response for email logs.
|
|
1708
|
+
*/
|
|
1709
|
+
interface EmailLogListResponse {
|
|
1710
|
+
data: EmailLog[];
|
|
1711
|
+
total: number;
|
|
1712
|
+
page: number;
|
|
1713
|
+
limit: number;
|
|
1714
|
+
last_page: number;
|
|
1715
|
+
}
|
|
1716
|
+
//#endregion
|
|
1717
|
+
//#region src/core/email-template-service.d.ts
|
|
1718
|
+
/**
|
|
1719
|
+
* Service for managing email templates and logs.
|
|
1720
|
+
*/
|
|
1721
|
+
declare class EmailTemplateService {
|
|
1722
|
+
private http;
|
|
1723
|
+
constructor(http: HttpClient);
|
|
1724
|
+
/**
|
|
1725
|
+
* Returns a list of email templates.
|
|
1726
|
+
* @param filters Optional filters for listing templates
|
|
1727
|
+
*/
|
|
1728
|
+
list(filters?: EmailTemplateFilters): Promise<EmailTemplate[]>;
|
|
1729
|
+
/**
|
|
1730
|
+
* Returns email template details.
|
|
1731
|
+
* @param templateId Template ID
|
|
1732
|
+
*/
|
|
1733
|
+
get(templateId: string): Promise<EmailTemplate>;
|
|
1734
|
+
/**
|
|
1735
|
+
* Updates an email template.
|
|
1736
|
+
* @param templateId Template ID
|
|
1737
|
+
* @param data Update data
|
|
1738
|
+
*/
|
|
1739
|
+
update(templateId: string, data: EmailTemplateUpdate): Promise<EmailTemplate>;
|
|
1740
|
+
/**
|
|
1741
|
+
* Renders an email template with provided variables.
|
|
1742
|
+
* @param request Render request data
|
|
1743
|
+
*/
|
|
1744
|
+
render(request: EmailTemplateRenderRequest): Promise<EmailTemplateRenderResponse>;
|
|
1745
|
+
/**
|
|
1746
|
+
* Sends a test email using the specified template.
|
|
1747
|
+
* @param templateId Template ID
|
|
1748
|
+
* @param recipientEmail Recipient email address
|
|
1749
|
+
* @param variables Template variables
|
|
1750
|
+
* @param provider Optional provider override
|
|
1751
|
+
*/
|
|
1752
|
+
sendTest(templateId: string, recipientEmail: string, variables?: Record<string, any>, provider?: string): Promise<{
|
|
1753
|
+
success: boolean;
|
|
1754
|
+
}>;
|
|
1755
|
+
/**
|
|
1756
|
+
* Returns a paginated list of email logs.
|
|
1757
|
+
* @param filters Optional filters for listing logs
|
|
1758
|
+
*/
|
|
1759
|
+
listLogs(filters?: EmailLogFilters): Promise<EmailLogListResponse>;
|
|
1760
|
+
/**
|
|
1761
|
+
* Returns single email log details.
|
|
1762
|
+
* @param logId Log ID
|
|
1763
|
+
*/
|
|
1764
|
+
getLog(logId: string): Promise<EmailLog>;
|
|
1765
|
+
}
|
|
1766
|
+
//#endregion
|
|
1767
|
+
//#region src/types/file.d.ts
|
|
1768
|
+
/**
|
|
1769
|
+
* Metadata for a file.
|
|
1770
|
+
*/
|
|
1771
|
+
interface FileMetadata {
|
|
1772
|
+
/**
|
|
1773
|
+
* Safe filename.
|
|
1774
|
+
*/
|
|
1775
|
+
filename: string;
|
|
1776
|
+
/**
|
|
1777
|
+
* MIME type of the file.
|
|
1778
|
+
*/
|
|
1779
|
+
contentType: string;
|
|
1780
|
+
/**
|
|
1781
|
+
* File size in bytes.
|
|
1782
|
+
*/
|
|
1783
|
+
size: number;
|
|
1784
|
+
/**
|
|
1785
|
+
* Server path to the file.
|
|
1786
|
+
*/
|
|
1787
|
+
path: string;
|
|
1788
|
+
/**
|
|
1789
|
+
* Upload timestamp.
|
|
1790
|
+
*/
|
|
1791
|
+
created_at: string;
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* Options for file upload.
|
|
1795
|
+
*/
|
|
1796
|
+
interface FileUploadOptions {
|
|
1797
|
+
/**
|
|
1798
|
+
* Custom filename for the upload.
|
|
1799
|
+
*/
|
|
1800
|
+
filename?: string;
|
|
1801
|
+
/**
|
|
1802
|
+
* Custom content type for the upload.
|
|
1803
|
+
*/
|
|
1804
|
+
contentType?: string;
|
|
1805
|
+
}
|
|
1806
|
+
//#endregion
|
|
1807
|
+
//#region src/core/file-service.d.ts
|
|
1808
|
+
/**
|
|
1809
|
+
* Service for working with files (upload, download, delete).
|
|
1810
|
+
*/
|
|
1811
|
+
declare class FileService {
|
|
1812
|
+
private http;
|
|
1813
|
+
private getBaseUrl;
|
|
1814
|
+
private getToken;
|
|
1815
|
+
constructor(http: HttpClient, getBaseUrl: () => string, getToken: () => string | null);
|
|
1816
|
+
/**
|
|
1817
|
+
* Upload a file to the server.
|
|
1818
|
+
* @param file The file or blob to upload
|
|
1819
|
+
* @param options Optional upload options (filename, contentType)
|
|
1820
|
+
*/
|
|
1821
|
+
upload(file: File | Blob, options?: FileUploadOptions): Promise<FileMetadata>;
|
|
1822
|
+
/**
|
|
1823
|
+
* Get the download URL for a file.
|
|
1824
|
+
* @param path The server path to the file
|
|
1825
|
+
*/
|
|
1826
|
+
getDownloadUrl(path: string): string;
|
|
1827
|
+
/**
|
|
1828
|
+
* Delete a file from the server.
|
|
1829
|
+
* @param path The server path to the file
|
|
1830
|
+
*/
|
|
1831
|
+
delete(path: string): Promise<{
|
|
1832
|
+
success: boolean;
|
|
1833
|
+
}>;
|
|
1834
|
+
}
|
|
1835
|
+
//#endregion
|
|
1836
|
+
//#region src/types/realtime.d.ts
|
|
1837
|
+
type RealTimeState = 'disconnected' | 'connecting' | 'connected' | 'error';
|
|
1838
|
+
type RealTimeEvent = 'connecting' | 'connected' | 'disconnected' | 'error' | 'message';
|
|
1839
|
+
type WebSocketAction = 'subscribe' | 'unsubscribe' | 'ping';
|
|
1840
|
+
interface WebSocketMessage {
|
|
1841
|
+
action: WebSocketAction;
|
|
1842
|
+
collection?: string;
|
|
1843
|
+
operations?: string[];
|
|
1844
|
+
}
|
|
1845
|
+
interface ServerMessage {
|
|
1846
|
+
type: string | 'heartbeat' | 'pong' | 'subscribed' | 'unsubscribed';
|
|
1847
|
+
timestamp: string;
|
|
1848
|
+
data?: any;
|
|
1849
|
+
collection?: string;
|
|
1850
|
+
}
|
|
1851
|
+
/**
|
|
1852
|
+
* Real-time event object structure
|
|
1853
|
+
* @template T - Type of the event data
|
|
1854
|
+
*/
|
|
1855
|
+
interface RealtimeEvent<T = any> {
|
|
1856
|
+
/** Event type in format: {collection}.{operation} (e.g., "posts.create") */
|
|
1857
|
+
type: string;
|
|
1858
|
+
/** ISO 8601 timestamp */
|
|
1859
|
+
timestamp: string;
|
|
1860
|
+
/** Event data - full record for create/update, ID only for delete */
|
|
1861
|
+
data: T;
|
|
1862
|
+
}
|
|
1863
|
+
interface RealTimeConfig {
|
|
1864
|
+
maxReconnectionAttempts?: number;
|
|
1865
|
+
heartbeatInterval?: number;
|
|
1866
|
+
reconnectionDelay?: (attempt: number) => number;
|
|
1867
|
+
}
|
|
1868
|
+
type RealTimeEventHandler = (data?: any) => void;
|
|
1869
|
+
/**
|
|
1870
|
+
* Real-time event handlers
|
|
1871
|
+
*
|
|
1872
|
+
* Event type formats:
|
|
1873
|
+
* - Connection events: 'connecting', 'connected', 'disconnected', 'error'
|
|
1874
|
+
* - Message event: 'message' - receives full ServerMessage
|
|
1875
|
+
* - Specific events: '{collection}.{operation}' (e.g., 'posts.create')
|
|
1876
|
+
* - Collection wildcard: '{collection}.*' (e.g., 'posts.*') - all events for a collection
|
|
1877
|
+
* - Global wildcard: '*' - all events
|
|
1878
|
+
*/
|
|
1879
|
+
interface RealTimeEvents {
|
|
1880
|
+
connecting: () => void;
|
|
1881
|
+
connected: () => void;
|
|
1882
|
+
disconnected: () => void;
|
|
1883
|
+
error: (error: Error) => void;
|
|
1884
|
+
auth_error: (error: Error) => void;
|
|
1885
|
+
message: (data: ServerMessage) => void;
|
|
1886
|
+
[key: string]: RealTimeEventHandler;
|
|
1887
|
+
}
|
|
1888
|
+
//#endregion
|
|
1889
|
+
//#region src/core/realtime-service.d.ts
|
|
1890
|
+
interface RealTimeOptions {
|
|
1891
|
+
baseUrl: string;
|
|
1892
|
+
getToken: () => string | null;
|
|
1893
|
+
authManager?: AuthManager;
|
|
1894
|
+
maxRetries?: number;
|
|
1895
|
+
reconnectionDelay?: number;
|
|
1896
|
+
logger?: Logger;
|
|
1897
|
+
}
|
|
1898
|
+
declare class RealTimeService {
|
|
1899
|
+
private options;
|
|
1900
|
+
private state;
|
|
1901
|
+
private socket;
|
|
1902
|
+
private sse;
|
|
1903
|
+
private listeners;
|
|
1904
|
+
private retryCount;
|
|
1905
|
+
private reconnectTimer;
|
|
1906
|
+
private heartbeatTimer;
|
|
1907
|
+
private subscriptions;
|
|
1908
|
+
private subscriptionRequests;
|
|
1909
|
+
private pendingSubscriptions;
|
|
1910
|
+
private authUnsubscribe?;
|
|
1911
|
+
private isReconnectingForAuth;
|
|
1912
|
+
constructor(options: RealTimeOptions);
|
|
1913
|
+
connect(): Promise<void>;
|
|
1914
|
+
disconnect(): void;
|
|
1915
|
+
getState(): RealTimeState;
|
|
1916
|
+
on<K extends keyof RealTimeEvents>(event: K, handler: RealTimeEvents[K]): () => void;
|
|
1917
|
+
off<K extends keyof RealTimeEvents>(event: K, handler: RealTimeEvents[K]): void;
|
|
1918
|
+
subscribe(collection: string, operations?: string[]): Promise<void>;
|
|
1919
|
+
unsubscribe(collection: string): Promise<void>;
|
|
1920
|
+
getSubscriptions(): string[];
|
|
1921
|
+
private doConnect;
|
|
1922
|
+
private connectWebSocket;
|
|
1923
|
+
private connectSSE;
|
|
1924
|
+
private handleMessage;
|
|
1925
|
+
private handleReconnect;
|
|
1926
|
+
private handleError;
|
|
1927
|
+
private setState;
|
|
1928
|
+
private emit;
|
|
1929
|
+
private send;
|
|
1930
|
+
private startHeartbeat;
|
|
1931
|
+
private resubscribe;
|
|
1932
|
+
private clearTimers;
|
|
1933
|
+
private closeConnections;
|
|
1934
|
+
/**
|
|
1935
|
+
* Handle token refresh by reconnecting with new token
|
|
1936
|
+
*/
|
|
1937
|
+
private handleTokenRefresh;
|
|
1938
|
+
}
|
|
1939
|
+
//#endregion
|
|
1940
|
+
//#region src/types/migration.d.ts
|
|
1941
|
+
/**
|
|
1942
|
+
* Migration-related type definitions.
|
|
1943
|
+
*/
|
|
1944
|
+
/**
|
|
1945
|
+
* Represents a single migration revision.
|
|
1946
|
+
*/
|
|
1947
|
+
interface MigrationRevision {
|
|
1948
|
+
/** The revision identifier (e.g., "001_abc123") */
|
|
1949
|
+
revision: string;
|
|
1950
|
+
/** Human-readable description of the migration */
|
|
1951
|
+
description: string;
|
|
1952
|
+
/** Whether this revision has been applied to the database */
|
|
1953
|
+
isApplied: boolean;
|
|
1954
|
+
/** Whether this is a dynamic collection migration */
|
|
1955
|
+
isDynamic: boolean;
|
|
1956
|
+
}
|
|
1957
|
+
/**
|
|
1958
|
+
* Response from listing all migrations.
|
|
1959
|
+
*/
|
|
1960
|
+
interface MigrationListResponse {
|
|
1961
|
+
/** All available migration revisions */
|
|
1962
|
+
revisions: MigrationRevision[];
|
|
1963
|
+
/** Total number of revisions */
|
|
1964
|
+
total: number;
|
|
1965
|
+
/** The currently applied revision (if any) */
|
|
1966
|
+
currentRevision: string | null;
|
|
1967
|
+
}
|
|
1968
|
+
/**
|
|
1969
|
+
* Response from getting the current migration.
|
|
1970
|
+
*/
|
|
1971
|
+
interface CurrentRevisionResponse {
|
|
1972
|
+
/** The current revision identifier */
|
|
1973
|
+
revision: string;
|
|
1974
|
+
/** Human-readable description of the migration */
|
|
1975
|
+
description: string;
|
|
1976
|
+
/** Timestamp when this revision was applied */
|
|
1977
|
+
appliedAt: string;
|
|
1978
|
+
/** Whether this is a dynamic collection migration */
|
|
1979
|
+
isDynamic: boolean;
|
|
1980
|
+
}
|
|
1981
|
+
/**
|
|
1982
|
+
* A single item in the migration history.
|
|
1983
|
+
*/
|
|
1984
|
+
interface MigrationHistoryItem {
|
|
1985
|
+
/** The revision identifier */
|
|
1986
|
+
revision: string;
|
|
1987
|
+
/** Human-readable description of the migration */
|
|
1988
|
+
description: string;
|
|
1989
|
+
/** Whether this is a dynamic collection migration */
|
|
1990
|
+
isDynamic: boolean;
|
|
1991
|
+
/** Timestamp when this revision was applied */
|
|
1992
|
+
createdAt: string;
|
|
1993
|
+
}
|
|
1994
|
+
/**
|
|
1995
|
+
* Response from getting migration history.
|
|
1996
|
+
*/
|
|
1997
|
+
interface MigrationHistoryResponse {
|
|
1998
|
+
/** Applied migrations in chronological order */
|
|
1999
|
+
history: MigrationHistoryItem[];
|
|
2000
|
+
/** Total number of applied migrations */
|
|
2001
|
+
total: number;
|
|
2002
|
+
}
|
|
2003
|
+
//#endregion
|
|
2004
|
+
//#region src/core/migration-service.d.ts
|
|
2005
|
+
/**
|
|
2006
|
+
* Service for viewing migration status and history.
|
|
2007
|
+
* Requires superadmin authentication.
|
|
2008
|
+
*/
|
|
2009
|
+
declare class MigrationService {
|
|
2010
|
+
private http;
|
|
2011
|
+
constructor(http: HttpClient);
|
|
2012
|
+
/**
|
|
2013
|
+
* List all Alembic migration revisions.
|
|
2014
|
+
* Returns all migrations with their application status.
|
|
2015
|
+
*/
|
|
2016
|
+
list(): Promise<MigrationListResponse>;
|
|
2017
|
+
/**
|
|
2018
|
+
* Get the current database revision.
|
|
2019
|
+
* Returns the currently applied migration.
|
|
2020
|
+
*/
|
|
2021
|
+
getCurrent(): Promise<CurrentRevisionResponse | null>;
|
|
2022
|
+
/**
|
|
2023
|
+
* Get full migration history.
|
|
2024
|
+
* Returns all applied migrations in chronological order.
|
|
2025
|
+
*/
|
|
2026
|
+
getHistory(): Promise<MigrationHistoryResponse>;
|
|
2027
|
+
}
|
|
2028
|
+
//#endregion
|
|
2029
|
+
//#region src/core/client.d.ts
|
|
2030
|
+
/**
|
|
2031
|
+
* Main SDK client for interacting with SnackBase API.
|
|
2032
|
+
*/
|
|
2033
|
+
declare class SnackBaseClient {
|
|
2034
|
+
private config;
|
|
2035
|
+
private http;
|
|
2036
|
+
private logger;
|
|
2037
|
+
private authManager;
|
|
2038
|
+
private authService;
|
|
2039
|
+
private accountService;
|
|
2040
|
+
private userService;
|
|
2041
|
+
private collectionService;
|
|
2042
|
+
private recordService;
|
|
2043
|
+
private groupsService;
|
|
2044
|
+
private invitationService;
|
|
2045
|
+
private apiKeyService;
|
|
2046
|
+
private auditLogService;
|
|
2047
|
+
private roleService;
|
|
2048
|
+
private collectionRuleService;
|
|
2049
|
+
private macroService;
|
|
2050
|
+
private dashboardService;
|
|
2051
|
+
private adminService;
|
|
2052
|
+
private emailTemplateService;
|
|
2053
|
+
private fileService;
|
|
2054
|
+
private realtimeService;
|
|
2055
|
+
private migrationService;
|
|
2056
|
+
/**
|
|
2057
|
+
* Initialize a new SnackBaseClient instance.
|
|
2058
|
+
* @param config Configuration options
|
|
2059
|
+
*/
|
|
2060
|
+
constructor(config: SnackBaseConfig);
|
|
2061
|
+
/**
|
|
2062
|
+
* Returns the current client configuration.
|
|
2063
|
+
*/
|
|
2064
|
+
getConfig(): Required<SnackBaseConfig>;
|
|
2065
|
+
/**
|
|
2066
|
+
* Internal helper to access the HTTP client.
|
|
2067
|
+
* @internal
|
|
2068
|
+
*/
|
|
2069
|
+
get httpClient(): HttpClient;
|
|
2070
|
+
/**
|
|
2071
|
+
* Sets up the default interceptors for the HTTP client.
|
|
2072
|
+
*/
|
|
2073
|
+
private setupInterceptors;
|
|
2074
|
+
/**
|
|
2075
|
+
* Returns the current authenticated user.
|
|
2076
|
+
*/
|
|
2077
|
+
get user(): User | null;
|
|
2078
|
+
/**
|
|
2079
|
+
* Returns the current account.
|
|
2080
|
+
*/
|
|
2081
|
+
get account(): Account | null;
|
|
2082
|
+
/**
|
|
2083
|
+
* Returns whether the client is currently authenticated.
|
|
2084
|
+
*/
|
|
2085
|
+
get isAuthenticated(): boolean;
|
|
2086
|
+
/**
|
|
2087
|
+
* Access to authentication methods.
|
|
2088
|
+
*/
|
|
2089
|
+
get auth(): AuthService;
|
|
2090
|
+
/**
|
|
2091
|
+
* Access to account management methods.
|
|
2092
|
+
*/
|
|
2093
|
+
get accounts(): AccountService;
|
|
2094
|
+
/**
|
|
2095
|
+
* Access to user management methods.
|
|
2096
|
+
*/
|
|
2097
|
+
get users(): UserService;
|
|
2098
|
+
/**
|
|
2099
|
+
* Access to collection management methods.
|
|
2100
|
+
*/
|
|
2101
|
+
get collections(): CollectionService;
|
|
2102
|
+
/**
|
|
2103
|
+
* Access to record management methods (CRUD on dynamic collections).
|
|
2104
|
+
*/
|
|
2105
|
+
get records(): RecordService;
|
|
2106
|
+
/**
|
|
2107
|
+
* Access to group management methods.
|
|
2108
|
+
*/
|
|
2109
|
+
get groups(): GroupsService;
|
|
2110
|
+
/**
|
|
2111
|
+
* Access to invitation management methods.
|
|
2112
|
+
*/
|
|
2113
|
+
get invitations(): InvitationService;
|
|
2114
|
+
/**
|
|
2115
|
+
* Access to API key management methods.
|
|
2116
|
+
*/
|
|
2117
|
+
get apiKeys(): ApiKeyService;
|
|
2118
|
+
/**
|
|
2119
|
+
* Access to audit log management methods.
|
|
2120
|
+
*/
|
|
2121
|
+
get auditLogs(): AuditLogService;
|
|
2122
|
+
/**
|
|
2123
|
+
* Access to role management methods.
|
|
2124
|
+
*/
|
|
2125
|
+
get roles(): RoleService;
|
|
2126
|
+
/**
|
|
2127
|
+
* Access to collection rule management methods.
|
|
2128
|
+
*/
|
|
2129
|
+
get collectionRules(): CollectionRuleService;
|
|
2130
|
+
/**
|
|
2131
|
+
* Access to macro management methods.
|
|
2132
|
+
*/
|
|
2133
|
+
get macros(): MacroService;
|
|
2134
|
+
/**
|
|
2135
|
+
* Access to dashboard statistics and monitoring.
|
|
2136
|
+
*/
|
|
2137
|
+
get dashboard(): DashboardService;
|
|
2138
|
+
/**
|
|
2139
|
+
* Access to system administration and configuration methods.
|
|
2140
|
+
*/
|
|
2141
|
+
get admin(): AdminService;
|
|
2142
|
+
/**
|
|
2143
|
+
* Access to email template management methods.
|
|
2144
|
+
*/
|
|
2145
|
+
get emailTemplates(): EmailTemplateService;
|
|
2146
|
+
/**
|
|
2147
|
+
* Access to file management methods.
|
|
2148
|
+
*/
|
|
2149
|
+
get files(): FileService;
|
|
2150
|
+
/**
|
|
2151
|
+
* Access to real-time features and subscriptions.
|
|
2152
|
+
*/
|
|
2153
|
+
get realtime(): RealTimeService;
|
|
2154
|
+
/**
|
|
2155
|
+
* Access to migration status and history.
|
|
2156
|
+
*/
|
|
2157
|
+
get migrations(): MigrationService;
|
|
2158
|
+
/**
|
|
2159
|
+
* Subscribe to authentication events.
|
|
2160
|
+
* @param event Event name
|
|
2161
|
+
* @param listener Callback function
|
|
2162
|
+
*/
|
|
2163
|
+
on<K extends keyof AuthEvents>(event: K, listener: AuthEvents[K]): () => void;
|
|
2164
|
+
/**
|
|
2165
|
+
* Authenticate a user with email and password.
|
|
2166
|
+
*/
|
|
2167
|
+
login(credentials: LoginCredentials): Promise<AuthResponse>;
|
|
2168
|
+
/**
|
|
2169
|
+
* Log out the current user.
|
|
2170
|
+
*/
|
|
2171
|
+
logout(): Promise<{
|
|
2172
|
+
success: boolean;
|
|
2173
|
+
}>;
|
|
2174
|
+
/**
|
|
2175
|
+
* Register a new user and account.
|
|
2176
|
+
*/
|
|
2177
|
+
register(data: RegisterData): Promise<AuthResponse>;
|
|
2178
|
+
/**
|
|
2179
|
+
* Refresh the access token using the refresh token.
|
|
2180
|
+
*/
|
|
2181
|
+
refreshToken(): Promise<AuthResponse>;
|
|
2182
|
+
/**
|
|
2183
|
+
* Get the current authenticated user profile.
|
|
2184
|
+
*/
|
|
2185
|
+
getCurrentUser(): Promise<AuthResponse>;
|
|
2186
|
+
/**
|
|
2187
|
+
* Initiate password reset flow.
|
|
2188
|
+
*/
|
|
2189
|
+
forgotPassword(data: PasswordResetRequest): Promise<{
|
|
2190
|
+
message: string;
|
|
2191
|
+
}>;
|
|
2192
|
+
/**
|
|
2193
|
+
* Reset password using a token.
|
|
2194
|
+
*/
|
|
2195
|
+
resetPassword(data: PasswordResetConfirm): Promise<{
|
|
2196
|
+
message: string;
|
|
2197
|
+
}>;
|
|
2198
|
+
/**
|
|
2199
|
+
* Verify email using a token.
|
|
2200
|
+
*/
|
|
2201
|
+
verifyEmail(token: string): Promise<{
|
|
2202
|
+
message: string;
|
|
2203
|
+
}>;
|
|
2204
|
+
/**
|
|
2205
|
+
* Resend the verification email to the current user.
|
|
2206
|
+
*/
|
|
2207
|
+
resendVerificationEmail(): Promise<{
|
|
2208
|
+
message: string;
|
|
2209
|
+
}>;
|
|
2210
|
+
/**
|
|
2211
|
+
* Generate SAML SSO authorization URL.
|
|
2212
|
+
*/
|
|
2213
|
+
getSAMLUrl(provider: SAMLProvider, account: string, relayState?: string): Promise<SAMLUrlResponse>;
|
|
2214
|
+
/**
|
|
2215
|
+
* Handle SAML callback.
|
|
2216
|
+
*/
|
|
2217
|
+
handleSAMLCallback(params: SAMLCallbackParams): Promise<SAMLResponse>;
|
|
2218
|
+
/**
|
|
2219
|
+
* Get SAML metadata.
|
|
2220
|
+
*/
|
|
2221
|
+
getSAMLMetadata(provider: SAMLProvider, account: string): Promise<string>;
|
|
2222
|
+
/**
|
|
2223
|
+
* Internal access to AuthManager.
|
|
2224
|
+
* @internal
|
|
2225
|
+
*/
|
|
2226
|
+
get internalAuthManager(): AuthManager;
|
|
2227
|
+
/**
|
|
2228
|
+
* Validates the configuration object.
|
|
2229
|
+
* Throws descriptive errors for invalid options.
|
|
2230
|
+
*/
|
|
2231
|
+
private validateConfig;
|
|
2232
|
+
}
|
|
2233
|
+
//#endregion
|
|
2234
|
+
//#region src/types/utils.d.ts
|
|
2235
|
+
/**
|
|
2236
|
+
* Generic record type with system fields.
|
|
2237
|
+
* Use this to define your record interfaces.
|
|
2238
|
+
*
|
|
2239
|
+
* @example
|
|
2240
|
+
* interface Post {
|
|
2241
|
+
* title: string;
|
|
2242
|
+
* content: string;
|
|
2243
|
+
* views: number;
|
|
2244
|
+
* }
|
|
2245
|
+
* type PostRecord = CollectionRecord<Post>;
|
|
2246
|
+
*/
|
|
2247
|
+
type CollectionRecord<T> = T & BaseRecord;
|
|
2248
|
+
/**
|
|
2249
|
+
* Paginated list response type alias.
|
|
2250
|
+
*/
|
|
2251
|
+
type ListResponse<T> = RecordListResponse<T>;
|
|
2252
|
+
/**
|
|
2253
|
+
* Filter object type for a collection.
|
|
2254
|
+
* Allows filtering by fields of T.
|
|
2255
|
+
*
|
|
2256
|
+
* This is a basic typed filter. For complex MongoDB-style queries,
|
|
2257
|
+
* you might need more flexible types.
|
|
2258
|
+
*/
|
|
2259
|
+
type Filter<T> = { [P in keyof T]?: any } & {
|
|
2260
|
+
[key: string]: any;
|
|
2261
|
+
};
|
|
2262
|
+
/**
|
|
2263
|
+
* Helper to map FieldType strings to TypeScript types.
|
|
2264
|
+
*/
|
|
2265
|
+
type FieldTypeToTs<T extends string> = T extends 'text' ? string : T extends 'number' ? number : T extends 'boolean' ? boolean : T extends 'date' ? string : T extends 'datetime' ? string : T extends 'email' ? string : T extends 'url' ? string : T extends 'phone' ? string : T extends 'select' ? string : T extends 'multi_select' ? string[] : T extends 'relation' ? string | string[] : T extends 'json' ? any : any;
|
|
2266
|
+
/**
|
|
2267
|
+
* Infers a record type from a schema definition (array of FieldDefinition).
|
|
2268
|
+
* Note: The schema array must be defined `as const` to work correctly.
|
|
2269
|
+
*
|
|
2270
|
+
* @example
|
|
2271
|
+
* const postSchema = [
|
|
2272
|
+
* { name: 'title', type: 'text' },
|
|
2273
|
+
* { name: 'views', type: 'number' }
|
|
2274
|
+
* ] as const;
|
|
2275
|
+
*
|
|
2276
|
+
* type Post = InferSchema<typeof postSchema>;
|
|
2277
|
+
* // Result: { title: string; views: number }
|
|
2278
|
+
*/
|
|
2279
|
+
type InferSchema<T extends readonly FieldDefinition[]> = { [K in T[number] as K['name']]: FieldTypeToTs<K['type']> | (K['required'] extends true ? never : undefined | null) };
|
|
2280
|
+
//#endregion
|
|
2281
|
+
//#region src/utils/platform.d.ts
|
|
2282
|
+
/**
|
|
2283
|
+
* Detects the platform and returns the recommended storage backend.
|
|
2284
|
+
* - Web: localStorage
|
|
2285
|
+
* - React Native: asyncStorage
|
|
2286
|
+
*/
|
|
2287
|
+
declare function getAutoDetectedStorage(): StorageBackend;
|
|
2288
|
+
//#endregion
|
|
2289
|
+
export { type Account, ApiKey, ApiKeyCreate, AuditLog, AuditLogExportFormat, AuditLogFilters, AuditLogListResponse, AuthEvent, AuthEvents, AuthResponse, AuthState, BaseRecord, Collection, CollectionCreate, CollectionExportData, CollectionExportFieldDefinition, CollectionExportItem, CollectionExportParams, CollectionExportRules, CollectionImportItemResult, CollectionImportRequest, CollectionImportResult, CollectionRecord, CollectionRule, CollectionRuleUpdate, CollectionUpdate, Configuration, ConfigurationCreate, ConfigurationStats, ConnectionTestResult, CurrentRevisionResponse, DEFAULT_CONFIG, DashboardStats, EmailLog, EmailLogFilters, EmailLogListResponse, EmailTemplate, EmailTemplateFilters, EmailTemplateRenderRequest, EmailTemplateRenderResponse, EmailTemplateType, EmailTemplateUpdate, FieldDefinition, FieldType, FieldTypeToTs, FileMetadata, FileUploadOptions, Filter, FilterExpression, FilterOperator, Group, GroupCreate, GroupListParams, GroupListResponse, GroupUpdate, ImportStrategy, InferSchema, Invitation, InvitationCreate, InvitationListParams, ListResponse, LogLevel, LoginCredentials, MigrationHistoryItem, MigrationHistoryResponse, MigrationListResponse, MigrationRevision, OAuthCallbackParams, OAuthProvider, OAuthResponse, OAuthUrlResponse, PasswordResetConfirm, PasswordResetRequest, Permission, ProviderDefinition, QueryBuilder, QueryParams, RealTimeConfig, RealTimeEvent, RealTimeEventHandler, RealTimeEvents, RealTimeState, RealtimeEvent, RecentConfiguration, RecordListParams, RecordListResponse, RegisterData, Role, RoleCreate, RoleListResponse, RoleUpdate, RuleTestResult, RuleValidationParams, RuleValidationResult, SAMLCallbackParams, SAMLProvider, SAMLResponse, SAMLUrlResponse, ServerMessage, type SnackBaseClient as SnackBase, SnackBaseClient, SnackBaseConfig, SortDirection, SortExpression, StorageBackend, SystemHealth, type User, UserCreate, UserListParams, type UserListResponse, UserUpdate, WebSocketAction, WebSocketMessage, getAutoDetectedStorage };
|