@snackbase/sdk 0.1.1 → 0.3.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 +2835 -0
- package/dist/{index-Dr6K4PMl.d.mts → index.d.cts} +367 -38
- package/dist/index.d.mts +2447 -2
- package/dist/index.mjs +357 -56
- package/package.json +33 -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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/types/config.d.ts
|
|
2
|
-
type LogLevel
|
|
2
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
3
3
|
type StorageBackend = 'localStorage' | 'sessionStorage' | 'memory' | 'asyncStorage';
|
|
4
4
|
interface SnackBaseConfig {
|
|
5
5
|
/**
|
|
@@ -14,6 +14,11 @@ interface SnackBaseConfig {
|
|
|
14
14
|
* Optional API key for service authentication
|
|
15
15
|
*/
|
|
16
16
|
apiKey?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Optional override for system account detection
|
|
19
|
+
* (useful for testing/custom deployments)
|
|
20
|
+
*/
|
|
21
|
+
systemAccountId?: string;
|
|
17
22
|
/**
|
|
18
23
|
* Enable automatic token refresh (default: true)
|
|
19
24
|
*/
|
|
@@ -44,7 +49,7 @@ interface SnackBaseConfig {
|
|
|
44
49
|
/**
|
|
45
50
|
* Logging level (default: 'error')
|
|
46
51
|
*/
|
|
47
|
-
logLevel?: LogLevel
|
|
52
|
+
logLevel?: LogLevel;
|
|
48
53
|
/**
|
|
49
54
|
* Callback for 401 authentication errors
|
|
50
55
|
*/
|
|
@@ -73,7 +78,7 @@ interface SnackBaseConfig {
|
|
|
73
78
|
declare const DEFAULT_CONFIG: Partial<SnackBaseConfig>;
|
|
74
79
|
//#endregion
|
|
75
80
|
//#region src/core/logger.d.ts
|
|
76
|
-
declare enum LogLevel {
|
|
81
|
+
declare enum LogLevel$1 {
|
|
77
82
|
NONE = 0,
|
|
78
83
|
ERROR = 1,
|
|
79
84
|
WARN = 2,
|
|
@@ -82,7 +87,7 @@ declare enum LogLevel {
|
|
|
82
87
|
}
|
|
83
88
|
interface LogEntry {
|
|
84
89
|
timestamp: string;
|
|
85
|
-
level: LogLevel;
|
|
90
|
+
level: LogLevel$1;
|
|
86
91
|
message: string;
|
|
87
92
|
data?: any;
|
|
88
93
|
}
|
|
@@ -91,8 +96,8 @@ declare class Logger {
|
|
|
91
96
|
private handlers;
|
|
92
97
|
private logs;
|
|
93
98
|
private maxLogs;
|
|
94
|
-
constructor(level?: LogLevel);
|
|
95
|
-
setLevel(level: LogLevel): void;
|
|
99
|
+
constructor(level?: LogLevel$1);
|
|
100
|
+
setLevel(level: LogLevel$1): void;
|
|
96
101
|
getLogs(): LogEntry[];
|
|
97
102
|
clearLogs(): void;
|
|
98
103
|
private log;
|
|
@@ -153,7 +158,7 @@ declare class HttpClient {
|
|
|
153
158
|
}
|
|
154
159
|
//#endregion
|
|
155
160
|
//#region src/types/account.d.ts
|
|
156
|
-
interface Account
|
|
161
|
+
interface Account {
|
|
157
162
|
id: string;
|
|
158
163
|
slug: string;
|
|
159
164
|
name: string;
|
|
@@ -176,7 +181,7 @@ interface AccountListParams {
|
|
|
176
181
|
[key: string]: string | number | boolean | undefined;
|
|
177
182
|
}
|
|
178
183
|
interface AccountListResponse {
|
|
179
|
-
items: Account
|
|
184
|
+
items: Account[];
|
|
180
185
|
total: number;
|
|
181
186
|
}
|
|
182
187
|
interface AccountUserListParams {
|
|
@@ -186,14 +191,16 @@ interface AccountUserListParams {
|
|
|
186
191
|
}
|
|
187
192
|
//#endregion
|
|
188
193
|
//#region src/types/user.d.ts
|
|
189
|
-
interface User
|
|
194
|
+
interface User {
|
|
190
195
|
id: string;
|
|
191
196
|
email: string;
|
|
192
197
|
role: string;
|
|
198
|
+
account_id: string;
|
|
193
199
|
groups: string[];
|
|
194
200
|
is_active: boolean;
|
|
195
201
|
created_at: string;
|
|
196
202
|
last_login: string | null;
|
|
203
|
+
token_type: TokenType;
|
|
197
204
|
}
|
|
198
205
|
interface UserCreate {
|
|
199
206
|
email: string;
|
|
@@ -218,11 +225,20 @@ interface UserListParams {
|
|
|
218
225
|
[key: string]: string | number | boolean | undefined;
|
|
219
226
|
}
|
|
220
227
|
interface UserListResponse {
|
|
221
|
-
items: User
|
|
228
|
+
items: User[];
|
|
222
229
|
total: number;
|
|
223
230
|
}
|
|
224
231
|
//#endregion
|
|
225
232
|
//#region src/types/auth.d.ts
|
|
233
|
+
/**
|
|
234
|
+
* Token type enum matching backend TokenType
|
|
235
|
+
*/
|
|
236
|
+
declare enum TokenType {
|
|
237
|
+
JWT = "jwt",
|
|
238
|
+
API_KEY = "api_key",
|
|
239
|
+
PERSONAL_TOKEN = "personal_token",
|
|
240
|
+
OAUTH = "oauth"
|
|
241
|
+
}
|
|
226
242
|
interface AuthState {
|
|
227
243
|
user: User | null;
|
|
228
244
|
account: Account | null;
|
|
@@ -230,6 +246,7 @@ interface AuthState {
|
|
|
230
246
|
refreshToken: string | null;
|
|
231
247
|
isAuthenticated: boolean;
|
|
232
248
|
expiresAt: string | null;
|
|
249
|
+
tokenType: TokenType;
|
|
233
250
|
}
|
|
234
251
|
type AuthEvent = 'auth:login' | 'auth:logout' | 'auth:refresh' | 'auth:error';
|
|
235
252
|
interface AuthEvents {
|
|
@@ -246,15 +263,21 @@ interface LoginCredentials {
|
|
|
246
263
|
interface RegisterData {
|
|
247
264
|
email: string;
|
|
248
265
|
password: string;
|
|
249
|
-
|
|
250
|
-
|
|
266
|
+
account_name?: string;
|
|
267
|
+
account_slug?: string;
|
|
251
268
|
}
|
|
252
269
|
interface AuthResponse {
|
|
253
|
-
user
|
|
254
|
-
account
|
|
270
|
+
user?: User;
|
|
271
|
+
account?: Account;
|
|
255
272
|
token?: string;
|
|
273
|
+
refresh_token?: string;
|
|
256
274
|
refreshToken?: string;
|
|
275
|
+
expires_in?: number;
|
|
257
276
|
expiresAt?: string;
|
|
277
|
+
user_id?: string;
|
|
278
|
+
account_id?: string;
|
|
279
|
+
email?: string;
|
|
280
|
+
role?: string;
|
|
258
281
|
}
|
|
259
282
|
interface PasswordResetRequest {
|
|
260
283
|
account?: string;
|
|
@@ -312,11 +335,33 @@ declare class AuthManager {
|
|
|
312
335
|
constructor(options: AuthManagerOptions);
|
|
313
336
|
initialize(): Promise<void>;
|
|
314
337
|
getState(): AuthState;
|
|
315
|
-
get user(): User
|
|
316
|
-
get account(): Account
|
|
338
|
+
get user(): User | null;
|
|
339
|
+
get account(): Account | null;
|
|
317
340
|
get token(): string | null;
|
|
318
341
|
get refreshToken(): string | null;
|
|
319
342
|
get isAuthenticated(): boolean;
|
|
343
|
+
get tokenType(): TokenType;
|
|
344
|
+
/**
|
|
345
|
+
* Update auth state (enhanced to extract token_type)
|
|
346
|
+
*/
|
|
347
|
+
updateState(data: AuthResponse): Promise<void>;
|
|
348
|
+
/**
|
|
349
|
+
* Check if current user is superadmin
|
|
350
|
+
*/
|
|
351
|
+
isSuperadmin(): boolean;
|
|
352
|
+
/**
|
|
353
|
+
* Check if current session uses API key authentication
|
|
354
|
+
*/
|
|
355
|
+
isApiKeySession(): boolean;
|
|
356
|
+
/**
|
|
357
|
+
* Check if current session uses personal token authentication
|
|
358
|
+
*/
|
|
359
|
+
isPersonalTokenSession(): boolean;
|
|
360
|
+
/**
|
|
361
|
+
* Check if current session uses OAuth authentication
|
|
362
|
+
*/
|
|
363
|
+
isOAuthSession(): boolean;
|
|
364
|
+
private calculateExpiry;
|
|
320
365
|
setState(newState: Partial<AuthState>): Promise<void>;
|
|
321
366
|
clear(): Promise<void>;
|
|
322
367
|
on<K extends keyof AuthEvents>(event: K, listener: AuthEvents[K]): () => void;
|
|
@@ -442,15 +487,15 @@ declare class AccountService {
|
|
|
442
487
|
/**
|
|
443
488
|
* Get details for a specific account.
|
|
444
489
|
*/
|
|
445
|
-
get(accountId: string): Promise<Account
|
|
490
|
+
get(accountId: string): Promise<Account>;
|
|
446
491
|
/**
|
|
447
492
|
* Create a new account.
|
|
448
493
|
*/
|
|
449
|
-
create(data: AccountCreate): Promise<Account
|
|
494
|
+
create(data: AccountCreate): Promise<Account>;
|
|
450
495
|
/**
|
|
451
496
|
* Update an existing account.
|
|
452
497
|
*/
|
|
453
|
-
update(accountId: string, data: AccountUpdate): Promise<Account
|
|
498
|
+
update(accountId: string, data: AccountUpdate): Promise<Account>;
|
|
454
499
|
/**
|
|
455
500
|
* Delete an account and all its associated data.
|
|
456
501
|
*/
|
|
@@ -478,15 +523,15 @@ declare class UserService {
|
|
|
478
523
|
/**
|
|
479
524
|
* Get details for a specific user.
|
|
480
525
|
*/
|
|
481
|
-
get(userId: string): Promise<User
|
|
526
|
+
get(userId: string): Promise<User>;
|
|
482
527
|
/**
|
|
483
528
|
* Create a new user in a specific account.
|
|
484
529
|
*/
|
|
485
|
-
create(data: UserCreate): Promise<User
|
|
530
|
+
create(data: UserCreate): Promise<User>;
|
|
486
531
|
/**
|
|
487
532
|
* Update an existing user.
|
|
488
533
|
*/
|
|
489
|
-
update(userId: string, data: UserUpdate): Promise<User
|
|
534
|
+
update(userId: string, data: UserUpdate): Promise<User>;
|
|
490
535
|
/**
|
|
491
536
|
* Soft delete (deactivate) a user.
|
|
492
537
|
*/
|
|
@@ -536,10 +581,107 @@ interface Collection {
|
|
|
536
581
|
interface CollectionCreate {
|
|
537
582
|
name: string;
|
|
538
583
|
fields: FieldDefinition[];
|
|
584
|
+
list_rule?: string | null;
|
|
585
|
+
view_rule?: string | null;
|
|
586
|
+
create_rule?: string | null;
|
|
587
|
+
update_rule?: string | null;
|
|
588
|
+
delete_rule?: string | null;
|
|
539
589
|
}
|
|
540
590
|
interface CollectionUpdate {
|
|
541
591
|
name?: string;
|
|
542
592
|
fields?: FieldDefinition[];
|
|
593
|
+
list_rule?: string | null;
|
|
594
|
+
view_rule?: string | null;
|
|
595
|
+
create_rule?: string | null;
|
|
596
|
+
update_rule?: string | null;
|
|
597
|
+
delete_rule?: string | null;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Comprehensive field definition for export including all metadata
|
|
601
|
+
*/
|
|
602
|
+
interface CollectionExportFieldDefinition {
|
|
603
|
+
name: string;
|
|
604
|
+
type: FieldType;
|
|
605
|
+
required?: boolean;
|
|
606
|
+
default?: any;
|
|
607
|
+
unique?: boolean;
|
|
608
|
+
options?: Record<string, any> | null;
|
|
609
|
+
collection?: string | null;
|
|
610
|
+
on_delete?: string | null;
|
|
611
|
+
pii?: boolean;
|
|
612
|
+
mask_type?: string | null;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Access control rules structure for Permission System V2
|
|
616
|
+
* Rule values:
|
|
617
|
+
* - null = locked (access denied)
|
|
618
|
+
* - "" (empty string) = public (all users can access)
|
|
619
|
+
* - Expression string = conditional access (RLS rule)
|
|
620
|
+
*/
|
|
621
|
+
interface CollectionExportRules {
|
|
622
|
+
list_rule: string | null;
|
|
623
|
+
view_rule: string | null;
|
|
624
|
+
create_rule: string | null;
|
|
625
|
+
update_rule: string | null;
|
|
626
|
+
delete_rule: string | null;
|
|
627
|
+
list_fields: string;
|
|
628
|
+
view_fields: string;
|
|
629
|
+
create_fields: string;
|
|
630
|
+
update_fields: string;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Single collection in export bundle
|
|
634
|
+
*/
|
|
635
|
+
interface CollectionExportItem {
|
|
636
|
+
name: string;
|
|
637
|
+
schema: CollectionExportFieldDefinition[];
|
|
638
|
+
rules: CollectionExportRules;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Complete export file structure
|
|
642
|
+
*/
|
|
643
|
+
interface CollectionExportData {
|
|
644
|
+
version: string;
|
|
645
|
+
exported_at: string;
|
|
646
|
+
exported_by: string;
|
|
647
|
+
collections: CollectionExportItem[];
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Import conflict handling strategies
|
|
651
|
+
*/
|
|
652
|
+
type ImportStrategy = 'error' | 'skip' | 'update';
|
|
653
|
+
/**
|
|
654
|
+
* Import request payload
|
|
655
|
+
*/
|
|
656
|
+
interface CollectionImportRequest {
|
|
657
|
+
data: CollectionExportData;
|
|
658
|
+
strategy?: ImportStrategy;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Import result for a single collection
|
|
662
|
+
*/
|
|
663
|
+
interface CollectionImportItemResult {
|
|
664
|
+
name: string;
|
|
665
|
+
status: 'imported' | 'skipped' | 'updated' | 'error';
|
|
666
|
+
message: string;
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Complete import operation result
|
|
670
|
+
*/
|
|
671
|
+
interface CollectionImportResult {
|
|
672
|
+
success: boolean;
|
|
673
|
+
imported_count: number;
|
|
674
|
+
skipped_count: number;
|
|
675
|
+
updated_count: number;
|
|
676
|
+
failed_count: number;
|
|
677
|
+
collections: CollectionImportItemResult[];
|
|
678
|
+
migrations_created: string[];
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Export query parameters
|
|
682
|
+
*/
|
|
683
|
+
interface CollectionExportParams {
|
|
684
|
+
collection_ids?: string[];
|
|
543
685
|
}
|
|
544
686
|
//#endregion
|
|
545
687
|
//#region src/core/collection-service.d.ts
|
|
@@ -577,6 +719,56 @@ declare class CollectionService {
|
|
|
577
719
|
delete(collectionId: string): Promise<{
|
|
578
720
|
success: boolean;
|
|
579
721
|
}>;
|
|
722
|
+
/**
|
|
723
|
+
* Export collections to JSON format.
|
|
724
|
+
* Returns collection schemas and rules for backup or migration.
|
|
725
|
+
*
|
|
726
|
+
* @param params Optional filter by collection IDs
|
|
727
|
+
* @returns Complete export data structure with collections, schemas, and rules
|
|
728
|
+
* @throws {AuthorizationError} If user is not a superadmin
|
|
729
|
+
*
|
|
730
|
+
* @example
|
|
731
|
+
* // Export all collections
|
|
732
|
+
* const exportData = await client.collections.export();
|
|
733
|
+
*
|
|
734
|
+
* @example
|
|
735
|
+
* // Export specific collections
|
|
736
|
+
* const exportData = await client.collections.export({
|
|
737
|
+
* collection_ids: ['col-123', 'col-456']
|
|
738
|
+
* });
|
|
739
|
+
*/
|
|
740
|
+
export(params?: CollectionExportParams): Promise<CollectionExportData>;
|
|
741
|
+
/**
|
|
742
|
+
* Import collections from JSON export.
|
|
743
|
+
*
|
|
744
|
+
* @param request Import request with data and conflict strategy
|
|
745
|
+
* @returns Import result with per-collection status and migration IDs
|
|
746
|
+
* @throws {ValidationError} If import data is invalid
|
|
747
|
+
* @throws {ConflictError} If collection exists and strategy is 'error'
|
|
748
|
+
* @throws {AuthorizationError} If user is not a superadmin
|
|
749
|
+
*
|
|
750
|
+
* @example
|
|
751
|
+
* // Import with error strategy (fail on conflicts)
|
|
752
|
+
* const result = await client.collections.import({
|
|
753
|
+
* data: exportData,
|
|
754
|
+
* strategy: 'error'
|
|
755
|
+
* });
|
|
756
|
+
*
|
|
757
|
+
* @example
|
|
758
|
+
* // Import with skip strategy (skip existing collections)
|
|
759
|
+
* const result = await client.collections.import({
|
|
760
|
+
* data: exportData,
|
|
761
|
+
* strategy: 'skip'
|
|
762
|
+
* });
|
|
763
|
+
*
|
|
764
|
+
* @example
|
|
765
|
+
* // Import with update strategy (update existing collections)
|
|
766
|
+
* const result = await client.collections.import({
|
|
767
|
+
* data: exportData,
|
|
768
|
+
* strategy: 'update'
|
|
769
|
+
* });
|
|
770
|
+
*/
|
|
771
|
+
import(request: CollectionImportRequest): Promise<CollectionImportResult>;
|
|
580
772
|
}
|
|
581
773
|
//#endregion
|
|
582
774
|
//#region src/types/record.d.ts
|
|
@@ -952,10 +1144,11 @@ interface ApiKey {
|
|
|
952
1144
|
name: string;
|
|
953
1145
|
/**
|
|
954
1146
|
* The full API key. Only returned once during creation.
|
|
1147
|
+
* Format: sb_ak.<payload>.<signature>
|
|
955
1148
|
*/
|
|
956
1149
|
key?: string;
|
|
957
1150
|
/**
|
|
958
|
-
* The masked version of the key (e.g., "
|
|
1151
|
+
* The masked version of the key (e.g., "sb_ak....SIGN").
|
|
959
1152
|
*/
|
|
960
1153
|
masked_key: string;
|
|
961
1154
|
/**
|
|
@@ -971,6 +1164,12 @@ interface ApiKeyCreate {
|
|
|
971
1164
|
name: string;
|
|
972
1165
|
expires_at?: string;
|
|
973
1166
|
}
|
|
1167
|
+
interface ApiKeyListParams {
|
|
1168
|
+
limit?: number;
|
|
1169
|
+
offset?: number;
|
|
1170
|
+
[key: string]: string | number | boolean | undefined;
|
|
1171
|
+
}
|
|
1172
|
+
type ApiKeyListResponse = ApiKey[];
|
|
974
1173
|
//#endregion
|
|
975
1174
|
//#region src/core/api-key-service.d.ts
|
|
976
1175
|
/**
|
|
@@ -981,23 +1180,23 @@ declare class ApiKeyService {
|
|
|
981
1180
|
private http;
|
|
982
1181
|
constructor(http: HttpClient);
|
|
983
1182
|
/**
|
|
984
|
-
* List all API keys
|
|
985
|
-
*
|
|
1183
|
+
* List all API keys
|
|
1184
|
+
* GET /api/v1/admin/api-keys
|
|
986
1185
|
*/
|
|
987
|
-
list(): Promise<
|
|
1186
|
+
list(params?: ApiKeyListParams): Promise<ApiKeyListResponse>;
|
|
988
1187
|
/**
|
|
989
|
-
* Get
|
|
990
|
-
*
|
|
1188
|
+
* Get specific API key
|
|
1189
|
+
* GET /api/v1/admin/api-keys/{id}
|
|
991
1190
|
*/
|
|
992
1191
|
get(keyId: string): Promise<ApiKey>;
|
|
993
1192
|
/**
|
|
994
|
-
* Create a new API key
|
|
995
|
-
*
|
|
1193
|
+
* Create a new API key
|
|
1194
|
+
* POST /api/v1/admin/api-keys
|
|
996
1195
|
*/
|
|
997
1196
|
create(data: ApiKeyCreate): Promise<ApiKey>;
|
|
998
1197
|
/**
|
|
999
|
-
* Revoke an
|
|
1000
|
-
*
|
|
1198
|
+
* Revoke an API key
|
|
1199
|
+
* DELETE /api/v1/admin/api-keys/{id}
|
|
1001
1200
|
*/
|
|
1002
1201
|
revoke(keyId: string): Promise<{
|
|
1003
1202
|
success: boolean;
|
|
@@ -1005,6 +1204,13 @@ declare class ApiKeyService {
|
|
|
1005
1204
|
}
|
|
1006
1205
|
//#endregion
|
|
1007
1206
|
//#region src/types/audit-log.d.ts
|
|
1207
|
+
/**
|
|
1208
|
+
* Audit log extra metadata
|
|
1209
|
+
*/
|
|
1210
|
+
interface AuditLogExtraMetadata {
|
|
1211
|
+
auth_method?: 'jwt' | 'api_key' | 'personal_token' | 'oauth' | 'unknown';
|
|
1212
|
+
[key: string]: any;
|
|
1213
|
+
}
|
|
1008
1214
|
interface AuditLog {
|
|
1009
1215
|
id: string;
|
|
1010
1216
|
account_id: string;
|
|
@@ -1015,6 +1221,7 @@ interface AuditLog {
|
|
|
1015
1221
|
before: Record<string, any> | null;
|
|
1016
1222
|
after: Record<string, any> | null;
|
|
1017
1223
|
created_at: string;
|
|
1224
|
+
extra_metadata?: AuditLogExtraMetadata;
|
|
1018
1225
|
}
|
|
1019
1226
|
interface AuditLogFilters {
|
|
1020
1227
|
account_id?: string;
|
|
@@ -1029,7 +1236,7 @@ interface AuditLogFilters {
|
|
|
1029
1236
|
limit?: number;
|
|
1030
1237
|
sort?: string;
|
|
1031
1238
|
}
|
|
1032
|
-
type AuditLogExportFormat = 'csv' | 'json';
|
|
1239
|
+
type AuditLogExportFormat = 'csv' | 'json' | 'pdf';
|
|
1033
1240
|
interface AuditLogListResponse {
|
|
1034
1241
|
items: AuditLog[];
|
|
1035
1242
|
total: number;
|
|
@@ -1051,7 +1258,25 @@ declare class AuditLogService {
|
|
|
1051
1258
|
*/
|
|
1052
1259
|
get(logId: string): Promise<AuditLog>;
|
|
1053
1260
|
/**
|
|
1054
|
-
* Exports audit logs in the specified format.
|
|
1261
|
+
* Exports audit logs in the specified format (JSON, CSV, or PDF).
|
|
1262
|
+
*
|
|
1263
|
+
* @param params Optional filters (account_id, table_name, operation, date range, etc.)
|
|
1264
|
+
* @param format Export format: 'json', 'csv', or 'pdf' (default: 'json')
|
|
1265
|
+
* @returns Exported data as string (base64-encoded for PDF format)
|
|
1266
|
+
* @throws {AuthorizationError} If user is not a superadmin
|
|
1267
|
+
*
|
|
1268
|
+
* @example
|
|
1269
|
+
* // Export as JSON
|
|
1270
|
+
* const jsonData = await client.auditLogs.export({ table_name: 'users' }, 'json');
|
|
1271
|
+
*
|
|
1272
|
+
* @example
|
|
1273
|
+
* // Export as CSV
|
|
1274
|
+
* const csvData = await client.auditLogs.export({ table_name: 'users' }, 'csv');
|
|
1275
|
+
*
|
|
1276
|
+
* @example
|
|
1277
|
+
* // Export as PDF
|
|
1278
|
+
* const pdfBase64 = await client.auditLogs.export({ table_name: 'users' }, 'pdf');
|
|
1279
|
+
* // pdfBase64 is a base64-encoded PDF string
|
|
1055
1280
|
*/
|
|
1056
1281
|
export(params?: AuditLogFilters, format?: AuditLogExportFormat): Promise<string>;
|
|
1057
1282
|
}
|
|
@@ -1263,7 +1488,7 @@ interface DashboardStats {
|
|
|
1263
1488
|
/** Number of new users registered in the last 7 days */
|
|
1264
1489
|
new_users_7d: number;
|
|
1265
1490
|
/** List of the most recent user registrations */
|
|
1266
|
-
recent_registrations: User
|
|
1491
|
+
recent_registrations: User[];
|
|
1267
1492
|
/** Overview of current system health and status */
|
|
1268
1493
|
system_health: SystemHealth;
|
|
1269
1494
|
/** Number of currently active user sessions */
|
|
@@ -1903,15 +2128,35 @@ declare class SnackBaseClient {
|
|
|
1903
2128
|
/**
|
|
1904
2129
|
* Returns the current authenticated user.
|
|
1905
2130
|
*/
|
|
1906
|
-
get user(): User
|
|
2131
|
+
get user(): User | null;
|
|
1907
2132
|
/**
|
|
1908
2133
|
* Returns the current account.
|
|
1909
2134
|
*/
|
|
1910
|
-
get account(): Account
|
|
2135
|
+
get account(): Account | null;
|
|
1911
2136
|
/**
|
|
1912
2137
|
* Returns whether the client is currently authenticated.
|
|
1913
2138
|
*/
|
|
1914
2139
|
get isAuthenticated(): boolean;
|
|
2140
|
+
/**
|
|
2141
|
+
* Check if current user is superadmin.
|
|
2142
|
+
*/
|
|
2143
|
+
get isSuperadmin(): boolean;
|
|
2144
|
+
/**
|
|
2145
|
+
* Check if current session uses API key authentication.
|
|
2146
|
+
*/
|
|
2147
|
+
get isApiKeySession(): boolean;
|
|
2148
|
+
/**
|
|
2149
|
+
* Check if current session uses personal token authentication.
|
|
2150
|
+
*/
|
|
2151
|
+
get isPersonalTokenSession(): boolean;
|
|
2152
|
+
/**
|
|
2153
|
+
* Check if current session uses OAuth authentication.
|
|
2154
|
+
*/
|
|
2155
|
+
get isOAuthSession(): boolean;
|
|
2156
|
+
/**
|
|
2157
|
+
* Returns the current token type.
|
|
2158
|
+
*/
|
|
2159
|
+
get tokenType(): TokenType;
|
|
1915
2160
|
/**
|
|
1916
2161
|
* Access to authentication methods.
|
|
1917
2162
|
*/
|
|
@@ -2060,6 +2305,90 @@ declare class SnackBaseClient {
|
|
|
2060
2305
|
private validateConfig;
|
|
2061
2306
|
}
|
|
2062
2307
|
//#endregion
|
|
2308
|
+
//#region src/core/errors.d.ts
|
|
2309
|
+
/**
|
|
2310
|
+
* Base error class for all SnackBase SDK errors.
|
|
2311
|
+
*/
|
|
2312
|
+
declare class SnackBaseError extends Error {
|
|
2313
|
+
redirectUrl?: string | undefined;
|
|
2314
|
+
authProvider?: string | undefined;
|
|
2315
|
+
providerName?: string | undefined;
|
|
2316
|
+
readonly code: string;
|
|
2317
|
+
readonly status?: number;
|
|
2318
|
+
readonly details?: any;
|
|
2319
|
+
readonly field?: string;
|
|
2320
|
+
readonly retryable: boolean;
|
|
2321
|
+
constructor(message: string, code: string, status?: number, details?: any, retryable?: boolean, field?: string, redirectUrl?: string | undefined, authProvider?: string | undefined, providerName?: string | undefined);
|
|
2322
|
+
}
|
|
2323
|
+
/**
|
|
2324
|
+
* Thrown when authentication fails (401).
|
|
2325
|
+
*/
|
|
2326
|
+
declare class AuthenticationError extends SnackBaseError {
|
|
2327
|
+
constructor(message?: string, details?: any);
|
|
2328
|
+
}
|
|
2329
|
+
/**
|
|
2330
|
+
* Thrown when the user is not authorized to perform an action (403).
|
|
2331
|
+
*/
|
|
2332
|
+
declare class AuthorizationError extends SnackBaseError {
|
|
2333
|
+
constructor(message?: string, details?: any);
|
|
2334
|
+
}
|
|
2335
|
+
/**
|
|
2336
|
+
* Thrown when an API key is restricted to superadmin users (403).
|
|
2337
|
+
*/
|
|
2338
|
+
declare class ApiKeyRestrictedError extends SnackBaseError {
|
|
2339
|
+
constructor(message?: string, details?: any);
|
|
2340
|
+
}
|
|
2341
|
+
/**
|
|
2342
|
+
* Thrown when email verification is required (401).
|
|
2343
|
+
*/
|
|
2344
|
+
declare class EmailVerificationRequiredError extends SnackBaseError {
|
|
2345
|
+
constructor(message?: string, details?: any);
|
|
2346
|
+
}
|
|
2347
|
+
/**
|
|
2348
|
+
* Thrown when a resource is not found (404).
|
|
2349
|
+
*/
|
|
2350
|
+
declare class NotFoundError extends SnackBaseError {
|
|
2351
|
+
constructor(message?: string, details?: any);
|
|
2352
|
+
}
|
|
2353
|
+
/**
|
|
2354
|
+
* Thrown when a conflict occurs (409).
|
|
2355
|
+
*/
|
|
2356
|
+
declare class ConflictError extends SnackBaseError {
|
|
2357
|
+
constructor(message?: string, details?: any);
|
|
2358
|
+
}
|
|
2359
|
+
/**
|
|
2360
|
+
* Thrown when validation fails (422).
|
|
2361
|
+
*/
|
|
2362
|
+
declare class ValidationError extends SnackBaseError {
|
|
2363
|
+
readonly fields?: Record<string, string[]>;
|
|
2364
|
+
constructor(message?: string, details?: any);
|
|
2365
|
+
}
|
|
2366
|
+
/**
|
|
2367
|
+
* Thrown when rate limit is exceeded (429).
|
|
2368
|
+
*/
|
|
2369
|
+
declare class RateLimitError extends SnackBaseError {
|
|
2370
|
+
readonly retryAfter?: number;
|
|
2371
|
+
constructor(message?: string, details?: any, retryAfter?: number);
|
|
2372
|
+
}
|
|
2373
|
+
/**
|
|
2374
|
+
* Thrown when a network failure occurs.
|
|
2375
|
+
*/
|
|
2376
|
+
declare class NetworkError extends SnackBaseError {
|
|
2377
|
+
constructor(message?: string, details?: any);
|
|
2378
|
+
}
|
|
2379
|
+
/**
|
|
2380
|
+
* Thrown when a request times out.
|
|
2381
|
+
*/
|
|
2382
|
+
declare class TimeoutError extends SnackBaseError {
|
|
2383
|
+
constructor(message?: string, details?: any);
|
|
2384
|
+
}
|
|
2385
|
+
/**
|
|
2386
|
+
* Thrown when a server error occurs (500+).
|
|
2387
|
+
*/
|
|
2388
|
+
declare class ServerError extends SnackBaseError {
|
|
2389
|
+
constructor(message?: string, status?: number, details?: any);
|
|
2390
|
+
}
|
|
2391
|
+
//#endregion
|
|
2063
2392
|
//#region src/types/utils.d.ts
|
|
2064
2393
|
/**
|
|
2065
2394
|
* Generic record type with system fields.
|
|
@@ -2115,4 +2444,4 @@ type InferSchema<T extends readonly FieldDefinition[]> = { [K in T[number] as K[
|
|
|
2115
2444
|
*/
|
|
2116
2445
|
declare function getAutoDetectedStorage(): StorageBackend;
|
|
2117
2446
|
//#endregion
|
|
2118
|
-
export {
|
|
2447
|
+
export { type Account, ApiKey, ApiKeyCreate, ApiKeyListParams, ApiKeyListResponse, ApiKeyRestrictedError, AuditLog, AuditLogExportFormat, AuditLogExtraMetadata, AuditLogFilters, AuditLogListResponse, AuthEvent, AuthEvents, AuthResponse, AuthState, AuthenticationError, AuthorizationError, BaseRecord, Collection, CollectionCreate, CollectionExportData, CollectionExportFieldDefinition, CollectionExportItem, CollectionExportParams, CollectionExportRules, CollectionImportItemResult, CollectionImportRequest, CollectionImportResult, CollectionRecord, CollectionRule, CollectionRuleUpdate, CollectionUpdate, Configuration, ConfigurationCreate, ConfigurationStats, ConflictError, ConnectionTestResult, CurrentRevisionResponse, DEFAULT_CONFIG, DashboardStats, EmailLog, EmailLogFilters, EmailLogListResponse, EmailTemplate, EmailTemplateFilters, EmailTemplateRenderRequest, EmailTemplateRenderResponse, EmailTemplateType, EmailTemplateUpdate, EmailVerificationRequiredError, 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, NetworkError, NotFoundError, OAuthCallbackParams, OAuthProvider, OAuthResponse, OAuthUrlResponse, PasswordResetConfirm, PasswordResetRequest, Permission, ProviderDefinition, QueryBuilder, QueryParams, RateLimitError, RealTimeConfig, RealTimeEvent, RealTimeEventHandler, RealTimeEvents, RealTimeState, RealtimeEvent, RecentConfiguration, RecordListParams, RecordListResponse, RegisterData, Role, RoleCreate, RoleListResponse, RoleUpdate, RuleTestResult, RuleValidationParams, RuleValidationResult, SAMLCallbackParams, SAMLProvider, SAMLResponse, SAMLUrlResponse, ServerError, ServerMessage, type SnackBaseClient as SnackBase, SnackBaseClient, SnackBaseConfig, SnackBaseError, SortDirection, SortExpression, StorageBackend, SystemHealth, TimeoutError, TokenType, type User, UserCreate, UserListParams, type UserListResponse, UserUpdate, ValidationError, WebSocketAction, WebSocketMessage, getAutoDetectedStorage };
|