@tspvivek/baasix-sdk 0.1.0-alpha.1

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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +942 -0
  3. package/dist/client-CzF9B60b.d.ts +614 -0
  4. package/dist/client-aXK_gEyr.d.cts +614 -0
  5. package/dist/index.cjs +4159 -0
  6. package/dist/index.cjs.map +1 -0
  7. package/dist/index.d.cts +1498 -0
  8. package/dist/index.d.ts +1498 -0
  9. package/dist/index.js +4135 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/modules/auth.cjs +651 -0
  12. package/dist/modules/auth.cjs.map +1 -0
  13. package/dist/modules/auth.d.cts +384 -0
  14. package/dist/modules/auth.d.ts +384 -0
  15. package/dist/modules/auth.js +649 -0
  16. package/dist/modules/auth.js.map +1 -0
  17. package/dist/modules/files.cjs +266 -0
  18. package/dist/modules/files.cjs.map +1 -0
  19. package/dist/modules/files.d.cts +187 -0
  20. package/dist/modules/files.d.ts +187 -0
  21. package/dist/modules/files.js +264 -0
  22. package/dist/modules/files.js.map +1 -0
  23. package/dist/modules/items.cjs +654 -0
  24. package/dist/modules/items.cjs.map +1 -0
  25. package/dist/modules/items.d.cts +472 -0
  26. package/dist/modules/items.d.ts +472 -0
  27. package/dist/modules/items.js +651 -0
  28. package/dist/modules/items.js.map +1 -0
  29. package/dist/modules/schemas.cjs +269 -0
  30. package/dist/modules/schemas.cjs.map +1 -0
  31. package/dist/modules/schemas.d.cts +239 -0
  32. package/dist/modules/schemas.d.ts +239 -0
  33. package/dist/modules/schemas.js +267 -0
  34. package/dist/modules/schemas.js.map +1 -0
  35. package/dist/storage/index.cjs +162 -0
  36. package/dist/storage/index.cjs.map +1 -0
  37. package/dist/storage/index.d.cts +96 -0
  38. package/dist/storage/index.d.ts +96 -0
  39. package/dist/storage/index.js +157 -0
  40. package/dist/storage/index.js.map +1 -0
  41. package/dist/types-BdjsGANq.d.cts +40 -0
  42. package/dist/types-BdjsGANq.d.ts +40 -0
  43. package/package.json +107 -0
