@matter/node 0.16.0-alpha.0-20250906-463912bd0 → 0.16.0-alpha.0-20250912-0d12bf718

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 (217) hide show
  1. package/dist/cjs/behavior/Behavior.d.ts +0 -18
  2. package/dist/cjs/behavior/Behavior.d.ts.map +1 -1
  3. package/dist/cjs/behavior/Behavior.js +0 -34
  4. package/dist/cjs/behavior/Behavior.js.map +1 -1
  5. package/dist/cjs/behavior/Transitions.js +2 -2
  6. package/dist/cjs/behavior/Transitions.js.map +1 -1
  7. package/dist/cjs/behavior/context/ActionContext.d.ts +4 -29
  8. package/dist/cjs/behavior/context/ActionContext.d.ts.map +1 -1
  9. package/dist/cjs/behavior/context/server/{OfflineContext.d.ts → LocalActorContext.d.ts} +16 -12
  10. package/dist/cjs/behavior/context/server/LocalActorContext.d.ts.map +1 -0
  11. package/dist/cjs/behavior/context/server/{OfflineContext.js → LocalActorContext.js} +10 -9
  12. package/dist/cjs/behavior/context/server/LocalActorContext.js.map +6 -0
  13. package/dist/cjs/behavior/context/server/RemoteActorContext.d.ts +80 -0
  14. package/dist/cjs/behavior/context/server/RemoteActorContext.d.ts.map +1 -0
  15. package/dist/cjs/behavior/context/server/{OnlineContext.js → RemoteActorContext.js} +15 -27
  16. package/dist/cjs/behavior/context/server/RemoteActorContext.js.map +6 -0
  17. package/dist/cjs/behavior/context/server/index.d.ts +2 -2
  18. package/dist/cjs/behavior/context/server/index.d.ts.map +1 -1
  19. package/dist/cjs/behavior/context/server/index.js +2 -2
  20. package/dist/cjs/behavior/context/server/index.js.map +1 -1
  21. package/dist/cjs/behavior/internal/Reactors.d.ts.map +1 -1
  22. package/dist/cjs/behavior/internal/Reactors.js +4 -3
  23. package/dist/cjs/behavior/internal/Reactors.js.map +1 -1
  24. package/dist/cjs/behavior/state/managed/Datasource.d.ts.map +1 -1
  25. package/dist/cjs/behavior/state/managed/Datasource.js +1 -6
  26. package/dist/cjs/behavior/state/managed/Datasource.js.map +1 -1
  27. package/dist/cjs/behavior/state/managed/values/ListManager.d.ts.map +1 -1
  28. package/dist/cjs/behavior/state/managed/values/ListManager.js +4 -4
  29. package/dist/cjs/behavior/state/managed/values/ListManager.js.map +1 -1
  30. package/dist/cjs/behavior/supervision/ValueSupervisor.d.ts +16 -9
  31. package/dist/cjs/behavior/supervision/ValueSupervisor.d.ts.map +1 -1
  32. package/dist/cjs/behavior/system/commissioning/CommissioningClient.d.ts +12 -1
  33. package/dist/cjs/behavior/system/commissioning/CommissioningClient.d.ts.map +1 -1
  34. package/dist/cjs/behavior/system/commissioning/CommissioningClient.js +1 -0
  35. package/dist/cjs/behavior/system/commissioning/CommissioningClient.js.map +1 -1
  36. package/dist/cjs/behavior/system/network/ClientNetworkRuntime.d.ts.map +1 -1
  37. package/dist/cjs/behavior/system/network/ClientNetworkRuntime.js +3 -1
  38. package/dist/cjs/behavior/system/network/ClientNetworkRuntime.js.map +1 -1
  39. package/dist/cjs/behavior/system/network/NetworkClient.d.ts +9 -0
  40. package/dist/cjs/behavior/system/network/NetworkClient.d.ts.map +1 -1
  41. package/dist/cjs/behavior/system/network/NetworkClient.js +20 -0
  42. package/dist/cjs/behavior/system/network/NetworkClient.js.map +1 -1
  43. package/dist/cjs/behaviors/access-control/AccessControlServer.d.ts.map +1 -1
  44. package/dist/cjs/behaviors/access-control/AccessControlServer.js +19 -15
  45. package/dist/cjs/behaviors/access-control/AccessControlServer.js.map +1 -1
  46. package/dist/cjs/behaviors/administrator-commissioning/AdministratorCommissioningServer.d.ts.map +1 -1
  47. package/dist/cjs/behaviors/administrator-commissioning/AdministratorCommissioningServer.js +5 -5
  48. package/dist/cjs/behaviors/administrator-commissioning/AdministratorCommissioningServer.js.map +1 -1
  49. package/dist/cjs/behaviors/general-commissioning/GeneralCommissioningServer.d.ts.map +1 -1
  50. package/dist/cjs/behaviors/general-commissioning/GeneralCommissioningServer.js +6 -6
  51. package/dist/cjs/behaviors/general-commissioning/GeneralCommissioningServer.js.map +1 -1
  52. package/dist/cjs/behaviors/general-diagnostics/GeneralDiagnosticsServer.d.ts.map +1 -1
  53. package/dist/cjs/behaviors/general-diagnostics/GeneralDiagnosticsServer.js +2 -4
  54. package/dist/cjs/behaviors/general-diagnostics/GeneralDiagnosticsServer.js.map +1 -1
  55. package/dist/cjs/behaviors/group-key-management/GroupKeyManagementServer.d.ts.map +1 -1
  56. package/dist/cjs/behaviors/group-key-management/GroupKeyManagementServer.js +9 -6
  57. package/dist/cjs/behaviors/group-key-management/GroupKeyManagementServer.js.map +1 -1
  58. package/dist/cjs/behaviors/groups/GroupsServer.d.ts.map +1 -1
  59. package/dist/cjs/behaviors/groups/GroupsServer.js +12 -9
  60. package/dist/cjs/behaviors/groups/GroupsServer.js.map +2 -2
  61. package/dist/cjs/behaviors/operational-credentials/OperationalCredentialsServer.d.ts.map +1 -1
  62. package/dist/cjs/behaviors/operational-credentials/OperationalCredentialsServer.js +16 -9
  63. package/dist/cjs/behaviors/operational-credentials/OperationalCredentialsServer.js.map +1 -1
  64. package/dist/cjs/behaviors/window-covering/WindowCoveringServer.js +1 -1
  65. package/dist/cjs/behaviors/window-covering/WindowCoveringServer.js.map +1 -1
  66. package/dist/cjs/endpoint/Agent.d.ts +14 -0
  67. package/dist/cjs/endpoint/Agent.d.ts.map +1 -1
  68. package/dist/cjs/endpoint/Agent.js +32 -0
  69. package/dist/cjs/endpoint/Agent.js.map +1 -1
  70. package/dist/cjs/endpoint/Endpoint.js +2 -2
  71. package/dist/cjs/endpoint/Endpoint.js.map +1 -1
  72. package/dist/cjs/endpoint/properties/Behaviors.js +4 -4
  73. package/dist/cjs/endpoint/properties/Behaviors.js.map +1 -1
  74. package/dist/cjs/endpoint/properties/Commands.js +2 -2
  75. package/dist/cjs/endpoint/properties/Commands.js.map +1 -1
  76. package/dist/cjs/node/server/IdentityService.js +2 -2
  77. package/dist/cjs/node/server/IdentityService.js.map +1 -1
  78. package/dist/cjs/node/server/InteractionServer.js.map +1 -1
  79. package/dist/cjs/node/server/OnlineServerInteraction.d.ts +6 -6
  80. package/dist/cjs/node/server/OnlineServerInteraction.d.ts.map +1 -1
  81. package/dist/cjs/node/server/OnlineServerInteraction.js +4 -4
  82. package/dist/cjs/node/server/OnlineServerInteraction.js.map +1 -1
  83. package/dist/cjs/node/server/ProtocolService.js +1 -1
  84. package/dist/cjs/node/server/ProtocolService.js.map +1 -1
  85. package/dist/cjs/node/server/ServerSubscription.d.ts +2 -2
  86. package/dist/cjs/node/server/ServerSubscription.d.ts.map +1 -1
  87. package/dist/cjs/node/server/ServerSubscription.js +3 -3
  88. package/dist/cjs/node/server/ServerSubscription.js.map +1 -1
  89. package/dist/esm/behavior/Behavior.d.ts +0 -18
  90. package/dist/esm/behavior/Behavior.d.ts.map +1 -1
  91. package/dist/esm/behavior/Behavior.js +0 -35
  92. package/dist/esm/behavior/Behavior.js.map +1 -1
  93. package/dist/esm/behavior/Transitions.js +2 -2
  94. package/dist/esm/behavior/Transitions.js.map +1 -1
  95. package/dist/esm/behavior/context/ActionContext.d.ts +4 -29
  96. package/dist/esm/behavior/context/ActionContext.d.ts.map +1 -1
  97. package/dist/esm/behavior/context/server/{OfflineContext.d.ts → LocalActorContext.d.ts} +16 -12
  98. package/dist/esm/behavior/context/server/LocalActorContext.d.ts.map +1 -0
  99. package/dist/esm/behavior/context/server/{OfflineContext.js → LocalActorContext.js} +7 -6
  100. package/dist/esm/behavior/context/server/LocalActorContext.js.map +6 -0
  101. package/dist/esm/behavior/context/server/RemoteActorContext.d.ts +80 -0
  102. package/dist/esm/behavior/context/server/RemoteActorContext.d.ts.map +1 -0
  103. package/dist/esm/behavior/context/server/{OnlineContext.js → RemoteActorContext.js} +14 -31
  104. package/dist/esm/behavior/context/server/RemoteActorContext.js.map +6 -0
  105. package/dist/esm/behavior/context/server/index.d.ts +2 -2
  106. package/dist/esm/behavior/context/server/index.d.ts.map +1 -1
  107. package/dist/esm/behavior/context/server/index.js +2 -2
  108. package/dist/esm/behavior/internal/Reactors.d.ts.map +1 -1
  109. package/dist/esm/behavior/internal/Reactors.js +4 -3
  110. package/dist/esm/behavior/internal/Reactors.js.map +1 -1
  111. package/dist/esm/behavior/state/managed/Datasource.d.ts.map +1 -1
  112. package/dist/esm/behavior/state/managed/Datasource.js +2 -7
  113. package/dist/esm/behavior/state/managed/Datasource.js.map +1 -1
  114. package/dist/esm/behavior/state/managed/values/ListManager.d.ts.map +1 -1
  115. package/dist/esm/behavior/state/managed/values/ListManager.js +13 -5
  116. package/dist/esm/behavior/state/managed/values/ListManager.js.map +1 -1
  117. package/dist/esm/behavior/supervision/ValueSupervisor.d.ts +16 -9
  118. package/dist/esm/behavior/supervision/ValueSupervisor.d.ts.map +1 -1
  119. package/dist/esm/behavior/system/commissioning/CommissioningClient.d.ts +12 -1
  120. package/dist/esm/behavior/system/commissioning/CommissioningClient.d.ts.map +1 -1
  121. package/dist/esm/behavior/system/commissioning/CommissioningClient.js +1 -0
  122. package/dist/esm/behavior/system/commissioning/CommissioningClient.js.map +1 -1
  123. package/dist/esm/behavior/system/network/ClientNetworkRuntime.d.ts.map +1 -1
  124. package/dist/esm/behavior/system/network/ClientNetworkRuntime.js +3 -1
  125. package/dist/esm/behavior/system/network/ClientNetworkRuntime.js.map +1 -1
  126. package/dist/esm/behavior/system/network/NetworkClient.d.ts +9 -0
  127. package/dist/esm/behavior/system/network/NetworkClient.d.ts.map +1 -1
  128. package/dist/esm/behavior/system/network/NetworkClient.js +20 -0
  129. package/dist/esm/behavior/system/network/NetworkClient.js.map +1 -1
  130. package/dist/esm/behaviors/access-control/AccessControlServer.d.ts.map +1 -1
  131. package/dist/esm/behaviors/access-control/AccessControlServer.js +21 -15
  132. package/dist/esm/behaviors/access-control/AccessControlServer.js.map +1 -1
  133. package/dist/esm/behaviors/administrator-commissioning/AdministratorCommissioningServer.d.ts.map +1 -1
  134. package/dist/esm/behaviors/administrator-commissioning/AdministratorCommissioningServer.js +13 -6
  135. package/dist/esm/behaviors/administrator-commissioning/AdministratorCommissioningServer.js.map +1 -1
  136. package/dist/esm/behaviors/general-commissioning/GeneralCommissioningServer.d.ts.map +1 -1
  137. package/dist/esm/behaviors/general-commissioning/GeneralCommissioningServer.js +15 -7
  138. package/dist/esm/behaviors/general-commissioning/GeneralCommissioningServer.js.map +1 -1
  139. package/dist/esm/behaviors/general-diagnostics/GeneralDiagnosticsServer.d.ts.map +1 -1
  140. package/dist/esm/behaviors/general-diagnostics/GeneralDiagnosticsServer.js +3 -5
  141. package/dist/esm/behaviors/general-diagnostics/GeneralDiagnosticsServer.js.map +1 -1
  142. package/dist/esm/behaviors/group-key-management/GroupKeyManagementServer.d.ts.map +1 -1
  143. package/dist/esm/behaviors/group-key-management/GroupKeyManagementServer.js +10 -7
  144. package/dist/esm/behaviors/group-key-management/GroupKeyManagementServer.js.map +1 -1
  145. package/dist/esm/behaviors/groups/GroupsServer.d.ts.map +1 -1
  146. package/dist/esm/behaviors/groups/GroupsServer.js +12 -9
  147. package/dist/esm/behaviors/groups/GroupsServer.js.map +2 -2
  148. package/dist/esm/behaviors/operational-credentials/OperationalCredentialsServer.d.ts.map +1 -1
  149. package/dist/esm/behaviors/operational-credentials/OperationalCredentialsServer.js +17 -9
  150. package/dist/esm/behaviors/operational-credentials/OperationalCredentialsServer.js.map +1 -1
  151. package/dist/esm/behaviors/window-covering/WindowCoveringServer.js +1 -1
  152. package/dist/esm/behaviors/window-covering/WindowCoveringServer.js.map +1 -1
  153. package/dist/esm/endpoint/Agent.d.ts +14 -0
  154. package/dist/esm/endpoint/Agent.d.ts.map +1 -1
  155. package/dist/esm/endpoint/Agent.js +32 -0
  156. package/dist/esm/endpoint/Agent.js.map +1 -1
  157. package/dist/esm/endpoint/Endpoint.js +2 -2
  158. package/dist/esm/endpoint/Endpoint.js.map +1 -1
  159. package/dist/esm/endpoint/properties/Behaviors.js +4 -4
  160. package/dist/esm/endpoint/properties/Behaviors.js.map +1 -1
  161. package/dist/esm/endpoint/properties/Commands.js +2 -2
  162. package/dist/esm/endpoint/properties/Commands.js.map +1 -1
  163. package/dist/esm/node/server/IdentityService.js +2 -2
  164. package/dist/esm/node/server/IdentityService.js.map +1 -1
  165. package/dist/esm/node/server/InteractionServer.js.map +1 -1
  166. package/dist/esm/node/server/OnlineServerInteraction.d.ts +6 -6
  167. package/dist/esm/node/server/OnlineServerInteraction.d.ts.map +1 -1
  168. package/dist/esm/node/server/OnlineServerInteraction.js +4 -4
  169. package/dist/esm/node/server/OnlineServerInteraction.js.map +1 -1
  170. package/dist/esm/node/server/ProtocolService.js +2 -2
  171. package/dist/esm/node/server/ProtocolService.js.map +1 -1
  172. package/dist/esm/node/server/ServerSubscription.d.ts +2 -2
  173. package/dist/esm/node/server/ServerSubscription.d.ts.map +1 -1
  174. package/dist/esm/node/server/ServerSubscription.js +3 -3
  175. package/dist/esm/node/server/ServerSubscription.js.map +1 -1
  176. package/package.json +7 -7
  177. package/src/behavior/Behavior.ts +0 -41
  178. package/src/behavior/Transitions.ts +2 -2
  179. package/src/behavior/context/ActionContext.ts +4 -35
  180. package/src/behavior/context/server/{OfflineContext.ts → LocalActorContext.ts} +17 -14
  181. package/src/behavior/context/server/{OnlineContext.ts → RemoteActorContext.ts} +65 -52
  182. package/src/behavior/context/server/index.ts +2 -2
  183. package/src/behavior/internal/Reactors.ts +5 -4
  184. package/src/behavior/state/managed/Datasource.ts +3 -9
  185. package/src/behavior/state/managed/values/ListManager.ts +14 -11
  186. package/src/behavior/supervision/ValueSupervisor.ts +18 -10
  187. package/src/behavior/system/commissioning/CommissioningClient.ts +15 -0
  188. package/src/behavior/system/network/ClientNetworkRuntime.ts +5 -1
  189. package/src/behavior/system/network/NetworkClient.ts +23 -0
  190. package/src/behaviors/access-control/AccessControlServer.ts +25 -20
  191. package/src/behaviors/administrator-commissioning/AdministratorCommissioningServer.ts +14 -6
  192. package/src/behaviors/general-commissioning/GeneralCommissioningServer.ts +15 -8
  193. package/src/behaviors/general-diagnostics/GeneralDiagnosticsServer.ts +3 -5
  194. package/src/behaviors/group-key-management/GroupKeyManagementServer.ts +13 -7
  195. package/src/behaviors/groups/GroupsServer.ts +16 -11
  196. package/src/behaviors/operational-credentials/OperationalCredentialsServer.ts +21 -9
  197. package/src/behaviors/window-covering/WindowCoveringServer.ts +1 -1
  198. package/src/endpoint/Agent.ts +34 -0
  199. package/src/endpoint/Endpoint.ts +2 -2
  200. package/src/endpoint/properties/Behaviors.ts +4 -4
  201. package/src/endpoint/properties/Commands.ts +2 -2
  202. package/src/node/ClientNode.ts +1 -1
  203. package/src/node/server/IdentityService.ts +2 -2
  204. package/src/node/server/InteractionServer.ts +2 -2
  205. package/src/node/server/OnlineServerInteraction.ts +9 -9
  206. package/src/node/server/ProtocolService.ts +2 -2
  207. package/src/node/server/ServerSubscription.ts +5 -5
  208. package/dist/cjs/behavior/context/server/OfflineContext.d.ts.map +0 -1
  209. package/dist/cjs/behavior/context/server/OfflineContext.js.map +0 -6
  210. package/dist/cjs/behavior/context/server/OnlineContext.d.ts +0 -61
  211. package/dist/cjs/behavior/context/server/OnlineContext.d.ts.map +0 -1
  212. package/dist/cjs/behavior/context/server/OnlineContext.js.map +0 -6
  213. package/dist/esm/behavior/context/server/OfflineContext.d.ts.map +0 -1
  214. package/dist/esm/behavior/context/server/OfflineContext.js.map +0 -6
  215. package/dist/esm/behavior/context/server/OnlineContext.d.ts +0 -61
  216. package/dist/esm/behavior/context/server/OnlineContext.d.ts.map +0 -1
  217. package/dist/esm/behavior/context/server/OnlineContext.js.map +0 -6
