@rebasepro/types 0.8.0 → 0.9.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.
Files changed (78) hide show
  1. package/README.md +10 -10
  2. package/dist/controllers/auth.d.ts +1 -1
  3. package/dist/controllers/client.d.ts +184 -6
  4. package/dist/controllers/collection_registry.d.ts +3 -3
  5. package/dist/controllers/customization_controller.d.ts +1 -1
  6. package/dist/controllers/data.d.ts +267 -35
  7. package/dist/controllers/data_driver.d.ts +50 -37
  8. package/dist/controllers/index.d.ts +1 -1
  9. package/dist/controllers/local_config_persistence.d.ts +4 -4
  10. package/dist/controllers/navigation.d.ts +2 -2
  11. package/dist/controllers/registry.d.ts +17 -4
  12. package/dist/controllers/{side_entity_controller.d.ts → side_panel_controller.d.ts} +7 -7
  13. package/dist/controllers/storage.d.ts +39 -0
  14. package/dist/errors.d.ts +64 -0
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.es.js +142 -15
  17. package/dist/index.es.js.map +1 -1
  18. package/dist/index.umd.js +150 -17
  19. package/dist/index.umd.js.map +1 -1
  20. package/dist/rebase_context.d.ts +8 -4
  21. package/dist/types/auth_adapter.d.ts +4 -1
  22. package/dist/types/backend.d.ts +26 -26
  23. package/dist/types/builders.d.ts +2 -2
  24. package/dist/types/collections.d.ts +62 -63
  25. package/dist/types/component_overrides.d.ts +61 -3
  26. package/dist/types/cron.d.ts +10 -1
  27. package/dist/types/data_source.d.ts +15 -2
  28. package/dist/types/database_adapter.d.ts +4 -3
  29. package/dist/types/entities.d.ts +7 -7
  30. package/dist/types/entity_actions.d.ts +7 -7
  31. package/dist/types/entity_callbacks.d.ts +39 -39
  32. package/dist/types/entity_views.d.ts +3 -3
  33. package/dist/types/filter-operators.d.ts +62 -17
  34. package/dist/types/modify_collections.d.ts +2 -2
  35. package/dist/types/plugins.d.ts +9 -9
  36. package/dist/types/policy.d.ts +64 -10
  37. package/dist/types/properties.d.ts +41 -9
  38. package/dist/types/relations.d.ts +3 -3
  39. package/dist/types/slots.d.ts +14 -14
  40. package/dist/types/websockets.d.ts +12 -13
  41. package/dist/users/user.d.ts +21 -9
  42. package/package.json +1 -1
  43. package/src/controllers/auth.tsx +1 -1
  44. package/src/controllers/client.ts +214 -6
  45. package/src/controllers/collection_registry.ts +3 -3
  46. package/src/controllers/customization_controller.tsx +1 -1
  47. package/src/controllers/data.ts +290 -39
  48. package/src/controllers/data_driver.ts +49 -40
  49. package/src/controllers/index.ts +1 -1
  50. package/src/controllers/local_config_persistence.tsx +4 -4
  51. package/src/controllers/navigation.ts +2 -2
  52. package/src/controllers/registry.ts +18 -4
  53. package/src/controllers/{side_entity_controller.tsx → side_panel_controller.tsx} +7 -7
  54. package/src/controllers/storage.ts +60 -1
  55. package/src/errors.ts +80 -0
  56. package/src/index.ts +1 -0
  57. package/src/rebase_context.tsx +8 -4
  58. package/src/types/auth_adapter.ts +4 -1
  59. package/src/types/backend.ts +36 -36
  60. package/src/types/builders.ts +2 -2
  61. package/src/types/collections.ts +78 -79
  62. package/src/types/component_overrides.ts +72 -5
  63. package/src/types/cron.ts +10 -1
  64. package/src/types/data_source.ts +24 -2
  65. package/src/types/database_adapter.ts +4 -3
  66. package/src/types/entities.ts +7 -7
  67. package/src/types/entity_actions.tsx +7 -7
  68. package/src/types/entity_callbacks.ts +42 -42
  69. package/src/types/entity_views.tsx +3 -3
  70. package/src/types/filter-operators.ts +96 -23
  71. package/src/types/modify_collections.tsx +2 -2
  72. package/src/types/plugins.tsx +9 -9
  73. package/src/types/policy.ts +64 -8
  74. package/src/types/properties.ts +44 -9
  75. package/src/types/relations.ts +3 -3
  76. package/src/types/slots.tsx +14 -14
  77. package/src/types/websockets.ts +12 -14
  78. package/src/users/user.ts +22 -9
@@ -1,5 +1,5 @@
1
1
  import type { User } from "../users";
