@camstack/server 1.2.828 → 1.2.830

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 (126) hide show
  1. package/CHANGELOG.md +20 -3
  2. package/dist/agent/agent-boot-mode.js +14 -1
  3. package/dist/agent/agent-http.js +12 -0
  4. package/dist/agent/agent-hub-rediscovery.js +205 -0
  5. package/dist/agent/agent-membership-watch.js +29 -1
  6. package/dist/agent/agent-pairing-store.js +47 -3
  7. package/dist/agent/hubs-found.js +1 -0
  8. package/dist/agent/main.js +64 -6
  9. package/dist/api/core/agent-pairing.router.js +9 -0
  10. package/dist/api/core/cluster-update.provider.js +98 -0
  11. package/dist/api/mesh-membership-routes.js +3 -2
  12. package/dist/api/trpc/generated-cap-mounts.js +2 -1
  13. package/dist/api/trpc/generated-cap-routers.js +2339 -2286
  14. package/dist/api/trpc/server-provided-caps.js +1 -0
  15. package/dist/api/trpc/trpc.router.js +5 -0
  16. package/dist/auth/auth-provider-gate.js +6 -2
  17. package/dist/core/addon/device-meta-mirror.js +1 -0
  18. package/dist/core/cluster-update/cluster-update-job-store.js +106 -0
  19. package/dist/core/cluster-update/cluster-update-plan.js +147 -0
  20. package/dist/core/cluster-update/cluster-update-seams.js +13 -0
  21. package/dist/core/cluster-update/cluster-update-steps.js +293 -0
  22. package/dist/core/cluster-update/cluster-update.service.js +319 -0
  23. package/dist/main.js +3 -0
  24. package/dist/manual-boot.js +19 -0
  25. package/package.json +12 -11
  26. package/system/dist/addon-runner.js +12 -0
  27. package/system/dist/addon-runner.mjs +12 -0
  28. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  29. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  30. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  31. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  32. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  33. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  34. package/system/dist/builtins/autotrack/index.js +1 -1
  35. package/system/dist/builtins/autotrack/index.mjs +1 -1
  36. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  37. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  38. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  39. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  40. package/system/dist/builtins/camera-grid/index.js +1 -1
  41. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  42. package/system/dist/builtins/composer/composer.addon.js +4 -4
  43. package/system/dist/builtins/composer/composer.addon.mjs +4 -4
  44. package/system/dist/builtins/console-logging/index.js +1 -1
  45. package/system/dist/builtins/console-logging/index.mjs +1 -1
  46. package/system/dist/builtins/core-blocks/core-blocks.addon.js +3 -3
  47. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +3 -3
  48. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  49. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  50. package/system/dist/builtins/device-manager/device-aggregation.d.ts +25 -1
  51. package/system/dist/builtins/device-manager/device-manager.addon.d.ts +6 -0
  52. package/system/dist/builtins/device-manager/device-manager.addon.js +354 -7
  53. package/system/dist/builtins/device-manager/device-manager.addon.mjs +354 -7
  54. package/system/dist/builtins/device-manager/device-meta-actions.d.ts +6 -0
  55. package/system/dist/builtins/device-manager/device-meta-types.d.ts +4 -0
  56. package/system/dist/builtins/device-manager/device-row-store.d.ts +2 -1
  57. package/system/dist/builtins/device-manager/device-search.d.ts +42 -0
  58. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  59. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  60. package/system/dist/builtins/keychain/index.js +4 -4
  61. package/system/dist/builtins/keychain/index.mjs +4 -4
  62. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  63. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  64. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  65. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  66. package/system/dist/builtins/local-network/hub-mdns.d.ts +5 -1
  67. package/system/dist/builtins/local-network/local-network.addon.js +24 -13
  68. package/system/dist/builtins/local-network/local-network.addon.mjs +24 -13
  69. package/system/dist/builtins/loki-logging/index.js +1 -1
  70. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  71. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  72. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  73. package/system/dist/builtins/platform-probe/index.js +1 -1
  74. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  75. package/system/dist/builtins/record-entries/index.js +1 -1
  76. package/system/dist/builtins/record-entries/index.mjs +1 -1
  77. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  78. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  79. package/system/dist/builtins/snapshot/index.js +1 -1
  80. package/system/dist/builtins/snapshot/index.mjs +1 -1
  81. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  82. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  83. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  84. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  85. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  86. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  87. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  88. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  89. package/system/dist/builtins/system-config/system-config.addon.js +59 -20
  90. package/system/dist/builtins/system-config/system-config.addon.mjs +48 -10
  91. package/system/dist/builtins/winston-logging/index.js +1 -1
  92. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  93. package/system/dist/{capture-engine-1A7HAX3x.js → capture-engine-6_V-PR8O.js} +1 -1
  94. package/system/dist/{capture-engine-B0yQx6hA.mjs → capture-engine-cp3my4VK.mjs} +1 -1
  95. package/system/dist/{composition-sources-CyJ0d6Sc.mjs → composition-sources-C-iX_Uuu.mjs} +1 -1
  96. package/system/dist/{composition-sources-BzM19ASO.js → composition-sources-JwBPIhdO.js} +1 -1
  97. package/system/dist/{constants-DSO4ZEO3.js → constants-C4V2z-GT.js} +1 -1
  98. package/system/dist/{constants-B_FLEjP_.mjs → constants-D5oNuYLD.mjs} +1 -1
  99. package/system/dist/{device-ca-CveuNCHp.mjs → device-ca-CXPTrORC.mjs} +1 -1
  100. package/system/dist/{device-ca-DLTDsonl.js → device-ca-DAuMNieL.js} +1 -1
  101. package/system/dist/{dist-CIyyHwVx.mjs → dist-B8dBvJJK.mjs} +469 -27
  102. package/system/dist/{dist-DhbzVygm.js → dist-DVrLQr6W.js} +469 -27
  103. package/system/dist/file-host-worker.js +1 -1
  104. package/system/dist/file-host-worker.mjs +1 -1
  105. package/system/dist/{agent-https-BlLVD9hG.js → hub-identity-Cg1_bzoY.js} +120 -1
  106. package/system/dist/{agent-https-BSxTUzKT.mjs → hub-identity-D2sSTELW.mjs} +97 -2
  107. package/system/dist/{hub-mdns-ciao-C_ITDs0-.js → hub-mdns-ciao-DCHShuFh.js} +18 -18
  108. package/system/dist/{hub-mdns-ciao-CQdCUsrI.mjs → hub-mdns-ciao-Twxwj9Vh.mjs} +2 -2
  109. package/system/dist/index.js +61 -44
  110. package/system/dist/index.mjs +22 -10
  111. package/system/dist/kernel/hub-identity.d.ts +17 -0
  112. package/system/dist/kernel/index.d.ts +2 -0
  113. package/system/dist/kernel/moleculer/mesh-mtls/mesh-membership.d.ts +7 -0
  114. package/system/dist/kernel/moleculer/mesh-mtls/pairing/agent-pairing.d.ts +11 -1
  115. package/system/dist/kernel/moleculer/mesh-mtls/pairing/hub-pairing.d.ts +5 -0
  116. package/system/dist/kernel/moleculer/mesh-mtls/pairing/index.d.ts +1 -1
  117. package/system/dist/kernel/moleculer/mesh-mtls/pairing/pairing-protocol.d.ts +2 -0
  118. package/system/dist/{legacy-integration-rows-door-D_tfRhsx.js → legacy-integration-rows-door-i0gANn4l.js} +1 -1
  119. package/system/dist/{legacy-integration-rows-door-tX6Qktxd.mjs → legacy-integration-rows-door-lRhfbNBc.mjs} +1 -1
  120. package/system/dist/{rename-composition-block-DNhbAonr.js → rename-composition-block-BRy-9srI.js} +1 -1
  121. package/system/dist/{rename-composition-block-COaMxshT.mjs → rename-composition-block-C2IbabFp.mjs} +1 -1
  122. package/system/dist/{restore-archive-BMqp_hMT.mjs → restore-archive-CkyWtDIi.mjs} +1 -1
  123. package/system/dist/{restore-archive-Dbzuv5hK.js → restore-archive-_y4JaVgy.js} +1 -1
  124. package/system/dist/{wal-maintenance-CWODOTsa.js → wal-maintenance-BfkwceLa.js} +0 -0
  125. package/system/dist/{wal-maintenance-ITsLGvFA.mjs → wal-maintenance-Dn2cx4Km.mjs} +0 -0
  126. package/system/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  require("./chunk-Cek0wNdY.js");
