@matter/protocol 0.12.4-alpha.0-20250211-56b2c53a0 → 0.12.4-alpha.0-20250213-1187f81eb

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 (236) hide show
  1. package/dist/cjs/action/Interactable.d.ts +36 -0
  2. package/dist/cjs/action/Interactable.d.ts.map +1 -0
  3. package/dist/cjs/action/Interactable.js +22 -0
  4. package/dist/cjs/action/Interactable.js.map +6 -0
  5. package/dist/cjs/action/Val.d.ts +94 -0
  6. package/dist/cjs/action/Val.d.ts.map +1 -0
  7. package/dist/cjs/action/Val.js +33 -0
  8. package/dist/cjs/action/Val.js.map +6 -0
  9. package/dist/cjs/action/errors.d.ts +69 -0
  10. package/dist/cjs/action/errors.d.ts.map +1 -0
  11. package/dist/cjs/action/errors.js +108 -0
  12. package/dist/cjs/action/errors.js.map +6 -0
  13. package/dist/cjs/action/index.d.ts +13 -0
  14. package/dist/cjs/action/index.d.ts.map +1 -0
  15. package/dist/cjs/action/index.js +30 -0
  16. package/dist/cjs/action/index.js.map +6 -0
  17. package/dist/cjs/action/protocols.d.ts +118 -0
  18. package/dist/cjs/action/protocols.d.ts.map +1 -0
  19. package/dist/cjs/action/protocols.js +22 -0
  20. package/dist/cjs/action/protocols.js.map +6 -0
  21. package/dist/cjs/action/request/Invoke.d.ts +35 -0
  22. package/dist/cjs/action/request/Invoke.d.ts.map +1 -0
  23. package/dist/cjs/action/request/Invoke.js +80 -0
  24. package/dist/cjs/action/request/Invoke.js.map +6 -0
  25. package/dist/cjs/action/request/MalformedRequestError.d.ts +14 -0
  26. package/dist/cjs/action/request/MalformedRequestError.d.ts.map +1 -0
  27. package/dist/cjs/action/request/MalformedRequestError.js +32 -0
  28. package/dist/cjs/action/request/MalformedRequestError.js.map +6 -0
  29. package/dist/cjs/action/request/Read.d.ts +141 -0
  30. package/dist/cjs/action/request/Read.d.ts.map +1 -0
  31. package/dist/cjs/action/request/Read.js +173 -0
  32. package/dist/cjs/action/request/Read.js.map +6 -0
  33. package/dist/cjs/action/request/Specifier.d.ts +82 -0
  34. package/dist/cjs/action/request/Specifier.d.ts.map +1 -0
  35. package/dist/cjs/action/request/Specifier.js +88 -0
  36. package/dist/cjs/action/request/Specifier.js.map +6 -0
  37. package/dist/cjs/action/request/Subscribe.d.ts +26 -0
  38. package/dist/cjs/action/request/Subscribe.d.ts.map +1 -0
  39. package/dist/cjs/action/request/Subscribe.js +50 -0
  40. package/dist/cjs/action/request/Subscribe.js.map +6 -0
  41. package/dist/cjs/action/request/Write.d.ts +10 -0
  42. package/dist/cjs/action/request/Write.d.ts.map +1 -0
  43. package/dist/cjs/action/request/Write.js +22 -0
  44. package/dist/cjs/action/request/Write.js.map +6 -0
  45. package/dist/cjs/action/request/index.d.ts +11 -0
  46. package/dist/cjs/action/request/index.d.ts.map +1 -0
  47. package/dist/cjs/action/request/index.js +28 -0
  48. package/dist/cjs/action/request/index.js.map +6 -0
  49. package/dist/cjs/action/response/InvokeResult.d.ts +15 -0
  50. package/dist/cjs/action/response/InvokeResult.d.ts.map +1 -0
  51. package/dist/cjs/action/response/InvokeResult.js +22 -0
  52. package/dist/cjs/action/response/InvokeResult.js.map +6 -0
  53. package/dist/cjs/action/response/ReadResult.d.ts +63 -0
  54. package/dist/cjs/action/response/ReadResult.d.ts.map +1 -0
  55. package/dist/cjs/action/response/ReadResult.js +22 -0
  56. package/dist/cjs/action/response/ReadResult.js.map +6 -0
  57. package/dist/cjs/action/response/SubscribeResult.d.ts +13 -0
  58. package/dist/cjs/action/response/SubscribeResult.d.ts.map +1 -0
  59. package/dist/cjs/action/response/SubscribeResult.js +22 -0
  60. package/dist/cjs/action/response/SubscribeResult.js.map +6 -0
  61. package/dist/cjs/action/response/WriteResult.d.ts +12 -0
  62. package/dist/cjs/action/response/WriteResult.d.ts.map +1 -0
  63. package/dist/cjs/action/response/WriteResult.js +22 -0
  64. package/dist/cjs/action/response/WriteResult.js.map +6 -0
  65. package/dist/cjs/action/response/index.d.ts +10 -0
  66. package/dist/cjs/action/response/index.d.ts.map +1 -0
  67. package/dist/cjs/action/response/index.js +27 -0
  68. package/dist/cjs/action/response/index.js.map +6 -0
  69. package/dist/cjs/action/server/AccessControl.d.ts +152 -0
  70. package/dist/cjs/action/server/AccessControl.d.ts.map +1 -0
  71. package/dist/cjs/action/server/AccessControl.js +287 -0
  72. package/dist/cjs/action/server/AccessControl.js.map +6 -0
  73. package/dist/cjs/action/server/AttributeResponse.d.ts +36 -0
  74. package/dist/cjs/action/server/AttributeResponse.d.ts.map +1 -0
  75. package/dist/cjs/action/server/AttributeResponse.js +352 -0
  76. package/dist/cjs/action/server/AttributeResponse.js.map +6 -0
  77. package/dist/cjs/action/server/ServerInteraction.d.ts +35 -0
  78. package/dist/cjs/action/server/ServerInteraction.d.ts.map +1 -0
  79. package/dist/cjs/action/server/ServerInteraction.js +52 -0
  80. package/dist/cjs/action/server/ServerInteraction.js.map +6 -0
  81. package/dist/cjs/action/server/index.d.ts +9 -0
  82. package/dist/cjs/action/server/index.d.ts.map +1 -0
  83. package/dist/cjs/action/server/index.js +26 -0
  84. package/dist/cjs/action/server/index.js.map +6 -0
  85. package/dist/cjs/index.d.ts +1 -0
  86. package/dist/cjs/index.d.ts.map +1 -1
  87. package/dist/cjs/index.js +1 -0
  88. package/dist/cjs/index.js.map +1 -1
  89. package/dist/cjs/interaction/AccessControlManager.d.ts +1 -1
  90. package/dist/cjs/interaction/AccessControlManager.d.ts.map +1 -1
  91. package/dist/cjs/interaction/AccessControlManager.js +2 -2
  92. package/dist/cjs/interaction/AccessControlManager.js.map +1 -1
  93. package/dist/cjs/interaction/AttributeDataEncoder.d.ts +1 -3
  94. package/dist/cjs/interaction/AttributeDataEncoder.d.ts.map +1 -1
  95. package/dist/cjs/interaction/InteractionMessenger.d.ts +5 -5
  96. package/dist/cjs/interaction/InteractionMessenger.d.ts.map +1 -1
  97. package/dist/cjs/interaction/InteractionServer.d.ts +1 -1
  98. package/dist/cjs/interaction/InteractionServer.d.ts.map +1 -1
  99. package/dist/cjs/interaction/InteractionServer.js +2 -2
  100. package/dist/cjs/interaction/InteractionServer.js.map +1 -1
  101. package/dist/cjs/interaction/ServerSubscription.d.ts +2 -2
  102. package/dist/cjs/interaction/ServerSubscription.d.ts.map +1 -1
  103. package/dist/cjs/interaction/ServerSubscription.js +0 -1
  104. package/dist/cjs/interaction/ServerSubscription.js.map +1 -1
  105. package/dist/cjs/mdns/MdnsScanner.d.ts +2 -2
  106. package/dist/esm/action/Interactable.d.ts +36 -0
  107. package/dist/esm/action/Interactable.d.ts.map +1 -0
  108. package/dist/esm/action/Interactable.js +6 -0
  109. package/dist/esm/action/Interactable.js.map +6 -0
  110. package/dist/esm/action/Val.d.ts +94 -0
  111. package/dist/esm/action/Val.d.ts.map +1 -0
  112. package/dist/esm/action/Val.js +13 -0
  113. package/dist/esm/action/Val.js.map +6 -0
  114. package/dist/esm/action/errors.d.ts +69 -0
  115. package/dist/esm/action/errors.d.ts.map +1 -0
  116. package/dist/esm/action/errors.js +88 -0
  117. package/dist/esm/action/errors.js.map +6 -0
  118. package/dist/esm/action/index.d.ts +13 -0
  119. package/dist/esm/action/index.d.ts.map +1 -0
  120. package/dist/esm/action/index.js +13 -0
  121. package/dist/esm/action/index.js.map +6 -0
  122. package/dist/esm/action/protocols.d.ts +118 -0
  123. package/dist/esm/action/protocols.d.ts.map +1 -0
  124. package/dist/esm/action/protocols.js +6 -0
  125. package/dist/esm/action/protocols.js.map +6 -0
  126. package/dist/esm/action/request/Invoke.d.ts +35 -0
  127. package/dist/esm/action/request/Invoke.d.ts.map +1 -0
  128. package/dist/esm/action/request/Invoke.js +60 -0
  129. package/dist/esm/action/request/Invoke.js.map +6 -0
  130. package/dist/esm/action/request/MalformedRequestError.d.ts +14 -0
  131. package/dist/esm/action/request/MalformedRequestError.d.ts.map +1 -0
  132. package/dist/esm/action/request/MalformedRequestError.js +12 -0
  133. package/dist/esm/action/request/MalformedRequestError.js.map +6 -0
  134. package/dist/esm/action/request/Read.d.ts +141 -0
  135. package/dist/esm/action/request/Read.d.ts.map +1 -0
  136. package/dist/esm/action/request/Read.js +153 -0
  137. package/dist/esm/action/request/Read.js.map +6 -0
  138. package/dist/esm/action/request/Specifier.d.ts +82 -0
  139. package/dist/esm/action/request/Specifier.d.ts.map +1 -0
  140. package/dist/esm/action/request/Specifier.js +68 -0
  141. package/dist/esm/action/request/Specifier.js.map +6 -0
  142. package/dist/esm/action/request/Subscribe.d.ts +26 -0
  143. package/dist/esm/action/request/Subscribe.d.ts.map +1 -0
  144. package/dist/esm/action/request/Subscribe.js +30 -0
  145. package/dist/esm/action/request/Subscribe.js.map +6 -0
  146. package/dist/esm/action/request/Write.d.ts +10 -0
  147. package/dist/esm/action/request/Write.d.ts.map +1 -0
  148. package/dist/esm/action/request/Write.js +6 -0
  149. package/dist/esm/action/request/Write.js.map +6 -0
  150. package/dist/esm/action/request/index.d.ts +11 -0
  151. package/dist/esm/action/request/index.d.ts.map +1 -0
  152. package/dist/esm/action/request/index.js +11 -0
  153. package/dist/esm/action/request/index.js.map +6 -0
  154. package/dist/esm/action/response/InvokeResult.d.ts +15 -0
  155. package/dist/esm/action/response/InvokeResult.d.ts.map +1 -0
  156. package/dist/esm/action/response/InvokeResult.js +6 -0
  157. package/dist/esm/action/response/InvokeResult.js.map +6 -0
  158. package/dist/esm/action/response/ReadResult.d.ts +63 -0
  159. package/dist/esm/action/response/ReadResult.d.ts.map +1 -0
  160. package/dist/esm/action/response/ReadResult.js +6 -0
  161. package/dist/esm/action/response/ReadResult.js.map +6 -0
  162. package/dist/esm/action/response/SubscribeResult.d.ts +13 -0
  163. package/dist/esm/action/response/SubscribeResult.d.ts.map +1 -0
  164. package/dist/esm/action/response/SubscribeResult.js +6 -0
  165. package/dist/esm/action/response/SubscribeResult.js.map +6 -0
  166. package/dist/esm/action/response/WriteResult.d.ts +12 -0
  167. package/dist/esm/action/response/WriteResult.d.ts.map +1 -0
  168. package/dist/esm/action/response/WriteResult.js +6 -0
  169. package/dist/esm/action/response/WriteResult.js.map +6 -0
  170. package/dist/esm/action/response/index.d.ts +10 -0
  171. package/dist/esm/action/response/index.d.ts.map +1 -0
  172. package/dist/esm/action/response/index.js +10 -0
  173. package/dist/esm/action/response/index.js.map +6 -0
  174. package/dist/esm/action/server/AccessControl.d.ts +152 -0
  175. package/dist/esm/action/server/AccessControl.d.ts.map +1 -0
  176. package/dist/esm/action/server/AccessControl.js +267 -0
  177. package/dist/esm/action/server/AccessControl.js.map +6 -0
  178. package/dist/esm/action/server/AttributeResponse.d.ts +36 -0
  179. package/dist/esm/action/server/AttributeResponse.d.ts.map +1 -0
  180. package/dist/esm/action/server/AttributeResponse.js +339 -0
  181. package/dist/esm/action/server/AttributeResponse.js.map +6 -0
  182. package/dist/esm/action/server/ServerInteraction.d.ts +35 -0
  183. package/dist/esm/action/server/ServerInteraction.d.ts.map +1 -0
  184. package/dist/esm/action/server/ServerInteraction.js +32 -0
  185. package/dist/esm/action/server/ServerInteraction.js.map +6 -0
  186. package/dist/esm/action/server/index.d.ts +9 -0
  187. package/dist/esm/action/server/index.d.ts.map +1 -0
  188. package/dist/esm/action/server/index.js +9 -0
  189. package/dist/esm/action/server/index.js.map +6 -0
  190. package/dist/esm/index.d.ts +1 -0
  191. package/dist/esm/index.d.ts.map +1 -1
  192. package/dist/esm/index.js +1 -0
  193. package/dist/esm/index.js.map +1 -1
  194. package/dist/esm/interaction/AccessControlManager.d.ts +1 -1
  195. package/dist/esm/interaction/AccessControlManager.d.ts.map +1 -1
  196. package/dist/esm/interaction/AccessControlManager.js +2 -2
  197. package/dist/esm/interaction/AccessControlManager.js.map +1 -1
  198. package/dist/esm/interaction/AttributeDataEncoder.d.ts +1 -3
  199. package/dist/esm/interaction/AttributeDataEncoder.d.ts.map +1 -1
  200. package/dist/esm/interaction/InteractionMessenger.d.ts +5 -5
  201. package/dist/esm/interaction/InteractionMessenger.d.ts.map +1 -1
  202. package/dist/esm/interaction/InteractionServer.d.ts +1 -1
  203. package/dist/esm/interaction/InteractionServer.d.ts.map +1 -1
  204. package/dist/esm/interaction/InteractionServer.js +2 -2
  205. package/dist/esm/interaction/InteractionServer.js.map +1 -1
  206. package/dist/esm/interaction/ServerSubscription.d.ts +2 -2
  207. package/dist/esm/interaction/ServerSubscription.d.ts.map +1 -1
  208. package/dist/esm/interaction/ServerSubscription.js +0 -1
  209. package/dist/esm/interaction/ServerSubscription.js.map +1 -1
  210. package/dist/esm/mdns/MdnsScanner.d.ts +2 -2
  211. package/package.json +6 -6
  212. package/src/action/Interactable.ts +40 -0
  213. package/src/action/Val.ts +111 -0
  214. package/src/action/errors.ts +119 -0
  215. package/src/action/index.ts +13 -0
  216. package/src/action/protocols.ts +134 -0
  217. package/src/action/request/Invoke.ts +93 -0
  218. package/src/action/request/MalformedRequestError.ts +14 -0
  219. package/src/action/request/Read.ts +356 -0
  220. package/src/action/request/Specifier.ts +146 -0
  221. package/src/action/request/Subscribe.ts +54 -0
  222. package/src/action/request/Write.ts +13 -0
  223. package/src/action/request/index.ts +11 -0
  224. package/src/action/response/InvokeResult.ts +17 -0
  225. package/src/action/response/ReadResult.ts +89 -0
  226. package/src/action/response/SubscribeResult.ts +14 -0
  227. package/src/action/response/WriteResult.ts +13 -0
  228. package/src/action/response/index.ts +10 -0
  229. package/src/action/server/AccessControl.ts +494 -0
  230. package/src/action/server/AttributeResponse.ts +413 -0
  231. package/src/action/server/ServerInteraction.ts +64 -0
  232. package/src/action/server/index.ts +9 -0
  233. package/src/index.ts +1 -0
  234. package/src/interaction/AccessControlManager.ts +3 -3
  235. package/src/interaction/InteractionServer.ts +2 -3
  236. package/src/interaction/ServerSubscription.ts +0 -2
