@happyvertical/smrt-app-runtime 0.53.4 → 0.53.6

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direct-membership.d.ts","sourceRoot":"","sources":["../src/direct-membership.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,2BAA2B,CAAC;AAGnC,mEAAmE;AACnE,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,qBAAqB,CAAC;AAEjE,qEAAqE;AACrE,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC3C;AAED;;;GAGG;AACH,wBAAsB,iCAAiC,CAAC,OAAO,EAAE;IAC/D,QAAQ,CAAC,WAAW,EAAE,oBAAoB,CAAC;IAC3C,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;CACrC,GAAG,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC,CAoC7C"}
package/dist/index.d.ts CHANGED
@@ -11,8 +11,10 @@ import { type ResolvedApplicationRuntime, type RuntimeProviderOverrides } from '
11
11
  import { TaskRunner, type TaskRunnerConfig } from '@happyvertical/smrt-jobs';
12
12
  import { SessionService } from '@happyvertical/smrt-users';
13
13
  import { type DatabaseInterface } from '@happyvertical/sql';
14
+ import { type LocalMcpTokenStore } from './local-mcp-tokens.js';
14
15
  export * from './application-identity.js';
15
16
  export * from './deployed-runtime.js';
17
+ export { DEFAULT_LOCAL_MCP_TOKEN_TTL_SECONDS, type IssuedLocalMcpToken, type IssueLocalMcpTokenInput, isLocalMcpTokenPrincipal, LOCAL_MCP_TOKEN_PREFIX, LOCAL_MCP_TOKEN_PRINCIPAL, LOCAL_MCP_TOKEN_TABLE, type LocalMcpTokenPrincipal, type LocalMcpTokenRecord, type LocalMcpTokenStatus, type LocalMcpTokenStore, MAX_LOCAL_MCP_TOKEN_TTL_SECONDS, } from './local-mcp-tokens.js';
16
18
  export * from './operation-lock.js';
17
19
  export * from './provider-readiness.js';
18
20
  export * from './runtime-diagnostics.js';
