@matter/nodejs-shell 0.11.0-alpha.0-20241007-547af42a8

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 (56) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +192 -0
  3. package/dist/cjs/MatterNode.js +115 -0
  4. package/dist/cjs/MatterNode.js.map +6 -0
  5. package/dist/cjs/app.js +162 -0
  6. package/dist/cjs/app.js.map +6 -0
  7. package/dist/cjs/package.json +7 -0
  8. package/dist/cjs/shell/Shell.js +195 -0
  9. package/dist/cjs/shell/Shell.js.map +6 -0
  10. package/dist/cjs/shell/cmd_cluster-attributes.js +310 -0
  11. package/dist/cjs/shell/cmd_cluster-attributes.js.map +6 -0
  12. package/dist/cjs/shell/cmd_cluster-commands.js +158 -0
  13. package/dist/cjs/shell/cmd_cluster-commands.js.map +6 -0
  14. package/dist/cjs/shell/cmd_cluster-events.js +104 -0
  15. package/dist/cjs/shell/cmd_cluster-events.js.map +6 -0
  16. package/dist/cjs/shell/cmd_commission.js +237 -0
  17. package/dist/cjs/shell/cmd_commission.js.map +6 -0
  18. package/dist/cjs/shell/cmd_config.js +315 -0
  19. package/dist/cjs/shell/cmd_config.js.map +6 -0
  20. package/dist/cjs/shell/cmd_discover.js +123 -0
  21. package/dist/cjs/shell/cmd_discover.js.map +6 -0
  22. package/dist/cjs/shell/cmd_identify.js +66 -0
  23. package/dist/cjs/shell/cmd_identify.js.map +6 -0
  24. package/dist/cjs/shell/cmd_nodes.js +244 -0
  25. package/dist/cjs/shell/cmd_nodes.js.map +6 -0
  26. package/dist/cjs/shell/cmd_session.js +43 -0
  27. package/dist/cjs/shell/cmd_session.js.map +6 -0
  28. package/dist/cjs/shell/cmd_subscribe.js +59 -0
  29. package/dist/cjs/shell/cmd_subscribe.js.map +6 -0
  30. package/dist/cjs/shell/cmd_tlv.js +175 -0
  31. package/dist/cjs/shell/cmd_tlv.js.map +6 -0
  32. package/dist/cjs/util/CommandlineParser.js +106 -0
  33. package/dist/cjs/util/CommandlineParser.js.map +6 -0
  34. package/dist/cjs/util/Json.js +66 -0
  35. package/dist/cjs/util/Json.js.map +6 -0
  36. package/dist/cjs/util/String.js +32 -0
  37. package/dist/cjs/util/String.js.map +6 -0
  38. package/package.json +58 -0
  39. package/src/MatterNode.ts +141 -0
  40. package/src/app.ts +158 -0
  41. package/src/shell/Shell.ts +184 -0
  42. package/src/shell/cmd_cluster-attributes.ts +340 -0
  43. package/src/shell/cmd_cluster-commands.ts +174 -0
  44. package/src/shell/cmd_cluster-events.ts +99 -0
  45. package/src/shell/cmd_commission.ts +273 -0
  46. package/src/shell/cmd_config.ts +366 -0
  47. package/src/shell/cmd_discover.ts +127 -0
  48. package/src/shell/cmd_identify.ts +51 -0
  49. package/src/shell/cmd_nodes.ts +249 -0
  50. package/src/shell/cmd_session.ts +23 -0
  51. package/src/shell/cmd_subscribe.ts +43 -0
  52. package/src/shell/cmd_tlv.ts +169 -0
  53. package/src/tsconfig.json +22 -0
  54. package/src/util/CommandlineParser.ts +123 -0
  55. package/src/util/Json.ts +50 -0
  56. package/src/util/String.ts +9 -0