@@ -9,14 +9,12 @@ import {
9
9
  AsyncObservable,
10
10
  EventEmitter,
11
11
  GeneratedClass,
12
- ImplementationError,
13
12
  MaybePromise,
14
13
  NotImplementedError,
15
14
  Observable,
16
15
  Transaction,
17
16
  } from "#general";
18
17
  import { Schema } from "#model";
19
- import { SecureSession } from "#protocol";
20
18
  import type { ClusterType } from "#types";
21
19
  import { Reactor } from "./Reactor.js";
22
20
  import type { BehaviorBacking } from "./internal/BehaviorBacking.js";
@@ -106,45 +104,6 @@ export abstract class Behavior {
106
104
  return this.endpoint.env;
107
105
  }
108
106
 
109
- /**
110
- * The session in which the behavior has been invoked.
111
- */
112
- get session() {
113
- const session = this.#agent.context.session;
114
- if (session === undefined) {
115
- throw new ImplementationError(`Illegal operation outside session context`);
116
- }
117
-
118
- // TODO - would a behavior ever need access to an insecure session?
119
- SecureSession.assert(session);
120
-
121
- return session;
122
- }
123
-
124
- /**
125
- * Execute logic with elevated privileges.
126
- *
127
- * The provided function executes with privileges escalated to offline mode. This is not commonly necessary.
128
- *
129
- * Elevated logic effectively ignores ACLs so should be used with care.
130
- *
131
- * Note that interactions with the behavior will remain elevated until the synchronous completion of this call.
132
- * You should only elevate privileges for synchronous logic.
133
- *
134
- * @param fn the elevated logic
135
- */
136
- asAdmin(fn: () => void) {
137
- const context = this.context;
138
-
139
- const offline = context.offline;
140
- try {
141
- context.offline = true;
142
- fn();
143
- } finally {
144
- context.offline = offline;
145
- }
146
- }
147
-
148
107
  /**
149
108
  * Access the behavior's state.
150
109
  */
