@rebasepro/server-core 0.3.0 → 0.5.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/README.md +62 -25
- package/dist/common/src/collections/default-collections.d.ts +5 -8
- package/dist/common/src/data/query_builder.d.ts +6 -2
- package/dist/common/src/util/permissions.d.ts +14 -6
- package/dist/index.es.js +393 -315
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +393 -315
- package/dist/index.umd.js.map +1 -1
- package/dist/server-core/src/api/errors.d.ts +15 -0
- package/dist/server-core/src/api/rest/query-parser.d.ts +2 -0
- package/dist/server-core/src/api/types.d.ts +2 -1
- package/dist/server-core/src/auth/jwt.d.ts +10 -0
- package/dist/server-core/src/email/types.d.ts +1 -0
- package/dist/server-core/src/init.d.ts +31 -1
- package/dist/types/src/controllers/auth.d.ts +2 -2
- package/dist/types/src/controllers/client.d.ts +25 -40
- package/dist/types/src/controllers/data.d.ts +21 -3
- package/dist/types/src/controllers/data_driver.d.ts +5 -0
- package/dist/types/src/controllers/email.d.ts +2 -0
- package/dist/types/src/types/auth_adapter.d.ts +3 -56
- package/dist/types/src/types/backend.d.ts +38 -3
- package/dist/types/src/types/backend_hooks.d.ts +2 -17
- package/dist/types/src/types/collections.d.ts +30 -6
- package/dist/types/src/types/entity_views.d.ts +19 -28
- package/dist/types/src/types/properties.d.ts +9 -15
- package/dist/types/src/types/user_management_delegate.d.ts +16 -53
- package/dist/types/src/users/index.d.ts +0 -1
- package/dist/types/src/users/user.d.ts +0 -1
- package/package.json +5 -5
- package/src/api/errors.ts +20 -1
- package/src/api/openapi-generator.ts +1 -1
- package/src/api/rest/api-generator.ts +82 -24
- package/src/api/rest/query-parser.ts +184 -63
- package/src/api/server.ts +1 -1
- package/src/api/types.ts +2 -1
- package/src/auth/admin-routes.ts +2 -91
- package/src/auth/builtin-auth-adapter.ts +9 -70
- package/src/auth/custom-auth-adapter.ts +1 -1
- package/src/auth/jwt.ts +10 -0
- package/src/auth/routes.ts +5 -9
- package/src/email/smtp-email-service.ts +31 -0
- package/src/email/types.ts +1 -0
- package/src/init.ts +135 -31
- package/src/storage/image-transform.ts +2 -1
- package/test/admin-routes.test.ts +0 -169
- package/test/backend-hooks-admin.test.ts +0 -25
- package/test/custom-auth-adapter.test.ts +2 -10
- package/test/smtp-email-service.test.ts +169 -0
- package/dist/types/src/users/roles.d.ts +0 -14
- package/test.ts +0 -6
package/README.md
CHANGED
|
@@ -1,40 +1,77 @@
|
|
|
1
|
-
# @rebasepro/
|
|
1
|
+
# @rebasepro/server-core
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
This package provides a complete backend solution for Rebase applications using PostgreSQL as the database and Drizzle ORM for type-safe database operations.
|
|
3
|
+
Database-agnostic backend core for Rebase.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
|
-
|
|
8
|
+
pnpm add @rebasepro/server-core
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
##
|
|
11
|
+
## What This Package Does
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
import { createBackend } from "@rebasepro/backend";
|
|
13
|
+
This is the central orchestrator for any Rebase backend. It provides the framework-level plumbing — HTTP routing (Hono), authentication middleware, storage, email, cron jobs, custom functions, and the REST/GraphQL API generator — without being coupled to any specific database. Database implementations are plugged in via driver packages like `@rebasepro/server-postgresql` or `@rebasepro/server-mongodb`.
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
## Key Exports
|
|
16
|
+
|
|
17
|
+
| Export | Description |
|
|
18
|
+
|--------|-------------|
|
|
19
|
+
| `initializeRebaseBackend(config)` | Main entry point. Wires up drivers, auth, storage, API routes, cron, and custom functions. Returns a `RebaseBackendInstance`. |
|
|
20
|
+
| `rebase` | Server-side singleton (`RebaseClient`). Available after init. Admin-level access to data, auth, email, and storage. |
|
|
21
|
+
| `loadEnv()` | Validates `process.env` against the Rebase env schema (Zod). Auto-generates dev secrets. Supports `extend` for custom vars. |
|
|
22
|
+
| `serveSPA(app, config)` | Mounts SPA static-file serving + index.html fallback on a Hono app. |
|
|
23
|
+
| `RebaseBackendConfig` | Config type for `initializeRebaseBackend`. |
|
|
24
|
+
| `RebaseAuthConfig` | Auth config type (JWT, OAuth providers, hooks, service key). |
|
|
25
|
+
| `RebaseBackendInstance` | Return type — includes `driver`, `healthCheck()`, `shutdown()`, `cronScheduler`, `storageController`, etc. |
|
|
26
|
+
| `RebaseEnv` | Zod-inferred type of validated environment variables. |
|
|
27
|
+
| `z` | Re-exported Zod instance for extending `loadEnv`. |
|
|
28
|
+
| `_setRebaseMock` / `_resetRebaseMock` | Test helpers to mock the `rebase` singleton (NODE_ENV=test only). |
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
Also re-exports all abstract interfaces (`DatabaseAdapter`, `AuthAdapter`, `DataDriver`, etc.), API types (`HonoEnv`, `ApiConfig`), auth module, email module, storage module, history module, cron module, custom functions, logging utilities, and driver registry.
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
- Drizzle ORM integration
|
|
29
|
-
- Type-safe database operations
|
|
30
|
-
- Full Rebase compatibility
|
|
31
|
-
- Migration support
|
|
32
|
-
- Connection pooling
|
|
32
|
+
## Quick Start
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
```typescript
|
|
35
|
+
import { serve } from "@hono/node-server";
|
|
36
|
+
import { Hono } from "hono";
|
|
37
|
+
import { initializeRebaseBackend, loadEnv, serveSPA } from "@rebasepro/server-core";
|
|
38
|
+
import { createPostgresAdapter } from "@rebasepro/server-postgresql";
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
// 1. Load and validate environment
|
|
41
|
+
const env = loadEnv();
|
|
42
|
+
|
|
43
|
+
// 2. Create Hono app + HTTP server
|
|
44
|
+
const app = new Hono();
|
|
45
|
+
const server = serve({ fetch: app.fetch, port: env.PORT });
|
|
46
|
+
|
|
47
|
+
// 3. Initialize Rebase
|
|
48
|
+
const backend = await initializeRebaseBackend({
|
|
49
|
+
app,
|
|
50
|
+
server,
|
|
51
|
+
database: createPostgresAdapter({ connection: db, schema }),
|
|
52
|
+
collections: myCollections,
|
|
53
|
+
auth: {
|
|
54
|
+
collection: defaultUsersCollection,
|
|
55
|
+
jwtSecret: env.JWT_SECRET,
|
|
56
|
+
allowRegistration: env.ALLOW_REGISTRATION,
|
|
57
|
+
serviceKey: env.REBASE_SERVICE_KEY,
|
|
58
|
+
google: { clientId: env.GOOGLE_CLIENT_ID },
|
|
59
|
+
},
|
|
60
|
+
storage: { type: "s3", bucket: env.S3_BUCKET },
|
|
61
|
+
functionsDir: "./functions",
|
|
62
|
+
cronsDir: "./crons",
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// 4. Optionally serve a frontend SPA
|
|
66
|
+
serveSPA(app, { frontendPath: "./frontend/dist" });
|
|
67
|
+
```
|
|
37
68
|
|
|
38
|
-
##
|
|
69
|
+
## Related Packages
|
|
39
70
|
|
|
40
|
-
|
|
71
|
+
| Package | Role |
|
|
72
|
+
|---------|------|
|
|
73
|
+
| `@rebasepro/server-postgresql` | PostgreSQL database driver (Drizzle ORM) |
|
|
74
|
+
| `@rebasepro/server-mongodb` | MongoDB database driver |
|
|
75
|
+
| `@rebasepro/types` | Shared type definitions (`DataDriver`, `EntityCollection`, etc.) |
|
|
76
|
+
| `@rebasepro/client` | Client SDK used internally by the `rebase` singleton |
|
|
77
|
+
| `@rebasepro/common` | Shared utilities and default collections |
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { PostgresCollection } from "@rebasepro/types";
|
|
1
|
+
import type { PostgresCollection } from "@rebasepro/types";
|
|
2
2
|
/**
|
|
3
|
-
* Default users collection
|
|
3
|
+
* Default users collection.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* (Map keyed by slug, last-write-wins) so that developer-defined
|
|
9
|
-
* collections with the same slug override this default — no hardcoded
|
|
10
|
-
* string checks required.
|
|
5
|
+
* Prepended to the developer's collections array by the admin and server.
|
|
6
|
+
* Slug-based dedup (Map keyed by slug, last-write-wins) lets developers
|
|
7
|
+
* override by defining their own collection with `slug: "users"`.
|
|
11
8
|
*/
|
|
12
9
|
export declare const defaultUsersCollection: PostgresCollection;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { FindResponse, CollectionAccessor, QueryBuilderInterface, FilterOperator } from "@rebasepro/types";
|
|
1
|
+
import { FindResponse, CollectionAccessor, QueryBuilderInterface, FilterOperator, LogicalCondition, WhereValue, FilterCondition } from "@rebasepro/types";
|
|
2
|
+
export declare function or(...conditions: (FilterCondition | LogicalCondition)[]): LogicalCondition;
|
|
3
|
+
export declare function and(...conditions: (FilterCondition | LogicalCondition)[]): LogicalCondition;
|
|
4
|
+
export declare function cond(column: string, operator: FilterOperator, value: unknown): FilterCondition;
|
|
2
5
|
export declare class QueryBuilder<M extends Record<string, unknown> = Record<string, unknown>> implements QueryBuilderInterface<M> {
|
|
3
6
|
private collection;
|
|
4
7
|
private params;
|
|
@@ -8,7 +11,8 @@ export declare class QueryBuilder<M extends Record<string, unknown> = Record<str
|
|
|
8
11
|
* @example
|
|
9
12
|
* client.collection('users').where('age', '>=', 18).find()
|
|
10
13
|
*/
|
|
11
|
-
where
|
|
14
|
+
where<K extends keyof M & string>(column: K, operator: FilterOperator, value: WhereValue<M[K]>): this;
|
|
15
|
+
where(logicalCondition: LogicalCondition): this;
|
|
12
16
|
/**
|
|
13
17
|
* Order the results by a specific column.
|
|
14
18
|
* @example
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Entity, EntityCollection, User } from "@rebasepro/types";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal auth context for permission checking.
|
|
4
|
+
* Only requires the user object — avoids forcing callers to construct
|
|
5
|
+
* a full AuthController just to check permissions.
|
|
6
|
+
*/
|
|
7
|
+
export interface AuthContext<USER extends User = User> {
|
|
8
|
+
user: USER | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function checkOperation<M extends Record<string, unknown>, USER extends User>(collection: EntityCollection<M>, authContext: AuthContext<USER>, entity: Entity<M> | null, targetOperation: "select" | "insert" | "update" | "delete"): boolean;
|
|
11
|
+
export declare function canReadCollection<M extends Record<string, unknown>, USER extends User>(collection: EntityCollection<M>, authContext: AuthContext<USER>): boolean;
|
|
12
|
+
export declare function canEditEntity<M extends Record<string, unknown>, USER extends User>(collection: EntityCollection<M>, authContext: AuthContext<USER>, path: string, entity: Entity<M> | null): boolean;
|
|
13
|
+
export declare function canCreateEntity<M extends Record<string, unknown>, USER extends User>(collection: EntityCollection<M>, authContext: AuthContext<USER>, path: string, entity: Entity<M> | null): boolean;
|
|
14
|
+
export declare function canDeleteEntity<M extends Record<string, unknown>, USER extends User>(collection: EntityCollection<M>, authContext: AuthContext<USER>, path: string, entity: Entity<M> | null): boolean;
|