@@ -0,0 +1,614 @@
1
+ import { S as StorageAdapter } from './types-BdjsGANq.cjs';
2
+
3
+ /**
4
+ * Authentication mode for the SDK
5
+ * - 'jwt': Use JWT tokens stored in the configured storage adapter (default)
6
+ * - 'cookie': Use HTTP-only cookies (server handles token storage)
7
+ */
8
+ type AuthMode = "jwt" | "cookie";
9
+ /**
10
+ * SDK Configuration options
11
+ */
12
+ interface BaasixConfig {
13
+ /**
14
+ * The base URL of your Baasix instance
15
+ * @example 'https://api.example.com' or 'http://localhost:8056'
16
+ */
17
+ url: string;
18
+ /**
19
+ * Authentication mode
20
+ * @default 'jwt'
21
+ */
22
+ authMode?: AuthMode;
23
+ /**
24
+ * Storage adapter for persisting tokens and user data
25
+ * @default LocalStorageAdapter (web) or MemoryStorageAdapter (SSR)
26
+ */
27
+ storage?: StorageAdapter;
28
+ /**
29
+ * Static access token (useful for server-side or service accounts)
30
+ * When provided, this token is used instead of stored tokens
31
+ */
32
+ token?: string;
33
+ /**
34
+ * Custom headers to include in all requests
35
+ */
36
+ headers?: Record<string, string>;
37
+ /**
38
+ * Request timeout in milliseconds
39
+ * @default 30000 (30 seconds)
40
+ */
41
+ timeout?: number;
42
+ /**
43
+ * Whether to automatically refresh tokens before expiry
44
+ * @default true
45
+ */
46
+ autoRefresh?: boolean;
47
+ /**
48
+ * Credentials mode for fetch requests (important for cookies)
49
+ * @default 'include' for cookie mode, 'same-origin' for jwt mode
50
+ */
51
+ credentials?: RequestCredentials;
52
+ /**
53
+ * Tenant ID for multi-tenant mode
54
+ */
55
+ tenantId?: string;
56
+ /**
57
+ * Global error handler
58
+ */
59
+ onError?: (error: BaasixError) => void;
60
+ /**
61
+ * Called when authentication state changes
62
+ */
63
+ onAuthStateChange?: (event: AuthStateEvent, user: User | null) => void;
64
+ /**
65
+ * WebSocket server URL for realtime features
66
+ * @default Same as url
67
+ */
68
+ socketUrl?: string;
69
+ /**
70
+ * WebSocket path
71
+ * @default '/socket'
72
+ */
73
+ socketPath?: string;
74
+ }
75
+ interface User {
76
+ id: string;
77
+ email: string;
78
+ firstName?: string;
79
+ lastName?: string;
80
+ avatar?: string;
81
+ role?: Role;
82
+ role_Id?: string;
83
+ tenant_Id?: string;
84
+ status?: string;
85
+ createdAt?: string;
86
+ updatedAt?: string;
87
+ [key: string]: unknown;
88
+ }
89
+ interface Role {
90
+ id: string;
91
+ name: string;
92
+ description?: string;
93
+ [key: string]: unknown;
94
+ }
95
+ interface Tenant {
96
+ id: string;
97
+ name: string;
98
+ [key: string]: unknown;
99
+ }
100
+ interface AuthTokens {
101
+ accessToken: string;
102
+ refreshToken?: string;
103
+ expiresAt?: number;
104
+ expiresIn?: number;
105
+ }
106
+ interface LoginCredentials {
107
+ email: string;
108
+ password: string;
109
+ tenantId?: string;
110
+ }
111
+ interface RegisterData {
112
+ email: string;
113
+ password: string;
114
+ firstName?: string;
115
+ lastName?: string;
116
+ [key: string]: unknown;
117
+ }
118
+ interface AuthResponse {
119
+ token: string;
120
+ refreshToken?: string;
121
+ user: User;
122
+ expiresIn?: number;
123
+ }
124
+ type AuthStateEvent = "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "USER_UPDATED" | "TENANT_SWITCHED";
125
+ interface AuthState {
126
+ user: User | null;
127
+ isAuthenticated: boolean;
128
+ isLoading: boolean;
129
+ error: BaasixError | null;
130
+ }
131
+ interface MagicLinkOptions {
132
+ email: string;
133
+ redirectUrl?: string;
134
+ mode?: "link" | "code";
135
+ }
136
+ interface PasswordResetOptions {
137
+ email: string;
138
+ redirectUrl?: string;
139
+ }
140
+ /**
141
+ * Filter operators supported by Baasix
142
+ */
143
+ type FilterOperator = "eq" | "ne" | "neq" | "gt" | "gte" | "lt" | "lte" | "is" | "not" | "in" | "notIn" | "nin" | "like" | "notLike" | "iLike" | "notILike" | "ilike" | "contains" | "icontains" | "ncontains" | "startsWith" | "startsWiths" | "endsWith" | "endsWiths" | "nstartsWith" | "nstartsWiths" | "nendsWith" | "nendsWiths" | "between" | "notBetween" | "nbetween" | "isNull" | "isNotNull" | "arraycontains" | "arraycontained" | "arrayoverlap" | "arraylength" | "jsonbContains" | "jsonbContainedBy" | "jsonbNotContains" | "jsonbHasKey" | "jsonbHasAnyKeys" | "jsonbHasAllKeys" | "jsonbKeyEquals" | "jsonbKeyNotEquals" | "jsonbKeyGt" | "jsonbKeyGte" | "jsonbKeyLt" | "jsonbKeyLte" | "jsonbKeyIn" | "jsonbKeyNotIn" | "jsonbKeyLike" | "jsonbKeyIsNull" | "jsonbKeyIsNotNull" | "jsonbPathExists" | "jsonbPathMatch" | "jsonbDeepValue" | "jsonbArrayLength" | "jsonbTypeOf" | "within" | "containsGEO" | "intersects" | "nIntersects" | "dwithin";
144
+ /**
145
+ * Filter value with operator
146
+ */
147
+ type FilterValue<T = unknown> = T | {
148
+ [K in FilterOperator]?: T | T[];
149
+ } | {
150
+ cast?: string;
151
+ };
152
+ /**
153
+ * Filter condition for a field
154
+ */
155
+ type FilterCondition = {
156
+ [field: string]: FilterValue | FilterCondition;
157
+ };
158
+ /**
159
+ * Logical filter operators
160
+ */
161
+ interface LogicalFilter {
162
+ AND?: (FilterCondition | LogicalFilter)[];
163
+ OR?: (FilterCondition | LogicalFilter)[];
164
+ NOT?: FilterCondition | LogicalFilter;
165
+ }
166
+ /**
167
+ * Complete filter type
168
+ */
169
+ type Filter = FilterCondition | LogicalFilter;
170
+ /**
171
+ * Sort direction
172
+ */
173
+ type SortDirection = "asc" | "desc" | "ASC" | "DESC";
174
+ /**
175
+ * Sort configuration
176
+ */
177
+ type Sort = string | string[] | Record<string, SortDirection> | {
178
+ column: string;
179
+ order: SortDirection;
180
+ }[];
181
+ /**
182
+ * Aggregation function
183
+ */
184
+ type AggregateFunction = "count" | "sum" | "avg" | "min" | "max";
185
+ /**
186
+ * Aggregation configuration
187
+ */
188
+ interface AggregateConfig {
189
+ function: AggregateFunction;
190
+ field: string;
191
+ }
192
+ type Aggregate = Record<string, AggregateConfig>;
193
+ /**
194
+ * Query parameters for listing items
195
+ */
196
+ interface QueryParams<T = unknown> {
197
+ /**
198
+ * Fields to return
199
+ * @example ['*'], ['id', 'name'], ['*', 'author.*']
200
+ */
201
+ fields?: string[];
202
+ /**
203
+ * Filter conditions
204
+ */
205
+ filter?: Filter;
206
+ /**
207
+ * Sorting configuration
208
+ * @example { createdAt: 'desc' } or ['-createdAt', 'name']
209
+ */
210
+ sort?: Sort;
211
+ /**
212
+ * Number of items per page (-1 for all)
213
+ * @default 10
214
+ */
215
+ limit?: number;
216
+ /**
217
+ * Page number (1-indexed)
218
+ * @default 1
219
+ */
220
+ page?: number;
221
+ /**
222
+ * Number of items to skip
223
+ */
224
+ offset?: number;
225
+ /**
226
+ * Full-text search query
227
+ */
228
+ search?: string;
229
+ /**
230
+ * Fields to search in
231
+ */
232
+ searchFields?: string[];
233
+ /**
234
+ * Aggregation configuration
235
+ */
236
+ aggregate?: Aggregate;
237
+ /**
238
+ * Fields to group by (used with aggregate)
239
+ */
240
+ groupBy?: string[];
241
+ /**
242
+ * Include soft-deleted items
243
+ * @default false
244
+ */
245
+ paranoid?: boolean;
246
+ /**
247
+ * Filter conditions for related items (O2M/M2M)
248
+ */
249
+ relConditions?: Record<string, Filter>;
250
+ /**
251
+ * Additional metadata
252
+ */
253
+ meta?: T;
254
+ }
255
+ /**
256
+ * Paginated response
257
+ */
258
+ interface PaginatedResponse<T> {
259
+ data: T[];
260
+ totalCount?: number;
261
+ page?: number;
262
+ limit?: number;
263
+ totalPages?: number;
264
+ }
265
+ /**
266
+ * Single item response
267
+ */
268
+ interface SingleResponse<T> {
269
+ data: T;
270
+ }
271
+ /**
272
+ * Create/Update response
273
+ */
274
+ interface MutationResponse<T = string> {
275
+ data: T;
276
+ message?: string;
277
+ }
278
+ /**
279
+ * Delete response
280
+ */
281
+ interface DeleteResponse {
282
+ data: {
283
+ deleted: boolean;
284
+ count?: number;
285
+ };
286
+ message?: string;
287
+ }
288
+ /**
289
+ * Bulk operation response
290
+ */
291
+ interface BulkResponse<T = string[]> {
292
+ data: T;
293
+ message?: string;
294
+ errors?: Array<{
295
+ index: number;
296
+ error: string;
297
+ }>;
298
+ }
299
+ type FieldType = "String" | "Text" | "Integer" | "BigInt" | "Float" | "Double" | "Decimal" | "Boolean" | "Date" | "DateTime" | "Time" | "UUID" | "JSON" | "JSONB" | "Array" | "Geometry" | "Point" | "LineString" | "Polygon" | "Enum";
300
+ interface FieldDefinition {
301
+ type: FieldType;
302
+ primaryKey?: boolean;
303
+ allowNull?: boolean;
304
+ unique?: boolean;
305
+ defaultValue?: unknown;
306
+ values?: {
307
+ length?: number;
308
+ precision?: number;
309
+ scale?: number;
310
+ type?: string;
311
+ values?: string[];
312
+ };
313
+ validate?: {
314
+ min?: number;
315
+ max?: number;
316
+ len?: [number, number];
317
+ isEmail?: boolean;
318
+ isUrl?: boolean;
319
+ regex?: string;
320
+ };
321
+ comment?: string;
322
+ }
323
+ interface SchemaDefinition {
324
+ name: string;
325
+ timestamps?: boolean;
326
+ paranoid?: boolean;
327
+ fields: Record<string, FieldDefinition>;
328
+ indexes?: IndexDefinition[];
329
+ }
330
+ interface IndexDefinition {
331
+ name: string;
332
+ fields: string[];
333
+ unique?: boolean;
334
+ }
335
+ type RelationshipType = "M2O" | "O2M" | "M2M" | "M2A" | "O2O";
336
+ interface RelationshipDefinition {
337
+ type: RelationshipType;
338
+ target: string;
339
+ name: string;
340
+ alias?: string;
341
+ onDelete?: "CASCADE" | "RESTRICT" | "SET NULL";
342
+ onUpdate?: "CASCADE" | "RESTRICT" | "SET NULL";
343
+ tables?: string[];
344
+ }
345
+ interface SchemaInfo {
346
+ collectionName: string;
347
+ schema: SchemaDefinition;
348
+ relationships?: RelationshipDefinition[];
349
+ }
350
+ interface FileMetadata {
351
+ id: string;
352
+ title?: string;
353
+ description?: string;
354
+ filename: string;
355
+ mimeType: string;
356
+ size: number;
357
+ width?: number;
358
+ height?: number;
359
+ duration?: number;
360
+ storage: string;
361
+ path: string;
362
+ isPublic?: boolean;
363
+ uploadedBy?: string;
364
+ createdAt: string;
365
+ updatedAt?: string;
366
+ [key: string]: unknown;
367
+ }
368
+ interface UploadOptions {
369
+ title?: string;
370
+ description?: string;
371
+ folder?: string;
372
+ storage?: "local" | "s3";
373
+ isPublic?: boolean;
374
+ metadata?: Record<string, unknown>;
375
+ onProgress?: (progress: number) => void;
376
+ }
377
+ interface AssetTransformOptions {
378
+ width?: number;
379
+ height?: number;
380
+ fit?: "cover" | "contain" | "fill" | "inside" | "outside";
381
+ quality?: number;
382
+ format?: "jpeg" | "png" | "webp" | "avif";
383
+ }
384
+ type PermissionAction = "create" | "read" | "update" | "delete";
385
+ interface Permission {
386
+ id: string;
387
+ role_Id: string;
388
+ collection: string;
389
+ action: PermissionAction;
390
+ fields?: string[];
391
+ conditions?: Filter;
392
+ defaultValues?: Record<string, unknown>;
393
+ relConditions?: Record<string, Filter>;
394
+ }
395
+ interface CreatePermissionData {
396
+ role_Id: string;
397
+ collection: string;
398
+ action: PermissionAction;
399
+ fields?: string[];
400
+ conditions?: Filter;
401
+ defaultValues?: Record<string, unknown>;
402
+ relConditions?: Record<string, Filter>;
403
+ }
404
+ interface Notification {
405
+ id: string;
406
+ type: string;
407
+ title: string;
408
+ message: string;
409
+ data?: Record<string, unknown>;
410
+ seen: boolean;
411
+ user_Id: string;
412
+ createdAt: string;
413
+ }
414
+ interface SendNotificationData {
415
+ type?: string;
416
+ title: string;
417
+ message: string;
418
+ data?: Record<string, unknown>;
419
+ userIds: string[];
420
+ }
421
+ interface Workflow {
422
+ id: string;
423
+ name: string;
424
+ description?: string;
425
+ trigger: WorkflowTrigger;
426
+ nodes: WorkflowNode[];
427
+ edges: WorkflowEdge[];
428
+ isActive: boolean;
429
+ createdAt: string;
430
+ updatedAt?: string;
431
+ }
432
+ interface WorkflowTrigger {
433
+ type: "manual" | "webhook" | "schedule" | "hook";
434
+ config?: Record<string, unknown>;
435
+ }
436
+ interface WorkflowNode {
437
+ id: string;
438
+ type: string;
439
+ config: Record<string, unknown>;
440
+ position?: {
441
+ x: number;
442
+ y: number;
443
+ };
444
+ }
445
+ interface WorkflowEdge {
446
+ id: string;
447
+ source: string;
448
+ target: string;
449
+ condition?: string;
450
+ }
451
+ interface WorkflowExecution {
452
+ id: string;
453
+ workflow_Id: string;
454
+ status: "pending" | "running" | "completed" | "failed";
455
+ triggerData?: Record<string, unknown>;
456
+ result?: Record<string, unknown>;
457
+ error?: string;
458
+ startedAt: string;
459
+ completedAt?: string;
460
+ }
461
+ interface ReportConfig {
462
+ collection: string;
463
+ filter?: Filter;
464
+ groupBy?: string;
465
+ aggregate?: Aggregate;
466
+ dateRange?: {
467
+ start: string;
468
+ end: string;
469
+ field?: string;
470
+ };
471
+ }
472
+ interface ReportResult {
473
+ data: Record<string, unknown>[];
474
+ summary?: Record<string, unknown>;
475
+ }
476
+ interface BaasixErrorDetails {
477
+ code?: string;
478
+ field?: string;
479
+ message?: string;
480
+ [key: string]: unknown;
481
+ }
482
+ declare class BaasixError extends Error {
483
+ readonly status: number;
484
+ readonly code?: string;
485
+ readonly details?: BaasixErrorDetails[];
486
+ readonly isRetryable: boolean;
487
+ constructor(message: string, status?: number, code?: string, details?: BaasixErrorDetails[]);
488
+ toJSON(): {
489
+ name: string;
490
+ message: string;
491
+ status: number;
492
+ code: string | undefined;
493
+ details: BaasixErrorDetails[] | undefined;
494
+ };
495
+ }
496
+ /**
497
+ * Make all properties of T optional recursively
498
+ */
499
+ type DeepPartial<T> = {
500
+ [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
501
+ };
502
+ /**
503
+ * Extract the item type from a collection
504
+ */
505
+ type CollectionItem<T> = T extends Array<infer U> ? U : T;
506
+ /**
507
+ * Generic record type with ID
508
+ */
509
+ interface BaseItem {
510
+ id: string;
511
+ createdAt?: string;
512
+ updatedAt?: string;
513
+ deletedAt?: string;
514
+ [key: string]: unknown;
515
+ }
516
+ /**
517
+ * Settings configuration
518
+ */
519
+ interface Settings {
520
+ [key: string]: unknown;
521
+ }
522
+
523
+ interface RequestOptions extends RequestInit {
524
+ params?: Record<string, unknown>;
525
+ timeout?: number;
526
+ skipAuth?: boolean;
527
+ rawResponse?: boolean;
528
+ }
529
+ interface HttpClientConfig {
530
+ baseUrl: string;
531
+ authMode: AuthMode;
532
+ storage: StorageAdapter;
533
+ timeout: number;
534
+ autoRefresh: boolean;
535
+ credentials: RequestCredentials;
536
+ headers: Record<string, string>;
537
+ token?: string;
538
+ tenantId?: string;
539
+ onAuthError?: () => void;
540
+ onTokenRefresh?: (tokens: AuthTokens) => void;
541
+ }
542
+ /**
543
+ * Core HTTP client for making API requests.
544
+ * Handles authentication, token refresh, and error handling.
545
+ */
546
+ declare class HttpClient {
547
+ private config;
548
+ private refreshPromise;
549
+ constructor(config: HttpClientConfig);
550
+ /**
551
+ * Update client configuration
552
+ */
553
+ updateConfig(config: Partial<HttpClientConfig>): void;
554
+ /**
555
+ * Get the current base URL
556
+ */
557
+ getBaseUrl(): string;
558
+ /**
559
+ * Build the full URL with query parameters
560
+ */
561
+ private buildUrl;
562
+ /**
563
+ * Get the current access token
564
+ */
565
+ private getAccessToken;
566
+ /**
567
+ * Check if token is expired or about to expire (within 60 seconds)
568
+ */
569
+ private isTokenExpired;
570
+ /**
571
+ * Refresh the access token
572
+ */
573
+ private refreshToken;
574
+ /**
575
+ * Build request headers
576
+ */
577
+ private buildHeaders;
578
+ /**
579
+ * Parse error response
580
+ */
581
+ private parseError;
582
+ /**
583
+ * Make an HTTP request
584
+ */
585
+ request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
586
+ /**
587
+ * GET request
588
+ */
589
+ get<T>(path: string, options?: RequestOptions): Promise<T>;
590
+ /**
591
+ * POST request
592
+ */
593
+ post<T>(path: string, data?: unknown, options?: RequestOptions): Promise<T>;
594
+ /**
595
+ * PATCH request
596
+ */
597
+ patch<T>(path: string, data?: unknown, options?: RequestOptions): Promise<T>;
598
+ /**
599
+ * PUT request
600
+ */
601
+ put<T>(path: string, data?: unknown, options?: RequestOptions): Promise<T>;
602
+ /**
603
+ * DELETE request
604
+ */
605
+ delete<T>(path: string, options?: RequestOptions): Promise<T>;
606
+ /**
607
+ * Upload file with multipart/form-data
608
+ */
609
+ upload<T>(path: string, formData: FormData, options?: Omit<RequestOptions, "body"> & {
610
+ onProgress?: (progress: number) => void;
611
+ }): Promise<T>;
612
+ }
613
+
614
+ export { type WorkflowTrigger as $, type AuthMode as A, type BaseItem as B, type CreatePermissionData as C, type DeleteResponse as D, type FilterValue as E, type Filter as F, type FilterCondition as G, HttpClient as H, type IndexDefinition as I, type LogicalFilter as J, type SortDirection as K, type LoginCredentials as L, type MagicLinkOptions as M, type Notification as N, type AggregateFunction as O, type PasswordResetOptions as P, type QueryParams as Q, type RegisterData as R, type Sort as S, type Tenant as T, type User as U, type AggregateConfig as V, type Workflow as W, type FieldType as X, type FieldDefinition as Y, type RelationshipType as Z, type PermissionAction as _, type AuthStateEvent as a, type WorkflowNode as a0, type WorkflowEdge as a1, type BaasixErrorDetails as a2, BaasixError as a3, type DeepPartial as a4, type CollectionItem as a5, type AuthResponse as b, type AuthTokens as c, type AuthState as d, type PaginatedResponse as e, type BulkResponse as f, type MutationResponse as g, type SingleResponse as h, type UploadOptions as i, type FileMetadata as j, type AssetTransformOptions as k, type SchemaInfo as l, type SchemaDefinition as m, type RelationshipDefinition as n, type SendNotificationData as o, type Permission as p, type Role as q, type Settings as r, type ReportConfig as s, type ReportResult as t, type Aggregate as u, type WorkflowExecution as v, type BaasixConfig as w, type RequestOptions as x, type HttpClientConfig as y, type FilterOperator as z };