2
- const require_wal_maintenance = require("./wal-maintenance-CWODOTsa.js");
2
+ const require_wal_maintenance = require("./wal-maintenance-BfkwceLa.js");
3
3
  let node_worker_threads = require("node:worker_threads");
4
4
  //#region src/builtins/sqlite-storage/file-host-worker.ts
5
5
  /**
@@ -1,4 +1,4 @@
1
- import { A as callRecords, C as isFileHostWorkerData, D as RecordsEngine, M as controlTargetOf, O as callControl, S as isFileHostRequest, a as WalMaintenance, b as collectTransferables, d as callMigrate, f as migrateTargetOf, j as callVector, k as callData, l as SqliteSettingsBackend, o as createVectorIndex, s as vectorProviderOf, u as HUB_MIGRATIONS, v as serializeError, w as trustInput } from "./wal-maintenance-ITsLGvFA.mjs";
1
+ import { A as callRecords, C as isFileHostWorkerData, D as RecordsEngine, M as controlTargetOf, O as callControl, S as isFileHostRequest, a as WalMaintenance, b as collectTransferables, d as callMigrate, f as migrateTargetOf, j as callVector, k as callData, l as SqliteSettingsBackend, o as createVectorIndex, s as vectorProviderOf, u as HUB_MIGRATIONS, v as serializeError, w as trustInput } from "./wal-maintenance-Dn2cx4Km.mjs";
2
2
  import { parentPort, threadId, workerData } from "node:worker_threads";
3
3
  //#region src/builtins/sqlite-storage/file-host-worker.ts
4
4
  /**
@@ -1,12 +1,14 @@
1
1
  const require_chunk = require("./chunk-Cek0wNdY.js");
2
- const require_dist = require("./dist-DhbzVygm.js");
2
+ const require_dist = require("./dist-DVrLQr6W.js");
3
3
  const require_x509_es = require("./x509.es-WtnRNyYS.js");
4
4
  let zod = require("zod");
5
5
  let node_crypto = require("node:crypto");
6
6
  let _camstack_types_node = require("@camstack/types/node");
7
7
  let node_net = require("node:net");
8
8
  let node_fs = require("node:fs");
9
+ node_fs = require_chunk.__toESM(node_fs);
9
10
  let node_path = require("node:path");
11
+ node_path = require_chunk.__toESM(node_path);
10
12
  let node_os = require("node:os");
11
13
  node_os = require_chunk.__toESM(node_os);
12
14
  var MeshNodeCertificateBodySchema = zod.z.object({
@@ -1041,6 +1043,99 @@ function pemDigest(pem) {
1041
1043
  return (0, node_crypto.createHash)("sha256").update(pem).digest("hex").slice(0, 16);
1042
1044
  }
1043
1045
  //#endregion
1046
+ //#region src/kernel/hub-identity.ts
1047
+ /**
1048
+ * The hub's ANNOUNCED identity (#494): `hub-<16 hex>`, random, generated once
1049
+ * and kept in `<dataDir>/tls/hub-identity.json`, beside the mesh CA a system
1050
+ * backup already archives. A file still at the data root (the first location)
1051
+ * is read once and copied under `tls/`; it is never overwritten. The hub
1052
+ * announces the id over mDNS and gives it to an agent at pairing; the agent
1053
+ * records it to find ITS hub again when it has no address, and to refuse
1054
+ * another hub on the same LAN.
1055
+ *
1056
+ * It is public (it grants nothing) and it is NOT the mesh node id: every hub is
1057
+ * still `hub` on its own mesh. A seed never overwrites: a file that exists but
1058
+ * cannot be read is reported and left alone, because paired agents hold the id
1059
+ * it carried.
1060
+ */
1061
+ /** `hub-<16 hex>`. The same shape as `@camstack/types` `isHubId`. */
1062
+ var HUB_ID_PATTERN = /^hub-[0-9a-f]{16}$/;
1063
+ function isAnnouncedHubId(value) {
1064
+ return typeof value === "string" && HUB_ID_PATTERN.test(value);
1065
+ }
1066
+ var HUB_IDENTITY_FILE = "hub-identity.json";
1067
+ /** Data-dir-relative path. Beside the mesh CA, so a backup of `tls/` keeps the id. */
1068
+ var HUB_IDENTITY_RELATIVE = `tls/${HUB_IDENTITY_FILE}`;
1069
+ function readHubIdFile(file) {
1070
+ let parsed;
1071
+ try {
1072
+ parsed = JSON.parse(node_fs.readFileSync(file, "utf8"));
1073
+ } catch (err) {
1074
+ return {
1075
+ hubId: null,
1076
+ created: false,
1077
+ problem: `${file} is unreadable: ${err instanceof Error ? err.message : String(err)}`
1078
+ };
1079
+ }
1080
+ const hubId = parsed !== null && typeof parsed === "object" ? Reflect.get(parsed, "hubId") : void 0;
1081
+ if (!isAnnouncedHubId(hubId)) return {
1082
+ hubId: null,
1083
+ created: false,
1084
+ problem: `${file} holds a value that is not a hub id`
1085
+ };
1086
+ return {
1087
+ hubId,
1088
+ created: false,
1089
+ problem: null
1090
+ };
1091
+ }
1092
+ function identityPath(dataDir) {
1093
+ return node_path.join(dataDir, HUB_IDENTITY_RELATIVE);
1094
+ }
1095
+ /** Persist `hubId` at `file`. A file that appears meanwhile is kept (link refuses it). */
1096
+ function writeHubIdFile(file, hubId) {
1097
+ const tmp = `${file}.${process.pid}.tmp`;
1098
+ try {
1099
+ node_fs.mkdirSync(node_path.dirname(file), { recursive: true });
1100
+ node_fs.writeFileSync(tmp, `${JSON.stringify({ hubId }, null, 2)}\n`);
1101
+ node_fs.linkSync(tmp, file);
1102
+ } catch (err) {
1103
+ if (node_fs.existsSync(file)) return readHubIdFile(file);
1104
+ return {
1105
+ hubId: null,
1106
+ created: false,
1107
+ problem: `could not write ${file}: ${err instanceof Error ? err.message : String(err)}`
1108
+ };
1109
+ } finally {
1110
+ node_fs.rmSync(tmp, { force: true });
1111
+ }
1112
+ return {
1113
+ hubId,
1114
+ created: true,
1115
+ problem: null
1116
+ };
1117
+ }
1118
+ /**
1119
+ * Read the hub id, generating and persisting it on the first call ever.
1120
+ * Never throws. A file at the data root is copied under `tls/` once.
1121
+ */
1122
+ function loadOrCreateHubId(dataDir) {
1123
+ const file = identityPath(dataDir);
1124
+ if (node_fs.existsSync(file)) return readHubIdFile(file);
1125
+ const legacy = node_path.join(dataDir, HUB_IDENTITY_FILE);
1126
+ if (node_fs.existsSync(legacy)) {
1127
+ const read = readHubIdFile(legacy);
1128
+ if (read.hubId === null) return read;
1129
+ if (writeHubIdFile(file, read.hubId).hubId === null) return read;
1130
+ return {
1131
+ hubId: read.hubId,
1132
+ created: false,
1133
+ problem: null
1134
+ };
1135
+ }
1136
+ return writeHubIdFile(file, `hub-${(0, node_crypto.randomBytes)(8).toString("hex")}`);
1137
+ }
1138
+ //#endregion
1044
1139
  Object.defineProperty(exports, "AGENT_HTTPS_NAMES_COLLECTION", {
1045
1140
  enumerable: true,
1046
1141
  get: function() {
@@ -1077,6 +1172,18 @@ Object.defineProperty(exports, "CA_VALIDITY_DAYS", {
1077
1172
  return CA_VALIDITY_DAYS;
1078
1173
  }
1079
1174
  });
1175
+ Object.defineProperty(exports, "HUB_IDENTITY_FILE", {
1176
+ enumerable: true,
1177
+ get: function() {
1178
+ return HUB_IDENTITY_FILE;
1179
+ }
1180
+ });
1181
+ Object.defineProperty(exports, "HUB_IDENTITY_RELATIVE", {
1182
+ enumerable: true,
1183
+ get: function() {
1184
+ return HUB_IDENTITY_RELATIVE;
1185
+ }
1186
+ });
1080
1187
  Object.defineProperty(exports, "LEAF_RENEWAL_WINDOW_DAYS", {
1081
1188
  enumerable: true,
1082
1189
  get: function() {
@@ -1179,6 +1286,12 @@ Object.defineProperty(exports, "installAgentHttps", {
1179
1286
  return installAgentHttps;
1180
1287
  }
1181
1288
  });
1289
+ Object.defineProperty(exports, "isAnnouncedHubId", {
1290
+ enumerable: true,
1291
+ get: function() {
1292
+ return isAnnouncedHubId;
1293
+ }
1294
+ });
1182
1295
  Object.defineProperty(exports, "isConstrainedCa", {
1183
1296
  enumerable: true,
1184
1297
  get: function() {
@@ -1227,6 +1340,12 @@ Object.defineProperty(exports, "loadCa", {
1227
1340
  return loadCa;
1228
1341
  }
1229
1342
  });
1343
+ Object.defineProperty(exports, "loadOrCreateHubId", {
1344
+ enumerable: true,
1345
+ get: function() {
1346
+ return loadOrCreateHubId;
1347
+ }
1348
+ });
1230
1349
  Object.defineProperty(exports, "localCaCommonName", {
1231
1350
  enumerable: true,
1232
1351
  get: function() {
@@ -1,10 +1,12 @@
1
- import { mc as defineRecordKinds } from "./dist-CIyyHwVx.mjs";
1
+ import { mc as defineRecordKinds } from "./dist-B8dBvJJK.mjs";
2
2
  import { C as backdatedNotBefore, S as withUtcTimeEncoding, _ as NameConstraints, a as KeyUsageFlags, c as Pkcs10CertificateRequest, d as SubjectKeyIdentifierExtension, f as X509Certificate$1, g as GeneralSubtrees, h as GeneralSubtree, i as Extension, l as Pkcs10CertificateRequestGenerator, m as cryptoProvider, n as BasicConstraintsExtension, o as KeyUsagesExtension, p as X509CertificateGenerator, r as ExtendedKeyUsageExtension, s as PemConverter, t as AuthorityKeyIdentifierExtension, u as SubjectAlternativeNameExtension, v as GeneralName, x as AsnConvert } from "./x509.es-BRiJgOvu.mjs";
3
3
  import { z } from "zod";
4
4
  import { X509Certificate, createHash, createPrivateKey, randomBytes, webcrypto } from "node:crypto";
5
5
  import { writeOwnerOnlyFileSync } from "@camstack/types/node";
6
6
  import { isIP } from "node:net";
7
+ import * as fs$1 from "node:fs";
7
8
  import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
9
+ import * as path$1 from "node:path";
8
10
  import { join } from "node:path";
9
11
  import * as os$1 from "node:os";
10
12
  var MeshNodeCertificateBodySchema = z.object({
@@ -1039,4 +1041,97 @@ function pemDigest(pem) {
1039
1041
  return createHash("sha256").update(pem).digest("hex").slice(0, 16);
1040
1042
  }
1041
1043
  //#endregion
1042
- export { buildNameConstraintSet as A, setProcessAgentHttpsNames as B, LEAF_RENEWAL_WINDOW_DAYS as C, reasonRequiresNewCa as D, evaluateExistingCert as E, readNameConstraints as F, AGENT_HTTPS_NAMES_COLLECTION as I, AGENT_HTTPS_NAMES_COLUMNS as L, isLocalOnlyHostname as M, permitsIdentity as N, PERMITTED_DNS_SUFFIXES as O, permitsName as P, AgentHttpsNames as R, CA_VALIDITY_DAYS as S, SERVER_AUTH_OID as T, systemConfigRecordKinds as V, issueLeaf as _, collectAgentNames as a, collectCertIdentity as b, installAgentHttps as c, issueAgentHttpsLeaf as d, loadAgentHttps as f, generateCa as g, CA_COMMON_NAME as h, certificateNames as i, isConstrainedCa as j, PERMITTED_IP_RANGES as k, isContainerBridgeAddress as l, pinnedHttpsCaFingerprint as m, acceptAgentSans as n, createAgentHttpsRequest as o, pemDigest as p, agentHttpsPaths as r, describeHttpsLeaf as s, AgentHttpsInstallError as t, isPrivateAddress as u, loadCa as v, MAX_LEAF_VALIDITY_DAYS as w, systemHostFacts as x, localCaCommonName as y, getProcessAgentHttpsNames as z };
1044
+ //#region src/kernel/hub-identity.ts
1045
+ /**
1046
+ * The hub's ANNOUNCED identity (#494): `hub-<16 hex>`, random, generated once
1047
+ * and kept in `<dataDir>/tls/hub-identity.json`, beside the mesh CA a system
1048
+ * backup already archives. A file still at the data root (the first location)
1049
+ * is read once and copied under `tls/`; it is never overwritten. The hub
1050
+ * announces the id over mDNS and gives it to an agent at pairing; the agent
1051
+ * records it to find ITS hub again when it has no address, and to refuse
1052
+ * another hub on the same LAN.
1053
+ *
1054
+ * It is public (it grants nothing) and it is NOT the mesh node id: every hub is
1055
+ * still `hub` on its own mesh. A seed never overwrites: a file that exists but
1056
+ * cannot be read is reported and left alone, because paired agents hold the id
1057
+ * it carried.
1058
+ */
1059
+ /** `hub-<16 hex>`. The same shape as `@camstack/types` `isHubId`. */
1060
+ var HUB_ID_PATTERN = /^hub-[0-9a-f]{16}$/;
1061
+ function isAnnouncedHubId(value) {
1062
+ return typeof value === "string" && HUB_ID_PATTERN.test(value);
1063
+ }
1064
+ var HUB_IDENTITY_FILE = "hub-identity.json";
1065
+ /** Data-dir-relative path. Beside the mesh CA, so a backup of `tls/` keeps the id. */
1066
+ var HUB_IDENTITY_RELATIVE = `tls/${HUB_IDENTITY_FILE}`;
1067
+ function readHubIdFile(file) {
1068
+ let parsed;
1069
+ try {
1070
+ parsed = JSON.parse(fs$1.readFileSync(file, "utf8"));
1071
+ } catch (err) {
1072
+ return {
1073
+ hubId: null,
1074
+ created: false,
1075
+ problem: `${file} is unreadable: ${err instanceof Error ? err.message : String(err)}`
1076
+ };
1077
+ }
1078
+ const hubId = parsed !== null && typeof parsed === "object" ? Reflect.get(parsed, "hubId") : void 0;
1079
+ if (!isAnnouncedHubId(hubId)) return {
1080
+ hubId: null,
1081
+ created: false,
1082
+ problem: `${file} holds a value that is not a hub id`
1083
+ };
1084
+ return {
1085
+ hubId,
1086
+ created: false,
1087
+ problem: null
1088
+ };
1089
+ }
1090
+ function identityPath(dataDir) {
1091
+ return path$1.join(dataDir, HUB_IDENTITY_RELATIVE);
1092
+ }
1093
+ /** Persist `hubId` at `file`. A file that appears meanwhile is kept (link refuses it). */
1094
+ function writeHubIdFile(file, hubId) {
1095
+ const tmp = `${file}.${process.pid}.tmp`;
1096
+ try {
1097
+ fs$1.mkdirSync(path$1.dirname(file), { recursive: true });
1098
+ fs$1.writeFileSync(tmp, `${JSON.stringify({ hubId }, null, 2)}\n`);
1099
+ fs$1.linkSync(tmp, file);
1100
+ } catch (err) {
1101
+ if (fs$1.existsSync(file)) return readHubIdFile(file);
1102
+ return {
1103
+ hubId: null,
1104
+ created: false,
1105
+ problem: `could not write ${file}: ${err instanceof Error ? err.message : String(err)}`
1106
+ };
1107
+ } finally {
1108
+ fs$1.rmSync(tmp, { force: true });
1109
+ }
1110
+ return {
1111
+ hubId,
1112
+ created: true,
1113
+ problem: null
1114
+ };
1115
+ }
1116
+ /**
1117
+ * Read the hub id, generating and persisting it on the first call ever.
1118
+ * Never throws. A file at the data root is copied under `tls/` once.
1119
+ */
1120
+ function loadOrCreateHubId(dataDir) {
1121
+ const file = identityPath(dataDir);
1122
+ if (fs$1.existsSync(file)) return readHubIdFile(file);
1123
+ const legacy = path$1.join(dataDir, HUB_IDENTITY_FILE);
1124
+ if (fs$1.existsSync(legacy)) {
1125
+ const read = readHubIdFile(legacy);
1126
+ if (read.hubId === null) return read;
1127
+ if (writeHubIdFile(file, read.hubId).hubId === null) return read;
1128
+ return {
1129
+ hubId: read.hubId,
1130
+ created: false,
1131
+ problem: null
1132
+ };
1133
+ }
1134
+ return writeHubIdFile(file, `hub-${randomBytes(8).toString("hex")}`);
1135
+ }
1136
+ //#endregion
1137
+ export { evaluateExistingCert as A, AGENT_HTTPS_NAMES_COLLECTION as B, localCaCommonName as C, LEAF_RENEWAL_WINDOW_DAYS as D, CA_VALIDITY_DAYS as E, isConstrainedCa as F, systemConfigRecordKinds as G, AgentHttpsNames as H, isLocalOnlyHostname as I, permitsIdentity as L, PERMITTED_DNS_SUFFIXES as M, PERMITTED_IP_RANGES as N, MAX_LEAF_VALIDITY_DAYS as O, buildNameConstraintSet as P, permitsName as R, loadCa as S, systemHostFacts as T, getProcessAgentHttpsNames as U, AGENT_HTTPS_NAMES_COLUMNS as V, setProcessAgentHttpsNames as W, pemDigest as _, AgentHttpsInstallError as a, generateCa as b, certificateNames as c, describeHttpsLeaf as d, installAgentHttps as f, loadAgentHttps as g, issueAgentHttpsLeaf as h, loadOrCreateHubId as i, reasonRequiresNewCa as j, SERVER_AUTH_OID as k, collectAgentNames as l, isPrivateAddress as m, HUB_IDENTITY_RELATIVE as n, acceptAgentSans as o, isContainerBridgeAddress as p, isAnnouncedHubId as r, agentHttpsPaths as s, HUB_IDENTITY_FILE as t, createAgentHttpsRequest as u, pinnedHttpsCaFingerprint as v, collectCertIdentity as w, issueLeaf as x, CA_COMMON_NAME as y, readNameConstraints as z };
@@ -1,7 +1,7 @@
1
1
  const require_chunk = require("./chunk-Cek0wNdY.js");
2
- const require_dist = require("./dist-DhbzVygm.js");
2
+ const require_dist = require("./dist-DVrLQr6W.js");
3
3
  const require_x509_es = require("./x509.es-WtnRNyYS.js");
4
- const require_agent_https = require("./agent-https-BlLVD9hG.js");
4
+ const require_hub_identity = require("./hub-identity-Cg1_bzoY.js");
5
5
  let node_crypto = require("node:crypto");
6
6
  let _camstack_types_node = require("@camstack/types/node");
7
7
  let node_fs = require("node:fs");
@@ -191,7 +191,7 @@ async function ensureTlsCert(dataDir, options) {
191
191
  };
192
192
  const commonName = options?.commonName ?? DEFAULT_COMMON_NAME;
193
193
  const validDays = Math.min(options?.validDays ?? 397, 397);
194
- const rawIdentity = require_agent_https.collectCertIdentity({
194
+ const rawIdentity = require_hub_identity.collectCertIdentity({
195
195
  commonName,
196
196
  extraSans: options?.extraSans ?? [],
197
197
  ...options?.hostFacts === void 0 ? {} : { hostFacts: options.hostFacts }
@@ -200,13 +200,13 @@ async function ensureTlsCert(dataDir, options) {
200
200
  const reason = decideRegeneration(paths, onDisk.identity);
201
201
  if (reason === null) return describe(paths, false, null, false, null, null, onDisk.dropped);
202
202
  const previousFingerprint = readFingerprint(paths.certPath);
203
- const caRotated = require_agent_https.reasonRequiresNewCa(reason);
203
+ const caRotated = require_hub_identity.reasonRequiresNewCa(reason);
204
204
  (0, node_fs.mkdirSync)(tlsDir, { recursive: true });
205
205
  let dropped = [];
206
206
  try {
207
207
  dropped = await regenerate(paths, rawIdentity, {
208
208
  commonName,
209
- caCommonName: require_agent_https.localCaCommonName(options?.hubName),
209
+ caCommonName: require_hub_identity.localCaCommonName(options?.hubName),
210
210
  validDays,
211
211
  newCa: caRotated,
212
212
  reason
@@ -233,7 +233,7 @@ async function reissueTlsLeaf(dataDir, options) {
233
233
  if (!(0, node_fs.existsSync)(paths.caCertPath) || !(0, node_fs.existsSync)(paths.caKeyPath)) return ensureTlsCert(dataDir, options);
234
234
  const commonName = options?.commonName ?? DEFAULT_COMMON_NAME;
235
235
  const validDays = Math.min(options?.validDays ?? 397, 397);
236
- const identity = require_agent_https.collectCertIdentity({
236
+ const identity = require_hub_identity.collectCertIdentity({
237
237
  commonName,
238
238
  extraSans: options?.extraSans ?? [],
239
239
  ...options?.hostFacts === void 0 ? {} : { hostFacts: options.hostFacts }
@@ -242,7 +242,7 @@ async function reissueTlsLeaf(dataDir, options) {
242
242
  (0, node_fs.mkdirSync)(tlsDir, { recursive: true });
243
243
  return describe(paths, true, "san-coverage-gap", false, previousFingerprint, null, await regenerate(paths, identity, {
244
244
  commonName,
245
- caCommonName: require_agent_https.localCaCommonName(options?.hubName),
245
+ caCommonName: require_hub_identity.localCaCommonName(options?.hubName),
246
246
  validDays,
247
247
  newCa: false,
248
248
  reason: null
@@ -263,16 +263,16 @@ async function replaceUnconstrainedLocalCa(dataDir, options) {
263
263
  };
264
264
  if (!(0, node_fs.existsSync)(paths.caCertPath) || !(0, node_fs.existsSync)(paths.caKeyPath)) return false;
265
265
  try {
266
- if (require_agent_https.isConstrainedCa(new require_x509_es.X509Certificate((0, node_fs.readFileSync)(paths.caCertPath, "utf-8")))) return false;
266
+ if (require_hub_identity.isConstrainedCa(new require_x509_es.X509Certificate((0, node_fs.readFileSync)(paths.caCertPath, "utf-8")))) return false;
267
267
  } catch {
268
268
  return false;
269
269
  }
270
- const identity = require_agent_https.collectCertIdentity({
270
+ const identity = require_hub_identity.collectCertIdentity({
271
271
  commonName: options?.commonName ?? DEFAULT_COMMON_NAME,
272
272
  extraSans: options?.extraSans ?? [],
273
273
  ...options?.hostFacts === void 0 ? {} : { hostFacts: options.hostFacts }
274
274
  });
275
- const ca = await require_agent_https.generateCa(/* @__PURE__ */ new Date(), identity.dnsNames, require_agent_https.localCaCommonName(options?.hubName));
275
+ const ca = await require_hub_identity.generateCa(/* @__PURE__ */ new Date(), identity.dnsNames, require_hub_identity.localCaCommonName(options?.hubName));
276
276
  archivePreviousCa(paths, ca);
277
277
  await (0, node_fs_promises.writeFile)(`${paths.caCertPath}.new`, ca.certPem, "utf-8");
278
278
  (0, _camstack_types_node.writeOwnerOnlyFileSync)(`${paths.caKeyPath}.new`, ca.keyPem);
@@ -298,7 +298,7 @@ function decideRegeneration(paths, identity) {
298
298
  if (!(0, node_fs.existsSync)(paths.certPath) || !(0, node_fs.existsSync)(paths.keyPath)) return "missing";
299
299
  if (!(0, node_fs.existsSync)(paths.caCertPath) || !(0, node_fs.existsSync)(paths.caKeyPath)) return "no-local-ca";
300
300
  try {
301
- return require_agent_https.evaluateExistingCert({
301
+ return require_hub_identity.evaluateExistingCert({
302
302
  chainPem: (0, node_fs.readFileSync)(paths.certPath, "utf-8"),
303
303
  keyPem: (0, node_fs.readFileSync)(paths.keyPath, "utf-8"),
304
304
  caPem: (0, node_fs.readFileSync)(paths.caCertPath, "utf-8"),
@@ -312,13 +312,13 @@ function decideRegeneration(paths, identity) {
312
312
  async function regenerate(paths, rawIdentity, params) {
313
313
  const { commonName, caCommonName, validDays, newCa, reason } = params;
314
314
  const now = /* @__PURE__ */ new Date();
315
- const ca = newCa ? await require_agent_https.generateCa(now, rawIdentity.dnsNames, caCommonName) : await require_agent_https.loadCa((0, node_fs.readFileSync)(paths.caCertPath, "utf-8"), (0, node_fs.readFileSync)(paths.caKeyPath, "utf-8"));
316
- const constraints = require_agent_https.readNameConstraints(ca.cert);
315
+ const ca = newCa ? await require_hub_identity.generateCa(now, rawIdentity.dnsNames, caCommonName) : await require_hub_identity.loadCa((0, node_fs.readFileSync)(paths.caCertPath, "utf-8"), (0, node_fs.readFileSync)(paths.caKeyPath, "utf-8"));
316
+ const constraints = require_hub_identity.readNameConstraints(ca.cert);
317
317
  const { identity, dropped } = constraints === null ? {
318
318
  identity: rawIdentity,
319
319
  dropped: []
320
- } : require_agent_https.permitsIdentity(constraints, rawIdentity);
321
- const leaf = await require_agent_https.issueLeaf(ca, identity, commonName, validDays, now);
320
+ } : require_hub_identity.permitsIdentity(constraints, rawIdentity);
321
+ const leaf = await require_hub_identity.issueLeaf(ca, identity, commonName, validDays, now);
322
322
  const chainPem = `${leaf.certPem.trimEnd()}\n${ca.certPem.trimEnd()}\n`;
323
323
  if (newCa) {
324
324
  if (reason === "ca-unconstrained") archivePreviousCa(paths, ca);
@@ -336,11 +336,11 @@ async function regenerate(paths, rawIdentity, params) {
336
336
  /** The identity as far as the CA on disk may certify it; unchanged while that CA is absent or unconstrained. */
337
337
  function constrainToDiskCa(paths, identity) {
338
338
  try {
339
- const constraints = require_agent_https.readNameConstraints(new require_x509_es.X509Certificate((0, node_fs.readFileSync)(paths.caCertPath, "utf-8")));
339
+ const constraints = require_hub_identity.readNameConstraints(new require_x509_es.X509Certificate((0, node_fs.readFileSync)(paths.caCertPath, "utf-8")));
340
340
  return constraints === null ? {
341
341
  identity,
342
342
  dropped: []
343
- } : require_agent_https.permitsIdentity(constraints, identity);
343
+ } : require_hub_identity.permitsIdentity(constraints, identity);
344
344
  } catch {
345
345
  return {
346
346
  identity,
@@ -613,7 +613,7 @@ function readLocalCaConstrained(dir) {
613
613
  const caPath = (0, node_path.join)(dir, "camstack-ca.crt");
614
614
  if (!(0, node_fs.existsSync)(caPath)) return null;
615
615
  try {
616
- return require_agent_https.isConstrainedCa(new require_x509_es.X509Certificate((0, node_fs.readFileSync)(caPath, "utf-8")));
616
+ return require_hub_identity.isConstrainedCa(new require_x509_es.X509Certificate((0, node_fs.readFileSync)(caPath, "utf-8")));
617
617
  } catch {
618
618
  return null;
619
619
  }
@@ -1,7 +1,7 @@
1
1
  import { o as __toESM } from "./chunk-CNf5ZN-e.mjs";
2
- import { il as userError } from "./dist-CIyyHwVx.mjs";
2
+ import { il as userError } from "./dist-B8dBvJJK.mjs";
3
3
  import { f as X509Certificate$1 } from "./x509.es-BRiJgOvu.mjs";
4
- import { D as reasonRequiresNewCa, E as evaluateExistingCert, F as readNameConstraints, N as permitsIdentity, _ as issueLeaf, b as collectCertIdentity, g as generateCa, j as isConstrainedCa, v as loadCa, y as localCaCommonName } from "./agent-https-BSxTUzKT.mjs";
4
+ import { A as evaluateExistingCert, C as localCaCommonName, F as isConstrainedCa, L as permitsIdentity, S as loadCa, b as generateCa, j as reasonRequiresNewCa, w as collectCertIdentity, x as issueLeaf, z as readNameConstraints } from "./hub-identity-D2sSTELW.mjs";
5
5
  import { X509Certificate, createPrivateKey } from "node:crypto";
6
6
  import { writeOwnerOnlyFileSync } from "@camstack/types/node";
7
7
  import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";