@attraccess/plugin-matter 0.4.0-nightly.1188.1 → 0.5.0
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/index.js +1080 -1381
- package/frontend/{__federation_expose_Plugin-C8YKt0vo.js → __federation_expose_Plugin-BhusgEmE.js} +102 -147
- package/frontend/remoteEntry.js +1 -1
- package/frontend/style.css +0 -47
- package/package.json +10 -11
- package/dist/migrations.js +0 -328
package/dist/index.js
CHANGED
|
@@ -877,7 +877,7 @@ var require_coerce = __commonJS({
|
|
|
877
877
|
var SemVer = require_semver();
|
|
878
878
|
var parse7 = require_parse();
|
|
879
879
|
var { safeRe: re, t } = require_re();
|
|
880
|
-
var
|
|
880
|
+
var coerce2 = (version2, options) => {
|
|
881
881
|
if (version2 instanceof SemVer) {
|
|
882
882
|
return version2;
|
|
883
883
|
}
|
|
@@ -912,7 +912,7 @@ var require_coerce = __commonJS({
|
|
|
912
912
|
const build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
|
|
913
913
|
return parse7(`${major}.${minor}.${patch}${prerelease}${build}`, options);
|
|
914
914
|
};
|
|
915
|
-
module2.exports =
|
|
915
|
+
module2.exports = coerce2;
|
|
916
916
|
}
|
|
917
917
|
});
|
|
918
918
|
|
|
@@ -1259,7 +1259,7 @@ var require_range = __commonJS({
|
|
|
1259
1259
|
range = range.replace(BUILDSTRIPRE, "");
|
|
1260
1260
|
const memoOpts = (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) | (this.options.loose && FLAG_LOOSE);
|
|
1261
1261
|
const memoKey = memoOpts + ":" + range;
|
|
1262
|
-
const cached2 =
|
|
1262
|
+
const cached2 = cache2.get(memoKey);
|
|
1263
1263
|
if (cached2) {
|
|
1264
1264
|
return cached2;
|
|
1265
1265
|
}
|
|
@@ -1293,7 +1293,7 @@ var require_range = __commonJS({
|
|
|
1293
1293
|
rangeMap.delete("");
|
|
1294
1294
|
}
|
|
1295
1295
|
const result = [...rangeMap.values()];
|
|
1296
|
-
|
|
1296
|
+
cache2.set(memoKey, result);
|
|
1297
1297
|
return result;
|
|
1298
1298
|
}
|
|
1299
1299
|
intersects(range, options) {
|
|
@@ -1332,7 +1332,7 @@ var require_range = __commonJS({
|
|
|
1332
1332
|
};
|
|
1333
1333
|
module2.exports = Range;
|
|
1334
1334
|
var LRU = require_lrucache();
|
|
1335
|
-
var
|
|
1335
|
+
var cache2 = new LRU();
|
|
1336
1336
|
var parseOptions = require_parse_options();
|
|
1337
1337
|
var Comparator = require_comparator();
|
|
1338
1338
|
var debug = require_debug();
|
|
@@ -2189,7 +2189,7 @@ var require_semver2 = __commonJS({
|
|
|
2189
2189
|
var gte = require_gte();
|
|
2190
2190
|
var lte = require_lte();
|
|
2191
2191
|
var cmp = require_cmp();
|
|
2192
|
-
var
|
|
2192
|
+
var coerce2 = require_coerce();
|
|
2193
2193
|
var truncate = require_truncate();
|
|
2194
2194
|
var Comparator = require_comparator();
|
|
2195
2195
|
var Range = require_range();
|
|
@@ -2228,7 +2228,7 @@ var require_semver2 = __commonJS({
|
|
|
2228
2228
|
gte,
|
|
2229
2229
|
lte,
|
|
2230
2230
|
cmp,
|
|
2231
|
-
coerce,
|
|
2231
|
+
coerce: coerce2,
|
|
2232
2232
|
truncate,
|
|
2233
2233
|
Comparator,
|
|
2234
2234
|
Range,
|
|
@@ -5991,7 +5991,7 @@ __export(plugin_exports, {
|
|
|
5991
5991
|
module.exports = __toCommonJS(plugin_exports);
|
|
5992
5992
|
|
|
5993
5993
|
// backend/backup/controller.ts
|
|
5994
|
-
var
|
|
5994
|
+
var import_plugins_backend_sdk6 = require("@attraccess/plugins-backend-sdk");
|
|
5995
5995
|
var import_common14 = require("@nestjs/common");
|
|
5996
5996
|
|
|
5997
5997
|
// backend/permissions.ts
|
|
@@ -6138,7 +6138,7 @@ var MATTER_OPERATIONS = {
|
|
|
6138
6138
|
};
|
|
6139
6139
|
|
|
6140
6140
|
// backend/connection/controller.ts
|
|
6141
|
-
var
|
|
6141
|
+
var import_plugins_backend_sdk3 = require("@attraccess/plugins-backend-sdk");
|
|
6142
6142
|
var import_common3 = require("@nestjs/common");
|
|
6143
6143
|
|
|
6144
6144
|
// backend/connection/connection.service.ts
|
|
@@ -6858,8 +6858,8 @@ function cleanRegex(source) {
|
|
|
6858
6858
|
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
6859
6859
|
return source.slice(start, end);
|
|
6860
6860
|
}
|
|
6861
|
-
function floatSafeRemainder(val,
|
|
6862
|
-
const ratio = val /
|
|
6861
|
+
function floatSafeRemainder(val, step2) {
|
|
6862
|
+
const ratio = val / step2;
|
|
6863
6863
|
const roundedRatio = Math.round(ratio);
|
|
6864
6864
|
const tolerance = 4 * Number.EPSILON * Math.max(Math.abs(ratio), 1);
|
|
6865
6865
|
if (Math.abs(ratio - roundedRatio) < tolerance)
|
|
@@ -7466,9 +7466,9 @@ var Class = class {
|
|
|
7466
7466
|
constructor(..._args) {
|
|
7467
7467
|
}
|
|
7468
7468
|
};
|
|
7469
|
-
function members(proto,
|
|
7470
|
-
for (const key in
|
|
7471
|
-
const desc = Object.getOwnPropertyDescriptor(
|
|
7469
|
+
function members(proto, table2) {
|
|
7470
|
+
for (const key in table2) {
|
|
7471
|
+
const desc = Object.getOwnPropertyDescriptor(table2, key);
|
|
7472
7472
|
if (desc.get)
|
|
7473
7473
|
Object.defineProperty(proto, key, { ...desc, enumerable: false });
|
|
7474
7474
|
else
|
|
@@ -7483,10 +7483,10 @@ function hide(inst, key, value) {
|
|
|
7483
7483
|
return own(inst, key, value, false);
|
|
7484
7484
|
}
|
|
7485
7485
|
// @__NO_SIDE_EFFECTS__
|
|
7486
|
-
function derived(computes,
|
|
7486
|
+
function derived(computes, table2) {
|
|
7487
7487
|
for (const key in computes) {
|
|
7488
7488
|
const compute = computes[key];
|
|
7489
|
-
Object.defineProperty(
|
|
7489
|
+
Object.defineProperty(table2, key, {
|
|
7490
7490
|
configurable: true,
|
|
7491
7491
|
enumerable: true,
|
|
7492
7492
|
get() {
|
|
@@ -7497,7 +7497,7 @@ function derived(computes, table) {
|
|
|
7497
7497
|
}
|
|
7498
7498
|
});
|
|
7499
7499
|
}
|
|
7500
|
-
return
|
|
7500
|
+
return table2;
|
|
7501
7501
|
}
|
|
7502
7502
|
function defineBound(proto, key, fn) {
|
|
7503
7503
|
Object.defineProperty(proto, key, {
|
|
@@ -10192,7 +10192,7 @@ function handleIntersectionResults(result, left, right) {
|
|
|
10192
10192
|
if (!collect(iss, "r"))
|
|
10193
10193
|
result.issues.push(iss);
|
|
10194
10194
|
}
|
|
10195
|
-
const bothKeys = [...unrecKeys].filter(([,
|
|
10195
|
+
const bothKeys = [...unrecKeys].filter(([, f2]) => f2.l && f2.r).map(([k]) => k);
|
|
10196
10196
|
if (bothKeys.length) {
|
|
10197
10197
|
const aggregated = unrecIssue ? bothKeys.filter((k) => unrecIssue.keys.includes(k)) : [];
|
|
10198
10198
|
if (aggregated.length)
|
|
@@ -19071,8 +19071,8 @@ var $ZodRegistry = class {
|
|
|
19071
19071
|
if (p) {
|
|
19072
19072
|
const pm = { ...this.get(p) ?? {} };
|
|
19073
19073
|
delete pm.id;
|
|
19074
|
-
const
|
|
19075
|
-
return Object.keys(
|
|
19074
|
+
const f2 = { ...pm, ...this._map.get(schema) };
|
|
19075
|
+
return Object.keys(f2).length ? f2 : void 0;
|
|
19076
19076
|
}
|
|
19077
19077
|
return this._map.get(schema);
|
|
19078
19078
|
}
|
|
@@ -25646,21 +25646,21 @@ function visit(schema, fnOrHandlers) {
|
|
|
25646
25646
|
const h = fnOrHandlers[node2._zod.def.type];
|
|
25647
25647
|
return h ? h(node2, rewritten) : node2;
|
|
25648
25648
|
};
|
|
25649
|
-
const
|
|
25649
|
+
const cache2 = /* @__PURE__ */ new Map();
|
|
25650
25650
|
function run(s) {
|
|
25651
|
-
const cached2 =
|
|
25651
|
+
const cached2 = cache2.get(s);
|
|
25652
25652
|
if (cached2 === RESOLVING) {
|
|
25653
25653
|
return new $ZodLazy({
|
|
25654
25654
|
type: "lazy",
|
|
25655
|
-
getter: () =>
|
|
25655
|
+
getter: () => cache2.get(s)
|
|
25656
25656
|
});
|
|
25657
25657
|
}
|
|
25658
25658
|
if (cached2 !== void 0)
|
|
25659
25659
|
return cached2;
|
|
25660
|
-
|
|
25660
|
+
cache2.set(s, RESOLVING);
|
|
25661
25661
|
const inner = mapInner(s);
|
|
25662
25662
|
const mapped = fn(inner, inner !== s);
|
|
25663
|
-
|
|
25663
|
+
cache2.set(s, mapped);
|
|
25664
25664
|
return mapped;
|
|
25665
25665
|
}
|
|
25666
25666
|
function mapInner(s) {
|
|
@@ -25936,9 +25936,9 @@ var supportedCombinationSchema = external_exports.strictObject({
|
|
|
25936
25936
|
var COMPATIBILITY_TABLE = [
|
|
25937
25937
|
{
|
|
25938
25938
|
wireVersion: WIRE_VERSION,
|
|
25939
|
-
attraccess: "^
|
|
25940
|
-
plugin: "0.
|
|
25941
|
-
sidecar: "0.
|
|
25939
|
+
attraccess: "^2.0.0-0",
|
|
25940
|
+
plugin: "0.5.0-alpha.0",
|
|
25941
|
+
sidecar: "0.5.0-alpha.0",
|
|
25942
25942
|
matterJs: "0.18.0"
|
|
25943
25943
|
}
|
|
25944
25944
|
];
|
|
@@ -27121,7 +27121,7 @@ var SidecarHttpClient = class {
|
|
|
27121
27121
|
if (!checked.success) throw new SidecarRequestError("Invalid path parameters.", { code: "validation_failed" });
|
|
27122
27122
|
return checked.data;
|
|
27123
27123
|
}
|
|
27124
|
-
send(method, path, payload, options,
|
|
27124
|
+
send(method, path, payload, options, physical2, responseLimit) {
|
|
27125
27125
|
const timeoutMs = options.timeoutMs ?? this.defaultTimeoutMs;
|
|
27126
27126
|
const correlationId = options.correlationId ?? (0, import_node_crypto2.randomUUID)();
|
|
27127
27127
|
const headers = this.headers(correlationId, timeoutMs);
|
|
@@ -27136,7 +27136,7 @@ var SidecarHttpClient = class {
|
|
|
27136
27136
|
return new Promise((resolve, reject) => {
|
|
27137
27137
|
let settled = false;
|
|
27138
27138
|
let connected = false;
|
|
27139
|
-
const uncertain = () =>
|
|
27139
|
+
const uncertain = () => physical2 && connected;
|
|
27140
27140
|
const finish = (action) => {
|
|
27141
27141
|
if (settled) return;
|
|
27142
27142
|
settled = true;
|
|
@@ -27160,7 +27160,7 @@ var SidecarHttpClient = class {
|
|
|
27160
27160
|
status,
|
|
27161
27161
|
text,
|
|
27162
27162
|
typeof header === "string" ? header : null,
|
|
27163
|
-
|
|
27163
|
+
physical2 ? "uncertain" : void 0
|
|
27164
27164
|
)
|
|
27165
27165
|
)
|
|
27166
27166
|
);
|
|
@@ -27187,9 +27187,9 @@ var SidecarHttpClient = class {
|
|
|
27187
27187
|
req.destroy();
|
|
27188
27188
|
finish(
|
|
27189
27189
|
() => reject(
|
|
27190
|
-
new SidecarTimeoutError(
|
|
27190
|
+
new SidecarTimeoutError(physical2 ? `The request timed out. ${UNCERTAIN_HINT}` : "The request timed out.", {
|
|
27191
27191
|
correlationId,
|
|
27192
|
-
...
|
|
27192
|
+
...physical2 ? { outcome: "uncertain" } : {}
|
|
27193
27193
|
})
|
|
27194
27194
|
)
|
|
27195
27195
|
);
|
|
@@ -27488,452 +27488,345 @@ var PLUGIN_CONTEXT = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
|
|
|
27488
27488
|
var import_common = require("@nestjs/common");
|
|
27489
27489
|
var import_node_crypto4 = require("node:crypto");
|
|
27490
27490
|
|
|
27491
|
-
// backend/
|
|
27491
|
+
// backend/plugin-storage/tables.ts
|
|
27492
27492
|
var import_plugins_backend_sdk2 = require("@attraccess/plugins-backend-sdk");
|
|
27493
|
-
var
|
|
27494
|
-
};
|
|
27495
|
-
|
|
27496
|
-
|
|
27497
|
-
|
|
27498
|
-
|
|
27499
|
-
|
|
27500
|
-
|
|
27501
|
-
|
|
27502
|
-
|
|
27503
|
-
|
|
27504
|
-
|
|
27505
|
-
|
|
27506
|
-
],
|
|
27507
|
-
|
|
27508
|
-
|
|
27509
|
-
|
|
27510
|
-
|
|
27511
|
-
|
|
27512
|
-
|
|
27513
|
-
|
|
27514
|
-
|
|
27515
|
-
|
|
27516
|
-
|
|
27517
|
-
|
|
27518
|
-
|
|
27519
|
-
|
|
27520
|
-
|
|
27521
|
-
|
|
27522
|
-
|
|
27523
|
-
|
|
27524
|
-
|
|
27525
|
-
|
|
27526
|
-
|
|
27527
|
-
|
|
27528
|
-
|
|
27529
|
-
|
|
27530
|
-
|
|
27531
|
-
|
|
27532
|
-
}
|
|
27533
|
-
|
|
27534
|
-
|
|
27535
|
-
|
|
27536
|
-
|
|
27537
|
-
|
|
27538
|
-
|
|
27539
|
-
|
|
27540
|
-
|
|
27541
|
-
|
|
27542
|
-
|
|
27543
|
-
|
|
27544
|
-
|
|
27545
|
-
|
|
27546
|
-
|
|
27547
|
-
|
|
27548
|
-
|
|
27549
|
-
|
|
27550
|
-
|
|
27551
|
-
|
|
27552
|
-
|
|
27553
|
-
|
|
27554
|
-
|
|
27555
|
-
|
|
27556
|
-
|
|
27557
|
-
|
|
27558
|
-
|
|
27559
|
-
|
|
27560
|
-
|
|
27561
|
-
|
|
27562
|
-
|
|
27563
|
-
|
|
27564
|
-
|
|
27565
|
-
|
|
27566
|
-
|
|
27567
|
-
|
|
27568
|
-
|
|
27569
|
-
|
|
27570
|
-
|
|
27571
|
-
|
|
27572
|
-
|
|
27573
|
-
|
|
27574
|
-
|
|
27575
|
-
|
|
27576
|
-
|
|
27577
|
-
|
|
27578
|
-
|
|
27579
|
-
|
|
27580
|
-
|
|
27581
|
-
|
|
27582
|
-
|
|
27583
|
-
|
|
27584
|
-
|
|
27585
|
-
|
|
27586
|
-
|
|
27587
|
-
|
|
27588
|
-
|
|
27589
|
-
],
|
|
27590
|
-
|
|
27591
|
-
|
|
27592
|
-
|
|
27593
|
-
|
|
27594
|
-
|
|
27595
|
-
|
|
27596
|
-
|
|
27597
|
-
|
|
27598
|
-
|
|
27599
|
-
|
|
27600
|
-
|
|
27601
|
-
|
|
27602
|
-
|
|
27603
|
-
|
|
27604
|
-
|
|
27605
|
-
|
|
27606
|
-
|
|
27607
|
-
|
|
27608
|
-
|
|
27609
|
-
|
|
27610
|
-
|
|
27611
|
-
|
|
27612
|
-
|
|
27613
|
-
|
|
27614
|
-
|
|
27615
|
-
|
|
27616
|
-
|
|
27617
|
-
|
|
27618
|
-
|
|
27619
|
-
|
|
27620
|
-
|
|
27621
|
-
|
|
27622
|
-
|
|
27623
|
-
|
|
27624
|
-
|
|
27625
|
-
|
|
27626
|
-
|
|
27627
|
-
|
|
27628
|
-
|
|
27629
|
-
|
|
27630
|
-
|
|
27631
|
-
|
|
27632
|
-
|
|
27633
|
-
|
|
27634
|
-
|
|
27635
|
-
|
|
27636
|
-
|
|
27637
|
-
|
|
27638
|
-
|
|
27639
|
-
|
|
27640
|
-
|
|
27641
|
-
|
|
27642
|
-
|
|
27643
|
-
|
|
27644
|
-
|
|
27645
|
-
|
|
27646
|
-
|
|
27647
|
-
|
|
27648
|
-
|
|
27649
|
-
|
|
27650
|
-
|
|
27651
|
-
|
|
27652
|
-
|
|
27653
|
-
|
|
27654
|
-
|
|
27655
|
-
|
|
27656
|
-
|
|
27657
|
-
|
|
27658
|
-
|
|
27659
|
-
|
|
27660
|
-
|
|
27661
|
-
|
|
27662
|
-
|
|
27663
|
-
|
|
27664
|
-
|
|
27665
|
-
|
|
27666
|
-
|
|
27667
|
-
|
|
27668
|
-
|
|
27669
|
-
|
|
27670
|
-
|
|
27671
|
-
|
|
27672
|
-
|
|
27673
|
-
|
|
27674
|
-
|
|
27675
|
-
|
|
27676
|
-
|
|
27677
|
-
|
|
27678
|
-
|
|
27679
|
-
|
|
27680
|
-
|
|
27681
|
-
|
|
27682
|
-
|
|
27683
|
-
|
|
27684
|
-
|
|
27685
|
-
|
|
27686
|
-
|
|
27687
|
-
|
|
27688
|
-
|
|
27689
|
-
|
|
27690
|
-
|
|
27691
|
-
|
|
27692
|
-
|
|
27693
|
-
|
|
27694
|
-
|
|
27695
|
-
|
|
27696
|
-
|
|
27697
|
-
|
|
27698
|
-
|
|
27699
|
-
|
|
27700
|
-
|
|
27701
|
-
|
|
27702
|
-
|
|
27703
|
-
|
|
27704
|
-
|
|
27705
|
-
|
|
27706
|
-
|
|
27707
|
-
|
|
27708
|
-
|
|
27709
|
-
|
|
27710
|
-
|
|
27711
|
-
|
|
27712
|
-
|
|
27713
|
-
|
|
27714
|
-
|
|
27715
|
-
|
|
27716
|
-
|
|
27717
|
-
|
|
27718
|
-
|
|
27719
|
-
|
|
27720
|
-
|
|
27721
|
-
|
|
27722
|
-
|
|
27723
|
-
|
|
27724
|
-
|
|
27725
|
-
|
|
27726
|
-
|
|
27727
|
-
|
|
27728
|
-
|
|
27729
|
-
|
|
27730
|
-
|
|
27731
|
-
|
|
27732
|
-
|
|
27733
|
-
|
|
27734
|
-
|
|
27735
|
-
|
|
27736
|
-
|
|
27737
|
-
|
|
27738
|
-
|
|
27739
|
-
|
|
27740
|
-
|
|
27741
|
-
|
|
27742
|
-
|
|
27743
|
-
__decorateClass([
|
|
27744
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "integer", name: "source_cluster_id" })
|
|
27745
|
-
], MatterEndpointCapability.prototype, "sourceClusterId", 2);
|
|
27746
|
-
__decorateClass([
|
|
27747
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "text" })
|
|
27748
|
-
], MatterEndpointCapability.prototype, "details", 2);
|
|
27749
|
-
MatterEndpointCapability = __decorateClass([
|
|
27750
|
-
(0, import_plugins_backend_sdk2.Entity)({ name: "plugin_matter_endpoint_capabilities" })
|
|
27751
|
-
], MatterEndpointCapability);
|
|
27752
|
-
var MatterEndpointState = class {
|
|
27493
|
+
var physical = (name) => `plugin_matter_${name}`;
|
|
27494
|
+
var iso = (column) => import_plugins_backend_sdk2.f.string({ column });
|
|
27495
|
+
var connection = (0, import_plugins_backend_sdk2.table)(
|
|
27496
|
+
{
|
|
27497
|
+
id: import_plugins_backend_sdk2.f.integer(),
|
|
27498
|
+
// Validation allows URLs up to 2048 characters (connection/validation.ts); the legacy column is unbounded.
|
|
27499
|
+
url: import_plugins_backend_sdk2.f.text(),
|
|
27500
|
+
encryptedCredential: import_plugins_backend_sdk2.f.text({ column: "encrypted_credential" }),
|
|
27501
|
+
caCertificate: import_plugins_backend_sdk2.f.text({ column: "ca_certificate" }).optional(),
|
|
27502
|
+
credentialUpdatedAt: iso("credential_updated_at"),
|
|
27503
|
+
updatedAt: iso("updated_at"),
|
|
27504
|
+
updatedBy: import_plugins_backend_sdk2.f.integer({ column: "updated_by" }).optional()
|
|
27505
|
+
},
|
|
27506
|
+
{ primaryKey: ["id"], physicalName: physical("connection") }
|
|
27507
|
+
);
|
|
27508
|
+
var fabrics = (0, import_plugins_backend_sdk2.table)(
|
|
27509
|
+
{
|
|
27510
|
+
id: import_plugins_backend_sdk2.f.string(),
|
|
27511
|
+
fabricId: import_plugins_backend_sdk2.f.string({ column: "fabric_id" }),
|
|
27512
|
+
label: import_plugins_backend_sdk2.f.string().optional(),
|
|
27513
|
+
firstSeenAt: iso("first_seen_at"),
|
|
27514
|
+
lastSeenAt: iso("last_seen_at"),
|
|
27515
|
+
status: import_plugins_backend_sdk2.f.string(),
|
|
27516
|
+
retiredAt: iso("retired_at").optional(),
|
|
27517
|
+
fabricGeneration: import_plugins_backend_sdk2.f.integer({ column: "fabric_generation" }).optional(),
|
|
27518
|
+
storageInstanceId: import_plugins_backend_sdk2.f.string({ column: "storage_instance_id" }).optional(),
|
|
27519
|
+
rootCertFingerprint: import_plugins_backend_sdk2.f.string({ column: "root_cert_fingerprint" }).optional(),
|
|
27520
|
+
recordedAt: iso("recorded_at").optional()
|
|
27521
|
+
},
|
|
27522
|
+
{ primaryKey: ["id"], physicalName: physical("fabrics") }
|
|
27523
|
+
);
|
|
27524
|
+
var nodes = (0, import_plugins_backend_sdk2.table)(
|
|
27525
|
+
{
|
|
27526
|
+
id: import_plugins_backend_sdk2.f.string(),
|
|
27527
|
+
fabricRef: import_plugins_backend_sdk2.f.string({ column: "fabric_ref" }),
|
|
27528
|
+
nodeId: import_plugins_backend_sdk2.f.string({ column: "node_id" }),
|
|
27529
|
+
vendorId: import_plugins_backend_sdk2.f.integer({ column: "vendor_id" }).optional(),
|
|
27530
|
+
productId: import_plugins_backend_sdk2.f.integer({ column: "product_id" }).optional(),
|
|
27531
|
+
vendorName: import_plugins_backend_sdk2.f.string({ column: "vendor_name" }).optional(),
|
|
27532
|
+
productName: import_plugins_backend_sdk2.f.string({ column: "product_name" }).optional(),
|
|
27533
|
+
serialNumber: import_plugins_backend_sdk2.f.string({ column: "serial_number" }).optional(),
|
|
27534
|
+
uniqueId: import_plugins_backend_sdk2.f.string({ column: "unique_id" }).optional(),
|
|
27535
|
+
hardwareVersion: import_plugins_backend_sdk2.f.integer({ column: "hardware_version" }).optional(),
|
|
27536
|
+
softwareVersion: import_plugins_backend_sdk2.f.integer({ column: "software_version" }).optional(),
|
|
27537
|
+
softwareVersionString: import_plugins_backend_sdk2.f.string({ column: "software_version_string" }).optional(),
|
|
27538
|
+
attestationStatus: import_plugins_backend_sdk2.f.string({ column: "attestation_status" }).optional(),
|
|
27539
|
+
attestationCheckedAt: iso("attestation_checked_at").optional(),
|
|
27540
|
+
displayName: import_plugins_backend_sdk2.f.string({ length: 100, column: "display_name" }).optional(),
|
|
27541
|
+
description: import_plugins_backend_sdk2.f.string({ length: 500 }).optional(),
|
|
27542
|
+
location: import_plugins_backend_sdk2.f.string({ length: 100 }).optional(),
|
|
27543
|
+
lifecycleState: import_plugins_backend_sdk2.f.string({ column: "lifecycle_state" }),
|
|
27544
|
+
detachedReason: import_plugins_backend_sdk2.f.string({ column: "detached_reason" }).optional(),
|
|
27545
|
+
reachable: import_plugins_backend_sdk2.f.boolean().optional(),
|
|
27546
|
+
firstSeenAt: iso("first_seen_at"),
|
|
27547
|
+
lastSeenAt: iso("last_seen_at"),
|
|
27548
|
+
claimedAt: iso("claimed_at").optional(),
|
|
27549
|
+
claimedBy: import_plugins_backend_sdk2.f.integer({ column: "claimed_by" }).optional(),
|
|
27550
|
+
detachedAt: iso("detached_at").optional(),
|
|
27551
|
+
archivedAt: iso("archived_at").optional(),
|
|
27552
|
+
archivedBy: import_plugins_backend_sdk2.f.integer({ column: "archived_by" }).optional(),
|
|
27553
|
+
removedAt: iso("removed_at").optional(),
|
|
27554
|
+
removedBy: import_plugins_backend_sdk2.f.integer({ column: "removed_by" }).optional(),
|
|
27555
|
+
removalReason: import_plugins_backend_sdk2.f.string({ column: "removal_reason" }).optional(),
|
|
27556
|
+
mergedInto: import_plugins_backend_sdk2.f.string({ column: "merged_into" }).optional(),
|
|
27557
|
+
createdAt: iso("created_at"),
|
|
27558
|
+
updatedAt: iso("updated_at")
|
|
27559
|
+
},
|
|
27560
|
+
{
|
|
27561
|
+
primaryKey: ["id"],
|
|
27562
|
+
indexes: [{ name: "IDX_plugin_matter_nodes_lifecycle", fields: ["lifecycleState"] }],
|
|
27563
|
+
physicalName: physical("nodes")
|
|
27564
|
+
}
|
|
27565
|
+
);
|
|
27566
|
+
var endpoints = (0, import_plugins_backend_sdk2.table)(
|
|
27567
|
+
{
|
|
27568
|
+
id: import_plugins_backend_sdk2.f.string(),
|
|
27569
|
+
nodeRef: import_plugins_backend_sdk2.f.string({ column: "node_ref" }),
|
|
27570
|
+
endpointId: import_plugins_backend_sdk2.f.integer({ column: "endpoint_id" }),
|
|
27571
|
+
parentEndpointId: import_plugins_backend_sdk2.f.integer({ column: "parent_endpoint_id" }).optional(),
|
|
27572
|
+
deviceTypes: import_plugins_backend_sdk2.f.text({ column: "device_types" }),
|
|
27573
|
+
profile: import_plugins_backend_sdk2.f.string(),
|
|
27574
|
+
displayName: import_plugins_backend_sdk2.f.string({ length: 100, column: "display_name" }).optional(),
|
|
27575
|
+
description: import_plugins_backend_sdk2.f.string({ length: 500 }).optional(),
|
|
27576
|
+
location: import_plugins_backend_sdk2.f.string({ length: 100 }).optional(),
|
|
27577
|
+
bridged: import_plugins_backend_sdk2.f.boolean().optional(),
|
|
27578
|
+
bridgedUniqueId: import_plugins_backend_sdk2.f.string({ column: "bridged_unique_id" }).optional(),
|
|
27579
|
+
bridgedNodeLabel: import_plugins_backend_sdk2.f.string({ column: "bridged_node_label" }).optional(),
|
|
27580
|
+
bridgedVendorName: import_plugins_backend_sdk2.f.string({ column: "bridged_vendor_name" }).optional(),
|
|
27581
|
+
bridgedProductName: import_plugins_backend_sdk2.f.string({ column: "bridged_product_name" }).optional(),
|
|
27582
|
+
bridgedSerialNumber: import_plugins_backend_sdk2.f.string({ column: "bridged_serial_number" }).optional(),
|
|
27583
|
+
bridgedReachable: import_plugins_backend_sdk2.f.boolean({ column: "bridged_reachable" }).optional(),
|
|
27584
|
+
firstSeenAt: iso("first_seen_at"),
|
|
27585
|
+
lastSeenAt: iso("last_seen_at"),
|
|
27586
|
+
removedAt: iso("removed_at").optional(),
|
|
27587
|
+
removalReason: import_plugins_backend_sdk2.f.string({ column: "removal_reason" }).optional()
|
|
27588
|
+
},
|
|
27589
|
+
{ primaryKey: ["id"], physicalName: physical("endpoints") }
|
|
27590
|
+
);
|
|
27591
|
+
var endpointClusters = (0, import_plugins_backend_sdk2.table)(
|
|
27592
|
+
{
|
|
27593
|
+
id: import_plugins_backend_sdk2.f.string(),
|
|
27594
|
+
endpointRef: import_plugins_backend_sdk2.f.string({ column: "endpoint_ref" }),
|
|
27595
|
+
clusterId: import_plugins_backend_sdk2.f.integer({ column: "cluster_id" }),
|
|
27596
|
+
role: import_plugins_backend_sdk2.f.string(),
|
|
27597
|
+
revision: import_plugins_backend_sdk2.f.integer().optional(),
|
|
27598
|
+
featureMap: import_plugins_backend_sdk2.f.integer({ column: "feature_map" }).optional(),
|
|
27599
|
+
attributeIds: import_plugins_backend_sdk2.f.text({ column: "attribute_ids" }),
|
|
27600
|
+
acceptedCommandIds: import_plugins_backend_sdk2.f.text({ column: "accepted_command_ids" }),
|
|
27601
|
+
removedAt: iso("removed_at").optional()
|
|
27602
|
+
},
|
|
27603
|
+
{ primaryKey: ["id"], physicalName: physical("endpoint_clusters") }
|
|
27604
|
+
);
|
|
27605
|
+
var endpointCapabilities = (0, import_plugins_backend_sdk2.table)(
|
|
27606
|
+
{
|
|
27607
|
+
id: import_plugins_backend_sdk2.f.string(),
|
|
27608
|
+
endpointRef: import_plugins_backend_sdk2.f.string({ column: "endpoint_ref" }),
|
|
27609
|
+
capability: import_plugins_backend_sdk2.f.string(),
|
|
27610
|
+
sourceClusterId: import_plugins_backend_sdk2.f.integer({ column: "source_cluster_id" }),
|
|
27611
|
+
details: import_plugins_backend_sdk2.f.text()
|
|
27612
|
+
},
|
|
27613
|
+
{
|
|
27614
|
+
primaryKey: ["id"],
|
|
27615
|
+
indexes: [{ name: "UQ_plugin_matter_endpoint_capabilities", fields: ["endpointRef", "capability"], unique: true }],
|
|
27616
|
+
physicalName: physical("endpoint_capabilities")
|
|
27617
|
+
}
|
|
27618
|
+
);
|
|
27619
|
+
var endpointState = (0, import_plugins_backend_sdk2.table)(
|
|
27620
|
+
{
|
|
27621
|
+
id: import_plugins_backend_sdk2.f.string(),
|
|
27622
|
+
endpointRef: import_plugins_backend_sdk2.f.string({ column: "endpoint_ref" }),
|
|
27623
|
+
stateKey: import_plugins_backend_sdk2.f.string({ column: "state_key" }),
|
|
27624
|
+
reportedValue: import_plugins_backend_sdk2.f.text({ column: "reported_value" }).optional(),
|
|
27625
|
+
reportedAt: iso("reported_at").optional(),
|
|
27626
|
+
receivedAt: iso("received_at").optional(),
|
|
27627
|
+
source: import_plugins_backend_sdk2.f.string().optional(),
|
|
27628
|
+
quality: import_plugins_backend_sdk2.f.string().optional(),
|
|
27629
|
+
staleAfterMs: import_plugins_backend_sdk2.f.integer({ column: "stale_after_ms" }).withDefault(6e5),
|
|
27630
|
+
requestedValue: import_plugins_backend_sdk2.f.text({ column: "requested_value" }).optional(),
|
|
27631
|
+
requestedAt: iso("requested_at").optional(),
|
|
27632
|
+
requestedBy: import_plugins_backend_sdk2.f.integer({ column: "requested_by" }).optional(),
|
|
27633
|
+
requestId: import_plugins_backend_sdk2.f.string({ column: "request_id" }).optional(),
|
|
27634
|
+
correlationId: import_plugins_backend_sdk2.f.string({ column: "correlation_id" }).optional(),
|
|
27635
|
+
commandState: import_plugins_backend_sdk2.f.string({ column: "command_state" }).withDefault("none"),
|
|
27636
|
+
acceptedAt: iso("accepted_at").optional(),
|
|
27637
|
+
commandReportedAt: iso("command_reported_at").optional(),
|
|
27638
|
+
externalChangeAt: iso("external_change_at").optional(),
|
|
27639
|
+
externalChangeValue: import_plugins_backend_sdk2.f.text({ column: "external_change_value" }).optional(),
|
|
27640
|
+
faultCode: import_plugins_backend_sdk2.f.string({ column: "fault_code" }).optional(),
|
|
27641
|
+
// The sidecar reports fault messages of up to 256 characters (matter-contract `device.state`).
|
|
27642
|
+
faultMessage: import_plugins_backend_sdk2.f.text({ column: "fault_message" }).optional(),
|
|
27643
|
+
faultAt: iso("fault_at").optional(),
|
|
27644
|
+
updatedAt: iso("updated_at")
|
|
27645
|
+
},
|
|
27646
|
+
{
|
|
27647
|
+
primaryKey: ["id"],
|
|
27648
|
+
indexes: [{ name: "UQ_plugin_matter_endpoint_state_key", fields: ["endpointRef", "stateKey"], unique: true }],
|
|
27649
|
+
physicalName: physical("endpoint_state")
|
|
27650
|
+
}
|
|
27651
|
+
);
|
|
27652
|
+
var commands = (0, import_plugins_backend_sdk2.table)(
|
|
27653
|
+
{
|
|
27654
|
+
requestId: import_plugins_backend_sdk2.f.string({ column: "request_id" }),
|
|
27655
|
+
endpointRef: import_plugins_backend_sdk2.f.string({ column: "endpoint_ref" }),
|
|
27656
|
+
clusterId: import_plugins_backend_sdk2.f.integer({ column: "cluster_id" }),
|
|
27657
|
+
commandId: import_plugins_backend_sdk2.f.integer({ column: "command_id" }),
|
|
27658
|
+
stateKey: import_plugins_backend_sdk2.f.string({ column: "state_key" }).optional(),
|
|
27659
|
+
requestedAt: iso("requested_at"),
|
|
27660
|
+
requestedBy: import_plugins_backend_sdk2.f.integer({ column: "requested_by" }).optional(),
|
|
27661
|
+
correlationId: import_plugins_backend_sdk2.f.string({ column: "correlation_id" }).optional(),
|
|
27662
|
+
outcome: import_plugins_backend_sdk2.f.string(),
|
|
27663
|
+
acceptedAt: iso("accepted_at").optional(),
|
|
27664
|
+
reportedAt: iso("reported_at").optional(),
|
|
27665
|
+
failureCode: import_plugins_backend_sdk2.f.string({ column: "failure_code" }).optional()
|
|
27666
|
+
},
|
|
27667
|
+
{
|
|
27668
|
+
primaryKey: ["requestId"],
|
|
27669
|
+
indexes: [{ name: "IDX_plugin_matter_commands_requested_at", fields: ["requestedAt", "requestId"] }],
|
|
27670
|
+
physicalName: physical("commands")
|
|
27671
|
+
}
|
|
27672
|
+
);
|
|
27673
|
+
var reconciliationStatus = (0, import_plugins_backend_sdk2.table)(
|
|
27674
|
+
{
|
|
27675
|
+
id: import_plugins_backend_sdk2.f.integer(),
|
|
27676
|
+
lastStartedAt: iso("last_started_at").optional(),
|
|
27677
|
+
lastFinishedAt: iso("last_finished_at").optional(),
|
|
27678
|
+
lastResult: import_plugins_backend_sdk2.f.string({ column: "last_result" }).optional(),
|
|
27679
|
+
lastSummary: import_plugins_backend_sdk2.f.text({ column: "last_summary" }).optional(),
|
|
27680
|
+
sidecarFabricId: import_plugins_backend_sdk2.f.string({ column: "sidecar_fabric_id" }).optional()
|
|
27681
|
+
},
|
|
27682
|
+
{ primaryKey: ["id"], physicalName: physical("reconciliation_status") }
|
|
27683
|
+
);
|
|
27684
|
+
var recoveryKeys = (0, import_plugins_backend_sdk2.table)(
|
|
27685
|
+
{
|
|
27686
|
+
id: import_plugins_backend_sdk2.f.string(),
|
|
27687
|
+
keyId: import_plugins_backend_sdk2.f.string({ column: "key_id" }),
|
|
27688
|
+
encryptedKey: import_plugins_backend_sdk2.f.text({ column: "encrypted_key" }),
|
|
27689
|
+
createdAt: iso("created_at"),
|
|
27690
|
+
acknowledgedAt: iso("acknowledged_at").optional(),
|
|
27691
|
+
retiredAt: iso("retired_at").optional()
|
|
27692
|
+
},
|
|
27693
|
+
{
|
|
27694
|
+
primaryKey: ["id"],
|
|
27695
|
+
indexes: [{ name: "UQ_plugin_matter_recovery_keys_key_id", fields: ["keyId"], unique: true }],
|
|
27696
|
+
physicalName: physical("recovery_keys")
|
|
27697
|
+
}
|
|
27698
|
+
);
|
|
27699
|
+
var backups = (0, import_plugins_backend_sdk2.table)(
|
|
27700
|
+
{
|
|
27701
|
+
id: import_plugins_backend_sdk2.f.string(),
|
|
27702
|
+
createdAt: iso("created_at"),
|
|
27703
|
+
trigger: import_plugins_backend_sdk2.f.string(),
|
|
27704
|
+
actor: import_plugins_backend_sdk2.f.integer().optional(),
|
|
27705
|
+
outcome: import_plugins_backend_sdk2.f.string(),
|
|
27706
|
+
reason: import_plugins_backend_sdk2.f.string().optional(),
|
|
27707
|
+
sizeBytes: import_plugins_backend_sdk2.f.integer({ column: "size_bytes" }).optional(),
|
|
27708
|
+
sha256: import_plugins_backend_sdk2.f.string().optional(),
|
|
27709
|
+
formatVersion: import_plugins_backend_sdk2.f.integer({ column: "format_version" }).optional(),
|
|
27710
|
+
pluginVersion: import_plugins_backend_sdk2.f.string({ column: "plugin_version" }).optional(),
|
|
27711
|
+
sidecarVersion: import_plugins_backend_sdk2.f.string({ column: "sidecar_version" }).optional(),
|
|
27712
|
+
matterJsVersion: import_plugins_backend_sdk2.f.string({ column: "matter_js_version" }).optional(),
|
|
27713
|
+
storageSchemaVersion: import_plugins_backend_sdk2.f.integer({ column: "storage_schema_version" }).optional(),
|
|
27714
|
+
pluginMigration: import_plugins_backend_sdk2.f.string({ column: "plugin_migration" }).optional(),
|
|
27715
|
+
fabricId: import_plugins_backend_sdk2.f.string({ column: "fabric_id" }).optional(),
|
|
27716
|
+
rootCertFingerprint: import_plugins_backend_sdk2.f.string({ column: "root_cert_fingerprint" }).optional(),
|
|
27717
|
+
fabricGeneration: import_plugins_backend_sdk2.f.integer({ column: "fabric_generation" }).optional(),
|
|
27718
|
+
storageInstanceId: import_plugins_backend_sdk2.f.string({ column: "storage_instance_id" }).optional(),
|
|
27719
|
+
recoveryKeyId: import_plugins_backend_sdk2.f.string({ column: "recovery_key_id" }).optional(),
|
|
27720
|
+
consistent: import_plugins_backend_sdk2.f.boolean().optional(),
|
|
27721
|
+
// The encrypted backup file, base64 in text: the neutral schema has no binary type, and the legacy column is a
|
|
27722
|
+
// `blob`. Rows written by 1.x hold raw bytes there; `plugin-storage/blob.ts` reads both.
|
|
27723
|
+
blob: import_plugins_backend_sdk2.f.text().optional()
|
|
27724
|
+
},
|
|
27725
|
+
{
|
|
27726
|
+
primaryKey: ["id"],
|
|
27727
|
+
indexes: [{ name: "IDX_plugin_matter_backups_created_at", fields: ["createdAt"] }],
|
|
27728
|
+
physicalName: physical("backups")
|
|
27729
|
+
}
|
|
27730
|
+
);
|
|
27731
|
+
var MATTER_BASELINE_TABLES = {
|
|
27732
|
+
connection,
|
|
27733
|
+
fabrics,
|
|
27734
|
+
nodes,
|
|
27735
|
+
endpoints,
|
|
27736
|
+
endpointClusters,
|
|
27737
|
+
endpointCapabilities,
|
|
27738
|
+
endpointState,
|
|
27739
|
+
commands,
|
|
27740
|
+
reconciliationStatus,
|
|
27741
|
+
recoveryKeys,
|
|
27742
|
+
backups
|
|
27753
27743
|
};
|
|
27754
|
-
|
|
27755
|
-
|
|
27756
|
-
|
|
27757
|
-
|
|
27758
|
-
|
|
27759
|
-
], MatterEndpointState.prototype, "endpointRef", 2);
|
|
27760
|
-
__decorateClass([
|
|
27761
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "state_key" })
|
|
27762
|
-
], MatterEndpointState.prototype, "stateKey", 2);
|
|
27763
|
-
__decorateClass([
|
|
27764
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "text", name: "reported_value", nullable: true })
|
|
27765
|
-
], MatterEndpointState.prototype, "reportedValue", 2);
|
|
27766
|
-
__decorateClass([
|
|
27767
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "reported_at", nullable: true })
|
|
27768
|
-
], MatterEndpointState.prototype, "reportedAt", 2);
|
|
27769
|
-
__decorateClass([
|
|
27770
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "received_at", nullable: true })
|
|
27771
|
-
], MatterEndpointState.prototype, "receivedAt", 2);
|
|
27772
|
-
__decorateClass([
|
|
27773
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", nullable: true })
|
|
27774
|
-
], MatterEndpointState.prototype, "source", 2);
|
|
27775
|
-
__decorateClass([
|
|
27776
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", nullable: true })
|
|
27777
|
-
], MatterEndpointState.prototype, "quality", 2);
|
|
27778
|
-
__decorateClass([
|
|
27779
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "integer", name: "stale_after_ms" })
|
|
27780
|
-
], MatterEndpointState.prototype, "staleAfterMs", 2);
|
|
27781
|
-
__decorateClass([
|
|
27782
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "text", name: "requested_value", nullable: true })
|
|
27783
|
-
], MatterEndpointState.prototype, "requestedValue", 2);
|
|
27784
|
-
__decorateClass([
|
|
27785
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "requested_at", nullable: true })
|
|
27786
|
-
], MatterEndpointState.prototype, "requestedAt", 2);
|
|
27787
|
-
__decorateClass([
|
|
27788
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "integer", name: "requested_by", nullable: true })
|
|
27789
|
-
], MatterEndpointState.prototype, "requestedBy", 2);
|
|
27790
|
-
__decorateClass([
|
|
27791
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "request_id", nullable: true })
|
|
27792
|
-
], MatterEndpointState.prototype, "requestId", 2);
|
|
27793
|
-
__decorateClass([
|
|
27794
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "correlation_id", nullable: true })
|
|
27795
|
-
], MatterEndpointState.prototype, "correlationId", 2);
|
|
27796
|
-
__decorateClass([
|
|
27797
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "command_state" })
|
|
27798
|
-
], MatterEndpointState.prototype, "commandState", 2);
|
|
27799
|
-
__decorateClass([
|
|
27800
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "accepted_at", nullable: true })
|
|
27801
|
-
], MatterEndpointState.prototype, "acceptedAt", 2);
|
|
27802
|
-
__decorateClass([
|
|
27803
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "command_reported_at", nullable: true })
|
|
27804
|
-
], MatterEndpointState.prototype, "commandReportedAt", 2);
|
|
27805
|
-
__decorateClass([
|
|
27806
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "external_change_at", nullable: true })
|
|
27807
|
-
], MatterEndpointState.prototype, "externalChangeAt", 2);
|
|
27808
|
-
__decorateClass([
|
|
27809
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "text", name: "external_change_value", nullable: true })
|
|
27810
|
-
], MatterEndpointState.prototype, "externalChangeValue", 2);
|
|
27811
|
-
__decorateClass([
|
|
27812
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "fault_code", nullable: true })
|
|
27813
|
-
], MatterEndpointState.prototype, "faultCode", 2);
|
|
27814
|
-
__decorateClass([
|
|
27815
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "fault_message", nullable: true })
|
|
27816
|
-
], MatterEndpointState.prototype, "faultMessage", 2);
|
|
27817
|
-
__decorateClass([
|
|
27818
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "fault_at", nullable: true })
|
|
27819
|
-
], MatterEndpointState.prototype, "faultAt", 2);
|
|
27820
|
-
__decorateClass([
|
|
27821
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "updated_at" })
|
|
27822
|
-
], MatterEndpointState.prototype, "updatedAt", 2);
|
|
27823
|
-
MatterEndpointState = __decorateClass([
|
|
27824
|
-
(0, import_plugins_backend_sdk2.Entity)({ name: "plugin_matter_endpoint_state" })
|
|
27825
|
-
], MatterEndpointState);
|
|
27826
|
-
var MatterCommand = class {
|
|
27744
|
+
var LOOKUP_INDEXES = {
|
|
27745
|
+
fabrics: [{ fields: ["fabricId"] }],
|
|
27746
|
+
nodes: [{ fields: ["fabricRef", "nodeId"] }],
|
|
27747
|
+
endpoints: [{ fields: ["nodeRef", "endpointId"] }],
|
|
27748
|
+
endpointClusters: [{ fields: ["endpointRef", "clusterId", "role"] }]
|
|
27827
27749
|
};
|
|
27828
|
-
|
|
27829
|
-
|
|
27830
|
-
|
|
27831
|
-
|
|
27832
|
-
|
|
27833
|
-
|
|
27834
|
-
|
|
27835
|
-
(
|
|
27836
|
-
|
|
27837
|
-
|
|
27838
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "integer", name: "command_id" })
|
|
27839
|
-
], MatterCommand.prototype, "commandId", 2);
|
|
27840
|
-
__decorateClass([
|
|
27841
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "state_key", nullable: true })
|
|
27842
|
-
], MatterCommand.prototype, "stateKey", 2);
|
|
27843
|
-
__decorateClass([
|
|
27844
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "requested_at" })
|
|
27845
|
-
], MatterCommand.prototype, "requestedAt", 2);
|
|
27846
|
-
__decorateClass([
|
|
27847
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "integer", name: "requested_by", nullable: true })
|
|
27848
|
-
], MatterCommand.prototype, "requestedBy", 2);
|
|
27849
|
-
__decorateClass([
|
|
27850
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "correlation_id", nullable: true })
|
|
27851
|
-
], MatterCommand.prototype, "correlationId", 2);
|
|
27852
|
-
__decorateClass([
|
|
27853
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar" })
|
|
27854
|
-
], MatterCommand.prototype, "outcome", 2);
|
|
27855
|
-
__decorateClass([
|
|
27856
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "accepted_at", nullable: true })
|
|
27857
|
-
], MatterCommand.prototype, "acceptedAt", 2);
|
|
27858
|
-
__decorateClass([
|
|
27859
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "reported_at", nullable: true })
|
|
27860
|
-
], MatterCommand.prototype, "reportedAt", 2);
|
|
27861
|
-
__decorateClass([
|
|
27862
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "failure_code", nullable: true })
|
|
27863
|
-
], MatterCommand.prototype, "failureCode", 2);
|
|
27864
|
-
MatterCommand = __decorateClass([
|
|
27865
|
-
(0, import_plugins_backend_sdk2.Entity)({ name: "plugin_matter_commands" })
|
|
27866
|
-
], MatterCommand);
|
|
27867
|
-
var RECONCILIATION_ROW_ID = 1;
|
|
27868
|
-
var MatterReconciliationStatus = class {
|
|
27750
|
+
var withIndexes = (definition, indexes) => ({
|
|
27751
|
+
...definition,
|
|
27752
|
+
indexes: [...definition.indexes, ...indexes]
|
|
27753
|
+
});
|
|
27754
|
+
var MATTER_TABLES = {
|
|
27755
|
+
...MATTER_BASELINE_TABLES,
|
|
27756
|
+
fabrics: withIndexes(fabrics, LOOKUP_INDEXES.fabrics),
|
|
27757
|
+
nodes: withIndexes(nodes, LOOKUP_INDEXES.nodes),
|
|
27758
|
+
endpoints: withIndexes(endpoints, LOOKUP_INDEXES.endpoints),
|
|
27759
|
+
endpointClusters: withIndexes(endpointClusters, LOOKUP_INDEXES.endpointClusters)
|
|
27869
27760
|
};
|
|
27870
|
-
|
|
27871
|
-
|
|
27872
|
-
|
|
27873
|
-
|
|
27874
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "last_started_at", nullable: true })
|
|
27875
|
-
], MatterReconciliationStatus.prototype, "lastStartedAt", 2);
|
|
27876
|
-
__decorateClass([
|
|
27877
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "last_finished_at", nullable: true })
|
|
27878
|
-
], MatterReconciliationStatus.prototype, "lastFinishedAt", 2);
|
|
27879
|
-
__decorateClass([
|
|
27880
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "last_result", nullable: true })
|
|
27881
|
-
], MatterReconciliationStatus.prototype, "lastResult", 2);
|
|
27882
|
-
__decorateClass([
|
|
27883
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "text", name: "last_summary", nullable: true })
|
|
27884
|
-
], MatterReconciliationStatus.prototype, "lastSummary", 2);
|
|
27885
|
-
__decorateClass([
|
|
27886
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", name: "sidecar_fabric_id", nullable: true })
|
|
27887
|
-
], MatterReconciliationStatus.prototype, "sidecarFabricId", 2);
|
|
27888
|
-
MatterReconciliationStatus = __decorateClass([
|
|
27889
|
-
(0, import_plugins_backend_sdk2.Entity)({ name: "plugin_matter_reconciliation_status" })
|
|
27890
|
-
], MatterReconciliationStatus);
|
|
27891
|
-
var DEVICE_ENTITIES = [
|
|
27892
|
-
MatterFabric,
|
|
27893
|
-
MatterNode,
|
|
27894
|
-
MatterEndpoint,
|
|
27895
|
-
MatterEndpointCluster,
|
|
27896
|
-
MatterEndpointCapability,
|
|
27897
|
-
MatterEndpointState,
|
|
27898
|
-
MatterCommand,
|
|
27899
|
-
MatterReconciliationStatus
|
|
27761
|
+
var LEGACY_MIGRATIONS = [
|
|
27762
|
+
"CreateMatterConnection1793900000000",
|
|
27763
|
+
"CreateMatterDeviceModel1793900001000",
|
|
27764
|
+
"CreateMatterBackup1793900002000"
|
|
27900
27765
|
];
|
|
27766
|
+
var MATTER_STORAGE = (0, import_plugins_backend_sdk2.definePluginStorage)({
|
|
27767
|
+
tables: MATTER_TABLES,
|
|
27768
|
+
migrations: [
|
|
27769
|
+
{
|
|
27770
|
+
version: 1,
|
|
27771
|
+
name: "baseline",
|
|
27772
|
+
steps: Object.entries(MATTER_BASELINE_TABLES).map(([name, definition]) => import_plugins_backend_sdk2.step.createTable(name, definition))
|
|
27773
|
+
},
|
|
27774
|
+
{
|
|
27775
|
+
version: 2,
|
|
27776
|
+
name: "lookup-indexes",
|
|
27777
|
+
steps: Object.entries(LOOKUP_INDEXES).flatMap(
|
|
27778
|
+
([name, indexes]) => indexes.map((index) => import_plugins_backend_sdk2.step.addIndex(name, index))
|
|
27779
|
+
)
|
|
27780
|
+
}
|
|
27781
|
+
],
|
|
27782
|
+
adoption: { legacyMigrations: LEGACY_MIGRATIONS }
|
|
27783
|
+
});
|
|
27901
27784
|
|
|
27902
|
-
// backend/
|
|
27903
|
-
function
|
|
27904
|
-
|
|
27905
|
-
|
|
27785
|
+
// backend/plugin-storage/access.ts
|
|
27786
|
+
function bindTable(api, scope) {
|
|
27787
|
+
return {
|
|
27788
|
+
insert: (row) => api.insert(row, { scope }),
|
|
27789
|
+
insertMany: (rows) => api.insertMany(rows, { scope }),
|
|
27790
|
+
get: (key) => api.get(key, { scope }),
|
|
27791
|
+
find: (query) => api.find(query, { scope }),
|
|
27792
|
+
findOne: (query) => api.findOne(query, { scope }),
|
|
27793
|
+
count: (where) => api.count(where, { scope }),
|
|
27794
|
+
update: (where, patch) => api.update(where, patch, { scope }),
|
|
27795
|
+
delete: (where) => api.delete(where, { scope }),
|
|
27796
|
+
upsert: (row, options) => api.upsert(row, { ...options, scope })
|
|
27797
|
+
};
|
|
27798
|
+
}
|
|
27799
|
+
function bindTables(tables, scope) {
|
|
27800
|
+
return Object.fromEntries(
|
|
27801
|
+
Object.entries(tables).map(([name, api]) => [name, bindTable(api, scope)])
|
|
27802
|
+
);
|
|
27803
|
+
}
|
|
27804
|
+
var MatterStorage = class {
|
|
27805
|
+
constructor(context) {
|
|
27806
|
+
this.context = context;
|
|
27807
|
+
this.tables = context.storage.open(MATTER_STORAGE);
|
|
27808
|
+
}
|
|
27809
|
+
/**
|
|
27810
|
+
* Runs `work` in one atomic transaction of the host. `tables` carries the transaction scope; `scope.afterCommit`
|
|
27811
|
+
* defers effects until the commit. The host orders concurrent transactions, so a read followed by a write in `work`
|
|
27812
|
+
* cannot be interleaved with another transaction's writes.
|
|
27813
|
+
*/
|
|
27814
|
+
transaction(work) {
|
|
27815
|
+
return this.context.persistence.transaction((scope) => work(bindTables(this.tables, scope), scope));
|
|
27816
|
+
}
|
|
27817
|
+
};
|
|
27818
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
27819
|
+
function matterStorage(context) {
|
|
27820
|
+
let storage = cache.get(context);
|
|
27821
|
+
if (!storage) {
|
|
27822
|
+
storage = new MatterStorage(context);
|
|
27823
|
+
cache.set(context, storage);
|
|
27824
|
+
}
|
|
27825
|
+
return storage;
|
|
27906
27826
|
}
|
|
27907
27827
|
|
|
27908
27828
|
// backend/connection/entity.ts
|
|
27909
|
-
var import_plugins_backend_sdk3 = require("@attraccess/plugins-backend-sdk");
|
|
27910
27829
|
var CONNECTION_ROW_ID = 1;
|
|
27911
|
-
var MatterConnection = class {
|
|
27912
|
-
};
|
|
27913
|
-
__decorateClass([
|
|
27914
|
-
(0, import_plugins_backend_sdk3.PrimaryColumn)({ type: "integer" })
|
|
27915
|
-
], MatterConnection.prototype, "id", 2);
|
|
27916
|
-
__decorateClass([
|
|
27917
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "varchar" })
|
|
27918
|
-
], MatterConnection.prototype, "url", 2);
|
|
27919
|
-
__decorateClass([
|
|
27920
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "text", name: "encrypted_credential" })
|
|
27921
|
-
], MatterConnection.prototype, "encryptedCredential", 2);
|
|
27922
|
-
__decorateClass([
|
|
27923
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "text", name: "ca_certificate", nullable: true })
|
|
27924
|
-
], MatterConnection.prototype, "caCertificate", 2);
|
|
27925
|
-
__decorateClass([
|
|
27926
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "varchar", name: "credential_updated_at" })
|
|
27927
|
-
], MatterConnection.prototype, "credentialUpdatedAt", 2);
|
|
27928
|
-
__decorateClass([
|
|
27929
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "varchar", name: "updated_at" })
|
|
27930
|
-
], MatterConnection.prototype, "updatedAt", 2);
|
|
27931
|
-
__decorateClass([
|
|
27932
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "integer", name: "updated_by", nullable: true })
|
|
27933
|
-
], MatterConnection.prototype, "updatedBy", 2);
|
|
27934
|
-
MatterConnection = __decorateClass([
|
|
27935
|
-
(0, import_plugins_backend_sdk3.Entity)({ name: "plugin_matter_connection" })
|
|
27936
|
-
], MatterConnection);
|
|
27937
27830
|
|
|
27938
27831
|
// backend/connection/validation.ts
|
|
27939
27832
|
var import_node_crypto3 = require("node:crypto");
|
|
@@ -27984,11 +27877,11 @@ var MatterSettingsService = class {
|
|
|
27984
27877
|
constructor(context) {
|
|
27985
27878
|
this.context = context;
|
|
27986
27879
|
}
|
|
27987
|
-
get
|
|
27988
|
-
return this.context
|
|
27880
|
+
get storage() {
|
|
27881
|
+
return matterStorage(this.context);
|
|
27989
27882
|
}
|
|
27990
27883
|
async publicView() {
|
|
27991
|
-
const row = await this.
|
|
27884
|
+
const row = await this.storage.tables.connection.get(CONNECTION_ROW_ID);
|
|
27992
27885
|
if (!row) {
|
|
27993
27886
|
return {
|
|
27994
27887
|
url: null,
|
|
@@ -28008,7 +27901,7 @@ var MatterSettingsService = class {
|
|
|
28008
27901
|
}
|
|
28009
27902
|
/** The decrypted settings for the sidecar client, or null when nothing is configured. */
|
|
28010
27903
|
async clientConfig() {
|
|
28011
|
-
const row = await this.
|
|
27904
|
+
const row = await this.storage.tables.connection.get(CONNECTION_ROW_ID);
|
|
28012
27905
|
if (!row) return null;
|
|
28013
27906
|
try {
|
|
28014
27907
|
return {
|
|
@@ -28020,15 +27913,10 @@ var MatterSettingsService = class {
|
|
|
28020
27913
|
throw new CredentialUnreadableError("The stored credential cannot be decrypted. Enter it again.");
|
|
28021
27914
|
}
|
|
28022
27915
|
}
|
|
28023
|
-
/**
|
|
28024
|
-
* Writes go through the host's serialized write queue like the plugin's other writes. A plain transaction here
|
|
28025
|
-
* reads first and then has to upgrade its SQLite lock, which fails at once with SQLITE_BUSY (no busy wait) while
|
|
28026
|
-
* the queue's connection holds the write lock, e.g. for the reconciliation that every reconnect starts.
|
|
28027
|
-
*/
|
|
27916
|
+
/** Read and write in one host transaction, so a concurrent save cannot slip between them. */
|
|
28028
27917
|
save(input2, userId) {
|
|
28029
|
-
return
|
|
28030
|
-
const
|
|
28031
|
-
const existing = await repository.findOneBy({ id: CONNECTION_ROW_ID });
|
|
27918
|
+
return this.storage.transaction(async (tables) => {
|
|
27919
|
+
const existing = await tables.connection.get(CONNECTION_ROW_ID);
|
|
28032
27920
|
if (!existing && input2.credential === void 0) {
|
|
28033
27921
|
throw new MissingCredentialError("credential: The credential is required for the first configuration.");
|
|
28034
27922
|
}
|
|
@@ -28041,23 +27929,23 @@ var MatterSettingsService = class {
|
|
|
28041
27929
|
);
|
|
28042
27930
|
}
|
|
28043
27931
|
const credentialChanged = input2.credential !== void 0;
|
|
28044
|
-
await
|
|
28045
|
-
|
|
28046
|
-
|
|
28047
|
-
|
|
28048
|
-
|
|
28049
|
-
|
|
28050
|
-
|
|
28051
|
-
|
|
28052
|
-
|
|
27932
|
+
await tables.connection.upsert(
|
|
27933
|
+
{
|
|
27934
|
+
id: CONNECTION_ROW_ID,
|
|
27935
|
+
url: url2,
|
|
27936
|
+
encryptedCredential: credentialChanged ? this.context.secrets.encrypt(input2.credential) : existing.encryptedCredential,
|
|
27937
|
+
caCertificate,
|
|
27938
|
+
credentialUpdatedAt: credentialChanged || !existing ? now : existing.credentialUpdatedAt,
|
|
27939
|
+
updatedAt: now,
|
|
27940
|
+
updatedBy: userId
|
|
27941
|
+
},
|
|
27942
|
+
{ conflictOn: ["id"] }
|
|
27943
|
+
);
|
|
28053
27944
|
return { credentialChanged, caChanged: caCertificate !== (existing?.caCertificate ?? null) };
|
|
28054
27945
|
});
|
|
28055
27946
|
}
|
|
28056
27947
|
remove() {
|
|
28057
|
-
return
|
|
28058
|
-
const result = await manager.getRepository(MatterConnection).delete({ id: CONNECTION_ROW_ID });
|
|
28059
|
-
return (result.affected ?? 0) > 0;
|
|
28060
|
-
});
|
|
27948
|
+
return this.storage.transaction(async (tables) => await tables.connection.delete({ id: CONNECTION_ROW_ID }) > 0);
|
|
28061
27949
|
}
|
|
28062
27950
|
/** Records a settings change. Details are flags only. A missing or failing audit sink never fails the request. */
|
|
28063
27951
|
async audit(action, principal, details = {}) {
|
|
@@ -28169,23 +28057,23 @@ var MatterConnectionController = class {
|
|
|
28169
28057
|
}
|
|
28170
28058
|
};
|
|
28171
28059
|
__decorateClass([
|
|
28172
|
-
(0,
|
|
28060
|
+
(0, import_plugins_backend_sdk3.Auth)(...MATTER_OPERATIONS.connectionSettings),
|
|
28173
28061
|
(0, import_common3.Get)()
|
|
28174
28062
|
], MatterConnectionController.prototype, "get", 1);
|
|
28175
28063
|
__decorateClass([
|
|
28176
|
-
(0,
|
|
28064
|
+
(0, import_plugins_backend_sdk3.Auth)(...MATTER_OPERATIONS.connectionSave),
|
|
28177
28065
|
(0, import_common3.Put)(),
|
|
28178
28066
|
__decorateParam(0, (0, import_common3.Body)()),
|
|
28179
28067
|
__decorateParam(1, (0, import_common3.Req)())
|
|
28180
28068
|
], MatterConnectionController.prototype, "put", 1);
|
|
28181
28069
|
__decorateClass([
|
|
28182
|
-
(0,
|
|
28070
|
+
(0, import_plugins_backend_sdk3.Auth)(...MATTER_OPERATIONS.connectionRemove),
|
|
28183
28071
|
(0, import_common3.Delete)(),
|
|
28184
28072
|
(0, import_common3.HttpCode)(204),
|
|
28185
28073
|
__decorateParam(0, (0, import_common3.Req)())
|
|
28186
28074
|
], MatterConnectionController.prototype, "remove", 1);
|
|
28187
28075
|
__decorateClass([
|
|
28188
|
-
(0,
|
|
28076
|
+
(0, import_plugins_backend_sdk3.Auth)(...MATTER_OPERATIONS.connectionStatus),
|
|
28189
28077
|
(0, import_common3.Get)("status")
|
|
28190
28078
|
], MatterConnectionController.prototype, "status", 1);
|
|
28191
28079
|
MatterConnectionController = __decorateClass([
|
|
@@ -28195,7 +28083,7 @@ MatterConnectionController = __decorateClass([
|
|
|
28195
28083
|
], MatterConnectionController);
|
|
28196
28084
|
|
|
28197
28085
|
// backend/fabric/controller.ts
|
|
28198
|
-
var
|
|
28086
|
+
var import_plugins_backend_sdk5 = require("@attraccess/plugins-backend-sdk");
|
|
28199
28087
|
var import_common11 = require("@nestjs/common");
|
|
28200
28088
|
|
|
28201
28089
|
// backend/fabric/fabric.service.ts
|
|
@@ -28206,7 +28094,7 @@ var import_common8 = require("@nestjs/common");
|
|
|
28206
28094
|
var import_node_crypto10 = require("node:crypto");
|
|
28207
28095
|
|
|
28208
28096
|
// backend/devices/audit.service.ts
|
|
28209
|
-
var
|
|
28097
|
+
var import_plugins_backend_sdk4 = require("@attraccess/plugins-backend-sdk");
|
|
28210
28098
|
var import_common4 = require("@nestjs/common");
|
|
28211
28099
|
var import_node_crypto5 = require("node:crypto");
|
|
28212
28100
|
function auditSubjectId(ref) {
|
|
@@ -28228,7 +28116,7 @@ var DeviceAuditService = class {
|
|
|
28228
28116
|
* with the system principal, never with a user's. Pass `operationId` to tie the entries to an existing operation.
|
|
28229
28117
|
*/
|
|
28230
28118
|
actorFor(principal, operationId = (0, import_node_crypto5.randomUUID)()) {
|
|
28231
|
-
return principal ? { principal, system: false, operationId } : { principal:
|
|
28119
|
+
return principal ? { principal, system: false, operationId } : { principal: import_plugins_backend_sdk4.PLUGIN_AUDIT_SYSTEM_PRINCIPAL, system: true, operationId };
|
|
28232
28120
|
}
|
|
28233
28121
|
/** `by` as an actor: a prepared actor as it is, otherwise a new one with an operation ID of its own. */
|
|
28234
28122
|
actorOf(by) {
|
|
@@ -28317,13 +28205,18 @@ function factsOfRow(row) {
|
|
|
28317
28205
|
storageInstanceId: row.storageInstanceId
|
|
28318
28206
|
};
|
|
28319
28207
|
}
|
|
28320
|
-
function recordedFabricRow(
|
|
28321
|
-
return
|
|
28208
|
+
function recordedFabricRow({ fabrics: fabrics2 }) {
|
|
28209
|
+
return fabrics2.findOne({
|
|
28210
|
+
where: { fabricGeneration: { isNull: false }, retiredAt: null },
|
|
28211
|
+
orderBy: [
|
|
28212
|
+
{ field: "recordedAt", direction: "desc" },
|
|
28213
|
+
{ field: "firstSeenAt", direction: "desc" }
|
|
28214
|
+
]
|
|
28215
|
+
});
|
|
28322
28216
|
}
|
|
28323
|
-
async function recordFacts(
|
|
28324
|
-
const repo = manager.getRepository(MatterFabric);
|
|
28217
|
+
async function recordFacts({ fabrics: fabrics2 }, facts, label2 = null) {
|
|
28325
28218
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
28326
|
-
const existing = await
|
|
28219
|
+
const existing = await fabrics2.findOne({ where: { fabricId: facts.fabricId, retiredAt: null } });
|
|
28327
28220
|
const fields = {
|
|
28328
28221
|
fabricGeneration: facts.fabricGeneration,
|
|
28329
28222
|
storageInstanceId: facts.storageInstanceId,
|
|
@@ -28332,10 +28225,19 @@ async function recordFacts(manager, facts, label2 = null) {
|
|
|
28332
28225
|
status: "active",
|
|
28333
28226
|
lastSeenAt: now
|
|
28334
28227
|
};
|
|
28335
|
-
if (existing)
|
|
28336
|
-
|
|
28337
|
-
|
|
28338
|
-
|
|
28228
|
+
if (existing) {
|
|
28229
|
+
const patch = label2 === null ? fields : { ...fields, label: label2 };
|
|
28230
|
+
await fabrics2.update({ id: existing.id }, patch);
|
|
28231
|
+
return Object.assign(existing, patch);
|
|
28232
|
+
}
|
|
28233
|
+
return fabrics2.insert({
|
|
28234
|
+
id: (0, import_node_crypto6.randomUUID)(),
|
|
28235
|
+
fabricId: facts.fabricId,
|
|
28236
|
+
label: label2,
|
|
28237
|
+
firstSeenAt: now,
|
|
28238
|
+
retiredAt: null,
|
|
28239
|
+
...fields
|
|
28240
|
+
});
|
|
28339
28241
|
}
|
|
28340
28242
|
|
|
28341
28243
|
// backend/fabric/guard.ts
|
|
@@ -28401,101 +28303,6 @@ MatterFabricGuard = __decorateClass([
|
|
|
28401
28303
|
var import_common7 = require("@nestjs/common");
|
|
28402
28304
|
var import_node_crypto8 = require("node:crypto");
|
|
28403
28305
|
|
|
28404
|
-
// backend/backup/entities.ts
|
|
28405
|
-
var import_plugins_backend_sdk6 = require("@attraccess/plugins-backend-sdk");
|
|
28406
|
-
var MatterRecoveryKey = class {
|
|
28407
|
-
};
|
|
28408
|
-
__decorateClass([
|
|
28409
|
-
(0, import_plugins_backend_sdk6.PrimaryColumn)({ type: "varchar" })
|
|
28410
|
-
], MatterRecoveryKey.prototype, "id", 2);
|
|
28411
|
-
__decorateClass([
|
|
28412
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", name: "key_id" })
|
|
28413
|
-
], MatterRecoveryKey.prototype, "keyId", 2);
|
|
28414
|
-
__decorateClass([
|
|
28415
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "text", name: "encrypted_key" })
|
|
28416
|
-
], MatterRecoveryKey.prototype, "encryptedKey", 2);
|
|
28417
|
-
__decorateClass([
|
|
28418
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", name: "created_at" })
|
|
28419
|
-
], MatterRecoveryKey.prototype, "createdAt", 2);
|
|
28420
|
-
__decorateClass([
|
|
28421
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", name: "acknowledged_at", nullable: true })
|
|
28422
|
-
], MatterRecoveryKey.prototype, "acknowledgedAt", 2);
|
|
28423
|
-
__decorateClass([
|
|
28424
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", name: "retired_at", nullable: true })
|
|
28425
|
-
], MatterRecoveryKey.prototype, "retiredAt", 2);
|
|
28426
|
-
MatterRecoveryKey = __decorateClass([
|
|
28427
|
-
(0, import_plugins_backend_sdk6.Entity)({ name: "plugin_matter_recovery_keys" })
|
|
28428
|
-
], MatterRecoveryKey);
|
|
28429
|
-
var MatterBackup = class {
|
|
28430
|
-
};
|
|
28431
|
-
__decorateClass([
|
|
28432
|
-
(0, import_plugins_backend_sdk6.PrimaryColumn)({ type: "varchar" })
|
|
28433
|
-
], MatterBackup.prototype, "id", 2);
|
|
28434
|
-
__decorateClass([
|
|
28435
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", name: "created_at" })
|
|
28436
|
-
], MatterBackup.prototype, "createdAt", 2);
|
|
28437
|
-
__decorateClass([
|
|
28438
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar" })
|
|
28439
|
-
], MatterBackup.prototype, "trigger", 2);
|
|
28440
|
-
__decorateClass([
|
|
28441
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "integer", nullable: true })
|
|
28442
|
-
], MatterBackup.prototype, "actor", 2);
|
|
28443
|
-
__decorateClass([
|
|
28444
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar" })
|
|
28445
|
-
], MatterBackup.prototype, "outcome", 2);
|
|
28446
|
-
__decorateClass([
|
|
28447
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", nullable: true })
|
|
28448
|
-
], MatterBackup.prototype, "reason", 2);
|
|
28449
|
-
__decorateClass([
|
|
28450
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "integer", name: "size_bytes", nullable: true })
|
|
28451
|
-
], MatterBackup.prototype, "sizeBytes", 2);
|
|
28452
|
-
__decorateClass([
|
|
28453
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", nullable: true })
|
|
28454
|
-
], MatterBackup.prototype, "sha256", 2);
|
|
28455
|
-
__decorateClass([
|
|
28456
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "integer", name: "format_version", nullable: true })
|
|
28457
|
-
], MatterBackup.prototype, "formatVersion", 2);
|
|
28458
|
-
__decorateClass([
|
|
28459
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", name: "plugin_version", nullable: true })
|
|
28460
|
-
], MatterBackup.prototype, "pluginVersion", 2);
|
|
28461
|
-
__decorateClass([
|
|
28462
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", name: "sidecar_version", nullable: true })
|
|
28463
|
-
], MatterBackup.prototype, "sidecarVersion", 2);
|
|
28464
|
-
__decorateClass([
|
|
28465
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", name: "matter_js_version", nullable: true })
|
|
28466
|
-
], MatterBackup.prototype, "matterJsVersion", 2);
|
|
28467
|
-
__decorateClass([
|
|
28468
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "integer", name: "storage_schema_version", nullable: true })
|
|
28469
|
-
], MatterBackup.prototype, "storageSchemaVersion", 2);
|
|
28470
|
-
__decorateClass([
|
|
28471
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", name: "plugin_migration", nullable: true })
|
|
28472
|
-
], MatterBackup.prototype, "pluginMigration", 2);
|
|
28473
|
-
__decorateClass([
|
|
28474
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", name: "fabric_id", nullable: true })
|
|
28475
|
-
], MatterBackup.prototype, "fabricId", 2);
|
|
28476
|
-
__decorateClass([
|
|
28477
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", name: "root_cert_fingerprint", nullable: true })
|
|
28478
|
-
], MatterBackup.prototype, "rootCertFingerprint", 2);
|
|
28479
|
-
__decorateClass([
|
|
28480
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "integer", name: "fabric_generation", nullable: true })
|
|
28481
|
-
], MatterBackup.prototype, "fabricGeneration", 2);
|
|
28482
|
-
__decorateClass([
|
|
28483
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", name: "storage_instance_id", nullable: true })
|
|
28484
|
-
], MatterBackup.prototype, "storageInstanceId", 2);
|
|
28485
|
-
__decorateClass([
|
|
28486
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", name: "recovery_key_id", nullable: true })
|
|
28487
|
-
], MatterBackup.prototype, "recoveryKeyId", 2);
|
|
28488
|
-
__decorateClass([
|
|
28489
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "boolean", nullable: true })
|
|
28490
|
-
], MatterBackup.prototype, "consistent", 2);
|
|
28491
|
-
__decorateClass([
|
|
28492
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "blob", nullable: true })
|
|
28493
|
-
], MatterBackup.prototype, "blob", 2);
|
|
28494
|
-
MatterBackup = __decorateClass([
|
|
28495
|
-
(0, import_plugins_backend_sdk6.Entity)({ name: "plugin_matter_backups" })
|
|
28496
|
-
], MatterBackup);
|
|
28497
|
-
var BACKUP_ENTITIES = [MatterRecoveryKey, MatterBackup];
|
|
28498
|
-
|
|
28499
28306
|
// backend/backup/recovery-key.ts
|
|
28500
28307
|
var import_node_crypto7 = require("node:crypto");
|
|
28501
28308
|
var RECOVERY_KEY_BYTES = 32;
|
|
@@ -28563,11 +28370,11 @@ var RecoveryKeyService = class {
|
|
|
28563
28370
|
this.context = context;
|
|
28564
28371
|
this.audit = audit;
|
|
28565
28372
|
}
|
|
28566
|
-
get
|
|
28567
|
-
return this.context
|
|
28373
|
+
get storage() {
|
|
28374
|
+
return matterStorage(this.context);
|
|
28568
28375
|
}
|
|
28569
|
-
current() {
|
|
28570
|
-
return
|
|
28376
|
+
current(tables = this.storage.tables) {
|
|
28377
|
+
return tables.recoveryKeys.findOne({ where: { retiredAt: null } });
|
|
28571
28378
|
}
|
|
28572
28379
|
async view() {
|
|
28573
28380
|
const row = await this.current();
|
|
@@ -28580,8 +28387,10 @@ var RecoveryKeyService = class {
|
|
|
28580
28387
|
}
|
|
28581
28388
|
/** Creates the first key. 409 when one exists: use `rotate`. */
|
|
28582
28389
|
async generate(by) {
|
|
28583
|
-
|
|
28584
|
-
|
|
28390
|
+
const { row, reveal } = await this.storage.transaction(async (tables) => {
|
|
28391
|
+
if (await this.current(tables)) throw conflict("recovery_key_exists", "A recovery key already exists.");
|
|
28392
|
+
return this.create(tables);
|
|
28393
|
+
});
|
|
28585
28394
|
await this.audit.record(
|
|
28586
28395
|
"matter.recovery_key_generated",
|
|
28587
28396
|
by,
|
|
@@ -28596,8 +28405,10 @@ var RecoveryKeyService = class {
|
|
|
28596
28405
|
const row = await this.current();
|
|
28597
28406
|
if (!row || row.keyId !== keyId) throw conflict("recovery_key_mismatch", "That is not the current recovery key.");
|
|
28598
28407
|
if (row.acknowledgedAt) return;
|
|
28599
|
-
|
|
28600
|
-
|
|
28408
|
+
await this.storage.tables.recoveryKeys.update(
|
|
28409
|
+
{ id: row.id, acknowledgedAt: null },
|
|
28410
|
+
{ acknowledgedAt: (/* @__PURE__ */ new Date()).toISOString() }
|
|
28411
|
+
);
|
|
28601
28412
|
await this.audit.record(
|
|
28602
28413
|
"matter.recovery_key_acknowledged",
|
|
28603
28414
|
by,
|
|
@@ -28609,11 +28420,15 @@ var RecoveryKeyService = class {
|
|
|
28609
28420
|
}
|
|
28610
28421
|
/** Retires the current key and creates a new one. The old key stays (encrypted) so older backups can be read. */
|
|
28611
28422
|
async rotate(by) {
|
|
28612
|
-
const previous = await this.
|
|
28613
|
-
|
|
28614
|
-
|
|
28615
|
-
|
|
28616
|
-
|
|
28423
|
+
const { previous, row, reveal } = await this.storage.transaction(async (tables) => {
|
|
28424
|
+
const previous2 = await this.current(tables);
|
|
28425
|
+
if (!previous2) throw conflict("no_recovery_key", "There is no recovery key to rotate.");
|
|
28426
|
+
const retired = await tables.recoveryKeys.update(
|
|
28427
|
+
{ id: previous2.id, retiredAt: null },
|
|
28428
|
+
{ retiredAt: (/* @__PURE__ */ new Date()).toISOString() }
|
|
28429
|
+
);
|
|
28430
|
+
if (retired === 0) throw conflict("no_recovery_key", "There is no recovery key to rotate.");
|
|
28431
|
+
return { previous: previous2, ...await this.create(tables) };
|
|
28617
28432
|
});
|
|
28618
28433
|
await this.audit.record(
|
|
28619
28434
|
"matter.recovery_key_rotated",
|
|
@@ -28632,16 +28447,20 @@ var RecoveryKeyService = class {
|
|
|
28632
28447
|
* returned. Does nothing when a current key exists or the key is not the one with `keyId`.
|
|
28633
28448
|
*/
|
|
28634
28449
|
async adopt(key, keyId, by) {
|
|
28635
|
-
if (recoveryKeyId(key) !== keyId
|
|
28450
|
+
if (recoveryKeyId(key) !== keyId) return false;
|
|
28636
28451
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
28637
|
-
const row = await this.
|
|
28638
|
-
|
|
28639
|
-
|
|
28640
|
-
|
|
28641
|
-
|
|
28642
|
-
|
|
28643
|
-
|
|
28452
|
+
const row = await this.storage.transaction(async (tables) => {
|
|
28453
|
+
if (await this.current(tables)) return null;
|
|
28454
|
+
return tables.recoveryKeys.insert({
|
|
28455
|
+
id: (0, import_node_crypto8.randomUUID)(),
|
|
28456
|
+
keyId,
|
|
28457
|
+
encryptedKey: this.context.secrets.encrypt(key.toString("base64")),
|
|
28458
|
+
createdAt: now,
|
|
28459
|
+
acknowledgedAt: now,
|
|
28460
|
+
retiredAt: null
|
|
28461
|
+
});
|
|
28644
28462
|
});
|
|
28463
|
+
if (!row) return false;
|
|
28645
28464
|
await this.audit.record(
|
|
28646
28465
|
"matter.recovery_key_generated",
|
|
28647
28466
|
by,
|
|
@@ -28657,7 +28476,7 @@ var RecoveryKeyService = class {
|
|
|
28657
28476
|
}
|
|
28658
28477
|
/** The key (current or retired) with this ID, if the installation has it. */
|
|
28659
28478
|
async keyById(keyId) {
|
|
28660
|
-
const row = await this.
|
|
28479
|
+
const row = await this.storage.tables.recoveryKeys.findOne({ where: { keyId } });
|
|
28661
28480
|
return row ? this.open(row) : null;
|
|
28662
28481
|
}
|
|
28663
28482
|
open(row) {
|
|
@@ -28669,10 +28488,10 @@ var RecoveryKeyService = class {
|
|
|
28669
28488
|
throw new RecoveryKeyUnreadableError();
|
|
28670
28489
|
}
|
|
28671
28490
|
}
|
|
28672
|
-
async create(
|
|
28491
|
+
async create(tables) {
|
|
28673
28492
|
const key = generateRecoveryKey();
|
|
28674
28493
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
28675
|
-
const row = await
|
|
28494
|
+
const row = await tables.recoveryKeys.insert({
|
|
28676
28495
|
id: (0, import_node_crypto8.randomUUID)(),
|
|
28677
28496
|
keyId: recoveryKeyId(key),
|
|
28678
28497
|
encryptedKey: this.context.secrets.encrypt(key.toString("base64")),
|
|
@@ -28692,6 +28511,16 @@ RecoveryKeyService = __decorateClass([
|
|
|
28692
28511
|
// backend/fabric/tokens.ts
|
|
28693
28512
|
var PLUGIN_MIGRATION_READER = /* @__PURE__ */ Symbol.for("attraccess.matter.migration-reader");
|
|
28694
28513
|
|
|
28514
|
+
// backend/plugin-storage/blob.ts
|
|
28515
|
+
function encodeBlob(file2) {
|
|
28516
|
+
return file2.toString("base64");
|
|
28517
|
+
}
|
|
28518
|
+
function decodeBlob(stored) {
|
|
28519
|
+
if (typeof stored === "string") return stored === "" ? null : Buffer.from(stored, "base64");
|
|
28520
|
+
if (stored instanceof Uint8Array) return stored.byteLength === 0 ? null : Buffer.from(stored);
|
|
28521
|
+
return null;
|
|
28522
|
+
}
|
|
28523
|
+
|
|
28695
28524
|
// backend/backup/format.ts
|
|
28696
28525
|
var import_node_crypto9 = require("node:crypto");
|
|
28697
28526
|
var import_node_zlib = require("node:zlib");
|
|
@@ -28899,35 +28728,105 @@ function assertCompatible(header, local) {
|
|
|
28899
28728
|
}
|
|
28900
28729
|
|
|
28901
28730
|
// backend/backup/tables.ts
|
|
28902
|
-
var
|
|
28903
|
-
|
|
28904
|
-
|
|
28905
|
-
|
|
28906
|
-
|
|
28907
|
-
|
|
28908
|
-
|
|
28909
|
-
|
|
28910
|
-
|
|
28731
|
+
var BACKED_UP_TABLES = [
|
|
28732
|
+
"fabrics",
|
|
28733
|
+
"nodes",
|
|
28734
|
+
"endpoints",
|
|
28735
|
+
"endpointClusters",
|
|
28736
|
+
"endpointCapabilities",
|
|
28737
|
+
"endpointState",
|
|
28738
|
+
"commands",
|
|
28739
|
+
"reconciliationStatus"
|
|
28911
28740
|
];
|
|
28912
|
-
|
|
28913
|
-
|
|
28914
|
-
|
|
28915
|
-
|
|
28741
|
+
var physicalName = (table2) => MATTER_TABLES[table2].physicalName;
|
|
28742
|
+
var PLUGIN_TABLES = BACKED_UP_TABLES.map((table2) => [
|
|
28743
|
+
physicalName(table2),
|
|
28744
|
+
table2
|
|
28745
|
+
]);
|
|
28746
|
+
var ALLOWED_VALUES = {
|
|
28747
|
+
fabrics: { status: ["active", "absent"] },
|
|
28748
|
+
nodes: {
|
|
28749
|
+
lifecycleState: ["unclaimed", "claimed", "detached", "archived", "removed"],
|
|
28750
|
+
detachedReason: ["absent_from_sidecar", "fabric_mismatch", "fabric_absent"],
|
|
28751
|
+
removalReason: ["force_removed", "merged", "replaced"],
|
|
28752
|
+
attestationStatus: ["verified", "unverified", "failed", "unknown"]
|
|
28753
|
+
},
|
|
28754
|
+
endpoints: { removalReason: ["absent_from_sidecar", "replaced", "force_removed", "merged"] },
|
|
28755
|
+
endpointClusters: { role: ["server", "client"] },
|
|
28756
|
+
endpointState: {
|
|
28757
|
+
commandState: ["none", "requested", "accepted", "reported", "uncertain", "failed"],
|
|
28758
|
+
quality: ["good", "uncertain", "fault", "unavailable"],
|
|
28759
|
+
source: ["subscription_report", "read", "command_response"]
|
|
28760
|
+
},
|
|
28761
|
+
commands: { outcome: ["requested", "accepted", "reported", "uncertain", "failed"] },
|
|
28762
|
+
reconciliationStatus: { lastResult: ["applied", "skipped_unavailable", "skipped_non_authoritative", "failed"] }
|
|
28763
|
+
};
|
|
28764
|
+
function violatesChecks(logical, row) {
|
|
28765
|
+
const sets = ALLOWED_VALUES[logical] ?? {};
|
|
28766
|
+
if (Object.entries(sets).some(([field, allowed]) => row[field] != null && !allowed.includes(row[field]))) {
|
|
28767
|
+
return true;
|
|
28916
28768
|
}
|
|
28917
|
-
return
|
|
28769
|
+
if (logical === "endpoints") return row["endpointId"] < 0 || row["endpointId"] > 65534;
|
|
28770
|
+
return logical === "reconciliationStatus" && row["id"] !== 1;
|
|
28918
28771
|
}
|
|
28919
|
-
|
|
28772
|
+
var columnOf = (field, definition) => definition.column ?? field;
|
|
28773
|
+
var fieldsOf = (table2) => Object.entries(MATTER_TABLES[table2].fields);
|
|
28774
|
+
async function readTables(tables) {
|
|
28775
|
+
const result = {};
|
|
28776
|
+
for (const [name, logical] of PLUGIN_TABLES) {
|
|
28777
|
+
const fields = fieldsOf(logical);
|
|
28778
|
+
const rows = await tables[logical].find();
|
|
28779
|
+
result[name] = rows.map(
|
|
28780
|
+
(row) => Object.fromEntries(fields.map(([field, definition]) => [columnOf(field, definition), row[field] ?? null]))
|
|
28781
|
+
);
|
|
28782
|
+
}
|
|
28783
|
+
return result;
|
|
28784
|
+
}
|
|
28785
|
+
function tableColumns() {
|
|
28920
28786
|
return new Map(
|
|
28921
|
-
PLUGIN_TABLES.map(([
|
|
28922
|
-
|
|
28923
|
-
new Set(
|
|
28787
|
+
PLUGIN_TABLES.map(([name, logical]) => [
|
|
28788
|
+
name,
|
|
28789
|
+
new Set(fieldsOf(logical).map(([field, definition]) => columnOf(field, definition)))
|
|
28924
28790
|
])
|
|
28925
28791
|
);
|
|
28926
28792
|
}
|
|
28927
|
-
function
|
|
28928
|
-
|
|
28929
|
-
|
|
28930
|
-
|
|
28793
|
+
function coerce(definition, value) {
|
|
28794
|
+
if (value === null) return definition.nullable ? null : void 0;
|
|
28795
|
+
switch (definition.type) {
|
|
28796
|
+
case "string":
|
|
28797
|
+
case "text":
|
|
28798
|
+
return typeof value === "string" ? value : void 0;
|
|
28799
|
+
case "integer":
|
|
28800
|
+
return typeof value === "number" && Number.isSafeInteger(value) ? value : void 0;
|
|
28801
|
+
case "boolean":
|
|
28802
|
+
if (typeof value === "boolean") return value;
|
|
28803
|
+
return value === 0 || value === 1 ? value === 1 : void 0;
|
|
28804
|
+
default:
|
|
28805
|
+
return void 0;
|
|
28806
|
+
}
|
|
28807
|
+
}
|
|
28808
|
+
function rowOf(logical, raw) {
|
|
28809
|
+
const fields = fieldsOf(logical);
|
|
28810
|
+
const known = new Set(fields.map(([field, definition]) => columnOf(field, definition)));
|
|
28811
|
+
if (Object.keys(raw).some((name) => !known.has(name))) return null;
|
|
28812
|
+
const row = {};
|
|
28813
|
+
for (const [field, definition] of fields) {
|
|
28814
|
+
const value = raw[columnOf(field, definition)];
|
|
28815
|
+
if (value === void 0) {
|
|
28816
|
+
if (!definition.nullable && !definition.hasDefault) return null;
|
|
28817
|
+
if (definition.nullable) row[field] = null;
|
|
28818
|
+
continue;
|
|
28819
|
+
}
|
|
28820
|
+
const coerced = coerce(definition, value);
|
|
28821
|
+
if (coerced === void 0) return null;
|
|
28822
|
+
row[field] = coerced;
|
|
28823
|
+
}
|
|
28824
|
+
return violatesChecks(logical, row) ? null : row;
|
|
28825
|
+
}
|
|
28826
|
+
function tablesAreAcceptable(tables) {
|
|
28827
|
+
const columns = tableColumns();
|
|
28828
|
+
for (const [table2, rows] of Object.entries(tables)) {
|
|
28829
|
+
const allowed = columns.get(table2);
|
|
28931
28830
|
if (!allowed) return false;
|
|
28932
28831
|
for (const row of rows) {
|
|
28933
28832
|
for (const [name, value] of Object.entries(row)) {
|
|
@@ -28938,17 +28837,16 @@ function tablesAreAcceptable(manager, tables) {
|
|
|
28938
28837
|
}
|
|
28939
28838
|
return true;
|
|
28940
28839
|
}
|
|
28941
|
-
async function replaceTables(
|
|
28942
|
-
for (const [
|
|
28943
|
-
|
|
28944
|
-
|
|
28945
|
-
|
|
28946
|
-
|
|
28947
|
-
|
|
28948
|
-
|
|
28949
|
-
|
|
28950
|
-
);
|
|
28951
|
-
}
|
|
28840
|
+
async function replaceTables(tables, rows) {
|
|
28841
|
+
for (const [, logical] of PLUGIN_TABLES) {
|
|
28842
|
+
const key = MATTER_TABLES[logical].primaryKey[0];
|
|
28843
|
+
await tables[logical].delete({ [key]: { isNull: false } });
|
|
28844
|
+
}
|
|
28845
|
+
for (const [name, logical] of PLUGIN_TABLES) {
|
|
28846
|
+
const decoded = (rows[name] ?? []).map((row) => rowOf(logical, row));
|
|
28847
|
+
if (decoded.some((row) => row === null)) throw new Error("unacceptable tables");
|
|
28848
|
+
if (decoded.length > 0)
|
|
28849
|
+
await tables[logical].insertMany(decoded);
|
|
28952
28850
|
}
|
|
28953
28851
|
}
|
|
28954
28852
|
|
|
@@ -28974,28 +28872,7 @@ var BackupFailure = class extends Error {
|
|
|
28974
28872
|
this.reason = reason;
|
|
28975
28873
|
}
|
|
28976
28874
|
};
|
|
28977
|
-
var
|
|
28978
|
-
"id",
|
|
28979
|
-
"createdAt",
|
|
28980
|
-
"trigger",
|
|
28981
|
-
"actor",
|
|
28982
|
-
"outcome",
|
|
28983
|
-
"reason",
|
|
28984
|
-
"sizeBytes",
|
|
28985
|
-
"sha256",
|
|
28986
|
-
"formatVersion",
|
|
28987
|
-
"pluginVersion",
|
|
28988
|
-
"sidecarVersion",
|
|
28989
|
-
"matterJsVersion",
|
|
28990
|
-
"storageSchemaVersion",
|
|
28991
|
-
"pluginMigration",
|
|
28992
|
-
"fabricId",
|
|
28993
|
-
"rootCertFingerprint",
|
|
28994
|
-
"fabricGeneration",
|
|
28995
|
-
"storageInstanceId",
|
|
28996
|
-
"recoveryKeyId",
|
|
28997
|
-
"consistent"
|
|
28998
|
-
];
|
|
28875
|
+
var withoutFile = ({ blob: _blob, ...row }) => row;
|
|
28999
28876
|
function backupView(row) {
|
|
29000
28877
|
return {
|
|
29001
28878
|
id: row.id,
|
|
@@ -29023,8 +28900,8 @@ var MatterBackupService = class {
|
|
|
29023
28900
|
this.nextScheduledAt = null;
|
|
29024
28901
|
this.succeededListeners = /* @__PURE__ */ new Set();
|
|
29025
28902
|
}
|
|
29026
|
-
get
|
|
29027
|
-
return this.context
|
|
28903
|
+
get storage() {
|
|
28904
|
+
return matterStorage(this.context);
|
|
29028
28905
|
}
|
|
29029
28906
|
setNextScheduledAt(at) {
|
|
29030
28907
|
this.nextScheduledAt = at;
|
|
@@ -29087,21 +28964,21 @@ var MatterBackupService = class {
|
|
|
29087
28964
|
}
|
|
29088
28965
|
}
|
|
29089
28966
|
async produce(run, options) {
|
|
29090
|
-
const
|
|
28967
|
+
const connection2 = this.usableConnection(options);
|
|
29091
28968
|
const key = await this.currentKey();
|
|
29092
|
-
const contents = await this.collect(
|
|
28969
|
+
const contents = await this.collect(connection2, options);
|
|
29093
28970
|
return this.store(run, contents, key);
|
|
29094
28971
|
}
|
|
29095
28972
|
/** The sidecar snapshot and the plugin tables, and whether they belong together. */
|
|
29096
|
-
async collect(
|
|
29097
|
-
const { tables, recorded } = await
|
|
29098
|
-
recorded: factsOfRow(await recordedFabricRow(
|
|
29099
|
-
tables: await readTables(
|
|
28973
|
+
async collect(connection2, options) {
|
|
28974
|
+
const { tables, recorded } = await this.storage.transaction(async (db) => ({
|
|
28975
|
+
recorded: factsOfRow(await recordedFabricRow(db)),
|
|
28976
|
+
tables: await readTables(db)
|
|
29100
28977
|
}));
|
|
29101
28978
|
if (!recorded && !options.allowInRecovery) throw new BackupFailure("no_fabric");
|
|
29102
28979
|
let snapshot;
|
|
29103
28980
|
try {
|
|
29104
|
-
snapshot = await
|
|
28981
|
+
snapshot = await connection2.request("backup.snapshot", { body: {}, timeoutMs: BACKUP_TIMEOUT_MS });
|
|
29105
28982
|
} catch (error62) {
|
|
29106
28983
|
throw new BackupFailure(failureOf(error62));
|
|
29107
28984
|
}
|
|
@@ -29124,7 +29001,7 @@ var MatterBackupService = class {
|
|
|
29124
29001
|
},
|
|
29125
29002
|
key.key
|
|
29126
29003
|
);
|
|
29127
|
-
return this.
|
|
29004
|
+
return this.storage.tables.backups.insert({
|
|
29128
29005
|
...run,
|
|
29129
29006
|
outcome: "succeeded",
|
|
29130
29007
|
reason: null,
|
|
@@ -29142,16 +29019,16 @@ var MatterBackupService = class {
|
|
|
29142
29019
|
storageInstanceId: header.storageInstanceId,
|
|
29143
29020
|
recoveryKeyId: key.keyId,
|
|
29144
29021
|
consistent,
|
|
29145
|
-
blob: file2
|
|
29022
|
+
blob: encodeBlob(file2)
|
|
29146
29023
|
});
|
|
29147
29024
|
}
|
|
29148
29025
|
usableConnection(options) {
|
|
29149
|
-
const
|
|
29150
|
-
const status =
|
|
29026
|
+
const connection2 = this.connectionService.connection;
|
|
29027
|
+
const status = connection2.status();
|
|
29151
29028
|
if (status.state !== "connected") throw new BackupFailure("sidecar_unavailable");
|
|
29152
29029
|
if (status.insecureTransport) throw new BackupFailure("insecure_transport");
|
|
29153
29030
|
if (this.guard.recoveryRequired && !options.allowInRecovery) throw new BackupFailure("recovery_required");
|
|
29154
|
-
return
|
|
29031
|
+
return connection2;
|
|
29155
29032
|
}
|
|
29156
29033
|
async currentKey() {
|
|
29157
29034
|
let key;
|
|
@@ -29165,23 +29042,59 @@ var MatterBackupService = class {
|
|
|
29165
29042
|
}
|
|
29166
29043
|
/** Whether the snapshot is of the fabric the plugin recorded, and the record did not move meanwhile. */
|
|
29167
29044
|
async matchesRecord(header, recorded) {
|
|
29168
|
-
const after = factsOfRow(await recordedFabricRow(this.
|
|
29045
|
+
const after = factsOfRow(await recordedFabricRow(this.storage.tables));
|
|
29169
29046
|
const consistent = recorded !== null && header.fabricId === recorded.fabricId && header.fabricGeneration === recorded.fabricGeneration && header.rootCertFingerprint === recorded.rootCertFingerprint && header.storageInstanceId === recorded.storageInstanceId && after !== null && after.fabricId === recorded.fabricId && after.fabricGeneration === recorded.fabricGeneration;
|
|
29170
29047
|
return consistent;
|
|
29171
29048
|
}
|
|
29172
29049
|
async recordFailure(id, createdAt, trigger, actor, reason) {
|
|
29173
29050
|
try {
|
|
29174
|
-
|
|
29175
|
-
|
|
29176
|
-
|
|
29051
|
+
const { backups: backups2 } = this.storage.tables;
|
|
29052
|
+
await backups2.insert({
|
|
29053
|
+
id,
|
|
29054
|
+
createdAt,
|
|
29055
|
+
trigger,
|
|
29056
|
+
actor,
|
|
29057
|
+
outcome: "failed",
|
|
29058
|
+
reason,
|
|
29059
|
+
sizeBytes: null,
|
|
29060
|
+
sha256: null,
|
|
29061
|
+
formatVersion: null,
|
|
29062
|
+
pluginVersion: null,
|
|
29063
|
+
sidecarVersion: null,
|
|
29064
|
+
matterJsVersion: null,
|
|
29065
|
+
storageSchemaVersion: null,
|
|
29066
|
+
pluginMigration: null,
|
|
29067
|
+
fabricId: null,
|
|
29068
|
+
rootCertFingerprint: null,
|
|
29069
|
+
fabricGeneration: null,
|
|
29070
|
+
storageInstanceId: null,
|
|
29071
|
+
recoveryKeyId: null,
|
|
29072
|
+
consistent: null,
|
|
29073
|
+
blob: null
|
|
29074
|
+
});
|
|
29075
|
+
const stale = await backups2.find({
|
|
29076
|
+
where: { outcome: "failed" },
|
|
29077
|
+
orderBy: [{ field: "createdAt", direction: "desc" }],
|
|
29078
|
+
offset: FAILED_ATTEMPTS_KEPT,
|
|
29079
|
+
limit: 1e3
|
|
29080
|
+
});
|
|
29081
|
+
if (stale.length) await backups2.delete({ id: { in: stale.map((row) => row.id) } });
|
|
29177
29082
|
} catch {
|
|
29178
29083
|
this.context.logger.warn?.("A failed Matter backup attempt could not be recorded.");
|
|
29179
29084
|
}
|
|
29180
29085
|
}
|
|
29181
29086
|
/** Keeps the newest `BACKUP_RETENTION` successful backups. */
|
|
29182
|
-
async prune(
|
|
29183
|
-
const surplus = await
|
|
29184
|
-
|
|
29087
|
+
async prune(tables = this.storage.tables) {
|
|
29088
|
+
const surplus = await tables.backups.find({
|
|
29089
|
+
where: { outcome: "succeeded" },
|
|
29090
|
+
orderBy: [
|
|
29091
|
+
{ field: "createdAt", direction: "desc" },
|
|
29092
|
+
{ field: "id", direction: "desc" }
|
|
29093
|
+
],
|
|
29094
|
+
offset: BACKUP_RETENTION,
|
|
29095
|
+
limit: 1e3
|
|
29096
|
+
});
|
|
29097
|
+
if (surplus.length) await tables.backups.delete({ id: { in: surplus.map((row) => row.id) } });
|
|
29185
29098
|
return surplus.length;
|
|
29186
29099
|
}
|
|
29187
29100
|
toHttp(reason) {
|
|
@@ -29193,12 +29106,23 @@ var MatterBackupService = class {
|
|
|
29193
29106
|
// --- reading -----------------------------------------------------------------------------------------------------
|
|
29194
29107
|
/** Without the file itself. */
|
|
29195
29108
|
async list() {
|
|
29196
|
-
const rows = await this.
|
|
29197
|
-
|
|
29109
|
+
const rows = await this.storage.tables.backups.find({
|
|
29110
|
+
where: { outcome: "succeeded" },
|
|
29111
|
+
orderBy: [
|
|
29112
|
+
{ field: "createdAt", direction: "desc" },
|
|
29113
|
+
{ field: "id", direction: "desc" }
|
|
29114
|
+
]
|
|
29115
|
+
});
|
|
29116
|
+
return rows.map((row) => backupView(withoutFile(row)));
|
|
29198
29117
|
}
|
|
29199
29118
|
async summary() {
|
|
29200
29119
|
const stored = await this.list();
|
|
29201
|
-
const
|
|
29120
|
+
const failed = await this.storage.tables.backups.findOne({
|
|
29121
|
+
where: { outcome: "failed" },
|
|
29122
|
+
orderBy: [{ field: "createdAt", direction: "desc" }]
|
|
29123
|
+
});
|
|
29124
|
+
const newest = stored[0];
|
|
29125
|
+
const last = newest && (!failed || newest.createdAt > failed.createdAt) ? { createdAt: newest.createdAt, outcome: newest.outcome, trigger: newest.trigger, reason: null } : failed;
|
|
29202
29126
|
return {
|
|
29203
29127
|
lastSuccessfulAt: stored[0]?.createdAt ?? null,
|
|
29204
29128
|
lastAttempt: last ? { at: last.createdAt, outcome: last.outcome, trigger: last.trigger, reason: last.reason } : null,
|
|
@@ -29209,8 +29133,9 @@ var MatterBackupService = class {
|
|
|
29209
29133
|
}
|
|
29210
29134
|
/** The encrypted file, as stored: the ciphertext only, with a download name. Audited: it leaves the installation. */
|
|
29211
29135
|
async download(id, principal) {
|
|
29212
|
-
const row = await this.
|
|
29213
|
-
|
|
29136
|
+
const row = await this.storage.tables.backups.findOne({ where: { id, outcome: "succeeded" } });
|
|
29137
|
+
const file2 = decodeBlob(row?.blob);
|
|
29138
|
+
if (!row || !file2) throw new import_common8.NotFoundException({ code: "not_found", message: "There is no such backup." });
|
|
29214
29139
|
await this.audit.record(
|
|
29215
29140
|
"matter.backup_downloaded",
|
|
29216
29141
|
principal,
|
|
@@ -29220,13 +29145,13 @@ var MatterBackupService = class {
|
|
|
29220
29145
|
const date5 = row.createdAt.slice(0, 10);
|
|
29221
29146
|
return {
|
|
29222
29147
|
filename: `attraccess-matter-${date5}-${row.id.slice(0, 8)}${FILE_EXTENSION}`,
|
|
29223
|
-
file:
|
|
29148
|
+
file: file2
|
|
29224
29149
|
};
|
|
29225
29150
|
}
|
|
29226
29151
|
/** The stored file for a restore. */
|
|
29227
29152
|
async fileOf(id) {
|
|
29228
|
-
const row = await this.
|
|
29229
|
-
return row?.blob
|
|
29153
|
+
const row = await this.storage.tables.backups.findOne({ where: { id, outcome: "succeeded" } });
|
|
29154
|
+
return decodeBlob(row?.blob);
|
|
29230
29155
|
}
|
|
29231
29156
|
};
|
|
29232
29157
|
MatterBackupService = __decorateClass([
|
|
@@ -29255,22 +29180,31 @@ var import_node_crypto12 = require("node:crypto");
|
|
|
29255
29180
|
// backend/devices/commands.ts
|
|
29256
29181
|
var MAX_COMMAND_ROWS = 1e3;
|
|
29257
29182
|
var MAX_COMMAND_AGE_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
29258
|
-
async function pruneCommands(
|
|
29259
|
-
const repo = manager.getRepository(MatterCommand);
|
|
29183
|
+
async function pruneCommands({ commands: commands2 }, now = /* @__PURE__ */ new Date()) {
|
|
29260
29184
|
const cutoff = new Date(now.getTime() - MAX_COMMAND_AGE_MS).toISOString();
|
|
29261
|
-
let removed =
|
|
29262
|
-
|
|
29263
|
-
|
|
29264
|
-
|
|
29265
|
-
|
|
29185
|
+
let removed = await commands2.delete({ requestedAt: { lt: cutoff } });
|
|
29186
|
+
if (await commands2.count() < MAX_COMMAND_ROWS) return removed;
|
|
29187
|
+
const oldestKept = await commands2.findOne({
|
|
29188
|
+
orderBy: [
|
|
29189
|
+
{ field: "requestedAt", direction: "desc" },
|
|
29190
|
+
{ field: "requestId", direction: "desc" }
|
|
29191
|
+
],
|
|
29192
|
+
offset: MAX_COMMAND_ROWS - 1,
|
|
29193
|
+
limit: 1
|
|
29194
|
+
});
|
|
29266
29195
|
if (!oldestKept) return removed;
|
|
29267
|
-
removed +=
|
|
29268
|
-
|
|
29269
|
-
|
|
29270
|
-
|
|
29196
|
+
removed += await commands2.delete({
|
|
29197
|
+
or: [
|
|
29198
|
+
{ requestedAt: { lt: oldestKept.requestedAt } },
|
|
29199
|
+
{ requestedAt: oldestKept.requestedAt, requestId: { lt: oldestKept.requestId } }
|
|
29200
|
+
]
|
|
29201
|
+
});
|
|
29271
29202
|
return removed;
|
|
29272
29203
|
}
|
|
29273
29204
|
|
|
29205
|
+
// backend/devices/entities.ts
|
|
29206
|
+
var RECONCILIATION_ROW_ID = 1;
|
|
29207
|
+
|
|
29274
29208
|
// backend/devices/sync.ts
|
|
29275
29209
|
var import_node_crypto11 = require("node:crypto");
|
|
29276
29210
|
|
|
@@ -29390,8 +29324,8 @@ var ENDPOINT_PROTOCOL_COLUMNS = [
|
|
|
29390
29324
|
"bridgedReachable",
|
|
29391
29325
|
"lastSeenAt"
|
|
29392
29326
|
];
|
|
29393
|
-
function findLive(
|
|
29394
|
-
return
|
|
29327
|
+
function findLive(table2, column, value) {
|
|
29328
|
+
return table2.find({ where: { [column]: value, removedAt: null } });
|
|
29395
29329
|
}
|
|
29396
29330
|
var reattachedState = (node2) => node2.claimedAt ? "claimed" : "unclaimed";
|
|
29397
29331
|
var sorted = (ids) => JSON.stringify([...ids].sort((a, b) => a - b));
|
|
@@ -29424,21 +29358,21 @@ function assignChanged(target, patch) {
|
|
|
29424
29358
|
}
|
|
29425
29359
|
return any2 ? changed : null;
|
|
29426
29360
|
}
|
|
29427
|
-
async function retireEndpoint(
|
|
29361
|
+
async function retireEndpoint(tables, endpoint, reason, now) {
|
|
29428
29362
|
endpoint.removedAt = now;
|
|
29429
29363
|
endpoint.removalReason = reason;
|
|
29430
|
-
await
|
|
29431
|
-
await
|
|
29432
|
-
await
|
|
29364
|
+
await tables.endpoints.update({ id: endpoint.id }, { removedAt: now, removalReason: reason });
|
|
29365
|
+
await tables.endpointClusters.update({ endpointRef: endpoint.id, removedAt: null }, { removedAt: now });
|
|
29366
|
+
await tables.endpointCapabilities.delete({ endpointRef: endpoint.id });
|
|
29433
29367
|
}
|
|
29434
|
-
async function syncNode(
|
|
29368
|
+
async function syncNode(tables, node2, view, now, counters) {
|
|
29435
29369
|
const changed = assignChanged(node2, identityOf(view, node2.lastSeenAt));
|
|
29436
29370
|
if (changed) {
|
|
29437
29371
|
node2.updatedAt = now;
|
|
29438
|
-
await
|
|
29372
|
+
await tables.nodes.update({ id: node2.id }, { ...changed, updatedAt: now });
|
|
29439
29373
|
counters.nodesUpdated += 1;
|
|
29440
29374
|
}
|
|
29441
|
-
await syncEndpoints(
|
|
29375
|
+
await syncEndpoints(tables, node2, view, now, counters);
|
|
29442
29376
|
}
|
|
29443
29377
|
function endpointPatch(view, previous, seenAt) {
|
|
29444
29378
|
const clusters = view.clusters.map((cluster) => ({
|
|
@@ -29476,8 +29410,8 @@ function uniqueBy(items, key) {
|
|
|
29476
29410
|
return true;
|
|
29477
29411
|
});
|
|
29478
29412
|
}
|
|
29479
|
-
async function syncEndpoints(
|
|
29480
|
-
const live = await findLive(
|
|
29413
|
+
async function syncEndpoints(tables, node2, view, now, counters) {
|
|
29414
|
+
const live = await findLive(tables.endpoints, "nodeRef", node2.id);
|
|
29481
29415
|
const liveById = new Map(live.map((row) => [row.endpointId, row]));
|
|
29482
29416
|
const seen = /* @__PURE__ */ new Set();
|
|
29483
29417
|
const seenAt = view.observedAt;
|
|
@@ -29486,12 +29420,12 @@ async function syncEndpoints(manager, node2, view, now, counters) {
|
|
|
29486
29420
|
let row = liveById.get(endpoint.endpointId) ?? null;
|
|
29487
29421
|
const newUniqueId = endpoint.bridged?.uniqueId ?? null;
|
|
29488
29422
|
if (row && row.bridgedUniqueId !== null && newUniqueId !== null && row.bridgedUniqueId !== newUniqueId) {
|
|
29489
|
-
await retireEndpoint(
|
|
29423
|
+
await retireEndpoint(tables, row, "replaced", now);
|
|
29490
29424
|
counters.endpointsReplaced += 1;
|
|
29491
29425
|
row = null;
|
|
29492
29426
|
}
|
|
29493
29427
|
if (!row) {
|
|
29494
|
-
row =
|
|
29428
|
+
row = {
|
|
29495
29429
|
id: (0, import_node_crypto11.randomUUID)(),
|
|
29496
29430
|
nodeRef: node2.id,
|
|
29497
29431
|
endpointId: endpoint.endpointId,
|
|
@@ -29502,26 +29436,26 @@ async function syncEndpoints(manager, node2, view, now, counters) {
|
|
|
29502
29436
|
removedAt: null,
|
|
29503
29437
|
removalReason: null,
|
|
29504
29438
|
...endpointPatch(endpoint, null, seenAt ?? now)
|
|
29505
|
-
}
|
|
29506
|
-
await
|
|
29439
|
+
};
|
|
29440
|
+
await tables.endpoints.insert(row);
|
|
29507
29441
|
counters.endpointsAdded += 1;
|
|
29508
29442
|
} else {
|
|
29509
29443
|
const changed = assignChanged(row, endpointPatch(endpoint, row, seenAt ?? row.lastSeenAt));
|
|
29510
29444
|
if (changed) {
|
|
29511
|
-
await
|
|
29445
|
+
await tables.endpoints.update({ id: row.id }, changed);
|
|
29512
29446
|
counters.endpointsUpdated += 1;
|
|
29513
29447
|
}
|
|
29514
29448
|
}
|
|
29515
|
-
await syncClusters(
|
|
29449
|
+
await syncClusters(tables, row, endpoint, now, counters);
|
|
29516
29450
|
}
|
|
29517
29451
|
for (const row of live) {
|
|
29518
29452
|
if (seen.has(row.endpointId) || row.removedAt !== null) continue;
|
|
29519
|
-
await retireEndpoint(
|
|
29453
|
+
await retireEndpoint(tables, row, "absent_from_sidecar", now);
|
|
29520
29454
|
counters.endpointsRemoved += 1;
|
|
29521
29455
|
}
|
|
29522
29456
|
}
|
|
29523
|
-
async function syncClusters(
|
|
29524
|
-
const live = await findLive(
|
|
29457
|
+
async function syncClusters(tables, endpoint, view, now, counters) {
|
|
29458
|
+
const live = await findLive(tables.endpointClusters, "endpointRef", endpoint.id);
|
|
29525
29459
|
const key = (clusterId, role) => `${clusterId}:${role}`;
|
|
29526
29460
|
const liveByKey = new Map(live.map((row) => [key(row.clusterId, row.role), row]));
|
|
29527
29461
|
const clusters = uniqueBy(view.clusters, (cluster) => key(cluster.clusterId, cluster.role));
|
|
@@ -29538,37 +29472,33 @@ async function syncClusters(manager, endpoint, view, now, counters) {
|
|
|
29538
29472
|
};
|
|
29539
29473
|
const row = liveByKey.get(k);
|
|
29540
29474
|
if (!row) {
|
|
29541
|
-
added.push(
|
|
29542
|
-
|
|
29543
|
-
|
|
29544
|
-
|
|
29545
|
-
|
|
29546
|
-
|
|
29547
|
-
|
|
29548
|
-
|
|
29549
|
-
})
|
|
29550
|
-
);
|
|
29475
|
+
added.push({
|
|
29476
|
+
id: (0, import_node_crypto11.randomUUID)(),
|
|
29477
|
+
endpointRef: endpoint.id,
|
|
29478
|
+
clusterId: cluster.clusterId,
|
|
29479
|
+
role: cluster.role,
|
|
29480
|
+
removedAt: null,
|
|
29481
|
+
...patch
|
|
29482
|
+
});
|
|
29551
29483
|
counters.clustersChanged += 1;
|
|
29552
29484
|
continue;
|
|
29553
29485
|
}
|
|
29554
29486
|
const changed = assignChanged(row, patch);
|
|
29555
29487
|
if (changed) {
|
|
29556
|
-
await
|
|
29488
|
+
await tables.endpointClusters.update({ id: row.id }, changed);
|
|
29557
29489
|
counters.clustersChanged += 1;
|
|
29558
29490
|
}
|
|
29559
29491
|
}
|
|
29560
|
-
|
|
29561
|
-
await manager.insert(MatterEndpointCluster, added.slice(start, start + 50));
|
|
29562
|
-
}
|
|
29492
|
+
if (added.length > 0) await tables.endpointClusters.insertMany(added);
|
|
29563
29493
|
for (const row of live) {
|
|
29564
29494
|
if (seen.has(key(row.clusterId, row.role))) continue;
|
|
29565
29495
|
row.removedAt = now;
|
|
29566
|
-
await
|
|
29496
|
+
await tables.endpointClusters.update({ id: row.id }, { removedAt: now });
|
|
29567
29497
|
counters.clustersChanged += 1;
|
|
29568
29498
|
}
|
|
29569
|
-
await syncCapabilities(
|
|
29499
|
+
await syncCapabilities(tables, endpoint.id, clusters);
|
|
29570
29500
|
}
|
|
29571
|
-
async function syncCapabilities(
|
|
29501
|
+
async function syncCapabilities(tables, endpointRef, clusters) {
|
|
29572
29502
|
const wanted = deriveCapabilities(
|
|
29573
29503
|
clusters.map((cluster) => ({
|
|
29574
29504
|
clusterId: cluster.clusterId,
|
|
@@ -29577,33 +29507,32 @@ async function syncCapabilities(manager, endpointRef, clusters) {
|
|
|
29577
29507
|
}))
|
|
29578
29508
|
);
|
|
29579
29509
|
const existing = new Map(
|
|
29580
|
-
(await
|
|
29510
|
+
(await tables.endpointCapabilities.find({ where: { endpointRef } })).map((row) => [row.capability, row])
|
|
29581
29511
|
);
|
|
29582
29512
|
const added = [];
|
|
29583
29513
|
for (const capability of wanted) {
|
|
29584
29514
|
const details = JSON.stringify(capability.details);
|
|
29585
29515
|
const row = existing.get(capability.capability);
|
|
29586
29516
|
if (!row) {
|
|
29587
|
-
added.push(
|
|
29588
|
-
|
|
29589
|
-
|
|
29590
|
-
|
|
29591
|
-
|
|
29592
|
-
|
|
29593
|
-
|
|
29594
|
-
})
|
|
29595
|
-
);
|
|
29517
|
+
added.push({
|
|
29518
|
+
id: (0, import_node_crypto11.randomUUID)(),
|
|
29519
|
+
endpointRef,
|
|
29520
|
+
capability: capability.capability,
|
|
29521
|
+
sourceClusterId: capability.sourceClusterId,
|
|
29522
|
+
details
|
|
29523
|
+
});
|
|
29596
29524
|
} else if (row.sourceClusterId !== capability.sourceClusterId || row.details !== details) {
|
|
29597
|
-
await
|
|
29598
|
-
MatterEndpointCapability,
|
|
29525
|
+
await tables.endpointCapabilities.update(
|
|
29599
29526
|
{ id: row.id },
|
|
29600
29527
|
{ sourceClusterId: capability.sourceClusterId, details }
|
|
29601
29528
|
);
|
|
29602
29529
|
}
|
|
29603
29530
|
existing.delete(capability.capability);
|
|
29604
29531
|
}
|
|
29605
|
-
if (added.length > 0) await
|
|
29606
|
-
|
|
29532
|
+
if (added.length > 0) await tables.endpointCapabilities.insertMany(added);
|
|
29533
|
+
if (existing.size > 0) {
|
|
29534
|
+
await tables.endpointCapabilities.delete({ id: { in: [...existing.values()].map((row) => row.id) } });
|
|
29535
|
+
}
|
|
29607
29536
|
}
|
|
29608
29537
|
|
|
29609
29538
|
// backend/devices/reconciliation.service.ts
|
|
@@ -29628,8 +29557,7 @@ var MatterReconciliationService = class {
|
|
|
29628
29557
|
return this.connectionService.connection;
|
|
29629
29558
|
}
|
|
29630
29559
|
async status() {
|
|
29631
|
-
|
|
29632
|
-
return viewOf(row);
|
|
29560
|
+
return viewOf(await matterStorage(this.context).tables.reconciliationStatus.get(RECONCILIATION_ROW_ID));
|
|
29633
29561
|
}
|
|
29634
29562
|
/**
|
|
29635
29563
|
* Starts a run. A trigger that arrives during a run does not start a second one in parallel: all of them coalesce
|
|
@@ -29671,18 +29599,20 @@ var MatterReconciliationService = class {
|
|
|
29671
29599
|
this.context.logger.warn?.("Matter reconciliation failed.");
|
|
29672
29600
|
audits.length = 0;
|
|
29673
29601
|
}
|
|
29674
|
-
await this.context.
|
|
29675
|
-
const
|
|
29676
|
-
|
|
29677
|
-
|
|
29678
|
-
|
|
29679
|
-
|
|
29680
|
-
|
|
29681
|
-
|
|
29682
|
-
|
|
29683
|
-
|
|
29684
|
-
|
|
29685
|
-
|
|
29602
|
+
await matterStorage(this.context).transaction(async ({ reconciliationStatus: reconciliationStatus2 }) => {
|
|
29603
|
+
const previous = await reconciliationStatus2.get(RECONCILIATION_ROW_ID);
|
|
29604
|
+
await reconciliationStatus2.upsert(
|
|
29605
|
+
{
|
|
29606
|
+
id: RECONCILIATION_ROW_ID,
|
|
29607
|
+
lastStartedAt: startedAt,
|
|
29608
|
+
lastFinishedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
29609
|
+
lastResult: result,
|
|
29610
|
+
lastSummary: JSON.stringify(summary),
|
|
29611
|
+
// A skipped run did not learn the fabric: keep what the last applied run saw.
|
|
29612
|
+
sidecarFabricId: result === "applied" ? fabricId : previous?.sidecarFabricId ?? null
|
|
29613
|
+
},
|
|
29614
|
+
{ conflictOn: ["id"] }
|
|
29615
|
+
);
|
|
29686
29616
|
});
|
|
29687
29617
|
const actor = this.audit.actorOf(by);
|
|
29688
29618
|
const initiator = actor.system ? "system" : "administrator";
|
|
@@ -29717,12 +29647,12 @@ var MatterReconciliationService = class {
|
|
|
29717
29647
|
if (!list.authoritative) return skipped("not_authoritative", "skipped_non_authoritative");
|
|
29718
29648
|
const summary = emptySummary();
|
|
29719
29649
|
summary.nodesListed = list.nodes.length;
|
|
29720
|
-
const blocked = await this.context.
|
|
29650
|
+
const blocked = await matterStorage(this.context).transaction(async (tables) => {
|
|
29721
29651
|
const reason = this.guard.epoch !== epoch ? "restore_in_progress" : this.blocked(allowInRecovery);
|
|
29722
29652
|
if (reason) return reason;
|
|
29723
29653
|
const now = /* @__PURE__ */ new Date();
|
|
29724
|
-
await this.apply(
|
|
29725
|
-
await pruneCommands(
|
|
29654
|
+
await this.apply(tables, list, summary, audits, now.toISOString());
|
|
29655
|
+
await pruneCommands(tables, now);
|
|
29726
29656
|
return null;
|
|
29727
29657
|
});
|
|
29728
29658
|
if (blocked) return skipped(blocked);
|
|
@@ -29735,18 +29665,17 @@ var MatterReconciliationService = class {
|
|
|
29735
29665
|
if (this.guard.recoveryRequired && !allowInRecovery) return "recovery_required";
|
|
29736
29666
|
return null;
|
|
29737
29667
|
}
|
|
29738
|
-
async apply(
|
|
29668
|
+
async apply(tables, list, summary, audits, now) {
|
|
29739
29669
|
const { changes: counters, observed } = summary;
|
|
29740
|
-
const fabrics =
|
|
29741
|
-
const
|
|
29742
|
-
const activeFabrics = await fabrics.createQueryBuilder("f").where(`f.status = 'active' AND f.retiredAt IS NULL`).getMany();
|
|
29670
|
+
const { fabrics: fabrics2, nodes: nodes2 } = tables;
|
|
29671
|
+
const activeFabrics = await fabrics2.find({ where: { status: "active", retiredAt: null } });
|
|
29743
29672
|
const fabricIdOf = /* @__PURE__ */ new Map();
|
|
29744
29673
|
const detach = async (node2, reason) => {
|
|
29745
29674
|
node2.lifecycleState = "detached";
|
|
29746
29675
|
node2.detachedReason = reason;
|
|
29747
29676
|
node2.detachedAt = now;
|
|
29748
29677
|
node2.updatedAt = now;
|
|
29749
|
-
await
|
|
29678
|
+
await nodes2.update(
|
|
29750
29679
|
{ id: node2.id },
|
|
29751
29680
|
{ lifecycleState: "detached", detachedReason: reason, detachedAt: now, updatedAt: now }
|
|
29752
29681
|
);
|
|
@@ -29757,53 +29686,64 @@ var MatterReconciliationService = class {
|
|
|
29757
29686
|
details: { nodeRef: node2.id, fabricId: fabricIdOf.get(node2.fabricRef) ?? "0", nodeId: node2.nodeId, reason }
|
|
29758
29687
|
});
|
|
29759
29688
|
};
|
|
29760
|
-
const liveOf = async (fabricRef) => findLive(
|
|
29689
|
+
const liveOf = async (fabricRef) => findLive(nodes2, "fabricRef", fabricRef);
|
|
29761
29690
|
const detachableIn = async (fabricRef) => (await liveOf(fabricRef)).filter((n) => n.lifecycleState === "claimed" || n.lifecycleState === "unclaimed");
|
|
29762
|
-
for (const fabric2 of await
|
|
29691
|
+
for (const fabric2 of await fabrics2.find()) fabricIdOf.set(fabric2.id, fabric2.fabricId);
|
|
29763
29692
|
if (list.fabricId === null) {
|
|
29764
29693
|
for (const fabric2 of activeFabrics) {
|
|
29765
29694
|
fabric2.status = "absent";
|
|
29766
|
-
await
|
|
29695
|
+
await fabrics2.update({ id: fabric2.id }, { status: "absent" });
|
|
29767
29696
|
counters.fabricsChanged += 1;
|
|
29768
29697
|
for (const node2 of await detachableIn(fabric2.id)) await detach(node2, "fabric_absent");
|
|
29769
29698
|
}
|
|
29770
29699
|
return;
|
|
29771
29700
|
}
|
|
29772
|
-
let fabric = await
|
|
29701
|
+
let fabric = await fabrics2.findOne({ where: { fabricId: list.fabricId, retiredAt: null } });
|
|
29773
29702
|
if (!fabric) {
|
|
29774
|
-
fabric =
|
|
29703
|
+
fabric = {
|
|
29775
29704
|
id: (0, import_node_crypto12.randomUUID)(),
|
|
29776
29705
|
fabricId: list.fabricId,
|
|
29777
29706
|
label: null,
|
|
29778
29707
|
firstSeenAt: now,
|
|
29779
29708
|
lastSeenAt: now,
|
|
29780
29709
|
status: "active",
|
|
29781
|
-
retiredAt: null
|
|
29782
|
-
|
|
29783
|
-
|
|
29710
|
+
retiredAt: null,
|
|
29711
|
+
fabricGeneration: null,
|
|
29712
|
+
storageInstanceId: null,
|
|
29713
|
+
rootCertFingerprint: null,
|
|
29714
|
+
recordedAt: null
|
|
29715
|
+
};
|
|
29716
|
+
await fabrics2.insert(fabric);
|
|
29784
29717
|
fabricIdOf.set(fabric.id, fabric.fabricId);
|
|
29785
29718
|
counters.fabricsChanged += 1;
|
|
29786
29719
|
} else if (fabric.status !== "active") {
|
|
29787
29720
|
fabric.status = "active";
|
|
29788
29721
|
fabric.lastSeenAt = now;
|
|
29789
|
-
await
|
|
29722
|
+
await fabrics2.update({ id: fabric.id }, { status: "active", lastSeenAt: now });
|
|
29790
29723
|
counters.fabricsChanged += 1;
|
|
29791
29724
|
}
|
|
29792
29725
|
const mismatches = [];
|
|
29793
29726
|
for (const other of activeFabrics.filter((candidate) => candidate.id !== fabric.id)) {
|
|
29794
29727
|
other.status = "absent";
|
|
29795
|
-
await
|
|
29728
|
+
await fabrics2.update({ id: other.id }, { status: "absent" });
|
|
29796
29729
|
counters.fabricsChanged += 1;
|
|
29797
29730
|
const stale = await detachableIn(other.id);
|
|
29798
29731
|
for (const node2 of stale) await detach(node2, "fabric_mismatch");
|
|
29799
29732
|
mismatches.push({ fabric: other, detached: stale.length });
|
|
29800
29733
|
}
|
|
29801
|
-
const absentSince = await
|
|
29734
|
+
const absentSince = await nodes2.find({
|
|
29735
|
+
where: {
|
|
29736
|
+
fabricRef: { ne: fabric.id },
|
|
29737
|
+
removedAt: null,
|
|
29738
|
+
lifecycleState: "detached",
|
|
29739
|
+
detachedReason: "fabric_absent"
|
|
29740
|
+
}
|
|
29741
|
+
});
|
|
29802
29742
|
const byFabric = /* @__PURE__ */ new Map();
|
|
29803
29743
|
for (const node2 of absentSince) byFabric.set(node2.fabricRef, [...byFabric.get(node2.fabricRef) ?? [], node2]);
|
|
29804
29744
|
for (const [fabricRef, stranded] of byFabric) {
|
|
29805
29745
|
for (const node2 of stranded) await detach(node2, "fabric_mismatch");
|
|
29806
|
-
const other = await
|
|
29746
|
+
const other = await fabrics2.get(fabricRef);
|
|
29807
29747
|
if (other) mismatches.push({ fabric: other, detached: stranded.length });
|
|
29808
29748
|
}
|
|
29809
29749
|
const live = await liveOf(fabric.id);
|
|
@@ -29815,7 +29755,7 @@ var MatterReconciliationService = class {
|
|
|
29815
29755
|
listed.add(view.nodeId);
|
|
29816
29756
|
const node2 = byNodeId.get(view.nodeId);
|
|
29817
29757
|
if (!node2) {
|
|
29818
|
-
const created =
|
|
29758
|
+
const created = {
|
|
29819
29759
|
id: (0, import_node_crypto12.randomUUID)(),
|
|
29820
29760
|
fabricRef: fabric.id,
|
|
29821
29761
|
nodeId: view.nodeId,
|
|
@@ -29837,9 +29777,9 @@ var MatterReconciliationService = class {
|
|
|
29837
29777
|
createdAt: now,
|
|
29838
29778
|
updatedAt: now,
|
|
29839
29779
|
...identityOf(view, now)
|
|
29840
|
-
}
|
|
29841
|
-
await
|
|
29842
|
-
await syncNode(
|
|
29780
|
+
};
|
|
29781
|
+
await nodes2.insert(created);
|
|
29782
|
+
await syncNode(tables, created, view, now, counters);
|
|
29843
29783
|
counters.nodesQuarantined += 1;
|
|
29844
29784
|
quarantined += 1;
|
|
29845
29785
|
audits.push({
|
|
@@ -29863,7 +29803,7 @@ var MatterReconciliationService = class {
|
|
|
29863
29803
|
node2.detachedReason = null;
|
|
29864
29804
|
node2.detachedAt = null;
|
|
29865
29805
|
node2.updatedAt = now;
|
|
29866
|
-
await
|
|
29806
|
+
await nodes2.update(
|
|
29867
29807
|
{ id: node2.id },
|
|
29868
29808
|
{ lifecycleState: resultingState, detachedReason: null, detachedAt: null, updatedAt: now }
|
|
29869
29809
|
);
|
|
@@ -29874,7 +29814,7 @@ var MatterReconciliationService = class {
|
|
|
29874
29814
|
details: { nodeRef: node2.id, fabricId: fabric.fabricId, nodeId: node2.nodeId, resultingState }
|
|
29875
29815
|
});
|
|
29876
29816
|
}
|
|
29877
|
-
await syncNode(
|
|
29817
|
+
await syncNode(tables, node2, view, now, counters);
|
|
29878
29818
|
}
|
|
29879
29819
|
for (const node2 of live) {
|
|
29880
29820
|
if (listed.has(node2.nodeId)) continue;
|
|
@@ -29945,12 +29885,12 @@ function fabricAudit(rowId) {
|
|
|
29945
29885
|
};
|
|
29946
29886
|
}
|
|
29947
29887
|
var MatterFabricService = class {
|
|
29948
|
-
constructor(context, connectionService, guard, keys,
|
|
29888
|
+
constructor(context, connectionService, guard, keys, backups2, audit, reconciliation) {
|
|
29949
29889
|
this.context = context;
|
|
29950
29890
|
this.connectionService = connectionService;
|
|
29951
29891
|
this.guard = guard;
|
|
29952
29892
|
this.keys = keys;
|
|
29953
|
-
this.backups =
|
|
29893
|
+
this.backups = backups2;
|
|
29954
29894
|
this.audit = audit;
|
|
29955
29895
|
this.reconciliation = reconciliation;
|
|
29956
29896
|
this.unsubscribe = [];
|
|
@@ -29961,20 +29901,23 @@ var MatterFabricService = class {
|
|
|
29961
29901
|
get connection() {
|
|
29962
29902
|
return this.connectionService.connection;
|
|
29963
29903
|
}
|
|
29964
|
-
get
|
|
29965
|
-
return this.context
|
|
29904
|
+
get storage() {
|
|
29905
|
+
return matterStorage(this.context);
|
|
29906
|
+
}
|
|
29907
|
+
get tables() {
|
|
29908
|
+
return this.storage.tables;
|
|
29966
29909
|
}
|
|
29967
29910
|
onModuleInit() {
|
|
29968
|
-
const
|
|
29911
|
+
const connection2 = this.connection;
|
|
29969
29912
|
this.unsubscribe.push(
|
|
29970
|
-
|
|
29913
|
+
connection2.onStateChange((status) => {
|
|
29971
29914
|
if (status.state === "connected") this.detect("connect").catch(() => void 0);
|
|
29972
29915
|
}),
|
|
29973
|
-
|
|
29916
|
+
connection2.onEvent(({ event }) => {
|
|
29974
29917
|
if (event.type === "fabric.changed") this.detect("event").catch(() => void 0);
|
|
29975
29918
|
})
|
|
29976
29919
|
);
|
|
29977
|
-
if (
|
|
29920
|
+
if (connection2.status().state === "connected") this.detect("connect").catch(() => void 0);
|
|
29978
29921
|
}
|
|
29979
29922
|
onModuleDestroy() {
|
|
29980
29923
|
for (const stop of this.unsubscribe.splice(0)) stop();
|
|
@@ -30007,7 +29950,7 @@ var MatterFabricService = class {
|
|
|
30007
29950
|
return this.guard.mismatch;
|
|
30008
29951
|
}
|
|
30009
29952
|
try {
|
|
30010
|
-
const recorded = factsOfRow(await recordedFabricRow(this.
|
|
29953
|
+
const recorded = factsOfRow(await recordedFabricRow(this.tables));
|
|
30011
29954
|
const detection = detectMismatch(sidecar, recorded);
|
|
30012
29955
|
if (detection.kind === null) {
|
|
30013
29956
|
await this.agree(detection.adopt, mode === "connect" && !options.keepOutcomeUnknown);
|
|
@@ -30015,7 +29958,7 @@ var MatterFabricService = class {
|
|
|
30015
29958
|
}
|
|
30016
29959
|
const facts = mode === "event" && detection.kind === "generation_ahead" ? this.advanceOnTrust(sidecar) : null;
|
|
30017
29960
|
if (facts) {
|
|
30018
|
-
await
|
|
29961
|
+
await this.storage.transaction((tables) => recordFacts(tables, facts));
|
|
30019
29962
|
for (const handler of this.advanced) handler(facts);
|
|
30020
29963
|
return null;
|
|
30021
29964
|
}
|
|
@@ -30033,7 +29976,7 @@ var MatterFabricService = class {
|
|
|
30033
29976
|
* ahead of the plugin's record, which is a mismatch.
|
|
30034
29977
|
*/
|
|
30035
29978
|
async agree(adopt, settlesOutcome) {
|
|
30036
|
-
if (adopt) await
|
|
29979
|
+
if (adopt) await this.storage.transaction((tables) => recordFacts(tables, adopt));
|
|
30037
29980
|
this.settle(null);
|
|
30038
29981
|
if (settlesOutcome) this.guard.outcomeUnknown = false;
|
|
30039
29982
|
}
|
|
@@ -30048,12 +29991,12 @@ var MatterFabricService = class {
|
|
|
30048
29991
|
async auditMismatch(kind) {
|
|
30049
29992
|
if (this.auditedMismatch === kind) return;
|
|
30050
29993
|
this.auditedMismatch = kind;
|
|
30051
|
-
const { subject, details } = fabricAudit((await recordedFabricRow(this.
|
|
29994
|
+
const { subject, details } = fabricAudit((await recordedFabricRow(this.tables))?.id ?? null);
|
|
30052
29995
|
await this.audit.record("matter.fabric_recovery_required", null, subject, { ...details, mismatch: kind });
|
|
30053
29996
|
}
|
|
30054
29997
|
/** An administrator's way out of recovery, audited on the fabric row the plugin recorded. */
|
|
30055
29998
|
async auditRecoveryChoice(choice, by, rowId = null) {
|
|
30056
|
-
const { subject, details } = fabricAudit(rowId ?? (await recordedFabricRow(this.
|
|
29999
|
+
const { subject, details } = fabricAudit(rowId ?? (await recordedFabricRow(this.tables))?.id ?? null);
|
|
30057
30000
|
await this.audit.record("matter.recovery_action_chosen", by, subject, { ...details, choice });
|
|
30058
30001
|
}
|
|
30059
30002
|
settle(kind) {
|
|
@@ -30072,7 +30015,7 @@ var MatterFabricService = class {
|
|
|
30072
30015
|
fabric = null;
|
|
30073
30016
|
}
|
|
30074
30017
|
}
|
|
30075
|
-
const recorded = factsOfRow(await recordedFabricRow(this.
|
|
30018
|
+
const recorded = factsOfRow(await recordedFabricRow(this.tables));
|
|
30076
30019
|
const key = await this.keys.view();
|
|
30077
30020
|
const reachable = connected && fabric !== null;
|
|
30078
30021
|
const state = fabric?.state ?? "unknown";
|
|
@@ -30151,7 +30094,9 @@ var MatterFabricService = class {
|
|
|
30151
30094
|
}
|
|
30152
30095
|
const facts = factsOf(result);
|
|
30153
30096
|
if (!facts) throw sidecarFailure(new Error("The sidecar did not report a fabric."));
|
|
30154
|
-
const row = await
|
|
30097
|
+
const row = await this.storage.transaction(
|
|
30098
|
+
(tables) => recordFacts(tables, facts, label2?.trim() || DEFAULT_LABEL)
|
|
30099
|
+
);
|
|
30155
30100
|
this.settle(null);
|
|
30156
30101
|
this.guard.outcomeUnknown = false;
|
|
30157
30102
|
return { facts, rowId: row.id };
|
|
@@ -30183,7 +30128,7 @@ var MatterFabricService = class {
|
|
|
30183
30128
|
this.guard.busy = true;
|
|
30184
30129
|
try {
|
|
30185
30130
|
await this.reconciliation.request(actor, { allowInRecovery: true });
|
|
30186
|
-
await
|
|
30131
|
+
await this.storage.transaction((tables) => recordFacts(tables, facts));
|
|
30187
30132
|
this.settle(null);
|
|
30188
30133
|
this.guard.outcomeUnknown = false;
|
|
30189
30134
|
} finally {
|
|
@@ -30199,7 +30144,7 @@ var MatterFabricService = class {
|
|
|
30199
30144
|
if (sidecar.state !== "uninitialized") {
|
|
30200
30145
|
throw conflict("sidecar_not_empty", "A new fabric can only be started on a sidecar without one.");
|
|
30201
30146
|
}
|
|
30202
|
-
const old = (await recordedFabricRow(this.
|
|
30147
|
+
const old = (await recordedFabricRow(this.tables))?.id ?? null;
|
|
30203
30148
|
const actor = this.audit.actorFor(principal);
|
|
30204
30149
|
if (old) await this.auditRecoveryChoice("start_new", actor, old);
|
|
30205
30150
|
const created = await this.createOnSidecar(label2);
|
|
@@ -30301,45 +30246,45 @@ var MatterFabricController = class {
|
|
|
30301
30246
|
}
|
|
30302
30247
|
};
|
|
30303
30248
|
__decorateClass([
|
|
30304
|
-
(0,
|
|
30249
|
+
(0, import_plugins_backend_sdk5.Auth)(...MATTER_OPERATIONS.fabricStatus),
|
|
30305
30250
|
(0, import_common11.Get)("fabric")
|
|
30306
30251
|
], MatterFabricController.prototype, "status", 1);
|
|
30307
30252
|
__decorateClass([
|
|
30308
|
-
(0,
|
|
30253
|
+
(0, import_plugins_backend_sdk5.Auth)(...MATTER_OPERATIONS.fabricCreate),
|
|
30309
30254
|
(0, import_common11.Post)("fabric/create"),
|
|
30310
30255
|
(0, import_common11.HttpCode)(200),
|
|
30311
30256
|
__decorateParam(0, (0, import_common11.Body)()),
|
|
30312
30257
|
__decorateParam(1, (0, import_common11.Req)())
|
|
30313
30258
|
], MatterFabricController.prototype, "create", 1);
|
|
30314
30259
|
__decorateClass([
|
|
30315
|
-
(0,
|
|
30260
|
+
(0, import_plugins_backend_sdk5.Auth)(...MATTER_OPERATIONS.recoveryKeyGenerate),
|
|
30316
30261
|
(0, import_common11.Post)("fabric/recovery-key"),
|
|
30317
30262
|
(0, import_common11.HttpCode)(200),
|
|
30318
30263
|
__decorateParam(0, (0, import_common11.Req)())
|
|
30319
30264
|
], MatterFabricController.prototype, "generateKey", 1);
|
|
30320
30265
|
__decorateClass([
|
|
30321
|
-
(0,
|
|
30266
|
+
(0, import_plugins_backend_sdk5.Auth)(...MATTER_OPERATIONS.recoveryKeyAcknowledge),
|
|
30322
30267
|
(0, import_common11.Post)("fabric/recovery-key/acknowledge"),
|
|
30323
30268
|
(0, import_common11.HttpCode)(200),
|
|
30324
30269
|
__decorateParam(0, (0, import_common11.Body)()),
|
|
30325
30270
|
__decorateParam(1, (0, import_common11.Req)())
|
|
30326
30271
|
], MatterFabricController.prototype, "acknowledge", 1);
|
|
30327
30272
|
__decorateClass([
|
|
30328
|
-
(0,
|
|
30273
|
+
(0, import_plugins_backend_sdk5.Auth)(...MATTER_OPERATIONS.recoveryKeyRotate),
|
|
30329
30274
|
(0, import_common11.Post)("fabric/recovery-key/rotate"),
|
|
30330
30275
|
(0, import_common11.HttpCode)(200),
|
|
30331
30276
|
__decorateParam(0, (0, import_common11.Body)()),
|
|
30332
30277
|
__decorateParam(1, (0, import_common11.Req)())
|
|
30333
30278
|
], MatterFabricController.prototype, "rotate", 1);
|
|
30334
30279
|
__decorateClass([
|
|
30335
|
-
(0,
|
|
30280
|
+
(0, import_plugins_backend_sdk5.Auth)(...MATTER_OPERATIONS.recoveryAcceptSidecar),
|
|
30336
30281
|
(0, import_common11.Post)("recovery/accept-sidecar"),
|
|
30337
30282
|
(0, import_common11.HttpCode)(200),
|
|
30338
30283
|
__decorateParam(0, (0, import_common11.Body)()),
|
|
30339
30284
|
__decorateParam(1, (0, import_common11.Req)())
|
|
30340
30285
|
], MatterFabricController.prototype, "acceptSidecar", 1);
|
|
30341
30286
|
__decorateClass([
|
|
30342
|
-
(0,
|
|
30287
|
+
(0, import_plugins_backend_sdk5.Auth)(...MATTER_OPERATIONS.recoveryStartNew),
|
|
30343
30288
|
(0, import_common11.Post)("recovery/start-new"),
|
|
30344
30289
|
(0, import_common11.HttpCode)(200),
|
|
30345
30290
|
__decorateParam(0, (0, import_common11.Body)()),
|
|
@@ -30451,10 +30396,10 @@ var RestoreCommitter = class {
|
|
|
30451
30396
|
async replaceTables(staged, facts, actor) {
|
|
30452
30397
|
const ref = staged.header.backupId;
|
|
30453
30398
|
try {
|
|
30454
|
-
await
|
|
30455
|
-
if (!tablesAreAcceptable(
|
|
30456
|
-
await replaceTables(
|
|
30457
|
-
if (staged.header.consistent !== false) await recordFacts(
|
|
30399
|
+
await matterStorage(this.context).transaction(async (tables) => {
|
|
30400
|
+
if (!tablesAreAcceptable(staged.body.tables)) throw new Error("unacceptable tables");
|
|
30401
|
+
await replaceTables(tables, staged.body.tables);
|
|
30402
|
+
if (staged.header.consistent !== false) await recordFacts(tables, facts);
|
|
30458
30403
|
});
|
|
30459
30404
|
} catch {
|
|
30460
30405
|
if (await this.rollback(staged.stageId) !== "rolled_back") throw await this.rollbackFailed(actor, ref);
|
|
@@ -30542,9 +30487,9 @@ var RestoreCommitter = class {
|
|
|
30542
30487
|
async recordRolledBack(facts) {
|
|
30543
30488
|
if (!facts) return;
|
|
30544
30489
|
try {
|
|
30545
|
-
await
|
|
30546
|
-
const recorded = await recordedFabricRow(
|
|
30547
|
-
if (recorded?.fabricId === facts.fabricId) await recordFacts(
|
|
30490
|
+
await matterStorage(this.context).transaction(async (tables) => {
|
|
30491
|
+
const recorded = await recordedFabricRow(tables);
|
|
30492
|
+
if (recorded?.fabricId === facts.fabricId) await recordFacts(tables, facts);
|
|
30548
30493
|
});
|
|
30549
30494
|
} catch {
|
|
30550
30495
|
this.context.logger.warn?.("The Matter fabric after a rollback could not be recorded.");
|
|
@@ -30556,11 +30501,11 @@ var RestoreCommitter = class {
|
|
|
30556
30501
|
var VALIDATION_TTL_MS = 15 * 6e4;
|
|
30557
30502
|
var RESTORE_VALIDATION_TTL = /* @__PURE__ */ Symbol.for("attraccess.matter.restore-ttl");
|
|
30558
30503
|
var MatterRestoreService = class {
|
|
30559
|
-
constructor(context, connectionService, keys,
|
|
30504
|
+
constructor(context, connectionService, keys, backups2, fabric, guard, audit, reconciliation, migrationReader, validationTtlMs = VALIDATION_TTL_MS, rollbackTiming = DEFAULT_ROLLBACK_TIMING) {
|
|
30560
30505
|
this.context = context;
|
|
30561
30506
|
this.connectionService = connectionService;
|
|
30562
30507
|
this.keys = keys;
|
|
30563
|
-
this.backups =
|
|
30508
|
+
this.backups = backups2;
|
|
30564
30509
|
this.fabric = fabric;
|
|
30565
30510
|
this.guard = guard;
|
|
30566
30511
|
this.audit = audit;
|
|
@@ -30596,9 +30541,7 @@ var MatterRestoreService = class {
|
|
|
30596
30541
|
const file2 = await this.load(source);
|
|
30597
30542
|
if (!file2) throw new import_common13.NotFoundException({ code: "not_found", message: "There is no such backup." });
|
|
30598
30543
|
const opened = await this.open(file2, recoveryKey, audited, refuse);
|
|
30599
|
-
if (!tablesAreAcceptable(
|
|
30600
|
-
return refuse("incompatible_schema");
|
|
30601
|
-
}
|
|
30544
|
+
if (!tablesAreAcceptable(opened.body.tables)) return refuse("incompatible_schema");
|
|
30602
30545
|
const preflight = await this.preflight(opened.header.fabricId);
|
|
30603
30546
|
if (this.running) await this.refuseBusy(audited.ref, actor);
|
|
30604
30547
|
this.running = true;
|
|
@@ -30863,8 +30806,8 @@ MatterRestoreService = __decorateClass([
|
|
|
30863
30806
|
|
|
30864
30807
|
// backend/backup/controller.ts
|
|
30865
30808
|
var MatterBackupController = class {
|
|
30866
|
-
constructor(
|
|
30867
|
-
this.backups =
|
|
30809
|
+
constructor(backups2, restore) {
|
|
30810
|
+
this.backups = backups2;
|
|
30868
30811
|
this.restore = restore;
|
|
30869
30812
|
}
|
|
30870
30813
|
list() {
|
|
@@ -30898,38 +30841,38 @@ var MatterBackupController = class {
|
|
|
30898
30841
|
}
|
|
30899
30842
|
};
|
|
30900
30843
|
__decorateClass([
|
|
30901
|
-
(0,
|
|
30844
|
+
(0, import_plugins_backend_sdk6.Auth)(...MATTER_OPERATIONS.backupList),
|
|
30902
30845
|
(0, import_common14.Get)("backups")
|
|
30903
30846
|
], MatterBackupController.prototype, "list", 1);
|
|
30904
30847
|
__decorateClass([
|
|
30905
|
-
(0,
|
|
30848
|
+
(0, import_plugins_backend_sdk6.Auth)(...MATTER_OPERATIONS.backupCreate),
|
|
30906
30849
|
(0, import_common14.Post)("backups"),
|
|
30907
30850
|
(0, import_common14.HttpCode)(200),
|
|
30908
30851
|
__decorateParam(0, (0, import_common14.Req)())
|
|
30909
30852
|
], MatterBackupController.prototype, "create", 1);
|
|
30910
30853
|
__decorateClass([
|
|
30911
|
-
(0,
|
|
30854
|
+
(0, import_plugins_backend_sdk6.Auth)(...MATTER_OPERATIONS.backupDownload),
|
|
30912
30855
|
(0, import_common14.Get)("backups/:id/download"),
|
|
30913
30856
|
(0, import_common14.Header)("Content-Type", "application/octet-stream"),
|
|
30914
30857
|
__decorateParam(0, (0, import_common14.Param)("id")),
|
|
30915
30858
|
__decorateParam(1, (0, import_common14.Req)())
|
|
30916
30859
|
], MatterBackupController.prototype, "download", 1);
|
|
30917
30860
|
__decorateClass([
|
|
30918
|
-
(0,
|
|
30861
|
+
(0, import_plugins_backend_sdk6.Auth)(...MATTER_OPERATIONS.restoreValidate),
|
|
30919
30862
|
(0, import_common14.Post)("restore/validate"),
|
|
30920
30863
|
(0, import_common14.HttpCode)(200),
|
|
30921
30864
|
__decorateParam(0, (0, import_common14.Body)()),
|
|
30922
30865
|
__decorateParam(1, (0, import_common14.Req)())
|
|
30923
30866
|
], MatterBackupController.prototype, "validate", 1);
|
|
30924
30867
|
__decorateClass([
|
|
30925
|
-
(0,
|
|
30868
|
+
(0, import_plugins_backend_sdk6.Auth)(...MATTER_OPERATIONS.restoreConfirm),
|
|
30926
30869
|
(0, import_common14.Post)("restore/confirm"),
|
|
30927
30870
|
(0, import_common14.HttpCode)(200),
|
|
30928
30871
|
__decorateParam(0, (0, import_common14.Body)()),
|
|
30929
30872
|
__decorateParam(1, (0, import_common14.Req)())
|
|
30930
30873
|
], MatterBackupController.prototype, "confirm", 1);
|
|
30931
30874
|
__decorateClass([
|
|
30932
|
-
(0,
|
|
30875
|
+
(0, import_plugins_backend_sdk6.Auth)(...MATTER_OPERATIONS.restoreCancel),
|
|
30933
30876
|
(0, import_common14.Post)("restore/:validationId/cancel"),
|
|
30934
30877
|
(0, import_common14.HttpCode)(204),
|
|
30935
30878
|
__decorateParam(0, (0, import_common14.Param)("validationId")),
|
|
@@ -30946,11 +30889,11 @@ var import_common15 = require("@nestjs/common");
|
|
|
30946
30889
|
var DEFAULT_TIMING = { intervalMs: 24 * 36e5, checkMs: 15 * 6e4, debounceMs: 3e4 };
|
|
30947
30890
|
var SCHEDULER_TIMING = /* @__PURE__ */ Symbol.for("attraccess.matter.backup-timing");
|
|
30948
30891
|
var MatterBackupSchedulerService = class {
|
|
30949
|
-
constructor(context, connectionService, fabric,
|
|
30892
|
+
constructor(context, connectionService, fabric, backups2, guard, timing = {}) {
|
|
30950
30893
|
this.context = context;
|
|
30951
30894
|
this.connectionService = connectionService;
|
|
30952
30895
|
this.fabric = fabric;
|
|
30953
|
-
this.backups =
|
|
30896
|
+
this.backups = backups2;
|
|
30954
30897
|
this.guard = guard;
|
|
30955
30898
|
this.unsubscribe = [];
|
|
30956
30899
|
this.timing = { ...DEFAULT_TIMING, ...timing };
|
|
@@ -31289,12 +31232,11 @@ var MATTER_AUDIT_DOMAIN = {
|
|
|
31289
31232
|
};
|
|
31290
31233
|
|
|
31291
31234
|
// backend/devices/controller.ts
|
|
31292
|
-
var
|
|
31235
|
+
var import_plugins_backend_sdk7 = require("@attraccess/plugins-backend-sdk");
|
|
31293
31236
|
var import_common18 = require("@nestjs/common");
|
|
31294
31237
|
|
|
31295
31238
|
// backend/devices/lifecycle.service.ts
|
|
31296
31239
|
var import_common16 = require("@nestjs/common");
|
|
31297
|
-
var import_typeorm = require("typeorm");
|
|
31298
31240
|
var METADATA_FIELDS = ["displayName", "description", "location"];
|
|
31299
31241
|
var MatterLifecycleService = class {
|
|
31300
31242
|
constructor(context, connectionService, audit) {
|
|
@@ -31302,28 +31244,29 @@ var MatterLifecycleService = class {
|
|
|
31302
31244
|
this.connectionService = connectionService;
|
|
31303
31245
|
this.audit = audit;
|
|
31304
31246
|
}
|
|
31305
|
-
get
|
|
31306
|
-
return this.context
|
|
31247
|
+
get storage() {
|
|
31248
|
+
return matterStorage(this.context);
|
|
31307
31249
|
}
|
|
31308
31250
|
// --- reads -----------------------------------------------------------------------------------------------------
|
|
31309
31251
|
async listNodes(filter) {
|
|
31310
|
-
const
|
|
31311
|
-
|
|
31312
|
-
|
|
31313
|
-
|
|
31252
|
+
const where = filter.lifecycleState ? { lifecycleState: filter.lifecycleState } : filter.includeInactive ? void 0 : { lifecycleState: { notIn: ["archived", "removed"] } };
|
|
31253
|
+
return this.storage.tables.nodes.find({
|
|
31254
|
+
where,
|
|
31255
|
+
orderBy: [{ field: "createdAt" }, { field: "nodeId" }]
|
|
31256
|
+
});
|
|
31314
31257
|
}
|
|
31315
31258
|
async getNode(id) {
|
|
31316
|
-
const
|
|
31317
|
-
const node2 = await this.require(
|
|
31318
|
-
const
|
|
31319
|
-
|
|
31320
|
-
const fabric = await
|
|
31321
|
-
const refs =
|
|
31259
|
+
const { tables } = this.storage;
|
|
31260
|
+
const node2 = await this.require(tables, id);
|
|
31261
|
+
const endpoints2 = await findLive(tables.endpoints, "nodeRef", node2.id);
|
|
31262
|
+
endpoints2.sort((a, b) => a.endpointId - b.endpointId);
|
|
31263
|
+
const fabric = await tables.fabrics.get(node2.fabricRef);
|
|
31264
|
+
const refs = endpoints2.map((endpoint) => endpoint.id);
|
|
31322
31265
|
const [clusters, capabilities] = refs.length === 0 ? [[], []] : await Promise.all([
|
|
31323
|
-
|
|
31324
|
-
|
|
31266
|
+
tables.endpointClusters.find({ where: { endpointRef: { in: refs }, removedAt: null } }),
|
|
31267
|
+
tables.endpointCapabilities.find({ where: { endpointRef: { in: refs } } })
|
|
31325
31268
|
]);
|
|
31326
|
-
const detailed =
|
|
31269
|
+
const detailed = endpoints2.map((endpoint) => ({
|
|
31327
31270
|
endpoint,
|
|
31328
31271
|
clusters: clusters.filter((cluster) => cluster.endpointRef === endpoint.id),
|
|
31329
31272
|
capabilities: capabilities.filter((capability) => capability.endpointRef === endpoint.id)
|
|
@@ -31331,22 +31274,23 @@ var MatterLifecycleService = class {
|
|
|
31331
31274
|
return { node: node2, fabric, endpoints: detailed };
|
|
31332
31275
|
}
|
|
31333
31276
|
async getEndpoint(id) {
|
|
31334
|
-
const endpoint = await this.
|
|
31277
|
+
const endpoint = await this.storage.tables.endpoints.get(id);
|
|
31335
31278
|
if (!endpoint) throw new import_common16.NotFoundException("Unknown Matter endpoint.");
|
|
31336
31279
|
return endpoint;
|
|
31337
31280
|
}
|
|
31338
31281
|
// --- actions ---------------------------------------------------------------------------------------------------
|
|
31339
31282
|
async claim(id, input2, actor) {
|
|
31340
|
-
const node2 = await this.
|
|
31341
|
-
const node3 = await this.require(
|
|
31283
|
+
const node2 = await this.storage.transaction(async (tables) => {
|
|
31284
|
+
const node3 = await this.require(tables, id);
|
|
31342
31285
|
this.expect(node3, ["unclaimed"], "claimed");
|
|
31343
31286
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
31344
|
-
|
|
31345
|
-
|
|
31346
|
-
|
|
31347
|
-
|
|
31348
|
-
|
|
31349
|
-
|
|
31287
|
+
await this.transition(tables, node3, ["unclaimed"], {
|
|
31288
|
+
lifecycleState: "claimed",
|
|
31289
|
+
claimedAt: now,
|
|
31290
|
+
claimedBy: actor.userId,
|
|
31291
|
+
updatedAt: now,
|
|
31292
|
+
...input2.displayName !== void 0 ? { displayName: input2.displayName } : {}
|
|
31293
|
+
});
|
|
31350
31294
|
return node3;
|
|
31351
31295
|
});
|
|
31352
31296
|
await this.audit.record("matter.node_claimed", actor, nodeSubject(node2), {
|
|
@@ -31361,10 +31305,10 @@ var MatterLifecycleService = class {
|
|
|
31361
31305
|
* record returns to the state it had before it was detached: claimed if it ever was, unclaimed otherwise.
|
|
31362
31306
|
*/
|
|
31363
31307
|
async relink(id, input2, actor) {
|
|
31364
|
-
const { target, source, mismatch } = await this.
|
|
31365
|
-
const target2 = await this.require(
|
|
31308
|
+
const { target, source, mismatch } = await this.storage.transaction(async (tables) => {
|
|
31309
|
+
const target2 = await this.require(tables, id);
|
|
31366
31310
|
this.expect(target2, ["detached"], "relinked");
|
|
31367
|
-
const source2 = await
|
|
31311
|
+
const source2 = await tables.nodes.get(input2.sourceNodeId);
|
|
31368
31312
|
if (!source2) throw new import_common16.NotFoundException("Unknown source node (sourceNodeId).");
|
|
31369
31313
|
if (source2.id === target2.id) throw new import_common16.ConflictException("A node cannot be relinked to itself.");
|
|
31370
31314
|
if (source2.lifecycleState !== "unclaimed") {
|
|
@@ -31382,20 +31326,24 @@ var MatterLifecycleService = class {
|
|
|
31382
31326
|
const identity = Object.fromEntries(NODE_IDENTITY_COLUMNS.map((key) => [key, source2[key]]));
|
|
31383
31327
|
const sourceFabricRef = source2.fabricRef;
|
|
31384
31328
|
const sourceNodeId = source2.nodeId;
|
|
31385
|
-
|
|
31386
|
-
|
|
31387
|
-
|
|
31388
|
-
|
|
31389
|
-
|
|
31390
|
-
|
|
31391
|
-
|
|
31392
|
-
|
|
31393
|
-
|
|
31394
|
-
|
|
31395
|
-
|
|
31396
|
-
|
|
31397
|
-
|
|
31398
|
-
|
|
31329
|
+
await this.transition(tables, source2, ["unclaimed"], {
|
|
31330
|
+
lifecycleState: "removed",
|
|
31331
|
+
removedAt: now,
|
|
31332
|
+
removedBy: actor.userId,
|
|
31333
|
+
removalReason: "merged",
|
|
31334
|
+
mergedInto: target2.id,
|
|
31335
|
+
updatedAt: now
|
|
31336
|
+
});
|
|
31337
|
+
await this.transition(tables, target2, ["detached"], {
|
|
31338
|
+
...identity,
|
|
31339
|
+
fabricRef: sourceFabricRef,
|
|
31340
|
+
nodeId: sourceNodeId,
|
|
31341
|
+
lifecycleState: reattachedState(target2),
|
|
31342
|
+
detachedReason: null,
|
|
31343
|
+
detachedAt: null,
|
|
31344
|
+
updatedAt: now
|
|
31345
|
+
});
|
|
31346
|
+
await this.moveEndpoints(tables, source2, target2, now);
|
|
31399
31347
|
return { target: target2, source: source2, mismatch: mismatch2 };
|
|
31400
31348
|
});
|
|
31401
31349
|
await this.audit.record("matter.node_relinked", actor, nodeSubject(target), {
|
|
@@ -31407,18 +31355,18 @@ var MatterLifecycleService = class {
|
|
|
31407
31355
|
}
|
|
31408
31356
|
/** Re-reads one node from the sidecar. Changes nothing when the sidecar cannot answer. */
|
|
31409
31357
|
async repair(id, actor) {
|
|
31410
|
-
const before = await this.require(this.
|
|
31358
|
+
const before = await this.require(this.storage.tables, id);
|
|
31411
31359
|
this.expect(before, ["unclaimed", "claimed", "detached"], "repaired");
|
|
31412
|
-
const fabric = await this.
|
|
31360
|
+
const fabric = await this.storage.tables.fabrics.get(before.fabricRef);
|
|
31413
31361
|
if (!fabric) throw new import_common16.ConflictException("The node has no fabric record.");
|
|
31414
31362
|
const view = await this.readFromSidecar(fabric, before.nodeId);
|
|
31415
|
-
const { node: node2, reattached } = await this.
|
|
31416
|
-
const node3 = await this.require(
|
|
31363
|
+
const { node: node2, reattached } = await this.storage.transaction(async (tables) => {
|
|
31364
|
+
const node3 = await this.require(tables, id);
|
|
31417
31365
|
this.expect(node3, ["unclaimed", "claimed", "detached"], "repaired");
|
|
31418
31366
|
if (node3.fabricRef !== fabric.id || node3.nodeId !== before.nodeId) {
|
|
31419
31367
|
throw new import_common16.ConflictException("The node changed while it was read from the sidecar. Nothing was changed.");
|
|
31420
31368
|
}
|
|
31421
|
-
const current = await
|
|
31369
|
+
const current = await tables.fabrics.get(fabric.id);
|
|
31422
31370
|
if (current?.status !== "active") {
|
|
31423
31371
|
throw new import_common16.ConflictException(
|
|
31424
31372
|
"The node's fabric is not the active one. Run a reconciliation first. Nothing was changed."
|
|
@@ -31427,14 +31375,15 @@ var MatterLifecycleService = class {
|
|
|
31427
31375
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
31428
31376
|
let reattached2 = false;
|
|
31429
31377
|
if (node3.lifecycleState === "detached") {
|
|
31430
|
-
|
|
31431
|
-
|
|
31432
|
-
|
|
31433
|
-
|
|
31434
|
-
|
|
31378
|
+
await this.transition(tables, node3, ["detached"], {
|
|
31379
|
+
lifecycleState: reattachedState(node3),
|
|
31380
|
+
detachedReason: null,
|
|
31381
|
+
detachedAt: null,
|
|
31382
|
+
updatedAt: now
|
|
31383
|
+
});
|
|
31435
31384
|
reattached2 = true;
|
|
31436
31385
|
}
|
|
31437
|
-
await syncNode(
|
|
31386
|
+
await syncNode(tables, node3, view, now, newCounters());
|
|
31438
31387
|
return { node: node3, reattached: reattached2 };
|
|
31439
31388
|
});
|
|
31440
31389
|
await this.audit.record("matter.node_repaired", actor, nodeSubject(node2), { nodeRef: node2.id, reattached });
|
|
@@ -31442,16 +31391,17 @@ var MatterLifecycleService = class {
|
|
|
31442
31391
|
}
|
|
31443
31392
|
async archive(id, actor) {
|
|
31444
31393
|
let previousState = "detached";
|
|
31445
|
-
const node2 = await this.
|
|
31446
|
-
const node3 = await this.require(
|
|
31394
|
+
const node2 = await this.storage.transaction(async (tables) => {
|
|
31395
|
+
const node3 = await this.require(tables, id);
|
|
31447
31396
|
this.expect(node3, ["detached", "unclaimed"], "archived");
|
|
31448
31397
|
previousState = node3.lifecycleState;
|
|
31449
31398
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
31450
|
-
|
|
31451
|
-
|
|
31452
|
-
|
|
31453
|
-
|
|
31454
|
-
|
|
31399
|
+
await this.transition(tables, node3, ["detached", "unclaimed"], {
|
|
31400
|
+
lifecycleState: "archived",
|
|
31401
|
+
archivedAt: now,
|
|
31402
|
+
archivedBy: actor.userId,
|
|
31403
|
+
updatedAt: now
|
|
31404
|
+
});
|
|
31455
31405
|
return node3;
|
|
31456
31406
|
});
|
|
31457
31407
|
await this.audit.record("matter.node_archived", actor, nodeSubject(node2), { nodeRef: node2.id, previousState });
|
|
@@ -31462,18 +31412,21 @@ var MatterLifecycleService = class {
|
|
|
31462
31412
|
* by a fabric mismatch keeps that reason, so only repair or relink bring it back.
|
|
31463
31413
|
*/
|
|
31464
31414
|
async restore(id, actor) {
|
|
31465
|
-
const node2 = await this.
|
|
31466
|
-
const node3 = await this.require(
|
|
31415
|
+
const node2 = await this.storage.transaction(async (tables) => {
|
|
31416
|
+
const node3 = await this.require(tables, id);
|
|
31467
31417
|
this.expect(node3, ["archived"], "restored");
|
|
31468
31418
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
31469
|
-
const fabric = await
|
|
31470
|
-
|
|
31471
|
-
|
|
31472
|
-
|
|
31473
|
-
|
|
31474
|
-
|
|
31475
|
-
|
|
31476
|
-
|
|
31419
|
+
const fabric = await tables.fabrics.get(node3.fabricRef);
|
|
31420
|
+
await this.transition(tables, node3, ["archived"], {
|
|
31421
|
+
lifecycleState: "detached",
|
|
31422
|
+
// A node archived while unclaimed has no reason yet. If its fabric is no longer the sidecar's, it belongs to a
|
|
31423
|
+
// fabric mismatch like its siblings and must not be re-attached by itself either.
|
|
31424
|
+
detachedReason: node3.detachedReason ?? (fabric?.status === "active" ? "absent_from_sidecar" : "fabric_mismatch"),
|
|
31425
|
+
detachedAt: now,
|
|
31426
|
+
archivedAt: null,
|
|
31427
|
+
archivedBy: null,
|
|
31428
|
+
updatedAt: now
|
|
31429
|
+
});
|
|
31477
31430
|
return node3;
|
|
31478
31431
|
});
|
|
31479
31432
|
await this.audit.record("matter.node_restored", actor, nodeSubject(node2), { nodeRef: node2.id });
|
|
@@ -31485,19 +31438,20 @@ var MatterLifecycleService = class {
|
|
|
31485
31438
|
*/
|
|
31486
31439
|
async forceRemove(id, actor) {
|
|
31487
31440
|
let previousState = "detached";
|
|
31488
|
-
const node2 = await this.
|
|
31489
|
-
const node3 = await this.require(
|
|
31441
|
+
const node2 = await this.storage.transaction(async (tables) => {
|
|
31442
|
+
const node3 = await this.require(tables, id);
|
|
31490
31443
|
this.expect(node3, ["unclaimed", "claimed", "detached", "archived"], "force-removed");
|
|
31491
31444
|
previousState = node3.lifecycleState;
|
|
31492
31445
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
31493
|
-
|
|
31494
|
-
|
|
31495
|
-
|
|
31496
|
-
|
|
31497
|
-
|
|
31498
|
-
|
|
31499
|
-
|
|
31500
|
-
|
|
31446
|
+
await this.transition(tables, node3, ["unclaimed", "claimed", "detached", "archived"], {
|
|
31447
|
+
lifecycleState: "removed",
|
|
31448
|
+
removedAt: now,
|
|
31449
|
+
removedBy: actor.userId,
|
|
31450
|
+
removalReason: "force_removed",
|
|
31451
|
+
updatedAt: now
|
|
31452
|
+
});
|
|
31453
|
+
for (const endpoint of await findLive(tables.endpoints, "nodeRef", node3.id)) {
|
|
31454
|
+
await retireEndpoint(tables, endpoint, "force_removed", now);
|
|
31501
31455
|
}
|
|
31502
31456
|
return node3;
|
|
31503
31457
|
});
|
|
@@ -31506,15 +31460,14 @@ var MatterLifecycleService = class {
|
|
|
31506
31460
|
}
|
|
31507
31461
|
// --- metadata --------------------------------------------------------------------------------------------------
|
|
31508
31462
|
async updateNode(id, input2, actor) {
|
|
31509
|
-
const { node: node2, flags } = await this.
|
|
31510
|
-
const node3 = await this.require(
|
|
31463
|
+
const { node: node2, flags } = await this.storage.transaction(async (tables) => {
|
|
31464
|
+
const node3 = await this.require(tables, id);
|
|
31511
31465
|
if (node3.lifecycleState === "removed") throw new import_common16.ConflictException("A removed node cannot be edited.");
|
|
31512
31466
|
const flags2 = applyMetadata(node3, input2);
|
|
31513
31467
|
if (!flags2) return { node: node3, flags: flags2 };
|
|
31514
31468
|
node3.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
31515
|
-
await
|
|
31516
|
-
|
|
31517
|
-
{ id: node3.id },
|
|
31469
|
+
const changed = await tables.nodes.update(
|
|
31470
|
+
{ id: node3.id, lifecycleState: { ne: "removed" } },
|
|
31518
31471
|
{
|
|
31519
31472
|
displayName: node3.displayName,
|
|
31520
31473
|
description: node3.description,
|
|
@@ -31522,6 +31475,7 @@ var MatterLifecycleService = class {
|
|
|
31522
31475
|
updatedAt: node3.updatedAt
|
|
31523
31476
|
}
|
|
31524
31477
|
);
|
|
31478
|
+
if (changed === 0) throw new import_common16.ConflictException("A removed node cannot be edited.");
|
|
31525
31479
|
return { node: node3, flags: flags2 };
|
|
31526
31480
|
});
|
|
31527
31481
|
if (!flags) return node2;
|
|
@@ -31529,14 +31483,13 @@ var MatterLifecycleService = class {
|
|
|
31529
31483
|
return node2;
|
|
31530
31484
|
}
|
|
31531
31485
|
async updateEndpoint(id, input2, actor) {
|
|
31532
|
-
const { endpoint, flags } = await this.
|
|
31533
|
-
const endpoint2 = await
|
|
31486
|
+
const { endpoint, flags } = await this.storage.transaction(async (tables) => {
|
|
31487
|
+
const endpoint2 = await tables.endpoints.get(id);
|
|
31534
31488
|
if (!endpoint2) throw new import_common16.NotFoundException("Unknown Matter endpoint.");
|
|
31535
31489
|
if (endpoint2.removedAt !== null) throw new import_common16.ConflictException("A removed endpoint cannot be edited.");
|
|
31536
31490
|
const flags2 = applyMetadata(endpoint2, input2);
|
|
31537
31491
|
if (flags2) {
|
|
31538
|
-
await
|
|
31539
|
-
MatterEndpoint,
|
|
31492
|
+
await tables.endpoints.update(
|
|
31540
31493
|
{ id: endpoint2.id },
|
|
31541
31494
|
{ displayName: endpoint2.displayName, description: endpoint2.description, location: endpoint2.location }
|
|
31542
31495
|
);
|
|
@@ -31557,11 +31510,20 @@ var MatterLifecycleService = class {
|
|
|
31557
31510
|
return endpoint;
|
|
31558
31511
|
}
|
|
31559
31512
|
// --- helpers ---------------------------------------------------------------------------------------------------
|
|
31560
|
-
async require(
|
|
31561
|
-
const node2 = await
|
|
31513
|
+
async require(tables, id) {
|
|
31514
|
+
const node2 = await tables.nodes.get(id);
|
|
31562
31515
|
if (!node2) throw new import_common16.NotFoundException("Unknown Matter node.");
|
|
31563
31516
|
return node2;
|
|
31564
31517
|
}
|
|
31518
|
+
/**
|
|
31519
|
+
* Writes `patch` to the node, compare-and-set on the lifecycle state the caller checked: another writer that moved
|
|
31520
|
+
* the node first makes this fail with 409 instead of being overwritten. The in-memory node follows the patch.
|
|
31521
|
+
*/
|
|
31522
|
+
async transition(tables, node2, allowed, patch) {
|
|
31523
|
+
const changed = await tables.nodes.update({ id: node2.id, lifecycleState: { in: allowed } }, patch);
|
|
31524
|
+
if (changed === 0) throw new import_common16.ConflictException("The node changed in the meantime. Nothing was changed.");
|
|
31525
|
+
Object.assign(node2, patch);
|
|
31526
|
+
}
|
|
31565
31527
|
expect(node2, allowed, verb) {
|
|
31566
31528
|
if (!allowed.includes(node2.lifecycleState)) {
|
|
31567
31529
|
throw new import_common16.ConflictException(
|
|
@@ -31571,15 +31533,15 @@ var MatterLifecycleService = class {
|
|
|
31571
31533
|
}
|
|
31572
31534
|
/** The node as the sidecar reports it now, or a 409/503 that changes nothing. */
|
|
31573
31535
|
async readFromSidecar(fabric, nodeId) {
|
|
31574
|
-
const
|
|
31536
|
+
const connection2 = this.connectionService.connection;
|
|
31575
31537
|
try {
|
|
31576
|
-
const sidecarFabric = await
|
|
31538
|
+
const sidecarFabric = await connection2.request("fabric.get");
|
|
31577
31539
|
if (sidecarFabric.fabricId !== fabric.fabricId) {
|
|
31578
31540
|
throw new import_common16.ConflictException(
|
|
31579
31541
|
sidecarFabric.fabricId === null ? "The sidecar has no fabric. Nothing was changed." : "The sidecar runs a different fabric than the one this node belongs to. Nothing was changed."
|
|
31580
31542
|
);
|
|
31581
31543
|
}
|
|
31582
|
-
return await
|
|
31544
|
+
return await connection2.request("inventory.get", { params: { nodeId } });
|
|
31583
31545
|
} catch (error62) {
|
|
31584
31546
|
if (error62 instanceof import_common16.ConflictException) throw error62;
|
|
31585
31547
|
if (error62 instanceof SidecarClientError) {
|
|
@@ -31599,42 +31561,44 @@ var MatterLifecycleService = class {
|
|
|
31599
31561
|
}
|
|
31600
31562
|
}
|
|
31601
31563
|
/** Moves the source node's endpoints onto the target, matched by endpoint ID (and bridged unique ID when known). */
|
|
31602
|
-
async moveEndpoints(
|
|
31603
|
-
const sourceEndpoints = await findLive(
|
|
31604
|
-
const targetEndpoints = await findLive(
|
|
31564
|
+
async moveEndpoints(tables, source, target, now) {
|
|
31565
|
+
const sourceEndpoints = await findLive(tables.endpoints, "nodeRef", source.id);
|
|
31566
|
+
const targetEndpoints = await findLive(tables.endpoints, "nodeRef", target.id);
|
|
31605
31567
|
const targetById = new Map(targetEndpoints.map((endpoint) => [endpoint.endpointId, endpoint]));
|
|
31606
31568
|
const matched = /* @__PURE__ */ new Set();
|
|
31607
31569
|
const moves = [];
|
|
31608
31570
|
for (const from of sourceEndpoints) {
|
|
31609
31571
|
const candidate = targetById.get(from.endpointId) ?? null;
|
|
31610
31572
|
const sameHardware = candidate !== null && (candidate.bridgedUniqueId === null || from.bridgedUniqueId === null || candidate.bridgedUniqueId === from.bridgedUniqueId);
|
|
31611
|
-
if (candidate && !sameHardware) await retireEndpoint(
|
|
31573
|
+
if (candidate && !sameHardware) await retireEndpoint(tables, candidate, "replaced", now);
|
|
31612
31574
|
moves.push({ from, to: sameHardware ? candidate : null });
|
|
31613
31575
|
if (sameHardware && candidate) matched.add(candidate.id);
|
|
31614
31576
|
}
|
|
31615
31577
|
for (const endpoint of targetEndpoints) {
|
|
31616
31578
|
if (!matched.has(endpoint.id) && endpoint.removedAt === null) {
|
|
31617
|
-
await retireEndpoint(
|
|
31579
|
+
await retireEndpoint(tables, endpoint, "absent_from_sidecar", now);
|
|
31618
31580
|
}
|
|
31619
31581
|
}
|
|
31620
31582
|
for (const { from, to } of moves) {
|
|
31621
31583
|
if (!to) {
|
|
31622
31584
|
from.nodeRef = target.id;
|
|
31623
|
-
await
|
|
31585
|
+
await tables.endpoints.update({ id: from.id }, { nodeRef: target.id });
|
|
31624
31586
|
continue;
|
|
31625
31587
|
}
|
|
31626
|
-
|
|
31627
|
-
|
|
31628
|
-
|
|
31629
|
-
|
|
31630
|
-
await
|
|
31631
|
-
await
|
|
31632
|
-
await
|
|
31633
|
-
await
|
|
31634
|
-
await
|
|
31588
|
+
await tables.endpoints.update(
|
|
31589
|
+
{ id: to.id },
|
|
31590
|
+
Object.fromEntries(ENDPOINT_PROTOCOL_COLUMNS.map((key) => [key, from[key]]))
|
|
31591
|
+
);
|
|
31592
|
+
await tables.endpointClusters.update({ endpointRef: to.id, removedAt: null }, { removedAt: now });
|
|
31593
|
+
await tables.endpointCapabilities.delete({ endpointRef: to.id });
|
|
31594
|
+
await tables.endpointState.delete({ endpointRef: to.id });
|
|
31595
|
+
await tables.endpointClusters.update({ endpointRef: from.id, removedAt: null }, { endpointRef: to.id });
|
|
31596
|
+
await tables.endpointCapabilities.update({ endpointRef: from.id }, { endpointRef: to.id });
|
|
31597
|
+
await tables.endpointState.update({ endpointRef: from.id }, { endpointRef: to.id });
|
|
31598
|
+
await tables.commands.update({ endpointRef: from.id }, { endpointRef: to.id });
|
|
31635
31599
|
from.removedAt = now;
|
|
31636
31600
|
from.removalReason = "merged";
|
|
31637
|
-
await
|
|
31601
|
+
await tables.endpoints.update({ id: from.id }, { removedAt: now, removalReason: "merged" });
|
|
31638
31602
|
}
|
|
31639
31603
|
}
|
|
31640
31604
|
};
|
|
@@ -31721,7 +31685,7 @@ function canonicalJson2(value) {
|
|
|
31721
31685
|
const entries = Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson2(value[key])}`);
|
|
31722
31686
|
return `{${entries.join(",")}}`;
|
|
31723
31687
|
}
|
|
31724
|
-
var time3 = (
|
|
31688
|
+
var time3 = (iso2) => iso2 === null ? Number.NaN : Date.parse(iso2);
|
|
31725
31689
|
var isPending = (state) => state === "requested" || state === "accepted";
|
|
31726
31690
|
var isResolvable = (state) => isPending(state) || state === "uncertain";
|
|
31727
31691
|
function applyRequest(row, request) {
|
|
@@ -31846,6 +31810,16 @@ function toView(row, now = Date.now()) {
|
|
|
31846
31810
|
// backend/devices/state.service.ts
|
|
31847
31811
|
var MAX_CLOCK_SKEW_MS = 5 * 6e4;
|
|
31848
31812
|
var MAX_VALUE_BYTES = 4096;
|
|
31813
|
+
var newDelta = () => ({
|
|
31814
|
+
applied: 0,
|
|
31815
|
+
outOfOrder: 0,
|
|
31816
|
+
unknownEndpoint: 0,
|
|
31817
|
+
inactiveNode: 0,
|
|
31818
|
+
unmappedCluster: 0,
|
|
31819
|
+
unknownCommand: 0,
|
|
31820
|
+
futureTimestamp: 0,
|
|
31821
|
+
oversizedValue: 0
|
|
31822
|
+
});
|
|
31849
31823
|
var MatterStateService = class {
|
|
31850
31824
|
constructor(context) {
|
|
31851
31825
|
this.context = context;
|
|
@@ -31861,21 +31835,25 @@ var MatterStateService = class {
|
|
|
31861
31835
|
dropped: 0
|
|
31862
31836
|
};
|
|
31863
31837
|
}
|
|
31864
|
-
get
|
|
31865
|
-
return this.context
|
|
31838
|
+
get storage() {
|
|
31839
|
+
return matterStorage(this.context);
|
|
31866
31840
|
}
|
|
31867
31841
|
// --- reads ---------------------------------------------------------------------------------------------------
|
|
31868
31842
|
async read(endpointRef, now = Date.now()) {
|
|
31869
|
-
const rows = await this.
|
|
31843
|
+
const rows = await this.storage.tables.endpointState.find({
|
|
31844
|
+
where: { endpointRef },
|
|
31845
|
+
orderBy: [{ field: "stateKey", direction: "asc" }]
|
|
31846
|
+
});
|
|
31870
31847
|
return rows.map((row) => toView(row, now));
|
|
31871
31848
|
}
|
|
31872
31849
|
// --- internal API for the commands ticket ------------------------------------------------------------------
|
|
31873
31850
|
/** Records that a command was requested for a state key. Sets `requested`; the command stays unconfirmed. */
|
|
31874
31851
|
async recordRequest(input2, now = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
31875
|
-
return this.
|
|
31876
|
-
const
|
|
31877
|
-
|
|
31878
|
-
|
|
31852
|
+
return this.storage.transaction(async (tables) => {
|
|
31853
|
+
const current = await tables.endpointState.findOne({
|
|
31854
|
+
where: { endpointRef: input2.endpointRef, stateKey: input2.stateKey }
|
|
31855
|
+
});
|
|
31856
|
+
if (await tables.commands.get(input2.requestId)) {
|
|
31879
31857
|
return toView(current ?? emptyState(input2.endpointRef, input2.stateKey, (0, import_node_crypto14.randomUUID)(), now));
|
|
31880
31858
|
}
|
|
31881
31859
|
const next = applyRequest(current ?? emptyState(input2.endpointRef, input2.stateKey, (0, import_node_crypto14.randomUUID)(), now), {
|
|
@@ -31885,8 +31863,8 @@ var MatterStateService = class {
|
|
|
31885
31863
|
requestId: input2.requestId,
|
|
31886
31864
|
correlationId: input2.correlationId ?? null
|
|
31887
31865
|
});
|
|
31888
|
-
await
|
|
31889
|
-
await
|
|
31866
|
+
await tables.endpointState.upsert(next, { conflictOn: ["id"] });
|
|
31867
|
+
await tables.commands.insert({
|
|
31890
31868
|
requestId: input2.requestId,
|
|
31891
31869
|
endpointRef: input2.endpointRef,
|
|
31892
31870
|
clusterId: input2.clusterId,
|
|
@@ -31900,44 +31878,64 @@ var MatterStateService = class {
|
|
|
31900
31878
|
reportedAt: null,
|
|
31901
31879
|
failureCode: null
|
|
31902
31880
|
});
|
|
31903
|
-
await pruneCommands(
|
|
31881
|
+
await pruneCommands(tables, new Date(now));
|
|
31904
31882
|
return toView(next);
|
|
31905
31883
|
});
|
|
31906
31884
|
}
|
|
31907
31885
|
/** A physical command timed out: the effect is unknown. It becomes `uncertain` and is never retried here. */
|
|
31908
31886
|
async recordTimeout(requestId, now = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
31909
|
-
|
|
31910
|
-
|
|
31911
|
-
|
|
31887
|
+
const delta = newDelta();
|
|
31888
|
+
await this.storage.transaction(
|
|
31889
|
+
(tables) => this.applyOutcomeFor(
|
|
31890
|
+
tables,
|
|
31912
31891
|
requestId,
|
|
31913
31892
|
null,
|
|
31914
31893
|
{ outcome: TIMEOUT_OUTCOME, acceptedAt: null, reportedAt: null },
|
|
31915
31894
|
null,
|
|
31916
|
-
now
|
|
31895
|
+
now,
|
|
31896
|
+
delta
|
|
31917
31897
|
)
|
|
31918
31898
|
);
|
|
31899
|
+
this.merge(delta);
|
|
31919
31900
|
}
|
|
31920
31901
|
// --- event ingestion -------------------------------------------------------------------------------------------
|
|
31921
31902
|
/**
|
|
31922
|
-
* Applies events in order, in one
|
|
31923
|
-
*
|
|
31903
|
+
* Applies events in order, in one transaction: one commit for a whole burst of telemetry. The record port has no
|
|
31904
|
+
* savepoints, so an event that cannot be applied cannot be undone alone inside that transaction: the whole batch
|
|
31905
|
+
* is rolled back and its events are applied one by one, each in a transaction of its own. The rare failing event is
|
|
31906
|
+
* then skipped alone, and the others still apply.
|
|
31924
31907
|
*/
|
|
31925
31908
|
async ingest(events, receivedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
31926
31909
|
if (events.length === 0) return;
|
|
31927
|
-
|
|
31928
|
-
|
|
31929
|
-
|
|
31930
|
-
|
|
31931
|
-
|
|
31932
|
-
|
|
31933
|
-
|
|
31934
|
-
|
|
31935
|
-
|
|
31936
|
-
|
|
31937
|
-
|
|
31938
|
-
|
|
31910
|
+
const batch = newDelta();
|
|
31911
|
+
try {
|
|
31912
|
+
const fabrics2 = /* @__PURE__ */ new Map();
|
|
31913
|
+
await this.storage.transaction(async (tables) => {
|
|
31914
|
+
for (const event of events)
|
|
31915
|
+
await this.applyEvent(tables, fabrics2, event, event.receivedAt ?? receivedAt, batch);
|
|
31916
|
+
});
|
|
31917
|
+
this.merge(batch);
|
|
31918
|
+
return;
|
|
31919
|
+
} catch {
|
|
31920
|
+
this.context.logger.debug?.("A batch of Matter events is applied one by one after one of them failed.");
|
|
31921
|
+
}
|
|
31922
|
+
for (const event of events) {
|
|
31923
|
+
const delta = newDelta();
|
|
31924
|
+
try {
|
|
31925
|
+
await this.storage.transaction(
|
|
31926
|
+
(tables) => this.applyEvent(tables, /* @__PURE__ */ new Map(), event, event.receivedAt ?? receivedAt, delta)
|
|
31927
|
+
);
|
|
31928
|
+
this.merge(delta);
|
|
31929
|
+
} catch {
|
|
31930
|
+
this.context.logger.warn?.("A Matter event could not be applied to the device state.");
|
|
31939
31931
|
}
|
|
31940
|
-
}
|
|
31932
|
+
}
|
|
31933
|
+
}
|
|
31934
|
+
applyEvent(tables, fabrics2, event, at, delta) {
|
|
31935
|
+
return event.type === "device.state" ? this.reportIn(tables, fabrics2, event.payload, at, delta) : this.outcomeIn(tables, fabrics2, event.payload, at, delta);
|
|
31936
|
+
}
|
|
31937
|
+
merge(delta) {
|
|
31938
|
+
for (const key of Object.keys(delta)) this.stats[key] += delta[key];
|
|
31941
31939
|
}
|
|
31942
31940
|
/** One `device.state` event on its own. */
|
|
31943
31941
|
ingestReport(payload, receivedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
@@ -31947,17 +31945,16 @@ var MatterStateService = class {
|
|
|
31947
31945
|
ingestOutcome(payload, now = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
31948
31946
|
return this.ingest([{ type: "command.outcome", payload }], now);
|
|
31949
31947
|
}
|
|
31950
|
-
async reportIn(
|
|
31948
|
+
async reportIn(tables, fabrics2, payload, receivedAt, delta) {
|
|
31951
31949
|
const stateKey = stateKeyFor(payload.clusterId, payload.attributeId);
|
|
31952
|
-
if (stateKey === null) return void (
|
|
31950
|
+
if (stateKey === null) return void (delta.unmappedCluster += 1);
|
|
31953
31951
|
if (Date.parse(payload.observedAt) > Date.parse(receivedAt) + MAX_CLOCK_SKEW_MS) {
|
|
31954
|
-
return void (
|
|
31952
|
+
return void (delta.futureTimestamp += 1);
|
|
31955
31953
|
}
|
|
31956
|
-
if (!fitsValueBound(payload.value)) return void (
|
|
31957
|
-
const resolved = await this.resolve(
|
|
31958
|
-
if ("ignored" in resolved) return void (
|
|
31959
|
-
const
|
|
31960
|
-
const row = await states.findOneBy({ endpointRef: resolved.endpoint.id, stateKey }) ?? emptyState(resolved.endpoint.id, stateKey, (0, import_node_crypto14.randomUUID)(), receivedAt);
|
|
31954
|
+
if (!fitsValueBound(payload.value)) return void (delta.oversizedValue += 1);
|
|
31955
|
+
const resolved = await this.resolve(tables, fabrics2, payload);
|
|
31956
|
+
if ("ignored" in resolved) return void (delta[resolved.ignored] += 1);
|
|
31957
|
+
const row = await tables.endpointState.findOne({ where: { endpointRef: resolved.endpoint.id, stateKey } }) ?? emptyState(resolved.endpoint.id, stateKey, (0, import_node_crypto14.randomUUID)(), receivedAt);
|
|
31961
31958
|
const next = applyReport(
|
|
31962
31959
|
row,
|
|
31963
31960
|
{
|
|
@@ -31969,39 +31966,38 @@ var MatterStateService = class {
|
|
|
31969
31966
|
},
|
|
31970
31967
|
receivedAt
|
|
31971
31968
|
);
|
|
31972
|
-
if (!next) return void (
|
|
31973
|
-
await
|
|
31969
|
+
if (!next) return void (delta.outOfOrder += 1);
|
|
31970
|
+
await tables.endpointState.upsert(next, { conflictOn: ["id"] });
|
|
31974
31971
|
if (next.commandState === "reported" && row.commandState !== "reported" && next.requestId) {
|
|
31975
|
-
await
|
|
31976
|
-
MatterCommand,
|
|
31972
|
+
await tables.commands.update(
|
|
31977
31973
|
{ requestId: next.requestId },
|
|
31978
31974
|
{ outcome: "reported", reportedAt: next.commandReportedAt }
|
|
31979
31975
|
);
|
|
31980
31976
|
}
|
|
31981
|
-
|
|
31977
|
+
delta.applied += 1;
|
|
31982
31978
|
}
|
|
31983
|
-
async outcomeIn(
|
|
31984
|
-
const resolved = await this.resolve(
|
|
31985
|
-
if ("ignored" in resolved) return void (
|
|
31979
|
+
async outcomeIn(tables, fabrics2, payload, now, delta) {
|
|
31980
|
+
const resolved = await this.resolve(tables, fabrics2, payload);
|
|
31981
|
+
if ("ignored" in resolved) return void (delta[resolved.ignored] += 1);
|
|
31986
31982
|
await this.applyOutcomeFor(
|
|
31987
|
-
|
|
31983
|
+
tables,
|
|
31988
31984
|
payload.requestId,
|
|
31989
31985
|
resolved.endpoint.id,
|
|
31990
31986
|
{ outcome: payload.outcome, acceptedAt: payload.acceptedAt, reportedAt: payload.reportedAt },
|
|
31991
31987
|
payload.failureCode ?? null,
|
|
31992
|
-
now
|
|
31988
|
+
now,
|
|
31989
|
+
delta
|
|
31993
31990
|
);
|
|
31994
31991
|
}
|
|
31995
31992
|
/** `endpointRef` is where the event says the command ran; null for the plugin's own timeout. */
|
|
31996
|
-
async applyOutcomeFor(
|
|
31997
|
-
const command = await
|
|
31993
|
+
async applyOutcomeFor(tables, requestId, endpointRef, input2, failureCode, now, delta) {
|
|
31994
|
+
const command = await tables.commands.get(requestId);
|
|
31998
31995
|
if (!command || endpointRef !== null && command.endpointRef !== endpointRef) {
|
|
31999
|
-
return void (
|
|
31996
|
+
return void (delta.unknownCommand += 1);
|
|
32000
31997
|
}
|
|
32001
31998
|
if (outcomeAdvances(command.outcome, input2.outcome)) {
|
|
32002
|
-
await
|
|
32003
|
-
|
|
32004
|
-
{ requestId },
|
|
31999
|
+
await tables.commands.update(
|
|
32000
|
+
{ requestId, outcome: command.outcome },
|
|
32005
32001
|
{
|
|
32006
32002
|
outcome: input2.outcome,
|
|
32007
32003
|
acceptedAt: input2.acceptedAt ?? command.acceptedAt,
|
|
@@ -32010,28 +32006,42 @@ var MatterStateService = class {
|
|
|
32010
32006
|
}
|
|
32011
32007
|
);
|
|
32012
32008
|
}
|
|
32013
|
-
|
|
32009
|
+
delta.applied += 1;
|
|
32014
32010
|
if (!command.stateKey) return;
|
|
32015
|
-
const
|
|
32016
|
-
|
|
32011
|
+
const row = await tables.endpointState.findOne({
|
|
32012
|
+
where: { endpointRef: command.endpointRef, stateKey: command.stateKey }
|
|
32013
|
+
});
|
|
32017
32014
|
if (!row) return;
|
|
32018
32015
|
const next = applyOutcome(row, requestId, input2, now);
|
|
32019
|
-
if (next !== row) await
|
|
32016
|
+
if (next !== row) await tables.endpointState.upsert(next, { conflictOn: ["id"] });
|
|
32020
32017
|
}
|
|
32021
32018
|
/**
|
|
32022
32019
|
* Events only reach live endpoints of a claimed, unclaimed or detached node of the active fabric (or of the fabric
|
|
32023
|
-
* the event names, which must be the active one).
|
|
32020
|
+
* the event names, which must be the active one). The active fabrics are looked up once per batch, and the node and
|
|
32021
|
+
* endpoint by one query each.
|
|
32024
32022
|
*/
|
|
32025
|
-
async resolve(
|
|
32026
|
-
const
|
|
32027
|
-
|
|
32028
|
-
|
|
32023
|
+
async resolve(tables, fabrics2, target) {
|
|
32024
|
+
const lookupKey = target.fabricId ?? "";
|
|
32025
|
+
let active = fabrics2.get(lookupKey);
|
|
32026
|
+
if (!active) {
|
|
32027
|
+
active = tables.fabrics.find({
|
|
32028
|
+
where: {
|
|
32029
|
+
status: "active",
|
|
32030
|
+
retiredAt: null,
|
|
32031
|
+
...target.fabricId === void 0 ? {} : { fabricId: target.fabricId }
|
|
32032
|
+
}
|
|
32033
|
+
}).then((rows) => rows.map((row) => row.id));
|
|
32034
|
+
fabrics2.set(lookupKey, active);
|
|
32035
|
+
}
|
|
32036
|
+
const fabricRefs = await active;
|
|
32037
|
+
const found = fabricRefs.length === 0 ? null : await tables.nodes.findOne({
|
|
32038
|
+
where: { nodeId: target.nodeId, fabricRef: { in: fabricRefs }, removedAt: null }
|
|
32039
|
+
});
|
|
32029
32040
|
if (!found) return { ignored: "unknownEndpoint" };
|
|
32030
32041
|
if (found.lifecycleState === "archived" || found.lifecycleState === "removed") return { ignored: "inactiveNode" };
|
|
32031
|
-
const endpoint = await
|
|
32032
|
-
|
|
32033
|
-
|
|
32034
|
-
}).getOne();
|
|
32042
|
+
const endpoint = await tables.endpoints.findOne({
|
|
32043
|
+
where: { nodeRef: found.id, endpointId: target.endpointId, removedAt: null }
|
|
32044
|
+
});
|
|
32035
32045
|
return endpoint ? { endpoint } : { ignored: "unknownEndpoint" };
|
|
32036
32046
|
}
|
|
32037
32047
|
};
|
|
@@ -32202,24 +32212,24 @@ var MatterDevicesController = class {
|
|
|
32202
32212
|
}
|
|
32203
32213
|
};
|
|
32204
32214
|
__decorateClass([
|
|
32205
|
-
(0,
|
|
32215
|
+
(0, import_plugins_backend_sdk7.Auth)(...MATTER_OPERATIONS.nodeList),
|
|
32206
32216
|
(0, import_common18.Get)("nodes"),
|
|
32207
32217
|
__decorateParam(0, (0, import_common18.Query)())
|
|
32208
32218
|
], MatterDevicesController.prototype, "listNodes", 1);
|
|
32209
32219
|
__decorateClass([
|
|
32210
|
-
(0,
|
|
32220
|
+
(0, import_plugins_backend_sdk7.Auth)(...MATTER_OPERATIONS.nodeGet),
|
|
32211
32221
|
(0, import_common18.Get)("nodes/:id"),
|
|
32212
32222
|
__decorateParam(0, (0, import_common18.Param)("id"))
|
|
32213
32223
|
], MatterDevicesController.prototype, "getNode", 1);
|
|
32214
32224
|
__decorateClass([
|
|
32215
|
-
(0,
|
|
32225
|
+
(0, import_plugins_backend_sdk7.Auth)(...MATTER_OPERATIONS.nodeUpdate),
|
|
32216
32226
|
(0, import_common18.Patch)("nodes/:id"),
|
|
32217
32227
|
__decorateParam(0, (0, import_common18.Param)("id")),
|
|
32218
32228
|
__decorateParam(1, (0, import_common18.Body)()),
|
|
32219
32229
|
__decorateParam(2, (0, import_common18.Req)())
|
|
32220
32230
|
], MatterDevicesController.prototype, "updateNode", 1);
|
|
32221
32231
|
__decorateClass([
|
|
32222
|
-
(0,
|
|
32232
|
+
(0, import_plugins_backend_sdk7.Auth)(...MATTER_OPERATIONS.nodeClaim),
|
|
32223
32233
|
(0, import_common18.Post)("nodes/:id/claim"),
|
|
32224
32234
|
(0, import_common18.HttpCode)(200),
|
|
32225
32235
|
__decorateParam(0, (0, import_common18.Param)("id")),
|
|
@@ -32227,7 +32237,7 @@ __decorateClass([
|
|
|
32227
32237
|
__decorateParam(2, (0, import_common18.Req)())
|
|
32228
32238
|
], MatterDevicesController.prototype, "claim", 1);
|
|
32229
32239
|
__decorateClass([
|
|
32230
|
-
(0,
|
|
32240
|
+
(0, import_plugins_backend_sdk7.Auth)(...MATTER_OPERATIONS.nodeRelink),
|
|
32231
32241
|
(0, import_common18.Post)("nodes/:id/relink"),
|
|
32232
32242
|
(0, import_common18.HttpCode)(200),
|
|
32233
32243
|
__decorateParam(0, (0, import_common18.Param)("id")),
|
|
@@ -32235,28 +32245,28 @@ __decorateClass([
|
|
|
32235
32245
|
__decorateParam(2, (0, import_common18.Req)())
|
|
32236
32246
|
], MatterDevicesController.prototype, "relink", 1);
|
|
32237
32247
|
__decorateClass([
|
|
32238
|
-
(0,
|
|
32248
|
+
(0, import_plugins_backend_sdk7.Auth)(...MATTER_OPERATIONS.nodeRepair),
|
|
32239
32249
|
(0, import_common18.Post)("nodes/:id/repair"),
|
|
32240
32250
|
(0, import_common18.HttpCode)(200),
|
|
32241
32251
|
__decorateParam(0, (0, import_common18.Param)("id")),
|
|
32242
32252
|
__decorateParam(1, (0, import_common18.Req)())
|
|
32243
32253
|
], MatterDevicesController.prototype, "repair", 1);
|
|
32244
32254
|
__decorateClass([
|
|
32245
|
-
(0,
|
|
32255
|
+
(0, import_plugins_backend_sdk7.Auth)(...MATTER_OPERATIONS.nodeArchive),
|
|
32246
32256
|
(0, import_common18.Post)("nodes/:id/archive"),
|
|
32247
32257
|
(0, import_common18.HttpCode)(200),
|
|
32248
32258
|
__decorateParam(0, (0, import_common18.Param)("id")),
|
|
32249
32259
|
__decorateParam(1, (0, import_common18.Req)())
|
|
32250
32260
|
], MatterDevicesController.prototype, "archive", 1);
|
|
32251
32261
|
__decorateClass([
|
|
32252
|
-
(0,
|
|
32262
|
+
(0, import_plugins_backend_sdk7.Auth)(...MATTER_OPERATIONS.nodeRestore),
|
|
32253
32263
|
(0, import_common18.Post)("nodes/:id/restore"),
|
|
32254
32264
|
(0, import_common18.HttpCode)(200),
|
|
32255
32265
|
__decorateParam(0, (0, import_common18.Param)("id")),
|
|
32256
32266
|
__decorateParam(1, (0, import_common18.Req)())
|
|
32257
32267
|
], MatterDevicesController.prototype, "restore", 1);
|
|
32258
32268
|
__decorateClass([
|
|
32259
|
-
(0,
|
|
32269
|
+
(0, import_plugins_backend_sdk7.Auth)(...MATTER_OPERATIONS.nodeForceRemove),
|
|
32260
32270
|
(0, import_common18.Post)("nodes/:id/force-remove"),
|
|
32261
32271
|
(0, import_common18.HttpCode)(200),
|
|
32262
32272
|
__decorateParam(0, (0, import_common18.Param)("id")),
|
|
@@ -32264,23 +32274,23 @@ __decorateClass([
|
|
|
32264
32274
|
__decorateParam(2, (0, import_common18.Req)())
|
|
32265
32275
|
], MatterDevicesController.prototype, "forceRemove", 1);
|
|
32266
32276
|
__decorateClass([
|
|
32267
|
-
(0,
|
|
32277
|
+
(0, import_plugins_backend_sdk7.Auth)(...MATTER_OPERATIONS.endpointUpdate),
|
|
32268
32278
|
(0, import_common18.Patch)("endpoints/:id"),
|
|
32269
32279
|
__decorateParam(0, (0, import_common18.Param)("id")),
|
|
32270
32280
|
__decorateParam(1, (0, import_common18.Body)()),
|
|
32271
32281
|
__decorateParam(2, (0, import_common18.Req)())
|
|
32272
32282
|
], MatterDevicesController.prototype, "updateEndpoint", 1);
|
|
32273
32283
|
__decorateClass([
|
|
32274
|
-
(0,
|
|
32284
|
+
(0, import_plugins_backend_sdk7.Auth)(...MATTER_OPERATIONS.endpointState),
|
|
32275
32285
|
(0, import_common18.Get)("endpoints/:id/state"),
|
|
32276
32286
|
__decorateParam(0, (0, import_common18.Param)("id"))
|
|
32277
32287
|
], MatterDevicesController.prototype, "endpointState", 1);
|
|
32278
32288
|
__decorateClass([
|
|
32279
|
-
(0,
|
|
32289
|
+
(0, import_plugins_backend_sdk7.Auth)(...MATTER_OPERATIONS.reconciliationStatus),
|
|
32280
32290
|
(0, import_common18.Get)("reconciliation")
|
|
32281
32291
|
], MatterDevicesController.prototype, "reconciliationStatus", 1);
|
|
32282
32292
|
__decorateClass([
|
|
32283
|
-
(0,
|
|
32293
|
+
(0, import_plugins_backend_sdk7.Auth)(...MATTER_OPERATIONS.reconciliationRun),
|
|
32284
32294
|
(0, import_common18.Post)("reconciliation"),
|
|
32285
32295
|
(0, import_common18.HttpCode)(200),
|
|
32286
32296
|
__decorateParam(0, (0, import_common18.Req)())
|
|
@@ -32308,15 +32318,15 @@ var MatterIngestionService = class {
|
|
|
32308
32318
|
this.warnedFull = false;
|
|
32309
32319
|
}
|
|
32310
32320
|
onModuleInit() {
|
|
32311
|
-
const
|
|
32321
|
+
const connection2 = this.connectionService.connection;
|
|
32312
32322
|
this.unsubscribe.push(
|
|
32313
|
-
|
|
32323
|
+
connection2.onStateChange((status) => {
|
|
32314
32324
|
if (status.state === "connected") this.reconcile();
|
|
32315
32325
|
}),
|
|
32316
|
-
|
|
32317
|
-
|
|
32326
|
+
connection2.onReconciliationRequired(() => this.reconcile()),
|
|
32327
|
+
connection2.onEvent((event) => this.enqueue(event))
|
|
32318
32328
|
);
|
|
32319
|
-
if (
|
|
32329
|
+
if (connection2.status().state === "connected") this.reconcile();
|
|
32320
32330
|
}
|
|
32321
32331
|
onModuleDestroy() {
|
|
32322
32332
|
for (const stop of this.unsubscribe.splice(0)) stop();
|
|
@@ -32385,337 +32395,26 @@ function parseStateEvent(type, payload) {
|
|
|
32385
32395
|
return null;
|
|
32386
32396
|
}
|
|
32387
32397
|
|
|
32388
|
-
// backend/migrations.ts
|
|
32389
|
-
var migrations_exports = {};
|
|
32390
|
-
__export(migrations_exports, {
|
|
32391
|
-
CreateMatterBackup1793900002000: () => CreateMatterBackup1793900002000,
|
|
32392
|
-
CreateMatterConnection1793900000000: () => CreateMatterConnection1793900000000,
|
|
32393
|
-
CreateMatterDeviceModel1793900001000: () => CreateMatterDeviceModel1793900001000
|
|
32394
|
-
});
|
|
32395
|
-
|
|
32396
|
-
// backend/migrations/1793900000000-create-matter-connection.ts
|
|
32397
|
-
var CreateMatterConnection1793900000000 = class {
|
|
32398
|
-
constructor() {
|
|
32399
|
-
this.name = "CreateMatterConnection1793900000000";
|
|
32400
|
-
}
|
|
32401
|
-
async up(queryRunner) {
|
|
32402
|
-
await queryRunner.query(
|
|
32403
|
-
`CREATE TABLE IF NOT EXISTS "plugin_matter_connection" (
|
|
32404
|
-
"id" integer PRIMARY KEY NOT NULL,
|
|
32405
|
-
"url" varchar NOT NULL,
|
|
32406
|
-
"encrypted_credential" text NOT NULL,
|
|
32407
|
-
"ca_certificate" text,
|
|
32408
|
-
"credential_updated_at" varchar NOT NULL,
|
|
32409
|
-
"updated_at" varchar NOT NULL,
|
|
32410
|
-
"updated_by" integer,
|
|
32411
|
-
CONSTRAINT "CHK_plugin_matter_connection_singleton" CHECK ("id" = 1)
|
|
32412
|
-
)`
|
|
32413
|
-
);
|
|
32414
|
-
}
|
|
32415
|
-
async down(queryRunner) {
|
|
32416
|
-
await queryRunner.query(`DROP TABLE "plugin_matter_connection"`);
|
|
32417
|
-
}
|
|
32418
|
-
};
|
|
32419
|
-
|
|
32420
|
-
// backend/migrations/1793900001000-create-matter-device-model.ts
|
|
32421
|
-
var CreateMatterDeviceModel1793900001000 = class {
|
|
32422
|
-
constructor() {
|
|
32423
|
-
this.name = "CreateMatterDeviceModel1793900001000";
|
|
32424
|
-
}
|
|
32425
|
-
async up(queryRunner) {
|
|
32426
|
-
await queryRunner.query(
|
|
32427
|
-
`CREATE TABLE "plugin_matter_fabrics" (
|
|
32428
|
-
"id" varchar PRIMARY KEY NOT NULL,
|
|
32429
|
-
"fabric_id" varchar NOT NULL,
|
|
32430
|
-
"label" varchar,
|
|
32431
|
-
"first_seen_at" varchar NOT NULL,
|
|
32432
|
-
"last_seen_at" varchar NOT NULL,
|
|
32433
|
-
"status" varchar NOT NULL,
|
|
32434
|
-
"retired_at" varchar,
|
|
32435
|
-
CONSTRAINT "CHK_plugin_matter_fabrics_status" CHECK ("status" IN ('active', 'absent'))
|
|
32436
|
-
)`
|
|
32437
|
-
);
|
|
32438
|
-
await queryRunner.query(
|
|
32439
|
-
`CREATE UNIQUE INDEX "UQ_plugin_matter_fabrics_live" ON "plugin_matter_fabrics" ("fabric_id") WHERE "retired_at" IS NULL`
|
|
32440
|
-
);
|
|
32441
|
-
await queryRunner.query(
|
|
32442
|
-
`CREATE TABLE "plugin_matter_nodes" (
|
|
32443
|
-
"id" varchar PRIMARY KEY NOT NULL,
|
|
32444
|
-
"fabric_ref" varchar NOT NULL,
|
|
32445
|
-
"node_id" varchar NOT NULL,
|
|
32446
|
-
"vendor_id" integer,
|
|
32447
|
-
"product_id" integer,
|
|
32448
|
-
"vendor_name" varchar,
|
|
32449
|
-
"product_name" varchar,
|
|
32450
|
-
"serial_number" varchar,
|
|
32451
|
-
"unique_id" varchar,
|
|
32452
|
-
"hardware_version" integer,
|
|
32453
|
-
"software_version" integer,
|
|
32454
|
-
"software_version_string" varchar,
|
|
32455
|
-
"attestation_status" varchar,
|
|
32456
|
-
"attestation_checked_at" varchar,
|
|
32457
|
-
"display_name" varchar(100),
|
|
32458
|
-
"description" varchar(500),
|
|
32459
|
-
"location" varchar(100),
|
|
32460
|
-
"lifecycle_state" varchar NOT NULL,
|
|
32461
|
-
"detached_reason" varchar,
|
|
32462
|
-
"reachable" boolean,
|
|
32463
|
-
"first_seen_at" varchar NOT NULL,
|
|
32464
|
-
"last_seen_at" varchar NOT NULL,
|
|
32465
|
-
"claimed_at" varchar,
|
|
32466
|
-
"claimed_by" integer,
|
|
32467
|
-
"detached_at" varchar,
|
|
32468
|
-
"archived_at" varchar,
|
|
32469
|
-
"archived_by" integer,
|
|
32470
|
-
"removed_at" varchar,
|
|
32471
|
-
"removed_by" integer,
|
|
32472
|
-
"removal_reason" varchar,
|
|
32473
|
-
"merged_into" varchar,
|
|
32474
|
-
"created_at" varchar NOT NULL,
|
|
32475
|
-
"updated_at" varchar NOT NULL,
|
|
32476
|
-
CONSTRAINT "CHK_plugin_matter_nodes_lifecycle" CHECK ("lifecycle_state" IN ('unclaimed', 'claimed', 'detached', 'archived', 'removed')),
|
|
32477
|
-
CONSTRAINT "CHK_plugin_matter_nodes_detached_reason" CHECK ("detached_reason" IS NULL OR "detached_reason" IN ('absent_from_sidecar', 'fabric_mismatch', 'fabric_absent')),
|
|
32478
|
-
CONSTRAINT "CHK_plugin_matter_nodes_removal_reason" CHECK ("removal_reason" IS NULL OR "removal_reason" IN ('force_removed', 'merged', 'replaced')),
|
|
32479
|
-
CONSTRAINT "CHK_plugin_matter_nodes_attestation" CHECK ("attestation_status" IS NULL OR "attestation_status" IN ('verified', 'unverified', 'failed', 'unknown'))
|
|
32480
|
-
)`
|
|
32481
|
-
);
|
|
32482
|
-
await queryRunner.query(
|
|
32483
|
-
`CREATE UNIQUE INDEX "UQ_plugin_matter_nodes_live_identity" ON "plugin_matter_nodes" ("fabric_ref", "node_id") WHERE "removed_at" IS NULL`
|
|
32484
|
-
);
|
|
32485
|
-
await queryRunner.query(
|
|
32486
|
-
`CREATE INDEX "IDX_plugin_matter_nodes_lifecycle" ON "plugin_matter_nodes" ("lifecycle_state")`
|
|
32487
|
-
);
|
|
32488
|
-
await queryRunner.query(
|
|
32489
|
-
`CREATE TABLE "plugin_matter_endpoints" (
|
|
32490
|
-
"id" varchar PRIMARY KEY NOT NULL,
|
|
32491
|
-
"node_ref" varchar NOT NULL,
|
|
32492
|
-
"endpoint_id" integer NOT NULL,
|
|
32493
|
-
"parent_endpoint_id" integer,
|
|
32494
|
-
"device_types" text NOT NULL,
|
|
32495
|
-
"profile" varchar NOT NULL,
|
|
32496
|
-
"display_name" varchar(100),
|
|
32497
|
-
"description" varchar(500),
|
|
32498
|
-
"location" varchar(100),
|
|
32499
|
-
"bridged" boolean,
|
|
32500
|
-
"bridged_unique_id" varchar,
|
|
32501
|
-
"bridged_node_label" varchar,
|
|
32502
|
-
"bridged_vendor_name" varchar,
|
|
32503
|
-
"bridged_product_name" varchar,
|
|
32504
|
-
"bridged_serial_number" varchar,
|
|
32505
|
-
"bridged_reachable" boolean,
|
|
32506
|
-
"first_seen_at" varchar NOT NULL,
|
|
32507
|
-
"last_seen_at" varchar NOT NULL,
|
|
32508
|
-
"removed_at" varchar,
|
|
32509
|
-
"removal_reason" varchar,
|
|
32510
|
-
CONSTRAINT "CHK_plugin_matter_endpoints_range" CHECK ("endpoint_id" BETWEEN 0 AND 65534),
|
|
32511
|
-
CONSTRAINT "CHK_plugin_matter_endpoints_removal_reason" CHECK ("removal_reason" IS NULL OR "removal_reason" IN ('absent_from_sidecar', 'replaced', 'force_removed', 'merged'))
|
|
32512
|
-
)`
|
|
32513
|
-
);
|
|
32514
|
-
await queryRunner.query(
|
|
32515
|
-
`CREATE UNIQUE INDEX "UQ_plugin_matter_endpoints_live" ON "plugin_matter_endpoints" ("node_ref", "endpoint_id") WHERE "removed_at" IS NULL`
|
|
32516
|
-
);
|
|
32517
|
-
await queryRunner.query(
|
|
32518
|
-
`CREATE TABLE "plugin_matter_endpoint_clusters" (
|
|
32519
|
-
"id" varchar PRIMARY KEY NOT NULL,
|
|
32520
|
-
"endpoint_ref" varchar NOT NULL,
|
|
32521
|
-
"cluster_id" integer NOT NULL,
|
|
32522
|
-
"role" varchar NOT NULL,
|
|
32523
|
-
"revision" integer,
|
|
32524
|
-
"feature_map" integer,
|
|
32525
|
-
"attribute_ids" text NOT NULL,
|
|
32526
|
-
"accepted_command_ids" text NOT NULL,
|
|
32527
|
-
"removed_at" varchar,
|
|
32528
|
-
CONSTRAINT "CHK_plugin_matter_endpoint_clusters_role" CHECK ("role" IN ('server', 'client'))
|
|
32529
|
-
)`
|
|
32530
|
-
);
|
|
32531
|
-
await queryRunner.query(
|
|
32532
|
-
`CREATE UNIQUE INDEX "UQ_plugin_matter_endpoint_clusters_live" ON "plugin_matter_endpoint_clusters" ("endpoint_ref", "cluster_id", "role") WHERE "removed_at" IS NULL`
|
|
32533
|
-
);
|
|
32534
|
-
await queryRunner.query(
|
|
32535
|
-
`CREATE TABLE "plugin_matter_endpoint_capabilities" (
|
|
32536
|
-
"id" varchar PRIMARY KEY NOT NULL,
|
|
32537
|
-
"endpoint_ref" varchar NOT NULL,
|
|
32538
|
-
"capability" varchar NOT NULL,
|
|
32539
|
-
"source_cluster_id" integer NOT NULL,
|
|
32540
|
-
"details" text NOT NULL
|
|
32541
|
-
)`
|
|
32542
|
-
);
|
|
32543
|
-
await queryRunner.query(
|
|
32544
|
-
`CREATE UNIQUE INDEX "UQ_plugin_matter_endpoint_capabilities" ON "plugin_matter_endpoint_capabilities" ("endpoint_ref", "capability")`
|
|
32545
|
-
);
|
|
32546
|
-
await queryRunner.query(
|
|
32547
|
-
`CREATE TABLE "plugin_matter_endpoint_state" (
|
|
32548
|
-
"id" varchar PRIMARY KEY NOT NULL,
|
|
32549
|
-
"endpoint_ref" varchar NOT NULL,
|
|
32550
|
-
"state_key" varchar NOT NULL,
|
|
32551
|
-
"reported_value" text,
|
|
32552
|
-
"reported_at" varchar,
|
|
32553
|
-
"received_at" varchar,
|
|
32554
|
-
"source" varchar,
|
|
32555
|
-
"quality" varchar,
|
|
32556
|
-
"stale_after_ms" integer NOT NULL DEFAULT 600000,
|
|
32557
|
-
"requested_value" text,
|
|
32558
|
-
"requested_at" varchar,
|
|
32559
|
-
"requested_by" integer,
|
|
32560
|
-
"request_id" varchar,
|
|
32561
|
-
"correlation_id" varchar,
|
|
32562
|
-
"command_state" varchar NOT NULL DEFAULT 'none',
|
|
32563
|
-
"accepted_at" varchar,
|
|
32564
|
-
"command_reported_at" varchar,
|
|
32565
|
-
"external_change_at" varchar,
|
|
32566
|
-
"external_change_value" text,
|
|
32567
|
-
"fault_code" varchar,
|
|
32568
|
-
"fault_message" varchar,
|
|
32569
|
-
"fault_at" varchar,
|
|
32570
|
-
"updated_at" varchar NOT NULL,
|
|
32571
|
-
CONSTRAINT "CHK_plugin_matter_endpoint_state_command" CHECK ("command_state" IN ('none', 'requested', 'accepted', 'reported', 'uncertain', 'failed')),
|
|
32572
|
-
CONSTRAINT "CHK_plugin_matter_endpoint_state_quality" CHECK ("quality" IS NULL OR "quality" IN ('good', 'uncertain', 'fault', 'unavailable')),
|
|
32573
|
-
CONSTRAINT "CHK_plugin_matter_endpoint_state_source" CHECK ("source" IS NULL OR "source" IN ('subscription_report', 'read', 'command_response'))
|
|
32574
|
-
)`
|
|
32575
|
-
);
|
|
32576
|
-
await queryRunner.query(
|
|
32577
|
-
`CREATE UNIQUE INDEX "UQ_plugin_matter_endpoint_state_key" ON "plugin_matter_endpoint_state" ("endpoint_ref", "state_key")`
|
|
32578
|
-
);
|
|
32579
|
-
await queryRunner.query(
|
|
32580
|
-
`CREATE TABLE "plugin_matter_commands" (
|
|
32581
|
-
"request_id" varchar PRIMARY KEY NOT NULL,
|
|
32582
|
-
"endpoint_ref" varchar NOT NULL,
|
|
32583
|
-
"cluster_id" integer NOT NULL,
|
|
32584
|
-
"command_id" integer NOT NULL,
|
|
32585
|
-
"state_key" varchar,
|
|
32586
|
-
"requested_at" varchar NOT NULL,
|
|
32587
|
-
"requested_by" integer,
|
|
32588
|
-
"correlation_id" varchar,
|
|
32589
|
-
"outcome" varchar NOT NULL,
|
|
32590
|
-
"accepted_at" varchar,
|
|
32591
|
-
"reported_at" varchar,
|
|
32592
|
-
"failure_code" varchar,
|
|
32593
|
-
CONSTRAINT "CHK_plugin_matter_commands_outcome" CHECK ("outcome" IN ('requested', 'accepted', 'reported', 'uncertain', 'failed'))
|
|
32594
|
-
)`
|
|
32595
|
-
);
|
|
32596
|
-
await queryRunner.query(
|
|
32597
|
-
`CREATE INDEX "IDX_plugin_matter_commands_requested_at" ON "plugin_matter_commands" ("requested_at", "request_id")`
|
|
32598
|
-
);
|
|
32599
|
-
await queryRunner.query(
|
|
32600
|
-
`CREATE TABLE "plugin_matter_reconciliation_status" (
|
|
32601
|
-
"id" integer PRIMARY KEY NOT NULL,
|
|
32602
|
-
"last_started_at" varchar,
|
|
32603
|
-
"last_finished_at" varchar,
|
|
32604
|
-
"last_result" varchar,
|
|
32605
|
-
"last_summary" text,
|
|
32606
|
-
"sidecar_fabric_id" varchar,
|
|
32607
|
-
CONSTRAINT "CHK_plugin_matter_reconciliation_status_singleton" CHECK ("id" = 1),
|
|
32608
|
-
CONSTRAINT "CHK_plugin_matter_reconciliation_status_result" CHECK ("last_result" IS NULL OR "last_result" IN ('applied', 'skipped_unavailable', 'skipped_non_authoritative', 'failed'))
|
|
32609
|
-
)`
|
|
32610
|
-
);
|
|
32611
|
-
}
|
|
32612
|
-
async down(queryRunner) {
|
|
32613
|
-
await queryRunner.query(`DROP TABLE "plugin_matter_reconciliation_status"`);
|
|
32614
|
-
await queryRunner.query(`DROP TABLE "plugin_matter_commands"`);
|
|
32615
|
-
await queryRunner.query(`DROP TABLE "plugin_matter_endpoint_state"`);
|
|
32616
|
-
await queryRunner.query(`DROP TABLE "plugin_matter_endpoint_capabilities"`);
|
|
32617
|
-
await queryRunner.query(`DROP TABLE "plugin_matter_endpoint_clusters"`);
|
|
32618
|
-
await queryRunner.query(`DROP TABLE "plugin_matter_endpoints"`);
|
|
32619
|
-
await queryRunner.query(`DROP TABLE "plugin_matter_nodes"`);
|
|
32620
|
-
await queryRunner.query(`DROP TABLE "plugin_matter_fabrics"`);
|
|
32621
|
-
}
|
|
32622
|
-
};
|
|
32623
|
-
|
|
32624
|
-
// backend/migrations/1793900002000-create-matter-backup.ts
|
|
32625
|
-
var CreateMatterBackup1793900002000 = class {
|
|
32626
|
-
constructor() {
|
|
32627
|
-
this.name = "CreateMatterBackup1793900002000";
|
|
32628
|
-
}
|
|
32629
|
-
async up(queryRunner) {
|
|
32630
|
-
await queryRunner.query(`ALTER TABLE "plugin_matter_fabrics" ADD COLUMN "fabric_generation" integer`);
|
|
32631
|
-
await queryRunner.query(`ALTER TABLE "plugin_matter_fabrics" ADD COLUMN "storage_instance_id" varchar`);
|
|
32632
|
-
await queryRunner.query(`ALTER TABLE "plugin_matter_fabrics" ADD COLUMN "root_cert_fingerprint" varchar`);
|
|
32633
|
-
await queryRunner.query(`ALTER TABLE "plugin_matter_fabrics" ADD COLUMN "recorded_at" varchar`);
|
|
32634
|
-
await queryRunner.query(
|
|
32635
|
-
`CREATE TABLE "plugin_matter_recovery_keys" (
|
|
32636
|
-
"id" varchar PRIMARY KEY NOT NULL,
|
|
32637
|
-
"key_id" varchar NOT NULL,
|
|
32638
|
-
"encrypted_key" text NOT NULL,
|
|
32639
|
-
"created_at" varchar NOT NULL,
|
|
32640
|
-
"acknowledged_at" varchar,
|
|
32641
|
-
"retired_at" varchar
|
|
32642
|
-
)`
|
|
32643
|
-
);
|
|
32644
|
-
await queryRunner.query(
|
|
32645
|
-
`CREATE UNIQUE INDEX "UQ_plugin_matter_recovery_keys_current" ON "plugin_matter_recovery_keys" ((1)) WHERE "retired_at" IS NULL`
|
|
32646
|
-
);
|
|
32647
|
-
await queryRunner.query(
|
|
32648
|
-
`CREATE UNIQUE INDEX "UQ_plugin_matter_recovery_keys_key_id" ON "plugin_matter_recovery_keys" ("key_id")`
|
|
32649
|
-
);
|
|
32650
|
-
await queryRunner.query(
|
|
32651
|
-
`CREATE TABLE "plugin_matter_backups" (
|
|
32652
|
-
"id" varchar PRIMARY KEY NOT NULL,
|
|
32653
|
-
"created_at" varchar NOT NULL,
|
|
32654
|
-
"trigger" varchar NOT NULL,
|
|
32655
|
-
"actor" integer,
|
|
32656
|
-
"outcome" varchar NOT NULL,
|
|
32657
|
-
"reason" varchar,
|
|
32658
|
-
"size_bytes" integer,
|
|
32659
|
-
"sha256" varchar,
|
|
32660
|
-
"format_version" integer,
|
|
32661
|
-
"plugin_version" varchar,
|
|
32662
|
-
"sidecar_version" varchar,
|
|
32663
|
-
"matter_js_version" varchar,
|
|
32664
|
-
"storage_schema_version" integer,
|
|
32665
|
-
"plugin_migration" varchar,
|
|
32666
|
-
"fabric_id" varchar,
|
|
32667
|
-
"root_cert_fingerprint" varchar,
|
|
32668
|
-
"fabric_generation" integer,
|
|
32669
|
-
"storage_instance_id" varchar,
|
|
32670
|
-
"recovery_key_id" varchar,
|
|
32671
|
-
"consistent" boolean,
|
|
32672
|
-
"blob" blob,
|
|
32673
|
-
CONSTRAINT "CHK_plugin_matter_backups_outcome" CHECK ("outcome" IN ('succeeded', 'failed')),
|
|
32674
|
-
CONSTRAINT "CHK_plugin_matter_backups_trigger" CHECK ("trigger" IN ('manual', 'fabric_created', 'restore', 'daily', 'fabric_changed', 'pre_restore'))
|
|
32675
|
-
)`
|
|
32676
|
-
);
|
|
32677
|
-
await queryRunner.query(
|
|
32678
|
-
`CREATE INDEX "IDX_plugin_matter_backups_created_at" ON "plugin_matter_backups" ("created_at")`
|
|
32679
|
-
);
|
|
32680
|
-
}
|
|
32681
|
-
async down(queryRunner) {
|
|
32682
|
-
await queryRunner.query(`DROP TABLE "plugin_matter_backups"`);
|
|
32683
|
-
await queryRunner.query(`DROP TABLE "plugin_matter_recovery_keys"`);
|
|
32684
|
-
await queryRunner.query(`ALTER TABLE "plugin_matter_fabrics" DROP COLUMN "recorded_at"`);
|
|
32685
|
-
await queryRunner.query(`ALTER TABLE "plugin_matter_fabrics" DROP COLUMN "root_cert_fingerprint"`);
|
|
32686
|
-
await queryRunner.query(`ALTER TABLE "plugin_matter_fabrics" DROP COLUMN "storage_instance_id"`);
|
|
32687
|
-
await queryRunner.query(`ALTER TABLE "plugin_matter_fabrics" DROP COLUMN "fabric_generation"`);
|
|
32688
|
-
}
|
|
32689
|
-
};
|
|
32690
|
-
|
|
32691
32398
|
// backend/fabric/migration-reader.ts
|
|
32692
|
-
|
|
32693
|
-
|
|
32694
|
-
|
|
32695
|
-
|
|
32696
|
-
const rows = await context.getRepository(MatterFabric).query(`SELECT "name" FROM "${table}" ORDER BY "timestamp" DESC, "id" DESC LIMIT 1`);
|
|
32697
|
-
return rows[0]?.name ?? await sharedTableMigration(context);
|
|
32698
|
-
} catch {
|
|
32699
|
-
return sharedTableMigration(context);
|
|
32700
|
-
}
|
|
32701
|
-
};
|
|
32399
|
+
var isPlainIndexAdd = (step2) => step2.op === "addIndex" && step2.index.unique !== true;
|
|
32400
|
+
var changesRows = (migration) => migration.data !== void 0 || (migration.steps ?? []).some((entry) => !isPlainIndexAdd(entry));
|
|
32401
|
+
function storageSchemaName() {
|
|
32402
|
+
return schemaNameOf(MATTER_STORAGE);
|
|
32702
32403
|
}
|
|
32703
|
-
|
|
32704
|
-
const
|
|
32705
|
-
|
|
32706
|
-
|
|
32707
|
-
|
|
32708
|
-
|
|
32709
|
-
return null;
|
|
32710
|
-
}
|
|
32404
|
+
function schemaNameOf(definition) {
|
|
32405
|
+
const last = definition.migrations.filter(changesRows).at(-1) ?? definition.migrations[0];
|
|
32406
|
+
return last.version === 1 ? definition.adoption?.legacyMigrations.at(-1) : `v${last.version}:${last.name}`;
|
|
32407
|
+
}
|
|
32408
|
+
function storageSchemaReader() {
|
|
32409
|
+
return async () => storageSchemaName();
|
|
32711
32410
|
}
|
|
32712
32411
|
|
|
32713
32412
|
// backend/plugin.ts
|
|
32714
32413
|
var MatterPluginModule = class {
|
|
32715
32414
|
};
|
|
32716
32415
|
var plugin = {
|
|
32717
|
-
//
|
|
32718
|
-
|
|
32416
|
+
// The plugin's own tables: declared in ./plugin-storage/tables, created, adopted and migrated by the host.
|
|
32417
|
+
storage: MATTER_STORAGE,
|
|
32719
32418
|
auditDomains: [MATTER_AUDIT_DOMAIN],
|
|
32720
32419
|
// ATT-1003: least-privilege Matter and Thread keys; every route requires one (see ./permissions).
|
|
32721
32420
|
permissions: MATTER_PERMISSIONS,
|
|
@@ -32738,7 +32437,7 @@ var plugin = {
|
|
|
32738
32437
|
MatterLifecycleService,
|
|
32739
32438
|
MatterIngestionService,
|
|
32740
32439
|
// ATT-998: fabric persistence, encrypted backups and restore.
|
|
32741
|
-
{ provide: PLUGIN_MIGRATION_READER, useValue:
|
|
32440
|
+
{ provide: PLUGIN_MIGRATION_READER, useValue: storageSchemaReader() },
|
|
32742
32441
|
MatterFabricGuard,
|
|
32743
32442
|
RecoveryKeyService,
|
|
32744
32443
|
MatterBackupService,
|