2
- import type { RebaseData } from "./data";
2
+ import type { RebaseSdkData } from "./data";
3
3
  import type { EmailService } from "./email";
4
4
  import type { StorageSource } from "./storage";
5
5
  import type { CronJobStatus, CronJobLogEntry } from "../types/cron";
@@ -13,7 +13,10 @@ import type { StorageSourceDefinition } from "../types/storage_source";
13
13
  export type AuthChangeEvent = "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "USER_UPDATED";
14
14
 
15
15
  /**
16
- * Standard session interface representing an authenticated state
16
+ * Standard session interface representing an authenticated state.
17
+ *
18
+ * There is exactly one canonical definition of this type (here in
19
+ * `@rebasepro/types`). The `@rebasepro/client` package re-exports it.
17
20
  */
18
21
  export interface RebaseSession {
19
22
  accessToken: string;
@@ -22,6 +25,38 @@ export interface RebaseSession {
22
25
  user: User;
23
26
  }
24
27
 
28
+ /**
29
+ * Access and refresh token pair returned by authentication endpoints.
30
+ *
31
+ * Replaces the former `RebaseTokens` (client) and `AuthTokens` (auth) types,
32
+ * which had identical shapes.
33
+ *
34
+ * @group Auth
35
+ */
36
+ export interface AuthTokens {
37
+ accessToken: string;
38
+ refreshToken: string;
39
+ /** Unix timestamp (ms) when the access token expires. */
40
+ accessTokenExpiresAt: number;
41
+ }
42
+
43
+ /**
44
+ * A device-level session entry as returned by `GET /auth/sessions`.
45
+ *
46
+ * Represents one refresh-token / device pair. Not to be confused with
47
+ * {@link RebaseSession}, which is the client-side representation of the
48
+ * *current* authenticated state (user + tokens).
49
+ *
50
+ * @group Auth
51
+ */
52
+ export interface DeviceSession {
53
+ id: string;
54
+ userAgent?: string;
55
+ ipAddress?: string;
56
+ createdAt: string;
57
+ isCurrentSession?: boolean;
58
+ }
59
+
25
60
  /**
26
61
  * Unified Authentication Client Interface
27
62
  * Pure functional SDK interface, decoupled from UI and React hooks
@@ -37,6 +72,13 @@ export interface AuthClient {
37
72
  */
38
73
  getSession(): RebaseSession | null;
39
74
 
75
+ /**
76
+ * Get the current user's active sessions
77
+ */
78
+ getSessions?: () => Promise<DeviceSession[]>;
79
+ revokeSession?: (sessionId: string) => Promise<void>;
80
+ revokeAllSessions?: () => Promise<void>;
81
+
40
82
  /**
41
83
  * Sign out the current user and clear local session
42
84
  */
@@ -56,7 +98,14 @@ export interface AuthClient {
56
98
  // ─── Admin API ───────────────────────────────────────────────────────────────
57
99
 
58
100
  /**
59
- * User record as returned by the Admin API.
101
+ * User record as returned by the Admin API (`GET /admin/users`, etc.).
102
+ *
103
+ * This is a dedicated DTO for admin operations and differs from {@link User}:
104
+ * - `roles` is required (always an array), vs optional on `User`
105
+ * - Includes audit timestamps (`createdAt`, `updatedAt`) as ISO strings
106
+ * - `email` is non-nullable (admin users always have an email)
107
+ *
108
+ * @see User — the canonical client-facing user type
60
109
  * @group Admin
61
110
  */
62
111
  export interface AdminUser {
@@ -64,7 +113,11 @@ export interface AdminUser {
64
113
  email: string;
65
114
  displayName: string | null;
66
115
  photoURL: string | null;
67
- provider: string;
116
+ /**
117
+ * The provider used to authenticate the user (e.g. `"password"`,
118
+ * `"google"`). Named to match the canonical {@link User.providerId}.
119
+ */
120
+ providerId: string;
68
121
  roles: string[];
69
122
  metadata?: Record<string, any>;
70
123
  createdAt: string;
@@ -139,6 +192,35 @@ export interface FunctionsAPI {
139
192
  invoke<T = unknown>(name: string, payload?: unknown, options?: FunctionInvokeOptions): Promise<T>;
140
193
  }
141
194
 
195
+ // ─── HistoryConfig ───────────────────────────────────────────────────────────
196
+
197
+ /**
198
+ * Configuration for entity history / audit-log tracking.
199
+ *
200
+ * - `true` — enable history with default settings
201
+ * - `{ retention?: number }` — enable with optional retention period in days
202
+ */
203
+ export type HistoryConfig = boolean | { retention?: number };
204
+
205
+ // ─── RebaseWebSocket ─────────────────────────────────────────────────────────
206
+
207
+ /**
208
+ * Minimal WebSocket client contract exposed on {@link RebaseClient}.
209
+ *
210
+ * The full implementation (`RebaseWebSocketClient` in `@rebasepro/client`)
211
+ * adds subscription helpers, CRUD-over-WS, SQL execution, etc.
212
+ */
213
+ export interface RebaseWebSocket {
214
+ /** Disconnect the WebSocket and stop reconnecting. */
215
+ disconnect(): void;
216
+ /** Send an authentication token to the server. */
217
+ authenticate(token: string): Promise<void>;
218
+ /** Set a function that lazily resolves the auth token for auto-authentication. */
219
+ setAuthTokenGetter(getter: () => Promise<string | null>): void;
220
+ /** Listen for connection lifecycle events. */
221
+ on(event: "connect" | "disconnect" | "reconnect" | "error", cb: (...args: unknown[]) => void): () => void;
222
+ }
223
+
142
224
  // ─── RebaseClient ────────────────────────────────────────────────────────────
143
225
 
144
226
  /**
@@ -153,7 +235,25 @@ export interface FunctionsAPI {
153
235
  */
154
236
  export interface RebaseClient<DB = unknown> {
155
237
  /** Unified Data access layer */
156
- data: RebaseData;
238
+ data: RebaseSdkData<DB>;
239
+
240
+ /**
241
+ * Admin-scoped, **RLS-bypassing** data accessor.
242
+ *
243
+ * Present on the **server** singleton only (see {@link RebaseServerClient}).
244
+ * It runs with `{ uid: "service", roles: ["admin"] }` — every read and write
245
+ * bypasses row-level-security policies. This is the correct tool for trusted
246
+ * background work (cron jobs, migrations, service-to-service tasks).
247
+ *
248
+ * ⚠️ **Do NOT use it to serve user-facing data.** Inside a request handler,
249
+ * user-scoped queries must go through the request-scoped driver
250
+ * (`c.var.driver`), which carries the caller's identity so RLS applies.
251
+ * Reaching for `dataAsAdmin` (or its alias {@link data}) in a request handler
252
+ * silently exposes every row to every caller.
253
+ *
254
+ * Undefined in the browser SDK.
255
+ */
256
+ dataAsAdmin?: RebaseSdkData<DB>;
157
257
 
158
258
  /** Unified Authentication layer */
159
259
  auth: AuthClient;
@@ -205,7 +305,7 @@ export interface RebaseClient<DB = unknown> {
205
305
  baseUrl?: string;
206
306
 
207
307
  /** WebSocket client for realtime subscriptions */
208
- ws?: unknown;
308
+ ws?: RebaseWebSocket;
209
309
 
210
310
  /** Set the auth token for subsequent requests */
211
311
  setToken?(token: string | null): void;
@@ -229,6 +329,114 @@ export interface RebaseClient<DB = unknown> {
229
329
  sql?(query: string, options?: { database?: string; role?: string }): Promise<Record<string, unknown>[]>;
230
330
  }
231
331
 
332
+ // ─── RebaseServerClient ──────────────────────────────────────────────────────
333
+
334
+ /**
335
+ * The server-side Rebase surface — the shape of the `rebase` singleton exported
336
+ * from `@rebasepro/server-core`.
337
+ *
338
+ * Narrows {@link RebaseClient} to the guarantees that always hold on the server:
339
+ * the admin-scoped {@link dataAsAdmin} accessor, raw {@link sql}, and the
340
+ * {@link email} service are all present (non-optional).
341
+ *
342
+ * **Trust levels.** Both {@link dataAsAdmin} and the deprecated {@link data}
343
+ * alias point at the same admin-scoped, **RLS-bypassing** driver. Prefer
344
+ * `dataAsAdmin` so the privilege is explicit at every call site. For user-scoped
345
+ * queries inside a request handler use the request-scoped driver
346
+ * (`c.var.driver`) instead — never `dataAsAdmin`/`data`.
347
+ */
348
+ export interface RebaseServerClient<DB = unknown> extends RebaseClient<DB> {
349
+ /**
350
+ * @deprecated On the server, prefer {@link dataAsAdmin} for admin scope or
351
+ * the request-scoped driver (`c.var.driver`) for user scope. This alias
352
+ * points at the same admin-scoped, RLS-bypassing accessor as `dataAsAdmin`.
353
+ */
354
+ data: RebaseSdkData<DB>;
355
+
356
+ /**
357
+ * Admin-scoped, **RLS-bypassing** data accessor. Always present server-side.
358
+ * See {@link RebaseClient.dataAsAdmin} for the full safety contract.
359
+ */
360
+ dataAsAdmin: RebaseSdkData<DB>;
361
+
362
+ /**
363
+ * Server-side email service. Always present server-side (a no-op sender is
364
+ * wired when SMTP is not configured).
365
+ */
366
+ email: EmailService;
367
+
368
+ /**
369
+ * Execute raw SQL against the database. Always present server-side for SQL
370
+ * engines.
371
+ */
372
+ sql(query: string, options?: { database?: string; role?: string }): Promise<Record<string, unknown>[]>;
373
+ }
374
+
375
+ // ─── RebaseBrowserClient ─────────────────────────────────────────────────────
376
+
377
+ /**
378
+ * The browser-side Rebase surface — the shape produced by
379
+ * `createRebaseClient()` in `@rebasepro/client`.
380
+ *
381
+ * Its {@link data} accessor is **user-scoped**: every call carries the signed-in
382
+ * user's token, so backend RLS policies apply. It deliberately omits the
383
+ * server-only members — there is no `sql`, no `email`, and no
384
+ * `dataAsAdmin`, so the RLS-bypassing accessor can never be reached from
385
+ * browser code.
386
+ */
387
+ export interface RebaseBrowserClient<DB = unknown> {
388
+ /** User-scoped data access layer (carries the signed-in user's token). */
389
+ data: RebaseSdkData<DB>;
390
+
391
+ /** Unified Authentication layer */
392
+ auth: AuthClient;
393
+
394
+ /** Unified Storage layer (default storage source, backward-compatible) */
395
+ storage?: StorageSource;
396
+
397
+ /** Registry of all named storage sources for multi-backend support */
398
+ storageRegistry?: StorageSourceRegistry;
399
+
400
+ /** Build a server-backed {@link StorageSource} for a named storage source. */
401
+ createStorageSource?(storageId: string): StorageSource;
402
+
403
+ /** Discover the storage sources declared on the backend. */
404
+ fetchStorageSources?(): Promise<StorageSourceDefinition[]>;
405
+
406
+ /** Admin API for user management */
407
+ admin?: AdminAPI;
408
+
409
+ /** Cron job management API */
410
+ cron?: CronAPI;
411
+
412
+ /** Custom backend functions API */
413
+ functions?: FunctionsAPI;
414
+
415
+ /** Service API keys management API */
416
+ apiKeys?: ApiKeysAPI;
417
+
418
+ /** Base HTTP URL of the backend server */
419
+ baseUrl?: string;
420
+
421
+ /** WebSocket client for realtime subscriptions */
422
+ ws?: RebaseWebSocket;
423
+
424
+ /** Set the auth token for subsequent requests */
425
+ setToken?(token: string | null): void;
426
+
427
+ /** Set a function that lazily resolves the auth token */
428
+ setAuthTokenGetter?(getter: () => Promise<string | null>): void;
429
+
430
+ /** Set handler called when a request returns 401 */
431
+ setOnUnauthorized?(handler: () => Promise<boolean>): void;
432
+
433
+ /** Resolve the current auth token */
434
+ resolveToken?(): Promise<string | null>;
435
+
436
+ /** Make a raw HTTP call to the backend */
437
+ call?<T = unknown>(endpoint: string, payload?: unknown): Promise<T>;
438
+ }
439
+
232
440
  /**
233
441
  * Client-side registry for managing multiple storage sources.
234
442
  *
@@ -1,4 +1,4 @@
1
- import type { EntityCollection } from "../types/collections";
1
+ import type { CollectionConfig } from "../types/collections";
2
2
  import type { EntityReference } from "../types/entities";
3
3
 
4
4
  /**
@@ -7,7 +7,7 @@ import type { EntityReference } from "../types/entities";
7
7
  */
8
8
  export type CollectionRegistryController<
9
9
  DB = Record<string, unknown>,
10
- EC extends EntityCollection = EntityCollection
10
+ EC extends CollectionConfig = CollectionConfig
11
11
  > = {
12
12
 
13
13
  /**
@@ -16,7 +16,7 @@ export type CollectionRegistryController<
16
16
  * Each of the navigation entries in this field
17
17
  * generates an entry in the main menu.
18
18
  */
19
- collections?: EntityCollection[];
19
+ collections?: CollectionConfig[];
20
20
 
21
21
  /**
22
22
  * Is the registry ready to be used
@@ -30,7 +30,7 @@ export type CustomizationController = {
30
30
  * You can use the key to reference the custom view in
31
31
  * the `entityViews` prop of a collection.
32
32
  *
33
- * You can also define an entity view from the UI.
33
+ * You can also define a entity view from the UI.
34
34
  */
35
35
  entityViews?: EntityCustomView[];
36
36