@@ -23,7 +23,7 @@ import {
23
23
  } from "#general";
24
24
  import { Behavior } from "./Behavior.js";
25
25
  import { ClusterEvents } from "./cluster/ClusterEvents.js";
26
- import { OfflineContext } from "./context/server/OfflineContext.js";
26
+ import { LocalActorContext } from "./context/server/LocalActorContext.js";
27
27
  import { Events } from "./Events.js";
28
28
  import { BehaviorBacking } from "./internal/BehaviorBacking.js";
29
29
 
@@ -227,7 +227,7 @@ export class Transitions<B extends Behavior> {
227
227
 
228
228
  const previousRemainingTime = this.#prevPublishedRemainingTime;
229
229
  this.#prevPublishedRemainingTime = newRemainingTime;
230
- this.#config.remainingTimeEvent?.emit(newRemainingTime, previousRemainingTime, OfflineContext.ReadOnly);
230
+ this.#config.remainingTimeEvent?.emit(newRemainingTime, previousRemainingTime, LocalActorContext.ReadOnly);
231
231
  }
232
232
 
233
233
  /**
@@ -7,13 +7,8 @@
7
7
  import type { Agent } from "#endpoint/Agent.js";
8
8
  import type { Endpoint } from "#endpoint/Endpoint.js";
9
9
  import type { AccessLevel } from "#model";
10
- import type { Message, SecureSession } from "#protocol";
11
- import { MessageExchange } from "#protocol";
12
- import { Priority } from "#types";
13
- import type { ValueSupervisor } from "../supervision/ValueSupervisor.js";
14
- import { NodeActivity } from "./NodeActivity.js";
15
- import type { OfflineContext } from "./server/OfflineContext.js";
16
- import type { OnlineContext } from "./server/OnlineContext.js";
10
+ import type { LocalActorContext } from "./server/LocalActorContext.js";
11
+ import type { RemoteActorContext } from "./server/RemoteActorContext.js";
17
12
 
18
13
  /**
19
14
  * Provides contextual information for Matter actions such as accessing attributes or invoking commands.
@@ -21,7 +16,7 @@ import type { OnlineContext } from "./server/OnlineContext.js";
21
16
  * Matter.js provides an "online" ActionContext for you when responding to network requests. You can also use
22
17
  * "offline" agents to invoke cluster APIs {@link Endpoint} without an active user session.
23
18
  *
24
- * See {@link OnlineContext} and {@link OfflineContext} for details of these two types of interaction.
19
+ * See {@link RemoteActorContext} and {@link LocalActorContext} for details of these two types of interaction.
25
20
  *
26
21
  * Context includes:
27
22
  *
@@ -35,30 +30,4 @@ import type { OnlineContext } from "./server/OnlineContext.js";
35
30
  *
36
31
  * For the formal definition of an "action" see {@link MatterSpecification.v12.Core} § 8.2.4
37
32
  */
