@rebasepro/server 0.9.1-canary.97e305f → 0.9.1-canary.a57c262
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 +0 -9
- 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/rate-limiter.d.ts +2 -16
- package/dist/cron/cron-store.d.ts +0 -18
- package/dist/index.es.js +179 -633
- package/dist/index.es.js.map +1 -1
- package/dist/{openapi-generator-DqSIwNLV.js → openapi-generator-Z9oYWLf_.js} +2 -8
- package/dist/openapi-generator-Z9oYWLf_.js.map +1 -0
- package/package.json +5 -5
- package/dist/openapi-generator-DqSIwNLV.js.map +0 -1
|
@@ -24,15 +24,6 @@ export declare class RestApiGenerator {
|
|
|
24
24
|
* No-ops if the request is not authenticated via an API key.
|
|
25
25
|
*/
|
|
26
26
|
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
27
|
/**
|
|
37
28
|
* Get the request-scoped driver. Throws if none is set — never falls
|
|
38
29
|
* 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";
|
|
@@ -27,16 +27,6 @@ interface RateLimiterOptions {
|
|
|
27
27
|
* `limit`; returning `null` skips the limiter for this request.
|
|
28
28
|
*/
|
|
29
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
30
|
}
|
|
41
31
|
/**
|
|
42
32
|
* Create a rate-limiting middleware.
|
|
@@ -71,12 +61,8 @@ export interface DataRateLimitConfig {
|
|
|
71
61
|
apiKey?: number;
|
|
72
62
|
/** Per signed-in user. Default 1000. */
|
|
73
63
|
user?: number;
|
|
74
|
-
/**
|
|
75
|
-
|
|
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;
|
|
64
|
+
/** Per IP, for requests with no principal at all. Default 300. */
|
|
65
|
+
anonymous?: number;
|
|
80
66
|
/** Share counts across replicas. Defaults to this process's memory. */
|
|
81
67
|
store?: RateLimitStore;
|
|
82
68
|
}
|
|
@@ -28,23 +28,5 @@ export interface CronStore {
|
|
|
28
28
|
totalFailures: number;
|
|
29
29
|
lastRunAt?: string;
|
|
30
30
|
}>>;
|
|
31
|
-
/**
|
|
32
|
-
* Atomically claim a scheduled run slot for a job.
|
|
33
|
-
*
|
|
34
|
-
* `slot` is the *scheduled* fire time (ISO string) derived from the cron
|
|
35
|
-
* expression — deterministic across instances regardless of timer drift,
|
|
36
|
-
* so all instances contend on the same (jobId, slot) key. Exactly one
|
|
37
|
-
* caller wins the insert against the unique constraint and executes;
|
|
38
|
-
* the rest skip.
|
|
39
|
-
*
|
|
40
|
-
* Fails open (returns true) on unexpected store errors, so a broken
|
|
41
|
-
* claims table degrades to uncoordinated execution rather than silently
|
|
42
|
-
* never running jobs.
|
|
43
|
-
*
|
|
44
|
-
* Optional so custom stores written against the pre-claims interface
|
|
45
|
-
* keep working — the scheduler treats a missing implementation as
|
|
46
|
-
* uncoordinated (always run).
|
|
47
|
-
*/
|
|
48
|
-
tryClaimRun?(jobId: string, slot: string): Promise<boolean>;
|
|
49
31
|
}
|
|
50
32
|
export declare function createCronStore(driver: DataDriver): CronStore | undefined;
|