@@ -73,6 +75,24 @@ export declare function prepareLocalDatabaseStorage(options: ResolveLocalRuntime
73
75
  * use this boundary before opening SQLite outside the runtime bootstrap.
74
76
  */
75
77
  export declare function validateLocalDatabaseStorage(options: ResolveLocalRuntimePathsOptions): Promise<LocalRuntimePaths>;
78
+ /** Options for {@link openLocalMcpTokenStore}. */
79
+ export interface OpenLocalMcpTokenStoreOptions extends ResolveLocalRuntimePathsOptions {
80
+ /** Testable clock. */
81
+ now?: () => Date;
82
+ }
83
+ /** A {@link LocalMcpTokenStore} over its own connection; call `close()`. */
84
+ export interface OpenedLocalMcpTokenStore extends LocalMcpTokenStore {
85
+ close(): Promise<void>;
86
+ }
87
+ /**
88
+ * Open the local MCP token store of an already-initialized application for
89
+ * an operator command (`smrt app token`). It validates the existing storage
90
+ * custody exactly like `validateLocalDatabaseStorage()` and opens SQLite
91
+ * without running migrations or owner bootstrap. It does not take the writer
92
+ * lease: issuing or revoking a token while the web process runs is the
93
+ * expected use, and revocation takes effect on the next request.
94
+ */
95
+ export declare function openLocalMcpTokenStore(options: OpenLocalMcpTokenStoreOptions): Promise<OpenedLocalMcpTokenStore>;
76
96
  export interface LocalOwnerBootstrapInvitation {
77
97
  /** Plaintext is returned exactly when a new claim is issued; it is never persisted. */
78
98
  readonly token: string;
@@ -130,7 +150,7 @@ export interface LocalRuntimeDiagnostics {
130
150
  readonly paidCapabilitiesEnabled: boolean;
131
151
  readonly secretValuesIncluded: false;
132
152
  }
133
- export type LocalRuntimeErrorCode = 'bootstrap_claimed' | 'bootstrap_expired' | 'bootstrap_invalid' | 'bootstrap_unavailable' | 'capability_disabled' | 'invalid_configuration' | 'migration_failed' | 'unsafe_public_exposure';
153
+ export type LocalRuntimeErrorCode = 'bootstrap_claimed' | 'bootstrap_expired' | 'bootstrap_invalid' | 'bootstrap_unavailable' | 'capability_disabled' | 'invalid_configuration' | 'invalid_scope' | 'migration_failed' | 'owner_unavailable' | 'unsafe_public_exposure';
134
154
  /**
135
155
  * Fixed, secret-free surface for a failed application migration.
136
156
  *
@@ -171,6 +191,13 @@ export interface LocalApplicationRuntime {
171
191
  restoreSession(sessionId: string): ReturnType<SessionService['loadSessionContext']>;
172
192
  createEmbeddedJobRunner(config?: TaskRunnerConfig): Promise<TaskRunner>;
173
193
  diagnostics(): Promise<LocalRuntimeDiagnostics>;
194
+ /**
195
+ * Owner-minted bearer tokens for local MCP clients. Always present on a
196
+ * runtime returned by {@link initializeLocalApplicationRuntime}; optional
197
+ * only so structural test doubles stay valid. Absent means "no tokens":
198
+ * callers fail closed.
199
+ */
200
+ readonly mcpTokens?: LocalMcpTokenStore;
174
201
  }
175
202
  /** Validate an explicit runtime identity. */
176
203
  export declare function validateApplicationId(value: string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAoBH,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAE9B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG7E,OAAO,EAML,cAAc,EAIf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,KAAK,iBAAiB,EAAe,MAAM,oBAAoB,CAAC;AAEzE,cAAc,2BAA2B,CAAC;AAC1C,cAA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as initializeDeployedApplicationRuntime, C as lockOwnerPid, D as reclaimStaleRecord, E as RECLAIM_MUTEX_FILE, M as resolveApplicationId, N as runtimeConfigurationFingerprint, O as DeployedRuntimeCleanupError, S as isStaleOperationLock, T as withOperationLock, _ as projectRuntimeDiagnostics, a as prepareLocalDatabaseStorage, b as findInstalledPackage, c as validateLocalDatabaseStorage, d as prepareApplicationStateRoot, f as resolveApplicationStateRoot, g as RUNTIME_WORKER_FRESHNESS_SECONDS, h as RUNTIME_DIAGNOSTICS_SCHEMA_VERSION, i as initializeLocalApplicationRuntime, j as isSessionTenantAuthorized, k as DeployedRuntimeError, l as acquireWriterLease, m as MAX_RUNTIME_DIAGNOSTIC_TOOLS, n as MIGRATION_FAILED_MESSAGE, o as resolveLocalRuntimePaths, p as MAX_RUNTIME_DIAGNOSTIC_ERRORS, r as encodeApplicationId, s as validateApplicationId, t as LocalRuntimeError, u as readActiveWriterLease, v as PROVIDER_READINESS_SETTINGS, w as processExists, x as resolveReadinessModule, y as createProviderReadinessProbe } from "./chunks/src-DZGOVGsU.js";
2
- export { DeployedRuntimeCleanupError, DeployedRuntimeError, LocalRuntimeError, MAX_RUNTIME_DIAGNOSTIC_ERRORS, MAX_RUNTIME_DIAGNOSTIC_TOOLS, MIGRATION_FAILED_MESSAGE, PROVIDER_READINESS_SETTINGS, RECLAIM_MUTEX_FILE, RUNTIME_DIAGNOSTICS_SCHEMA_VERSION, RUNTIME_WORKER_FRESHNESS_SECONDS, acquireWriterLease, createProviderReadinessProbe, encodeApplicationId, findInstalledPackage, initializeDeployedApplicationRuntime, initializeLocalApplicationRuntime, isSessionTenantAuthorized, isStaleOperationLock, lockOwnerPid, prepareApplicationStateRoot, prepareLocalDatabaseStorage, processExists, projectRuntimeDiagnostics, readActiveWriterLease, reclaimStaleRecord, resolveApplicationId, resolveApplicationStateRoot, resolveLocalRuntimePaths, resolveReadinessModule, runtimeConfigurationFingerprint, validateApplicationId, validateLocalDatabaseStorage, withOperationLock };
1
+ import { A as reclaimStaleRecord, C as findInstalledPackage, D as processExists, E as lockOwnerPid, F as LOCAL_MCP_TOKEN_PRINCIPAL, G as initializeDeployedApplicationRuntime, I as LOCAL_MCP_TOKEN_TABLE, K as isSessionTenantAuthorized, L as MAX_LOCAL_MCP_TOKEN_TTL_SECONDS, M as runtimeConfigurationFingerprint, N as DEFAULT_LOCAL_MCP_TOKEN_TTL_SECONDS, O as withOperationLock, P as LOCAL_MCP_TOKEN_PREFIX, R as isLocalMcpTokenPrincipal, S as createProviderReadinessProbe, T as isStaleOperationLock, U as DeployedRuntimeCleanupError, W as DeployedRuntimeError, _ as MAX_RUNTIME_DIAGNOSTIC_TOOLS, a as openLocalMcpTokenStore, b as projectRuntimeDiagnostics, c as validateApplicationId, d as readActiveWriterLease, f as ONBOARDING_HANDOFF_FILES, g as MAX_RUNTIME_DIAGNOSTIC_ERRORS, h as resolveApplicationStateRoot, i as initializeLocalApplicationRuntime, j as resolveApplicationId, k as RECLAIM_MUTEX_FILE, l as validateLocalDatabaseStorage, m as removeOnboardingHandoff, n as MIGRATION_FAILED_MESSAGE, o as prepareLocalDatabaseStorage, p as prepareApplicationStateRoot, r as encodeApplicationId, s as resolveLocalRuntimePaths, t as LocalRuntimeError, u as acquireWriterLease, v as RUNTIME_DIAGNOSTICS_SCHEMA_VERSION, w as resolveReadinessModule, x as PROVIDER_READINESS_SETTINGS, y as RUNTIME_WORKER_FRESHNESS_SECONDS } from "./chunks/src-D7cM0zHW.js";
2
+ export { DEFAULT_LOCAL_MCP_TOKEN_TTL_SECONDS, DeployedRuntimeCleanupError, DeployedRuntimeError, LOCAL_MCP_TOKEN_PREFIX, LOCAL_MCP_TOKEN_PRINCIPAL, LOCAL_MCP_TOKEN_TABLE, LocalRuntimeError, MAX_LOCAL_MCP_TOKEN_TTL_SECONDS, MAX_RUNTIME_DIAGNOSTIC_ERRORS, MAX_RUNTIME_DIAGNOSTIC_TOOLS, MIGRATION_FAILED_MESSAGE, ONBOARDING_HANDOFF_FILES, PROVIDER_READINESS_SETTINGS, RECLAIM_MUTEX_FILE, RUNTIME_DIAGNOSTICS_SCHEMA_VERSION, RUNTIME_WORKER_FRESHNESS_SECONDS, acquireWriterLease, createProviderReadinessProbe, encodeApplicationId, findInstalledPackage, initializeDeployedApplicationRuntime, initializeLocalApplicationRuntime, isLocalMcpTokenPrincipal, isSessionTenantAuthorized, isStaleOperationLock, lockOwnerPid, openLocalMcpTokenStore, prepareApplicationStateRoot, prepareLocalDatabaseStorage, processExists, projectRuntimeDiagnostics, readActiveWriterLease, reclaimStaleRecord, removeOnboardingHandoff, resolveApplicationId, resolveApplicationStateRoot, resolveLocalRuntimePaths, resolveReadinessModule, runtimeConfigurationFingerprint, validateApplicationId, validateLocalDatabaseStorage, withOperationLock };
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Owner-minted bearer tokens for local MCP clients (`local` profile only).
3
+ *
4
+ * A token is a random 256-bit value with a fixed prefix. The runtime stores
5
+ * only a domain-separated HMAC of it (keyed by the local application secret)
6
+ * in the runtime-owned `_smrt_local_mcp_tokens` system table, alongside the
7
+ * owner's user and tenant, the granted scopes and the expiry. The plaintext
8
+ * is returned exactly once, by `issue()`.
9
+ *
10
+ * A token never carries more authority than its owner holds *now*: `issue()`
11
+ * refuses scopes the owner does not currently hold, and `verify()` returns
12
+ * the token's scopes intersected with the owner's live permissions from its
13
+ * active direct membership in the bound tenant (inherited authority never
14
+ * substitutes for it; no such membership, an inactive user, a revoked or an
15
+ * expired token all yield `null`). Routes should still bind the principal with
16
+ * `runtime.runAsPrincipal`, which applies the same intersection inside the
17
+ * request permission context.
18
+ */
19
+ import type { DatabaseInterface } from '@happyvertical/sql';
20
+ /** Runtime-owned system table; ignored by schema diff, parity and portability. */
21
+ export declare const LOCAL_MCP_TOKEN_TABLE = "_smrt_local_mcp_tokens";
22
+ /** Prefix of every local MCP token (aids secret scanning). */
23
+ export declare const LOCAL_MCP_TOKEN_PREFIX = "smrt_mcp_";
24
+ /** Default token lifetime: 30 days. */
25
+ export declare const DEFAULT_LOCAL_MCP_TOKEN_TTL_SECONDS: number;
26
+ /** Longest token lifetime: 365 days. There is no non-expiring token. */
27
+ export declare const MAX_LOCAL_MCP_TOKEN_TTL_SECONDS: number;
28
+ /** Input for {@link LocalMcpTokenStore.issue}. */
29
+ export interface IssueLocalMcpTokenInput {
30
+ /** Permission slugs the token may use. Each must be held by the owner. */
31
+ readonly scopes: readonly string[];
32
+ /**
33
+ * Lifetime in whole seconds, 60..{@link MAX_LOCAL_MCP_TOKEN_TTL_SECONDS}.
34
+ * Defaults to {@link DEFAULT_LOCAL_MCP_TOKEN_TTL_SECONDS}.
35
+ */
36
+ readonly expiresInSeconds?: number;
37
+ /** Operator note shown by `list()` (printable, at most 80 characters). */
38
+ readonly label?: string;
39
+ }
40
+ /** The one-time result of {@link LocalMcpTokenStore.issue}. */
41
+ export interface IssuedLocalMcpToken {
42
+ /** Public token id used by `list()`/`revoke()`; not a credential. */
43
+ readonly id: string;
44
+ /** The bearer credential. Shown once; only its HMAC is stored. */
45
+ readonly token: string;
46
+ readonly scopes: readonly string[];
47
+ readonly label: string | null;
48
+ readonly createdAt: string;
49
+ readonly expiresAt: string;
50
+ }
51
+ /** Lifecycle state of a stored token. */
52
+ export type LocalMcpTokenStatus = 'active' | 'expired' | 'revoked';
53
+ /** Secret-free token metadata returned by {@link LocalMcpTokenStore.list}. */
54
+ export interface LocalMcpTokenRecord {
55
+ readonly id: string;
56
+ readonly scopes: readonly string[];
57
+ readonly label: string | null;
58
+ readonly createdAt: string;
59
+ readonly expiresAt: string;
60
+ readonly revokedAt: string | null;
61
+ readonly status: LocalMcpTokenStatus;
62
+ }
63
+ /**
64
+ * Brand on every principal `verify()` returns. It is an enumerable symbol, so
65
+ * a spread copy keeps it and `runAsPrincipal` can refuse any attempt to widen
66
+ * the binding of a token-derived principal.
67
+ *
68
+ * @internal
69
+ */
70
+ export declare const LOCAL_MCP_TOKEN_PRINCIPAL: unique symbol;
71
+ /**
72
+ * A verified token principal, structurally an MCP app principal. `scopes`
73
+ * are the token scopes the owner still holds in `tenantId`. The object is
74
+ * frozen (its `scopes` array too) and always binds `direct`: passed straight to `runAsPrincipal`, it
75
+ * is authorized only by the owner's active direct membership in `tenantId`.
76
+ * A copy that sets any other `tenantBinding` is rejected, not ignored.
77
+ */
78
+ export interface LocalMcpTokenPrincipal {
79
+ readonly id: string;
80
+ readonly tenantId: string;
81
+ readonly kind: 'human';
82
+ /** Frozen: token scopes ∩ live permissions at verification. */
83
+ readonly scopes: readonly string[];
84
+ readonly tenantBinding: 'direct';
85
+ /** @internal Token provenance brand; see {@link LOCAL_MCP_TOKEN_PRINCIPAL}. */
86
+ readonly [LOCAL_MCP_TOKEN_PRINCIPAL]: true;
87
+ }
88
+ /** True for a principal derived from a verified local MCP token. */
89
+ export declare function isLocalMcpTokenPrincipal(value: unknown): boolean;
90
+ /** Owner-scoped local MCP token operations. */
91
+ export interface LocalMcpTokenStore {
92
+ /** Mint a token bound to the local owner's user and tenant. */
93
+ issue(input: IssueLocalMcpTokenInput): Promise<IssuedLocalMcpToken>;
94
+ /** Every stored token, newest first, without token values or hashes. */
95
+ list(): Promise<LocalMcpTokenRecord[]>;
96
+ /** Revoke a token by id. Repeating it is a no-op. Unknown ids throw. */
97
+ revoke(id: string): Promise<'revoked' | 'already-revoked'>;
98
+ /**
99
+ * Resolve a presented token to its principal, or `null` (fail closed) for
100
+ * a malformed, unknown, revoked or expired token, or an owner whose user or
101
+ * membership is no longer active.
102
+ */
103
+ verify(token: string): Promise<LocalMcpTokenPrincipal | null>;
104
+ }
105
+ /** @internal Collaborators supplied by the local runtime. */
106
+ export interface LocalMcpTokenStoreDependencies {
107
+ readonly db: DatabaseInterface;
108
+ /** Read the local application secret (validated custody). */
109
+ readonly readSecret: () => Promise<string>;
110
+ readonly now: () => Date;
111
+ /** The active local owner, or `null` before owner setup. */
112
+ readonly findOwner: (db: DatabaseInterface) => Promise<{
113
+ userId: string;
114
+ tenantId: string;
115
+ } | null>;
116
+ /** Build the stable, secret-free runtime error. */
117
+ readonly fail: (code: 'invalid_scope' | 'owner_unavailable' | 'invalid_configuration', message: string) => Error;
118
+ }
119
+ /** Create the runtime-owned token table if it does not exist. */
120
+ export declare function ensureLocalMcpTokenTable(db: DatabaseInterface): Promise<void>;
121
+ /** @internal Build the store over an open local database. */
122
+ export declare function createLocalMcpTokenStore(deps: LocalMcpTokenStoreDependencies): LocalMcpTokenStore;
123
+ //# sourceMappingURL=local-mcp-tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-mcp-tokens.d.ts","sourceRoot":"","sources":["../src/local-mcp-tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AASH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAI5D,kFAAkF;AAClF,eAAO,MAAM,qBAAqB,2BAA2B,CAAC;AAC9D,8DAA8D;AAC9D,eAAO,MAAM,sBAAsB,cAAc,CAAC;AAClD,uCAAuC;AACvC,eAAO,MAAM,mCAAmC,QAAoB,CAAC;AACrE,wEAAwE;AACxE,eAAO,MAAM,+BAA+B,QAAqB,CAAC;AAYlE,kDAAkD;AAClD,MAAM,WAAW,uBAAuB;IACtC,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,0EAA0E;IAC1E,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,+DAA+D;AAC/D,MAAM,WAAW,mBAAmB;IAClC,qEAAqE;IACrE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAA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C;IACpE,wEAAwE;IACxE,IAAI,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC;IACvC,wEAAwE;IACxE,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,iBAAiB,CAAC,CAAC;IAC3D;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;CAC/D;AAED,6DAA6D;AAC7D,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,EAAE,EAAE,iBAAiB,CAAC;IAC/B,6DAA6D;IAC7D,QAAQ,CAAC,UAAU,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3C,QAAQ,CAAC,GAAG,EAAE,MAAM,IAAI,CAAC;IACzB,4DAA4D;IAC5D,QAAQ,CAAC,SAAS,EAAE,CAClB,EAAE,EAAE,iBAAiB,KAClB,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;IAC1D,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,CACb,IAAI,EAAE,eAAe,GAAG,mBAAmB,GAAG,uBAAuB,EACrE,OAAO,EAAE,MAAM,KACZ,KAAK,CAAC;CACZ;AAaD,iEAAiE;AACjE,wBAAsB,wBAAwB,CAC5C,EAAE,EAAE,iBAAiB,GACpB,OAAO,CAAC,IAAI,CAAC,CAcf;AAED,6DAA6D;AAC7D,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,8BAA8B,GACnC,kBAAkB,CAmOpB"}
@@ -2,7 +2,7 @@
2
2
  "version": "1.0.0",
3
3
  "timestamp": 0,
4
4
  "packageName": "@happyvertical/smrt-app-runtime",
5
- "packageVersion": "0.53.4",
5
+ "packageVersion": "0.53.6",
6
6
  "objects": {},
7
7
  "moduleType": "smrt",
8
8
  "smrtDependencies": [
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Hardened copies of caller-supplied plain data (#3413 review N1).
3
+ *
4
+ * Every copy is built from own data properties only, into null-prototype
5
+ * objects and fresh dense arrays, and deep-frozen. It rejects, at every
6
+ * depth: the keys `__proto__`, `constructor` and `prototype`; accessor
7
+ * properties (getters are never invoked); objects whose prototype is not
8
+ * `Object.prototype` or `null` (class instances, objects inheriting data);
9
+ * arrays that are sparse, subclassed or carry extra own keys; functions; and
10
+ * nesting deeper than {@link MAX_PLAIN_DATA_DEPTH}. Non-enumerable own
11
+ * properties are dropped.
12
+ *
13
+ * @internal
14
+ */
15
+ /** Keys that can rewrite a prototype or impersonate a constructor. */
16
+ export declare const FORBIDDEN_DATA_KEYS: ReadonlySet<string>;
17
+ /** Deepest accepted nesting. */
18
+ export declare const MAX_PLAIN_DATA_DEPTH = 8;
19
+ /** Thrown for input that is not acceptable plain data. */
20
+ export declare class PlainDataError extends Error {
21
+ readonly name = "PlainDataError";
22
+ }
23
+ /** Deep-frozen copy of `value`, or a {@link PlainDataError}. */
24
+ export declare function deepFrozenPlainCopy(value: unknown, depth?: number): unknown;
25
+ /** Own data value of `key` on a copy made by {@link deepFrozenPlainCopy}. */
26
+ export declare function ownValue(record: object, key: PropertyKey): unknown;
27
+ //# sourceMappingURL=plain-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plain-data.d.ts","sourceRoot":"","sources":["../src/plain-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,sEAAsE;AACtE,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAIlD,CAAC;AAEH,gCAAgC;AAChC,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAEtC,0DAA0D;AAC1D,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAkB,IAAI,oBAAoB;CAC3C;AAED,gEAAgE;AAChE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,OAAO,CA4DtE;AAED,6EAA6E;AAC7E,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAIlE"}
@@ -3,13 +3,13 @@
3
3
  "sensitiveFieldsExcluded": true,
4
4
  "generatedAt": "1970-01-01T00:00:00.000Z",
5
5
  "packageName": "@happyvertical/smrt-app-runtime",
6
- "packageVersion": "0.53.4",
6
+ "packageVersion": "0.53.6",
7
7
  "sourceManifestPath": "dist/manifest.json",
8
8
  "agentDocPath": "AGENTS.md",
9
9
  "sourceHashes": {
10
- "manifest": "f8a14990e08ea950957549cfbbb2be899cd072b001200577acb271db6f16be8c",
11
- "packageJson": "13238017d8b75b279d6a8c11475de37d708a0b5a6b313d5a120936a11299f4e6",
12
- "agents": "5c8c37ce0684124b676c28b12ef9bad2eeebfc6a6bf2ecae7cb01289a8fe4616"
10
+ "manifest": "9a87f18463e3aa2a89961a660006e5465b586669d0c55f0598e97f02a613fb8f",
11
+ "packageJson": "dd8941ece95f537ac574e15eaa7e093c32e4bed4733833459eafe476a84cce23",
12
+ "agents": "f5b360b498cc5c914a13958ebf462791c4793409b98e09ce325a68514bdc1d37"
13
13
  },
14
14
  "exports": [
15
15
  ".",
@@ -66,5 +66,5 @@
66
66
  "polymorphicAssociations": 0,
67
67
  "uuidColumns": 0
68
68
  },
69
- "agentDoc": "# @happyvertical/smrt-app-runtime\n\nApplication infrastructure composition for the validated runtime profiles in\n`@happyvertical/smrt-config`.\n\n## Local profile\n\n- `validateApplicationId()` is the canonical strict validator for explicit app\n IDs. `encodeApplicationId()` derives a length-bounded, collision-resistant\n ID from package names; generated operational surfaces must share these APIs.\n- `initializeLocalApplicationRuntime()` owns user data paths, SQLite tuning,\n local application-secret creation, and the single-use owner bootstrap flow.\n- SQLite is acquired through `@happyvertical/sql`'s explicit\n `{ driver: 'node:sqlite', custody: 'trusted-parent' }` boundary after the\n runtime establishes its user-owned mode-0700 data root.\n- Application migrations are explicit through `prepareDatabase`; runtime never\n creates application model tables implicitly. A rejected `prepareDatabase` is\n normalized into `LocalRuntimeError` with the stable `migration_failed` code\n and the fixed recovery message `MIGRATION_FAILED_MESSAGE` (\"run pnpm\n app:setup and inspect the private migration logs\"). The caller's error text\n is never surfaced — it is retained only as a non-enumerable `cause` for\n private logs — and the same application root stays retryable.\n- Standalone migration commands must call `prepareLocalDatabaseStorage()`\n before opening SQLite so custody is established without creating schema or\n bootstrap records.\n- Read-only/copy/import operator commands must call\n `validateLocalDatabaseStorage()` before opening SQLite; it verifies the\n app-bound marker, source separation, real path chain, ownership, and mode\n without creating or repairing storage.\n- Owner bootstrap creates normal `Person`, `User`, `Tenant`, owner `Role` /\n `Membership`, and `Session` records in one transaction.\n- Bootstrap is loopback-only. Only an HMAC of the short-lived token is stored.\n A token that cannot claim fails a read-only preflight before role/catalog\n seeding (#3323); the claim transaction's conditional UPDATE stays the\n authority for single use, expiry, and concurrency.\n- Background jobs and application-defined paid capabilities are default-off.\n- The embedded runner reuses `TaskRunner`; it is not a second job contract.\n\n## Deployed profiles\n\n- `initializeDeployedApplicationRuntime()` composes only `self-hosted` and\n `cloud`; it rejects local initialization and provider/binding mismatches.\n- Provider bindings own credentials, vendor clients, and readiness checks.\n Runtime diagnostics contain selectors and status only.\n- The database binding must expose a provider-owned `close` callback before\n `connect` can run. The runtime owns that cleanup boundary and runs the\n application's explicit, idempotent `prepareDatabase` hook.\n- A failed startup cleanup throws `DeployedRuntimeCleanupError`; callers retain\n and retry its idempotent `retryCleanup()` boundary until it succeeds.\n- Public authentication, asset storage, and secret bindings are mandatory and\n readiness-checked before startup succeeds.\n- `createTaskWorker()` and `createScheduleWorker()` initialize the normal jobs\n package runners against the shared PostgreSQL database. They are intended for\n separate processes; the web process does not start them automatically. The\n worker process must import the app's compiled registration\n (`.smrt/runtime/register.js`, #3117) first; runners resolve `objectType`\n through the registry and never load application source themselves.\n- `close()` drains in-flight readiness/session/worker initialization and\n serialized runner start/stop operations, stops every runner returned by the\n runtime, and then closes PostgreSQL. Returned runners must not be restarted\n after runtime shutdown begins.\n- A tracked operation may await a re-entrant `close()` request without\n deadlocking; external `close()` callers still await complete cleanup.\n- `health()` is process liveness. `readiness()` probes database/auth/assets/\n secrets; it does not claim that an external worker fleet is running.\n- Database-provider readiness is additive; a PostgreSQL-specific server-version\n probe always gates startup and live readiness.\n- Cloud must keep required tenant context and must never introduce a root or\n unscoped tenant fallback. RLS remains an explicit deployment/migration choice.\n\n## SvelteKit entry (`./sveltekit`)\n\n- Server-only subpath; `@sveltejs/kit` is an optional peer and is externalized\n in `vite.config.ts` (kit recognizes `redirect`/`fail` by class identity).\n The root entry must never import kit or Svelte.\n- `createSmrtSvelteKitRuntime()` order is fixed: readiness gate → URL tenant\n selection (`locals.selectedTenant*`, never tenant context, headers ignored) →\n verified session (tenant context entered only when\n `isSessionTenantAuthorized()` accepts it, else unauthenticated; never via\n `createSessionHandler`, which re-runs `resolve` on downstream errors) →\n publish `locals.tenantContext` only for that verified tenant.\n- `database-rls` isolation forces `postgresRls: true`, including on\n `skipPaths` (anonymous principal). `resolve` runs at most once;\n session-layer failure before it is a 500 with cleared locals.\n- In an RLS request `classOptions()`/`databaseConfig()` return the\n transaction-bound request db (class `db` overrides win). Anything that\n outlives a request (session service, tenant selector) must use the base\n config, never these.\n- The writer lease, provider readiness, and onboarding file cleanup are\n injected hooks. Apps pass the root entry's `acquireWriterLease` (over\n `prepareApplicationStateRoot`) and `createProviderReadinessProbe`; deployed\n startup fails closed without `providerReadiness`.\n- Owner setup re-checks loopback peer and loopback URL host per request and\n returns only fixed `{ code, message }` failures.\n- `resolveApplicationId()` / `runtimeConfigurationFingerprint()` must stay\n byte-compatible with process managers (golden vectors in tests).\n\n## Operator state (root entry)\n\n- One owner for the state shared by the web process and `smrt app`\n (`@happyvertical/smrt-cli/app` re-exports these): `resolveApplicationStateRoot`\n / `prepareApplicationStateRoot` (private app-bound mode-0700 root and\n marker), `withOperationLock` (`operation.lock`), `acquireWriterLease` /\n `readActiveWriterLease` (`writer.lease`), `reclaimStaleRecord`, and\n `createProviderReadinessProbe` (`SMRT_*_READINESS_MODULE`, resolved from the\n app root with Node's own ESM rules). File names, record formats, and\n messages are a cross-process contract; never change them unilaterally.\n- Tests that hook `node:fs` interleavings must live in this package: from a\n consumer the package is an externalized dependency a mock cannot reach.\n\n## Public runtime diagnostics\n\n- `projectRuntimeDiagnostics()` is the only public diagnostic projection. It\n constructs the schema-version-1 allowlist and never serializes the private\n local or deployed diagnostics objects.\n- The allowlist is limited to active profile/coarse health, schema and\n migration readiness, six fixed capability statuses, a sorted/capped public\n tool inventory plus digest, explicit operational topology differences,\n coarse worker heartbeat state, and eight stable code/timestamp errors.\n- Callers supply an explicit clock and worker-heartbeat seam. A missing\n heartbeat is `unknown`; web-process liveness never proves worker liveness.\n- Error ingestion maps unknown codes to `runtime_error`, truncates timestamps\n to the minute, and ignores messages, stacks, logs, records, and nested state.\n- Authentication and diagnostics-read authorization belong before every call\n to the projector or its runtime probes.\n\n## Invariants\n\n- Never expose application-secret bytes or bootstrap token hashes in diagnostics.\n- Never include migration or provider error text in a local or deployed startup\n error message; migration driver text is a likely credential carrier.\n- Never include provider error text, URLs, tokens, or credentials in deployed\n errors, diagnostics, health, or readiness payloads.\n- Keep local data, assets, database, and secrets outside the source tree.\n- Do not reach into collection/database private fields. Add an upstream public\n API if composition cannot be expressed through exported surfaces.\n- Keep profile selection out of domain models, generated APIs, MCP/WebMCP\n surfaces, effects, approvals, and authorization records.\n\n## Validation\n\n```bash\npnpm --filter @happyvertical/smrt-app-runtime test\npnpm --filter @happyvertical/smrt-app-runtime typecheck\npnpm --filter @happyvertical/smrt-app-runtime build\n```\n"
69
+ "agentDoc": "# @happyvertical/smrt-app-runtime\n\nApplication infrastructure composition for the validated runtime profiles in\n`@happyvertical/smrt-config`.\n\n## Local profile\n\n- `validateApplicationId()` is the canonical strict validator for explicit app\n IDs. `encodeApplicationId()` derives a length-bounded, collision-resistant\n ID from package names; generated operational surfaces must share these APIs.\n- `initializeLocalApplicationRuntime()` owns user data paths, SQLite tuning,\n local application-secret creation, and the single-use owner bootstrap flow.\n- SQLite is acquired through `@happyvertical/sql`'s explicit\n `{ driver: 'node:sqlite', custody: 'trusted-parent' }` boundary after the\n runtime establishes its user-owned mode-0700 data root.\n- Application migrations are explicit through `prepareDatabase`; runtime never\n creates application model tables implicitly. A rejected `prepareDatabase` is\n normalized into `LocalRuntimeError` with the stable `migration_failed` code\n and the fixed recovery message `MIGRATION_FAILED_MESSAGE` (\"run pnpm\n app:setup and inspect the private migration logs\"). The caller's error text\n is never surfaced — it is retained only as a non-enumerable `cause` for\n private logs — and the same application root stays retryable.\n- Standalone migration commands must call `prepareLocalDatabaseStorage()`\n before opening SQLite so custody is established without creating schema or\n bootstrap records.\n- Read-only/copy/import operator commands must call\n `validateLocalDatabaseStorage()` before opening SQLite; it verifies the\n app-bound marker, source separation, real path chain, ownership, and mode\n without creating or repairing storage.\n- Owner bootstrap creates normal `Person`, `User`, `Tenant`, owner `Role` /\n `Membership`, and `Session` records in one transaction.\n- Bootstrap is loopback-only. Only an HMAC of the short-lived token is stored.\n A token that cannot claim fails a read-only preflight before role/catalog\n seeding (#3323); the claim transaction's conditional UPDATE stays the\n authority for single use, expiry, and concurrency.\n- Local MCP tokens (`mcpTokens`, `openLocalMcpTokenStore`, `smrt app token`):\n owner-bound, scoped, expiring (default 30 d, max 365 d), revocable. Only a\n domain-separated HMAC (application secret) is stored, in the runtime-owned\n `_smrt_local_mcp_tokens` system table (created like the bootstrap table;\n never application schema). Issue refuses scopes the owner lacks; verify\n returns token scopes ∩ live permissions and `null` for anything else.\n- Bearer binding is explicit (`tenantBinding`, set by the auth adapter;\n `direct-membership.ts`): `direct` (local tokens, default hosted resolver)\n needs an active direct membership in exactly the tenant; the default\n `direct-or-inherited` (hosted app mappings) applies\n `isSessionTenantAuthorized`'s rule. The direct row, when present, is pinned\n into `PermissionResolver`, so inheritance never substitutes for it.\n `verify()` principals (and their `scopes` arrays) are frozen;\n `runAsPrincipal` takes a validated, deep-frozen, null-prototype copy of\n the principal before any await (`plain-data.ts`: own data only; poison\n keys `__proto__`/`constructor`/`prototype`, accessors, inherited or\n non-plain data, sparse arrays and functions rejected), authorizes from it,\n and hands `fn` that snapshot. Token `issue()` input is read the same way.\n They carry\n `tenantBinding: 'direct'` and the\n `LOCAL_MCP_TOKEN_PRINCIPAL` brand; `runAsPrincipal` rejects a copy that\n widens the binding, so the two public APIs compose safely.\n Never log or return the token outside `issue()`. The operator store opens an\n uncached connection and takes no writer lease (revocation is per request).\n- Background jobs and application-defined paid capabilities are default-off.\n- The embedded runner reuses `TaskRunner`; it is not a second job contract.\n\n## Deployed profiles\n\n- `initializeDeployedApplicationRuntime()` composes only `self-hosted` and\n `cloud`; it rejects local initialization and provider/binding mismatches.\n- Provider bindings own credentials, vendor clients, and readiness checks.\n Runtime diagnostics contain selectors and status only.\n- The database binding must expose a provider-owned `close` callback before\n `connect` can run. The runtime owns that cleanup boundary and runs the\n application's explicit, idempotent `prepareDatabase` hook.\n- A failed startup cleanup throws `DeployedRuntimeCleanupError`; callers retain\n and retry its idempotent `retryCleanup()` boundary until it succeeds.\n- Public authentication, asset storage, and secret bindings are mandatory and\n readiness-checked before startup succeeds.\n- `createTaskWorker()` and `createScheduleWorker()` initialize the normal jobs\n package runners against the shared PostgreSQL database. They are intended for\n separate processes; the web process does not start them automatically. The\n worker process must import the app's compiled registration\n (`.smrt/runtime/register.js`, #3117) first; runners resolve `objectType`\n through the registry and never load application source themselves.\n- `close()` drains in-flight readiness/session/worker initialization and\n serialized runner start/stop operations, stops every runner returned by the\n runtime, and then closes PostgreSQL. Returned runners must not be restarted\n after runtime shutdown begins.\n- A tracked operation may await a re-entrant `close()` request without\n deadlocking; external `close()` callers still await complete cleanup.\n- `health()` is process liveness. `readiness()` probes database/auth/assets/\n secrets; it does not claim that an external worker fleet is running.\n- Database-provider readiness is additive; a PostgreSQL-specific server-version\n probe always gates startup and live readiness.\n- Cloud must keep required tenant context and must never introduce a root or\n unscoped tenant fallback. RLS remains an explicit deployment/migration choice.\n\n## SvelteKit entry (`./sveltekit`)\n\n- Server-only subpath; `@sveltejs/kit` is an optional peer and is externalized\n in `vite.config.ts` (kit recognizes `redirect`/`fail` by class identity).\n The root entry must never import kit or Svelte.\n- Without a `runtime` option the profile comes from smrt-config's\n `resolveEffectiveApplicationRuntime(await loadConfig())`, the same rule as\n `smrt app` (#3446): no block → `local`; `null`/`false`/`0`/`''` fail closed.\n- `createSmrtSvelteKitRuntime()` order is fixed: readiness gate → URL tenant\n selection (`locals.selectedTenant*`, never tenant context, headers ignored) →\n verified session (tenant context entered only when\n `isSessionTenantAuthorized()` accepts it, else unauthenticated; never via\n `createSessionHandler`, which re-runs `resolve` on downstream errors) →\n publish `locals.tenantContext` only for that verified tenant.\n- `database-rls` isolation forces `postgresRls: true`, including on\n `skipPaths` (anonymous principal). `resolve` runs at most once;\n session-layer failure before it is a 500 with cleared locals.\n- In an RLS request `classOptions()`/`databaseConfig()` return the\n transaction-bound request db (class `db` overrides win). Anything that\n outlives a request (session service, tenant selector) must use the base\n config, never these.\n- The local writer lease defaults to `defaultWriterLease()` (root\n `acquireWriterLease` over `prepareApplicationStateRoot`, presenting\n `SMRT_OPERATION_INSTANCE`); `acquireWriterLease` replaces it, `false` opts\n out, deployed profiles never take it. Provider readiness stays injected:\n apps pass `createProviderReadinessProbe`; deployed startup fails closed\n without `providerReadiness`.\n- `getCollection()` builds from `classOptions()` on every call (RLS request db\n inside a request); each generated route's embedded prelude imports the\n app's `smrt.ts` and reaches it through core's\n `createGeneratedCollectionAccess()` (a legacy accessor export wins,\n deprecated for one release).\n- Owner setup removes the `smrt app` onboarding hand-off files by default,\n immediately after the claim commits (before cookie serialization or hooks);\n `onOwnerClaimed` is for additional cleanup and\n `removeOnboardingHandoff: false` is the explicit opt-out.\n- Owner setup re-checks loopback peer and loopback URL host per request and\n returns only fixed `{ code, message }` failures.\n- `verifyLocalMcpToken` (local only) and `resolveMcpPrincipal` (hosted only:\n issuer/subject → `oidc_identities` → exactly one active user with exactly\n one active direct membership, else `null`) are the runtime's MCP credential\n bindings; pass the runtime as `createHostedMcpResourceAuth({ runtime })`.\n Token claims never select a tenant.\n- `resolveApplicationId()` / `runtimeConfigurationFingerprint()` must stay\n byte-compatible with process managers (golden vectors in tests).\n\n## Operator state (root entry)\n\n- One owner for the state shared by the web process and `smrt app`\n (`@happyvertical/smrt-cli/app` re-exports these): `resolveApplicationStateRoot`\n / `prepareApplicationStateRoot` (private app-bound mode-0700 root and\n marker), `withOperationLock` (`operation.lock`), `acquireWriterLease` /\n `readActiveWriterLease` (`writer.lease`), `reclaimStaleRecord`, and\n `createProviderReadinessProbe` (`SMRT_*_READINESS_MODULE`, resolved from the\n app root with Node's own ESM rules). File names, record formats, and\n messages are a cross-process contract; never change them unilaterally.\n- Tests that hook `node:fs` interleavings must live in this package: from a\n consumer the package is an externalized dependency a mock cannot reach.\n\n## Public runtime diagnostics\n\n- `projectRuntimeDiagnostics()` is the only public diagnostic projection. It\n constructs the schema-version-1 allowlist and never serializes the private\n local or deployed diagnostics objects.\n- The allowlist is limited to active profile/coarse health, schema and\n migration readiness, six fixed capability statuses, a sorted/capped public\n tool inventory plus digest, explicit operational topology differences,\n coarse worker heartbeat state, and eight stable code/timestamp errors.\n- Callers supply an explicit clock and worker-heartbeat seam. A missing\n heartbeat is `unknown`; web-process liveness never proves worker liveness.\n- Error ingestion maps unknown codes to `runtime_error`, truncates timestamps\n to the minute, and ignores messages, stacks, logs, records, and nested state.\n- Authentication and diagnostics-read authorization belong before every call\n to the projector or its runtime probes.\n\n## Invariants\n\n- Never expose application-secret bytes or bootstrap token hashes in diagnostics.\n- Never include migration or provider error text in a local or deployed startup\n error message; migration driver text is a likely credential carrier.\n- Never include provider error text, URLs, tokens, or credentials in deployed\n errors, diagnostics, health, or readiness payloads.\n- Keep local data, assets, database, and secrets outside the source tree.\n- Do not reach into collection/database private fields. Add an upstream public\n API if composition cannot be expressed through exported surfaces.\n- Keep profile selection out of domain models, generated APIs, MCP/WebMCP\n surfaces, effects, approvals, and authorization records.\n\n## Validation\n\n```bash\npnpm --filter @happyvertical/smrt-app-runtime test\npnpm --filter @happyvertical/smrt-app-runtime typecheck\npnpm --filter @happyvertical/smrt-app-runtime build\n```\n"
70
70
  }
@@ -39,4 +39,15 @@ export interface StateCustodyOptions {
39
39
  * Create or verify the private, app-bound state/lock directory.
40
40
  */
41
41
  export declare function prepareApplicationStateRoot(options: ApplicationStateRootOptions & StateCustodyOptions): string;
42
+ /**
43
+ * Hand-off files `smrt app setup` / `recover` leave in the private state root.
44
+ * They hold the loopback `/setup?token=` URL, so they are spent once the owner
45
+ * claim commits.
46
+ */
47
+ export declare const ONBOARDING_HANDOFF_FILES: readonly string[];
48
+ /**
49
+ * Remove the onboarding hand-off files from `stateRoot`. Missing files are
50
+ * fine. Call only after the owner claim transaction has committed.
51
+ */
52
+ export declare function removeOnboardingHandoff(stateRoot: string): void;
42
53
  //# sourceMappingURL=state-root.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"state-root.d.ts","sourceRoot":"","sources":["../src/state-root.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAgBH,2CAA2C;AAC3C,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC;IACxC,wCAAwC;IACxC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qCAAqC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAClD;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,2BAA2B,GACnC,MAAM,CAoBR;AAWD,8DAA8D;AAC9D,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,2BAA2B,GAAG,mBAAmB,GACzD,MAAM,CAyFR"}
1
+ {"version":3,"file":"state-root.d.ts","sourceRoot":"","sources":["../src/state-root.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAiBH,2CAA2C;AAC3C,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC;IACxC,wCAAwC;IACxC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qCAAqC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAClD;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,2BAA2B,GACnC,MAAM,CAoBR;AAWD,8DAA8D;AAC9D,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,2BAA2B,GAAG,mBAAmB,GACzD,MAAM,CAyFR;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAGpD,CAAC;AAEH;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAI/D"}
@@ -15,6 +15,6 @@
15
15
  */
16
16
  export { createRuntimeDiagnosticsHandler, createRuntimeHealthHandler, createSessionLayoutLoad, type DiagnosticsPrincipalLocals, RUNTIME_DIAGNOSTICS_READ_PERMISSION, type RuntimeDiagnosticsHandlerOptions, type SessionLayoutData, } from './handlers.js';
17
17
  export { createOwnerSetupPage, DEFAULT_OWNER_SETUP_MESSAGES, isLoopbackAddress, isLoopbackHostname, isLoopbackRequest, OWNER_SETUP_FIELDS, type OwnerSetupActionEvent, type OwnerSetupErrorCode, type OwnerSetupEvent, type OwnerSetupFailure, type OwnerSetupPage, type OwnerSetupPageData, type OwnerSetupPageOptions, } from './owner-setup.js';
18
- export { type ApplicationRuntimeDiagnosticsOptions, authorizedTenantLocalsHandle, composeHandles, createSmrtSvelteKitRuntime, type ProviderReadinessComponent, type ProviderReadinessFactory, type RuntimeHealthBody, type SmrtRuntimeBoundPrincipal, type SmrtRuntimeLocals, type SmrtRuntimeSessionCookie, type SmrtRuntimeSessionOptions, type SmrtSvelteKitRuntime, type SmrtSvelteKitRuntimeOptions, type WriterLease, type WriterLeaseContext, } from './runtime.js';
18
+ export { type ApplicationRuntimeDiagnosticsOptions, authorizedTenantLocalsHandle, composeHandles, createSmrtSvelteKitRuntime, defaultWriterLease, type ProviderReadinessComponent, type ProviderReadinessFactory, type RuntimeHealthBody, type SmrtRuntimeBoundPrincipal, type SmrtRuntimeBoundPrincipalSnapshot, type SmrtRuntimeDeepReadonly, type SmrtRuntimeLocals, type SmrtRuntimeMcpIdentity, type SmrtRuntimeMcpPrincipalMapping, type SmrtRuntimeSessionCookie, type SmrtRuntimeSessionOptions, type SmrtSvelteKitRuntime, type SmrtSvelteKitRuntimeOptions, type TenantBindingMode, type WriterLease, type WriterLeaseContext, } from './runtime.js';
19
19
  export { createSubdomainTenantSelector, normalizeTenantSelection, type SubdomainTenantSelectorOptions, selectTenantSlug, type TenantSelection, type TenantSelectionEvent, type TenantSelector, } from './tenancy.js';
20
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sveltekit/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,+BAA+B,EAC/B,0BAA0B,EAC1B,uBAAuB,EACvB,KA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AK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,oCAAoC,EACzC,4BAA4B,EAC5B,cAAc,EACd,0BAA0B,EAC1B,kBAAkB,EAClB,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,iCAAiC,EACtC,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,8BAA8B,EACnC,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,EAChC,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,kBAAkB,GACxB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,6BAA6B,EAC7B,wBAAwB,EACxB,KAAK,8BAA8B,EACnC,gBAAgB,EAChB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,cAAc,GACpB,MAAM,cAAc,CAAC"}
@@ -59,8 +59,15 @@ export interface OwnerSetupPageOptions {
59
59
  /** Override where the signed-in user comes from. Defaults to `locals.user`. */
60
60
  readonly resolveUser?: (event: OwnerSetupEvent) => unknown;
61
61
  /**
62
- * Best-effort cleanup after a successful claim (for example removing local
63
- * onboarding handoff files). Errors are ignored: the owner and session are
62
+ * Set false to keep the `smrt app` onboarding hand-off files after a claim.
63
+ * By default the runtime removes `onboarding.json` and
64
+ * `onboarding-launch.html` from the private state root once the claim has
65
+ * committed, so `pnpm app:open` stops offering the spent invitation.
66
+ */
67
+ readonly removeOnboardingHandoff?: boolean;
68
+ /**
69
+ * Best-effort extra cleanup after a successful claim (the hand-off files are
70
+ * already removed by default). Errors are ignored: the owner and session are
64
71
  * already authoritative and a stale token now fails closed.
65
72
  */
66
73
  readonly onOwnerClaimed?: (result: LocalOwnerClaimResult, event: OwnerSetupActionEvent) => void | Promise<void>;
@@ -85,7 +92,7 @@ export interface OwnerSetupPage {
85
92
  * `name`, `email`, and optional `tenantName`. Success sets the session cookie
86
93
  * and redirects 303; failures return `fail(status, { code, message })`.
87
94
  */
88
- export declare function createOwnerSetupPage(runtime: Pick<SmrtSvelteKitRuntime, 'resolvedRuntime' | 'localRuntime' | 'sessionCookie'>, options?: OwnerSetupPageOptions): OwnerSetupPage;
95
+ export declare function createOwnerSetupPage(runtime: Pick<SmrtSvelteKitRuntime, 'resolvedRuntime' | 'localRuntime' | 'sessionCookie'> & Partial<Pick<SmrtSvelteKitRuntime, 'applicationStateRoot'>>, options?: OwnerSetupPageOptions): OwnerSetupPage;
89
96
  /**
90
97
  * True only when both the peer address and the addressed host are loopback.
91
98
  * The host check rejects tunnels and DNS-rebinding hosts that forward to a
@@ -1 +1 @@
1
- {"version":3,"file":"owner-setup.d.ts","sourceRoot":"","sources":["../../src/sveltekit/owner-setup.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,eAAe,CAAC;AACnE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEzD,8CAA8C;AAC9C,MAAM,WAAW,kBAAkB;IACjC,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,yDAAyD;AACzD,MAAM,MAAM,mBAAmB;AAC7B,wCAAwC;AACtC,gBAAgB;AAClB,2EAA2E;GACzE,mBAAmB;AACrB,kEAAkE;GAChE,qBAAqB;AACvB,+EAA+E;GAC7E,eAAe,CAAC;AAEpB,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AC,IAAI,CAAC,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACvE,QAAQ,CAAC,OAAO,EAAE;QAChB,QAAQ,CAAC,OAAO,EAAE,CAChB,KAAK,EAAE,qBAAqB,KACzB,OAAO,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC;KAChD,CAAC;CACH;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,IAAI,CACX,oBAAoB,EACpB,iBAAiB,GAAG,cAAc,GAAG,eAAe,CACrD,GACC,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,CAAC,EAC7D,OAAO,GAAE,qBAA0B,GAClC,cAAc,CAmGhB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,gBAAgB,IAAI,MAAM,CAAC;CAC5B,GAAG,OAAO,CAQV;AAED,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAc3E;AAED,oEAAoE;AACpE,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAG5D"}
@@ -20,15 +20,16 @@
20
20
  * using `switchSessionTenant()` from `@happyvertical/smrt-users/sveltekit`.
21
21
  */
22
22
  import { type ResolvedApplicationRuntime } from '@happyvertical/smrt-config';
23
- import type { SmrtClassOptions } from '@happyvertical/smrt-core';
23
+ import { type SmrtClassOptions, type SmrtCollection, type SmrtObject } from '@happyvertical/smrt-core';
24
24
  import { type MinimalTenantContext } from '@happyvertical/smrt-tenancy';
25
25
  import type { SessionHandlerOptions, SessionLocals } from '@happyvertical/smrt-users/sveltekit';
26
26
  import { type DatabaseInterface } from '@happyvertical/sql';
27
27
  import type { Handle, ServerInit } from '@sveltejs/kit';
28
28
  import { type DeployedApplicationRuntime, initializeDeployedApplicationRuntime } from '../deployed-runtime.js';
29
- import { initializeLocalApplicationRuntime, type LocalApplicationRuntime, type LocalOwnerBootstrapInvitation } from '../index.js';
29
+ import { type TenantBindingMode } from '../direct-membership.js';
30
+ import { initializeLocalApplicationRuntime, type LocalApplicationRuntime, type LocalMcpTokenPrincipal, type LocalOwnerBootstrapInvitation } from '../index.js';
30
31
  import { type RuntimeDiagnostics } from '../runtime-diagnostics.js';
31
- import type { WriterLease } from '../writer-lease.js';
32
+ import { type WriterLease } from '../writer-lease.js';
32
33
  import { type TenantSelector } from './tenancy.js';
33
34
  /** `App.Locals` fields populated by the SMRT runtime `handle`. */
34
35
  export interface SmrtRuntimeLocals extends SessionLocals {
@@ -107,7 +108,8 @@ export interface SmrtSvelteKitRuntimeOptions {
107
108
  readonly env?: NodeJS.ProcessEnv;
108
109
  /**
109
110
  * Resolved runtime profile. Defaults to `smrt.config` `runtime` when
110
- * present, otherwise the `local` profile.
111
+ * present, otherwise the `local` profile; a present value that is not a
112
+ * runtime block (`null`, `false`, `0`, `''`) fails closed.
111
113
  */
112
114
  readonly runtime?: ResolvedApplicationRuntime | (() => ResolvedApplicationRuntime | Promise<ResolvedApplicationRuntime>);
113
115
  /**
@@ -129,10 +131,14 @@ export interface SmrtSvelteKitRuntimeOptions {
129
131
  /** Session lifetime for the owner-bootstrap session cookie. Default 7 days. */
130
132
  readonly sessionTtlSeconds?: number;
131
133
  /**
132
- * Local single-writer lease held for the web process (for example the CLI's
133
- * state-root writer lease). Released when local startup fails.
134
+ * Local single-writer lease held for the web process, released when local
135
+ * startup fails. Defaults to the state-root writer lease shared with
136
+ * `smrt app` operations ({@link defaultWriterLease}: `writer.lease` under
137
+ * `prepareApplicationStateRoot()`, presenting `SMRT_OPERATION_INSTANCE`).
138
+ * Pass a factory to replace it, or `false` to hold no lease. Deployed
139
+ * profiles never take it.
134
140
  */
135
- readonly acquireWriterLease?: (context: WriterLeaseContext) => WriterLease;
141
+ readonly acquireWriterLease?: ((context: WriterLeaseContext) => WriterLease) | false;
136
142
  /**
137
143
  * Deployed provider readiness probes. Required by `self-hosted` and `cloud`;
138
144
  * deployed startup fails closed without them.
@@ -170,6 +176,7 @@ export interface SmrtRuntimeSessionCookie {
170
176
  readonly secure?: boolean;
171
177
  readonly maxAgeSeconds: number;
172
178
  }
179
+ export type { TenantBindingMode } from '../direct-membership.js';
173
180
  /** The composed runtime; `handle` and `init` are bound and destructurable. */
174
181
  /** A principal a route authenticated itself, for {@link SmrtSvelteKitRuntime.runAsPrincipal}. */
175
182
  export interface SmrtRuntimeBoundPrincipal {
@@ -177,7 +184,44 @@ export interface SmrtRuntimeBoundPrincipal {
177
184
  readonly tenantId?: string | null;
178
185
  /** Granted scopes that cap the live permission set (e.g. token scopes). */
179
186
  readonly scopes?: readonly string[];
187
+ /**
188
+ * How tenant authority may be established, set by the authenticating
189
+ * adapter (never request input). `direct` (local owner tokens, the default
190
+ * hosted resolver) needs an active direct membership in exactly
191
+ * `tenantId`. `direct-or-inherited` (the default; hosted application-owned
192
+ * mappings) applies the session step's rule: that direct row, or with no
193
+ * direct row, authority inherited from an active inheritable ancestor.
194
+ */
195
+ readonly tenantBinding?: TenantBindingMode;
196
+ }
197
+ /** A verified hosted access-token identity (see `McpVerifiedIdentity`). */
198
+ export interface SmrtRuntimeMcpIdentity {
199
+ /** Exact issuer the token was verified against. */
200
+ readonly issuer: string;
201
+ /** Verified `sub` claim. */
202
+ readonly subject: string;
203
+ }
204
+ /** The current account and tenant a hosted MCP identity maps to. */
205
+ export interface SmrtRuntimeMcpPrincipalMapping {
206
+ readonly id: string;
207
+ readonly tenantId: string;
208
+ readonly kind: 'human';
209
+ /** The default resolver maps only direct memberships. */
210
+ readonly tenantBinding: 'direct';
180
211
  }
212
+ /** `T` with every nested array and object field readonly. */
213
+ export type SmrtRuntimeDeepReadonly<T> = T extends readonly (infer U)[] ? readonly SmrtRuntimeDeepReadonly<U>[] : T extends object ? {
214
+ readonly [K in keyof T]: SmrtRuntimeDeepReadonly<T[K]>;
215
+ } : T;
216
+ /**
217
+ * The frozen principal `runAsPrincipal` hands its callback: a deep, frozen
218
+ * snapshot of the caller's principal taken before any await, with the
219
+ * effective `tenantBinding` and effective (frozen) `scopes`.
220
+ */
221
+ export type SmrtRuntimeBoundPrincipalSnapshot<P> = SmrtRuntimeDeepReadonly<Omit<P, 'scopes' | 'tenantBinding'>> & {
222
+ readonly scopes: readonly string[];
223
+ readonly tenantBinding: TenantBindingMode;
224
+ };
181
225
  export interface SmrtSvelteKitRuntime {
182
226
  /** `hooks.server.ts` `handle`. */
183
227
  readonly handle: Handle;
@@ -191,6 +235,12 @@ export interface SmrtSvelteKitRuntime {
191
235
  ready(): Promise<void>;
192
236
  /** Canonical application ID. */
193
237
  applicationId(): string;
238
+ /**
239
+ * Private state root shared with the `smrt app` operator commands (writer
240
+ * lease, operation lock, onboarding hand-off files). Resolves the path only;
241
+ * it does not create it.
242
+ */
243
+ applicationStateRoot(): string;
194
244
  /** Secret-free configuration fingerprint. Requires a resolved runtime. */
195
245
  configurationFingerprint(): string;
196
246
  /**
@@ -207,6 +257,13 @@ export interface SmrtSvelteKitRuntime {
207
257
  * Same per-request rule as {@link databaseConfig}.
208
258
  */
209
259
  classOptions(className: string): SmrtClassOptions;
260
+ /**
261
+ * The registered collection for a class, built from {@link classOptions}
262
+ * evaluated on this call: inside an RLS request it is bound to the request
263
+ * transaction. Generated API routes resolve collections through it. Call it
264
+ * per request and never retain the result beyond that request.
265
+ */
266
+ getCollection<T extends SmrtObject = SmrtObject>(className: string): Promise<SmrtCollection<T>>;
210
267
  /**
211
268
  * Run `fn` as a principal the route verified itself (for example a bearer
212
269
  * token mapped by an MCP route), replacing the cookie session's permission
@@ -215,17 +272,40 @@ export interface SmrtSvelteKitRuntime {
215
272
  * under the RLS transaction rule of {@link databaseConfig} a fresh
216
273
  * transaction publishes that user, tenant and permission set, and
217
274
  * `databaseConfig()`/`classOptions()` return it inside `fn`. Rejects (before
218
- * `fn` runs) without a user id, a tenant, or an authorized membership.
275
+ * `fn` runs) without a user id, a tenant, or a membership its
276
+ * `tenantBinding` accepts: `direct` needs an active direct membership in
277
+ * exactly that tenant; `direct-or-inherited` (default) also accepts
278
+ * authority inherited from an active inheritable ancestor when no direct
279
+ * row exists. A suspended or pending direct row is always authoritative.
219
280
  *
220
- * `fn` receives the principal with `scopes` replaced by that effective
221
- * permission set (live permissions, capped by the given scopes). Callers
281
+ * `principal` is read once, before any await: `fn` receives a frozen copy
282
+ * of that snapshot (its effective `tenantBinding`, and `scopes` replaced by
283
+ * the effective, frozen permission set: live permissions capped by the
284
+ * given scopes), never the caller's object. Callers
222
285
  * that authorize in code (rather than through database policy, as under
223
286
  * `application` isolation) must authorize with these effective scopes so a
224
287
  * revoked permission takes effect even while a token still carries it.
225
288
  */
226
- runAsPrincipal<T, P extends SmrtRuntimeBoundPrincipal = SmrtRuntimeBoundPrincipal>(principal: P, fn: (bound: P & {
227
- scopes: string[];
228
- }) => Promise<T>): Promise<T>;
289
+ runAsPrincipal<T, P extends SmrtRuntimeBoundPrincipal = SmrtRuntimeBoundPrincipal>(principal: P, fn: (bound: SmrtRuntimeBoundPrincipalSnapshot<P>) => Promise<T>): Promise<T>;
290
+ /**
291
+ * Verify an owner-minted local MCP token (`smrt app token`). Resolves the
292
+ * token's owner principal with its scopes capped to the owner's live
293
+ * permissions, or `null` for anything else: a malformed, unknown, revoked
294
+ * or expired token, an inactive owner or membership, or any non-`local`
295
+ * profile. Pass the runtime as `createHostedMcpResourceAuth({ runtime })`
296
+ * so `/mcp` accepts these tokens in the local profile.
297
+ */
298
+ verifyLocalMcpToken(token: string): Promise<LocalMcpTokenPrincipal | null>;
299
+ /**
300
+ * Default membership-backed hosted MCP principal mapping: the verified
301
+ * issuer/subject must be linked (`oidc_identities`) to exactly one active
302
+ * user with exactly one active direct tenant membership. Anything else
303
+ * (unlinked, ambiguous, inactive, several tenants, the `local` profile)
304
+ * resolves `null`, which denies the request. Token claims never select the
305
+ * tenant. Applications with multi-tenant users pass their own
306
+ * `resolvePrincipal`, which takes precedence.
307
+ */
308
+ resolveMcpPrincipal(identity: SmrtRuntimeMcpIdentity): Promise<SmrtRuntimeMcpPrincipalMapping | null>;
229
309
  /** The local runtime. Rejects outside the `local` profile. */
230
310
  localRuntime(): Promise<LocalApplicationRuntime>;
231
311
  /** The deployed runtime. Rejects in the `local` profile. */
@@ -260,6 +340,12 @@ export interface SmrtSvelteKitRuntimeSeams {
260
340
  export declare function createSmrtSvelteKitRuntime(options?: SmrtSvelteKitRuntimeOptions): SmrtSvelteKitRuntime;
261
341
  /** @internal */
262
342
  export declare function composeSmrtSvelteKitRuntime(options: SmrtSvelteKitRuntimeOptions, seams: SmrtSvelteKitRuntimeSeams): SmrtSvelteKitRuntime;
343
+ /**
344
+ * The default local writer lease: the state-root `writer.lease` shared with
345
+ * `smrt app` operations, presenting the managed operation instance
346
+ * (`SMRT_OPERATION_INSTANCE`) that `smrt app start` passes to its writer.
347
+ */
348
+ export declare function defaultWriterLease(context: WriterLeaseContext, env?: NodeJS.ProcessEnv): WriterLease;
263
349
  /**
264
350
  * Step 3: publish the authorized tenant context only when this runtime's
265
351
  * session step verified the session tenant and it matches the active