38
- export interface ActionContext extends ValueSupervisor.Session {
39
- /**
40
- * The Matter session in which an interaction occurs.
41
- */
42
- session?: SecureSession;
43
-
44
- /**
45
- * The Matter exchange in which an interaction occurs.
46
- */
47
- exchange?: MessageExchange;
48
-
49
- /**
50
- * The wire message that initiated invocation.
51
- */
52
- message?: Message;
53
-
54
- /**
55
- * Activity tracking information. If present, activity frames are inserted at key points for diagnostic
56
- * purposes.
57
- */
58
- activity?: NodeActivity.Activity;
59
-
60
- /**
61
- * The priority of actions in this context.
62
- */
63
- priority?: Priority;
64
- }
33
+ export type ActionContext = LocalActorContext | RemoteActorContext;
@@ -4,26 +4,29 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
+ import { ValueSupervisor } from "#behavior/supervision/ValueSupervisor.js";
7
8
  import type { Agent } from "#endpoint/Agent.js";
8
9
  import { Diagnostic, InternalError, MaybePromise, Transaction } from "#general";
9
10
  import { AccessLevel } from "#model";
10
11
  import { AccessControl } from "#protocol";
11
- import type { ActionContext } from "../ActionContext.js";
12
12
  import { Contextual } from "../Contextual.js";
