@matter/node 0.16.0-alpha.0-20251003-dc6d5523d → 0.16.0-alpha.0-20251004-92135c7df
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.
- package/dist/cjs/behavior/internal/BehaviorBacking.d.ts +4 -0
- package/dist/cjs/behavior/internal/BehaviorBacking.d.ts.map +1 -1
- package/dist/cjs/behavior/internal/BehaviorBacking.js +6 -0
- package/dist/cjs/behavior/internal/BehaviorBacking.js.map +1 -1
- package/dist/cjs/behavior/system/commissioning/CommissioningClient.d.ts.map +1 -1
- package/dist/cjs/behavior/system/commissioning/CommissioningClient.js +15 -0
- package/dist/cjs/behavior/system/commissioning/CommissioningClient.js.map +1 -1
- package/dist/cjs/endpoint/Endpoint.d.ts +12 -1
- package/dist/cjs/endpoint/Endpoint.d.ts.map +1 -1
- package/dist/cjs/endpoint/Endpoint.js +25 -15
- package/dist/cjs/endpoint/Endpoint.js.map +1 -1
- package/dist/cjs/endpoint/properties/Behaviors.d.ts +5 -1
- package/dist/cjs/endpoint/properties/Behaviors.d.ts.map +1 -1
- package/dist/cjs/endpoint/properties/Behaviors.js +7 -0
- package/dist/cjs/endpoint/properties/Behaviors.js.map +1 -1
- package/dist/cjs/node/ClientNode.d.ts +2 -0
- package/dist/cjs/node/ClientNode.d.ts.map +1 -1
- package/dist/cjs/node/ClientNode.js +14 -0
- package/dist/cjs/node/ClientNode.js.map +1 -1
- package/dist/cjs/storage/client/ClientEndpointStore.d.ts +4 -0
- package/dist/cjs/storage/client/ClientEndpointStore.d.ts.map +1 -1
- package/dist/cjs/storage/client/ClientEndpointStore.js +6 -0
- package/dist/cjs/storage/client/ClientEndpointStore.js.map +1 -1
- package/dist/esm/behavior/internal/BehaviorBacking.d.ts +4 -0
- package/dist/esm/behavior/internal/BehaviorBacking.d.ts.map +1 -1
- package/dist/esm/behavior/internal/BehaviorBacking.js +6 -0
- package/dist/esm/behavior/internal/BehaviorBacking.js.map +1 -1
- package/dist/esm/behavior/system/commissioning/CommissioningClient.d.ts.map +1 -1
- package/dist/esm/behavior/system/commissioning/CommissioningClient.js +19 -1
- package/dist/esm/behavior/system/commissioning/CommissioningClient.js.map +1 -1
- package/dist/esm/endpoint/Endpoint.d.ts +12 -1
- package/dist/esm/endpoint/Endpoint.d.ts.map +1 -1
- package/dist/esm/endpoint/Endpoint.js +25 -15
- package/dist/esm/endpoint/Endpoint.js.map +1 -1
- package/dist/esm/endpoint/properties/Behaviors.d.ts +5 -1
- package/dist/esm/endpoint/properties/Behaviors.d.ts.map +1 -1
- package/dist/esm/endpoint/properties/Behaviors.js +7 -0
- package/dist/esm/endpoint/properties/Behaviors.js.map +1 -1
- package/dist/esm/node/ClientNode.d.ts +2 -0
- package/dist/esm/node/ClientNode.d.ts.map +1 -1
- package/dist/esm/node/ClientNode.js +16 -2
- package/dist/esm/node/ClientNode.js.map +1 -1
- package/dist/esm/storage/client/ClientEndpointStore.d.ts +4 -0
- package/dist/esm/storage/client/ClientEndpointStore.d.ts.map +1 -1
- package/dist/esm/storage/client/ClientEndpointStore.js +6 -0
- package/dist/esm/storage/client/ClientEndpointStore.js.map +1 -1
- package/package.json +7 -7
- package/src/behavior/internal/BehaviorBacking.ts +7 -0
- package/src/behavior/system/commissioning/CommissioningClient.ts +22 -0
- package/src/endpoint/Endpoint.ts +36 -13
- package/src/endpoint/properties/Behaviors.ts +9 -0
- package/src/node/ClientNode.ts +28 -2
- package/src/storage/client/ClientEndpointStore.ts +7 -0
|
@@ -8,8 +8,10 @@ import { Behavior } from "#behavior/Behavior.js";
|
|
|
8
8
|
import { Events as BaseEvents } from "#behavior/Events.js";
|
|
9
9
|
import { OperationalCredentialsClient } from "#behaviors/operational-credentials";
|
|
10
10
|
import {
|
|
11
|
+
Diagnostic,
|
|
11
12
|
Duration,
|
|
12
13
|
ImplementationError,
|
|
14
|
+
Logger,
|
|
13
15
|
NotImplementedError,
|
|
14
16
|
Observable,
|
|
15
17
|
ServerAddress,
|
|
@@ -45,6 +47,8 @@ import { ControllerBehavior } from "../controller/ControllerBehavior.js";
|
|
|
45
47
|
import { NetworkClient } from "../network/NetworkClient.js";
|
|
46
48
|
import { RemoteDescriptor } from "./RemoteDescriptor.js";
|
|
47
49
|
|
|
50
|
+
const logger = Logger.get("CommissioningClient");
|
|
51
|
+
|
|
48
52
|
/**
|
|
49
53
|
* Client functionality related to commissioning.
|
|
50
54
|
*
|
|
@@ -155,6 +159,13 @@ export class CommissioningClient extends Behavior {
|
|
|
155
159
|
network.state.startupSubscription = opts.startupSubscription;
|
|
156
160
|
network.state.caseAuthenticatedTags = opts.caseAuthenticatedTags;
|
|
157
161
|
|
|
162
|
+
logger.notice(
|
|
163
|
+
"Commissioned",
|
|
164
|
+
Diagnostic.strong(this.endpoint.id),
|
|
165
|
+
"as",
|
|
166
|
+
Diagnostic.strong(this.endpoint.identity),
|
|
167
|
+
);
|
|
168
|
+
|
|
158
169
|
node.lifecycle.commissioned.emit(this.context);
|
|
159
170
|
|
|
160
171
|
await node.start();
|
|
@@ -177,11 +188,22 @@ export class CommissioningClient extends Behavior {
|
|
|
177
188
|
throw new ImplementationError("Cannot decommission node that is not commissioned");
|
|
178
189
|
}
|
|
179
190
|
|
|
191
|
+
const formerAddress = PeerAddress(peerAddress).toString();
|
|
192
|
+
|
|
180
193
|
const opcreds = this.agent.get(OperationalCredentialsClient);
|
|
181
194
|
|
|
182
195
|
await opcreds.removeFabric({ fabricIndex: opcreds.state.currentFabricIndex });
|
|
183
196
|
|
|
184
197
|
this.state.peerAddress = undefined;
|
|
198
|
+
|
|
199
|
+
await this.context.transaction.commit();
|
|
200
|
+
|
|
201
|
+
logger.info(
|
|
202
|
+
"Decommissioned",
|
|
203
|
+
Diagnostic.strong(this.endpoint.id),
|
|
204
|
+
"formerly",
|
|
205
|
+
Diagnostic.strong(formerAddress),
|
|
206
|
+
);
|
|
185
207
|
}
|
|
186
208
|
|
|
187
209
|
/**
|
package/src/endpoint/Endpoint.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { DataModelPath } from "#model";
|
|
|
24
24
|
import type { Node } from "#node/Node.js";
|
|
25
25
|
import { IdentityService } from "#node/server/IdentityService.js";
|
|
26
26
|
import { ProtocolService } from "#node/server/ProtocolService.js";
|
|
27
|
+
import { Val } from "#protocol";
|
|
27
28
|
import { EndpointNumber } from "#types";
|
|
28
29
|
import { RootEndpoint } from "../endpoints/root.js";
|
|
29
30
|
import { Agent } from "./Agent.js";
|
|
@@ -170,14 +171,28 @@ export class Endpoint<T extends EndpointType = EndpointType.Empty> {
|
|
|
170
171
|
return this.#stateView;
|
|
171
172
|
}
|
|
172
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Current state for a specific behavior ID.
|
|
176
|
+
*/
|
|
177
|
+
stateOf(type: string): Immutable<Val.Struct>;
|
|
178
|
+
|
|
173
179
|
/**
|
|
174
180
|
* Current state for a specific behavior.
|
|
175
181
|
*/
|
|
176
|
-
stateOf<T extends Behavior.Type>(type: T)
|
|
177
|
-
|
|
178
|
-
|
|
182
|
+
stateOf<T extends Behavior.Type>(type: T): Immutable<Behavior.StateOf<T>>;
|
|
183
|
+
|
|
184
|
+
stateOf(type: Behavior.Type | string) {
|
|
185
|
+
if (typeof type === "string") {
|
|
186
|
+
if (!(type in this.#stateView)) {
|
|
187
|
+
throw new ImplementationError(`Behavior ${type} is not supported by ${this}`);
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
if (!this.behaviors.has(type)) {
|
|
191
|
+
throw new ImplementationError(`Behavior ${type.id} is not supported by ${this}`);
|
|
192
|
+
}
|
|
193
|
+
type = type.id;
|
|
179
194
|
}
|
|
180
|
-
return (this.#stateView as Record<string, unknown>)[type
|
|
195
|
+
return (this.#stateView as Record<string, unknown>)[type];
|
|
181
196
|
}
|
|
182
197
|
|
|
183
198
|
/**
|
|
@@ -719,20 +734,28 @@ export class Endpoint<T extends EndpointType = EndpointType.Empty> {
|
|
|
719
734
|
* Path identifying the endpoint in the Matter data model.
|
|
720
735
|
*/
|
|
721
736
|
get path(): DataModelPath {
|
|
722
|
-
|
|
737
|
+
if (this.#owner) {
|
|
738
|
+
return this.#owner.path.at(this.identity, this.#type.name);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
return DataModelPath(this.identity, this.type?.name);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Diagnostic identity.
|
|
746
|
+
*
|
|
747
|
+
* This is an unqualified path segment.
|
|
748
|
+
*/
|
|
749
|
+
get identity() {
|
|
723
750
|
if (this.lifecycle?.hasId) {
|
|
724
|
-
|
|
725
|
-
} else if (this.lifecycle?.hasNumber) {
|
|
726
|
-
ident = this.number;
|
|
727
|
-
} else {
|
|
728
|
-
ident = "?";
|
|
751
|
+
return this.id;
|
|
729
752
|
}
|
|
730
753
|
|
|
731
|
-
if (this
|
|
732
|
-
return this
|
|
754
|
+
if (this.lifecycle?.hasNumber) {
|
|
755
|
+
return this.number;
|
|
733
756
|
}
|
|
734
757
|
|
|
735
|
-
return
|
|
758
|
+
return "?";
|
|
736
759
|
}
|
|
737
760
|
|
|
738
761
|
/**
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
describeList,
|
|
20
20
|
Diagnostic,
|
|
21
21
|
EventEmitter,
|
|
22
|
+
Immutable,
|
|
22
23
|
ImplementationError,
|
|
23
24
|
Lifecycle,
|
|
24
25
|
Logger,
|
|
@@ -557,6 +558,14 @@ export class Behaviors {
|
|
|
557
558
|
return elements;
|
|
558
559
|
}
|
|
559
560
|
|
|
561
|
+
/**
|
|
562
|
+
* Access the state view of a behavior if loaded.
|
|
563
|
+
*/
|
|
564
|
+
maybeStateOf(behaviorId: string): Immutable<Val.Struct> | undefined {
|
|
565
|
+
const backing = this.#backings[behaviorId];
|
|
566
|
+
return backing?.maybeDatasource?.view;
|
|
567
|
+
}
|
|
568
|
+
|
|
560
569
|
[Symbol.iterator]() {
|
|
561
570
|
return Object.values(this.#supported)[Symbol.iterator]();
|
|
562
571
|
}
|
package/src/node/ClientNode.ts
CHANGED
|
@@ -11,8 +11,8 @@ import { NetworkClient } from "#behavior/system/network/NetworkClient.js";
|
|
|
11
11
|
import { NetworkRuntime } from "#behavior/system/network/NetworkRuntime.js";
|
|
12
12
|
import { Agent } from "#endpoint/Agent.js";
|
|
13
13
|
import { EndpointInitializer } from "#endpoint/properties/EndpointInitializer.js";
|
|
14
|
-
import { Identity, Lifecycle, MaybePromise } from "#general";
|
|
15
|
-
import { Interactable, OccurrenceManager } from "#protocol";
|
|
14
|
+
import { Diagnostic, Identity, Lifecycle, Logger, MaybePromise } from "#general";
|
|
15
|
+
import { Interactable, OccurrenceManager, PeerAddress } from "#protocol";
|
|
16
16
|
import { ClientNodeStore } from "#storage/client/ClientNodeStore.js";
|
|
17
17
|
import { RemoteWriter } from "#storage/client/RemoteWriter.js";
|
|
18
18
|
import { ServerNodeStore } from "#storage/server/ServerNodeStore.js";
|
|
@@ -22,6 +22,8 @@ import { ClientNodeInteraction } from "./client/ClientNodeInteraction.js";
|
|
|
22
22
|
import { Node } from "./Node.js";
|
|
23
23
|
import type { ServerNode } from "./ServerNode.js";
|
|
24
24
|
|
|
25
|
+
const logger = Logger.get("ClientNode");
|
|
26
|
+
|
|
25
27
|
/**
|
|
26
28
|
* A remote Matter {@link Node}.
|
|
27
29
|
*
|
|
@@ -188,6 +190,30 @@ export class ClientNode extends Node<ClientNode.RootEndpoint> {
|
|
|
188
190
|
|
|
189
191
|
return this.#interaction;
|
|
190
192
|
}
|
|
193
|
+
|
|
194
|
+
override get identity() {
|
|
195
|
+
// If commissioned, use the peer address for logging purposes
|
|
196
|
+
let address = this.behaviors.maybeStateOf("commissioning")?.peerAddress as PeerAddress | undefined;
|
|
197
|
+
|
|
198
|
+
// During early initialization commissioning state may not be loaded, so check directly in storage too
|
|
199
|
+
if (!address) {
|
|
200
|
+
address = this.env.get(ClientNodeStore).storeForEndpoint(this).peerAddress as PeerAddress | undefined;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Use the peer address as a log identifier if present
|
|
204
|
+
if (address) {
|
|
205
|
+
return PeerAddress(address).toString();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Fall back to persistence ID
|
|
209
|
+
return super.identity;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
protected override statusUpdate(message: string): void {
|
|
213
|
+
// Log client node status updates as info rather than notice and change the log facility to make clear it's a
|
|
214
|
+
// client
|
|
215
|
+
logger.info(Diagnostic.strong(this.toString()), message);
|
|
216
|
+
}
|
|
191
217
|
}
|
|
192
218
|
|
|
193
219
|
export namespace ClientNode {
|
|
@@ -26,6 +26,13 @@ export class ClientEndpointStore extends EndpointStore {
|
|
|
26
26
|
return this.#number;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Shortcut to persisted peer address so we can use in logging prior to full initialization.
|
|
31
|
+
*/
|
|
32
|
+
get peerAddress() {
|
|
33
|
+
return this.initialValues.get("commissioning")?.["peerAddress"];
|
|
34
|
+
}
|
|
35
|
+
|
|
29
36
|
participantFor(transaction: Transaction) {
|
|
30
37
|
let participant = transaction.getParticipant(this.#owner);
|
|
31
38
|
if (participant === undefined) {
|