@snackbase/sdk 0.1.1 → 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.
@@ -1,5 +1,5 @@
1
1
  //#region src/types/config.d.ts
2
- type LogLevel$1 = 'debug' | 'info' | 'warn' | 'error';
2
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
3
3
  type StorageBackend = 'localStorage' | 'sessionStorage' | 'memory' | 'asyncStorage';
4
4
  interface SnackBaseConfig {
5
5
  /**
@@ -44,7 +44,7 @@ interface SnackBaseConfig {
44
44
  /**
45
45
  * Logging level (default: 'error')
46
46
  */
47
- logLevel?: LogLevel$1;
47
+ logLevel?: LogLevel;
48
48
  /**
49
49
  * Callback for 401 authentication errors
50
50
  */
@@ -73,7 +73,7 @@ interface SnackBaseConfig {
73
73
  declare const DEFAULT_CONFIG: Partial<SnackBaseConfig>;
74
74
  //#endregion
75
75
  //#region src/core/logger.d.ts
76
- declare enum LogLevel {
76
+ declare enum LogLevel$1 {
77
77
  NONE = 0,
78
78
  ERROR = 1,
79
79
  WARN = 2,
@@ -82,7 +82,7 @@ declare enum LogLevel {
82
82
  }
83
83
  interface LogEntry {
84
84
  timestamp: string;
85
- level: LogLevel;
85
+ level: LogLevel$1;
86
86
  message: string;
87
87
  data?: any;
88
88
  }
@@ -91,8 +91,8 @@ declare class Logger {
91
91
  private handlers;
92
92
  private logs;
93
93
  private maxLogs;
94
- constructor(level?: LogLevel);
95
- setLevel(level: LogLevel): void;
94
+ constructor(level?: LogLevel$1);
95
+ setLevel(level: LogLevel$1): void;
96
96
  getLogs(): LogEntry[];
97
97
  clearLogs(): void;
98
98
  private log;
@@ -153,7 +153,7 @@ declare class HttpClient {
153
153
  }
154
154
  //#endregion
155
155
  //#region src/types/account.d.ts
156
- interface Account$1 {
156
+ interface Account {
157
157
  id: string;
158
158
  slug: string;
159
159
  name: string;
@@ -176,7 +176,7 @@ interface AccountListParams {
176
176
  [key: string]: string | number | boolean | undefined;
177
177
  }
178
178
  interface AccountListResponse {
179
- items: Account$1[];
179
+ items: Account[];
180
180
  total: number;
181
181
  }
182
182
  interface AccountUserListParams {
@@ -186,7 +186,7 @@ interface AccountUserListParams {
186
186
  }
187
187
  //#endregion
188
188
  //#region src/types/user.d.ts
189
- interface User$1 {
189
+ interface User {
190
190
  id: string;
191
191
  email: string;
192
192
  role: string;
@@ -218,7 +218,7 @@ interface UserListParams {
218
218
  [key: string]: string | number | boolean | undefined;
219
219
  }
220
220
  interface UserListResponse {
221
- items: User$1[];
221
+ items: User[];
222
222
  total: number;
223
223
  }
224
224
  //#endregion
@@ -246,15 +246,21 @@ interface LoginCredentials {
246
246
  interface RegisterData {
247
247
  email: string;
248
248
  password: string;
249
- accountName?: string;
250
- accountSlug?: string;
249
+ account_name?: string;
250
+ account_slug?: string;
251
251
  }
252
252
  interface AuthResponse {
253
- user: User;
254
- account: Account;
253
+ user?: User;
254
+ account?: Account;
255
255
  token?: string;
256
+ refresh_token?: string;
256
257
  refreshToken?: string;
258
+ expires_in?: number;
257
259
  expiresAt?: string;
260
+ user_id?: string;
261
+ account_id?: string;
262
+ email?: string;
263
+ role?: string;
258
264
  }
259
265
  interface PasswordResetRequest {
260
266
  account?: string;
@@ -312,8 +318,8 @@ declare class AuthManager {
312
318
  constructor(options: AuthManagerOptions);
313
319
  initialize(): Promise<void>;
314
320
  getState(): AuthState;
315
- get user(): User$1 | null;
316
- get account(): Account$1 | null;
321
+ get user(): User | null;
322
+ get account(): Account | null;
317
323
  get token(): string | null;
318
324
  get refreshToken(): string | null;
319
325
  get isAuthenticated(): boolean;
@@ -442,15 +448,15 @@ declare class AccountService {
442
448
  /**
443
449
  * Get details for a specific account.
444
450
  */
445
- get(accountId: string): Promise<Account$1>;
451
+ get(accountId: string): Promise<Account>;
446
452
  /**
447
453
  * Create a new account.
448
454
  */
449
- create(data: AccountCreate): Promise<Account$1>;
455
+ create(data: AccountCreate): Promise<Account>;
450
456
  /**
451
457
  * Update an existing account.
452
458
  */
453
- update(accountId: string, data: AccountUpdate): Promise<Account$1>;
459
+ update(accountId: string, data: AccountUpdate): Promise<Account>;
454
460
  /**
455
461
  * Delete an account and all its associated data.
456
462
  */
@@ -478,15 +484,15 @@ declare class UserService {
478
484
  /**
479
485
  * Get details for a specific user.
480
486
  */
481
- get(userId: string): Promise<User$1>;
487
+ get(userId: string): Promise<User>;
482
488
  /**
483
489
  * Create a new user in a specific account.
484
490
  */
485
- create(data: UserCreate): Promise<User$1>;
491
+ create(data: UserCreate): Promise<User>;
486
492
  /**
487
493
  * Update an existing user.
488
494
  */
489
- update(userId: string, data: UserUpdate): Promise<User$1>;
495
+ update(userId: string, data: UserUpdate): Promise<User>;
490
496
  /**
491
497
  * Soft delete (deactivate) a user.
492
498
  */
@@ -536,10 +542,107 @@ interface Collection {
536
542
  interface CollectionCreate {
537
543
  name: string;
538
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;
539
550
  }
540
551
  interface CollectionUpdate {
541
552
  name?: string;
542
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[];
543
646
  }
544
647
  //#endregion
545
648
  //#region src/core/collection-service.d.ts
@@ -577,6 +680,56 @@ declare class CollectionService {
577
680
  delete(collectionId: string): Promise<{
578
681
  success: boolean;
579
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>;
580
733
  }
581
734
  //#endregion
582
735
  //#region src/types/record.d.ts
@@ -1029,7 +1182,7 @@ interface AuditLogFilters {
1029
1182
  limit?: number;
1030
1183
  sort?: string;
1031
1184
  }
1032
- type AuditLogExportFormat = 'csv' | 'json';
1185
+ type AuditLogExportFormat = 'csv' | 'json' | 'pdf';
1033
1186
  interface AuditLogListResponse {
1034
1187
  items: AuditLog[];
1035
1188
  total: number;
@@ -1051,7 +1204,25 @@ declare class AuditLogService {
1051
1204
  */
1052
1205
  get(logId: string): Promise<AuditLog>;
1053
1206
  /**
1054
- * Exports audit logs in the specified format.
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
1055
1226
  */
1056
1227
  export(params?: AuditLogFilters, format?: AuditLogExportFormat): Promise<string>;
1057
1228
  }
@@ -1263,7 +1434,7 @@ interface DashboardStats {
1263
1434
  /** Number of new users registered in the last 7 days */
1264
1435
  new_users_7d: number;
1265
1436
  /** List of the most recent user registrations */
1266
- recent_registrations: User$1[];
1437
+ recent_registrations: User[];
1267
1438
  /** Overview of current system health and status */
1268
1439
  system_health: SystemHealth;
1269
1440
  /** Number of currently active user sessions */
@@ -1903,11 +2074,11 @@ declare class SnackBaseClient {
1903
2074
  /**
1904
2075
  * Returns the current authenticated user.
1905
2076
  */
1906
- get user(): User$1 | null;
2077
+ get user(): User | null;
1907
2078
  /**
1908
2079
  * Returns the current account.
1909
2080
  */
1910
- get account(): Account$1 | null;
2081
+ get account(): Account | null;
1911
2082
  /**
1912
2083
  * Returns whether the client is currently authenticated.
1913
2084
  */
@@ -2115,4 +2286,4 @@ type InferSchema<T extends readonly FieldDefinition[]> = { [K in T[number] as K[
2115
2286
  */
2116
2287
  declare function getAutoDetectedStorage(): StorageBackend;
2117
2288
  //#endregion
2118
- export { AuditLogFilters as $, EmailTemplateRenderResponse as A, OAuthCallbackParams as At, SystemHealth as B, SAMLUrlResponse as Bt, FileUploadOptions as C, FieldDefinition as Ct, EmailTemplate as D, AuthResponse as Dt, EmailLogListResponse as E, AuthEvents as Et, ConfigurationStats as F, PasswordResetRequest as Ft, RoleCreate as G, UserUpdate as Gt, CollectionRuleUpdate as H, UserCreate as Ht, ConnectionTestResult as I, RegisterData as It, RuleTestResult as J, LogLevel$1 as Jt, RoleListResponse as K, Account$1 as Kt, ProviderDefinition as L, SAMLCallbackParams as Lt, EmailTemplateUpdate as M, OAuthResponse as Mt, Configuration as N, OAuthUrlResponse as Nt, EmailTemplateFilters as O, AuthState as Ot, ConfigurationCreate as P, PasswordResetConfirm as Pt, AuditLogExportFormat as Q, RecentConfiguration as R, SAMLProvider as Rt, FileMetadata as S, CollectionUpdate as St, EmailLogFilters as T, AuthEvent as Tt, Permission as U, UserListParams as Ut, CollectionRule as V, User$1 as Vt, Role as W, UserListResponse as Wt, RuleValidationResult as X, StorageBackend as Xt, RuleValidationParams as Y, SnackBaseConfig as Yt, AuditLog as Z, RealTimeState as _, BaseRecord as _t, InferSchema as a, InvitationListParams as at, WebSocketAction as b, Collection as bt, CurrentRevisionResponse as c, GroupListParams as ct, MigrationListResponse as d, QueryBuilder as dt, AuditLogListResponse as et, MigrationRevision as f, FilterExpression as ft, RealTimeEvents as g, SortExpression as gt, RealTimeEventHandler as h, SortDirection as ht, Filter as i, InvitationCreate as it, EmailTemplateType as j, OAuthProvider as jt, EmailTemplateRenderRequest as k, LoginCredentials as kt, MigrationHistoryItem as l, GroupListResponse as lt, RealTimeEvent as m, QueryParams as mt, CollectionRecord as n, ApiKeyCreate as nt, ListResponse as o, Group as ot, RealTimeConfig as p, FilterOperator as pt, RoleUpdate as q, DEFAULT_CONFIG as qt, FieldTypeToTs as r, Invitation as rt, SnackBaseClient as s, GroupCreate as st, getAutoDetectedStorage as t, ApiKey as tt, MigrationHistoryResponse as u, GroupUpdate as ut, RealtimeEvent as v, RecordListParams as vt, EmailLog as w, FieldType as wt, WebSocketMessage as x, CollectionCreate as xt, ServerMessage as y, RecordListResponse as yt, DashboardStats as z, SAMLResponse as zt };
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 };