@@ -0,0 +1,175 @@
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 cmd_tlv_exports = {};
20
+ __export(cmd_tlv_exports, {
21
+ default: () => commands
22
+ });
23
+ module.exports = __toCommonJS(cmd_tlv_exports);
24
+ var import_general = require("#general");
25
+ var import_types = require("#types");
26
+ /**
27
+ * @license
28
+ * Copyright 2022-2024 Matter.js Authors
29
+ * SPDX-License-Identifier: Apache-2.0
30
+ */
31
+ const logger = import_general.Logger.get("tlv");
32
+ const TlvTypeNames = {
33
+ [import_types.TlvType.Null]: "(Null)",
34
+ [import_types.TlvType.Boolean]: "Boolean(",
35
+ [import_types.TlvType.UnsignedInt]: "UnsignedInt(",
36
+ [import_types.TlvType.SignedInt]: "SignedInt(",
37
+ [import_types.TlvType.Float]: "Float(",
38
+ [import_types.TlvType.Utf8String]: "Utf8String(",
39
+ [import_types.TlvType.ByteString]: "ByteString(",
40
+ [import_types.TlvType.Array]: "Array {",
41
+ [import_types.TlvType.List]: "List {",
42
+ [import_types.TlvType.Structure]: "Structure {",
43
+ [import_types.TlvType.EndOfContainer]: "}"
44
+ };
45
+ function logAnyTlvStream(encoded) {
46
+ if (encoded.length === 0) {
47
+ return void 0;
48
+ }
49
+ const reader = new import_types.TlvArrayReader(encoded);
50
+ logGenericElement(reader);
51
+ const nextElement = reader.readTagType();
52
+ if (nextElement !== void 0) {
53
+ throw new import_general.UnexpectedDataError(`Unexpected data left after parsing all data: ${import_general.Logger.toJSON(nextElement)}`);
54
+ }
55
+ }
56
+ function logGenericElement(reader, preReadElement, allowTag = false) {
57
+ const element = preReadElement ?? reader.readTagType();
58
+ const {
59
+ tag,
60
+ typeLength: { type }
61
+ } = element;
62
+ switch (type) {
63
+ case import_types.TlvType.Null:
64
+ case import_types.TlvType.Boolean:
65
+ case import_types.TlvType.UnsignedInt:
66
+ case import_types.TlvType.SignedInt:
67
+ case import_types.TlvType.Float:
68
+ case import_types.TlvType.Utf8String:
69
+ case import_types.TlvType.ByteString:
70
+ if (tag !== void 0 && !allowTag) {
71
+ throw new import_general.UnexpectedDataError(`Tag detected for a native type: ${import_general.Logger.toJSON(element)}`);
72
+ }
73
+ const value = reader.readPrimitive(element.typeLength);
74
+ const logValue = value instanceof Uint8Array ? import_general.Bytes.toHex(value) : value;
75
+ const logNumberHex = typeof value === "number" || typeof value === "bigint" ? value.toString(16) : void 0;
76
+ logger.info(
77
+ tag?.id !== void 0 ? `${tag.id}/0x${tag?.id?.toString(16)} => ` : "",
78
+ TlvTypeNames[type],
79
+ `${logValue}${logNumberHex !== void 0 ? `/0x${logNumberHex}` : ""}`,
80
+ ")"
81
+ );
82
+ break;
83
+ case import_types.TlvType.Array:
84
+ case import_types.TlvType.List:
85
+ tag?.id !== void 0 ? logger.info(`${tag.id}/0x${tag.id.toString(16)} => `, TlvTypeNames[type]) : logger.info(TlvTypeNames[type]);
86
+ import_general.Logger.nest(() => logGenericArrayOrList(reader, type === import_types.TlvType.List));
87
+ logger.info(TlvTypeNames[import_types.TlvType.EndOfContainer]);
88
+ break;
89
+ case import_types.TlvType.Structure:
90
+ tag?.id !== void 0 ? logger.info(`${tag.id}/0x${tag.id.toString(16)} => `, TlvTypeNames[type]) : logger.info(TlvTypeNames[type]);
91
+ import_general.Logger.nest(() => logGenericStructure(reader));
92
+ logger.info(TlvTypeNames[import_types.TlvType.EndOfContainer]);
93
+ break;
94
+ default:
95
+ throw new import_general.UnexpectedDataError(`Unknown type: ${type}`);
96
+ }
97
+ }
98
+ function logGenericArrayOrList(reader, allowTag = false) {
99
+ const result = new Array();
100
+ while (true) {
101
+ const element = reader.readTagType();
102
+ const {
103
+ tag,
104
+ typeLength: { type }
105
+ } = element;
106
+ if (type === import_types.TlvType.EndOfContainer) break;
107
+ if (tag !== void 0 && !allowTag) {
108
+ throw new import_general.UnexpectedDataError(`Tag detected : ${import_general.Logger.toJSON(element)}`);
109
+ }
110
+ logGenericElement(reader, element, allowTag);
111
+ }
112
+ return result;
113
+ }
114
+ function logGenericStructure(reader) {
115
+ const result = {};
116
+ while (true) {
117
+ const element = reader.readTagType();
118
+ const {
119
+ tag,
120
+ typeLength: { type }
121
+ } = element;
122
+ if (type === import_types.TlvType.EndOfContainer) break;
123
+ if (tag === void 0 || tag.id === void 0) {
124
+ throw new import_general.UnexpectedDataError(`Tag missing for a structure: ${import_general.Logger.toJSON(element)}`);
125
+ }
126
+ logGenericElement(reader, element, true);
127
+ }
128
+ return result;
129
+ }
130
+ function commands() {
131
+ return {
132
+ command: "tlv",
133
+ describe: "TLV decoding tools",
134
+ builder: (yargs) => {
135
+ return yargs.command(
136
+ "decode [value]",
137
+ "Decodes a TLV string (hex) into matter.js JavaScript object",
138
+ (yargs2) => {
139
+ return yargs2.positional("value", {
140
+ describe: "The TLV value as hex string",
141
+ type: "string",
142
+ demandOption: true
143
+ });
144
+ },
145
+ async (argv) => {
146
+ const { value } = argv;
147
+ const bytes = import_general.Bytes.fromHex(value);
148
+ const tlvEncoded = import_types.TlvAny.decode(bytes);
149
+ const decoded = import_types.TlvAny.decodeAnyTlvStream(tlvEncoded);
150
+ console.log("Decoded:", (0, import_general.serialize)(decoded));
151
+ }
152
+ ).command(
153
+ "log [value]",
154
+ "Decodes a TLV string (hex string) and logs it's structure",
155
+ (yargs2) => {
156
+ return yargs2.positional("value", {
157
+ describe: "The TLV value as hex string",
158
+ type: "string",
159
+ demandOption: true
160
+ });
161
+ },
162
+ async (argv) => {
163
+ const { value } = argv;
164
+ const bytes = import_general.Bytes.fromHex(value);
165
+ const tlvEncoded = import_types.TlvAny.decode(bytes);
166
+ logAnyTlvStream(tlvEncoded);
167
+ }
168
+ );
169
+ },
170
+ handler: async (argv) => {
171
+ argv.unhandled = true;
172
+ }
173
+ };
174
+ }
175
+ //# sourceMappingURL=cmd_tlv.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/shell/cmd_tlv.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,qBAA8D;AAC9D,mBAAuE;AAPvE;AAAA;AAAA;AAAA;AAA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W,SAAS;AAAA,YAC7B,UAAU;AAAA,YACV,MAAM;AAAA,YACN,cAAc;AAAA,UAClB,CAAC;AAAA,QACL;AAAA,QACA,OAAM,SAAQ;AACV,gBAAM,EAAE,MAAM,IAAI;AAClB,gBAAM,QAAQ,qBAAM,QAAQ,KAAK;AACjC,gBAAM,aAAa,oBAAO,OAAO,KAAK;AACtC,0BAAgB,UAAU;AAAA,QAC9B;AAAA,MACJ;AAAA,IACR;AAAA,IACA,SAAS,OAAO,SAAc;AAC1B,WAAK,YAAY;AAAA,IACrB;AAAA,EACJ;AACJ;",
5
+ "names": ["yargs"]
6
+ }
@@ -0,0 +1,106 @@
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 CommandlineParser_exports = {};
20
+ __export(CommandlineParser_exports, {
21
+ commandlineParser: () => commandlineParser
22
+ });
23
+ module.exports = __toCommonJS(CommandlineParser_exports);
24
+ /**
25
+ * Quote aware Command line parser
26
+ *
27
+ * @license
28
+ * Copyright 2022-2024 Matter.js Authors
29
+ * SPDX-License-Identifier: Apache-2.0
30
+ */
31
+ class StringReader {
32
+ constructor(str) {
33
+ this.str = str;
34
+ this.pos = -1;
35
+ }
36
+ pos;
37
+ current;
38
+ next() {
39
+ if (this.pos < this.str.length) {
40
+ this.current = this.str[++this.pos];
41
+ }
42
+ return this.current;
43
+ }
44
+ }
45
+ function isWhitespace(c) {
46
+ return c === " ";
47
+ }
48
+ function consumeWhitespace(r) {
49
+ while (r.current !== void 0 && isWhitespace(r.current)) {
50
+ r.next();
51
+ }
52
+ }
53
+ function escaped(r) {
54
+ const n = r.next();
55
+ if (n === void 0) {
56
+ throw new Error("Unterminated escape sequence");
57
+ }
58
+ return n;
59
+ }
60
+ function quoted(r) {
61
+ let s = "";
62
+ const q = r.current;
63
+ const e = q === '"';
64
+ for (let c = r.next(); c !== q; c = r.next()) {
65
+ if (c === void 0) {
66
+ throw new Error(`Unterminated quote: ${q}`);
67
+ }
68
+ if (e && c === "\\") {
69
+ s += escaped(r);
70
+ } else {
71
+ s += c;
72
+ }
73
+ }
74
+ return s;
75
+ }
76
+ function commandlineParser(line) {
77
+ const args = [];
78
+ let s = "";
79
+ const r = new StringReader(line);
80
+ r.next();
81
+ consumeWhitespace(r);
82
+ let sawQuote = false;
83
+ while (r.current !== void 0) {
84
+ if (isWhitespace(r.current)) {
85
+ args.push(s);
86
+ sawQuote = false;
87
+ s = "";
88
+ consumeWhitespace(r);
89
+ } else if (r.current == "\\") {
90
+ s += escaped(r);
91
+ r.next();
92
+ } else if (r.current === "'" || r.current === '"') {
93
+ s += quoted(r);
94
+ sawQuote = true;
95
+ r.next();
96
+ } else {
97
+ s += r.current;
98
+ r.next();
99
+ }
100
+ }
101
+ if (sawQuote || s.length) {
102
+ args.push(s);
103
+ }
104
+ return args;
105
+ }
106
+ //# sourceMappingURL=CommandlineParser.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/util/CommandlineParser.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BA,MAAM,aAAa;AAAA,EAIf,YAA6B,KAAa;AAAb;AACzB,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AAQ,CAAC;AACd,QAAE,KAAK;AAAA,IACX,WAAW,EAAE,YAAY,OAAO,EAAE,YAAY,KAAK;AAC/C,WAAK,OAAO,CAAC;AACb,iBAAW;AACX,QAAE,KAAK;AAAA,IACX,OAAO;AACH,WAAK,EAAE;AACP,QAAE,KAAK;AAAA,IACX;AAAA,EACJ;AAEA,MAAI,YAAY,EAAE,QAAQ;AACtB,SAAK,KAAK,CAAC;AAAA,EACf;AAEA,SAAO;AACX;",
5
+ "names": []
6
+ }
@@ -0,0 +1,66 @@
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 Json_exports = {};
20
+ __export(Json_exports, {
21
+ convertJsonDataWithModel: () => convertJsonDataWithModel
22
+ });
23
+ module.exports = __toCommonJS(Json_exports);
24
+ var import_general = require("@matter/general");
25
+ var import_common = require("@project-chip/matter.js/common");
26
+ var import_String = require("./String");
27
+ /**
28
+ * @license
29
+ * Copyright 2022-2024 Matter.js Authors
30
+ * SPDX-License-Identifier: Apache-2.0
31
+ */
32
+ function convertJsonDataWithModel(model, data) {
33
+ const definingModel = model.definingModel ?? model;
34
+ switch (definingModel.effectiveMetatype) {
35
+ case "array":
36
+ if (!Array.isArray(data)) {
37
+ throw new import_common.ValidationDatatypeMismatchError(`Expected array, got ${typeof data}`);
38
+ }
39
+ return data.map((item) => convertJsonDataWithModel(definingModel.children[0], item));
40
+ case "object":
41
+ if (typeof data !== "object") {
42
+ throw new import_common.ValidationDatatypeMismatchError(`Expected object, got ${typeof data}`);
43
+ }
44
+ for (const child of definingModel.children) {
45
+ const childKeyName = (0, import_String.camelize)(child.name);
46
+ data[childKeyName] = convertJsonDataWithModel(child, data[childKeyName]);
47
+ }
48
+ return data;
49
+ case "integer":
50
+ if (typeof data === "string") {
51
+ if (definingModel.metabase?.byteSize !== void 0 && definingModel.metabase.byteSize > 6) {
52
+ return BigInt(data);
53
+ } else if (data.startsWith("0x")) {
54
+ return parseInt(data.substring(2), 16);
55
+ }
56
+ }
57
+ break;
58
+ case "bytes":
59
+ if (typeof data === "string") {
60
+ return import_general.Bytes.fromHex(data);
61
+ }
62
+ break;
63
+ }
64
+ return data;
65
+ }
66
+ //# sourceMappingURL=Json.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/util/Json.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,qBAAsB;AAEtB,oBAAgD;AAChD,oBAAyB;AATzB;AAAA;AAAA;AAAA;AAAA;AAWO,SAAS,yBAAyB,OAAmB,MAAgB;AACxE,QAAM,gBAAgB,MAAM,iBAAiB;AAC7C,UAAQ,cAAc,mBAAmB;AAAA,IACrC,KAAK;AACD,UAAI,CAAC,MAAM,QAAQ,IAAI,GAAG;AACtB,cAAM,IAAI,8CAAgC,uBAAuB,OAAO,IAAI,EAAE;AAAA,MAClF;AACA,aAAO,KAAK,IAAI,UAAQ,yBAAyB,cAAc,SAAS,CAAC,GAAG,IAAI,CAAC;AAAA,IACrF,KAAK;AACD,UAAI,OAAO,SAAS,UAAU;AAC1B,cAAM,IAAI,8CAAgC,wBAAwB,OAAO,IAAI,EAAE;AAAA,MACnF;AACA,iBAAW,SAAS,cAAc,UAAU;AACxC,cAAM,mBAAe,wBAAS,MAAM,IAAI;AACxC,aAAK,YAAY,IAAI,yBAAyB,OAAO,KAAK,YAAY,CAAC;AAAA,MAC3E;AACA,aAAO;AAAA,IACX,KAAK;AACD,UAAI,OAAO,SAAS,UAAU;AAC1B,YAAI,cAAc,UAAU,aAAa,UAAa,cAAc,SAAS,WAAW,GAAG;AAGvF,iBAAO,OAAO,IAAI;AAAA,QACtB,WAAW,KAAK,WAAW,IAAI,GAAG;AAE9B,iBAAO,SAAS,KAAK,UAAU,CAAC,GAAG,EAAE;AAAA,QACzC;AAAA,MACJ;AACA;AAAA,IACJ,KAAK;AACD,UAAI,OAAO,SAAS,UAAU;AAE1B,eAAO,qBAAM,QAAQ,IAAI;AAAA,MAC7B;AACA;AAAA,EACR;AAEA,SAAO;AACX;",
5
+ "names": []
6
+ }
@@ -0,0 +1,32 @@
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 String_exports = {};
20
+ __export(String_exports, {
21
+ camelize: () => camelize
22
+ });
23
+ module.exports = __toCommonJS(String_exports);
24
+ /**
25
+ * @license
26
+ * Copyright 2022-2024 Matter.js Authors
27
+ * SPDX-License-Identifier: Apache-2.0
28
+ */
29
+ function camelize(str) {
30
+ return str.charAt(0).toLowerCase() + str.slice(1);
31
+ }
32
+ //# sourceMappingURL=String.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/util/String.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,SAAS,SAAS,KAAa;AAClC,SAAO,IAAI,OAAO,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC;AACpD;",
5
+ "names": []
6
+ }
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@matter/nodejs-shell",
3
+ "version": "0.11.0-alpha.0-20241007-547af42a8",
4
+ "description": "Shell app for Matter controller",
5
+ "keywords": [
6
+ "iot",
7
+ "home automation",
8
+ "matter",
9
+ "smart device"
10
+ ],
11
+ "license": "Apache-2.0",
12
+ "author": "matter.js authors",
13
+ "contributors": [
14
+ "Martin Turon <mturon@google.com>",
15
+ "Ingo Fischer <github@fischer-ka.de>"
16
+ ],
17
+ "bugs": {
18
+ "url": "https://github.com/project-chip/matter.js/issues"
19
+ },
20
+ "homepage": "https://github.com/project-chip/matter.js",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/project-chip/matter.js.git"
24
+ },
25
+ "scripts": {
26
+ "clean": "matter-build clean",
27
+ "build": "matter-build",
28
+ "build-clean": "matter-build --clean",
29
+ "shell": "matter-run src/app.ts"
30
+ },
31
+ "bin": {
32
+ "matter-shell": "dist/cjs/app.js"
33
+ },
34
+ "imports": {
35
+ "#general": "@matter/general",
36
+ "#types": "@matter/types"
37
+ },
38
+ "dependencies": {
39
+ "@matter/nodejs-ble": "0.11.0-alpha.0-20241007-547af42a8",
40
+ "@matter/nodejs": "0.11.0-alpha.0-20241007-547af42a8",
41
+ "@matter/general": "0.11.0-alpha.0-20241007-547af42a8",
42
+ "@matter/tools": "0.11.0-alpha.0-20241007-547af42a8",
43
+ "@project-chip/matter.js": "0.11.0-alpha.0-20241007-547af42a8",
44
+ "yargs": "^17.7.2"
45
+ },
46
+ "engines": {
47
+ "node": ">=18.0.0"
48
+ },
49
+ "files": [
50
+ "dist/**/*",
51
+ "src/**/*",
52
+ "LICENSE",
53
+ "README.md"
54
+ ],
55
+ "publishConfig": {
56
+ "access": "public"
57
+ }
58
+ }
@@ -0,0 +1,141 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2024 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ // Include this first to auto-register Crypto, Network and Time Node.js implementations
8
+ import { Logger, StorageContext, StorageManager } from "@matter/general";
9
+ import { StorageBackendDisk } from "@matter/nodejs";
10
+ import { CommissioningController, MatterServer } from "@project-chip/matter.js";
11
+ import { NodeId } from "@project-chip/matter.js/datatype";
12
+ import { CommissioningControllerNodeOptions, PairedNode } from "@project-chip/matter.js/device";
13
+ import { EndpointInterface } from "@project-chip/matter.js/endpoint";
14
+
15
+ const logger = Logger.get("Node");
16
+
17
+ export class MatterNode {
18
+ private storageLocation?: string;
19
+ private storage?: StorageBackendDisk;
20
+ private storageManager?: StorageManager;
21
+ private storageContext?: StorageContext;
22
+
23
+ commissioningController?: CommissioningController;
24
+ private matterController?: MatterServer;
25
+
26
+ constructor(
27
+ private readonly nodeNum: number,
28
+ private readonly netInterface?: string,
29
+ ) {}
30
+
31
+ async initialize(resetStorage: boolean) {
32
+ /**
33
+ * Initialize the storage system.
34
+ *
35
+ * The storage manager is then also used by the Matter server, so this code block in general is required,
36
+ * but you can choose a different storage backend as long as it implements the required API.
37
+ */
38
+
39
+ this.storageLocation = `.matter-shell-${this.nodeNum}`;
40
+ this.storage = new StorageBackendDisk(this.storageLocation, false);
41
+ logger.info(`Storage location: ${this.storageLocation} (Directory)`);
42
+ this.storageManager = new StorageManager(this.storage);
43
+ await this.storageManager.initialize();
44
+ this.storageContext = this.storageManager.createContext("Node");
45
+ if (resetStorage) {
46
+ this.storage.clearAll([]);
47
+ }
48
+ }
49
+
50
+ get Store() {
51
+ if (!this.storageContext) {
52
+ throw new Error("Storage uninitialized");
53
+ }
54
+ return this.storageContext;
55
+ }
56
+
57
+ async close() {
58
+ await this.matterController?.close();
59
+ this.closeStorage();
60
+ }
61
+
62
+ closeStorage() {
63
+ try {
64
+ this.storage?.close();
65
+ process.exit(0);
66
+ } catch {
67
+ process.exit(1);
68
+ }
69
+ }
70
+
71
+ async start() {
72
+ if (this.storageManager === undefined) {
73
+ throw new Error("StorageManager not initialized"); // Should never happen
74
+ }
75
+ if (this.matterController !== undefined) {
76
+ return;
77
+ }
78
+ logger.info(`matter.js shell controller started for node ${this.nodeNum}`);
79
+
80
+ /**
81
+ * Create Matter Server and Controller Node
82
+ *
83
+ * To allow the device to be announced, found, paired and operated we need a MatterServer instance and add a
84
+ * CommissioningController to it and add the just created device instance to it.
85
+ * The Controller node defines the port where the server listens for the UDP packages of the Matter protocol
86
+ * and initializes deice specific certificates and such.
87
+ *
88
+ * The below logic also adds command handlers for commands of clusters that normally are handled internally
89
+ * like testEventTrigger (General Diagnostic Cluster) that can be implemented with the logic when these commands
90
+ * are called.
91
+ */
92
+
93
+ this.matterController = new MatterServer(this.storageManager, { mdnsInterface: this.netInterface });
94
+ this.commissioningController = new CommissioningController({
95
+ autoConnect: false,
96
+ });
97
+ await this.matterController.addCommissioningController(this.commissioningController);
98
+
99
+ /**
100
+ * Start the Matter Server
101
+ *
102
+ * After everything was plugged together we can start the server. When not delayed announcement is set for the
103
+ * CommissioningServer node then this command also starts the announcement of the device into the network.
104
+ */
105
+
106
+ await this.matterController.start();
107
+ }
108
+
109
+ async connectAndGetNodes(nodeIdStr?: string, connectOptions?: CommissioningControllerNodeOptions) {
110
+ await this.start();
111
+ const nodeId = nodeIdStr !== undefined ? NodeId(BigInt(nodeIdStr)) : undefined;
112
+
113
+ if (this.commissioningController === undefined) {
114
+ throw new Error("CommissioningController not initialized");
115
+ }
116
+ let nodes: PairedNode[];
117
+ if (nodeId === undefined) {
118
+ nodes = await this.commissioningController.connect(connectOptions);
119
+ } else {
120
+ nodes = [await this.commissioningController.connectNode(NodeId(nodeId), connectOptions)];
121
+ }
122
+ return nodes;
123
+ }
124
+
125
+ async iterateNodeDevices(
126
+ nodes: PairedNode[],
127
+ callback: (device: EndpointInterface, node: PairedNode) => Promise<void>,
128
+ endpointId?: number,
129
+ ) {
130
+ for (const node of nodes) {
131
+ let devices = node.getDevices();
132
+ if (endpointId !== undefined) {
133
+ devices = devices.filter(device => device.number === endpointId);
134
+ }
135
+
136
+ for (const device of devices) {
137
+ await callback(device, node);
138
+ }
139
+ }
140
+ }
141
+ }