@astrale-os/kernel-client 0.6.0-beta.85 → 0.6.0-beta.87
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/auth/auth.d.ts +2 -8
- package/dist/auth/credential.d.ts +1 -7
- package/dist/auth/identity.d.ts +2 -1
- package/dist/client/credential.d.ts +2 -1
- package/dist/errors/stale-route-error.d.ts +4 -14
- package/dist/errors/stale-route-error.js +2 -13
- package/dist/errors/transport-error.d.ts +1 -1
- package/dist/graph/domain/domain.typecheck.js +1 -0
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/index.js +1 -1
- package/dist/schema/introspection.js +1 -5
- package/dist/schema/schema.js +4 -8
- package/dist/session/admission.js +3 -3
- package/dist/session/bound.d.ts +2 -2
- package/dist/session/bound.js +3 -2
- package/dist/session/content/api.d.ts +45 -0
- package/dist/session/content/api.js +28 -0
- package/dist/session/content/batch.d.ts +5 -0
- package/dist/session/content/batch.js +93 -0
- package/dist/session/content/index.d.ts +1 -0
- package/dist/session/content/index.js +1 -0
- package/dist/session/content/input.d.ts +9 -0
- package/dist/session/content/input.js +33 -0
- package/dist/session/content/parts.d.ts +36 -0
- package/dist/session/content/parts.js +154 -0
- package/dist/session/content/retry.d.ts +3 -0
- package/dist/session/content/retry.js +41 -0
- package/dist/session/content/wire.d.ts +12 -0
- package/dist/session/content/wire.js +60 -0
- package/dist/session/context/index.d.ts +1 -1
- package/dist/session/context/index.js +1 -1
- package/dist/session/context/limits.d.ts +0 -1
- package/dist/session/context/limits.js +0 -1
- package/dist/session/context/operation.d.ts +0 -1
- package/dist/session/context/operation.js +1 -1
- package/dist/session/context/policy.d.ts +0 -1
- package/dist/session/context/policy.js +0 -16
- package/dist/session/discovery/bundle.d.ts +4 -3
- package/dist/session/discovery/bundle.js +20 -21
- package/dist/session/discovery/discovery.d.ts +0 -3
- package/dist/session/discovery/discovery.js +6 -14
- package/dist/session/discovery/index.d.ts +0 -5
- package/dist/session/discovery/index.js +1 -2
- package/dist/session/discovery/release.d.ts +6 -5
- package/dist/session/discovery/release.js +3 -3
- package/dist/session/discovery/snapshot.d.ts +1 -8
- package/dist/session/discovery/snapshot.js +2 -2
- package/dist/session/exchange/domain.js +1 -1
- package/dist/session/exchange/exchange.d.ts +1 -7
- package/dist/session/exchange/exchange.js +0 -4
- package/dist/session/exchange/index.d.ts +1 -1
- package/dist/session/exchange/index.js +1 -1
- package/dist/session/exchange/presentation.js +1 -2
- package/dist/session/exchange/source.d.ts +2 -1
- package/dist/session/index.d.ts +3 -2
- package/dist/session/index.js +1 -1
- package/dist/session/options.d.ts +65 -0
- package/dist/session/options.js +132 -0
- package/dist/session/routing/cache.d.ts +9 -14
- package/dist/session/routing/cache.js +17 -186
- package/dist/session/routing/dispatch.d.ts +4 -3
- package/dist/session/routing/dispatch.js +63 -113
- package/dist/session/routing/envelope.d.ts +3 -3
- package/dist/session/routing/expiry.d.ts +4 -0
- package/dist/session/routing/expiry.js +32 -0
- package/dist/session/routing/index.d.ts +4 -2
- package/dist/session/routing/index.js +4 -2
- package/dist/session/routing/integrity.d.ts +7 -0
- package/dist/session/routing/integrity.js +44 -0
- package/dist/session/routing/recovery.d.ts +16 -0
- package/dist/session/routing/recovery.js +41 -0
- package/dist/session/routing/result.d.ts +5 -0
- package/dist/session/routing/result.js +12 -0
- package/dist/session/routing/store.d.ts +23 -0
- package/dist/session/routing/store.js +99 -0
- package/dist/session/session.d.ts +11 -51
- package/dist/session/session.js +37 -139
- package/dist/session/session.typecheck.js +12 -4
- package/dist/session/views/catalog.d.ts +9 -5
- package/dist/session/views/catalog.js +29 -24
- package/dist/session/views/index.d.ts +1 -1
- package/dist/session/views/index.js +1 -1
- package/dist/session/views/resolve.d.ts +6 -4
- package/dist/session/views/resolve.js +14 -6
- package/dist/store/entity-index.d.ts +1 -2
- package/dist/store/entity-index.js +0 -3
- package/dist/store/memory.js +2 -2
- package/dist/store/shape.d.ts +2 -1
- package/dist/transport/auto/decision.d.ts +3 -2
- package/dist/transport/http/admission.d.ts +5 -0
- package/dist/transport/http/admission.js +101 -0
- package/dist/transport/http/binary.d.ts +5 -0
- package/dist/transport/http/binary.js +70 -0
- package/dist/transport/http/configuration.d.ts +24 -0
- package/dist/transport/http/configuration.js +116 -0
- package/dist/transport/http/index.d.ts +2 -1
- package/dist/transport/http/response.d.ts +7 -0
- package/dist/transport/http/response.js +9 -0
- package/dist/transport/http/retired.d.ts +8 -0
- package/dist/transport/http/retired.js +28 -0
- package/dist/transport/http/transport.d.ts +1 -19
- package/dist/transport/http/transport.js +17 -300
- package/dist/transport/websocket/connection.d.ts +2 -1
- package/package.json +5 -5
- package/dist/session/content.d.ts +0 -27
- package/dist/session/content.js +0 -135
- package/dist/session/discovery/legacy/index.d.ts +0 -38
- package/dist/session/discovery/legacy/index.js +0 -38
- package/dist/session/discovery/legacy/intrinsic.d.ts +0 -33
- package/dist/session/discovery/legacy/intrinsic.js +0 -67
- package/dist/session/discovery/legacy/projection.d.ts +0 -8
- package/dist/session/discovery/legacy/projection.js +0 -17
- package/dist/session/discovery/legacy/publication.d.ts +0 -26
- package/dist/session/discovery/legacy/publication.js +0 -76
|
@@ -26,7 +26,7 @@ export function isKernelOrigin(origin) {
|
|
|
26
26
|
export async function installedIssuer(dependencies, origin, source, operation) {
|
|
27
27
|
const caller = sourceCaller(dependencies, source, operation);
|
|
28
28
|
const domain = await createSchema(caller.dispatch, dependencies.limits).inspect(origin);
|
|
29
|
-
const remote = domain.
|
|
29
|
+
const remote = domain.release;
|
|
30
30
|
return remote === null || remote.identity.issuer === dependencies.kernel
|
|
31
31
|
? undefined
|
|
32
32
|
: remote.identity.issuer;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MintedCredential
|
|
1
|
+
import type { MintedCredential } from '@astrale-os/kernel-core/auth';
|
|
2
2
|
import type { IssuerId } from '@astrale-os/kernel-core/auth/issuer';
|
|
3
3
|
import type { Client } from '../../client/index.js';
|
|
4
4
|
import type { SchemaOptions } from '../../schema/schema.js';
|
|
@@ -29,18 +29,12 @@ export interface DomainExchangeRequest {
|
|
|
29
29
|
readonly issuer: IssuerId;
|
|
30
30
|
/** Requested delegation lifetime; the source credential's remaining lifetime bounds it. */
|
|
31
31
|
readonly ttlSeconds: number;
|
|
32
|
-
readonly attenuation: UnresolvedIdentityExpr;
|
|
33
32
|
/**
|
|
34
33
|
* Lifetime the returned credential must exceed. A source that bounds the delegation within it is
|
|
35
34
|
* exhausted rather than exchanged.
|
|
36
35
|
*/
|
|
37
36
|
readonly coverageMs?: number;
|
|
38
37
|
}
|
|
39
|
-
/** The attenuation that delegates the source caller's own identity. */
|
|
40
|
-
export declare const SELF_ATTENUATION: Readonly<{
|
|
41
|
-
readonly kind: 'identity';
|
|
42
|
-
readonly self: true;
|
|
43
|
-
}>;
|
|
44
38
|
/**
|
|
45
39
|
* Delegate the source caller to one Domain issuer and redeem that delegation at the issuer's
|
|
46
40
|
* advertised endpoint for the Domain's credential to the source Kernel.
|
|
@@ -4,8 +4,6 @@ import { delegationCoverageMs } from '../credential/index.js';
|
|
|
4
4
|
import { resolveAuth } from '../routing/index.js';
|
|
5
5
|
import { redeem, tokenEndpoint } from './issuer.js';
|
|
6
6
|
import { delegationTtl, isAuthority, renewing, sourceCaller, sourceExhausted } from './source.js';
|
|
7
|
-
/** The attenuation that delegates the source caller's own identity. */
|
|
8
|
-
export const SELF_ATTENUATION = Object.freeze({ kind: 'identity', self: true });
|
|
9
7
|
/**
|
|
10
8
|
* Delegate the source caller to one Domain issuer and redeem that delegation at the issuer's
|
|
11
9
|
* advertised endpoint for the Domain's credential to the source Kernel.
|
|
@@ -22,7 +20,6 @@ export async function exchangeDomainCredential(dependencies, source, request, op
|
|
|
22
20
|
const delegation = await credentialApi(caller.call).delegate(principal, {
|
|
23
21
|
audience: request.issuer,
|
|
24
22
|
ttlSeconds,
|
|
25
|
-
attenuation: request.attenuation,
|
|
26
23
|
});
|
|
27
24
|
const credential = await redeem(dependencies, request.issuer, endpoint, delegation, operation);
|
|
28
25
|
// A Domain credential never outlives its source, so only a fresher source can lengthen it.
|
|
@@ -47,7 +44,6 @@ export async function acquireDomainCredential(dependencies, request, operation)
|
|
|
47
44
|
const exchange = (source) => exchangeDomainCredential(dependencies, source, {
|
|
48
45
|
issuer: request.issuer,
|
|
49
46
|
ttlSeconds: request.ttlSeconds,
|
|
50
|
-
attenuation: SELF_ATTENUATION,
|
|
51
47
|
...(request.ttlSeconds * 1_000 > coverageMs ? { coverageMs } : {}),
|
|
52
48
|
}, operation);
|
|
53
49
|
const source = await resolveAuth(auth, call, operation);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { callableOrigin, installedIssuer } from './domain.js';
|
|
2
|
-
export { acquireDomainCredential, exchangeDomainCredential,
|
|
2
|
+
export { acquireDomainCredential, exchangeDomainCredential, type DomainCredential, type DomainExchangeRequest, type ExchangeDependencies, } from './exchange.js';
|
|
3
3
|
export { admitExchangeOptions, admitExchangeRequest, type ExchangeRequest, type SessionExchangeOptions, type SessionExchangeRequest, } from './options.js';
|
|
4
4
|
export { createSessionExchange, type SessionExchange } from './presentation.js';
|
|
5
5
|
export { isAuthority } from './source.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { callableOrigin, installedIssuer } from './domain.js';
|
|
2
|
-
export { acquireDomainCredential, exchangeDomainCredential,
|
|
2
|
+
export { acquireDomainCredential, exchangeDomainCredential, } from './exchange.js';
|
|
3
3
|
export { admitExchangeOptions, admitExchangeRequest, } from './options.js';
|
|
4
4
|
export { createSessionExchange } from './presentation.js';
|
|
5
5
|
export { isAuthority } from './source.js';
|
|
@@ -2,7 +2,7 @@ import { ClientError } from '../../errors/index.js';
|
|
|
2
2
|
import { runSessionOperation } from '../context/index.js';
|
|
3
3
|
import { createSessionCredentialProvider, delegationCoverageMs } from '../credential/index.js';
|
|
4
4
|
import { createInstallations, declaringOrigin, isKernelOrigin } from './domain.js';
|
|
5
|
-
import { exchangeDomainCredential
|
|
5
|
+
import { exchangeDomainCredential } from './exchange.js';
|
|
6
6
|
import { MAXIMUM_EXCHANGE_SOURCES } from './limits.js';
|
|
7
7
|
import { isAuthority, renewing } from './source.js';
|
|
8
8
|
/**
|
|
@@ -51,7 +51,6 @@ export function createSessionExchange(dependencies, options) {
|
|
|
51
51
|
mint: (signal) => exchangeDomainCredential(dependencies, source, {
|
|
52
52
|
issuer: domain,
|
|
53
53
|
ttlSeconds: options.ttlSeconds,
|
|
54
|
-
attenuation: SELF_ATTENUATION,
|
|
55
54
|
coverageMs,
|
|
56
55
|
}, dependencies.operation(signal)),
|
|
57
56
|
});
|
|
@@ -8,7 +8,7 @@ import { ExchangeError } from '../../errors/index.js';
|
|
|
8
8
|
/** A resolved source that carries both a credential and its delegation. */
|
|
9
9
|
export type SourceAuthority = Required<EffectiveAuth>;
|
|
10
10
|
/** Source Kernel syscalls issued as exactly one admitted source caller within one operation. */
|
|
11
|
-
|
|
11
|
+
interface SourceCaller {
|
|
12
12
|
dispatch(call: Call): Promise<Result>;
|
|
13
13
|
readonly call: AuthCall;
|
|
14
14
|
}
|
|
@@ -30,3 +30,4 @@ export declare function delegationTtl(credential: string | undefined, ttlSeconds
|
|
|
30
30
|
* concurrent Calls share one renewal; an auth that cannot refresh keeps the failure.
|
|
31
31
|
*/
|
|
32
32
|
export declare function renewing<T>(auth: SessionAuth, call: invocation.Call, source: SourceAuthority, operation: SessionOperation, attempt: (source: SourceAuthority) => Promise<T>): Promise<T>;
|
|
33
|
+
export {};
|
package/dist/session/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export type { SessionControlOptions, SessionPolicy } from './context/index.js';
|
|
2
|
-
export type { ContentApi, ContentLocation, ContentUploadOptions, ContentUploadResult, } from './content.js';
|
|
2
|
+
export type { ContentApi, ContentDownload, ContentLocation, ContentRejection, ContentUploadOptions, ContentUploadResult, } from './content/index.js';
|
|
3
3
|
export { bindSession, type BoundClientSession, type BoundSessionControls, type BoundSessionSource, } from './bound.js';
|
|
4
4
|
export { createSessionCredentialProvider, type SessionCredential, type SessionCredentialProvider, type SessionCredentialProviderOptions, type SessionCredentialState, } from './credential/index.js';
|
|
5
5
|
export type { IntrinsicRelease, SessionSnapshot } from './discovery/index.js';
|
|
6
6
|
export type { SessionExchangeOptions, SessionExchangeRequest } from './exchange/index.js';
|
|
7
7
|
export type { Auth, PersistedRoute, SessionRouteArtifact, SessionRouteStore, SessionAuth, SessionEnvelopeTransport, SessionRequestOptions, SessionRequestOptionsWithBody, } from './routing/index.js';
|
|
8
|
-
export {
|
|
8
|
+
export type { ClientSessionOptions } from './options.js';
|
|
9
|
+
export { ClientSession, connect, type ConnectOptions } from './session.js';
|
|
9
10
|
export type { CallableReference, InputOfReference, InputModeOfReference, InstanceCallableReference, OutputOfReference, } from './reference.js';
|
|
10
11
|
export { reference } from './reference.js';
|
|
11
12
|
export { execution, type ExecutionOutcome, type ExecutionRef, type ExecutionState, type ExecutionStatus, } from './execution.js';
|
package/dist/session/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { bindSession, } from './bound.js';
|
|
2
2
|
export { createSessionCredentialProvider, } from './credential/index.js';
|
|
3
|
-
export { ClientSession, connect
|
|
3
|
+
export { ClientSession, connect } from './session.js';
|
|
4
4
|
export { reference } from './reference.js';
|
|
5
5
|
export { execution, } from './execution.js';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { IssuerId } from '@astrale-os/kernel-core/auth/issuer';
|
|
2
|
+
import type { ClientFactory, ClientPool as ClientPoolType } from '../pool/index.js';
|
|
3
|
+
import type { ClientWarning } from '../transport/auto/index.js';
|
|
4
|
+
import type { Fetch } from '../transport/http/index.js';
|
|
5
|
+
import type { WebSocketConstructor } from '../transport/websocket/index.js';
|
|
6
|
+
import type { SessionPolicy } from './context/index.js';
|
|
7
|
+
import type { SessionExchangeOptions } from './exchange/index.js';
|
|
8
|
+
import type { ClientPoolCapability, SessionAuth, SessionEnvelopeTransport, SessionRouteStore } from './routing/index.js';
|
|
9
|
+
import { ClientPool } from '../pool/index.js';
|
|
10
|
+
import { RouteCache } from './routing/index.js';
|
|
11
|
+
export interface ClientSessionOptions {
|
|
12
|
+
/** Exact canonical source Kernel identity; its invocation and discovery endpoints are derived. */
|
|
13
|
+
readonly kernel: string;
|
|
14
|
+
readonly fetch?: Fetch;
|
|
15
|
+
readonly client?: ClientFactory;
|
|
16
|
+
readonly pool?: Pick<ClientPoolType, 'clientFor'>;
|
|
17
|
+
readonly websocket?: WebSocketConstructor;
|
|
18
|
+
readonly auth?: SessionAuth;
|
|
19
|
+
/**
|
|
20
|
+
* Present each Domain callable with a credential its declaring Domain exchanges for the `auth`
|
|
21
|
+
* caller, so the Domain is the principal and the caller is `auth`. Kernel and local callables keep
|
|
22
|
+
* the `auth` credential. `connect` defaults to `auto` when `auth` is present; `new ClientSession`
|
|
23
|
+
* keeps source authority when this option is omitted. `{ mode: 'source' }` keeps it for every Call.
|
|
24
|
+
*/
|
|
25
|
+
readonly exchange?: SessionExchangeOptions;
|
|
26
|
+
/** Optional caller-owned persistence for bounded confidential route artifacts. */
|
|
27
|
+
readonly routeStore?: SessionRouteStore;
|
|
28
|
+
readonly policy: SessionPolicy;
|
|
29
|
+
readonly envelopeTransport?: SessionEnvelopeTransport;
|
|
30
|
+
readonly onWarning?: (warning: ClientWarning) => void;
|
|
31
|
+
/** Bounds the source Kernel's own `release.json`. */
|
|
32
|
+
readonly maximumReleaseBytes?: number;
|
|
33
|
+
readonly maximumBundleBytes?: number;
|
|
34
|
+
readonly maximumResponseBytes?: number;
|
|
35
|
+
readonly timeoutMs?: number;
|
|
36
|
+
readonly schemaLifecycleTimeoutMs?: number;
|
|
37
|
+
}
|
|
38
|
+
/** The caller's options once admitted, defaulted and captured, ready for the Session to wire. */
|
|
39
|
+
export interface SessionConfiguration {
|
|
40
|
+
readonly kernel: IssuerId;
|
|
41
|
+
readonly sourceEndpoint: string;
|
|
42
|
+
readonly policy: Readonly<SessionPolicy>;
|
|
43
|
+
readonly fetch: Fetch;
|
|
44
|
+
readonly maximumReleaseBytes: number;
|
|
45
|
+
readonly maximumBundleBytes: number;
|
|
46
|
+
readonly maximumResponseBytes: number;
|
|
47
|
+
readonly timeoutMs: number;
|
|
48
|
+
readonly schemaLifecycleTimeoutMs: number;
|
|
49
|
+
readonly websocketAvailable: boolean;
|
|
50
|
+
/** Present when the Session created, and therefore closes, its own pool. */
|
|
51
|
+
readonly ownedPool?: ClientPool;
|
|
52
|
+
readonly pool: ClientPoolCapability;
|
|
53
|
+
readonly routes: RouteCache;
|
|
54
|
+
readonly auth: SessionAuth | undefined;
|
|
55
|
+
readonly exchange: Readonly<{
|
|
56
|
+
ttlSeconds: number;
|
|
57
|
+
}> | undefined;
|
|
58
|
+
readonly envelopeTransport: SessionEnvelopeTransport;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Settle the caller's options in their public rejection order: the options object, policy, Kernel,
|
|
62
|
+
* Fetch, client/pool exclusivity, byte limits, durations, pool, route store, auth, exchange and
|
|
63
|
+
* envelope transport.
|
|
64
|
+
*/
|
|
65
|
+
export declare function acceptSessionOptions(options: ClientSessionOptions): SessionConfiguration;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Client } from '../client/index.js';
|
|
2
|
+
import { ClientPool } from '../pool/index.js';
|
|
3
|
+
import { DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS } from '../schema/index.js';
|
|
4
|
+
import { AutoTransport } from '../transport/auto/index.js';
|
|
5
|
+
import { HttpTransport } from '../transport/http/index.js';
|
|
6
|
+
import { WebSocketTransport } from '../transport/websocket/index.js';
|
|
7
|
+
import { admitKernel, admitPolicy, DEFAULT_MAXIMUM_BUNDLE_BYTES, DEFAULT_MAXIMUM_RELEASE_BYTES, DEFAULT_MAXIMUM_RESPONSE_BYTES, DEFAULT_TIMEOUT_MS, kernelInvocationEndpoint, platformDuration, positive, } from './context/index.js';
|
|
8
|
+
import { admitExchangeOptions } from './exchange/index.js';
|
|
9
|
+
import { admitEnvelopeTransport, admitSessionAuth, RouteCache } from './routing/index.js';
|
|
10
|
+
/**
|
|
11
|
+
* Settle the caller's options in their public rejection order: the options object, policy, Kernel,
|
|
12
|
+
* Fetch, client/pool exclusivity, byte limits, durations, pool, route store, auth, exchange and
|
|
13
|
+
* envelope transport.
|
|
14
|
+
*/
|
|
15
|
+
export function acceptSessionOptions(options) {
|
|
16
|
+
if (options === null || typeof options !== 'object') {
|
|
17
|
+
throw new TypeError('ClientSession options are invalid.');
|
|
18
|
+
}
|
|
19
|
+
const policy = admitPolicy(options.policy);
|
|
20
|
+
const kernel = admitKernel(options.kernel, policy.allowInsecureHttp === true);
|
|
21
|
+
const sourceEndpoint = kernelInvocationEndpoint(kernel);
|
|
22
|
+
const fetch = options.fetch ?? globalThis.fetch;
|
|
23
|
+
if (typeof fetch !== 'function')
|
|
24
|
+
throw new TypeError('ClientSession requires Fetch.');
|
|
25
|
+
const fetchImpl = options.fetch === undefined ? fetch.bind(globalThis) : fetch;
|
|
26
|
+
if (options.client !== undefined && options.pool !== undefined) {
|
|
27
|
+
throw new TypeError('ClientSession accepts either client or pool, not both.');
|
|
28
|
+
}
|
|
29
|
+
const maximumReleaseBytes = positive(options.maximumReleaseBytes ?? DEFAULT_MAXIMUM_RELEASE_BYTES, 'maximumReleaseBytes');
|
|
30
|
+
const maximumBundleBytes = positive(options.maximumBundleBytes ?? DEFAULT_MAXIMUM_BUNDLE_BYTES, 'maximumBundleBytes');
|
|
31
|
+
const maximumResponseBytes = positive(options.maximumResponseBytes ?? DEFAULT_MAXIMUM_RESPONSE_BYTES, 'maximumResponseBytes');
|
|
32
|
+
const timeoutMs = platformDuration(options.timeoutMs ?? DEFAULT_TIMEOUT_MS, 'timeoutMs');
|
|
33
|
+
const schemaLifecycleTimeoutMs = platformDuration(options.schemaLifecycleTimeoutMs ?? DEFAULT_SCHEMA_LIFECYCLE_TIMEOUT_MS, 'schemaLifecycleTimeoutMs');
|
|
34
|
+
let ownedPool;
|
|
35
|
+
let pool;
|
|
36
|
+
if (options.pool === undefined) {
|
|
37
|
+
ownedPool = new ClientPool({
|
|
38
|
+
client: options.client ??
|
|
39
|
+
defaultClientFactory({
|
|
40
|
+
fetch: fetchImpl,
|
|
41
|
+
...(options.websocket === undefined ? {} : { websocket: options.websocket }),
|
|
42
|
+
...(options.onWarning === undefined ? {} : { onWarning: options.onWarning }),
|
|
43
|
+
maximumResponseBytes,
|
|
44
|
+
timeoutMs,
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
47
|
+
pool = captureClientPool(ownedPool);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
pool = captureClientPool(options.pool);
|
|
51
|
+
}
|
|
52
|
+
// The route store is read while it is captured, so it keeps its place before auth and exchange.
|
|
53
|
+
const routes = new RouteCache(policy.maximumRouteAgeMs, undefined, options.routeStore);
|
|
54
|
+
const auth = admitSessionAuth(options.auth);
|
|
55
|
+
const exchange = admitExchangeOptions(options.exchange, auth);
|
|
56
|
+
return Object.freeze({
|
|
57
|
+
kernel,
|
|
58
|
+
sourceEndpoint,
|
|
59
|
+
policy,
|
|
60
|
+
fetch: fetchImpl,
|
|
61
|
+
maximumReleaseBytes,
|
|
62
|
+
maximumBundleBytes,
|
|
63
|
+
maximumResponseBytes,
|
|
64
|
+
timeoutMs,
|
|
65
|
+
schemaLifecycleTimeoutMs,
|
|
66
|
+
websocketAvailable: options.client !== undefined ||
|
|
67
|
+
options.pool !== undefined ||
|
|
68
|
+
options.websocket !== undefined ||
|
|
69
|
+
typeof WebSocket === 'function',
|
|
70
|
+
...(ownedPool === undefined ? {} : { ownedPool }),
|
|
71
|
+
pool,
|
|
72
|
+
routes,
|
|
73
|
+
auth,
|
|
74
|
+
exchange,
|
|
75
|
+
envelopeTransport: admitEnvelopeTransport(options.envelopeTransport ?? 'http'),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function captureClientPool(input) {
|
|
79
|
+
if (input === null ||
|
|
80
|
+
typeof input !== 'object' ||
|
|
81
|
+
typeof input.clientFor !== 'function') {
|
|
82
|
+
throw new TypeError('Session client pool capability is invalid.');
|
|
83
|
+
}
|
|
84
|
+
return Object.freeze({
|
|
85
|
+
clientFor: (target) => admitPooledClient(input.clientFor.call(input, target)),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function admitPooledClient(input) {
|
|
89
|
+
if (input === null ||
|
|
90
|
+
typeof input !== 'object' ||
|
|
91
|
+
typeof input.dispatch !== 'function' ||
|
|
92
|
+
typeof input.as !== 'function' ||
|
|
93
|
+
typeof input.close !== 'function') {
|
|
94
|
+
throw new TypeError('Session client pool capability returned an invalid Client.');
|
|
95
|
+
}
|
|
96
|
+
return input;
|
|
97
|
+
}
|
|
98
|
+
function defaultClientFactory(options) {
|
|
99
|
+
return (target) => {
|
|
100
|
+
switch (target.transport) {
|
|
101
|
+
case 'http':
|
|
102
|
+
return new Client({
|
|
103
|
+
transport: new HttpTransport({
|
|
104
|
+
url: target.url,
|
|
105
|
+
fetch: options.fetch,
|
|
106
|
+
timeoutMs: options.timeoutMs,
|
|
107
|
+
maximumResponseBytes: options.maximumResponseBytes,
|
|
108
|
+
}),
|
|
109
|
+
});
|
|
110
|
+
case 'websocket':
|
|
111
|
+
return new Client({
|
|
112
|
+
transport: new WebSocketTransport({
|
|
113
|
+
url: target.url,
|
|
114
|
+
timeoutMs: options.timeoutMs,
|
|
115
|
+
maximumResponseBytes: options.maximumResponseBytes,
|
|
116
|
+
...(options.websocket === undefined ? {} : { websocket: options.websocket }),
|
|
117
|
+
}),
|
|
118
|
+
});
|
|
119
|
+
case 'auto':
|
|
120
|
+
return new Client({
|
|
121
|
+
transport: new AutoTransport({
|
|
122
|
+
endpoints: target.endpoints,
|
|
123
|
+
fetch: options.fetch,
|
|
124
|
+
timeoutMs: options.timeoutMs,
|
|
125
|
+
maximumResponseBytes: options.maximumResponseBytes,
|
|
126
|
+
...(options.websocket === undefined ? {} : { websocket: options.websocket }),
|
|
127
|
+
...(options.onWarning === undefined ? {} : { onWarning: options.onWarning }),
|
|
128
|
+
}),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import { invocation } from '@astrale-os/kernel-protocol';
|
|
1
|
+
import type { invocation } from '@astrale-os/kernel-protocol';
|
|
2
2
|
import type { EffectiveAuth } from './auth.js';
|
|
3
|
+
import type { SessionRouteStore } from './store.js';
|
|
3
4
|
export interface LearnedRoute {
|
|
4
5
|
readonly route: invocation.Route;
|
|
5
6
|
readonly credential?: string;
|
|
6
7
|
readonly expiresAt: number;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
readonly
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
}
|
|
16
|
-
/** Caller-owned persistence for confidential route artifacts. */
|
|
17
|
-
export interface SessionRouteStore {
|
|
18
|
-
read(): unknown;
|
|
19
|
-
write(artifact: SessionRouteArtifact): void;
|
|
9
|
+
/** One warm entry; `sealed` and `integrity` are present only when it can be persisted. */
|
|
10
|
+
export interface CachedRoute {
|
|
11
|
+
readonly learned: LearnedRoute;
|
|
12
|
+
/** Separate from route age; derived only from a supported finite carrier expiry. */
|
|
13
|
+
readonly credentialRefreshBoundary?: number;
|
|
14
|
+
readonly sealed?: LearnedRoute;
|
|
15
|
+
readonly integrity?: string;
|
|
20
16
|
}
|
|
21
17
|
/** Confidential warm routing state owned by exactly one ClientSession. */
|
|
22
18
|
export declare class RouteCache {
|
|
@@ -35,6 +31,5 @@ export declare class RouteCache {
|
|
|
35
31
|
private invalidate;
|
|
36
32
|
private reserve;
|
|
37
33
|
private restore;
|
|
38
|
-
private restoreInput;
|
|
39
34
|
private persist;
|
|
40
35
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { invocation } from '@astrale-os/kernel-protocol';
|
|
2
1
|
import { DEFAULT_MAXIMUM_ROUTES } from '../context/index.js';
|
|
3
|
-
|
|
2
|
+
import { credentialExpiry, refreshBoundary } from './expiry.js';
|
|
3
|
+
import { digestText, matchesIntegrity, routeIntegrity } from './integrity.js';
|
|
4
|
+
import { captureRouteStore, restoreRoutes, routeArtifact } from './store.js';
|
|
4
5
|
/** Confidential warm routing state owned by exactly one ClientSession. */
|
|
5
6
|
export class RouteCache {
|
|
6
7
|
maximumAgeMs;
|
|
@@ -11,12 +12,14 @@ export class RouteCache {
|
|
|
11
12
|
constructor(maximumAgeMs, maximumSize = DEFAULT_MAXIMUM_ROUTES, store) {
|
|
12
13
|
this.maximumAgeMs = maximumAgeMs;
|
|
13
14
|
this.maximumSize = maximumSize;
|
|
14
|
-
this.store = store === undefined ? undefined :
|
|
15
|
+
this.store = store === undefined ? undefined : captureRouteStore(store);
|
|
15
16
|
this.restore();
|
|
16
17
|
}
|
|
17
18
|
async key(source, call, auth) {
|
|
18
19
|
const credential = auth.credential === undefined ? 'anonymous' : await digestText(auth.credential);
|
|
19
|
-
const delegate = auth.delegate === undefined
|
|
20
|
+
const delegate = auth.delegate === undefined
|
|
21
|
+
? 'anonymous'
|
|
22
|
+
: await digestText(JSON.stringify({ ttlSeconds: auth.delegate.ttlSeconds }));
|
|
20
23
|
return JSON.stringify([source, call.target, credential, delegate]);
|
|
21
24
|
}
|
|
22
25
|
async get(key, sourceCredential, now, operationDeadline) {
|
|
@@ -55,16 +58,16 @@ export class RouteCache {
|
|
|
55
58
|
return cached.learned;
|
|
56
59
|
}
|
|
57
60
|
async learn(key, route, credential, sourceCredential, now = Date.now()) {
|
|
58
|
-
const
|
|
59
|
-
const credentialRefreshBoundary =
|
|
60
|
-
const expiresAt = Math.min(now + this.maximumAgeMs, refreshBoundary(
|
|
61
|
+
const expiry = credential === undefined ? undefined : credentialExpiry(credential);
|
|
62
|
+
const credentialRefreshBoundary = expiry === undefined ? undefined : refreshBoundary(expiry);
|
|
63
|
+
const expiresAt = Math.min(now + this.maximumAgeMs, refreshBoundary(expiry));
|
|
61
64
|
const entry = Object.freeze({
|
|
62
65
|
route,
|
|
63
66
|
...(credential === undefined ? {} : { credential }),
|
|
64
67
|
expiresAt,
|
|
65
68
|
});
|
|
66
69
|
// A carrier with no supported finite expiry may be used for this follow, but never warmed.
|
|
67
|
-
if (credential !== undefined &&
|
|
70
|
+
if (credential !== undefined && expiry === undefined)
|
|
68
71
|
return entry;
|
|
69
72
|
if (expiresAt <= now)
|
|
70
73
|
return entry;
|
|
@@ -119,197 +122,25 @@ export class RouteCache {
|
|
|
119
122
|
if (this.store === undefined)
|
|
120
123
|
return;
|
|
121
124
|
try {
|
|
122
|
-
|
|
125
|
+
const restored = restoreRoutes(this.store.read(), now, this.maximumAgeMs, this.maximumSize);
|
|
126
|
+
for (const [key, entry] of restored) {
|
|
127
|
+
this.reserve(key);
|
|
128
|
+
this.entries.set(key, entry);
|
|
129
|
+
}
|
|
123
130
|
}
|
|
124
131
|
catch {
|
|
125
132
|
this.keyTokens.clear();
|
|
126
133
|
this.entries.clear();
|
|
127
134
|
}
|
|
128
135
|
}
|
|
129
|
-
restoreInput(input, now) {
|
|
130
|
-
if (input === undefined)
|
|
131
|
-
return;
|
|
132
|
-
if (typeof input !== 'object' || input === null || Array.isArray(input))
|
|
133
|
-
return;
|
|
134
|
-
const artifact = input;
|
|
135
|
-
if (artifact.version !== 1 ||
|
|
136
|
-
typeof artifact.entries !== 'object' ||
|
|
137
|
-
artifact.entries === null ||
|
|
138
|
-
Array.isArray(artifact.entries)) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
let count = 0;
|
|
142
|
-
for (const key in artifact.entries) {
|
|
143
|
-
if (!Object.hasOwn(artifact.entries, key))
|
|
144
|
-
continue;
|
|
145
|
-
count += 1;
|
|
146
|
-
if (count > this.maximumSize) {
|
|
147
|
-
this.keyTokens.clear();
|
|
148
|
-
this.entries.clear();
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const value = Reflect.get(artifact.entries, key);
|
|
152
|
-
const entry = admitStoredEntry(value, now, this.maximumAgeMs);
|
|
153
|
-
if (entry === undefined)
|
|
154
|
-
continue;
|
|
155
|
-
this.reserve(key);
|
|
156
|
-
this.entries.set(key, entry);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
136
|
persist() {
|
|
160
137
|
if (this.store === undefined)
|
|
161
138
|
return;
|
|
162
|
-
const entries = Object.fromEntries([...this.entries].flatMap(([key, cached]) => cached.integrity === undefined
|
|
163
|
-
? []
|
|
164
|
-
: [
|
|
165
|
-
[
|
|
166
|
-
key,
|
|
167
|
-
Object.freeze({
|
|
168
|
-
...(cached.sealed ?? cached.learned),
|
|
169
|
-
integrity: cached.integrity,
|
|
170
|
-
}),
|
|
171
|
-
],
|
|
172
|
-
]));
|
|
173
139
|
try {
|
|
174
|
-
this.store.write(
|
|
140
|
+
this.store.write(routeArtifact(this.entries));
|
|
175
141
|
}
|
|
176
142
|
catch {
|
|
177
143
|
// A cache-store outage must not turn a valid invocation into a product failure.
|
|
178
144
|
}
|
|
179
145
|
}
|
|
180
146
|
}
|
|
181
|
-
function captureSessionRouteStore(input) {
|
|
182
|
-
if (input === null ||
|
|
183
|
-
typeof input !== 'object' ||
|
|
184
|
-
typeof input.read !== 'function' ||
|
|
185
|
-
typeof input.write !== 'function') {
|
|
186
|
-
throw new TypeError('Session route store capability is invalid.');
|
|
187
|
-
}
|
|
188
|
-
const read = input.read;
|
|
189
|
-
const write = input.write;
|
|
190
|
-
return Object.freeze({
|
|
191
|
-
read: () => read.call(input),
|
|
192
|
-
write: (artifact) => write.call(input, artifact),
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
function admitStoredEntry(input, now, maximumAgeMs) {
|
|
196
|
-
try {
|
|
197
|
-
if (typeof input !== 'object' || input === null || Array.isArray(input))
|
|
198
|
-
return undefined;
|
|
199
|
-
const value = input;
|
|
200
|
-
if ((value.credential !== undefined && typeof value.credential !== 'string') ||
|
|
201
|
-
typeof value.expiresAt !== 'number' ||
|
|
202
|
-
!Number.isSafeInteger(value.expiresAt) ||
|
|
203
|
-
typeof value.integrity !== 'string' ||
|
|
204
|
-
!/^[A-Za-z0-9_-]{43}$/u.test(value.integrity)) {
|
|
205
|
-
return undefined;
|
|
206
|
-
}
|
|
207
|
-
const credentialExpiry = value.credential === undefined ? undefined : jwtExpiry(value.credential);
|
|
208
|
-
if (value.credential !== undefined && credentialExpiry === undefined)
|
|
209
|
-
return undefined;
|
|
210
|
-
const sealed = Object.freeze({
|
|
211
|
-
route: invocation.acceptRoute(value.route),
|
|
212
|
-
...(value.credential === undefined ? {} : { credential: value.credential }),
|
|
213
|
-
expiresAt: value.expiresAt,
|
|
214
|
-
});
|
|
215
|
-
const expiresAt = Math.min(value.expiresAt, now + maximumAgeMs, refreshBoundary(credentialExpiry));
|
|
216
|
-
if (expiresAt <= now)
|
|
217
|
-
return undefined;
|
|
218
|
-
return Object.freeze({
|
|
219
|
-
learned: Object.freeze({
|
|
220
|
-
route: sealed.route,
|
|
221
|
-
...(sealed.credential === undefined ? {} : { credential: sealed.credential }),
|
|
222
|
-
expiresAt,
|
|
223
|
-
}),
|
|
224
|
-
sealed,
|
|
225
|
-
integrity: value.integrity,
|
|
226
|
-
...(credentialExpiry === undefined
|
|
227
|
-
? {}
|
|
228
|
-
: { credentialRefreshBoundary: refreshBoundary(credentialExpiry) }),
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
catch {
|
|
232
|
-
return undefined;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
function refreshBoundary(credentialExpiry) {
|
|
236
|
-
return credentialExpiry === undefined
|
|
237
|
-
? Number.POSITIVE_INFINITY
|
|
238
|
-
: credentialExpiry - DESTINATION_CREDENTIAL_REFRESH_SKEW_MS;
|
|
239
|
-
}
|
|
240
|
-
async function routeIntegrity(sourceCredential, key, learned) {
|
|
241
|
-
const webCrypto = typeof crypto === 'undefined' ? undefined : crypto;
|
|
242
|
-
if (webCrypto?.subtle === undefined) {
|
|
243
|
-
throw new TypeError('Persistent Session route integrity requires Web Crypto HMAC support.');
|
|
244
|
-
}
|
|
245
|
-
const algorithm = Object.freeze({ name: 'HMAC', hash: 'SHA-256' });
|
|
246
|
-
const cryptographicKey = await webCrypto.subtle.importKey('raw', new TextEncoder().encode(sourceCredential), algorithm, false, ['sign']);
|
|
247
|
-
const signature = await webCrypto.subtle.sign(algorithm, cryptographicKey, new TextEncoder().encode(integrityMaterial(key, learned)));
|
|
248
|
-
return encodeBase64Url(new Uint8Array(signature));
|
|
249
|
-
}
|
|
250
|
-
async function matchesIntegrity(sourceCredential, key, learned, expected) {
|
|
251
|
-
try {
|
|
252
|
-
return (await routeIntegrity(sourceCredential, key, learned)) === expected;
|
|
253
|
-
}
|
|
254
|
-
catch {
|
|
255
|
-
return false;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
function integrityMaterial(key, learned) {
|
|
259
|
-
return JSON.stringify({
|
|
260
|
-
version: 1,
|
|
261
|
-
key,
|
|
262
|
-
route: learned.route,
|
|
263
|
-
...(learned.credential === undefined ? {} : { credential: learned.credential }),
|
|
264
|
-
expiresAt: learned.expiresAt,
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
function encodeBase64Url(input) {
|
|
268
|
-
let binary = '';
|
|
269
|
-
for (const byte of input)
|
|
270
|
-
binary += String.fromCharCode(byte);
|
|
271
|
-
return globalThis.btoa(binary).replace(/\+/gu, '-').replace(/\//gu, '_').replace(/=+$/gu, '');
|
|
272
|
-
}
|
|
273
|
-
function canonicalDelegate(input) {
|
|
274
|
-
return JSON.stringify({
|
|
275
|
-
ttlSeconds: input.ttlSeconds,
|
|
276
|
-
...(input.attenuation === undefined ? {} : { attenuation: canonicalExpr(input.attenuation) }),
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
function canonicalExpr(input) {
|
|
280
|
-
return 'self' in input
|
|
281
|
-
? { kind: 'identity', self: true }
|
|
282
|
-
: { kind: 'identity', credential: input.credential };
|
|
283
|
-
}
|
|
284
|
-
async function digestText(input) {
|
|
285
|
-
const webCrypto = typeof crypto === 'undefined' ? undefined : crypto;
|
|
286
|
-
if (webCrypto?.subtle === undefined) {
|
|
287
|
-
throw new TypeError('Session route caching requires Web Crypto SHA-256 support.');
|
|
288
|
-
}
|
|
289
|
-
const bytes = await webCrypto.subtle.digest('SHA-256', new TextEncoder().encode(input));
|
|
290
|
-
return [...new Uint8Array(bytes)].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
291
|
-
}
|
|
292
|
-
function jwtExpiry(input) {
|
|
293
|
-
const parts = input.split('.');
|
|
294
|
-
if (parts.length !== 3)
|
|
295
|
-
return undefined;
|
|
296
|
-
try {
|
|
297
|
-
const encoded = parts[1].replace(/-/gu, '+').replace(/_/gu, '/');
|
|
298
|
-
const padding = '='.repeat((4 - (encoded.length % 4)) % 4);
|
|
299
|
-
const json = decodeBase64(encoded + padding);
|
|
300
|
-
const payload = JSON.parse(json);
|
|
301
|
-
return typeof payload.exp === 'number' && Number.isSafeInteger(payload.exp) && payload.exp > 0
|
|
302
|
-
? payload.exp * 1_000
|
|
303
|
-
: undefined;
|
|
304
|
-
}
|
|
305
|
-
catch {
|
|
306
|
-
return undefined;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
function decodeBase64(input) {
|
|
310
|
-
if (typeof globalThis.atob === 'function') {
|
|
311
|
-
const binary = globalThis.atob(input);
|
|
312
|
-
return new TextDecoder().decode(Uint8Array.from(binary, (character) => character.charCodeAt(0)));
|
|
313
|
-
}
|
|
314
|
-
throw new TypeError('Session route caching requires base64 decoding support.');
|
|
315
|
-
}
|
|
@@ -31,12 +31,13 @@ export declare class SessionDispatcher {
|
|
|
31
31
|
/** Reuse Session authority and route recovery while forcing HTTP for streaming calls. */
|
|
32
32
|
dispatchHttp(input: Parameters<typeof acceptCall>[0], options: SessionRequestOptions, operation: SessionOperation, body?: Blob): Promise<Result>;
|
|
33
33
|
private dispatchWith;
|
|
34
|
+
/** The cached route for this partition, evicted when it no longer passes delivery checks. */
|
|
35
|
+
private warmRoute;
|
|
34
36
|
private dispatchSource;
|
|
35
37
|
private followSource;
|
|
36
38
|
private dispatchDestinationWithRecovery;
|
|
37
39
|
private dispatchDestination;
|
|
40
|
+
/** The Client for a destination: the pooled envelope, or a fresh HTTP Client when streaming. */
|
|
41
|
+
private destinationClient;
|
|
38
42
|
private streamingClientFor;
|
|
39
43
|
}
|
|
40
|
-
export declare function requireResultKind<Kind extends 'value' | 'stream' | 'binary'>(expected: Kind, result: Result): Extract<Result, {
|
|
41
|
-
kind: Kind;
|
|
42
|
-
}>;
|