@cyaxis/ulvia 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +410 -142
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -25240,32 +25240,48 @@ var init_assetFiles = () => {};
25240
25240
  // packages/features/cms-repository/src/repository/filesystem/core/immutableJsonCache.ts
25241
25241
  class ImmutableJsonCache {
25242
25242
  maximumEntries;
25243
+ maximumBytes;
25243
25244
  entries = new Map;
25244
- constructor(maximumEntries = 256) {
25245
+ bytes = 0;
25246
+ constructor(maximumEntries = 256, maximumBytes = 64 * 1024 * 1024) {
25245
25247
  this.maximumEntries = maximumEntries;
25248
+ this.maximumBytes = maximumBytes;
25246
25249
  }
25247
25250
  get(key, canonicalJson) {
25251
+ return this.project(key, canonicalJson, (value) => value);
25252
+ }
25253
+ project(key, canonicalJson, project) {
25248
25254
  const entry = this.entries.get(key);
25249
25255
  if (!entry || entry.canonicalJson !== canonicalJson) {
25250
- this.entries.delete(key);
25256
+ this.delete(key);
25251
25257
  return null;
25252
25258
  }
25253
25259
  this.entries.delete(key);
25254
25260
  this.entries.set(key, entry);
25255
- return structuredClone(entry.value);
25261
+ return structuredClone(project(entry.value));
25256
25262
  }
25257
25263
  set(key, canonicalJson, value) {
25258
- this.entries.delete(key);
25259
- this.entries.set(key, { canonicalJson, value });
25260
- while (this.entries.size > this.maximumEntries) {
25261
- this.entries.delete(this.entries.keys().next().value);
25264
+ this.delete(key);
25265
+ const bytes = canonicalJson.length * 2 + JSON.stringify(value).length * 2;
25266
+ if (bytes <= this.maximumBytes) {
25267
+ const frozen = structuredClone(value);
25268
+ deepFreeze(frozen);
25269
+ this.entries.set(key, { canonicalJson, value: frozen, bytes });
25270
+ this.bytes += bytes;
25271
+ while (this.entries.size > this.maximumEntries || this.bytes > this.maximumBytes) {
25272
+ this.delete(this.entries.keys().next().value);
25273
+ }
25262
25274
  }
25263
25275
  return structuredClone(value);
25264
25276
  }
25265
25277
  delete(key) {
25278
+ this.bytes -= this.entries.get(key)?.bytes ?? 0;
25266
25279
  this.entries.delete(key);
25267
25280
  }
25268
25281
  }
25282
+ var init_immutableJsonCache = __esm(() => {
25283
+ init_protocol();
25284
+ });
25269
25285
 
25270
25286
  // packages/features/cms-repository/src/repository/filesystem/artifacts/collections.ts
25271
25287
  import { createHash as createHash3, randomUUID as randomUUID3 } from "crypto";
@@ -25359,21 +25375,11 @@ class LocalCollectionRepository {
25359
25375
  return verifyStoredCollectionArtifact(metadata.release, assets, metadata.digest);
25360
25376
  }
25361
25377
  async getMetadata(publisherId, collectionId, version) {
25362
- if (!isRepositoryIdentifier(publisherId) || !isCollectionNamespace(collectionId) || !VERSION2.test(version)) {
25363
- return null;
25364
- }
25365
- const path = this.releasePath(publisherId, collectionId, version);
25366
- const bytes = await readFile5(path).catch((error) => {
25367
- if (error.code === "ENOENT") {
25368
- this.metadataCache.delete(path);
25369
- return null;
25370
- }
25371
- throw error;
25372
- });
25373
- if (!bytes) {
25378
+ const document2 = await this.readDocument(publisherId, collectionId, version);
25379
+ if (!document2) {
25374
25380
  return null;
25375
25381
  }
25376
- const canonicalJson = bytes.toString("utf8");
25382
+ const { path, bytes, canonicalJson } = document2;
25377
25383
  const cached = this.metadataCache.get(path, canonicalJson);
25378
25384
  if (cached) {
25379
25385
  return cached;
@@ -25386,12 +25392,27 @@ class LocalCollectionRepository {
25386
25392
  return this.metadataCache.set(path, canonicalJson, artifact);
25387
25393
  }
25388
25394
  async getAsset(publisherId, collectionId, version, assetId, metadataOnly = false) {
25389
- const metadata = await this.getMetadata(publisherId, collectionId, version);
25390
- const definition = metadata?.release.assets.find((asset) => asset.id === assetId);
25391
- if (!metadata || !definition) {
25395
+ const document2 = await this.readDocument(publisherId, collectionId, version);
25396
+ if (!document2) {
25392
25397
  return null;
25393
25398
  }
25394
- const bytes = Bun.file(join5(this.assetDirectory(metadata.canonicalJson), assetFileName(assetId)));
25399
+ const project = (metadata) => ({
25400
+ definition: metadata.release.assets.find((asset) => asset.id === assetId),
25401
+ digest: metadata.digest
25402
+ });
25403
+ let selected = this.metadataCache.project(document2.path, document2.canonicalJson, project);
25404
+ if (!selected) {
25405
+ const metadata = await this.getMetadata(publisherId, collectionId, version);
25406
+ if (!metadata) {
25407
+ return null;
25408
+ }
25409
+ selected = project(metadata);
25410
+ }
25411
+ const definition = selected.definition;
25412
+ if (!definition) {
25413
+ return null;
25414
+ }
25415
+ const bytes = Bun.file(join5(this.root, "assets", "collections", selected.digest.slice("sha256:".length), assetFileName(assetId)));
25395
25416
  if (metadataOnly) {
25396
25417
  return await bytes.exists() && bytes.size === definition.byteLength ? { definition, bytes } : null;
25397
25418
  }
@@ -25405,6 +25426,20 @@ class LocalCollectionRepository {
25405
25426
  async prune() {
25406
25427
  await pruneRepository(this.root);
25407
25428
  }
25429
+ async readDocument(publisherId, collectionId, version) {
25430
+ if (!isRepositoryIdentifier(publisherId) || !isCollectionNamespace(collectionId) || !VERSION2.test(version)) {
25431
+ return null;
25432
+ }
25433
+ const path = this.releasePath(publisherId, collectionId, version);
25434
+ const bytes = await readFile5(path).catch((error) => {
25435
+ if (error.code === "ENOENT") {
25436
+ this.metadataCache.delete(path);
25437
+ return null;
25438
+ }
25439
+ throw error;
25440
+ });
25441
+ return bytes ? { path, bytes, canonicalJson: new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes) } : null;
25442
+ }
25408
25443
  releasePath(publisherId, collectionId, version) {
25409
25444
  return join5(this.root, "releases", publisherId, collectionId, `${version}.json`);
25410
25445
  }
@@ -25435,6 +25470,7 @@ var init_collections2 = __esm(() => {
25435
25470
  init_immutableFiles();
25436
25471
  init_recovery();
25437
25472
  init_assetFiles();
25473
+ init_immutableJsonCache();
25438
25474
  VERSION2 = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u;
25439
25475
  });
25440
25476
 
@@ -25737,7 +25773,6 @@ var init_planPublications = __esm(() => {
25737
25773
  var init_publishContractSet = __esm(() => {
25738
25774
  init_planPublications();
25739
25775
  });
25740
-
25741
25776
  // packages/features/cms-repository/src/exports/contracts/catalogue.ts
25742
25777
  var init_catalogue2 = __esm(() => {
25743
25778
  init_InMemoryReleaseCatalogue();
@@ -27151,19 +27186,27 @@ var init_cacheGeneration = __esm(() => {
27151
27186
  // packages/foundation/http-runner/src/core/compression/content.ts
27152
27187
  var {CryptoHasher, gzipSync } = globalThis.Bun;
27153
27188
  import { brotliCompressSync } from "zlib";
27154
- function compress(raw, contentType) {
27189
+ function compress(raw, contentType, codecs = CODECS) {
27155
27190
  const rawBytes = typeof raw === "string" ? new TextEncoder().encode(raw) : new Uint8Array(raw);
27156
- const brotliResult = brotliCompressSync(rawBytes);
27191
+ let brotli;
27192
+ let gzip;
27157
27193
  const hash = new CryptoHasher("sha256").update(rawBytes).digest("hex").slice(0, 10);
27158
27194
  return {
27159
27195
  raw: rawBytes,
27160
- brotli: new Uint8Array(brotliResult.buffer, brotliResult.byteOffset, brotliResult.byteLength),
27161
- gzip: new Uint8Array(gzipSync(rawBytes)),
27196
+ get brotli() {
27197
+ return brotli ??= new Uint8Array(codecs.brotli(rawBytes));
27198
+ },
27199
+ get gzip() {
27200
+ return gzip ??= new Uint8Array(codecs.gzip(rawBytes));
27201
+ },
27162
27202
  contentType,
27163
27203
  hash
27164
27204
  };
27165
27205
  }
27166
- var init_content = () => {};
27206
+ var CODECS;
27207
+ var init_content = __esm(() => {
27208
+ CODECS = { brotli: brotliCompressSync, gzip: (bytes) => gzipSync(new Uint8Array(bytes)) };
27209
+ });
27167
27210
 
27168
27211
  // packages/foundation/http-runner/src/core/buildCspContent.ts
27169
27212
  var init_buildCspContent = () => {};
@@ -27178,15 +27221,6 @@ var init_response2 = __esm(() => {
27178
27221
  init_cacheGeneration();
27179
27222
  init_headers();
27180
27223
  });
27181
-
27182
- // packages/foundation/http-runner/src/core/compression.ts
27183
- var init_compression = __esm(() => {
27184
- init_cacheGeneration();
27185
- init_content();
27186
- init_headers();
27187
- init_response2();
27188
- });
27189
-
27190
27224
  // packages/foundation/http-runner/src/core/byteRanges.ts
27191
27225
  function parseContentRange(value) {
27192
27226
  const match = /^bytes (\d+)-(\d+)\/(\d+)$/u.exec(value ?? "");
@@ -27196,6 +27230,18 @@ function parseContentRange(value) {
27196
27230
  return match && [start, end, size].every(Number.isSafeInteger) && start >= 0 && end >= start && end < size ? { start, end, size } : null;
27197
27231
  }
27198
27232
 
27233
+ // packages/foundation/http-runner/src/core/compression/streaming.ts
27234
+ var init_streaming = () => {};
27235
+
27236
+ // packages/foundation/http-runner/src/core/compression.ts
27237
+ var init_compression = __esm(() => {
27238
+ init_cacheGeneration();
27239
+ init_content();
27240
+ init_headers();
27241
+ init_response2();
27242
+ init_streaming();
27243
+ });
27244
+
27199
27245
  // packages/foundation/http-runner/src/exports/index.ts
27200
27246
  var init_exports2 = __esm(() => {
27201
27247
  init_BunRunner();
@@ -28312,11 +28358,15 @@ var init_publishedPage = () => {};
28312
28358
 
28313
28359
  // packages/features/cms-content/src/pages/core/routing/values.ts
28314
28360
  var init_values4 = () => {};
28361
+ // packages/features/cms-content/src/application/core/pageRenderInputs.ts
28362
+ var init_pageRenderInputs = () => {};
28363
+
28315
28364
  // packages/features/cms-content/src/application/core/createContentReader.ts
28316
28365
  var init_createContentReader = __esm(() => {
28317
28366
  init_resolvePublishedRoute();
28318
28367
  init_publishedPage();
28319
28368
  init_values4();
28369
+ init_pageRenderInputs();
28320
28370
  });
28321
28371
  // packages/features/cms-content/src/blocs/core/markup/bindingRoot.ts
28322
28372
  function wrapBindingCore(content) {
@@ -28797,7 +28847,6 @@ var init_links = __esm(() => {
28797
28847
  init_errors7();
28798
28848
  init_esm7();
28799
28849
  });
28800
-
28801
28850
  // packages/features/cms-content/src/blocs/core/catalogue/siteBlocGroups.ts
28802
28851
  var init_siteBlocGroups = __esm(() => {
28803
28852
  init_errors5();
@@ -30318,8 +30367,8 @@ function localEdgeEnvironment(_instance, config, connection, services, image, pr
30318
30367
  }
30319
30368
 
30320
30369
  // packages/runtimes/ulvia-cli/src/runtime/stack/version.ts
30321
- var injectedCliVersion = "1.0.0";
30322
- var injectedStackVersion = "1.0.0";
30370
+ var injectedCliVersion = "1.0.2";
30371
+ var injectedStackVersion = "1.0.5";
30323
30372
  var CLI_VERSION = injectedCliVersion ?? "development";
30324
30373
  var DEFAULT_STACK_VERSION = injectedStackVersion ?? "unbundled";
30325
30374
  function defaultStackVersion() {
@@ -31040,6 +31089,193 @@ function toRecord(entry) {
31040
31089
  };
31041
31090
  }
31042
31091
 
31092
+ // packages/runtimes/ulvia-cli/src/runtime/stack/logs/OperatorObservabilityClient.ts
31093
+ init_compatibility();
31094
+
31095
+ // packages/features/cms-repository/src/providers/installations/core/errors.ts
31096
+ class ProviderInstallationValidationError extends TypeError {
31097
+ code;
31098
+ path;
31099
+ constructor(code, message, path = "$") {
31100
+ super(`${path}: ${message}`);
31101
+ this.name = "ProviderInstallationValidationError";
31102
+ this.code = code;
31103
+ this.path = path;
31104
+ }
31105
+ }
31106
+ // packages/features/cms-repository/src/providers/installations/core/limits.ts
31107
+ var DEFAULT_PROVIDER_INSTALLATION_LIMITS = Object.freeze({
31108
+ maxDocumentBytes: 512 * 1024,
31109
+ maxJsonDepth: 48,
31110
+ maxImplementations: 128
31111
+ });
31112
+ // packages/features/cms-repository/src/providers/installations/core/protocol.ts
31113
+ init_protocol();
31114
+ var PROVIDER_CONNECTION_PROTOCOL = deepFreeze({
31115
+ protocol: "ulvia-provider/v1",
31116
+ authentication: "bearer",
31117
+ report: { method: "GET", path: "/ulvia/report" },
31118
+ registration: { method: "PUT", path: "/ulvia/connections/{installationId}" },
31119
+ disconnect: { method: "DELETE", path: "/ulvia/connections/{installationId}" }
31120
+ });
31121
+ function assertProviderConnectionToken(token) {
31122
+ if (typeof token !== "string" || !/^[\x21-\x7e]{24,512}$/u.test(token)) {
31123
+ throw new TypeError("Invalid provider token");
31124
+ }
31125
+ }
31126
+ // packages/features/cms-repository/src/providers/installations/core/parsing/parseProviderConnectionTarget.ts
31127
+ init_values3();
31128
+
31129
+ // packages/features/cms-repository/src/providers/installations/core/parsing/documents.ts
31130
+ init_contracts();
31131
+ init_protocol();
31132
+ init_errors6();
31133
+ init_values3();
31134
+ function parseInstallationDocument(value, limits, parseRecord) {
31135
+ validateLimits(limits);
31136
+ try {
31137
+ if (canonicalIJsonBytes(value, limits.maxJsonDepth).byteLength > limits.maxDocumentBytes) {
31138
+ throw new ProviderInstallationValidationError("body_limit_exceeded", "document exceeds byte limit");
31139
+ }
31140
+ return deepFreeze(parseRecord(expectRecord2(structuredClone(value), "$")));
31141
+ } catch (error) {
31142
+ return translateError(error);
31143
+ }
31144
+ }
31145
+ function parseInstallationJson(input, limits, parseValue) {
31146
+ validateLimits(limits);
31147
+ try {
31148
+ return parseValue(parseStrictJson(input, limits.maxDocumentBytes, limits.maxJsonDepth));
31149
+ } catch (error) {
31150
+ return translateError(error);
31151
+ }
31152
+ }
31153
+ function validateLimits(limits) {
31154
+ for (const value of [limits.maxDocumentBytes, limits.maxJsonDepth, limits.maxImplementations]) {
31155
+ if (!Number.isSafeInteger(value) || value <= 0) {
31156
+ throw new TypeError("Provider installation limits must be positive safe integers");
31157
+ }
31158
+ }
31159
+ }
31160
+ function translateError(error) {
31161
+ if (!(error instanceof ReleaseValidationError) && !(error instanceof ProviderManifestValidationError)) {
31162
+ throw error;
31163
+ }
31164
+ const codes = new Set([
31165
+ "body_limit_exceeded",
31166
+ "duplicate_json_property",
31167
+ "invalid_json",
31168
+ "invalid_utf8",
31169
+ "json_depth_limit_exceeded"
31170
+ ]);
31171
+ const code = codes.has(error.code) ? error.code : "invalid_installation";
31172
+ const prefix = `${error.path}: `;
31173
+ const message = error.message.startsWith(prefix) ? error.message.slice(prefix.length) : error.message;
31174
+ throw new ProviderInstallationValidationError(code, message, error.path);
31175
+ }
31176
+
31177
+ // packages/features/cms-repository/src/providers/installations/core/parsing/fields.ts
31178
+ init_contracts();
31179
+ init_errors6();
31180
+ init_values3();
31181
+ init_parseEndpoint();
31182
+ function parseOpaqueId(value, path) {
31183
+ const id = expectString2(value, path, 128);
31184
+ if (!/^[A-Za-z0-9][A-Za-z0-9_.:-]*$/.test(id)) {
31185
+ throw new ProviderInstallationValidationError("invalid_installation", "must be an opaque identifier", path);
31186
+ }
31187
+ return id;
31188
+ }
31189
+ function parseDigest(value, path) {
31190
+ const digest = expectString2(value, path, 71);
31191
+ if (!isReleaseDigest(digest)) {
31192
+ throw new ProviderInstallationValidationError("invalid_installation", "must be a SHA-256 digest", path);
31193
+ }
31194
+ return digest;
31195
+ }
31196
+ // packages/features/cms-repository/src/providers/installations/core/parsing/parseProviderInstallation.ts
31197
+ init_identifiers2();
31198
+ init_versionRange2();
31199
+ init_values3();
31200
+ // packages/features/cms-repository/src/providers/installations/core/parsing/parseGatewayRegistration.ts
31201
+ init_values3();
31202
+ init_identifiers2();
31203
+ // packages/features/cms-repository/src/providers/installations/core/reports/parseProviderRuntimeReport.ts
31204
+ init_identifiers2();
31205
+ init_values3();
31206
+ init_versionRange2();
31207
+ function parseProviderRuntimeReport(value, limits = DEFAULT_PROVIDER_INSTALLATION_LIMITS) {
31208
+ return parseInstallationDocument(value, limits, (record) => {
31209
+ rejectUnknownKeys2(record, ["protocol", "providerId", "instanceId", "account", "buildVersion", "manifest", "implementations"], "$");
31210
+ if (record.protocol !== "ulvia-provider/v1") {
31211
+ throw new ProviderInstallationValidationError("invalid_installation", "must be ulvia-provider/v1", "$.protocol");
31212
+ }
31213
+ const account = expectRecord2(record.account, "$.account");
31214
+ rejectUnknownKeys2(account, ["id", "label"], "$.account");
31215
+ const manifest = expectRecord2(record.manifest, "$.manifest");
31216
+ rejectUnknownKeys2(manifest, ["version", "digest"], "$.manifest");
31217
+ const implementations = expectArray2(record.implementations, "$.implementations", limits.maxImplementations).map((implementation, index) => parseImplementation2(implementation, `$.implementations[${index}]`));
31218
+ unique2(implementations.map((entry) => `${entry.contractId}\x00${entry.version}`), "$.implementations");
31219
+ return {
31220
+ protocol: "ulvia-provider/v1",
31221
+ providerId: parseIdentifier2(record.providerId, "$.providerId", 96),
31222
+ instanceId: parseOpaqueId(record.instanceId, "$.instanceId"),
31223
+ account: {
31224
+ id: parseOpaqueId(account.id, "$.account.id"),
31225
+ label: expectString2(account.label, "$.account.label", 128)
31226
+ },
31227
+ buildVersion: parseSemVer2(record.buildVersion, "$.buildVersion"),
31228
+ manifest: {
31229
+ version: parseSemVer2(manifest.version, "$.manifest.version"),
31230
+ digest: parseDigest(manifest.digest, "$.manifest.digest")
31231
+ },
31232
+ implementations: implementations.sort((left, right) => compareOrdinal(left.contractId, right.contractId) || compareOrdinal(left.version, right.version))
31233
+ };
31234
+ });
31235
+ }
31236
+ function parseProviderRuntimeReportJson(input, limits = DEFAULT_PROVIDER_INSTALLATION_LIMITS) {
31237
+ return parseInstallationJson(input, limits, (value) => parseProviderRuntimeReport(value, limits));
31238
+ }
31239
+ function parseImplementation2(value, path) {
31240
+ const record = expectRecord2(value, path);
31241
+ rejectUnknownKeys2(record, ["contractId", "version", "digest", "status"], path);
31242
+ const status = record.status;
31243
+ if (status !== "ready" && status !== "setup-required" && status !== "unavailable") {
31244
+ throw new ProviderInstallationValidationError("invalid_installation", "must be ready, setup-required, or unavailable", `${path}.status`);
31245
+ }
31246
+ return {
31247
+ contractId: parseIdentifier2(record.contractId, `${path}.contractId`, 96),
31248
+ version: parseSemVer2(record.version, `${path}.version`),
31249
+ digest: parseDigest(record.digest, `${path}.digest`),
31250
+ status
31251
+ };
31252
+ }
31253
+ // packages/features/cms-repository/src/providers/installations/core/reports/validateProviderRuntimeReport.ts
31254
+ init_versionRange2();
31255
+ // packages/features/cms-repository/src/providers/installations/core/validateProviderInstallation.ts
31256
+ init_schema();
31257
+ // packages/features/cms-repository/src/providers/installations/core/lifecycle/ProviderInstallationLifecycle.ts
31258
+ init_protocol();
31259
+ init_values3();
31260
+
31261
+ // packages/features/cms-repository/src/providers/installations/core/lifecycle/candidates.ts
31262
+ init_protocol();
31263
+ init_values3();
31264
+
31265
+ // packages/features/cms-repository/src/providers/installations/core/lifecycle/preparations.ts
31266
+ init_verifyProviderManifestAdmission();
31267
+ init_limits3();
31268
+ init_values3();
31269
+
31270
+ // packages/features/cms-repository/src/providers/installations/core/lifecycle/state.ts
31271
+ init_identifiers2();
31272
+ // packages/features/cms-repository/src/providers/installations/default-implementation/memory/InMemoryProviderInstallationStore.ts
31273
+ init_protocol();
31274
+
31275
+ // packages/features/cms-repository/src/providers/installations/core/selectionRevision.ts
31276
+ init_protocol();
31277
+ // packages/features/cms-repository/src/providers/installations/core/lifecycle/readiness.ts
31278
+ init_protocol();
31043
31279
  // packages/features/cms-repository/src/exports/contracts/bindings.ts
31044
31280
  init_compileContractBindings();
31045
31281
  init_compile();
@@ -31247,9 +31483,11 @@ function parseResourceMetadata(value) {
31247
31483
  throw new TypeError("Invalid resource metadata");
31248
31484
  }
31249
31485
  const record = value;
31250
- if (Object.keys(record).sort().join() !== "headers,status" || !STATUSES.has(Number(record.status)) || typeof record.status !== "number" || !record.headers || typeof record.headers !== "object" || Array.isArray(record.headers)) {
31486
+ if (Object.keys(record).some((key) => !["headers", "status", "vary", "cacheTags"].includes(key)) || !STATUSES.has(Number(record.status)) || typeof record.status !== "number" || !record.headers || typeof record.headers !== "object" || Array.isArray(record.headers)) {
31251
31487
  throw new TypeError("Invalid resource metadata");
31252
31488
  }
31489
+ const vary = boundedList(record.vary, 3, (value) => ["accept", "accept-language", "accept-encoding"].includes(value));
31490
+ const cacheTags = boundedList(record.cacheTags, 32, (value) => /^[a-z0-9][a-z0-9:._-]{0,127}$/u.test(value));
31253
31491
  const headers = {};
31254
31492
  for (const [name, content] of Object.entries(record.headers)) {
31255
31493
  if (!HEADERS.has(name) || typeof content !== "string" || content.length > 2048 || /[\x00-\x1f\x7f]/u.test(content)) {
@@ -31276,7 +31514,12 @@ function parseResourceMetadata(value) {
31276
31514
  if (headers["content-length"] !== undefined && !/^(?:0|[1-9][0-9]{0,14})$/u.test(headers["content-length"])) {
31277
31515
  throw new TypeError("Invalid resource length");
31278
31516
  }
31279
- return Object.freeze({ status: record.status, headers: Object.freeze(headers) });
31517
+ return Object.freeze({
31518
+ status: record.status,
31519
+ headers: Object.freeze(headers),
31520
+ ...vary ? { vary: Object.freeze(vary) } : {},
31521
+ ...cacheTags ? { cacheTags: Object.freeze(cacheTags) } : {}
31522
+ });
31280
31523
  }
31281
31524
  function decodeResourceMetadata(header) {
31282
31525
  if (header === null) {
@@ -31287,6 +31530,15 @@ function decodeResourceMetadata(header) {
31287
31530
  }
31288
31531
  return parseResourceMetadata(JSON.parse(header));
31289
31532
  }
31533
+ function boundedList(value, maximum, valid) {
31534
+ if (value === undefined) {
31535
+ return;
31536
+ }
31537
+ if (!Array.isArray(value) || value.length > maximum || new Set(value).size !== value.length || value.some((item) => typeof item !== "string" || !valid(item))) {
31538
+ throw new TypeError("Invalid resource cache metadata");
31539
+ }
31540
+ return [...value];
31541
+ }
31290
31542
 
31291
31543
  // packages/features/cms-gateway/src/invocation/http/response/validate.ts
31292
31544
  init_schema();
@@ -31675,6 +31927,8 @@ class HttpGatewayTransport {
31675
31927
  const firstByteTimeout = setTimeout(() => abort.abort(new DOMException("Provider first byte timed out", "TimeoutError")), this.#timeoutMs);
31676
31928
  const exchange = {
31677
31929
  ...prepared,
31930
+ ...request.onDispatch ? { onDispatch: request.onDispatch } : {},
31931
+ ...request.authorityReads ? { authorityReads: request.authorityReads } : {},
31678
31932
  requestId: request.requestId,
31679
31933
  installationId: request.installationId,
31680
31934
  providerTokenRef: request.providerTokenRef,
@@ -31939,78 +32193,6 @@ import { isIP as isIP2 } from "net";
31939
32193
  init_compatibility();
31940
32194
  init_protocol();
31941
32195
  import { createHash as createHash9, createHmac, timingSafeEqual } from "crypto";
31942
- // packages/features/cms-repository/src/providers/installations/core/limits.ts
31943
- var DEFAULT_PROVIDER_INSTALLATION_LIMITS = Object.freeze({
31944
- maxDocumentBytes: 512 * 1024,
31945
- maxJsonDepth: 48,
31946
- maxImplementations: 128
31947
- });
31948
- // packages/features/cms-repository/src/providers/installations/core/protocol.ts
31949
- init_protocol();
31950
- var PROVIDER_CONNECTION_PROTOCOL = deepFreeze({
31951
- protocol: "ulvia-provider/v1",
31952
- authentication: "bearer",
31953
- report: { method: "GET", path: "/ulvia/report" },
31954
- registration: { method: "PUT", path: "/ulvia/connections/{installationId}" },
31955
- disconnect: { method: "DELETE", path: "/ulvia/connections/{installationId}" }
31956
- });
31957
- function assertProviderConnectionToken(token) {
31958
- if (typeof token !== "string" || !/^[\x21-\x7e]{24,512}$/u.test(token)) {
31959
- throw new TypeError("Invalid provider token");
31960
- }
31961
- }
31962
- // packages/features/cms-repository/src/providers/installations/core/parsing/parseProviderConnectionTarget.ts
31963
- init_values3();
31964
-
31965
- // packages/features/cms-repository/src/providers/installations/core/parsing/documents.ts
31966
- init_contracts();
31967
- init_protocol();
31968
- init_errors6();
31969
- init_values3();
31970
-
31971
- // packages/features/cms-repository/src/providers/installations/core/parsing/fields.ts
31972
- init_contracts();
31973
- init_errors6();
31974
- init_values3();
31975
- init_parseEndpoint();
31976
- // packages/features/cms-repository/src/providers/installations/core/parsing/parseProviderInstallation.ts
31977
- init_identifiers2();
31978
- init_versionRange2();
31979
- init_values3();
31980
- // packages/features/cms-repository/src/providers/installations/core/parsing/parseGatewayRegistration.ts
31981
- init_values3();
31982
- init_identifiers2();
31983
- // packages/features/cms-repository/src/providers/installations/core/reports/parseProviderRuntimeReport.ts
31984
- init_identifiers2();
31985
- init_values3();
31986
- init_versionRange2();
31987
- // packages/features/cms-repository/src/providers/installations/core/reports/validateProviderRuntimeReport.ts
31988
- init_versionRange2();
31989
- // packages/features/cms-repository/src/providers/installations/core/validateProviderInstallation.ts
31990
- init_schema();
31991
- // packages/features/cms-repository/src/providers/installations/core/lifecycle/ProviderInstallationLifecycle.ts
31992
- init_protocol();
31993
- init_values3();
31994
-
31995
- // packages/features/cms-repository/src/providers/installations/core/lifecycle/candidates.ts
31996
- init_protocol();
31997
- init_values3();
31998
-
31999
- // packages/features/cms-repository/src/providers/installations/core/lifecycle/preparations.ts
32000
- init_verifyProviderManifestAdmission();
32001
- init_limits3();
32002
- init_values3();
32003
-
32004
- // packages/features/cms-repository/src/providers/installations/core/lifecycle/state.ts
32005
- init_identifiers2();
32006
- // packages/features/cms-repository/src/providers/installations/default-implementation/memory/InMemoryProviderInstallationStore.ts
32007
- init_protocol();
32008
-
32009
- // packages/features/cms-repository/src/providers/installations/core/selectionRevision.ts
32010
- init_protocol();
32011
- // packages/features/cms-repository/src/providers/installations/core/lifecycle/readiness.ts
32012
- init_protocol();
32013
- // packages/features/cms-gateway/src/protocol/ProviderInvocationToken.ts
32014
32196
  var TOKEN_VERSION = 1;
32015
32197
  var MAX_TTL_SECONDS = 30;
32016
32198
  var IDENTIFIER = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
@@ -32134,6 +32316,57 @@ function isPublicAddress(candidate) {
32134
32316
  return true;
32135
32317
  }
32136
32318
 
32319
+ // packages/features/cms-gateway/src/invocation/node-http/pinnedAgents.ts
32320
+ import { Agent as HttpAgent } from "http";
32321
+ import { Agent as HttpsAgent } from "https";
32322
+ var options = { keepAlive: true, maxSockets: 16, maxTotalSockets: 64, maxFreeSockets: 4 };
32323
+ function authority(request) {
32324
+ const headers = request.headers;
32325
+ const host = headers && !Array.isArray(headers) && "host" in headers ? headers.host : undefined;
32326
+ if (typeof host !== "string" || !host) {
32327
+ throw new TypeError("Pinned connection requires an explicit Host authority");
32328
+ }
32329
+ return host;
32330
+ }
32331
+
32332
+ class PinnedHttpAgent extends HttpAgent {
32333
+ keepSocketAlive(socket) {
32334
+ const keep = super.keepSocketAlive(socket);
32335
+ if (keep === false) {
32336
+ return false;
32337
+ }
32338
+ socket.setTimeout(1e4);
32339
+ return true;
32340
+ }
32341
+ reuseSocket(socket, request) {
32342
+ socket.setTimeout(0);
32343
+ super.reuseSocket(socket, request);
32344
+ }
32345
+ getName(request) {
32346
+ return `${super.getName(request)}\x00${authority(request)}`;
32347
+ }
32348
+ }
32349
+
32350
+ class PinnedHttpsAgent extends HttpsAgent {
32351
+ keepSocketAlive(socket) {
32352
+ const keep = super.keepSocketAlive(socket);
32353
+ if (keep === false) {
32354
+ return false;
32355
+ }
32356
+ socket.setTimeout(1e4);
32357
+ return true;
32358
+ }
32359
+ reuseSocket(socket, request) {
32360
+ socket.setTimeout(0);
32361
+ super.reuseSocket(socket, request);
32362
+ }
32363
+ getName(request) {
32364
+ return `${super.getName(request)}\x00${authority(request)}`;
32365
+ }
32366
+ }
32367
+ var pinnedHttpAgent = new PinnedHttpAgent(options);
32368
+ var pinnedHttpsAgent = new PinnedHttpsAgent(options);
32369
+
32137
32370
  // packages/features/cms-gateway/src/invocation/node-http/nodeHttpRequest.ts
32138
32371
  import { request as httpRequest } from "http";
32139
32372
  import { request as httpsRequest } from "https";
@@ -32149,7 +32382,7 @@ async function sendPinnedHttpRequest(value) {
32149
32382
  method: value.method,
32150
32383
  headers: { ...value.headers, host: value.url.host },
32151
32384
  signal: value.signal,
32152
- agent: false,
32385
+ agent: secure ? pinnedHttpsAgent : pinnedHttpAgent,
32153
32386
  ...secure ? { servername: value.url.hostname.replace(/^\[|\]$/g, "") } : {}
32154
32387
  };
32155
32388
  const request = (secure ? httpsRequest : httpRequest)(options, (incoming) => {
@@ -32269,6 +32502,7 @@ class NodeGatewayHttpNetwork {
32269
32502
  const addresses = await withAbort(() => (this.#options.resolveAddresses ?? defaultResolveAddresses)(hostname), request.signal);
32270
32503
  const address = selectGatewayAddress(origin, addresses, this.#options.allowPrivateAddresses);
32271
32504
  const authorization = await withAbort(() => this.#authorization(request), request.signal);
32505
+ request.onDispatch?.();
32272
32506
  return (this.#options.sendPinned ?? sendPinnedHttpRequest)({
32273
32507
  url,
32274
32508
  address,
@@ -32385,6 +32619,7 @@ class OperatorObservabilityClient {
32385
32619
  endpoint;
32386
32620
  token;
32387
32621
  instanceId;
32622
+ #contractVersion;
32388
32623
  constructor(endpoint, token, instanceId) {
32389
32624
  this.endpoint = endpoint;
32390
32625
  this.token = token;
@@ -32459,7 +32694,7 @@ class OperatorObservabilityClient {
32459
32694
  "content-type": "application/json",
32460
32695
  "x-ulvia-request-id": crypto.randomUUID(),
32461
32696
  "x-ulvia-contract-id": "ulvia.cms.installations",
32462
- "x-ulvia-contract-version": "1.0.0",
32697
+ "x-ulvia-contract-version": await this.contractVersion(),
32463
32698
  "x-ulvia-capability-id": capabilityId
32464
32699
  },
32465
32700
  body: JSON.stringify(input),
@@ -32470,34 +32705,67 @@ class OperatorObservabilityClient {
32470
32705
  await response.body?.cancel();
32471
32706
  throw new Error(`Local Provider rejected the operator request (${response.status})`);
32472
32707
  }
32473
- const reader = response.body?.getReader();
32474
- if (!reader) {
32475
- throw new Error("Local Provider returned an empty response");
32708
+ return readResponse(response);
32709
+ }
32710
+ contractVersion() {
32711
+ if (this.#contractVersion) {
32712
+ return this.#contractVersion;
32476
32713
  }
32477
- let source = "";
32478
- const decoder = new TextDecoder;
32479
- try {
32480
- let bytes = 0;
32481
- for (;; ) {
32482
- const part = await reader.read();
32483
- if (part.done) {
32484
- break;
32485
- }
32486
- bytes += part.value.byteLength;
32487
- if (bytes > 2 * 1024 * 1024) {
32488
- await reader.cancel();
32489
- throw new Error("Local Provider response exceeds its limit");
32490
- }
32491
- source += decoder.decode(part.value, { stream: true });
32714
+ const load = async () => {
32715
+ const response = await fetch(new URL("/ulvia/report", this.endpoint), {
32716
+ headers: { authorization: `Bearer ${this.token}` },
32717
+ redirect: "manual",
32718
+ signal: AbortSignal.timeout(5000)
32719
+ });
32720
+ if (!response.ok) {
32721
+ await response.body?.cancel();
32722
+ throw new Error("Local Provider report is unavailable");
32492
32723
  }
32493
- const value = JSON.parse(source + decoder.decode());
32494
- if (!value || typeof value !== "object" || Array.isArray(value)) {
32495
- throw new Error("Invalid local Provider response");
32724
+ const report = parseProviderRuntimeReportJson(JSON.stringify(await readResponse(response)));
32725
+ const control = report.implementations.find((item) => item.contractId === "ulvia.cms.installations" && item.status === "ready");
32726
+ if (report.instanceId !== this.instanceId || !control || !isCanonicalSemVer(control.version) || !satisfiesVersionRange(control.version, "^1.0.0")) {
32727
+ throw new Error("Local Provider control contract does not match the instance");
32496
32728
  }
32497
- return value;
32498
- } finally {
32499
- reader.releaseLock();
32729
+ return control.version;
32730
+ };
32731
+ const pending = load();
32732
+ this.#contractVersion = pending;
32733
+ pending.catch(() => {
32734
+ if (this.#contractVersion === pending) {
32735
+ this.#contractVersion = undefined;
32736
+ }
32737
+ });
32738
+ return pending;
32739
+ }
32740
+ }
32741
+ async function readResponse(response) {
32742
+ const reader = response.body?.getReader();
32743
+ if (!reader) {
32744
+ throw new Error("Local Provider returned an empty response");
32745
+ }
32746
+ let source = "";
32747
+ const decoder = new TextDecoder;
32748
+ try {
32749
+ let bytes = 0;
32750
+ for (;; ) {
32751
+ const part = await reader.read();
32752
+ if (part.done) {
32753
+ break;
32754
+ }
32755
+ bytes += part.value.byteLength;
32756
+ if (bytes > 2 * 1024 * 1024) {
32757
+ await reader.cancel();
32758
+ throw new Error("Local Provider response exceeds its limit");
32759
+ }
32760
+ source += decoder.decode(part.value, { stream: true });
32500
32761
  }
32762
+ const value = JSON.parse(source + decoder.decode());
32763
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
32764
+ throw new Error("Invalid local Provider response");
32765
+ }
32766
+ return value;
32767
+ } finally {
32768
+ reader.releaseLock();
32501
32769
  }
32502
32770
  }
32503
32771
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyaxis/ulvia",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Ulvia CMS installation and release CLI.",
5
5
  "license": "MIT",
6
6
  "type": "module",