@@ -0,0 +1,287 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var AccessControl_exports = {};
20
+ __export(AccessControl_exports, {
21
+ AccessControl: () => AccessControl
22
+ });
23
+ module.exports = __toCommonJS(AccessControl_exports);
24
+ var import_model = require("#model");
25
+ var import_types = require("#types");
26
+ var import_errors = require("../errors.js");
27
+ /**
28
+ * @license
29
+ * Copyright 2022-2025 Matter.js Authors
30
+ * SPDX-License-Identifier: Apache-2.0
31
+ */
32
+ const cache = /* @__PURE__ */ new WeakMap();
33
+ function AccessControl(schema) {
34
+ let enforcer = cache.get(schema);
35
+ if (enforcer === void 0) {
36
+ enforcer = enforcerFor(schema);
37
+ }
38
+ return enforcer;
39
+ }
40
+ ((AccessControl2) => {
41
+ let Authority;
42
+ ((Authority2) => {
43
+ Authority2[Authority2["Granted"] = 1] = "Granted";
44
+ Authority2[Authority2["Unauthorized"] = 2] = "Unauthorized";
45
+ Authority2[Authority2["Restricted"] = 3] = "Restricted";
46
+ })(Authority = AccessControl2.Authority || (AccessControl2.Authority = {}));
47
+ })(AccessControl || (AccessControl = {}));
48
+ Object.freeze(AccessControl);
49
+ Object.freeze(AccessControl.Authority);
50
+ function enforcerFor(schema) {
51
+ if (schema.tag === import_model.ElementTag.Command) {
52
+ return commandEnforcerFor(schema);
53
+ }
54
+ return dataEnforcerFor(schema);
55
+ }
56
+ function dataEnforcerFor(schema) {
57
+ const limits = limitsFor(schema);
58
+ let mayRead = (session, location) => {
59
+ if (session.offline || session.command) {
60
+ return true;
61
+ }
62
+ return session.authorityAt(limits.readLevel, location) === 1 /* Granted */;
63
+ };
64
+ let mayWrite = (session, location) => {
65
+ if (session.offline || session.command) {
66
+ return true;
67
+ }
68
+ return session.authorityAt(limits.writeLevel, location) === 1 /* Granted */;
69
+ };
70
+ let authorizeRead = (session, location) => {
71
+ if (session.offline || session.command) {
72
+ return;
73
+ }
74
+ if (session.authorityAt(limits.readLevel, location) === 1 /* Granted */) {
75
+ return;
76
+ }
77
+ throw new import_errors.ReadError(location, "Permission denied", import_types.StatusCode.UnsupportedAccess);
78
+ };
79
+ let authorizeWrite = (session, location) => {
80
+ if (session.offline || session.command) {
81
+ return;
82
+ }
83
+ if (session.authorityAt(limits.writeLevel, location) === 1 /* Granted */) {
84
+ return;
85
+ }
86
+ throw new import_errors.WriteError(location, "Permission denied", import_types.StatusCode.UnsupportedAccess);
87
+ };
88
+ if (limits.timed) {
89
+ const wrappedAuthorizeWrite = authorizeWrite;
90
+ const wrappedMayWrite = mayWrite;
91
+ authorizeWrite = (session, location) => {
92
+ if (!session.offline && !session.timed) {
93
+ throw new import_errors.WriteError(
94
+ location,
95
+ "Permission denied because interaction is not timed",
96
+ import_types.StatusCode.NeedsTimedInteraction
97
+ );
98
+ }
99
+ wrappedAuthorizeWrite?.(session, location);
100
+ };
101
+ mayWrite = (session, location) => {
102
+ if (!session.offline && !session.timed) {
103
+ return false;
104
+ }
105
+ return wrappedMayWrite(session, location);
106
+ };
107
+ }
108
+ if (limits.fabricSensitive) {
109
+ const wrappedAuthorizeRead = authorizeRead;
110
+ const wrappedMayRead = mayRead;
111
+ const wrappedAuthorizeWrite = authorizeWrite;
112
+ const wrappedMayWrite = mayWrite;
113
+ authorizeRead = (session, location) => {
114
+ if (session.offline || session.command) {
115
+ return;
116
+ }
117
+ if (session.fabricFiltered) {
118
+ if (session.fabric === void 0) {
119
+ throw new import_errors.ReadError(
120
+ location,
121
+ "Permission denied: No accessing fabric",
122
+ import_types.StatusCode.UnsupportedAccess
123
+ );
124
+ }
125
+ if (location?.owningFabric && location.owningFabric !== session.fabric) {
126
+ throw new import_errors.ReadError(
127
+ location,
128
+ "Permission denied: Owning/accessing fabric mismatch",
129
+ import_types.StatusCode.UnsupportedAccess
130
+ );
131
+ }
132
+ }
133
+ wrappedAuthorizeRead(session, location);
134
+ };
135
+ mayRead = (session, location) => {
136
+ if (session.offline || session.command) {
137
+ return true;
138
+ }
139
+ if (session.fabric === void 0) {
140
+ return false;
141
+ }
142
+ if (location?.owningFabric && location.owningFabric !== session.fabric) {
143
+ return false;
144
+ }
145
+ return wrappedMayRead(session, location);
146
+ };
147
+ authorizeWrite = (session, location) => {
148
+ if (session.offline || session.command) {
149
+ return;
150
+ }
151
+ if (session.fabric === void 0) {
152
+ throw new import_errors.WriteError(location, "Permission denied: No accessing fabric", import_types.StatusCode.UnsupportedAccess);
153
+ }
154
+ if (location?.owningFabric && location.owningFabric !== session.fabric) {
155
+ throw new import_errors.WriteError(location, "Permission denied: Owning/accessing fabric mismatch");
156
+ }
157
+ wrappedAuthorizeWrite(session, location);
158
+ };
159
+ mayWrite = (session, location) => {
160
+ if (session.offline || session.command) {
161
+ return true;
162
+ }
163
+ if (session.fabric === void 0) {
164
+ return false;
165
+ }
166
+ if (location?.owningFabric && location.owningFabric !== session.fabric) {
167
+ return false;
168
+ }
169
+ return wrappedMayWrite(session, location);
170
+ };
171
+ }
172
+ if (!limits.readable) {
173
+ authorizeRead = (session, location) => {
174
+ if (session.offline || session.command) {
175
+ return;
176
+ }
177
+ throw new import_errors.ReadError(location, "Permission defined: Value is write-only");
178
+ };
179
+ mayRead = (session) => {
180
+ return !!session.offline || !!session.command;
181
+ };
182
+ }
183
+ if (!limits.writable) {
184
+ authorizeWrite = (session, location) => {
185
+ if (session.offline || session.command) {
186
+ return;
187
+ }
188
+ throw new import_errors.WriteError(location, "Permission denied: Value is read-only");
189
+ };
190
+ mayWrite = (session) => {
191
+ return !!session.offline || !!session.command;
192
+ };
193
+ }
194
+ return Object.freeze({
195
+ limits,
196
+ authorizeRead,
197
+ mayRead,
198
+ authorizeWrite,
199
+ mayWrite,
200
+ authorizeInvoke(_session, location) {
201
+ throw new import_errors.SchemaImplementationError(location, "Permission denied: Invoke request but non-command schema");
202
+ },
203
+ mayInvoke() {
204
+ return false;
205
+ }
206
+ });
207
+ }
208
+ function commandEnforcerFor(schema) {
209
+ const limits = limitsFor(schema);
210
+ const timed = schema.effectiveAccess.timed;
211
+ const fabric = schema.effectiveAccess.fabric;
212
+ return {
213
+ limits,
214
+ authorizeRead(_session, location) {
215
+ throw new import_errors.SchemaImplementationError(location, "Permission denied: Read request but command schema");
216
+ },
217
+ mayRead() {
218
+ return false;
219
+ },
220
+ authorizeWrite(_session, location) {
221
+ throw new import_errors.SchemaImplementationError(location, "Permission denied: Write request but command schema");
222
+ },
223
+ mayWrite() {
224
+ return false;
225
+ },
226
+ authorizeInvoke(session, location) {
227
+ if (session.offline) {
228
+ return;
229
+ }
230
+ if (!session.command) {
231
+ throw new import_errors.InvokeError(location, "Invoke attempt without command context");
232
+ }
233
+ if (timed && !session.timed) {
234
+ throw new import_errors.InvokeError(
235
+ location,
236
+ "Invoke attempt without required timed context",
237
+ import_types.StatusCode.TimedRequestMismatch
238
+ );
239
+ }
240
+ if (fabric && session.fabric === void 0) {
241
+ throw new import_errors.WriteError(location, "Permission denied: No accessing fabric", import_types.StatusCode.UnsupportedAccess);
242
+ }
243
+ if (session.authorityAt(limits.writeLevel, location) === 1 /* Granted */) {
244
+ return;
245
+ }
246
+ throw new import_errors.InvokeError(location, "Permission denied", import_types.StatusCode.UnsupportedAccess);
247
+ },
248
+ mayInvoke(session, location) {
249
+ if (session.offline) {
250
+ return true;
251
+ }
252
+ if (!session.command) {
253
+ return false;
254
+ }
255
+ if (timed && !session.timed) {
256
+ return false;
257
+ }
258
+ if (fabric && session.fabric === void 0) {
259
+ return false;
260
+ }
261
+ return session.authorityAt(limits.writeLevel, location) === 1 /* Granted */;
262
+ }
263
+ };
264
+ }
265
+ function limitsFor(schema) {
266
+ const access = schema.effectiveAccess;
267
+ const quality = schema instanceof import_model.ValueModel ? schema.effectiveQuality : void 0;
268
+ let fixed = quality?.fixed;
269
+ for (let s = schema.parent; !fixed && s instanceof import_model.ValueModel; s = s.parent) {
270
+ if (s.effectiveQuality.fixed) {
271
+ fixed = true;
272
+ }
273
+ }
274
+ const limits = Object.freeze({
275
+ readable: access.readable,
276
+ writable: access.writable && !fixed,
277
+ fabricScoped: access.fabric === import_model.Access.Fabric.Scoped || access.fabric === import_model.Access.Fabric.Sensitive,
278
+ fabricSensitive: access.fabric === import_model.Access.Fabric.Sensitive,
279
+ timed: access.timed === true,
280
+ // Official Matter defaults are View for read and Operate for write. However, the schema's effective access
281
+ // should already have these defaults. Here we just adopt minimum needed rights as a safe fallback access level.
282
+ readLevel: access.readPriv === void 0 ? import_model.AccessLevel.View : import_model.Access.PrivilegeLevel[access.readPriv],
283
+ writeLevel: access.writePriv === void 0 ? import_model.AccessLevel.Operate : import_model.Access.PrivilegeLevel[access.writePriv]
284
+ });
285
+ return limits;
286
+ }
287
+ //# sourceMappingURL=AccessControl.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/action/server/AccessControl.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,mBAAmF;AACnF,mBAA8E;AAC9E,oBAA8E;AAR9E;AAAA;AAAA;AAAA;AAAA;AAUA,MAAM,QAAQ,oBAAI,QAA+B;AAkD1C,SAAS,cAAc,QAAgB;AAC1C,MAAI,WAAW,MAAM,IAAI,MAAM;AAC/B,MAAI,aAAa,QAAW;AACxB,eAAW,YAAY,MAAM;AAAA,EACjC;AACA,SAAO;AACX;AAAA,CAEO,CAAUA,mBAAV;AAyGI,MAAK;AAAL,IAAKC,eAAL;AAIH,IAAAA,sBAAA,aAAU,KAAV;AAKA,IAAAA,sBAAA,kBAAe,KAAf;AAKA,IAAAA,sBAAA,gBAAa,KAAb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aAAO,QAAQ,YAAY,OAAO,YAAY,QAAQ,MAAM;AAAA,IAChE;AAAA,EACJ;AACJ;AAEA,SAAS,UAAU,QAAgB;AAC/B,QAAM,SAAS,OAAO;AACtB,QAAM,UAAU,kBAAkB,0BAAa,OAAO,mBAAmB;AAGzE,MAAI,QAAQ,SAAS;AACrB,WAAS,IAAI,OAAO,QAAQ,CAAC,SAAS,aAAa,yBAAY,IAAI,EAAE,QAAQ;AACzE,QAAI,EAAE,iBAAiB,OAAO;AAC1B,cAAQ;AAAA,IACZ;AAAA,EACJ;AAEA,QAAM,SAA+B,OAAO,OAAO;AAAA,IAC/C,UAAU,OAAO;AAAA,IACjB,UAAU,OAAO,YAAY,CAAC;AAAA,IAC9B,cAAc,OAAO,WAAW,oBAAO,OAAO,UAAU,OAAO,WAAW,oBAAO,OAAO;AAAA,IACxF,iBAAiB,OAAO,WAAW,oBAAO,OAAO;AAAA,IACjD,OAAO,OAAO,UAAU;AAAA;AAAA;AAAA,IAIxB,WAAW,OAAO,aAAa,SAAY,yBAAY,OAAO,oBAAO,eAAe,OAAO,QAAQ;AAAA,IACnG,YAAY,OAAO,cAAc,SAAY,yBAAY,UAAU,oBAAO,eAAe,OAAO,SAAS;AAAA,EAC7G,CAAC;AAED,SAAO;AACX;",
5
+ "names": ["AccessControl", "Authority"]
6
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2025 Project CHIP Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { NodeProtocol } from "#action/protocols.js";
7
+ import { Read } from "#action/request/Read.js";
8
+ import { ReadResult } from "#action/response/ReadResult.js";
9
+ import { AccessControl } from "#action/server/AccessControl.js";
10
+ export declare const GlobalAttrIds: Set<any>;
11
+ export declare const WildcardPathFlagsCodec: import("#types").BitmapSchemaInternal<{
12
+ skipRootNode: import("#types").BitFlag;
13
+ skipGlobalAttributes: import("#types").BitFlag;
14
+ skipAttributeList: import("#types").BitFlag;
15
+ reserved1: import("#types").BitFlag;
16
+ skipCommandLists: import("#types").BitFlag;
17
+ skipCustomElements: import("#types").BitFlag;
18
+ skipFixedAttributes: import("#types").BitFlag;
19
+ skipChangesOmittedAttributes: import("#types").BitFlag;
20
+ skipDiagnosticsClusters: import("#types").BitFlag;
21
+ }>;
22
+ export declare const FallbackLimits: AccessControl.Limits;
23
+ /**
24
+ * Implements read of attribute data for Matter "read" and "subscribe" interactions.
25
+ *
26
+ * TODO - profile; ensure nested functions are properly JITed and/or inlined
27
+ */
28
+ export declare class AttributeResponse<SessionT extends AccessControl.Session = AccessControl.Session> {
29
+ #private;
30
+ constructor(node: NodeProtocol, session: SessionT, { dataVersionFilters, attributeRequests }: Read.Attributes);
31
+ /**
32
+ * Emits chunks produced by paths added via {@link #addWildcard} and {@link #addConcrete}.
33
+ */
34
+ [Symbol.iterator](): Generator<ReadResult.Chunk, void, void>;
35
+ }
36
+ //# sourceMappingURL=AttributeResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttributeResponse.d.ts","sourceRoot":"","sources":["../../../../src/action/server/AttributeResponse.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAA4D,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC9G,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAgBhE,eAAO,MAAM,aAAa,UAAgE,CAAC;AAC3F,eAAO,MAAM,sBAAsB;;;;;;;;;;EAAwC,CAAC;AAC5E,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC,MAQ1C,CAAC;AAEF;;;;GAIG;AACH,qBAAa,iBAAiB,CAAC,QAAQ,SAAS,aAAa,CAAC,OAAO,GAAG,aAAa,CAAC,OAAO;;gBAwB7E,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,EAAE,IAAI,CAAC,UAAU;IAkC7G;;OAEG;IACF,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC;CAqThE"}
@@ -0,0 +1,352 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var AttributeResponse_exports = {};
20
+ __export(AttributeResponse_exports, {
21
+ AttributeResponse: () => AttributeResponse,
22
+ FallbackLimits: () => FallbackLimits,
23
+ GlobalAttrIds: () => GlobalAttrIds,
24
+ WildcardPathFlagsCodec: () => WildcardPathFlagsCodec
25
+ });
26
+ module.exports = __toCommonJS(AttributeResponse_exports);
27
+ var import_AccessControl = require("#action/server/AccessControl.js");
28
+ var import_general = require("#general");
29
+ var import_model = require("#model");
30
+ var import_types = require("#types");
31
+ /**
32
+ * @license
33
+ * Copyright 2022-2025 Project CHIP Authors
34
+ * SPDX-License-Identifier: Apache-2.0
35
+ */
36
+ const GlobalAttrIds = new Set(Object.values(import_types.GlobalAttributes).map((attr) => attr.id));
37
+ const WildcardPathFlagsCodec = (0, import_types.BitmapSchema)(import_types.WildcardPathFlagsBitmap);
38
+ const FallbackLimits = {
39
+ fabricScoped: false,
40
+ fabricSensitive: false,
41
+ readable: true,
42
+ readLevel: import_model.AccessLevel.View,
43
+ timed: false,
44
+ writable: true,
45
+ writeLevel: import_model.AccessLevel.Administer
46
+ };
47
+ class AttributeResponse {
48
+ // Configuration
49
+ #session;
50
+ #node;
51
+ #versions;
52
+ // Each input AttributePathIB that does not have an error installs a producer. Producers run after validation and
53
+ // generate actual attribute data
54
+ #dataProducers;
55
+ // The initial "chunk" may be a list of errors. As producers execute it is a set of records associated with the
56
+ // most recently touched endpoint. When the endpoint changes the previous chunk emits
57
+ #chunk;
58
+ // The following state updates as data producers execute. This serves both to convey state between functions and as
59
+ // a cache between producers that touch the same endpoint and/or cluster
60
+ #currentEndpoint;
61
+ #currentCluster;
62
+ #currentState;
63
+ #wildcardPathFlags = 0;
64
+ // The node ID may be expensive to retrieve and is invariant so we cache it here
65
+ #cachedNodeId;
66
+ constructor(node, session, { dataVersionFilters, attributeRequests }) {
67
+ this.#node = node;
68
+ this.#session = session;
69
+ const nodeId = session.fabric === void 0 ? import_types.NodeId.UNSPECIFIED_NODE_ID : this.#nodeId;
70
+ if (dataVersionFilters?.length) {
71
+ this.#versions = {};
72
+ for (const {
73
+ path: { nodeId: filterNodeId, endpointId, clusterId },
74
+ dataVersion
75
+ } of dataVersionFilters) {
76
+ if (filterNodeId !== void 0 && filterNodeId !== nodeId) {
77
+ continue;
78
+ }
79
+ if (typeof endpointId !== "number") {
80
+ continue;
81
+ }
82
+ (this.#versions[endpointId] ?? (this.#versions[endpointId] = {}))[clusterId] = dataVersion;
83
+ }
84
+ }
85
+ for (const path of attributeRequests) {
86
+ if (path.endpointId === void 0 || path.clusterId === void 0 || path.attributeId === void 0) {
87
+ this.#addWildcard(path);
88
+ } else {
89
+ this.#addConcrete(path);
90
+ }
91
+ }
92
+ }
93
+ /**
94
+ * Emits chunks produced by paths added via {@link #addWildcard} and {@link #addConcrete}.
95
+ */
96
+ *[Symbol.iterator]() {
97
+ if (this.#dataProducers) {
98
+ for (const producer of this.#dataProducers) {
99
+ yield* producer.apply(this);
100
+ }
101
+ }
102
+ if (this.#chunk !== void 0) {
103
+ yield this.#chunk;
104
+ }
105
+ }
106
+ /**
107
+ * Validate a wildcard path and update internal state.
108
+ */
109
+ #addWildcard(path) {
110
+ const { nodeId, endpointId, clusterId, attributeId, wildcardPathFlags } = path;
111
+ if (nodeId !== void 0 && nodeId !== this.#nodeId) {
112
+ return;
113
+ }
114
+ const wpf = wildcardPathFlags ? WildcardPathFlagsCodec.encode(wildcardPathFlags) : 0;
115
+ if (clusterId === void 0 && attributeId !== void 0 && !GlobalAttrIds.has(attributeId)) {
116
+ throw new import_types.StatusResponseError(
117
+ `Illegal read of wildcard cluster with non-global attribute #${attributeId}`,
118
+ import_types.Status.InvalidAction
119
+ );
120
+ }
121
+ if (endpointId === void 0) {
122
+ this.#addProducer(function* () {
123
+ this.#wildcardPathFlags = wpf;
124
+ for (const endpoint2 of this.#node) {
125
+ yield* this.#readEndpointForWildcard(endpoint2, path);
126
+ }
127
+ });
128
+ return;
129
+ }
130
+ const endpoint = this.#node[endpointId];
131
+ if (endpoint) {
132
+ this.#addProducer(function() {
133
+ this.#wildcardPathFlags = wpf;
134
+ return this.#readEndpointForWildcard(endpoint, path);
135
+ });
136
+ }
137
+ }
138
+ /**
139
+ * Validate a concrete path and update internal state.
140
+ */
141
+ #addConcrete(path) {
142
+ const { nodeId, endpointId, clusterId, attributeId } = path;
143
+ if (nodeId !== void 0 && this.#nodeId !== nodeId) {
144
+ this.#addStatus(path, import_types.Status.UnsupportedNode);
145
+ }
146
+ const endpoint = this.#node[endpointId];
147
+ const cluster = endpoint?.[clusterId];
148
+ const attribute = cluster?.type.attributes[attributeId];
149
+ let limits;
150
+ if (attribute === void 0) {
151
+ const modelAttr = this.#node.matter.member(path.clusterId, [import_model.ElementTag.Cluster])?.member(path.attributeId, [import_model.ElementTag.Attribute]);
152
+ if (modelAttr) {
153
+ limits = (0, import_AccessControl.AccessControl)(modelAttr).limits;
154
+ } else {
155
+ limits = FallbackLimits;
156
+ }
157
+ } else {
158
+ limits = attribute.limits;
159
+ }
160
+ switch (this.#session.authorityAt(limits.readLevel)) {
161
+ case import_AccessControl.AccessControl.Authority.Granted:
162
+ break;
163
+ case import_AccessControl.AccessControl.Authority.Unauthorized:
164
+ this.#addStatus(path, import_types.Status.UnsupportedAccess);
165
+ return;
166
+ case import_AccessControl.AccessControl.Authority.Restricted:
167
+ this.#addStatus(path, import_types.Status.AccessRestricted);
168
+ return;
169
+ default:
170
+ throw new import_general.InternalError(
171
+ `Unsupported authorization state ${this.#session.authorityAt(limits.readLevel)}`
172
+ );
173
+ }
174
+ if (endpoint === void 0) {
175
+ this.#addStatus(path, import_types.Status.UnsupportedEndpoint);
176
+ return;
177
+ }
178
+ if (cluster === void 0) {
179
+ this.#addStatus(path, import_types.Status.UnsupportedCluster);
180
+ return;
181
+ }
182
+ if (attribute === void 0) {
183
+ this.#addStatus(path, import_types.Status.UnsupportedAttribute);
184
+ return;
185
+ }
186
+ if (!limits.readable) {
187
+ this.#addStatus(path, import_types.Status.UnsupportedRead);
188
+ return;
189
+ }
190
+ const skipVersion = this.#versions?.[path.endpointId]?.[path.clusterId];
191
+ if (skipVersion !== void 0 && skipVersion === cluster.version) {
192
+ return;
193
+ }
194
+ this.#addProducer(function* () {
195
+ if (this.#currentEndpoint !== endpoint) {
196
+ if (this.#chunk) {
197
+ yield this.#chunk;
198
+ this.#chunk = void 0;
199
+ }
200
+ this.#currentEndpoint = endpoint;
201
+ this.#currentCluster = cluster;
202
+ this.#currentState = cluster.open(this.#session);
203
+ } else if (this.#currentCluster !== cluster) {
204
+ this.#currentCluster = cluster;
205
+ this.#currentState = cluster.open(this.#session);
206
+ } else if (this.#currentState === void 0) {
207
+ this.#currentState = cluster.open(this.#session);
208
+ }
209
+ this.#addValue(path, this.#currentState);
210
+ });
211
+ }
212
+ /**
213
+ * Starts new chunk or adds to current chunk all values from {@link endpoint} selected by {@link path}.
214
+ *
215
+ * Emits previous chunk if it exists and was not for this endpoint. This means that our chunk size is one endpoint
216
+ * worth of data, except for the initial error chunk if there are path errors.
217
+ *
218
+ * {@link this.#wildcardPathFlags} to numeric bitmap must be set prior to invocation.
219
+ *
220
+ * TODO - skip endpoints for which subject is unauthorized
221
+ */
222
+ *#readEndpointForWildcard(endpoint, path) {
223
+ if (endpoint.wildcardPathFlags & this.#wildcardPathFlags) {
224
+ return;
225
+ }
226
+ if (this.#currentEndpoint !== endpoint) {
227
+ if (this.#chunk) {
228
+ yield this.#chunk;
229
+ this.#chunk = void 0;
230
+ }
231
+ this.#currentEndpoint = endpoint;
232
+ this.#currentCluster = void 0;
233
+ }
234
+ const { clusterId } = path;
235
+ if (clusterId === void 0) {
236
+ for (const cluster of endpoint) {
237
+ this.#readClusterForWildcard(cluster, path);
238
+ }
239
+ } else {
240
+ const cluster = endpoint[clusterId];
241
+ if (cluster !== void 0) {
242
+ this.#readClusterForWildcard(cluster, path);
243
+ }
244
+ }
245
+ }
246
+ /**
247
+ * Read values from a specific {@link cluster} for a wildcard path.
248
+ *
249
+ * Depends on state initialized by {@link #readEndpointForWildcard}.
250
+ *
251
+ * TODO - skip clusters for which subject is unauthorized
252
+ */
253
+ #readClusterForWildcard(cluster, path) {
254
+ if (cluster.type.wildcardPathFlags & this.#wildcardPathFlags) {
255
+ return;
256
+ }
257
+ if (this.#currentCluster !== cluster) {
258
+ this.#currentCluster = cluster;
259
+ this.#currentState = void 0;
260
+ }
261
+ const skipVersion = this.#versions?.[this.#currentEndpoint.id]?.[cluster.type.id];
262
+ if (skipVersion !== void 0 && skipVersion === cluster.version) {
263
+ return;
264
+ }
265
+ const { attributeId } = path;
266
+ if (attributeId === void 0) {
267
+ for (const attribute of cluster.type.attributes) {
268
+ this.#readAttributeForWildcard(attribute, path);
269
+ }
270
+ } else {
271
+ const attribute = cluster.type.attributes[attributeId];
272
+ if (attribute !== void 0) {
273
+ this.#readAttributeForWildcard(attribute, path);
274
+ }
275
+ }
276
+ }
277
+ /**
278
+ * Read values from a specific {@link attribute} for a wildcard path.
279
+ *
280
+ * Depends on state initialized by {@link #readClusterForWildcard}.
281
+ */
282
+ #readAttributeForWildcard(attribute, path) {
283
+ if (attribute.wildcardPathFlags & this.#wildcardPathFlags) {
284
+ return;
285
+ }
286
+ if (!attribute.limits.readable || this.#session.authorityAt(attribute.limits.readLevel, this.#currentCluster.location) !== import_AccessControl.AccessControl.Authority.Granted) {
287
+ return;
288
+ }
289
+ if (this.#currentState === void 0) {
290
+ this.#currentState = this.#currentCluster.open(this.#session);
291
+ }
292
+ this.#addValue(
293
+ {
294
+ ...path,
295
+ endpointId: this.#currentEndpoint?.id,
296
+ clusterId: this.#currentCluster?.type.id,
297
+ attributeId: attribute.id
298
+ },
299
+ this.#currentState[attribute.id]
300
+ );
301
+ }
302
+ /**
303
+ * Add a function that produces data. These functions are run after validation of input paths.
304
+ */
305
+ #addProducer(producer) {
306
+ if (this.#dataProducers) {
307
+ this.#dataProducers.push(producer);
308
+ } else {
309
+ this.#dataProducers = [producer];
310
+ }
311
+ }
312
+ /**
313
+ * Add a status value.
314
+ */
315
+ #addStatus(path, status) {
316
+ const report = {
317
+ kind: "attr-status",
318
+ path,
319
+ status
320
+ };
321
+ if (this.#chunk) {
322
+ this.#chunk.push(report);
323
+ } else {
324
+ this.#chunk = [report];
325
+ }
326
+ }
327
+ /**
328
+ * Add an attribute value.
329
+ */
330
+ #addValue(path, value) {
331
+ const report = {
332
+ kind: "attr-value",
333
+ path,
334
+ value
335
+ };
336
+ if (this.#chunk) {
337
+ this.#chunk.push(report);
338
+ } else {
339
+ this.#chunk = [report];
340
+ }
341
+ }
342
+ /**
343
+ * The node ID used to filter paths with node ID specified. Unsure if this is ever actually used.
344
+ */
345
+ get #nodeId() {
346
+ if (this.#cachedNodeId === void 0) {
347
+ this.#cachedNodeId = (this.#session.fabric && this.#node.nodeIdFor(this.#session.fabric)) ?? import_types.NodeId.UNSPECIFIED_NODE_ID;
348
+ }
349
+ return this.#cachedNodeId;
350
+ }
351
+ }
352
+ //# sourceMappingURL=AttributeResponse.js.map