@hasna/treasury 0.1.2
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/LICENSE +202 -0
- package/README.md +85 -0
- package/dist/adapters/fixtures.d.ts +31 -0
- package/dist/adapters/fixtures.d.ts.map +1 -0
- package/dist/adapters/types.d.ts +42 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/api/index.d.ts +37 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/cli/context.d.ts +9 -0
- package/dist/cli/context.d.ts.map +1 -0
- package/dist/cli/dashboard.d.ts +5 -0
- package/dist/cli/dashboard.d.ts.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +4353 -0
- package/dist/cli/namespaces.d.ts +7 -0
- package/dist/cli/namespaces.d.ts.map +1 -0
- package/dist/config.d.ts +42 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/core/app-home.d.ts +9 -0
- package/dist/core/app-home.d.ts.map +1 -0
- package/dist/core/errors.d.ts +8 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/db/audit.d.ts +16 -0
- package/dist/db/audit.d.ts.map +1 -0
- package/dist/db/backup.d.ts +14 -0
- package/dist/db/backup.d.ts.map +1 -0
- package/dist/db/database.d.ts +40 -0
- package/dist/db/database.d.ts.map +1 -0
- package/dist/db/migration-plan.d.ts +14 -0
- package/dist/db/migration-plan.d.ts.map +1 -0
- package/dist/db/schema.d.ts +8 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/generated/storage-kit/health.d.ts +20 -0
- package/dist/generated/storage-kit/health.d.ts.map +1 -0
- package/dist/generated/storage-kit/index.d.ts +8 -0
- package/dist/generated/storage-kit/index.d.ts.map +1 -0
- package/dist/generated/storage-kit/migrations.d.ts +48 -0
- package/dist/generated/storage-kit/migrations.d.ts.map +1 -0
- package/dist/generated/storage-kit/mode.d.ts +48 -0
- package/dist/generated/storage-kit/mode.d.ts.map +1 -0
- package/dist/generated/storage-kit/pool.d.ts +34 -0
- package/dist/generated/storage-kit/pool.d.ts.map +1 -0
- package/dist/generated/storage-kit/query.d.ts +36 -0
- package/dist/generated/storage-kit/query.d.ts.map +1 -0
- package/dist/generated/storage-kit/tls.d.ts +26 -0
- package/dist/generated/storage-kit/tls.d.ts.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23773 -0
- package/dist/mcp/compact.d.ts +12 -0
- package/dist/mcp/compact.d.ts.map +1 -0
- package/dist/mcp/http.d.ts +38 -0
- package/dist/mcp/http.d.ts.map +1 -0
- package/dist/mcp/index.d.ts +32 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +6243 -0
- package/dist/mcp/tools/domain.d.ts +10 -0
- package/dist/mcp/tools/domain.d.ts.map +1 -0
- package/dist/mcp/tools/standard.d.ts +4 -0
- package/dist/mcp/tools/standard.d.ts.map +1 -0
- package/dist/mcp/tools/storage.d.ts +4 -0
- package/dist/mcp/tools/storage.d.ts.map +1 -0
- package/dist/release/package-smoke.d.ts +11 -0
- package/dist/release/package-smoke.d.ts.map +1 -0
- package/dist/server/app.d.ts +19 -0
- package/dist/server/app.d.ts.map +1 -0
- package/dist/server/auth-constants.d.ts +22 -0
- package/dist/server/auth-constants.d.ts.map +1 -0
- package/dist/server/auth.d.ts +147 -0
- package/dist/server/auth.d.ts.map +1 -0
- package/dist/server/health.d.ts +23 -0
- package/dist/server/health.d.ts.map +1 -0
- package/dist/server/index.d.ts +11 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +2094 -0
- package/dist/server/list-query.d.ts +7 -0
- package/dist/server/list-query.d.ts.map +1 -0
- package/dist/services/authorization-constants.d.ts +14 -0
- package/dist/services/authorization-constants.d.ts.map +1 -0
- package/dist/services/authorization.d.ts +95 -0
- package/dist/services/authorization.d.ts.map +1 -0
- package/dist/services/balances.d.ts +33 -0
- package/dist/services/balances.d.ts.map +1 -0
- package/dist/services/context.d.ts +24 -0
- package/dist/services/context.d.ts.map +1 -0
- package/dist/services/entities.d.ts +14 -0
- package/dist/services/entities.d.ts.map +1 -0
- package/dist/services/forecast.d.ts +10 -0
- package/dist/services/forecast.d.ts.map +1 -0
- package/dist/services/fx.d.ts +33 -0
- package/dist/services/fx.d.ts.map +1 -0
- package/dist/services/ingest.d.ts +19 -0
- package/dist/services/ingest.d.ts.map +1 -0
- package/dist/services/registry.d.ts +33 -0
- package/dist/services/registry.d.ts.map +1 -0
- package/dist/services/runway.d.ts +28 -0
- package/dist/services/runway.d.ts.map +1 -0
- package/dist/services/storage.d.ts +35 -0
- package/dist/services/storage.d.ts.map +1 -0
- package/dist/services/sweeps.d.ts +26 -0
- package/dist/services/sweeps.d.ts.map +1 -0
- package/dist/types/index.d.ts +133 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/docker-compose.yml +53 -0
- package/hasna.contract.json +20 -0
- package/openapi.json +615 -0
- package/package.json +80 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { ApiPrincipal } from "../../server/auth.js";
|
|
3
|
+
import { type Profile } from "../../services/registry.js";
|
|
4
|
+
/**
|
|
5
|
+
* Register every registry op as an MCP domain tool, threading the CALLER
|
|
6
|
+
* principal into per-op authorization exactly like /v1 — never a SYSTEM bypass
|
|
7
|
+
* (defeats wave-1 failure class #1). Filtered by the active tool profile.
|
|
8
|
+
*/
|
|
9
|
+
export declare function registerDomainTools(server: McpServer, principal: ApiPrincipal, profile: Profile): void;
|
|
10
|
+
//# sourceMappingURL=domain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/domain.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAgC,KAAK,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAwBxF;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAatG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/standard.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAgBzD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,GAAG,IAAI,CA2CtF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/storage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAOzD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,GAAG,IAAI,CAiDrF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
export interface SmokeResult {
|
|
3
|
+
ok: boolean;
|
|
4
|
+
entity_id: string;
|
|
5
|
+
cash_in_base_minor: number;
|
|
6
|
+
openapi_paths: number;
|
|
7
|
+
mcp_built: boolean;
|
|
8
|
+
serve_built: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function runSmoke(): Promise<SmokeResult>;
|
|
11
|
+
//# sourceMappingURL=package-smoke.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-smoke.d.ts","sourceRoot":"","sources":["../../src/release/package-smoke.ts"],"names":[],"mappings":";AAaA,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,wBAAsB,QAAQ,IAAI,OAAO,CAAC,WAAW,CAAC,CAkBrD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import type { Context } from "hono";
|
|
3
|
+
export declare function checkRateLimit(ip: string): boolean;
|
|
4
|
+
export declare function resetRateLimit(): void;
|
|
5
|
+
export declare function getBindHost(): string;
|
|
6
|
+
export declare function isLoopback(host?: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Derive the rate-limit key from the CONNECTION, not the client-controllable
|
|
9
|
+
* `X-Forwarded-For` header. Preference order:
|
|
10
|
+
* 1. the real socket peer (Bun `server.requestIP`) — unspoofable by the client;
|
|
11
|
+
* 2. the RIGHTMOST `X-Forwarded-For` hop (appended by the trusted proxy),
|
|
12
|
+
* never the leftmost client-supplied entry;
|
|
13
|
+
* 3. a single connection bucket as a last resort.
|
|
14
|
+
* This defeats the X-Forwarded-For rotation/spoofing bypass of the per-IP limit
|
|
15
|
+
* on the unauthenticated auth surface.
|
|
16
|
+
*/
|
|
17
|
+
export declare function clientIp(c: Context): string;
|
|
18
|
+
export declare function createApp(): Hono;
|
|
19
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/server/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAepC,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CASlD;AAED,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAQD,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,UAAU,CAAC,IAAI,SAAgB,GAAG,OAAO,CAExD;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAU3C;AAmBD,wBAAgB,SAAS,IAAI,IAAI,CAsEhC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AuthorizationRole } from "../services/authorization.js";
|
|
2
|
+
export declare const apiScopes: readonly ["treasury:read", "treasury:write", "treasury:recommend", "treasury:export", "treasury:admin", "storage:admin"];
|
|
3
|
+
export type ApiScope = (typeof apiScopes)[number];
|
|
4
|
+
export interface AuthConstants {
|
|
5
|
+
apiScopes: readonly ApiScope[];
|
|
6
|
+
knownRoles: AuthorizationRole[];
|
|
7
|
+
roleScopes: Record<AuthorizationRole, ApiScope[]>;
|
|
8
|
+
actionScope: Record<string, ApiScope>;
|
|
9
|
+
defaultAction: ApiScope;
|
|
10
|
+
env: {
|
|
11
|
+
apiKey: string[];
|
|
12
|
+
credentials: string[];
|
|
13
|
+
};
|
|
14
|
+
verifyToken?: (token: string) => {
|
|
15
|
+
identity_id: string;
|
|
16
|
+
jti: string;
|
|
17
|
+
scopes: string[];
|
|
18
|
+
entity_ids?: string[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare const AUTH_CONSTANTS: AuthConstants;
|
|
22
|
+
//# sourceMappingURL=auth-constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-constants.d.ts","sourceRoot":"","sources":["../../src/server/auth-constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,eAAO,MAAM,SAAS,0HAGZ,CAAC;AACX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAElD,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;IAC/B,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC,iBAAiB,EAAE,QAAQ,EAAE,CAAC,CAAC;IAClD,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACtC,aAAa,EAAE,QAAQ,CAAC;IACxB,GAAG,EAAE;QAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,WAAW,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IACjD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK;QAC/B,WAAW,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;KAC3E,CAAC;CACH;AAGD,eAAO,MAAM,cAAc,EAAE,aAmB5B,CAAC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { AuthorizationContext, AuthorizationRole } from "../services/authorization.js";
|
|
2
|
+
import { apiScopes } from "./auth-constants.js";
|
|
3
|
+
import type { ApiScope } from "./auth-constants.js";
|
|
4
|
+
/**
|
|
5
|
+
* CANONICAL transport credential module — identical across all 9 Hasna internal
|
|
6
|
+
* apps. The MECHANISM (timing-safe bearer compare, expiry, revocation, STRICT
|
|
7
|
+
* deny-by-default entity scoping, and the rule that a network credential can
|
|
8
|
+
* NEVER escalate to a SYSTEM bypass) is NOT a per-app design choice.
|
|
9
|
+
*
|
|
10
|
+
* The ONLY per-app difference is the imported `./auth-constants.js`, which
|
|
11
|
+
* carries the domain scope/role NAMES (apiScopes, knownRoles, roleScopes,
|
|
12
|
+
* actionScope), the env-var names, and an OPTIONAL `verifyToken` hook (provided
|
|
13
|
+
* only by the token-issuer app). This file is otherwise byte-identical.
|
|
14
|
+
*
|
|
15
|
+
* ONE shared authenticate path (`authenticateToken` / `authenticateApiRequest`)
|
|
16
|
+
* is the SOLE credential resolver for BOTH the /v1 serve tier AND the MCP HTTP
|
|
17
|
+
* transport, so the identical credential set is honored on both surfaces. It
|
|
18
|
+
* resolves, in order: the single static legacy API key (a trusted bootstrap
|
|
19
|
+
* principal, `owner` ROLE but NEVER a bypass), an env-configured serve
|
|
20
|
+
* credential, then — if the app is a token issuer — a signed bearer token whose
|
|
21
|
+
* OWN scopes/entity_ids are its sole authority (it carries no roles).
|
|
22
|
+
*/
|
|
23
|
+
export type { ApiScope };
|
|
24
|
+
export { apiScopes };
|
|
25
|
+
export type ApiCredentialType = "api_key" | "user" | "session" | "service";
|
|
26
|
+
export interface ApiCredentialConfig {
|
|
27
|
+
id: string;
|
|
28
|
+
token?: string;
|
|
29
|
+
key?: string;
|
|
30
|
+
type?: ApiCredentialType;
|
|
31
|
+
actor_id?: string;
|
|
32
|
+
roles?: AuthorizationRole[];
|
|
33
|
+
scopes?: ApiScope[];
|
|
34
|
+
/** CANONICAL entity dimension. */
|
|
35
|
+
entity_id?: string;
|
|
36
|
+
entity_ids?: string[];
|
|
37
|
+
/**
|
|
38
|
+
* DEPRECATED org-dimension aliases, still accepted and folded into the
|
|
39
|
+
* principal's `entity_ids` for drop-in compatibility with older credential
|
|
40
|
+
* blobs. New credentials should use entity_id/entity_ids only.
|
|
41
|
+
*/
|
|
42
|
+
org_id?: string;
|
|
43
|
+
org_ids?: string[];
|
|
44
|
+
expires_at?: string;
|
|
45
|
+
revoked?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* CANONICAL principal shape. Extends the shared AuthorizationContext (actor_id,
|
|
49
|
+
* roles, entity_id/entity_ids, bypass) and adds the credential identity + the
|
|
50
|
+
* resolved API scopes. Entity dimension only — the org_* aliases are collapsed
|
|
51
|
+
* into `entity_ids` at authentication time.
|
|
52
|
+
*/
|
|
53
|
+
export interface ApiPrincipal extends AuthorizationContext {
|
|
54
|
+
credential_id: string;
|
|
55
|
+
credential_type: ApiCredentialType;
|
|
56
|
+
scopes: ApiScope[];
|
|
57
|
+
/**
|
|
58
|
+
* SYSTEM bypass — grants unrestricted entity access, mirroring the CLI's
|
|
59
|
+
* local-owner context. It is set ONLY by the in-process `localOwnerPrincipal`
|
|
60
|
+
* (stdio / auth-off loopback dev); it is NEVER derived from a caller-supplied
|
|
61
|
+
* credential (`authenticateToken` never sets it), so a bearer token can never
|
|
62
|
+
* escalate to a bypass.
|
|
63
|
+
*/
|
|
64
|
+
bypass?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface ApiAuthResult {
|
|
67
|
+
allowed: boolean;
|
|
68
|
+
status?: number;
|
|
69
|
+
code?: "UNAUTHORIZED" | "PERMISSION_DENIED";
|
|
70
|
+
message?: string;
|
|
71
|
+
/** Single required scope (principal-level `authorizeScopeAndEntity`). */
|
|
72
|
+
required_scope?: ApiScope;
|
|
73
|
+
/** Required scope set (request-level `authorizeApiRequest`). */
|
|
74
|
+
required_scopes?: ApiScope[];
|
|
75
|
+
principal?: ApiPrincipal;
|
|
76
|
+
}
|
|
77
|
+
/** Map an authorization action to its required API scope (deny-by-default fallback). */
|
|
78
|
+
export declare const actionScope: Record<string, ApiScope>;
|
|
79
|
+
/** Back-compat UPPER_SNAKE alias (controls). */
|
|
80
|
+
export declare const ACTION_SCOPE: Record<string, "treasury:read" | "treasury:write" | "treasury:recommend" | "treasury:export" | "treasury:admin" | "storage:admin">;
|
|
81
|
+
export declare function requiredScopeForAction(action: string): ApiScope;
|
|
82
|
+
/** Back-compat alias (workforce). */
|
|
83
|
+
export declare const scopeForAction: typeof requiredScopeForAction;
|
|
84
|
+
/** Roles → API scopes (union). Names are per-app; the mechanism is shared. */
|
|
85
|
+
export declare function scopesForRoles(roles: AuthorizationRole[]): ApiScope[];
|
|
86
|
+
/** Back-compat alias (entities). */
|
|
87
|
+
export declare const apiScopesForRoles: typeof scopesForRoles;
|
|
88
|
+
/** First non-empty configured legacy API key across the app's env-var names. */
|
|
89
|
+
export declare function legacyApiKey(): string | undefined;
|
|
90
|
+
/** Back-compat alias (access). */
|
|
91
|
+
export declare const getApiKey: typeof legacyApiKey;
|
|
92
|
+
export declare function isApiAuthConfigured(): boolean;
|
|
93
|
+
export declare function configuredApiCredentials(): ApiCredentialConfig[];
|
|
94
|
+
/**
|
|
95
|
+
* Extract a bearer token from an Authorization header value OR a Request. Accepts
|
|
96
|
+
* both shapes so it is drop-in for `bearerToken(header)` and `bearerToken(req)`.
|
|
97
|
+
*/
|
|
98
|
+
export declare function bearerToken(input: string | null | undefined | Request): string;
|
|
99
|
+
/** Back-compat alias (controls, billing). */
|
|
100
|
+
export declare const bearerFromHeader: typeof bearerToken;
|
|
101
|
+
/**
|
|
102
|
+
* Authenticate a raw bearer token to a principal, honoring expiry + revocation.
|
|
103
|
+
* NEVER sets `bypass` — a network-presented credential cannot escalate to the
|
|
104
|
+
* entity-unrestricted SYSTEM context.
|
|
105
|
+
*/
|
|
106
|
+
export declare function authenticateToken(token: string): ApiPrincipal | null;
|
|
107
|
+
/** Back-compat alias (entities, holdings). */
|
|
108
|
+
export declare const authenticateBearer: typeof authenticateToken;
|
|
109
|
+
export declare function authenticateApiRequest(req: Request): ApiPrincipal | null;
|
|
110
|
+
/** Back-compat alias (consolidations, entities). */
|
|
111
|
+
export declare const authenticateRequest: typeof authenticateApiRequest;
|
|
112
|
+
/**
|
|
113
|
+
* The in-process local-owner principal (CLI / stdio / auth-off loopback dev).
|
|
114
|
+
* This is the ONLY principal that carries `bypass: true`; it is never produced
|
|
115
|
+
* from a network credential.
|
|
116
|
+
*/
|
|
117
|
+
export declare function localOwnerPrincipal(): ApiPrincipal;
|
|
118
|
+
export declare function principalHasScope(principal: ApiPrincipal, scope: ApiScope): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Bridge an authenticated principal to the shared authorization context. Threads
|
|
121
|
+
* the principal's scopes so the service layer honors scope-based grants (for a
|
|
122
|
+
* token/serve credential that carries scopes but no roles) identically on the
|
|
123
|
+
* /v1 and MCP paths. `bypass` is propagated ONLY when already set by
|
|
124
|
+
* `localOwnerPrincipal` — a network principal always carries `bypass: false`.
|
|
125
|
+
*/
|
|
126
|
+
export declare function toAuthorizationContext(principal: ApiPrincipal): AuthorizationContext & {
|
|
127
|
+
scopes?: ApiScope[];
|
|
128
|
+
};
|
|
129
|
+
/** Back-compat aliases (access: principalToContext, entities: principalContext). */
|
|
130
|
+
export declare const principalToContext: typeof toAuthorizationContext;
|
|
131
|
+
export declare const principalContext: typeof toAuthorizationContext;
|
|
132
|
+
/**
|
|
133
|
+
* Request-level gate: authenticate + require a scope set + (optional) entity.
|
|
134
|
+
* Deny-by-default. Used by apps that gate at the HTTP layer (access).
|
|
135
|
+
*/
|
|
136
|
+
export declare function authorizeApiRequest(req: Request, requirement: {
|
|
137
|
+
public?: boolean;
|
|
138
|
+
scopes: ApiScope[];
|
|
139
|
+
entity_id?: string;
|
|
140
|
+
}): ApiAuthResult;
|
|
141
|
+
/**
|
|
142
|
+
* Principal-level gate: require a single scope + (optional) entity access for an
|
|
143
|
+
* already-authenticated principal. Deny-by-default; knowing an entity_id grants
|
|
144
|
+
* nothing without matching access.
|
|
145
|
+
*/
|
|
146
|
+
export declare function authorizeScopeAndEntity(principal: ApiPrincipal, requiredScope: ApiScope, entityId?: string): ApiAuthResult;
|
|
147
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/server/auth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAE5F,OAAO,EAAkB,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,EAAE,QAA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B,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAEnF;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,YAAY,GACtB,oBAAoB,GAAG;IAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAA;CAAE,CAQhD;AACD,oFAAoF;AACpF,eAAO,MAAM,kBAAkB,+BAAyB,CAAC;AACzD,eAAO,MAAM,gBAAgB,+BAAyB,CAAC;AAEvD;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACxE,aAAa,CA4Bf;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,YAAY,EACvB,aAAa,EAAE,QAAQ,EACvB,QAAQ,CAAC,EAAE,MAAM,GAChB,aAAa,CAcf"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare function versionPayload(): {
|
|
2
|
+
status: "ok";
|
|
3
|
+
version: string;
|
|
4
|
+
mode: "local" | "cloud";
|
|
5
|
+
};
|
|
6
|
+
export declare function healthPayload(): {
|
|
7
|
+
status: "ok";
|
|
8
|
+
version: string;
|
|
9
|
+
mode: "local" | "cloud";
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Readiness probe. The response BODY matches BUILD-SPEC §6.2 exactly:
|
|
13
|
+
* `{ status: "ready" }` with 200 on success, and a minimal `{ status: "unavailable" }`
|
|
14
|
+
* with 503 on failure. `ok` is a transport-only discriminant for the HTTP status
|
|
15
|
+
* code and is NOT part of the response body.
|
|
16
|
+
*/
|
|
17
|
+
export declare function readyPayload(): Promise<{
|
|
18
|
+
ok: boolean;
|
|
19
|
+
body: {
|
|
20
|
+
status: "ready" | "unavailable";
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
23
|
+
//# sourceMappingURL=health.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/server/health.ts"],"names":[],"mappings":"AAOA,wBAAgB,cAAc,IAAI;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAA;CAAE,CAE3F;AAED,wBAAgB,aAAa,IAAI;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAA;CAAE,CAE1F;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE;QAAE,MAAM,EAAE,OAAO,GAAG,aAAa,CAAA;KAAE,CAAA;CAAE,CAAC,CAQxG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
export declare function getPort(): number;
|
|
3
|
+
/**
|
|
4
|
+
* Fail-closed startup guard (BUILD-SPEC §6.3): auth is decoupled from storage
|
|
5
|
+
* mode. Unauthenticated /v1 is permitted ONLY on a loopback bind in local mode.
|
|
6
|
+
* A cloud-mode or non-loopback bind with no credentials configured is a hard
|
|
7
|
+
* startup error — never silently serve open.
|
|
8
|
+
*/
|
|
9
|
+
export declare function assertServeSafety(): void;
|
|
10
|
+
export declare function startServer(): ReturnType<typeof Bun.serve>;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";AAMA,wBAAgB,OAAO,IAAI,MAAM,CAEhC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAWxC;AAED,wBAAgB,WAAW,IAAI,UAAU,CAAC,OAAO,GAAG,CAAC,KAAK,CAAC,CAS1D"}
|