13
13
  import type { NodeActivity } from "../NodeActivity.js";
14
-
15
14
  export let nextInternalId = 1;
16
15
 
17
- let ReadOnly: ActionContext | undefined;
16
+ let ReadOnly: LocalActorContext | undefined;
17
+
18
+ export interface LocalActorContext extends ValueSupervisor.LocalActorSession {}
18
19
 
19
20
  /**
20
- * {@link OfflineContext.act} gives you access to the {@link Agent} API outside of user interaction.
21
+ * The context for operations triggered locally, either for in-process node implementations or remote nodes that are
22
+ * peers of a local node.
21
23
  *
22
- * You can also use {@link OfflineContext.ReadOnly} for read-only {@link Agent} access.
24
+ * You can also use {@link LocalActorContext.ReadOnly} for read-only {@link Agent} access.
23
25
  */
24
- export const OfflineContext = {
26
+ export const LocalActorContext = {
25
27
  /**
26
- * Operate in offline context. Interactions with private Matter.js APIs happen in an offline context.
28
+ * Operate on behalf of a local actor. This is the context for operations on nodes initiated locally, without
29
+ * authentication.
27
30
  *
28
31
  * {@link act} provides an {@link ActionContext} you can use to access agents for a {@link Endpoint}.
29
32
  * State changes and change events occur once {@link actor} returns.
@@ -36,8 +39,8 @@ export const OfflineContext = {
36
39
  */
37
40
  act<T>(
38
41
  purpose: string,
39
- actor: (context: ActionContext) => MaybePromise<T>,
40
- options?: OfflineContext.Options,
42
+ actor: (context: LocalActorContext) => MaybePromise<T>,
43
+ options?: LocalActorContext.Options,
41
44
  ): MaybePromise<T> {
42
45
  const context = this.open(purpose, options);
43
46
 
@@ -57,7 +60,7 @@ export const OfflineContext = {
57
60
  * This context operates with a {@link Transaction} created via {@link Transaction.open} and the same rules
58
61
  * apply for lifecycle management using {@link Transaction.Finalization}.
59
62
  */
60
- open(purpose: string, options?: OfflineContext.Options): ActionContext & Transaction.Finalization {
63
+ open(purpose: string, options?: LocalActorContext.Options): LocalActorContext & Transaction.Finalization {
61
64
  const id = nextInternalId;
62
65
  nextInternalId = (nextInternalId + 1) % 65535;
63
66
  const via = Diagnostic.via(`${purpose}#${id.toString(16)}`);
@@ -115,7 +118,7 @@ export const OfflineContext = {
115
118
  },
116
119
 
117
120
  /**
118
- * Normally you need to use {@link OfflineContext.act} to work with behaviors, and you can only interact with the
121
+ * Normally you need to use {@link LocalActorContext.act} to work with behaviors, and you can only interact with the
119
122
  * behaviors in the actor function. This {@link ActionContext} allows you to create offline agents that remain
120
123
  * functional for the lifespan of the node.
121
124
  *
@@ -123,7 +126,7 @@ export const OfflineContext = {
123
126
  */
124
127
  get ReadOnly() {
125
128
  if (ReadOnly === undefined) {
126
- ReadOnly = OfflineContext.open("read-only", { isolation: "ro" });
129
+ ReadOnly = LocalActorContext.open("read-only", { isolation: "ro" });
127
130
  }
128
131
  return ReadOnly;
129
132
  },
@@ -131,9 +134,9 @@ export const OfflineContext = {
131
134
  [Symbol.toStringTag]: "OfflineContext",
132
135
  };
133
136
 
134
- export namespace OfflineContext {
137
+ export namespace LocalActorContext {
135
138
  /**
136
- * {@link OfflineContext} configuration options.
139
+ * {@link LocalActorContext} configuration options.
137
140
  */
138
141
  export interface Options {
139
142
  command?: boolean;
@@ -4,57 +4,73 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import { AsyncObservable, Diagnostic, ImplementationError, InternalError, MaybePromise, Transaction } from "#general";
7
+ import { ValueSupervisor } from "#behavior/supervision/ValueSupervisor.js";
8
+ import { AsyncObservable, Diagnostic, InternalError, MaybePromise, Transaction } from "#general";
8
9
  import { AccessLevel } from "#model";
9
10
  import type { Node } from "#node/Node.js";
10
11
  import type { Message, NodeProtocol } from "#protocol";
11
- import {
12
- AccessControl,
13
- AclEndpointContext,
14
- FabricAccessControl,
15
- MessageExchange,
16
- SecureSession,
17
- Subject,
18
- } from "#protocol";
19
- import { FabricIndex, NodeId } from "#types";
20
- import { ActionContext } from "../ActionContext.js";
12
+ import { AccessControl, AclEndpointContext, FabricAccessControl, MessageExchange, SecureSession } from "#protocol";
13
+ import { FabricIndex, Priority } from "#types";
21
14
  import { Contextual } from "../Contextual.js";
22
15
  import { NodeActivity } from "../NodeActivity.js";
23
16
 
17
+ export interface RemoteActorContext extends ValueSupervisor.RemoteActorSession {
18
+ /**
19
+ * Override for {@link ValueSupervisor.RemoteActorSession} to specialize the context.
20
+ */
21
+ interactionComplete?: AsyncObservable<[context?: RemoteActorContext]>;
22
+
23
+ /**
24
+ * The Matter session in which an interaction occurs.
25
+ */
26
+ session: SecureSession;
27
+
28
+ /**
29
+ * The Matter exchange in which an interaction occurs.
30
+ */
31
+ exchange: MessageExchange;
32
+
33
+ /**
34
+ * The wire message that initiated invocation.
35
+ */
36
+ message?: Message;
37
+
38
+ /**
39
+ * Activity tracking information. If present, activity frames are inserted at key points for diagnostic
40
+ * purposes.
41
+ */
42
+ activity?: NodeActivity.Activity;
43
+
44
+ /**
45
+ * The priority of actions in this context.
46
+ */
47
+ priority?: Priority;
48
+ }
49
+
24
50
  /**
25
51
  * Caches completion events per exchange. Uses if multiple OnlineContext instances are created for an exchange.
26
52
  * Entries will be cleaned up when the exchange is closed.
27
53
  */
28
- const exchangeCompleteEvents = new WeakMap<MessageExchange, AsyncObservable<[session?: ActionContext | undefined]>>();
54
+ const exchangeCompleteEvents = new WeakMap<
55
+ MessageExchange,
56
+ AsyncObservable<[session?: RemoteActorContext | undefined]>
57
+ >();
29
58
 
30
59
  /**
31
- * Operate in online context. Public Matter API interactions happen in online context.
60
+ * The context for operations triggered by an authenticated peer. Public Matter interactions use this context.
32
61
  */
33
- export function OnlineContext(options: OnlineContext.Options) {
34
- let fabric: FabricIndex | undefined;
35
- let subject: Subject;
62
+ export function RemoteActorContext(options: RemoteActorContext.Options) {
36
63
  let nodeProtocol: NodeProtocol | undefined;
37
64
  let accessLevelCache: Map<AccessControl.Location, number[]> | undefined;
38
- let aclManager: FabricAccessControl;
39
65
 
40
66
  const { exchange, message } = options;
41
- const session = exchange?.session;
42
-
43
- if (session) {
44
- SecureSession.assert(session);
45
- fabric = session.fabric?.fabricIndex;
46
- subject = session.subjectFor(message);
47
- // Without a fabric, we assume default PASE based access controls and use a fresh FabricAccessControlManager instance
48
- aclManager = session?.fabric?.acl ?? new FabricAccessControl();
49
- } else {
50
- fabric = options.fabric;
51
- if (options.subject !== undefined) {
52
- subject = Subject.Node({ id: options.subject });
53
- } else {
54
- throw new ImplementationError("OnlineContext requires an authorized subject");
55
- }
56
- aclManager = options.aclManager ?? new FabricAccessControl();
57
- }
67
+ const session = exchange.session;
68
+
69
+ SecureSession.assert(session);
70
+ const fabric = session.fabric;
71
+ const subject = session.subjectFor(message);
72
+ // Without a fabric, we assume default PASE based access controls and use a fresh FabricAccessControlManager instance
73
+ const accessControl = fabric?.accessControl ?? new FabricAccessControl();
58
74
 
59
75
  // If we have subjects, the first is the main one, used for diagnostics
60
76
  const via = Diagnostic.via(
@@ -63,11 +79,11 @@ export function OnlineContext(options: OnlineContext.Options) {
63
79
 
64
80
  return {
65
81
  /**
66
- * Run an actor with a read/write context.
82
+ * Operate on behalf of a remote actor.
67
83
  *
68
84
  * If the actor changes state, this may return a promise even if {@link actor} does not return a promise.
69
85
  */
70
- act<T>(actor: (context: ActionContext) => MaybePromise<T>): MaybePromise<T> {
86
+ act<T>(actor: (context: RemoteActorContext) => MaybePromise<T>): MaybePromise<T> {
71
87
  const context = this.open();
72
88
 
73
89
  let result;
@@ -86,7 +102,7 @@ export function OnlineContext(options: OnlineContext.Options) {
86
102
  * This context operates with a {@link Transaction} created via {@link Transaction.open} and the same rules
87
103
  * apply for lifecycle management using {@link Transaction.Finalization}.
88
104
  */
89
- open(): ActionContext & Transaction.Finalization {
105
+ open(): RemoteActorContext & Transaction.Finalization {
90
106
  let close;
91
107
  let tx;
92
108
  try {
@@ -101,7 +117,7 @@ export function OnlineContext(options: OnlineContext.Options) {
101
117
  return createContext(tx, {
102
118
  resolve: tx.resolve.bind(tx),
103
119
  reject: tx.reject.bind(tx),
104
- }) as ActionContext & Transaction.Finalization;
120
+ });
105
121
  },
106
122
 
107
123
  /**
@@ -115,7 +131,7 @@ export function OnlineContext(options: OnlineContext.Options) {
115
131
 
116
132
  return createContext(Transaction.open(via, "snapshot"), {
117
133
  [Symbol.dispose]: close,
118
- }) as OnlineContext.ReadOnly;
134
+ }) as RemoteActorContext.ReadOnly;
119
135
  },
120
136
 
121
137
  [Symbol.toStringTag]: "OnlineContext",
@@ -142,11 +158,11 @@ export function OnlineContext(options: OnlineContext.Options) {
142
158
  /**
143
159
  * Initialization stage two - create context object after obtaining transaction
144
160
  */
145
- function createContext(transaction: Transaction, methods: {}) {
161
+ function createContext<T extends {}>(transaction: Transaction, methods: T) {
146
162
  if (session) {
147
163
  SecureSession.assert(session);
148
164
  }
149
- let interactionComplete: AsyncObservable<[session?: ActionContext | undefined]> | undefined;
165
+ let interactionComplete: AsyncObservable<[session?: RemoteActorContext | undefined]> | undefined;
150
166
  if (exchange !== undefined) {
151
167
  interactionComplete = exchangeCompleteEvents.get(exchange);
152
168
  if (interactionComplete === undefined) {
@@ -163,13 +179,13 @@ export function OnlineContext(options: OnlineContext.Options) {
163
179
  };
164
180
  exchange.closing.on(notifyInteractionComplete);
165
181
  }
166
- const context: ActionContext = {
182
+ const context: RemoteActorContext & T = {
167
183
  ...options,
168
184
  session,
169
185
  exchange,
170
186
  subject,
171
187
 
172
- fabric,
188
+ fabric: fabric?.fabricIndex ?? FabricIndex.NO_FABRIC,
173
189
  transaction,
174
190
 
175
191
  interactionComplete,
@@ -194,7 +210,7 @@ export function OnlineContext(options: OnlineContext.Options) {
194
210
  throw new InternalError("OnlineContext initialized without node");
195
211
  }
196
212
 
197
- const accessLevels = aclManager.accessLevelsFor(context, location, aclEndpointContextFor(location));
213
+ const accessLevels = accessControl.accessLevelsFor(context, location, aclEndpointContextFor(location));
198
214
 
199
215
  if (accessLevelCache === undefined) {
200
216
  accessLevelCache = new Map();
@@ -206,7 +222,7 @@ export function OnlineContext(options: OnlineContext.Options) {
206
222
  : AccessControl.Authority.Unauthorized;
207
223
  },
208
224
 
209
- get [Contextual.context](): ActionContext {
225
+ get [Contextual.context](): RemoteActorContext {
210
226
  return this;
211
227
  },
212
228
  };
@@ -247,21 +263,18 @@ export function OnlineContext(options: OnlineContext.Options) {
247
263
  }
248
264
  }
249
265
 
250
- export namespace OnlineContext {
266
+ export namespace RemoteActorContext {
251
267
  export type Options = {
252
268
  node: Node;
269
+ exchange: MessageExchange;
253
270
  activity?: NodeActivity.Activity;
254
271
  command?: boolean;
255
272
  timed?: boolean;
256
273
  fabricFiltered?: boolean;
257
274
  message?: Message;
258
- aclManager?: FabricAccessControl;
259
- } & (
260
- | { exchange: MessageExchange; fabric?: undefined; subject?: undefined }
261
- | { exchange?: undefined; fabric: FabricIndex; subject: NodeId }
262
- );
275
+ };
263
276
 
264
- export interface ReadOnly extends ActionContext {
277
+ export interface ReadOnly extends RemoteActorContext {
265
278
  [Symbol.dispose](): void;
266
279
  }
267
280
  }
@@ -4,5 +4,5 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- export * from "./OfflineContext.js";
8
- export * from "./OnlineContext.js";
7
+ export * from "./LocalActorContext.js";
8
+ export * from "./RemoteActorContext.js";
@@ -7,11 +7,12 @@
7
7
  import type { Endpoint } from "#endpoint/Endpoint.js";
8
8
  import type { Observable, Observer, Transaction } from "#general";
9
9
  import { asError, ImplementationError, InternalError, Logger, MatterAggregateError, MaybePromise } from "#general";
10
+ import { hasRemoteActor } from "#protocol";
10
11
  import type { Reactor } from "../Reactor.js";
11
- import type { ActionContext } from "../context/ActionContext.js";
12
+ import { ActionContext } from "../context/ActionContext.js";
12
13
  import { Contextual } from "../context/Contextual.js";
13
14
  import { NodeActivity } from "../context/NodeActivity.js";
14
- import { OfflineContext } from "../context/server/OfflineContext.js";
15
+ import { LocalActorContext } from "../context/server/LocalActorContext.js";
15
16
  import type { BehaviorBacking } from "./BehaviorBacking.js";
16
17
 
17
18
  const logger = Logger.get("Reactors");
@@ -301,7 +302,7 @@ class ReactorBacking<T extends any[], R> {
301
302
  }
302
303
 
303
304
  // Otherwise run in independent context and errors do not interfere with emitter
304
- const command = originalContext?.command;
305
+ const command = hasRemoteActor(originalContext) && originalContext.command;
305
306
  try {
306
307
  const reactor = (context: ActionContext) => {
307
308
  return this.#reactWithContext(context, this.#owner.backing, args);
@@ -311,7 +312,7 @@ class ReactorBacking<T extends any[], R> {
311
312
  // construction and destruction
312
313
  //
313
314
  // Also, do not inject activity here. No reason to have both the reactor and the context registered
314
- let result: MaybePromise<Awaited<R> | undefined> = OfflineContext.act(this.toString(), reactor, {
315
+ let result: MaybePromise<Awaited<R> | undefined> = LocalActorContext.act(this.toString(), reactor, {
315
316
  command,
316
317
  });
317
318
 
@@ -16,9 +16,8 @@ import {
16
16
  Observable,
17
17
  Transaction,
18
18
  } from "#general";
19
- import { AccessLevel } from "#model";
20
19
  import type { Val } from "#protocol";
21
- import { AccessControl, ExpiredReferenceError } from "#protocol";
20
+ import { AccessControl, ExpiredReferenceError, hasRemoteActor } from "#protocol";
22
21
  import { RootSupervisor } from "../../supervision/RootSupervisor.js";
23
22
  import { ValueSupervisor } from "../../supervision/ValueSupervisor.js";
24
23
  import { StateType } from "../StateType.js";
@@ -125,12 +124,6 @@ export function Datasource<const T extends StateType = StateType>(options: Datas
125
124
  get view() {
126
125
  if (!readOnlyView) {
127
126
  const session: ValueSupervisor.Session = {
128
- offline: true,
129
- authorityAt(desiredAccessLevel: AccessLevel) {
130
- return desiredAccessLevel === AccessLevel.View
131
- ? AccessControl.Authority.Granted
132
- : AccessControl.Authority.Unauthorized;
133
- },
134
127
  transaction: viewTx,
135
128
  };
136
129
  readOnlyView = createReference(this, internals, session).managed as InstanceType<T>;
@@ -281,7 +274,7 @@ interface Internals extends Datasource.Options {
281
274
  primaryKey: "name" | "id";
282
275
  sessions?: Map<ValueSupervisor.Session, SessionContext>;
283
276
  featuresKey?: string;
284
- interactionObserver(session?: AccessControl.Session): MaybePromise<void>;
277
+ interactionObserver(session?: ValueSupervisor.Session): MaybePromise<void>;
285
278
  events: Datasource.InternalEvents;
286
279
  changedEventFor(key: string): undefined | Datasource.Events[any];
287
280
  persistentFields: Set<string>;
@@ -635,6 +628,7 @@ function createReference(resource: Transaction.Resource, internals: Internals, s
635
628
  transaction.beginSync();
636
629
 
637
630
  if (
631
+ hasRemoteActor(session) &&
638
632
  !session.interactionStarted &&
639
633
  session.interactionComplete &&
640
634
  !session.interactionComplete.isObservedBy(internals.interactionObserver)
@@ -7,7 +7,16 @@
7
7
  import { isObject, serialize } from "#general";
8
8
  import type { Schema } from "#model";
9
9
  import { Access, DataModelPath, ValueModel } from "#model";
10
- import { AccessControl, ExpiredReferenceError, ReadError, SchemaImplementationError, Val, WriteError } from "#protocol";
10
+ import {
11
+ AccessControl,
12
+ ExpiredReferenceError,
13
+ hasLocalActor,
14
+ hasRemoteActor,
15
+ ReadError,
16
+ SchemaImplementationError,
17
+ Val,
18
+ WriteError,
19
+ } from "#protocol";
11
20
  import { StatusCode } from "#types";
12
21
  import type { RootSupervisor } from "../../../supervision/RootSupervisor.js";
13
22
  import type { ValueSupervisor } from "../../../supervision/ValueSupervisor.js";
@@ -206,7 +215,7 @@ function createProxy(config: ListConfig, reference: Val.Reference<Val.List>, ses
206
215
  }
207
216
 
208
217
  // If there's no fabric index or it's a match, consider "in scope"
209
- if (session.offline || !entry.fabricIndex || entry.fabricIndex === session.fabric) {
218
+ if (hasLocalActor(session) || !entry.fabricIndex || entry.fabricIndex === session.fabric) {
210
219
  if (nextPos === index) {
211
220
  // Found our target
212
221
  return i;
@@ -229,7 +238,7 @@ function createProxy(config: ListConfig, reference: Val.Reference<Val.List>, ses
229
238
  throw new WriteError(reference.location, `Index ${index} would leave gaps in fabric-filtered list`);
230
239
  }
231
240
 
232
- if (session.fabricFiltered || config.fabricSensitive) {
241
+ if (hasRemoteActor(session) && (session.fabricFiltered || config.fabricSensitive)) {
233
242
  const nextReadEntry = readEntry;
234
243
 
235
244
  hasEntry = (index: number) => {
@@ -262,10 +271,7 @@ function createProxy(config: ListConfig, reference: Val.Reference<Val.List>, ses
262
271
  let length = 0;
263
272
  for (let i = 0; i < readVal().length; i++) {
264
273
  const entry = readVal()[i] as undefined | { fabricIndex?: number };
265
- if (
266
- isObject(entry) &&
267
- (session.offline || !entry.fabricIndex || entry.fabricIndex === session.fabric)
268
- ) {
274
+ if (isObject(entry) && (!entry.fabricIndex || entry.fabricIndex === session.fabric)) {
269
275
  length++;
270
276
  }
271
277
  }
@@ -278,10 +284,7 @@ function createProxy(config: ListConfig, reference: Val.Reference<Val.List>, ses
278
284
  reference.change(() => {
279
285
  for (let i = formerLength - 1; i >= length; i--) {
280
286
  const entry = writeVal()[mapScopedToActual(i, true)] as undefined | { fabricIndex?: number };
281
- if (
282
- isObject(entry) &&
283
- (session.offline || !entry.fabricIndex || entry.fabricIndex === session.fabric)
284
- ) {
287
+ if (isObject(entry) && (!entry.fabricIndex || entry.fabricIndex === session.fabric)) {
285
288
  writeVal().splice(mapScopedToActual(i, false), 1);
286
289
  } else if (entry !== undefined) {
287
290
  throw new WriteError(
@@ -4,7 +4,6 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import { ActionContext } from "#behavior/context/ActionContext.js";
8
7
  import type { AsyncObservable, Transaction } from "#general";
9
8
  import { DataModelPath, Schema } from "#model";
10
9
  import type { AccessControl, Val } from "#protocol";
@@ -67,9 +66,9 @@ export interface ValueSupervisor {
67
66
 
68
67
  export namespace ValueSupervisor {
69
68
  /**
70
- * Session information required for value management.
69
+ * {@link Session} values that control supervision.
71
70
  */
72
- export interface Session extends AccessControl.Session {
71
+ export interface SupervisionSettings {
73
72
  /**
74
73
  * The transaction used for isolating state changes associated with this session.
75
74
  */
@@ -82,22 +81,31 @@ export namespace ValueSupervisor {
82
81
  acceptInvalid?: boolean;
83
82
 
84
83
  /**
85
- * If present the session is associated with an online interaction. Emits when the interaction ends.
84
+ * If true, structs initialize without named properties which are more expensive to install. This is useful
85
+ * when implementing the Matter protocol where ID is the only value necessary.
86
86
  */
87
- interactionComplete?: AsyncObservable<[session?: ActionContext]>;
87
+ protocol?: boolean;
88
+ }
88
89
 
90
+ /**
91
+ * {@link Session} information that enforces stricter controls based on an authenticated remote subject.
92
+ */
93
+ export interface RemoteActorSession extends AccessControl.RemoteActorSession, SupervisionSettings {
89
94
  /**
90
- * Set to true when the interaction has started and the interactionBegin event was emitted for this session
95
+ * If present the session is associated with an online interaction. Emits when the interaction ends.
91
96
  */
92
- interactionStarted?: boolean;
97
+ interactionComplete?: AsyncObservable<[session?: RemoteActorSession]>;
93
98
 
94
99
  /**
95
- * If true, structs initialize without named properties which are more expensive to install. This is useful
96
- * when implementing the Matter protocol where ID is the only value necessary.
100
+ * Set to true when the interaction has started and the interactionBegin event was emitted for this session
97
101
  */
98
- protocol?: boolean;
102
+ interactionStarted?: boolean;
99
103
  }
100
104
 
105
+ export interface LocalActorSession extends AccessControl.LocalActorSession, SupervisionSettings {}
106
+
107
+ export type Session = LocalActorSession | RemoteActorSession;
108
+
101
109
  export type Validate = (value: Val, session: Session, location: ValidationLocation) => void;
102
110
 
103
111
  export type Manage = (reference: Val.Reference, session: Session) => Val;