@rebasepro/server 0.9.1-canary.f2f61da → 0.9.1-canary.fd3754b
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/api/rest/api-generator.d.ts +1 -13
- package/dist/auth/api-keys/api-key-middleware.d.ts +1 -60
- package/dist/auth/api-keys/api-key-permission-guard.d.ts +0 -33
- package/dist/auth/api-keys/api-key-types.d.ts +8 -21
- package/dist/auth/api-keys/index.d.ts +2 -2
- package/dist/auth/index.d.ts +1 -4
- package/dist/auth/jwt.d.ts +1 -12
- package/dist/auth/middleware.d.ts +0 -21
- package/dist/auth/rate-limiter.d.ts +6 -68
- package/dist/env.d.ts +0 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +232 -994
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +48745 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/init/middlewares.d.ts +0 -1
- package/dist/init.d.ts +0 -41
- package/dist/{jwt-BJzQOa8a.js → jwt-BwIn8xmk.js} +5 -173
- package/dist/jwt-BwIn8xmk.js.map +1 -0
- package/dist/ms-DnYXB-Wd.js +162 -0
- package/dist/ms-DnYXB-Wd.js.map +1 -0
- package/dist/{openapi-generator-DqSIwNLV.js → openapi-generator-Z9oYWLf_.js} +2 -8
- package/dist/openapi-generator-Z9oYWLf_.js.map +1 -0
- package/dist/{src-CsHhSKbi.js → src-B4OLmNVa.js} +2 -60
- package/dist/src-B4OLmNVa.js.map +1 -0
- package/dist/src-B9tjYmqP.js +24598 -0
- package/dist/src-B9tjYmqP.js.map +1 -0
- package/package.json +11 -11
- package/dist/api/rest/write-validation.d.ts +0 -19
- package/dist/auth/collection-callback-warning.d.ts +0 -21
- package/dist/auth/rate-limit-store.d.ts +0 -49
- package/dist/jwt-BJzQOa8a.js.map +0 -1
- package/dist/openapi-generator-DqSIwNLV.js.map +0 -1
- package/dist/src-CsHhSKbi.js.map +0 -1
- package/dist/utils/compression.d.ts +0 -16
|
@@ -5,15 +5,12 @@ import { HonoEnv } from "../types";
|
|
|
5
5
|
* Lightweight REST API generator that leverages existing Rebase DataDriver.
|
|
6
6
|
* Supports `include` query parameter for eager-loading relations via Drizzle.
|
|
7
7
|
*/
|
|
8
|
-
/** Rows accepted by a single POST /<collection>/bulk. See `maxBulkRows`. */
|
|
9
|
-
export declare const DEFAULT_MAX_BULK_ROWS = 1000;
|
|
10
8
|
export declare class RestApiGenerator {
|
|
11
9
|
private collections;
|
|
12
10
|
private router;
|
|
13
11
|
private driver;
|
|
14
|
-
private maxBulkRows;
|
|
15
12
|
private authAdapter?;
|
|
16
|
-
constructor(collections: CollectionConfig[], driver: DataDriver, authAdapter?: AuthAdapter
|
|
13
|
+
constructor(collections: CollectionConfig[], driver: DataDriver, authAdapter?: AuthAdapter);
|
|
17
14
|
/**
|
|
18
15
|
* Generate REST routes using existing DataDriver
|
|
19
16
|
*/
|
|
@@ -24,15 +21,6 @@ export declare class RestApiGenerator {
|
|
|
24
21
|
* No-ops if the request is not authenticated via an API key.
|
|
25
22
|
*/
|
|
26
23
|
private enforceApiKeyPermission;
|
|
27
|
-
/**
|
|
28
|
-
* API key permission check for nested paths. The operation targets the
|
|
29
|
-
* LAST collection in the path (e.g. "posts" for /authors/1/posts), so
|
|
30
|
-
* that is the slug the key must hold permission for — checking the
|
|
31
|
-
* parent instead would let a key scoped to "authors" write "posts".
|
|
32
|
-
* `parseSubPath` always yields a collectionPath ending in a collection
|
|
33
|
-
* slug, never an id.
|
|
34
|
-
*/
|
|
35
|
-
private enforceSubcollectionApiKeyPermission;
|
|
36
24
|
/**
|
|
37
25
|
* Get the request-scoped driver. Throws if none is set — never falls
|
|
38
26
|
* back to the unscoped `this.driver` to avoid bypassing RLS/auth.
|
|
@@ -10,18 +10,9 @@
|
|
|
10
10
|
* 4. Sets `c.set("user", ...)` and `c.set("apiKey", ...)` for downstream use
|
|
11
11
|
* 5. Scopes the DataDriver via `withAuth()` using the API key's service identity
|
|
12
12
|
*
|
|
13
|
-
* Authorization is double-gated for API keys: the key's own permission list
|
|
14
|
-
* (checked by the REST generator) is one ceiling, and Postgres RLS is another,
|
|
15
|
-
* independent one — `withAuth()` runs API-key requests as the restricted
|
|
16
|
-
* `rebase_user` role like any other caller. An `admin` key passes RLS via the
|
|
17
|
-
* injected `default_admin` policies; a non-admin key (roles `["service"]`,
|
|
18
|
-
* uid `api-key:<id>`) only sees rows that a policy explicitly grants to the
|
|
19
|
-
* `service` role or to the public. Owner-style policies
|
|
20
|
-
* (`owner_id = auth.uid()`) never match an API key's synthetic uid.
|
|
21
|
-
*
|
|
22
13
|
* @module
|
|
23
14
|
*/
|
|
24
|
-
import type { Context
|
|
15
|
+
import type { Context } from "hono";
|
|
25
16
|
import type { DataDriver } from "@rebasepro/types";
|
|
26
17
|
import type { HonoEnv } from "../../api/types";
|
|
27
18
|
import type { ApiKeyStore } from "./api-key-store";
|
|
@@ -46,53 +37,3 @@ export interface ApiKeyAuthOptions {
|
|
|
46
37
|
* `createAuthMiddleware()` when a `rk_` prefixed token is detected.
|
|
47
38
|
*/
|
|
48
39
|
export declare function validateApiKey(c: Context<HonoEnv>, token: string, options: ApiKeyAuthOptions): Promise<Response | true>;
|
|
49
|
-
/**
|
|
50
|
-
* Permission guard for API-key requests to the storage router.
|
|
51
|
-
*
|
|
52
|
-
* Storage previously did not accept API keys at all (`rk_` tokens were
|
|
53
|
-
* misparsed as JWTs and 401'd). Now that the pre-auth middleware
|
|
54
|
-
* authenticates them, this guard decides what they may do: the key needs a
|
|
55
|
-
* `"storage"` permission entry (or the global `"*"` wildcard) covering the
|
|
56
|
-
* operation derived from the HTTP method. Requests not authenticated via an
|
|
57
|
-
* API key pass through to the storage router's own auth gates.
|
|
58
|
-
*
|
|
59
|
-
* TUS resumable-upload routes (`/tus`, `/tus/:id`) are classified as `write`
|
|
60
|
-
* for EVERY method: the protocol's offset check is a GET and its cancel is a
|
|
61
|
-
* DELETE, but both are steps of an upload — a write-scoped key must be able
|
|
62
|
-
* to complete (and abort) its own resumable upload without also holding
|
|
63
|
-
* `read`/`delete` on stored objects.
|
|
64
|
-
*/
|
|
65
|
-
export declare function createStorageApiKeyGuard(): MiddlewareHandler<HonoEnv>;
|
|
66
|
-
/**
|
|
67
|
-
* Permission guard for API-key requests to the custom-functions router.
|
|
68
|
-
*
|
|
69
|
-
* The collection permission guard lives in the REST generator and never sees
|
|
70
|
-
* function routes, so before this middleware existed ANY valid API key —
|
|
71
|
-
* however narrowly scoped — could invoke every custom function. This guard
|
|
72
|
-
* closes that: API-key requests must hold a `"functions"`/`"functions/<name>"`
|
|
73
|
-
* permission entry (or the global `"*"` wildcard) for the derived operation.
|
|
74
|
-
*
|
|
75
|
-
* Non-API-key requests (JWT, service key, anonymous) pass through untouched —
|
|
76
|
-
* functions decide their own auth for those, as before.
|
|
77
|
-
*
|
|
78
|
-
* @param mountPrefix - The path the functions router is mounted at
|
|
79
|
-
* (e.g. `/api/functions`), used to extract the function
|
|
80
|
-
* name from the request path.
|
|
81
|
-
*/
|
|
82
|
-
export declare function createFunctionApiKeyGuard(mountPrefix: string): MiddlewareHandler<HonoEnv>;
|
|
83
|
-
/**
|
|
84
|
-
* Standalone pre-auth middleware for `rk_` bearer tokens.
|
|
85
|
-
*
|
|
86
|
-
* Routers whose auth gate is JWT-based (`requireAuth` / `createRequireAuth` —
|
|
87
|
-
* the admin surfaces: admin users/roles, api-keys management, cron, backups,
|
|
88
|
-
* logs, schema editor) don't know about API keys. Mounting this middleware in
|
|
89
|
-
* front of them authenticates `rk_` tokens and populates the request context;
|
|
90
|
-
* the downstream gates then see the already-resolved user and apply their
|
|
91
|
-
* role checks (`requireAdmin`) as usual — so an `admin: true` key passes and
|
|
92
|
-
* a non-admin key is rejected with 403.
|
|
93
|
-
*
|
|
94
|
-
* Requests without an `rk_` bearer token pass through untouched. An invalid,
|
|
95
|
-
* revoked, or expired `rk_` token is rejected here (401) rather than falling
|
|
96
|
-
* through to be misparsed as a JWT.
|
|
97
|
-
*/
|
|
98
|
-
export declare function createApiKeyPreAuth(options: ApiKeyAuthOptions): MiddlewareHandler<HonoEnv>;
|
|
@@ -30,36 +30,3 @@ export declare function httpMethodToOperation(method: string): ApiKeyOperation;
|
|
|
30
30
|
* @returns `true` if the operation is permitted.
|
|
31
31
|
*/
|
|
32
32
|
export declare function isOperationAllowed(permissions: ApiKeyPermission[], collection: string, operation: ApiKeyOperation): boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Check whether the given permissions array allows a storage operation.
|
|
35
|
-
*
|
|
36
|
-
* Storage, like functions, lives outside the collection namespace: an entry
|
|
37
|
-
* with collection `"storage"` grants storage access for the listed
|
|
38
|
-
* operations (GET routes → `read`, upload/folder/tus → `write`,
|
|
39
|
-
* DELETE routes → `delete`), and the global `"*"` wildcard also matches.
|
|
40
|
-
* A collection-scoped key gets no storage access at all.
|
|
41
|
-
*
|
|
42
|
-
* Matching is exactly {@link isOperationAllowed} with `"storage"` as the
|
|
43
|
-
* resource name — delegated so the semantics can never drift.
|
|
44
|
-
*/
|
|
45
|
-
export declare function isStorageAllowed(permissions: ApiKeyPermission[], operation: ApiKeyOperation): boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Check whether the given permissions array allows invoking a custom function.
|
|
48
|
-
*
|
|
49
|
-
* Functions live outside the collection namespace, so they have their own
|
|
50
|
-
* resource names in the permission list:
|
|
51
|
-
*
|
|
52
|
-
* - `{ collection: "functions", ... }` grants every function
|
|
53
|
-
* - `{ collection: "functions/<name>", ... }` grants a single function
|
|
54
|
-
* - the global `"*"` wildcard (full-access keys) also matches
|
|
55
|
-
*
|
|
56
|
-
* The operation is derived from the HTTP method as usual (GET → read,
|
|
57
|
-
* POST/PUT/PATCH → write, DELETE → delete). The functions index route is
|
|
58
|
-
* checked as `functionName === ""`, which only the `"functions"` and `"*"`
|
|
59
|
-
* entries can grant.
|
|
60
|
-
*
|
|
61
|
-
* A collection-scoped key (e.g. read-only on `events`) therefore can NOT
|
|
62
|
-
* invoke functions — before this guard existed, any valid key could call
|
|
63
|
-
* every function.
|
|
64
|
-
*/
|
|
65
|
-
export declare function isFunctionAllowed(permissions: ApiKeyPermission[], functionName: string, operation: ApiKeyOperation): boolean;
|
|
@@ -10,13 +10,10 @@
|
|
|
10
10
|
/**
|
|
11
11
|
* A single permission entry scoping an API key to a collection and set of operations.
|
|
12
12
|
*
|
|
13
|
-
* Use `"*"` as the collection value to grant access to all collections
|
|
14
|
-
* (and all custom functions). Custom functions are addressed with the
|
|
15
|
-
* `functions` namespace: `"functions"` grants every function,
|
|
16
|
-
* `"functions/<name>"` grants a single one.
|
|
13
|
+
* Use `"*"` as the collection value to grant access to all collections.
|
|
17
14
|
*/
|
|
18
15
|
export interface ApiKeyPermission {
|
|
19
|
-
/** Collection slug,
|
|
16
|
+
/** Collection slug, or `"*"` for all collections. */
|
|
20
17
|
collection: string;
|
|
21
18
|
/** Allowed operations on the collection. */
|
|
22
19
|
operations: ("read" | "write" | "delete")[];
|
|
@@ -33,19 +30,9 @@ export interface ApiKey {
|
|
|
33
30
|
/** SHA-256 hash of the full plaintext key. */
|
|
34
31
|
key_hash: string;
|
|
35
32
|
permissions: ApiKeyPermission[];
|
|
36
|
-
/**
|
|
37
|
-
* When true, the key is granted the `admin` role: it passes the
|
|
38
|
-
* admin-gated routes (users, roles, cron, backups, logs, API keys) and
|
|
39
|
-
* the RLS `default_admin` policies. Non-admin keys carry only the
|
|
40
|
-
* `service` role — RLS grants them nothing unless a collection policy
|
|
41
|
-
* explicitly names that role.
|
|
42
|
-
*/
|
|
33
|
+
/** When true, the key is granted the `admin` role (access to admin routes). */
|
|
43
34
|
admin: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Requests per 15-minute window. `null` means "no per-key override" —
|
|
46
|
-
* the data rate limiter then applies its default API-key limit
|
|
47
|
-
* (1000/window unless configured otherwise), not unlimited.
|
|
48
|
-
*/
|
|
35
|
+
/** Requests per 15-minute window. `null` means unlimited. */
|
|
49
36
|
rate_limit: number | null;
|
|
50
37
|
created_by: string;
|
|
51
38
|
created_at: string;
|
|
@@ -63,7 +50,7 @@ export interface ApiKeyMasked {
|
|
|
63
50
|
name: string;
|
|
64
51
|
key_prefix: string;
|
|
65
52
|
permissions: ApiKeyPermission[];
|
|
66
|
-
/** When true, the key is granted the `admin` role (admin routes
|
|
53
|
+
/** When true, the key is granted the `admin` role (access to admin routes). */
|
|
67
54
|
admin: boolean;
|
|
68
55
|
rate_limit: number | null;
|
|
69
56
|
created_by: string;
|
|
@@ -79,9 +66,9 @@ export interface ApiKeyMasked {
|
|
|
79
66
|
export interface CreateApiKeyRequest {
|
|
80
67
|
name: string;
|
|
81
68
|
permissions: ApiKeyPermission[];
|
|
82
|
-
/** When true, grants the `admin` role
|
|
69
|
+
/** When true, grants the `admin` role — allows access to admin routes. */
|
|
83
70
|
admin?: boolean;
|
|
84
|
-
/** Requests per 15-minute window. Omit or `null`
|
|
71
|
+
/** Requests per 15-minute window. Omit or `null` for unlimited. */
|
|
85
72
|
rate_limit?: number | null;
|
|
86
73
|
/** ISO-8601 expiration timestamp. Omit for no expiration. */
|
|
87
74
|
expires_at?: string | null;
|
|
@@ -93,7 +80,7 @@ export interface CreateApiKeyRequest {
|
|
|
93
80
|
export interface UpdateApiKeyRequest {
|
|
94
81
|
name?: string;
|
|
95
82
|
permissions?: ApiKeyPermission[];
|
|
96
|
-
/** When true, grants the `admin` role
|
|
83
|
+
/** When true, grants the `admin` role — allows access to admin routes. */
|
|
97
84
|
admin?: boolean;
|
|
98
85
|
rate_limit?: number | null;
|
|
99
86
|
expires_at?: string | null;
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
export type { ApiKey, ApiKeyMasked, ApiKeyPermission, ApiKeyWithSecret, CreateApiKeyRequest, UpdateApiKeyRequest } from "./api-key-types";
|
|
10
10
|
export { createApiKeyStore } from "./api-key-store";
|
|
11
11
|
export type { ApiKeyStore } from "./api-key-store";
|
|
12
|
-
export { isApiKeyToken, validateApiKey
|
|
12
|
+
export { isApiKeyToken, validateApiKey } from "./api-key-middleware";
|
|
13
13
|
export type { ApiKeyAuthOptions } from "./api-key-middleware";
|
|
14
|
-
export { httpMethodToOperation, isOperationAllowed
|
|
14
|
+
export { httpMethodToOperation, isOperationAllowed } from "./api-key-permission-guard";
|
|
15
15
|
export type { ApiKeyOperation } from "./api-key-permission-guard";
|
|
16
16
|
export { createApiKeyRoutes } from "./api-key-routes";
|
|
17
17
|
export type { ApiKeyRouteOptions } from "./api-key-routes";
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -28,10 +28,7 @@ export type { AuthModuleConfig, CookieAuthConfig } from "./routes";
|
|
|
28
28
|
export { mountMagicLinkRoutes } from "./magic-link-routes";
|
|
29
29
|
export { createResetPasswordRoute } from "./reset-password-admin";
|
|
30
30
|
export type { ResetPasswordRouteConfig } from "./reset-password-admin";
|
|
31
|
-
export { createRateLimiter, defaultAuthLimiter, strictAuthLimiter, createApiKeyRateLimiter,
|
|
32
|
-
export type { DataRateLimitConfig } from "./rate-limiter";
|
|
33
|
-
export { MemoryRateLimitStore } from "./rate-limit-store";
|
|
34
|
-
export type { RateLimitStore, RateLimitDecision } from "./rate-limit-store";
|
|
31
|
+
export { createRateLimiter, defaultAuthLimiter, strictAuthLimiter, createApiKeyRateLimiter, apiKeyKeyGenerator } from "./rate-limiter";
|
|
35
32
|
export { createApiKeyStore, createApiKeyRoutes, isApiKeyToken, validateApiKey, httpMethodToOperation, isOperationAllowed } from "./api-keys";
|
|
36
33
|
export type { ApiKey, ApiKeyMasked, ApiKeyPermission, ApiKeyWithSecret, CreateApiKeyRequest, UpdateApiKeyRequest, ApiKeyStore, ApiKeyOperation } from "./api-keys";
|
|
37
34
|
export { createBuiltinAuthAdapter } from "./builtin-auth-adapter";
|
package/dist/auth/jwt.d.ts
CHANGED
|
@@ -38,18 +38,7 @@ export declare function getAccessTokenExpiryMs(): number;
|
|
|
38
38
|
*/
|
|
39
39
|
export declare function getAccessTokenExpiry(): number;
|
|
40
40
|
/**
|
|
41
|
-
* Verify and decode an access token
|
|
42
|
-
*
|
|
43
|
-
* Every token this server issues is signed with the same secret, so what a
|
|
44
|
-
* token *is* comes from its claims, not from its signature. A download token
|
|
45
|
-
* ({@link generateDownloadToken}) is therefore a validly-signed string that
|
|
46
|
-
* must never authenticate anybody: it is scoped to one file path and handed out
|
|
47
|
-
* in URLs, which is a far weaker thing to hold than a session.
|
|
48
|
-
*
|
|
49
|
-
* Today it is rejected below for want of an id — but only by luck, since
|
|
50
|
-
* nothing stops a future download token from carrying one. So the purpose is
|
|
51
|
-
* checked explicitly: a token minted for reading a file is not a token for
|
|
52
|
-
* being a user.
|
|
41
|
+
* Verify and decode an access token
|
|
53
42
|
*/
|
|
54
43
|
export declare function verifyAccessToken(token: string): AccessTokenPayload | null;
|
|
55
44
|
/**
|
|
@@ -150,27 +150,6 @@ export declare const queryTokenAuth: MiddlewareHandler<HonoEnv>;
|
|
|
150
150
|
* untouched, so they still require a valid token.
|
|
151
151
|
*/
|
|
152
152
|
export declare const publicObjectAuth: MiddlewareHandler<HonoEnv>;
|
|
153
|
-
/**
|
|
154
|
-
* Helper to match paths for scoped file tokens.
|
|
155
|
-
* Matches exact paths or prefixes (exact folder prefixes or ending with /).
|
|
156
|
-
*
|
|
157
|
-
* The traversal check is defence in depth, not the load-bearing defence.
|
|
158
|
-
*
|
|
159
|
-
* A prefix comparison is a lie for any path containing `..`: `user1/../user2/x`
|
|
160
|
-
* starts with `user1/`, so a token scoped to `user1/` would authorize reading
|
|
161
|
-
* user2's file — and the storage controller would not object, because its own
|
|
162
|
-
* guard stops a path escaping the *bucket*, and that one resolves to `user2/x`,
|
|
163
|
-
* comfortably inside it. The grant is what would be escaped, and this is the
|
|
164
|
-
* only layer that knows what was granted.
|
|
165
|
-
*
|
|
166
|
-
* Nothing arrives here in that shape today: the URL parser resolves `..` (and
|
|
167
|
-
* `%2e%2e`, which the WHATWG spec treats as a dot for normalization) before
|
|
168
|
-
* Hono routes the request, so this comparison already runs on a resolved path.
|
|
169
|
-
* But that is a guarantee of the runtime rather than of this code, and it is
|
|
170
|
-
* one line to not depend on it. The same rule already guards the public-object
|
|
171
|
-
* path — see `isPublicStoragePath`.
|
|
172
|
-
*/
|
|
173
|
-
export declare function isPathMatch(requested: string, allowed: string): boolean;
|
|
174
153
|
/**
|
|
175
154
|
* Middleware that authenticates file-serving routes using scoped download tokens.
|
|
176
155
|
* It enforces that only scoped "file-read" tokens can access "/file/*" and "?token=" query params.
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { MiddlewareHandler } from "hono";
|
|
2
2
|
import { HonoEnv } from "../api/types";
|
|
3
|
-
import { RateLimitStore } from "./rate-limit-store";
|
|
4
|
-
/**
|
|
5
|
-
* Sliding-window rate limiting for Hono.
|
|
6
|
-
*
|
|
7
|
-
* The counting lives in a {@link RateLimitStore} — in this process's memory by
|
|
8
|
-
* default, which is a per-replica limit and says so. See `rate-limit-store.ts`.
|
|
9
|
-
*/
|
|
10
3
|
interface RateLimiterOptions {
|
|
11
4
|
/** Time window in milliseconds (default: 15 minutes) */
|
|
12
5
|
windowMs?: number;
|
|
@@ -16,32 +9,13 @@ interface RateLimiterOptions {
|
|
|
16
9
|
keyGenerator?: (c: Parameters<MiddlewareHandler<HonoEnv>>[0]) => string;
|
|
17
10
|
/** Custom message for rate limit responses */
|
|
18
11
|
message?: string;
|
|
19
|
-
/**
|
|
20
|
-
* Where to keep the counts. Defaults to a private in-memory store — pass a
|
|
21
|
-
* shared one to have several limiters (or several processes) agree.
|
|
22
|
-
*/
|
|
23
|
-
store?: RateLimitStore;
|
|
24
|
-
/**
|
|
25
|
-
* Per-request limit override, for buckets whose allowance is data rather
|
|
26
|
-
* than config (an API key's own `rate_limit`). Returning `undefined` uses
|
|
27
|
-
* `limit`; returning `null` skips the limiter for this request.
|
|
28
|
-
*/
|
|
29
|
-
resolveLimit?: (c: Parameters<MiddlewareHandler<HonoEnv>>[0]) => number | null | undefined;
|
|
30
|
-
/**
|
|
31
|
-
* Number of trusted reverse-proxy hops in front of this server. Each hop
|
|
32
|
-
* appends the address it saw to `X-Forwarded-For`, so the real client IP is
|
|
33
|
-
* the Nth entry from the right. Anything further left is client-supplied and
|
|
34
|
-
* ignored — which is what stops a caller spoofing `X-Forwarded-For` to
|
|
35
|
-
* rotate rate-limit keys. Defaults to `TRUSTED_PROXY_HOPS` (env) or `1`.
|
|
36
|
-
* Set to `0` when the server is exposed directly (no proxy): `X-Forwarded-For`
|
|
37
|
-
* is then ignored entirely in favour of `X-Real-IP`.
|
|
38
|
-
*/
|
|
39
|
-
trustedProxyHops?: number;
|
|
40
12
|
}
|
|
41
13
|
/**
|
|
42
14
|
* Create a rate-limiting middleware.
|
|
43
15
|
*
|
|
44
|
-
* Uses a sliding window: only
|
|
16
|
+
* Uses a sliding window algorithm: only timestamps within the last
|
|
17
|
+
* `windowMs` milliseconds are counted. Old entries are garbage-collected
|
|
18
|
+
* every `windowMs` to prevent unbounded memory growth.
|
|
45
19
|
*/
|
|
46
20
|
export declare function createRateLimiter(options?: RateLimiterOptions): MiddlewareHandler<HonoEnv>;
|
|
47
21
|
/**
|
|
@@ -62,48 +36,12 @@ export declare const strictAuthLimiter: MiddlewareHandler<HonoEnv>;
|
|
|
62
36
|
* via an API key.
|
|
63
37
|
*/
|
|
64
38
|
export declare function apiKeyKeyGenerator(c: Parameters<MiddlewareHandler<HonoEnv>>[0]): string;
|
|
65
|
-
/** How the data API's limits are apportioned. All fields optional. */
|
|
66
|
-
export interface DataRateLimitConfig {
|
|
67
|
-
/** Turn the whole thing off — for a deployment whose proxy already does it. */
|
|
68
|
-
enabled?: boolean;
|
|
69
|
-
windowMs?: number;
|
|
70
|
-
/** Fallback for an API key with no `rate_limit` of its own. Default 1000. */
|
|
71
|
-
apiKey?: number;
|
|
72
|
-
/** Per signed-in user. Default 1000. */
|
|
73
|
-
user?: number;
|
|
74
|
-
/**
|
|
75
|
-
* Per IP, for requests with no principal at all. Default 300.
|
|
76
|
-
* `null` disables the anonymous bucket entirely — used for routers whose
|
|
77
|
-
* anonymous traffic must not be throttled (public webhook functions).
|
|
78
|
-
*/
|
|
79
|
-
anonymous?: number | null;
|
|
80
|
-
/** Share counts across replicas. Defaults to this process's memory. */
|
|
81
|
-
store?: RateLimitStore;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Rate limiting for the data API.
|
|
85
|
-
*
|
|
86
|
-
* Every request is in exactly one bucket, resolved most-specific first: an API
|
|
87
|
-
* key by its id, a signed-in user by their uid, anyone else by IP. Previously
|
|
88
|
-
* only the first of those was limited at all — the middleware returned early
|
|
89
|
-
* for any request without an API key — so JWT and anonymous traffic to
|
|
90
|
-
* `/api/data/*` was unbounded, which is most of the traffic a BaaS gets.
|
|
91
|
-
*
|
|
92
|
-
* Per bucket, not per route: the point is to bound what one caller costs, and
|
|
93
|
-
* they can spend it wherever they like.
|
|
94
|
-
*
|
|
95
|
-
* The defaults are deliberately loose. This is a floor against a runaway client
|
|
96
|
-
* or a naive scraper, not a quota — a deployment that wants real quotas should
|
|
97
|
-
* set them, and one that already has a proxy doing this should pass
|
|
98
|
-
* `enabled: false` rather than pay for it twice.
|
|
99
|
-
*/
|
|
100
|
-
export declare function createDataRateLimiter(config?: DataRateLimitConfig): MiddlewareHandler<HonoEnv>;
|
|
101
39
|
/**
|
|
102
40
|
* Create a rate limiter specifically for API key requests.
|
|
103
41
|
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
42
|
+
* When a request is authenticated via an API key that has a `rate_limit`
|
|
43
|
+
* configured, this limiter enforces per-key limits using the key's ID
|
|
44
|
+
* as the rate limit bucket.
|
|
107
45
|
*
|
|
108
46
|
* @param defaultLimit - Fallback limit when the key has no `rate_limit` set.
|
|
109
47
|
* @param windowMs - Time window in milliseconds (default: 15 minutes).
|
package/dist/env.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* by specialized driver packages like `@rebasepro/server-postgres`.
|
|
8
8
|
*/
|
|
9
9
|
export { initializeRebaseBackend, isAuthAdapter, isDatabaseAdapter } from "./init";
|
|
10
|
-
export type { RebaseBackendConfig, RebaseBackendInstance, RebaseAuthConfig
|
|
10
|
+
export type { RebaseBackendConfig, RebaseBackendInstance, RebaseAuthConfig } from "./init";
|
|
11
11
|
export { rebase, _setRebaseMock, _resetRebaseMock } from "./singleton";
|
|
12
12
|
export { loadCollectionsFromDirectory, applyCollectionDefaults, type CollectionDefaults } from "./collections/loader";
|
|
13
13
|
export * from "./db/interfaces";
|