@mdbase-dev/connect 0.1.0-beta.100

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.
Files changed (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +696 -0
  3. package/dist/advanced.d.ts +9 -0
  4. package/dist/advanced.js +6 -0
  5. package/dist/application-contract.d.ts +22 -0
  6. package/dist/application-contract.js +75 -0
  7. package/dist/application-identity.d.ts +34 -0
  8. package/dist/application-identity.js +148 -0
  9. package/dist/application-session.d.ts +167 -0
  10. package/dist/application-session.js +722 -0
  11. package/dist/async.d.ts +1 -0
  12. package/dist/async.js +19 -0
  13. package/dist/authority-proof.d.ts +3 -0
  14. package/dist/authority-proof.js +24 -0
  15. package/dist/authority-sync-request.d.ts +3 -0
  16. package/dist/authority-sync-request.js +20 -0
  17. package/dist/authorization-refresh.d.ts +14 -0
  18. package/dist/authorization-refresh.js +41 -0
  19. package/dist/authorization-types.d.ts +7 -0
  20. package/dist/authorization-types.js +1 -0
  21. package/dist/authorization-url.d.ts +5 -0
  22. package/dist/authorization-url.js +34 -0
  23. package/dist/base64.d.ts +3 -0
  24. package/dist/base64.js +21 -0
  25. package/dist/browser/integrity.json +4 -0
  26. package/dist/browser/mdbase-connect.min.js +3 -0
  27. package/dist/browser/mdbase-connect.min.js.sha384 +1 -0
  28. package/dist/browser.d.ts +3 -0
  29. package/dist/browser.js +5 -0
  30. package/dist/capabilities.d.ts +24 -0
  31. package/dist/capabilities.js +91 -0
  32. package/dist/collection-client.d.ts +66 -0
  33. package/dist/collection-client.js +686 -0
  34. package/dist/connect-authorization-helpers.d.ts +4 -0
  35. package/dist/connect-authorization-helpers.js +25 -0
  36. package/dist/connect-options.d.ts +35 -0
  37. package/dist/connect-options.js +1 -0
  38. package/dist/connect.d.ts +66 -0
  39. package/dist/connect.js +711 -0
  40. package/dist/connection-file-transport.d.ts +34 -0
  41. package/dist/connection-file-transport.js +85 -0
  42. package/dist/connection-index.d.ts +3 -0
  43. package/dist/connection-index.js +20 -0
  44. package/dist/connection-notifications.d.ts +31 -0
  45. package/dist/connection-notifications.js +197 -0
  46. package/dist/connection-transport-internals.d.ts +24 -0
  47. package/dist/connection-transport-internals.js +1 -0
  48. package/dist/connection-transport.d.ts +64 -0
  49. package/dist/connection-transport.js +725 -0
  50. package/dist/connection-types.d.ts +38 -0
  51. package/dist/connection-types.js +1 -0
  52. package/dist/connection.d.ts +175 -0
  53. package/dist/connection.js +606 -0
  54. package/dist/crypto-entry.d.ts +7 -0
  55. package/dist/crypto-entry.js +4 -0
  56. package/dist/crypto.d.ts +63 -0
  57. package/dist/crypto.js +409 -0
  58. package/dist/direct-access.d.ts +3 -0
  59. package/dist/direct-access.js +29 -0
  60. package/dist/errors.d.ts +45 -0
  61. package/dist/errors.js +142 -0
  62. package/dist/external-store.d.ts +10 -0
  63. package/dist/external-store.js +10 -0
  64. package/dist/file-crypto.d.ts +25 -0
  65. package/dist/file-crypto.js +132 -0
  66. package/dist/file-sha256.d.ts +12 -0
  67. package/dist/file-sha256.js +143 -0
  68. package/dist/file-stream-source.d.ts +17 -0
  69. package/dist/file-stream-source.js +157 -0
  70. package/dist/file-transfer-internals.d.ts +23 -0
  71. package/dist/file-transfer-internals.js +228 -0
  72. package/dist/files.d.ts +115 -0
  73. package/dist/files.js +563 -0
  74. package/dist/fresh-encrypted-request.d.ts +4 -0
  75. package/dist/fresh-encrypted-request.js +28 -0
  76. package/dist/grant-key-leases.d.ts +24 -0
  77. package/dist/grant-key-leases.js +144 -0
  78. package/dist/hosted-file-request.d.ts +6 -0
  79. package/dist/hosted-file-request.js +63 -0
  80. package/dist/hosted-operation-response.d.ts +5 -0
  81. package/dist/hosted-operation-response.js +26 -0
  82. package/dist/index.d.ts +27 -0
  83. package/dist/index.js +10 -0
  84. package/dist/internal-types.d.ts +100 -0
  85. package/dist/internal-types.js +1 -0
  86. package/dist/local-file-transport.d.ts +37 -0
  87. package/dist/local-file-transport.js +457 -0
  88. package/dist/mdbase-connect.d.ts +28 -0
  89. package/dist/mdbase-connect.js +53 -0
  90. package/dist/notifications.d.ts +48 -0
  91. package/dist/notifications.js +52 -0
  92. package/dist/operation-helpers.d.ts +27 -0
  93. package/dist/operation-helpers.js +144 -0
  94. package/dist/operation-types.d.ts +707 -0
  95. package/dist/operation-types.js +1 -0
  96. package/dist/outcomes.d.ts +51 -0
  97. package/dist/outcomes.js +194 -0
  98. package/dist/pending-mutation-store.d.ts +13 -0
  99. package/dist/pending-mutation-store.js +64 -0
  100. package/dist/pending-recovery-transports.d.ts +5 -0
  101. package/dist/pending-recovery-transports.js +52 -0
  102. package/dist/popup-authorization.d.ts +31 -0
  103. package/dist/popup-authorization.js +100 -0
  104. package/dist/query-pagination.d.ts +6 -0
  105. package/dist/query-pagination.js +119 -0
  106. package/dist/request-budget.d.ts +34 -0
  107. package/dist/request-budget.js +104 -0
  108. package/dist/request-coordinator.d.ts +29 -0
  109. package/dist/request-coordinator.js +213 -0
  110. package/dist/retired-grant-keys.d.ts +9 -0
  111. package/dist/retired-grant-keys.js +56 -0
  112. package/dist/runtime-utils.d.ts +52 -0
  113. package/dist/runtime-utils.js +368 -0
  114. package/dist/saved-view-pagination.d.ts +6 -0
  115. package/dist/saved-view-pagination.js +76 -0
  116. package/dist/selection.d.ts +48 -0
  117. package/dist/selection.js +112 -0
  118. package/dist/session.d.ts +114 -0
  119. package/dist/session.js +569 -0
  120. package/dist/shared-operation.d.ts +7 -0
  121. package/dist/shared-operation.js +41 -0
  122. package/dist/stored-token.d.ts +10 -0
  123. package/dist/stored-token.js +64 -0
  124. package/dist/structured-readiness.d.ts +77 -0
  125. package/dist/structured-readiness.js +126 -0
  126. package/dist/token-response.d.ts +12 -0
  127. package/dist/token-response.js +81 -0
  128. package/dist/transient-retry.d.ts +22 -0
  129. package/dist/transient-retry.js +59 -0
  130. package/dist/watch-policy.d.ts +8 -0
  131. package/dist/watch-policy.js +12 -0
  132. package/package.json +51 -0
@@ -0,0 +1,9 @@
1
+ /** Low-level construction and test seams. Ordinary applications use the root package. */
2
+ export { MdbaseCollectionClient } from "./collection-client.js";
3
+ export type { MdbaseCollectionTransport } from "./operation-types.js";
4
+ export { createPkce } from "./runtime-utils.js";
5
+ export { connectError, connectProblem, operationProblem } from "./errors.js";
6
+ export { connectFailure, connectSuccess } from "./outcomes.js";
7
+ export type { MdbaseApplicationVerificationStore, MdbaseApplicationSessionConnect } from "./application-session.js";
8
+ export { MdbaseSession } from "./session.js";
9
+ export type { MdbaseSessionConnect, MdbaseSessionOptions, MdbaseSessionSnapshot } from "./session.js";
@@ -0,0 +1,6 @@
1
+ /** Low-level construction and test seams. Ordinary applications use the root package. */
2
+ export { MdbaseCollectionClient } from "./collection-client.js";
3
+ export { createPkce } from "./runtime-utils.js";
4
+ export { connectError, connectProblem, operationProblem } from "./errors.js";
5
+ export { connectFailure, connectSuccess } from "./outcomes.js";
6
+ export { MdbaseSession } from "./session.js";
@@ -0,0 +1,22 @@
1
+ import { type ApplicationCapabilityId, type ApplicationCapabilityRequirements, type LegacyApplicationCapabilityRequirements, type LegacyApplicationCapabilityId, type ApplicationRequirements, type LegacyApplicationRequirements, type MdbaseAppManifest, type LegacyMdbaseAppManifest, type CollectionOperation } from "@mdbase-dev/connect-protocol";
2
+ export declare const DEFAULT_OPERATIONS: CollectionOperation[];
3
+ /** SDK input compatibility boundary; protocol ApplicationRequirements remains v2-only. */
4
+ export type MdbaseApplicationManifest = MdbaseAppManifest | LegacyMdbaseAppManifest;
5
+ export type MdbaseApplicationRequirements = ApplicationRequirements | LegacyApplicationRequirements;
6
+ export type MdbaseApplicationCapabilityRequirements = ApplicationCapabilityRequirements | LegacyApplicationCapabilityRequirements;
7
+ export type MdbaseApplicationCapabilityId = ApplicationCapabilityId | LegacyApplicationCapabilityId;
8
+ interface MdbaseAuthorizationSelection {
9
+ operations?: CollectionOperation[];
10
+ capabilities?: MdbaseApplicationCapabilityId[];
11
+ }
12
+ export declare function semanticContractVersion(requirements: MdbaseApplicationRequirements): 1 | 2;
13
+ export declare function invalidAuthorizationSelection(message: string): never;
14
+ export declare function validateAuthorizationSelection(requirements: MdbaseApplicationRequirements, options: MdbaseAuthorizationSelection): void;
15
+ export declare function declaredOperations(requirements: MdbaseApplicationRequirements): CollectionOperation[];
16
+ export declare function authorizationOperations(application: {
17
+ requirements: MdbaseApplicationRequirements;
18
+ provisions?: MdbaseApplicationManifest["provisions"];
19
+ }, options: MdbaseAuthorizationSelection): CollectionOperation[];
20
+ export declare function retainedCapabilities(requirements: MdbaseApplicationRequirements, operations: CollectionOperation[]): MdbaseApplicationCapabilityId[];
21
+ export declare function authorizationFiles(requirements: MdbaseApplicationRequirements): import("@mdbase-dev/connect-protocol").ApplicationFileRequest | undefined;
22
+ export {};
@@ -0,0 +1,75 @@
1
+ import { APPLICATION_SETUP_OPERATIONS, applicationFileRequest, capabilityOperationsForContractVersion } from "@mdbase-dev/connect-protocol";
2
+ import { connectError } from "./errors.js";
3
+ export const DEFAULT_OPERATIONS = ["describe", "changes", "read", "query"];
4
+ export function semanticContractVersion(requirements) {
5
+ const version = requirements.capabilities === undefined ? 1 : requirements.capabilities?.contract_version;
6
+ if (version !== 1 && version !== 2)
7
+ invalidAuthorizationSelection("Unsupported declared capability contract version.");
8
+ return version;
9
+ }
10
+ export function invalidAuthorizationSelection(message) {
11
+ throw connectError("invalid_application_manifest", message, {
12
+ details: { issues: [{ path: "/requirements/capabilities", keyword: "authorizationSelection", message, params: {} }] }
13
+ });
14
+ }
15
+ export function validateAuthorizationSelection(requirements, options) {
16
+ if (options.operations !== undefined && options.capabilities !== undefined) {
17
+ invalidAuthorizationSelection("Specify operations or capabilities, not both.");
18
+ }
19
+ if (options.operations !== undefined && semanticContractVersion(requirements) !== 1) {
20
+ invalidAuthorizationSelection("Exact operations authorization is only supported for legacy v1 declarations.");
21
+ }
22
+ if (options.capabilities !== undefined) {
23
+ const declared = new Set([
24
+ ...(requirements.capabilities?.required ?? []),
25
+ ...(requirements.capabilities?.optional ?? [])
26
+ ]);
27
+ if (options.capabilities.some((id) => !declared.has(id)
28
+ || capabilityOperationsForContractVersion(semanticContractVersion(requirements), id) === undefined)) {
29
+ invalidAuthorizationSelection("Authorization can only include capabilities declared by the application.");
30
+ }
31
+ }
32
+ }
33
+ export function declaredOperations(requirements) {
34
+ const capabilities = requirements.capabilities;
35
+ if (!capabilities)
36
+ return [...DEFAULT_OPERATIONS];
37
+ return [...new Set([...capabilities.required, ...(capabilities.optional ?? [])].flatMap((id) => capabilityOperationsForContractVersion(capabilities.contract_version, id) ?? []))];
38
+ }
39
+ export function authorizationOperations(application, options) {
40
+ const { requirements } = application;
41
+ validateAuthorizationSelection(requirements, options);
42
+ // Legacy callers selected independent exact operations, including subsets of declarations.
43
+ if (semanticContractVersion(requirements) === 1) {
44
+ if (options.operations !== undefined)
45
+ return [...new Set(options.operations)];
46
+ if (options.capabilities === undefined)
47
+ return [...DEFAULT_OPERATIONS];
48
+ }
49
+ const declared = requirements.capabilities;
50
+ const selected = [...(declared?.required ?? []), ...(options.capabilities ?? declared?.optional ?? [])];
51
+ const operations = selected.flatMap((id) => capabilityOperationsForContractVersion(semanticContractVersion(requirements), id) ?? []);
52
+ const hasSetup = (application.provisions?.type_packs.length ?? 0) > 0
53
+ || (application.provisions?.configuration?.length ?? 0) > 0;
54
+ return [...new Set([
55
+ ...operations,
56
+ ...(semanticContractVersion(requirements) === 2 && hasSetup ? APPLICATION_SETUP_OPERATIONS : [])
57
+ ])];
58
+ }
59
+ export function retainedCapabilities(requirements, operations) {
60
+ return [...(requirements.capabilities?.required ?? []), ...(requirements.capabilities?.optional ?? [])].filter((id) => (capabilityOperationsForContractVersion(semanticContractVersion(requirements), id) ?? []).every((operation) => operations.includes(operation)));
61
+ }
62
+ export function authorizationFiles(requirements) {
63
+ const files = requirements.files;
64
+ if (!files)
65
+ return undefined;
66
+ if (semanticContractVersion(requirements) === 1) {
67
+ if (!("actions" in files) || "required" in files || "optional" in files) {
68
+ invalidAuthorizationSelection("Legacy file declarations must use exact files.actions.");
69
+ }
70
+ return { actions: [...files.actions], scope: structuredClone(files.scope) };
71
+ }
72
+ if ("actions" in files)
73
+ invalidAuthorizationSelection("V2 file declarations must use required/optional file actions.");
74
+ return applicationFileRequest(files);
75
+ }
@@ -0,0 +1,34 @@
1
+ import { authorizationSigningMessage, type ApplicationAuthorizationBinding, type ApplicationAuthorizationProof } from "@mdbase-dev/connect-protocol";
2
+ import type { Application } from "./internal-types.js";
3
+ export interface ApplicationIdentity {
4
+ handle: string;
5
+ signingPrivateKey: CryptoKey;
6
+ signingPublicKey: string;
7
+ }
8
+ export interface ApplicationIdentityStore {
9
+ create(handle: string): Promise<ApplicationIdentity>;
10
+ get(handle: string): Promise<ApplicationIdentity | null>;
11
+ delete(handle: string): Promise<void>;
12
+ }
13
+ /** Origin-scoped persistence for one non-extractable signing key per app/server installation. */
14
+ export declare class IndexedDbApplicationIdentityStore implements ApplicationIdentityStore {
15
+ private database;
16
+ create(handle: string): Promise<ApplicationIdentity>;
17
+ get(handle: string): Promise<ApplicationIdentity | null>;
18
+ delete(handle: string): Promise<void>;
19
+ private open;
20
+ }
21
+ /** Process-local identity storage for portable applications, tests, and custom hosts. */
22
+ export declare class MemoryApplicationIdentityStore implements ApplicationIdentityStore {
23
+ private readonly records;
24
+ create(handle: string): Promise<ApplicationIdentity>;
25
+ get(handle: string): Promise<ApplicationIdentity | null>;
26
+ delete(handle: string): Promise<void>;
27
+ }
28
+ export declare class ApplicationIdentityStoreError extends Error {
29
+ constructor(message: string);
30
+ }
31
+ export { authorizationSigningMessage };
32
+ export declare function applicationInstallationId(identity: Pick<ApplicationIdentity, "signingPublicKey">): Promise<string>;
33
+ export declare function signApplicationAuthorization(binding: ApplicationAuthorizationBinding, identity: Pick<ApplicationIdentity, "signingPrivateKey" | "signingPublicKey">): Promise<ApplicationAuthorizationProof>;
34
+ export declare function applicationIdentity(store: ApplicationIdentityStore, serverUrl: string, application: Application): Promise<ApplicationIdentity>;
@@ -0,0 +1,148 @@
1
+ import { applicationInstallationIdFromPublicKey, authorizationSigningMessage } from "@mdbase-dev/connect-protocol";
2
+ const DATABASE_NAME = "mdbase-connect-identities";
3
+ const STORE_NAME = "application-identities";
4
+ const P256_ORDER = BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551");
5
+ const P256_HALF_ORDER = P256_ORDER / 2n;
6
+ /** Origin-scoped persistence for one non-extractable signing key per app/server installation. */
7
+ export class IndexedDbApplicationIdentityStore {
8
+ database = null;
9
+ async create(handle) {
10
+ const record = await generateApplicationIdentity(handle);
11
+ const database = await this.open();
12
+ await idbWrite(database, (store) => store.add(record));
13
+ return record;
14
+ }
15
+ async get(handle) {
16
+ const database = await this.open();
17
+ return await idbRequest(database.transaction(STORE_NAME).objectStore(STORE_NAME).get(handle)) ?? null;
18
+ }
19
+ async delete(handle) {
20
+ const database = await this.open();
21
+ await idbWrite(database, (store) => store.delete(handle));
22
+ }
23
+ open() {
24
+ if (typeof indexedDB === "undefined") {
25
+ throw new ApplicationIdentityStoreError("Persistent application identity requires browser IndexedDB or an injected identity store.");
26
+ }
27
+ if (!this.database) {
28
+ this.database = new Promise((resolve, reject) => {
29
+ const request = indexedDB.open(DATABASE_NAME, 1);
30
+ request.onupgradeneeded = () => {
31
+ if (!request.result.objectStoreNames.contains(STORE_NAME)) {
32
+ request.result.createObjectStore(STORE_NAME, { keyPath: "handle" });
33
+ }
34
+ };
35
+ request.onerror = () => reject(request.error);
36
+ request.onsuccess = () => resolve(request.result);
37
+ });
38
+ }
39
+ return this.database;
40
+ }
41
+ }
42
+ /** Process-local identity storage for portable applications, tests, and custom hosts. */
43
+ export class MemoryApplicationIdentityStore {
44
+ records = new Map();
45
+ async create(handle) {
46
+ if (this.records.has(handle))
47
+ throw new Error(`Application identity already exists: ${handle}`);
48
+ const record = await generateApplicationIdentity(handle);
49
+ this.records.set(handle, record);
50
+ return record;
51
+ }
52
+ async get(handle) {
53
+ return this.records.get(handle) ?? null;
54
+ }
55
+ async delete(handle) {
56
+ this.records.delete(handle);
57
+ }
58
+ }
59
+ export class ApplicationIdentityStoreError extends Error {
60
+ constructor(message) {
61
+ super(message);
62
+ this.name = "ApplicationIdentityStoreError";
63
+ }
64
+ }
65
+ export { authorizationSigningMessage };
66
+ export async function applicationInstallationId(identity) {
67
+ return applicationInstallationIdFromPublicKey(identity.signingPublicKey);
68
+ }
69
+ export async function signApplicationAuthorization(binding, identity) {
70
+ if (binding.installation_signing_public_key !== identity.signingPublicKey
71
+ || binding.application_installation_id !== await applicationInstallationId(identity)) {
72
+ throw new Error("Application authorization identity does not match its binding.");
73
+ }
74
+ const signature = canonicalSignature(new Uint8Array(await crypto.subtle.sign({ name: "ECDSA", hash: "SHA-256" }, identity.signingPrivateKey, authorizationSigningMessage(binding))));
75
+ return { binding, signature: base64Url(signature) };
76
+ }
77
+ export async function applicationIdentity(store, serverUrl, application) {
78
+ const handle = `application-installation:v2:${serverUrl}:${application.id}`;
79
+ const existing = await store.get(handle);
80
+ if (existing)
81
+ return existing;
82
+ try {
83
+ return await store.create(handle);
84
+ }
85
+ catch (error) {
86
+ const raced = await store.get(handle);
87
+ if (raced)
88
+ return raced;
89
+ throw error;
90
+ }
91
+ }
92
+ async function generateApplicationIdentity(handle) {
93
+ const signing = await crypto.subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, ["sign", "verify"]);
94
+ const signingPublicKey = base64Url(new Uint8Array(await crypto.subtle.exportKey("raw", signing.publicKey)));
95
+ const signingPkcs8 = await crypto.subtle.exportKey("pkcs8", signing.privateKey);
96
+ const signingPrivateKey = await crypto.subtle.importKey("pkcs8", signingPkcs8, { name: "ECDSA", namedCurve: "P-256" }, false, ["sign"]);
97
+ return { handle, signingPrivateKey, signingPublicKey };
98
+ }
99
+ function idbRequest(request) {
100
+ return new Promise((resolve, reject) => {
101
+ request.onerror = () => reject(request.error);
102
+ request.onsuccess = () => resolve(request.result);
103
+ });
104
+ }
105
+ function idbWrite(database, write) {
106
+ return new Promise((resolve, reject) => {
107
+ const transaction = database.transaction(STORE_NAME, "readwrite");
108
+ write(transaction.objectStore(STORE_NAME)).onerror = () => reject(transaction.error);
109
+ transaction.onerror = () => reject(transaction.error);
110
+ transaction.onabort = () => reject(transaction.error ?? new Error("Identity transaction aborted."));
111
+ transaction.oncomplete = () => resolve();
112
+ });
113
+ }
114
+ function concat(values) {
115
+ const output = new Uint8Array(values.reduce((length, value) => length + value.byteLength, 0));
116
+ let offset = 0;
117
+ for (const value of values) {
118
+ output.set(value, offset);
119
+ offset += value.byteLength;
120
+ }
121
+ return output;
122
+ }
123
+ function base64Url(value) {
124
+ return btoa(String.fromCharCode(...value))
125
+ .replaceAll("+", "-")
126
+ .replaceAll("/", "_")
127
+ .replace(/=+$/u, "");
128
+ }
129
+ function canonicalSignature(signature) {
130
+ if (signature.byteLength !== 64)
131
+ throw new Error("Application authorization signature is invalid.");
132
+ const s = bytesBigInt(signature.slice(32));
133
+ if (s === 0n || s >= P256_ORDER)
134
+ throw new Error("Application authorization signature is invalid.");
135
+ if (s <= P256_HALF_ORDER)
136
+ return signature;
137
+ return concat([signature.slice(0, 32), bigIntBytes(P256_ORDER - s, 32)]);
138
+ }
139
+ function bytesBigInt(value) {
140
+ return BigInt(`0x${hex(value)}`);
141
+ }
142
+ function bigIntBytes(value, length) {
143
+ const encoded = value.toString(16).padStart(length * 2, "0");
144
+ return Uint8Array.from({ length }, (_, index) => Number.parseInt(encoded.slice(index * 2, index * 2 + 2), 16));
145
+ }
146
+ function hex(value) {
147
+ return [...value].map((byte) => byte.toString(16).padStart(2, "0")).join("");
148
+ }
@@ -0,0 +1,167 @@
1
+ import { type ConnectProblem, type JsonObject, type CollectionOperation } from "@mdbase-dev/connect-protocol";
2
+ import { type MdbaseApplicationManifest as MdbaseAppManifest, type MdbaseApplicationCapabilityId as ApplicationCapabilityId } from "./application-contract.js";
3
+ import { type ApplicationSessionContext } from "./structured-readiness.js";
4
+ import type { MdbaseAuthorizationOutcome, MdbaseAuthorizeOptions, MdbaseConnection } from "./connection.js";
5
+ import type { MdbaseConnectionInfo } from "./connection-types.js";
6
+ import { type ConnectOutcome, type CollectionTypeProblemCode, type RegistrationProblemCode, type SessionProblemCode } from "./outcomes.js";
7
+ import type { MdbaseApplicationSelection, MdbaseSelectionHistory } from "./selection.js";
8
+ import type { CollectionSetupAssessment, ConfigurationSetupAssessment, ConnectRequestOptions, TypePackAssessment } from "./operation-types.js";
9
+ import { type ResolvedConnectTimeouts } from "./request-budget.js";
10
+ import type { Application } from "./internal-types.js";
11
+ import { type MdbaseSessionConnect, type MdbaseUnavailableReason } from "./session.js";
12
+ export interface MdbaseApplicationSessionConnect<Frontmatter extends JsonObject = JsonObject> extends MdbaseSessionConnect<Frontmatter> {
13
+ register(options?: ConnectRequestOptions): Promise<ConnectOutcome<Application, RegistrationProblemCode>>;
14
+ manifest(options?: ConnectRequestOptions): Promise<ConnectOutcome<MdbaseAppManifest, RegistrationProblemCode>>;
15
+ connectionApplicationId(collectionId: string): string | null;
16
+ }
17
+ export interface MdbaseApplicationSessionOptions {
18
+ selection: MdbaseApplicationSelection;
19
+ autoSelect?: "only" | "never";
20
+ verificationStore?: MdbaseApplicationVerificationStore;
21
+ }
22
+ export interface MdbaseApplicationVerificationStore {
23
+ read(key: string): string | null;
24
+ write(key: string, value: string): void;
25
+ remove(key: string): void;
26
+ }
27
+ export declare class MdbaseMemoryVerificationStore implements MdbaseApplicationVerificationStore {
28
+ private readonly values;
29
+ read(key: string): string | null;
30
+ write(key: string, value: string): void;
31
+ remove(key: string): void;
32
+ }
33
+ export interface MdbaseDefinitionUpdate {
34
+ id: string;
35
+ name: string;
36
+ status: TypePackAssessment["status"];
37
+ applicable: boolean;
38
+ assessmentDigest: string;
39
+ currentVersion?: string;
40
+ desiredVersion: string;
41
+ resources: TypePackAssessment["resources"];
42
+ contractSetups: TypePackAssessment["contractSetups"];
43
+ canApply: boolean;
44
+ reason: string;
45
+ }
46
+ export interface MdbaseCollectionSetupUpdate {
47
+ status: CollectionSetupAssessment["status"];
48
+ applicable: boolean;
49
+ assessmentDigest: string;
50
+ collectionRevision: string;
51
+ provisionDigest: string;
52
+ configuration: ConfigurationSetupAssessment[];
53
+ typePacks: MdbaseDefinitionUpdate[];
54
+ canApply: boolean;
55
+ reason: string;
56
+ }
57
+ export type MdbaseApplicationSessionSnapshot = {
58
+ status: "not_started";
59
+ connections: MdbaseConnectionInfo[];
60
+ } | {
61
+ status: "starting";
62
+ connections: MdbaseConnectionInfo[];
63
+ } | {
64
+ status: "start_failed";
65
+ problem: ConnectProblem<SessionProblemCode>;
66
+ connections: MdbaseConnectionInfo[];
67
+ } | {
68
+ status: "destroyed";
69
+ connections: MdbaseConnectionInfo[];
70
+ } | {
71
+ status: "unselected";
72
+ connections: MdbaseConnectionInfo[];
73
+ } | ({
74
+ status: "authorization_required";
75
+ } & ApplicationSessionContext) | ({
76
+ status: "checking_setup";
77
+ } & ApplicationSessionContext) | ({
78
+ status: "setup_review_required";
79
+ update: MdbaseCollectionSetupUpdate;
80
+ } & ApplicationSessionContext) | ({
81
+ status: "ready";
82
+ verification: "cached" | "verified";
83
+ } & ApplicationSessionContext) | {
84
+ status: "unavailable";
85
+ collectionId: string;
86
+ reason: MdbaseUnavailableReason;
87
+ connections: MdbaseConnectionInfo[];
88
+ } | ({
89
+ status: "blocked";
90
+ problem: {
91
+ code: string;
92
+ message: string;
93
+ recovery?: string;
94
+ };
95
+ } & ApplicationSessionContext);
96
+ /**
97
+ * The application-level lifecycle boundary. It derives authorization from the
98
+ * bundled manifest, exposes semantic capabilities, and never mutates collection
99
+ * setup without an explicit `applyCollectionSetup` call.
100
+ */
101
+ export declare class MdbaseApplicationSession<Frontmatter extends JsonObject = JsonObject> {
102
+ private readonly connect;
103
+ private readonly options;
104
+ private readonly timeouts;
105
+ private readonly listeners;
106
+ private readonly verificationStore;
107
+ private snapshot;
108
+ private manifest;
109
+ private application;
110
+ private base;
111
+ private stopBase?;
112
+ private setupAssessment;
113
+ private setupTypePackAdoptions;
114
+ private verificationGeneration;
115
+ private readinessController?;
116
+ private lifecycleGeneration;
117
+ private readonly operationControllers;
118
+ private startOperation;
119
+ constructor(connect: MdbaseApplicationSessionConnect<Frontmatter>, options: MdbaseApplicationSessionOptions, timeouts?: ResolvedConnectTimeouts);
120
+ start(options?: ConnectRequestOptions): Promise<ConnectOutcome<MdbaseApplicationSessionSnapshot, SessionProblemCode>>;
121
+ private waitForStart;
122
+ private abandonStart;
123
+ private beginStart;
124
+ private startWithinBudget;
125
+ private performStartWithinBudget;
126
+ private startFailure;
127
+ destroy(): void;
128
+ private cleanupBase;
129
+ getSnapshot(): MdbaseApplicationSessionSnapshot;
130
+ subscribe(listener: () => void): () => void;
131
+ connection(): MdbaseConnection<Frontmatter> | null;
132
+ select(collectionId: string, options?: {
133
+ history?: MdbaseSelectionHistory;
134
+ }): ConnectOutcome<MdbaseConnection<Frontmatter>, SessionProblemCode>;
135
+ clearSelection(options?: {
136
+ history?: MdbaseSelectionHistory;
137
+ }): ConnectOutcome<void, SessionProblemCode>;
138
+ forget(collectionId: string): ConnectOutcome<void, SessionProblemCode>;
139
+ authorize(target: "choose" | "selected" | {
140
+ collectionId: string;
141
+ }, options?: Omit<MdbaseAuthorizeOptions, "returnTo" | "target">): Promise<ConnectOutcome<MdbaseAuthorizationOutcome<Frontmatter>, SessionProblemCode>>;
142
+ handleAuthorizationCallback(callbackUrl: string | URL, options?: ConnectRequestOptions): Promise<ConnectOutcome<MdbaseConnection<Frontmatter>, SessionProblemCode>>;
143
+ completeAuthorization(callbackUrl?: string | URL, options?: ConnectRequestOptions): Promise<ConnectOutcome<MdbaseConnection<Frontmatter>, SessionProblemCode>>;
144
+ ensureCapabilities(capabilities: ApplicationCapabilityId[], options?: ConnectRequestOptions): Promise<ConnectOutcome<MdbaseAuthorizationOutcome<Frontmatter> | {
145
+ kind: "unchanged";
146
+ connection: MdbaseConnection<Frontmatter>;
147
+ }, SessionProblemCode>>;
148
+ ensureOperations(operations: CollectionOperation[], options?: ConnectRequestOptions): Promise<ConnectOutcome<{
149
+ kind: "unchanged";
150
+ connection: MdbaseConnection<Frontmatter>;
151
+ } | MdbaseAuthorizationOutcome<Frontmatter>, SessionProblemCode>>;
152
+ applyCollectionSetup(options?: ConnectRequestOptions): Promise<ConnectOutcome<MdbaseApplicationSessionSnapshot, CollectionTypeProblemCode | SessionProblemCode>>;
153
+ private applyCollectionSetupStarted;
154
+ private refresh;
155
+ private verifySetup;
156
+ private publishReady;
157
+ private collectionSetupInput;
158
+ private context;
159
+ private publish;
160
+ private lifecycleBase;
161
+ private withLifecycleBase;
162
+ private beginLifecycleOperation;
163
+ private lifecycleCurrent;
164
+ private destroyedOutcome;
165
+ private requireManifest;
166
+ private requireApplication;
167
+ }