@matter/node 0.11.9 → 0.12.0-alpha.0-20241213-fcd71a96d

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 (221) hide show
  1. package/dist/cjs/behavior/internal/BehaviorBacking.d.ts +6 -1
  2. package/dist/cjs/behavior/internal/BehaviorBacking.d.ts.map +1 -1
  3. package/dist/cjs/behavior/internal/BehaviorBacking.js +2 -1
  4. package/dist/cjs/behavior/internal/BehaviorBacking.js.map +1 -1
  5. package/dist/cjs/behavior/internal/ClientBehaviorBacking.d.ts +2 -1
  6. package/dist/cjs/behavior/internal/ClientBehaviorBacking.d.ts.map +1 -1
  7. package/dist/cjs/behavior/internal/ClientBehaviorBacking.js +4 -0
  8. package/dist/cjs/behavior/internal/ClientBehaviorBacking.js.map +1 -1
  9. package/dist/cjs/behavior/internal/ServerBehaviorBacking.d.ts +2 -0
  10. package/dist/cjs/behavior/internal/ServerBehaviorBacking.d.ts.map +1 -1
  11. package/dist/cjs/behavior/internal/ServerBehaviorBacking.js +37 -0
  12. package/dist/cjs/behavior/internal/ServerBehaviorBacking.js.map +1 -1
  13. package/dist/cjs/behavior/state/transaction/Transaction.d.ts +18 -18
  14. package/dist/cjs/behavior/system/events/EventsBehavior.d.ts +26 -0
  15. package/dist/cjs/behavior/system/events/EventsBehavior.d.ts.map +1 -0
  16. package/dist/cjs/behavior/system/events/EventsBehavior.js +74 -0
  17. package/dist/cjs/behavior/system/events/EventsBehavior.js.map +6 -0
  18. package/dist/cjs/behavior/system/events/index.d.ts +7 -0
  19. package/dist/cjs/behavior/system/events/index.d.ts.map +1 -0
  20. package/dist/cjs/behavior/system/events/index.js +24 -0
  21. package/dist/cjs/behavior/system/events/index.js.map +6 -0
  22. package/dist/cjs/behavior/system/network/ServerNetworkRuntime.d.ts.map +1 -1
  23. package/dist/cjs/behavior/system/network/ServerNetworkRuntime.js +3 -0
  24. package/dist/cjs/behavior/system/network/ServerNetworkRuntime.js.map +1 -1
  25. package/dist/cjs/behaviors/administrator-commissioning/AdministratorCommissioningServer.d.ts +8 -0
  26. package/dist/cjs/behaviors/administrator-commissioning/AdministratorCommissioningServer.d.ts.map +1 -1
  27. package/dist/cjs/behaviors/administrator-commissioning/AdministratorCommissioningServer.js +12 -4
  28. package/dist/cjs/behaviors/administrator-commissioning/AdministratorCommissioningServer.js.map +1 -1
  29. package/dist/cjs/behaviors/general-diagnostics/GeneralDiagnosticsServer.d.ts +2 -4
  30. package/dist/cjs/behaviors/general-diagnostics/GeneralDiagnosticsServer.d.ts.map +1 -1
  31. package/dist/cjs/behaviors/general-diagnostics/GeneralDiagnosticsServer.js +6 -8
  32. package/dist/cjs/behaviors/general-diagnostics/GeneralDiagnosticsServer.js.map +1 -1
  33. package/dist/cjs/behaviors/operational-credentials/OperationalCredentialsServer.d.ts.map +1 -1
  34. package/dist/cjs/behaviors/operational-credentials/OperationalCredentialsServer.js +23 -20
  35. package/dist/cjs/behaviors/operational-credentials/OperationalCredentialsServer.js.map +1 -1
  36. package/dist/cjs/endpoint/Agent.d.ts +1 -1
  37. package/dist/cjs/endpoint/Agent.js +1 -1
  38. package/dist/cjs/endpoint/index.d.ts +1 -1
  39. package/dist/cjs/endpoint/index.d.ts.map +1 -1
  40. package/dist/cjs/endpoint/index.js +1 -1
  41. package/dist/cjs/endpoint/index.js.map +1 -1
  42. package/dist/cjs/endpoint/properties/Behaviors.d.ts +13 -0
  43. package/dist/cjs/endpoint/properties/Behaviors.d.ts.map +1 -1
  44. package/dist/cjs/endpoint/properties/Behaviors.js +37 -24
  45. package/dist/cjs/endpoint/properties/Behaviors.js.map +2 -2
  46. package/dist/cjs/endpoint/properties/EndpointInitializer.d.ts +8 -3
  47. package/dist/cjs/endpoint/properties/EndpointInitializer.d.ts.map +1 -1
  48. package/dist/cjs/endpoint/properties/EndpointInitializer.js +5 -0
  49. package/dist/cjs/endpoint/properties/EndpointInitializer.js.map +1 -1
  50. package/dist/cjs/endpoint/server/BehaviorServer.d.ts +21 -0
  51. package/dist/cjs/endpoint/server/BehaviorServer.d.ts.map +1 -0
  52. package/dist/cjs/endpoint/server/BehaviorServer.js +272 -0
  53. package/dist/cjs/endpoint/server/BehaviorServer.js.map +6 -0
  54. package/dist/{esm/endpoint → cjs/endpoint/server}/EndpointServer.d.ts +5 -6
  55. package/dist/cjs/endpoint/server/EndpointServer.d.ts.map +1 -0
  56. package/dist/cjs/endpoint/{EndpointServer.js → server/EndpointServer.js} +38 -14
  57. package/dist/cjs/endpoint/server/EndpointServer.js.map +6 -0
  58. package/dist/cjs/{node → endpoint}/server/ServerEndpointInitializer.d.ts +4 -4
  59. package/dist/cjs/endpoint/server/ServerEndpointInitializer.d.ts.map +1 -0
  60. package/dist/cjs/{node → endpoint}/server/ServerEndpointInitializer.js +7 -7
  61. package/dist/cjs/endpoint/server/ServerEndpointInitializer.js.map +6 -0
  62. package/dist/cjs/endpoint/server/index.d.ts +8 -0
  63. package/dist/cjs/endpoint/server/index.d.ts.map +1 -0
  64. package/dist/cjs/endpoint/server/index.js +25 -0
  65. package/dist/cjs/endpoint/server/index.js.map +6 -0
  66. package/dist/cjs/endpoint/type/MutableEndpoint.d.ts.map +1 -1
  67. package/dist/cjs/endpoint/type/MutableEndpoint.js +3 -0
  68. package/dist/cjs/endpoint/type/MutableEndpoint.js.map +1 -1
  69. package/dist/cjs/node/Node.d.ts +5 -0
  70. package/dist/cjs/node/Node.d.ts.map +1 -1
  71. package/dist/cjs/node/Node.js +17 -2
  72. package/dist/cjs/node/Node.js.map +1 -1
  73. package/dist/cjs/node/NodeLifecycle.d.ts +11 -1
  74. package/dist/cjs/node/NodeLifecycle.d.ts.map +1 -1
  75. package/dist/cjs/node/NodeLifecycle.js +14 -0
  76. package/dist/cjs/node/NodeLifecycle.js.map +1 -1
  77. package/dist/cjs/node/ServerNode.d.ts +3 -2
  78. package/dist/cjs/node/ServerNode.d.ts.map +1 -1
  79. package/dist/cjs/node/ServerNode.js +9 -9
  80. package/dist/cjs/node/ServerNode.js.map +1 -1
  81. package/dist/cjs/node/server/ServerEnvironment.js +1 -1
  82. package/dist/cjs/node/server/ServerEnvironment.js.map +1 -1
  83. package/dist/cjs/node/server/TransactionalInteractionServer.d.ts +2 -2
  84. package/dist/cjs/node/server/TransactionalInteractionServer.d.ts.map +1 -1
  85. package/dist/cjs/node/server/TransactionalInteractionServer.js +9 -4
  86. package/dist/cjs/node/server/TransactionalInteractionServer.js.map +2 -2
  87. package/dist/cjs/node/server/index.d.ts +0 -1
  88. package/dist/cjs/node/server/index.d.ts.map +1 -1
  89. package/dist/cjs/node/server/index.js +0 -1
  90. package/dist/cjs/node/server/index.js.map +1 -1
  91. package/dist/esm/behavior/internal/BehaviorBacking.d.ts +6 -1
  92. package/dist/esm/behavior/internal/BehaviorBacking.d.ts.map +1 -1
  93. package/dist/esm/behavior/internal/BehaviorBacking.js +2 -1
  94. package/dist/esm/behavior/internal/BehaviorBacking.js.map +1 -1
  95. package/dist/esm/behavior/internal/ClientBehaviorBacking.d.ts +2 -1
  96. package/dist/esm/behavior/internal/ClientBehaviorBacking.d.ts.map +1 -1
  97. package/dist/esm/behavior/internal/ClientBehaviorBacking.js +4 -0
  98. package/dist/esm/behavior/internal/ClientBehaviorBacking.js.map +1 -1
  99. package/dist/esm/behavior/internal/ServerBehaviorBacking.d.ts +2 -0
  100. package/dist/esm/behavior/internal/ServerBehaviorBacking.d.ts.map +1 -1
  101. package/dist/esm/behavior/internal/ServerBehaviorBacking.js +37 -0
  102. package/dist/esm/behavior/internal/ServerBehaviorBacking.js.map +1 -1
  103. package/dist/esm/behavior/state/transaction/Transaction.d.ts +18 -18
  104. package/dist/esm/behavior/system/events/EventsBehavior.d.ts +26 -0
  105. package/dist/esm/behavior/system/events/EventsBehavior.d.ts.map +1 -0
  106. package/dist/esm/behavior/system/events/EventsBehavior.js +54 -0
  107. package/dist/esm/behavior/system/events/EventsBehavior.js.map +6 -0
  108. package/dist/esm/behavior/system/events/index.d.ts +7 -0
  109. package/dist/esm/behavior/system/events/index.d.ts.map +1 -0
  110. package/dist/esm/behavior/system/events/index.js +7 -0
  111. package/dist/esm/behavior/system/events/index.js.map +6 -0
  112. package/dist/esm/behavior/system/network/ServerNetworkRuntime.d.ts.map +1 -1
  113. package/dist/esm/behavior/system/network/ServerNetworkRuntime.js +3 -0
  114. package/dist/esm/behavior/system/network/ServerNetworkRuntime.js.map +1 -1
  115. package/dist/esm/behaviors/administrator-commissioning/AdministratorCommissioningServer.d.ts +8 -0
  116. package/dist/esm/behaviors/administrator-commissioning/AdministratorCommissioningServer.d.ts.map +1 -1
  117. package/dist/esm/behaviors/administrator-commissioning/AdministratorCommissioningServer.js +12 -4
  118. package/dist/esm/behaviors/administrator-commissioning/AdministratorCommissioningServer.js.map +1 -1
  119. package/dist/esm/behaviors/general-diagnostics/GeneralDiagnosticsServer.d.ts +2 -4
  120. package/dist/esm/behaviors/general-diagnostics/GeneralDiagnosticsServer.d.ts.map +1 -1
  121. package/dist/esm/behaviors/general-diagnostics/GeneralDiagnosticsServer.js +6 -8
  122. package/dist/esm/behaviors/general-diagnostics/GeneralDiagnosticsServer.js.map +1 -1
  123. package/dist/esm/behaviors/operational-credentials/OperationalCredentialsServer.d.ts.map +1 -1
  124. package/dist/esm/behaviors/operational-credentials/OperationalCredentialsServer.js +23 -20
  125. package/dist/esm/behaviors/operational-credentials/OperationalCredentialsServer.js.map +1 -1
  126. package/dist/esm/endpoint/Agent.d.ts +1 -1
  127. package/dist/esm/endpoint/Agent.js +1 -1
  128. package/dist/esm/endpoint/index.d.ts +1 -1
  129. package/dist/esm/endpoint/index.d.ts.map +1 -1
  130. package/dist/esm/endpoint/index.js +1 -1
  131. package/dist/esm/endpoint/properties/Behaviors.d.ts +13 -0
  132. package/dist/esm/endpoint/properties/Behaviors.d.ts.map +1 -1
  133. package/dist/esm/endpoint/properties/Behaviors.js +38 -27
  134. package/dist/esm/endpoint/properties/Behaviors.js.map +2 -2
  135. package/dist/esm/endpoint/properties/EndpointInitializer.d.ts +8 -3
  136. package/dist/esm/endpoint/properties/EndpointInitializer.d.ts.map +1 -1
  137. package/dist/esm/endpoint/properties/EndpointInitializer.js +5 -0
  138. package/dist/esm/endpoint/properties/EndpointInitializer.js.map +1 -1
  139. package/dist/esm/endpoint/server/BehaviorServer.d.ts +21 -0
  140. package/dist/esm/endpoint/server/BehaviorServer.d.ts.map +1 -0
  141. package/dist/esm/endpoint/server/BehaviorServer.js +269 -0
  142. package/dist/esm/endpoint/server/BehaviorServer.js.map +6 -0
  143. package/dist/{cjs/endpoint → esm/endpoint/server}/EndpointServer.d.ts +5 -6
  144. package/dist/esm/endpoint/server/EndpointServer.d.ts.map +1 -0
  145. package/dist/esm/endpoint/{EndpointServer.js → server/EndpointServer.js} +38 -14
  146. package/dist/esm/endpoint/server/EndpointServer.js.map +6 -0
  147. package/dist/esm/{node → endpoint}/server/ServerEndpointInitializer.d.ts +4 -4
  148. package/dist/esm/endpoint/server/ServerEndpointInitializer.d.ts.map +1 -0
  149. package/dist/esm/{node → endpoint}/server/ServerEndpointInitializer.js +7 -7
  150. package/dist/esm/endpoint/server/ServerEndpointInitializer.js.map +6 -0
  151. package/dist/esm/endpoint/server/index.d.ts +8 -0
  152. package/dist/esm/endpoint/server/index.d.ts.map +1 -0
  153. package/dist/esm/endpoint/server/index.js +8 -0
  154. package/dist/esm/endpoint/server/index.js.map +6 -0
  155. package/dist/esm/endpoint/type/MutableEndpoint.d.ts.map +1 -1
  156. package/dist/esm/endpoint/type/MutableEndpoint.js +3 -0
  157. package/dist/esm/endpoint/type/MutableEndpoint.js.map +1 -1
  158. package/dist/esm/node/Node.d.ts +5 -0
  159. package/dist/esm/node/Node.d.ts.map +1 -1
  160. package/dist/esm/node/Node.js +17 -2
  161. package/dist/esm/node/Node.js.map +1 -1
  162. package/dist/esm/node/NodeLifecycle.d.ts +11 -1
  163. package/dist/esm/node/NodeLifecycle.d.ts.map +1 -1
  164. package/dist/esm/node/NodeLifecycle.js +15 -1
  165. package/dist/esm/node/NodeLifecycle.js.map +1 -1
  166. package/dist/esm/node/ServerNode.d.ts +3 -2
  167. package/dist/esm/node/ServerNode.d.ts.map +1 -1
  168. package/dist/esm/node/ServerNode.js +10 -10
  169. package/dist/esm/node/ServerNode.js.map +1 -1
  170. package/dist/esm/node/server/ServerEnvironment.js +1 -1
  171. package/dist/esm/node/server/ServerEnvironment.js.map +1 -1
  172. package/dist/esm/node/server/TransactionalInteractionServer.d.ts +2 -2
  173. package/dist/esm/node/server/TransactionalInteractionServer.d.ts.map +1 -1
  174. package/dist/esm/node/server/TransactionalInteractionServer.js +9 -4
  175. package/dist/esm/node/server/TransactionalInteractionServer.js.map +2 -2
  176. package/dist/esm/node/server/index.d.ts +0 -1
  177. package/dist/esm/node/server/index.d.ts.map +1 -1
  178. package/dist/esm/node/server/index.js +0 -1
  179. package/dist/esm/node/server/index.js.map +1 -1
  180. package/package.json +7 -7
  181. package/src/behavior/internal/BehaviorBacking.ts +9 -1
  182. package/src/behavior/internal/ClientBehaviorBacking.ts +6 -1
  183. package/src/behavior/internal/ServerBehaviorBacking.ts +51 -0
  184. package/src/behavior/system/events/EventsBehavior.ts +60 -0
  185. package/src/behavior/system/events/index.ts +7 -0
  186. package/src/behavior/system/network/ServerNetworkRuntime.ts +6 -0
  187. package/src/behaviors/administrator-commissioning/AdministratorCommissioningServer.ts +14 -4
  188. package/src/behaviors/general-diagnostics/GeneralDiagnosticsServer.ts +16 -9
  189. package/src/behaviors/operational-credentials/OperationalCredentialsServer.ts +26 -20
  190. package/src/endpoint/Agent.ts +1 -1
  191. package/src/endpoint/index.ts +1 -1
  192. package/src/endpoint/properties/Behaviors.ts +56 -28
  193. package/src/endpoint/properties/EndpointInitializer.ts +9 -3
  194. package/src/endpoint/server/BehaviorServer.ts +387 -0
  195. package/src/endpoint/{EndpointServer.ts → server/EndpointServer.ts} +50 -20
  196. package/src/{node → endpoint}/server/ServerEndpointInitializer.ts +7 -7
  197. package/src/endpoint/server/index.ts +8 -0
  198. package/src/endpoint/type/MutableEndpoint.ts +4 -0
  199. package/src/node/Node.ts +22 -4
  200. package/src/node/NodeLifecycle.ts +17 -1
  201. package/src/node/ServerNode.ts +11 -13
  202. package/src/node/server/ServerEnvironment.ts +1 -1
  203. package/src/node/server/TransactionalInteractionServer.ts +13 -7
  204. package/src/node/server/index.ts +0 -1
  205. package/dist/cjs/behavior/internal/ClusterServerBacking.d.ts +0 -36
  206. package/dist/cjs/behavior/internal/ClusterServerBacking.d.ts.map +0 -1
  207. package/dist/cjs/behavior/internal/ClusterServerBacking.js +0 -342
  208. package/dist/cjs/behavior/internal/ClusterServerBacking.js.map +0 -6
  209. package/dist/cjs/endpoint/EndpointServer.d.ts.map +0 -1
  210. package/dist/cjs/endpoint/EndpointServer.js.map +0 -6
  211. package/dist/cjs/node/server/ServerEndpointInitializer.d.ts.map +0 -1
  212. package/dist/cjs/node/server/ServerEndpointInitializer.js.map +0 -6
  213. package/dist/esm/behavior/internal/ClusterServerBacking.d.ts +0 -36
  214. package/dist/esm/behavior/internal/ClusterServerBacking.d.ts.map +0 -1
  215. package/dist/esm/behavior/internal/ClusterServerBacking.js +0 -330
  216. package/dist/esm/behavior/internal/ClusterServerBacking.js.map +0 -6
  217. package/dist/esm/endpoint/EndpointServer.d.ts.map +0 -1
  218. package/dist/esm/endpoint/EndpointServer.js.map +0 -6
  219. package/dist/esm/node/server/ServerEndpointInitializer.d.ts.map +0 -1
  220. package/dist/esm/node/server/ServerEndpointInitializer.js.map +0 -6
  221. package/src/behavior/internal/ClusterServerBacking.ts +0 -446
@@ -310,6 +310,8 @@ export class ServerNetworkRuntime extends NetworkRuntime {
310
310
  }
311
311
 
312
312
  protected override async stop() {
313
+ this.blockNewActivity();
314
+
313
315
  this.#observers.close();
314
316
 
315
317
  await this.owner.env.close(DeviceCommissioner);
@@ -320,6 +322,10 @@ export class ServerNetworkRuntime extends NetworkRuntime {
320
322
 
321
323
  await this.#interactionServer?.[Symbol.asyncDispose]();
322
324
  this.#interactionServer = undefined;
325
+
326
+ // DeviceAdvertiser does this but we do so here just in case DeviceAdvertiser did not initialize for some reason
327
+ await this.#mdnsBroadcaster?.close();
328
+ this.#mdnsBroadcaster = undefined;
323
329
  }
324
330
 
325
331
  protected override blockNewActivity() {
@@ -201,16 +201,16 @@ export class AdministratorCommissioningServer extends AdministratorCommissioning
201
201
  );
202
202
  }
203
203
 
204
- if (commissioningTimeout > MAXIMUM_COMMISSIONING_TIMEOUT_S) {
204
+ if (commissioningTimeout > this.internal.maximumCommissioningTimeoutS) {
205
205
  throw new StatusResponseError(
206
- `Commissioning timeout must not exceed ${MAXIMUM_COMMISSIONING_TIMEOUT_S} seconds.`,
206
+ `Commissioning timeout must not exceed ${this.internal.maximumCommissioningTimeoutS} seconds.`,
207
207
  StatusCode.InvalidCommand,
208
208
  );
209
209
  }
210
210
 
211
- if (commissioningTimeout < MINIMUM_COMMISSIONING_TIMEOUT_S) {
211
+ if (commissioningTimeout < this.internal.minimumCommissioningTimeoutS) {
212
212
  throw new StatusResponseError(
213
- `Commissioning timeout must not be lower then ${MINIMUM_COMMISSIONING_TIMEOUT_S} seconds.`,
213
+ `Commissioning timeout must not be lower then ${this.internal.minimumCommissioningTimeoutS} seconds.`,
214
214
  StatusCode.InvalidCommand,
215
215
  );
216
216
  }
@@ -279,6 +279,16 @@ export namespace AdministratorCommissioningServer {
279
279
  export class Internal {
280
280
  commissioningWindowTimeout?: Timer;
281
281
  stopMonitoringFabricForRemoval?: () => void;
282
+
283
+ /**
284
+ * Mandated by spec; should only be modified in testing.
285
+ */
286
+ minimumCommissioningTimeoutS = MINIMUM_COMMISSIONING_TIMEOUT_S;
287
+
288
+ /**
289
+ * Mandated by spec; should only be modified in testing.
290
+ */
291
+ maximumCommissioningTimeoutS = MAXIMUM_COMMISSIONING_TIMEOUT_S;
282
292
  }
283
293
 
284
294
  export class State extends AdministratorCommissioningBehavior.State {
@@ -8,6 +8,7 @@ import { Val } from "#behavior/state/Val.js";
8
8
  import { ValueSupervisor } from "#behavior/supervision/ValueSupervisor.js";
9
9
  import { NetworkServer } from "#behavior/system/network/NetworkServer.js";
10
10
  import { NetworkCommissioningServer } from "#behaviors/network-commissioning";
11
+ import { TimeSynchronizationBehavior } from "#behaviors/time-synchronization";
11
12
  import { GeneralDiagnostics } from "#clusters/general-diagnostics";
12
13
  import { Endpoint } from "#endpoint/Endpoint.js";
13
14
  import { Bytes, ImplementationError, ipv4ToBytes, Logger, Time, Timer } from "#general";
@@ -102,9 +103,20 @@ export class GeneralDiagnosticsServer extends Base {
102
103
 
103
104
  override timeSnapshot() {
104
105
  const time = Time.nowMs();
106
+
107
+ // TC_DGGEN_2_4.py fails us if we set this without TimeSynchronizationCluster support. Spec is worded poorly
108
+ // but my read of "SHALL only if" is "may not unless" and not "SHALL if and only if". But conforming to tests
109
+ // for now
110
+ const posixTimeMs =
111
+ this.agent.has(TimeSynchronizationBehavior) &&
112
+ this.agent.get(TimeSynchronizationBehavior).state.utcTime !== null
113
+ ? time
114
+ : null;
115
+
105
116
  return {
106
- systemTimeMs: time - this.internal.bootUpTime,
107
- posixTimeMs: time,
117
+ systemTimeMs: time - Time.startup.systemMs,
118
+
119
+ posixTimeMs,
108
120
  };
109
121
  }
110
122
 
@@ -280,7 +292,6 @@ export class GeneralDiagnosticsServer extends Base {
280
292
  );
281
293
 
282
294
  // Update the timestamps now that node is really online.
283
- this.internal.bootUpTime = Time.nowMs();
284
295
  this.internal.lastTotalOperationalHoursCounterUpdateTime = Time.nowMs();
285
296
 
286
297
  this.internal.lastTotalOperationalHoursTimer = Time.getPeriodicTimer(
@@ -368,9 +379,6 @@ export class GeneralDiagnosticsServer extends Base {
368
379
 
369
380
  export namespace GeneralDiagnosticsServer {
370
381
  export class Internal {
371
- /** Remember the bootUp time for the device. */
372
- bootUpTime: number = Time.nowMs();
373
-
374
382
  /** Last time the total operational hours counter was updated. */
375
383
  lastTotalOperationalHoursCounterUpdateTime: number = Time.nowMs();
376
384
 
@@ -388,12 +396,11 @@ export namespace GeneralDiagnosticsServer {
388
396
  [Val.properties](endpoint: Endpoint, _session: ValueSupervisor.Session) {
389
397
  return {
390
398
  /**
391
- * Dynamically calculate the upTime. This is ok because the attribute is not send out via subscriptions
399
+ * Dynamically calculate the upTime. This is ok because the attribute is not sent via subscriptions
392
400
  * anyway.
393
401
  */
394
402
  get upTime() {
395
- const bootUpTime = endpoint.behaviors.internalsOf(GeneralDiagnosticsServer).bootUpTime;
396
- return Math.round((Time.nowMs() - bootUpTime) / 1000);
403
+ return Math.round((Time.nowMs() - Time.startup.systemMs) / 1000);
397
404
  },
398
405
 
399
406
  /**
@@ -119,7 +119,7 @@ export class OperationalCredentialsServer extends OperationalCredentialsBehavior
119
119
 
120
120
  if (isForUpdateNoc && this.session.isPase) {
121
121
  throw new StatusResponseError(
122
- "csrRequest for UpdateNoc received on a PASE session.",
122
+ "csrRequest for UpdateNoc received on a PASE session",
123
123
  StatusCode.InvalidCommand,
124
124
  );
125
125
  }
@@ -128,7 +128,7 @@ export class OperationalCredentialsServer extends OperationalCredentialsBehavior
128
128
  const failsafeContext = commissioner.failsafeContext;
129
129
  if (failsafeContext.fabricIndex !== undefined) {
130
130
  throw new StatusResponseError(
131
- `csrRequest received after ${failsafeContext.forUpdateNoc ? "UpdateNOC" : "AddNOC"} already invoked.`,
131
+ `csrRequest received after ${failsafeContext.forUpdateNoc ? "UpdateNOC" : "AddNOC"} already invoked`,
132
132
  StatusCode.ConstraintError,
133
133
  );
134
134
  }
@@ -205,7 +205,7 @@ export class OperationalCredentialsServer extends OperationalCredentialsBehavior
205
205
 
206
206
  if (failsafeContext.fabricIndex !== undefined) {
207
207
  throw new StatusResponseError(
208
- `addNoc received after ${failsafeContext.forUpdateNoc ? "UpdateNOC" : "AddNOC"} already invoked.`,
208
+ `AddNoc is illegal after ${failsafeContext.forUpdateNoc ? "UpdateNOC" : "AddNOC"} in the same failsafe context`,
209
209
  StatusCode.ConstraintError,
210
210
  );
211
211
  }
@@ -213,20 +213,20 @@ export class OperationalCredentialsServer extends OperationalCredentialsBehavior
213
213
  if (!failsafeContext.hasRootCert) {
214
214
  return {
215
215
  statusCode: OperationalCredentials.NodeOperationalCertStatus.InvalidNoc,
216
- debugText: "Root certificate not found.",
216
+ debugText: "Root certificate not found",
217
217
  };
218
218
  }
219
219
 
220
220
  if (failsafeContext.csrSessionId !== this.session.id) {
221
221
  return {
222
222
  statusCode: OperationalCredentials.NodeOperationalCertStatus.MissingCsr,
223
- debugText: "CSR not found in failsafe context.",
223
+ debugText: "CSR not found in failsafe context",
224
224
  };
225
225
  }
226
226
 
227
227
  if (failsafeContext.forUpdateNoc) {
228
228
  throw new StatusResponseError(
229
- `addNoc received after csr request was invoked for UpdateNOC.`,
229
+ `AddNoc is illegal after CsrRequest for UpdateNOC in same failsafe context`,
230
230
  StatusCode.ConstraintError,
231
231
  );
232
232
  }
@@ -235,7 +235,7 @@ export class OperationalCredentialsServer extends OperationalCredentialsBehavior
235
235
  if (state.commissionedFabrics >= state.supportedFabrics) {
236
236
  return {
237
237
  statusCode: OperationalCredentials.NodeOperationalCertStatus.TableFull,
238
- debugText: `No more fabrics can be added because limit ${state.supportedFabrics} reached.`,
238
+ debugText: `No more fabrics can be added because limit ${state.supportedFabrics} reached`,
239
239
  };
240
240
  }
241
241
 
@@ -268,7 +268,7 @@ export class OperationalCredentialsServer extends OperationalCredentialsBehavior
268
268
 
269
269
  try {
270
270
  if (this.session.isPase) {
271
- logger.debug(`Add Fabric ${fabric.fabricIndex} to PASE session ${this.session.name}.`);
271
+ logger.debug(`Add Fabric ${fabric.fabricIndex} to PASE session ${this.session.name}`);
272
272
  this.session.addAssociatedFabric(fabric);
273
273
  }
274
274
 
@@ -277,7 +277,7 @@ export class OperationalCredentialsServer extends OperationalCredentialsBehavior
277
277
  const existingNocIndex = this.state.nocs.findIndex(n => n.fabricIndex === fabric.fabricIndex);
278
278
  if (existingFabricIndex !== -1 || existingNocIndex !== -1) {
279
279
  throw new MatterFlowError(
280
- `FabricIndex ${fabric.fabricIndex} already exists in state. This should not happen.`,
280
+ `FabricIndex ${fabric.fabricIndex} already exists in state. This should not happen`,
281
281
  );
282
282
  }
283
283
  } catch (e) {
@@ -308,32 +308,35 @@ export class OperationalCredentialsServer extends OperationalCredentialsBehavior
308
308
 
309
309
  if (timedOp.fabricIndex !== undefined) {
310
310
  throw new StatusResponseError(
311
- `updateNoc received after ${timedOp.forUpdateNoc ? "UpdateNOC" : "AddNOC"} already invoked.`,
311
+ `UpdateNoc is illegal after ${timedOp.forUpdateNoc ? "UpdateNOC" : "AddNOC"} in same failsafe context`,
312
312
  StatusCode.ConstraintError,
313
313
  );
314
314
  }
315
315
 
316
- if (timedOp.forUpdateNoc) {
316
+ if (timedOp.forUpdateNoc === false) {
317
317
  throw new StatusResponseError(
318
- `addNoc received after csr request was invoked for UpdateNOC.`,
318
+ "UpdateNoc is illegal after CsrRequest for AddNOC in same failsafe context",
319
319
  StatusCode.ConstraintError,
320
320
  );
321
321
  }
322
322
 
323
- if (timedOp.hasRootCert) {
323
+ if (timedOp.rootCertSet) {
324
324
  throw new StatusResponseError(
325
- "Trusted root certificate added in this session which is now allowed for UpdateNOC.",
325
+ "UpdateNoc is illegal after AddTrustedRootCertificate in same failsafe context",
326
326
  StatusCode.ConstraintError,
327
327
  );
328
328
  }
329
329
 
330
- if (!timedOp.forUpdateNoc) {
331
- throw new StatusResponseError("csrRequest not invoked for UpdateNOC.", StatusCode.ConstraintError);
330
+ if (timedOp.forUpdateNoc === undefined) {
331
+ throw new StatusResponseError(
332
+ "UpdateNoc is illegal before CsrRequest in same failsafe context",
333
+ StatusCode.ConstraintError,
334
+ );
332
335
  }
333
336
 
334
337
  if (this.session.associatedFabric.fabricIndex !== timedOp.associatedFabric?.fabricIndex) {
335
338
  throw new StatusResponseError(
336
- "Fabric of this session and the failsafe context do not match.",
339
+ "Fabric of this session and the failsafe context do not match",
337
340
  StatusCode.ConstraintError,
338
341
  );
339
342
  }
@@ -395,16 +398,19 @@ export class OperationalCredentialsServer extends OperationalCredentialsBehavior
395
398
  override addTrustedRootCertificate({ rootCaCertificate }: OperationalCredentials.AddTrustedRootCertificateRequest) {
396
399
  const failsafeContext = this.#failsafeContext;
397
400
 
398
- if (failsafeContext.hasRootCert) {
401
+ // TC_OPCREDS_3_4 fails if we don't allow set of the root certificate in updates, even though that's illegal and
402
+ // UpdateNoc will subsequently fail. So we can't just test for presence of root certificate; we actually need
403
+ // to test if it's been set
404
+ if (failsafeContext.rootCertSet) {
399
405
  throw new StatusResponseError(
400
- "Trusted root certificate already added in this FailSafe context.",
406
+ "Trusted root certificate already added in this FailSafe context",
401
407
  StatusCode.ConstraintError,
402
408
  );
403
409
  }
404
410
 
405
411
  if (failsafeContext.fabricIndex !== undefined) {
406
412
  throw new StatusResponseError(
407
- `Cannot add trusted root certificates after ${failsafeContext.forUpdateNoc ? "UpdateNOC" : "AddNOC"}.`,
413
+ `Cannot add trusted root certificates after ${failsafeContext.forUpdateNoc ? "UpdateNOC" : "AddNOC"}`,
408
414
  StatusCode.ConstraintError,
409
415
  );
410
416
  }
@@ -101,7 +101,7 @@ export class Agent {
101
101
  /**
102
102
  * Trigger initialization of a supported {@link Behavior.Type}.
103
103
  *
104
- * Functionally identical to {@link load} but has no return value and errors are logged rathjer than thrown.
104
+ * Functionally identical to {@link load} but has no return value and errors are logged rather than thrown.
105
105
  */
106
106
  activate(type: Behavior.Type) {
107
107
  this.#endpoint.behaviors.activate(type, this);
@@ -6,7 +6,7 @@
6
6
 
7
7
  export * from "./Agent.js";
8
8
  export * from "./Endpoint.js";
9
- export * from "./EndpointServer.js";
10
9
  export * from "./properties/index.js";
10
+ export * from "./server/index.js";
11
11
  export * from "./storage/index.js";
12
12
  export * from "./type/index.js";
@@ -6,7 +6,6 @@
6
6
 
7
7
  import { Behavior } from "#behavior/Behavior.js";
8
8
  import type { ClusterBehavior } from "#behavior/cluster/ClusterBehavior.js";
9
- import { ValidatedElements } from "#behavior/cluster/ValidatedElements.js";
10
9
  import { ActionContext } from "#behavior/context/ActionContext.js";
11
10
  import { ActionTracer } from "#behavior/context/ActionTracer.js";
12
11
  import { NodeActivity } from "#behavior/context/NodeActivity.js";
@@ -21,12 +20,10 @@ import {
21
20
  Diagnostic,
22
21
  EventEmitter,
23
22
  ImplementationError,
24
- InternalError,
25
23
  Lifecycle,
26
24
  Logger,
27
25
  MaybePromise,
28
26
  ReadOnlyError,
29
- UninitializedDependencyError,
30
27
  } from "#general";
31
28
  import { FeatureSet } from "#model";
32
29
  import { ClusterType } from "#types";
@@ -41,6 +38,12 @@ import type { SupportedBehaviors } from "./SupportedBehaviors.js";
41
38
 
42
39
  const logger = Logger.get("Behaviors");
43
40
 
41
+ export interface SupportedElements {
42
+ attributes: Set<string>;
43
+ commands: Set<string>;
44
+ events: Set<string>;
45
+ }
46
+
44
47
  /**
45
48
  * This class manages {@link Behavior} instances owned by a {@link Endpoint}.
46
49
  */
@@ -80,10 +83,9 @@ export class Behaviors {
80
83
  return result;
81
84
  }
82
85
 
86
+ const elements = this.elementsOf(type);
83
87
  const elementDiagnostic = Array<unknown>();
84
88
 
85
- const elements = new ValidatedElements(type as ClusterBehavior.Type);
86
-
87
89
  const features = new FeatureSet(cluster.supportedFeatures);
88
90
  if (features.size) {
89
91
  elementDiagnostic.push([Diagnostic.strong("features"), features]);
@@ -148,7 +150,7 @@ export class Behaviors {
148
150
  }
149
151
 
150
152
  // Initialization action. We initialize all behaviors in the same transaction
151
- const initializeBehaviors = (context: ActionContext) => {
153
+ const initializeBehaviors = (context: ActionContext): MaybePromise => {
152
154
  const agent = context.agentFor(this.#endpoint);
153
155
 
154
156
  // Activate behaviors
@@ -161,7 +163,7 @@ export class Behaviors {
161
163
  }
162
164
 
163
165
  // Wait for all behaviors to initialize
164
- return Construction.all(
166
+ let promise = Construction.all(
165
167
  {
166
168
  [Symbol.iterator]: () => {
167
169
  return Object.values(this.#backings)[Symbol.iterator]();
@@ -170,6 +172,16 @@ export class Behaviors {
170
172
 
171
173
  causes => new EndpointBehaviorsError(causes),
172
174
  );
175
+
176
+ // Notify other components that participate in initialization
177
+ const endpointInitializer = this.#endpoint.env.get(EndpointInitializer);
178
+ if (promise) {
179
+ promise = promise.then(() => endpointInitializer.behaviorsInitialized(agent));
180
+ } else {
181
+ promise = endpointInitializer.behaviorsInitialized(agent);
182
+ }
183
+
184
+ return promise;
173
185
  };
174
186
 
175
187
  // Initialize instrumentation
@@ -463,17 +475,36 @@ export class Behaviors {
463
475
  * does access to {@link Behavior.State} and {@link Behavior.Events}.
464
476
  */
465
477
  internalsOf<T extends Behavior.Type>(type: T) {
466
- let backing = this.#backings[type.id];
467
- if (!backing) {
468
- this.#activateLate(type);
469
- backing = this.#backings[type.id];
470
- if (backing === undefined) {
471
- throw new InternalError(`Behavior ${this.#endpoint}.${type.id} late activation did not create backing`);
472
- }
473
- }
478
+ const backing = this.#backingFor(type);
474
479
  return backing.getInternal() as InstanceType<T["Internal"]>;
475
480
  }
476
481
 
482
+ /**
483
+ * Obtain current data version of behavior.
484
+ */
485
+ versionOf(type: Behavior.Type) {
486
+ const backing = this.#backingFor(type);
487
+ return backing.datasource.version;
488
+ }
489
+
490
+ /**
491
+ * Access elements supported by a behavior.
492
+ */
493
+ elementsOf(type: Behavior.Type): SupportedElements {
494
+ if (!this.has(type)) {
495
+ throw new ImplementationError(`Endpoint ${this.#endpoint} does not support behavior ${type.id}`);
496
+ }
497
+
498
+ const elements = this.#backingFor(type).elements;
499
+ if (elements === undefined) {
500
+ throw new ImplementationError(
501
+ `Endpoint ${this.#endpoint} behavior ${type.id} elements accessed before initialization`,
502
+ );
503
+ }
504
+
505
+ return elements;
506
+ }
507
+
477
508
  #activateLate(type: Behavior.Type) {
478
509
  const result = OfflineContext.act("behavior-late-activation", this.#endpoint.env.get(NodeActivity), context =>
479
510
  this.activate(type, context.agentFor(this.#endpoint)),
@@ -495,29 +526,26 @@ export class Behaviors {
495
526
  }
496
527
 
497
528
  /**
498
- * Obtain a backing for an endpoint shortcut.
529
+ * Obtain a backing for a behavior.
499
530
  */
500
- #backingFor(container: string, type: Behavior.Type) {
531
+ #backingFor(type: Behavior.Type) {
532
+ // Crash if endpoint is not initialized
501
533
  if (this.#endpoint.construction.status !== Lifecycle.Status.Initializing) {
502
534
  this.#endpoint.construction.assert(this.#endpoint.toString(), `behavior ${type.id}`);
503
535
  }
504
536
 
537
+ // Obtain backing
505
538
  let backing = this.#backings[type.id];
539
+
540
+ // If backing is not already initialized, attempt late initialization
506
541
  if (!backing) {
507
- try {
508
- this.#activateLate(type);
509
- } catch (e) {
510
- logger.warn(`Cannot initialize ${container}.${type.id} until node is initialized: ${e}`);
511
- throw new UninitializedDependencyError(
512
- `${container}.${type.id}`,
513
- "is not available until node is initialized, you may await node.construction to avoid this error",
514
- );
515
- }
542
+ this.#activateLate(type);
516
543
  backing = this.#backings[type.id];
517
544
  if (backing === undefined) {
518
- throw new InternalError(`Behavior ${this.#endpoint}.${type.id} late activation did not create backing`);
545
+ throw new BehaviorInitializationError(`${this.#endpoint}.${type.id}`, "initialization failed");
519
546
  }
520
547
  }
548
+
521
549
  return backing;
522
550
  }
523
551
 
@@ -556,7 +584,7 @@ export class Behaviors {
556
584
  #augmentEndpoint(type: Behavior.Type) {
557
585
  Object.defineProperty(this.#endpoint.state, type.id, {
558
586
  get: () => {
559
- return this.#backingFor("state", type).stateView;
587
+ return this.#backingFor(type).stateView;
560
588
  },
561
589
 
562
590
  set() {
@@ -4,9 +4,10 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import { Behavior } from "#behavior/Behavior.js";
8
- import { BehaviorBacking } from "#behavior/internal/BehaviorBacking.js";
9
- import { Endpoint } from "../Endpoint.js";
7
+ import type { Behavior } from "#behavior/Behavior.js";
8
+ import type { BehaviorBacking } from "#behavior/internal/BehaviorBacking.js";
9
+ import type { Agent } from "#endpoint/Agent.js";
10
+ import type { Endpoint } from "../Endpoint.js";
10
11
 
11
12
  /**
12
13
  * Base class for {@link Endpoint} initialization services.
@@ -35,4 +36,9 @@ export abstract class EndpointInitializer {
35
36
  * @returns a new {@link BehaviorBacking}
36
37
  */
37
38
  abstract createBacking(endpoint: Endpoint, type: Behavior.Type): BehaviorBacking;
39
+
40
+ /**
41
+ * Invoked after behaviors are initialized but before the initialization transaction commits.
42
+ */
43
+ behaviorsInitialized(_agent: Agent) {}
38
44
  }