@camstack/server 1.2.892 → 1.2.893
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/CHANGELOG.md +6 -0
- package/dist/api/trpc/generated-cap-routers.js +10 -0
- package/package.json +11 -28
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/alerts/alerts.addon.js +1 -1
- package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/index.js +1 -1
- package/system/dist/builtins/camera-grid/index.mjs +1 -1
- package/system/dist/builtins/composer/composer.addon.js +4 -4
- package/system/dist/builtins/composer/composer.addon.mjs +4 -4
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +3 -3
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +3 -3
- package/system/dist/builtins/device-history/device-history.addon.js +2 -2
- package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
- package/system/dist/builtins/device-manager/device-identity-index.d.ts +73 -0
- package/system/dist/builtins/device-manager/device-manager.addon.js +231 -11
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +231 -11
- package/system/dist/builtins/device-manager/device-row-store.d.ts +4 -1
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +4 -4
- package/system/dist/builtins/keychain/index.mjs +4 -4
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
- package/system/dist/builtins/local-network/local-network.addon.js +3 -3
- package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
- package/system/dist/builtins/loki-logging/index.js +1 -1
- package/system/dist/builtins/loki-logging/index.mjs +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +1 -1
- package/system/dist/builtins/record-entries/index.js +1 -1
- package/system/dist/builtins/record-entries/index.mjs +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +1 -1
- package/system/dist/builtins/snapshot/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +3 -3
- package/system/dist/builtins/system-config/system-config.addon.mjs +284 -284
- package/system/dist/builtins/winston-logging/index.js +1 -1
- package/system/dist/builtins/winston-logging/index.mjs +1 -1
- package/system/dist/{capture-engine-sl6e9f9S.mjs → capture-engine-CIVKm_jN.mjs} +1 -1
- package/system/dist/{capture-engine-DHmlkW_d.js → capture-engine-mZ2J-GD6.js} +1 -1
- package/system/dist/{composition-sources-PqcZfe3j.js → composition-sources-CGP5ZUYo.js} +1 -1
- package/system/dist/{composition-sources-CznD85Ri.mjs → composition-sources-bJP8_Z2o.mjs} +1 -1
- package/system/dist/{constants-_2SOk0By.js → constants-BD8oSQro.js} +1 -1
- package/system/dist/{constants-CHwj_mIM.mjs → constants-w-6vvTPp.mjs} +1 -1
- package/system/dist/{device-ca-WIEO5ZcE.js → device-ca-CXxnQaff.js} +1 -1
- package/system/dist/{device-ca-D2H1EMUY.mjs → device-ca-DE_oetBE.mjs} +1 -1
- package/system/dist/{dist-yx2KHo3b.js → dist-B2-Uflhy.js} +106 -0
- package/system/dist/{dist-DbAhCrHy.mjs → dist-Be8yFd71.mjs} +95 -1
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-identity-Buegac-w.js → hub-identity-BjYvJU_v.js} +1 -1
- package/system/dist/{hub-identity-BcvZqT0L.mjs → hub-identity-C3g7b58L.mjs} +1 -1
- package/system/dist/{hub-mdns-ciao-DcNPj7WJ.js → hub-mdns-ciao-BRfv9GfW.js} +2 -2
- package/system/dist/{hub-mdns-ciao-B6K_dO2s.mjs → hub-mdns-ciao-v6X_SbWl.mjs} +2 -2
- package/system/dist/index.js +8 -8
- package/system/dist/index.mjs +8 -8
- package/system/dist/{legacy-integration-rows-door-BsZyVNiR.js → legacy-integration-rows-door-B0q34gh3.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-DHOJeDPG.mjs → legacy-integration-rows-door-DG35DG06.mjs} +1 -1
- package/system/dist/{rename-composition-block-BXMor7MR.js → rename-composition-block-DNte3Cs9.js} +1 -1
- package/system/dist/{rename-composition-block-DcVS1LuC.mjs → rename-composition-block-LEbZ4oZE.mjs} +1 -1
- package/system/dist/{restore-archive-BG8VJ8Ar.mjs → restore-archive--4ENkU5f.mjs} +82 -82
- package/system/dist/{restore-archive-BURufVQd.js → restore-archive-DpFPheMK.js} +1 -1
- package/system/dist/{wal-maintenance-CeaJyKNT.js → wal-maintenance-BWUJktqT.js} +0 -0
- package/system/dist/{wal-maintenance-B4wGD6QR.mjs → wal-maintenance-DQVDhuVJ.mjs} +0 -0
- package/system/package.json +1 -1
|
@@ -3,10 +3,10 @@ Object.defineProperties(exports, {
|
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
5
|
const require_chunk = require("../../chunk-Cek0wNdY.js");
|
|
6
|
-
const require_dist = require("../../dist-
|
|
6
|
+
const require_dist = require("../../dist-B2-Uflhy.js");
|
|
7
7
|
const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
|
|
8
8
|
const require_log_redactor = require("../../log-redactor-BhIEMaG9.js");
|
|
9
|
-
const require_rename_composition_block = require("../../rename-composition-block-
|
|
9
|
+
const require_rename_composition_block = require("../../rename-composition-block-DNte3Cs9.js");
|
|
10
10
|
const require_prefix_range = require("../../prefix-range-D_KueXbQ.js");
|
|
11
11
|
const require_prefix_walk = require("../../prefix-walk-Dv6MLZlM.js");
|
|
12
12
|
const require_retired_settings_keys = require("../../retired-settings-keys-C8nOOr5H.js");
|
|
@@ -4744,7 +4744,7 @@ function compareUnranked(a, b) {
|
|
|
4744
4744
|
if (a[2] !== b[2]) return a[2] < b[2] ? -1 : 1;
|
|
4745
4745
|
return a[3] - b[3];
|
|
4746
4746
|
}
|
|
4747
|
-
function compareKeys(a, b) {
|
|
4747
|
+
function compareKeys$1(a, b) {
|
|
4748
4748
|
if (a.length === 5 && b.length === 5) {
|
|
4749
4749
|
if (a[0] !== b[0]) return a[0] - b[0];
|
|
4750
4750
|
return compareUnranked([
|
|
@@ -4919,14 +4919,14 @@ async function searchDevices(deps, input) {
|
|
|
4919
4919
|
const keyed = listed.map((c) => ({
|
|
4920
4920
|
c,
|
|
4921
4921
|
key: sortKeyOf(c)
|
|
4922
|
-
})).sort((a, b) => compareKeys(a.key, b.key));
|
|
4922
|
+
})).sort((a, b) => compareKeys$1(a.key, b.key));
|
|
4923
4923
|
const limit = Math.min(input.limit ?? 50, 200);
|
|
4924
4924
|
let start = 0;
|
|
4925
4925
|
if (input.cursor !== void 0 && input.cursor !== null) {
|
|
4926
4926
|
const after = decodeCursor(input.cursor);
|
|
4927
4927
|
if (after === null) deps.logger.warn("deviceManager.search: undecodable cursor — restarting from the first page");
|
|
4928
4928
|
else {
|
|
4929
|
-
const next = keyed.findIndex((k) => compareKeys(k.key, after) > 0);
|
|
4929
|
+
const next = keyed.findIndex((k) => compareKeys$1(k.key, after) > 0);
|
|
4930
4930
|
start = next === -1 ? keyed.length : next;
|
|
4931
4931
|
}
|
|
4932
4932
|
}
|
|
@@ -8898,6 +8898,214 @@ async function setIdentifiers(pctx, input) {
|
|
|
8898
8898
|
});
|
|
8899
8899
|
}
|
|
8900
8900
|
//#endregion
|
|
8901
|
+
//#region src/builtins/device-manager/device-identity-index.ts
|
|
8902
|
+
/**
|
|
8903
|
+
* The identifier INDEX (planning#593): identifier key → devices, so the
|
|
8904
|
+
* device-manager can say which devices of DIFFERENT integrations share
|
|
8905
|
+
* provider-declared identifiers (D1059) without reading the fleet per question.
|
|
8906
|
+
*
|
|
8907
|
+
* It is a PROJECTION of the device rows, never an authority: it holds, per
|
|
8908
|
+
* device, only what the pair rule needs — owning addon, integration instance and
|
|
8909
|
+
* the declared identifiers — and it moves with the rows, as the
|
|
8910
|
+
* {@link DeviceRowObserver} of the one `DeviceRowStore`. Every write of a row
|
|
8911
|
+
* passes through that store (`upsert`, `upsertRegistration`, `patch`, `remove`;
|
|
8912
|
+
* `swapIds` is built of them), so a row that changes reaches the index on the
|
|
8913
|
+
* same statement. A deleted device leaves the index on its row's DELETE — the
|
|
8914
|
+
* statement `removeDevice` runs right before it records the tombstone (D865) —
|
|
8915
|
+
* not on an event or on absence from a listing.
|
|
8916
|
+
*
|
|
8917
|
+
* It loads once, from the fleet listing the device-manager already reads at
|
|
8918
|
+
* boot ({@link seed}). Until then it answers `unknown` (D315), never `[]`; a row
|
|
8919
|
+
* write that lands while the snapshot is in flight is buffered and replayed over
|
|
8920
|
+
* it, so the seed can never roll a newer write back.
|
|
8921
|
+
*
|
|
8922
|
+
* Read-only: it finds candidates, it links nothing (that is step 3).
|
|
8923
|
+
*/
|
|
8924
|
+
/** The `kind=value` keys of one declaration. */
|
|
8925
|
+
function keysOf(identifiers) {
|
|
8926
|
+
if (identifiers === null) return [];
|
|
8927
|
+
const out = [];
|
|
8928
|
+
for (const kind of require_dist.DEVICE_IDENTIFIER_KEYS) {
|
|
8929
|
+
const entry = identifiers[kind];
|
|
8930
|
+
if (entry === void 0) continue;
|
|
8931
|
+
for (const e of [entry].flat()) out.push(`${kind}=${e.value}`);
|
|
8932
|
+
}
|
|
8933
|
+
return out;
|
|
8934
|
+
}
|
|
8935
|
+
function isIdentifierKind(value) {
|
|
8936
|
+
return require_dist.DEVICE_IDENTIFIER_KEYS.some((k) => k === value);
|
|
8937
|
+
}
|
|
8938
|
+
function parseKey(key) {
|
|
8939
|
+
const at = key.indexOf("=");
|
|
8940
|
+
const kind = key.slice(0, at);
|
|
8941
|
+
return isIdentifierKind(kind) ? {
|
|
8942
|
+
key: kind,
|
|
8943
|
+
value: key.slice(at + 1)
|
|
8944
|
+
} : null;
|
|
8945
|
+
}
|
|
8946
|
+
/**
|
|
8947
|
+
* Same integration? The same instance when both carry one; otherwise — one side
|
|
8948
|
+
* was never stamped — the same addon. In doubt, the same: no candidate.
|
|
8949
|
+
*/
|
|
8950
|
+
function sameIntegration(a, b) {
|
|
8951
|
+
if (a.integrationId !== null && b.integrationId !== null) return a.integrationId === b.integrationId;
|
|
8952
|
+
return a.addonId === b.addonId;
|
|
8953
|
+
}
|
|
8954
|
+
function sideOf(d) {
|
|
8955
|
+
return {
|
|
8956
|
+
deviceId: d.deviceId,
|
|
8957
|
+
addonId: d.addonId,
|
|
8958
|
+
integrationId: d.integrationId
|
|
8959
|
+
};
|
|
8960
|
+
}
|
|
8961
|
+
function compareKeys(x, y) {
|
|
8962
|
+
if (x.key !== y.key) return x.key < y.key ? -1 : 1;
|
|
8963
|
+
return x.value < y.value ? -1 : x.value > y.value ? 1 : 0;
|
|
8964
|
+
}
|
|
8965
|
+
/**
|
|
8966
|
+
* Grade the keys two devices share. `null` when they are no candidate at all
|
|
8967
|
+
* (no strong key matched).
|
|
8968
|
+
*
|
|
8969
|
+
* | Matched keys | Confidence |
|
|
8970
|
+
* | ----------------------------------------- | ------------ |
|
|
8971
|
+
* | two strong KINDS (e.g. `mac` + `serial`) | `auto` |
|
|
8972
|
+
* | `mac` + `ip` | `auto` |
|
|
8973
|
+
* | exactly one strong kind | `proposal` |
|
|
8974
|
+
* | weak keys only (`hostname`, `ip`) | no candidate |
|
|
8975
|
+
*
|
|
8976
|
+
* Strength counts distinct KINDS, not values: two MACs of one device matching
|
|
8977
|
+
* the other's two MACs are one kind of evidence, so a proposal.
|
|
8978
|
+
*/
|
|
8979
|
+
function classifyIdentityMatch(keys) {
|
|
8980
|
+
const kinds = new Set(keys.map((k) => k.key));
|
|
8981
|
+
const strongKinds = [...kinds].filter((kind) => require_dist.identifierStrength(kind) === "strong");
|
|
8982
|
+
if (strongKinds.length === 0) return null;
|
|
8983
|
+
if (strongKinds.length >= 2) return "auto";
|
|
8984
|
+
if (kinds.has("mac") && kinds.has("ip")) return "auto";
|
|
8985
|
+
return "proposal";
|
|
8986
|
+
}
|
|
8987
|
+
var DeviceIdentityIndex = class {
|
|
8988
|
+
devices = /* @__PURE__ */ new Map();
|
|
8989
|
+
byKey = /* @__PURE__ */ new Map();
|
|
8990
|
+
/** `null` once seeded; until then, the writes to replay over the snapshot. */
|
|
8991
|
+
pending = [];
|
|
8992
|
+
/** Load from a fleet snapshot, then replay every write that landed meanwhile. */
|
|
8993
|
+
seed(rows) {
|
|
8994
|
+
const buffered = this.pending ?? [];
|
|
8995
|
+
this.pending = null;
|
|
8996
|
+
this.devices.clear();
|
|
8997
|
+
this.byKey.clear();
|
|
8998
|
+
for (const row of rows) this.rowWritten(row.meta);
|
|
8999
|
+
for (const write of buffered) write(this);
|
|
9000
|
+
}
|
|
9001
|
+
rowWritten(meta) {
|
|
9002
|
+
if (this.buffer((i) => i.rowWritten(meta))) return;
|
|
9003
|
+
this.put({
|
|
9004
|
+
deviceId: meta.id,
|
|
9005
|
+
addonId: meta.addonId,
|
|
9006
|
+
integrationId: meta.integrationId ?? null,
|
|
9007
|
+
identifiers: meta.identifiers ?? null
|
|
9008
|
+
});
|
|
9009
|
+
}
|
|
9010
|
+
registrationWritten(row) {
|
|
9011
|
+
if (this.buffer((i) => i.registrationWritten(row))) return;
|
|
9012
|
+
const existing = this.devices.get(row.deviceId);
|
|
9013
|
+
this.put({
|
|
9014
|
+
deviceId: row.deviceId,
|
|
9015
|
+
addonId: row.addonId,
|
|
9016
|
+
integrationId: existing?.integrationId ?? null,
|
|
9017
|
+
identifiers: existing?.identifiers ?? null
|
|
9018
|
+
});
|
|
9019
|
+
}
|
|
9020
|
+
rowPatched(deviceId, patch) {
|
|
9021
|
+
if (patch.identifiers === void 0 && patch.integrationId === void 0) return;
|
|
9022
|
+
if (this.buffer((i) => i.rowPatched(deviceId, patch))) return;
|
|
9023
|
+
const existing = this.devices.get(deviceId);
|
|
9024
|
+
if (existing === void 0) return;
|
|
9025
|
+
this.put({
|
|
9026
|
+
...existing,
|
|
9027
|
+
...patch.identifiers !== void 0 ? { identifiers: patch.identifiers } : {},
|
|
9028
|
+
...patch.integrationId !== void 0 ? { integrationId: patch.integrationId } : {}
|
|
9029
|
+
});
|
|
9030
|
+
}
|
|
9031
|
+
rowRemoved(deviceId) {
|
|
9032
|
+
if (this.buffer((i) => i.rowRemoved(deviceId))) return;
|
|
9033
|
+
this.drop(deviceId);
|
|
9034
|
+
}
|
|
9035
|
+
/**
|
|
9036
|
+
* Every cross-integration candidate pair, graded by `classifyIdentityMatch`,
|
|
9037
|
+
* plus the devices whose identity is unknown (nothing declared).
|
|
9038
|
+
*/
|
|
9039
|
+
candidates() {
|
|
9040
|
+
if (this.pending !== null) return {
|
|
9041
|
+
status: "unknown",
|
|
9042
|
+
reason: "the identifier index has not loaded yet"
|
|
9043
|
+
};
|
|
9044
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9045
|
+
const pairs = [];
|
|
9046
|
+
for (const [key, members] of this.byKey) {
|
|
9047
|
+
const parsed = parseKey(key);
|
|
9048
|
+
if (parsed === null || require_dist.identifierStrength(parsed.key) !== "strong") continue;
|
|
9049
|
+
if (members.size < 2) continue;
|
|
9050
|
+
const sorted = [...members].sort((x, y) => x - y);
|
|
9051
|
+
for (let i = 0; i < sorted.length; i++) for (let j = i + 1; j < sorted.length; j++) {
|
|
9052
|
+
const pair = this.pairOf(sorted[i], sorted[j], seen);
|
|
9053
|
+
if (pair !== null) pairs.push(pair);
|
|
9054
|
+
}
|
|
9055
|
+
}
|
|
9056
|
+
pairs.sort((x, y) => x.a.deviceId - y.a.deviceId || x.b.deviceId - y.b.deviceId);
|
|
9057
|
+
return {
|
|
9058
|
+
status: "answered",
|
|
9059
|
+
pairs,
|
|
9060
|
+
undeclaredDeviceIds: [...this.devices.values()].filter((d) => d.identifiers === null).map((d) => d.deviceId).sort((x, y) => x - y)
|
|
9061
|
+
};
|
|
9062
|
+
}
|
|
9063
|
+
pairOf(idA, idB, seen) {
|
|
9064
|
+
if (idA === void 0 || idB === void 0) return null;
|
|
9065
|
+
const tag = `${idA}/${idB}`;
|
|
9066
|
+
if (seen.has(tag)) return null;
|
|
9067
|
+
seen.add(tag);
|
|
9068
|
+
const a = this.devices.get(idA);
|
|
9069
|
+
const b = this.devices.get(idB);
|
|
9070
|
+
if (a === void 0 || b === void 0 || sameIntegration(a, b)) return null;
|
|
9071
|
+
const bKeys = new Set(keysOf(b.identifiers));
|
|
9072
|
+
const keys = keysOf(a.identifiers).filter((k) => bKeys.has(k)).map(parseKey).filter((k) => k !== null).sort(compareKeys);
|
|
9073
|
+
const confidence = classifyIdentityMatch(keys);
|
|
9074
|
+
return confidence === null ? null : {
|
|
9075
|
+
a: sideOf(a),
|
|
9076
|
+
b: sideOf(b),
|
|
9077
|
+
keys,
|
|
9078
|
+
confidence
|
|
9079
|
+
};
|
|
9080
|
+
}
|
|
9081
|
+
/** True when the write was buffered for replay over a seed still in flight. */
|
|
9082
|
+
buffer(write) {
|
|
9083
|
+
if (this.pending === null) return false;
|
|
9084
|
+
this.pending.push(write);
|
|
9085
|
+
return true;
|
|
9086
|
+
}
|
|
9087
|
+
put(device) {
|
|
9088
|
+
this.drop(device.deviceId);
|
|
9089
|
+
this.devices.set(device.deviceId, device);
|
|
9090
|
+
for (const key of keysOf(device.identifiers)) {
|
|
9091
|
+
const members = this.byKey.get(key) ?? /* @__PURE__ */ new Set();
|
|
9092
|
+
members.add(device.deviceId);
|
|
9093
|
+
this.byKey.set(key, members);
|
|
9094
|
+
}
|
|
9095
|
+
}
|
|
9096
|
+
drop(deviceId) {
|
|
9097
|
+
const existing = this.devices.get(deviceId);
|
|
9098
|
+
if (existing === void 0) return;
|
|
9099
|
+
this.devices.delete(deviceId);
|
|
9100
|
+
for (const key of keysOf(existing.identifiers)) {
|
|
9101
|
+
const members = this.byKey.get(key);
|
|
9102
|
+
if (members === void 0) continue;
|
|
9103
|
+
members.delete(deviceId);
|
|
9104
|
+
if (members.size === 0) this.byKey.delete(key);
|
|
9105
|
+
}
|
|
9106
|
+
}
|
|
9107
|
+
};
|
|
9108
|
+
//#endregion
|
|
8901
9109
|
//#region src/builtins/device-manager/linked-devices-manual-backfill.ts
|
|
8902
9110
|
var LINKED_MANUAL_BACKFILL_MARKER_KEY = "_linkedDevicesManualBackfillVersion";
|
|
8903
9111
|
function planManualBackfill(params) {
|
|
@@ -10652,6 +10860,7 @@ function encodeDeviceRowPatch(patch) {
|
|
|
10652
10860
|
var DeviceRowStore = class {
|
|
10653
10861
|
backend;
|
|
10654
10862
|
logger;
|
|
10863
|
+
observer;
|
|
10655
10864
|
declared = null;
|
|
10656
10865
|
/** Call-site attribution for fleet reads. Armed only by
|
|
10657
10866
|
* `CAMSTACK_FLEET_READ_CENSUS_MS`; see `fleet-read-census.ts`. */
|
|
@@ -10666,9 +10875,10 @@ var DeviceRowStore = class {
|
|
|
10666
10875
|
get censusArmed() {
|
|
10667
10876
|
return this.census.armed;
|
|
10668
10877
|
}
|
|
10669
|
-
constructor(backend, logger, census) {
|
|
10878
|
+
constructor(backend, logger, census, observer) {
|
|
10670
10879
|
this.backend = backend;
|
|
10671
10880
|
this.logger = logger;
|
|
10881
|
+
this.observer = observer;
|
|
10672
10882
|
this.census = census ?? new FleetReadCensus(process.env["CAMSTACK_FLEET_READ_CENSUS_MS"], Date.now());
|
|
10673
10883
|
if (this.census.armed) {
|
|
10674
10884
|
const startedAt = Date.now();
|
|
@@ -10943,6 +11153,7 @@ var DeviceRowStore = class {
|
|
|
10943
11153
|
key: String(meta.id),
|
|
10944
11154
|
value: encodeDeviceRow(meta, extra)
|
|
10945
11155
|
});
|
|
11156
|
+
this.observer?.rowWritten(meta);
|
|
10946
11157
|
}
|
|
10947
11158
|
/**
|
|
10948
11159
|
* Write the named columns of an EXISTING row and nothing else.
|
|
@@ -10964,10 +11175,14 @@ var DeviceRowStore = class {
|
|
|
10964
11175
|
filter: { where: { id: String(deviceId) } },
|
|
10965
11176
|
data: columns
|
|
10966
11177
|
});
|
|
10967
|
-
if (updated === 0)
|
|
10968
|
-
|
|
10969
|
-
|
|
10970
|
-
|
|
11178
|
+
if (updated === 0) {
|
|
11179
|
+
this.logger.warn("device row patch matched no row — the device was removed under it", {
|
|
11180
|
+
tags: { deviceId },
|
|
11181
|
+
meta: { columns: Object.keys(columns) }
|
|
11182
|
+
});
|
|
11183
|
+
return;
|
|
11184
|
+
}
|
|
11185
|
+
this.observer?.rowPatched(deviceId, patch);
|
|
10971
11186
|
}
|
|
10972
11187
|
/**
|
|
10973
11188
|
* Insert-or-update the registration columns. See {@link DeviceRegistrationRow}
|
|
@@ -10993,6 +11208,7 @@ var DeviceRowStore = class {
|
|
|
10993
11208
|
exportFingerprint: row.exportFingerprint
|
|
10994
11209
|
}
|
|
10995
11210
|
});
|
|
11211
|
+
this.observer?.registrationWritten(row);
|
|
10996
11212
|
}
|
|
10997
11213
|
/** Drop the device's row. Idempotent. */
|
|
10998
11214
|
/**
|
|
@@ -11092,6 +11308,7 @@ var DeviceRowStore = class {
|
|
|
11092
11308
|
collection: DEVICE_ROWS_COLLECTION,
|
|
11093
11309
|
key: String(deviceId)
|
|
11094
11310
|
});
|
|
11311
|
+
this.observer?.rowRemoved(deviceId);
|
|
11095
11312
|
}
|
|
11096
11313
|
/**
|
|
11097
11314
|
* The retirement door for the three blobs this collection replaced.
|
|
@@ -14028,7 +14245,8 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
|
|
|
14028
14245
|
};
|
|
14029
14246
|
const settingsStoreApi = this.ctx.api?.settingsStore;
|
|
14030
14247
|
if (!settingsStoreApi) throw new Error("[device-manager] settings-store API not available — refusing to serve a fleet it cannot persist");
|
|
14031
|
-
const
|
|
14248
|
+
const identityIndex = new DeviceIdentityIndex();
|
|
14249
|
+
const deviceRows = new DeviceRowStore(deviceRowBackendOf(settingsStoreApi), this.ctx.logger.child("rows"), void 0, identityIndex);
|
|
14032
14250
|
await deviceRows.declare();
|
|
14033
14251
|
this.deviceRows = deviceRows;
|
|
14034
14252
|
const records = this.ctx.records;
|
|
@@ -14091,6 +14309,7 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
|
|
|
14091
14309
|
const idToAddonId = metaStore.idToAddonId;
|
|
14092
14310
|
const bootRows = await deviceRows.listAll();
|
|
14093
14311
|
for (const row of bootRows) idToAddonId.set(row.meta.id, row.meta.addonId);
|
|
14312
|
+
identityIndex.seed(bootRows);
|
|
14094
14313
|
const stampIntegrationId$1 = (deviceId, integrationId) => stampIntegrationId(metaStore, this.ctx, deviceId, integrationId);
|
|
14095
14314
|
const templates = this.makeTemplateActions();
|
|
14096
14315
|
const pctx = {
|
|
@@ -14176,6 +14395,7 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
|
|
|
14176
14395
|
setRole: (input) => setRole(pctx, input),
|
|
14177
14396
|
setDisplay: (input) => setDisplay(pctx, input),
|
|
14178
14397
|
setIdentifiers: (input) => setIdentifiers(pctx, input),
|
|
14398
|
+
listIdentityCandidates: async () => identityIndex.candidates(),
|
|
14179
14399
|
getRoleDisplayDefaults: (input) => getRoleDisplayDefaults(pctx, input),
|
|
14180
14400
|
setRoleDisplayDefaults: (input) => setRoleDisplayDefaults(pctx, input),
|
|
14181
14401
|
applyInitialMeta: (input) => applyInitialMeta(pctx, input),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { $
|
|
1
|
+
import { $ as DEVICE_TEMPLATE_VALUES_CAP, $s as implementedMethodsOf$1, Bi as isKernelDerivedFeature, Br as deviceExtensionCapability, Ca as normalizeTags, Dn as WORKLOAD_TRANSITION_CATEGORY, Do as sameIdentifiers, Dr as createDeviceExtensionProvider, El as isDeviceConfigCap, Eo as runtimeStatePolicyFor, Fr as defineExtensionSlotProvider, Gi as isWorkloadSettled, Hc as SECRET_CLEAR, Ho as siteZoneKey, Hr as deviceManagerCapability, Io as settleDeviceFeatures, It as MINUTES_PER_DAY, Jc as WELL_KNOWN_TAB_MAP, Jl as resolveSecretMarkers, Kr as deviceStateCapability, Mo as searchRank, Nl as isSecretMarker, On as WorkloadStateSchema, Pl as isSecretMarkerLike, Qn as buildStreamParamsConfigSchema, Ri as isEmptyIdentifiers, Rs as canonicalStoredDeviceType, S as CAP_NAMES_WITH_STATUS, So as resolveTemplateRef, To as runtimeFieldUnit, Ts as workloadTransition, Ur as deviceOffersActions, W as DEVICE_IDENTIFIER_KEYS, X as DEVICE_TEMPLATE_MAX_LENGTH, Xa as reconcileReportedFeatures, Xr as enumerateItemArrayFields, Y as DEVICE_TEMPLATE_FILTERS, Yi as legacyAutoLinkIds, Z as DEVICE_TEMPLATE_MAX_OUTPUT, Zl as secretTreeFromPaths, Zr as enumerateSchemaFields, ai as extractSourceInfoFromMetadata, at as DeviceStatusSchema, au as vocabActionIdFor, b as CAMERA_SWITCH_ORDER, bt as FieldClaimSchema, cn as STREAM_PROFILE_META, dt as ExportNameRefusedError, du as DeviceType$1, eu as sleep$2, fa as mergeIdentifiers, fc as BaseAddon, fu as errMsg$1, hi as formatMinutes, iu as userError, j as ConditionMirror, ja as parseStreamParamsFormPatch, jl as isSecretClear, kl as isKeychainStoredField, lu as DeviceFeature, ml as defineRecordKinds, mu as EventCategory$1, ni as expandContainer, nr as canonicalIconKey, nu as toSecretFieldView, ol as collectZodSecretPaths$1, or as checkDeviceAlias, ot as DeviceTombstoneSchema, qr as deviceStatusCapability, rt as DeviceIdentifiersSchema, ru as transformSecretWrite, s as ALL_CAPABILITY_DEFINITIONS, sl as commandEffect, st as DiscoveryProposalBodySchema, ta as locationIconKey, tl as auditedFields, uu as DeviceRole, vi as generateDeviceAlias, vl as expandCapMethods$1, wa as normalizeUnit, wi as identifierStrength, wl as isCommand$1, ws as workloadCapability, yt as FieldClaimModeSchema, z as DAY_NAMES, zs as capAppliesToDeviceKind } from "../../dist-Be8yFd71.mjs";
|
|
2
2
|
import { t as require_read_all_rows } from "../../read-all-rows-TaPqdWNF.mjs";
|
|
3
3
|
import { a as redactLogText, i as redactLogMeta, n as isSecretArgumentKey } from "../../log-redactor-XLDrPzOi.mjs";
|
|
4
|
-
import { n as renameCompositionBlock, t as composedBlockIdOf } from "../../rename-composition-block-
|
|
4
|
+
import { n as renameCompositionBlock, t as composedBlockIdOf } from "../../rename-composition-block-LEbZ4oZE.mjs";
|
|
5
5
|
import { t as prefixRange } from "../../prefix-range-Dl0znowN.mjs";
|
|
6
6
|
import { t as loadPrefixed } from "../../prefix-walk-DAOBSyH1.mjs";
|
|
7
7
|
import { n as purgeRetiredSettingsRows } from "../../retired-settings-keys-u6xQA6r7.mjs";
|
|
@@ -4738,7 +4738,7 @@ function compareUnranked(a, b) {
|
|
|
4738
4738
|
if (a[2] !== b[2]) return a[2] < b[2] ? -1 : 1;
|
|
4739
4739
|
return a[3] - b[3];
|
|
4740
4740
|
}
|
|
4741
|
-
function compareKeys(a, b) {
|
|
4741
|
+
function compareKeys$1(a, b) {
|
|
4742
4742
|
if (a.length === 5 && b.length === 5) {
|
|
4743
4743
|
if (a[0] !== b[0]) return a[0] - b[0];
|
|
4744
4744
|
return compareUnranked([
|
|
@@ -4913,14 +4913,14 @@ async function searchDevices(deps, input) {
|
|
|
4913
4913
|
const keyed = listed.map((c) => ({
|
|
4914
4914
|
c,
|
|
4915
4915
|
key: sortKeyOf(c)
|
|
4916
|
-
})).sort((a, b) => compareKeys(a.key, b.key));
|
|
4916
|
+
})).sort((a, b) => compareKeys$1(a.key, b.key));
|
|
4917
4917
|
const limit = Math.min(input.limit ?? 50, 200);
|
|
4918
4918
|
let start = 0;
|
|
4919
4919
|
if (input.cursor !== void 0 && input.cursor !== null) {
|
|
4920
4920
|
const after = decodeCursor(input.cursor);
|
|
4921
4921
|
if (after === null) deps.logger.warn("deviceManager.search: undecodable cursor — restarting from the first page");
|
|
4922
4922
|
else {
|
|
4923
|
-
const next = keyed.findIndex((k) => compareKeys(k.key, after) > 0);
|
|
4923
|
+
const next = keyed.findIndex((k) => compareKeys$1(k.key, after) > 0);
|
|
4924
4924
|
start = next === -1 ? keyed.length : next;
|
|
4925
4925
|
}
|
|
4926
4926
|
}
|
|
@@ -8892,6 +8892,214 @@ async function setIdentifiers(pctx, input) {
|
|
|
8892
8892
|
});
|
|
8893
8893
|
}
|
|
8894
8894
|
//#endregion
|
|
8895
|
+
//#region src/builtins/device-manager/device-identity-index.ts
|
|
8896
|
+
/**
|
|
8897
|
+
* The identifier INDEX (planning#593): identifier key → devices, so the
|
|
8898
|
+
* device-manager can say which devices of DIFFERENT integrations share
|
|
8899
|
+
* provider-declared identifiers (D1059) without reading the fleet per question.
|
|
8900
|
+
*
|
|
8901
|
+
* It is a PROJECTION of the device rows, never an authority: it holds, per
|
|
8902
|
+
* device, only what the pair rule needs — owning addon, integration instance and
|
|
8903
|
+
* the declared identifiers — and it moves with the rows, as the
|
|
8904
|
+
* {@link DeviceRowObserver} of the one `DeviceRowStore`. Every write of a row
|
|
8905
|
+
* passes through that store (`upsert`, `upsertRegistration`, `patch`, `remove`;
|
|
8906
|
+
* `swapIds` is built of them), so a row that changes reaches the index on the
|
|
8907
|
+
* same statement. A deleted device leaves the index on its row's DELETE — the
|
|
8908
|
+
* statement `removeDevice` runs right before it records the tombstone (D865) —
|
|
8909
|
+
* not on an event or on absence from a listing.
|
|
8910
|
+
*
|
|
8911
|
+
* It loads once, from the fleet listing the device-manager already reads at
|
|
8912
|
+
* boot ({@link seed}). Until then it answers `unknown` (D315), never `[]`; a row
|
|
8913
|
+
* write that lands while the snapshot is in flight is buffered and replayed over
|
|
8914
|
+
* it, so the seed can never roll a newer write back.
|
|
8915
|
+
*
|
|
8916
|
+
* Read-only: it finds candidates, it links nothing (that is step 3).
|
|
8917
|
+
*/
|
|
8918
|
+
/** The `kind=value` keys of one declaration. */
|
|
8919
|
+
function keysOf(identifiers) {
|
|
8920
|
+
if (identifiers === null) return [];
|
|
8921
|
+
const out = [];
|
|
8922
|
+
for (const kind of DEVICE_IDENTIFIER_KEYS) {
|
|
8923
|
+
const entry = identifiers[kind];
|
|
8924
|
+
if (entry === void 0) continue;
|
|
8925
|
+
for (const e of [entry].flat()) out.push(`${kind}=${e.value}`);
|
|
8926
|
+
}
|
|
8927
|
+
return out;
|
|
8928
|
+
}
|
|
8929
|
+
function isIdentifierKind(value) {
|
|
8930
|
+
return DEVICE_IDENTIFIER_KEYS.some((k) => k === value);
|
|
8931
|
+
}
|
|
8932
|
+
function parseKey(key) {
|
|
8933
|
+
const at = key.indexOf("=");
|
|
8934
|
+
const kind = key.slice(0, at);
|
|
8935
|
+
return isIdentifierKind(kind) ? {
|
|
8936
|
+
key: kind,
|
|
8937
|
+
value: key.slice(at + 1)
|
|
8938
|
+
} : null;
|
|
8939
|
+
}
|
|
8940
|
+
/**
|
|
8941
|
+
* Same integration? The same instance when both carry one; otherwise — one side
|
|
8942
|
+
* was never stamped — the same addon. In doubt, the same: no candidate.
|
|
8943
|
+
*/
|
|
8944
|
+
function sameIntegration(a, b) {
|
|
8945
|
+
if (a.integrationId !== null && b.integrationId !== null) return a.integrationId === b.integrationId;
|
|
8946
|
+
return a.addonId === b.addonId;
|
|
8947
|
+
}
|
|
8948
|
+
function sideOf(d) {
|
|
8949
|
+
return {
|
|
8950
|
+
deviceId: d.deviceId,
|
|
8951
|
+
addonId: d.addonId,
|
|
8952
|
+
integrationId: d.integrationId
|
|
8953
|
+
};
|
|
8954
|
+
}
|
|
8955
|
+
function compareKeys(x, y) {
|
|
8956
|
+
if (x.key !== y.key) return x.key < y.key ? -1 : 1;
|
|
8957
|
+
return x.value < y.value ? -1 : x.value > y.value ? 1 : 0;
|
|
8958
|
+
}
|
|
8959
|
+
/**
|
|
8960
|
+
* Grade the keys two devices share. `null` when they are no candidate at all
|
|
8961
|
+
* (no strong key matched).
|
|
8962
|
+
*
|
|
8963
|
+
* | Matched keys | Confidence |
|
|
8964
|
+
* | ----------------------------------------- | ------------ |
|
|
8965
|
+
* | two strong KINDS (e.g. `mac` + `serial`) | `auto` |
|
|
8966
|
+
* | `mac` + `ip` | `auto` |
|
|
8967
|
+
* | exactly one strong kind | `proposal` |
|
|
8968
|
+
* | weak keys only (`hostname`, `ip`) | no candidate |
|
|
8969
|
+
*
|
|
8970
|
+
* Strength counts distinct KINDS, not values: two MACs of one device matching
|
|
8971
|
+
* the other's two MACs are one kind of evidence, so a proposal.
|
|
8972
|
+
*/
|
|
8973
|
+
function classifyIdentityMatch(keys) {
|
|
8974
|
+
const kinds = new Set(keys.map((k) => k.key));
|
|
8975
|
+
const strongKinds = [...kinds].filter((kind) => identifierStrength(kind) === "strong");
|
|
8976
|
+
if (strongKinds.length === 0) return null;
|
|
8977
|
+
if (strongKinds.length >= 2) return "auto";
|
|
8978
|
+
if (kinds.has("mac") && kinds.has("ip")) return "auto";
|
|
8979
|
+
return "proposal";
|
|
8980
|
+
}
|
|
8981
|
+
var DeviceIdentityIndex = class {
|
|
8982
|
+
devices = /* @__PURE__ */ new Map();
|
|
8983
|
+
byKey = /* @__PURE__ */ new Map();
|
|
8984
|
+
/** `null` once seeded; until then, the writes to replay over the snapshot. */
|
|
8985
|
+
pending = [];
|
|
8986
|
+
/** Load from a fleet snapshot, then replay every write that landed meanwhile. */
|
|
8987
|
+
seed(rows) {
|
|
8988
|
+
const buffered = this.pending ?? [];
|
|
8989
|
+
this.pending = null;
|
|
8990
|
+
this.devices.clear();
|
|
8991
|
+
this.byKey.clear();
|
|
8992
|
+
for (const row of rows) this.rowWritten(row.meta);
|
|
8993
|
+
for (const write of buffered) write(this);
|
|
8994
|
+
}
|
|
8995
|
+
rowWritten(meta) {
|
|
8996
|
+
if (this.buffer((i) => i.rowWritten(meta))) return;
|
|
8997
|
+
this.put({
|
|
8998
|
+
deviceId: meta.id,
|
|
8999
|
+
addonId: meta.addonId,
|
|
9000
|
+
integrationId: meta.integrationId ?? null,
|
|
9001
|
+
identifiers: meta.identifiers ?? null
|
|
9002
|
+
});
|
|
9003
|
+
}
|
|
9004
|
+
registrationWritten(row) {
|
|
9005
|
+
if (this.buffer((i) => i.registrationWritten(row))) return;
|
|
9006
|
+
const existing = this.devices.get(row.deviceId);
|
|
9007
|
+
this.put({
|
|
9008
|
+
deviceId: row.deviceId,
|
|
9009
|
+
addonId: row.addonId,
|
|
9010
|
+
integrationId: existing?.integrationId ?? null,
|
|
9011
|
+
identifiers: existing?.identifiers ?? null
|
|
9012
|
+
});
|
|
9013
|
+
}
|
|
9014
|
+
rowPatched(deviceId, patch) {
|
|
9015
|
+
if (patch.identifiers === void 0 && patch.integrationId === void 0) return;
|
|
9016
|
+
if (this.buffer((i) => i.rowPatched(deviceId, patch))) return;
|
|
9017
|
+
const existing = this.devices.get(deviceId);
|
|
9018
|
+
if (existing === void 0) return;
|
|
9019
|
+
this.put({
|
|
9020
|
+
...existing,
|
|
9021
|
+
...patch.identifiers !== void 0 ? { identifiers: patch.identifiers } : {},
|
|
9022
|
+
...patch.integrationId !== void 0 ? { integrationId: patch.integrationId } : {}
|
|
9023
|
+
});
|
|
9024
|
+
}
|
|
9025
|
+
rowRemoved(deviceId) {
|
|
9026
|
+
if (this.buffer((i) => i.rowRemoved(deviceId))) return;
|
|
9027
|
+
this.drop(deviceId);
|
|
9028
|
+
}
|
|
9029
|
+
/**
|
|
9030
|
+
* Every cross-integration candidate pair, graded by `classifyIdentityMatch`,
|
|
9031
|
+
* plus the devices whose identity is unknown (nothing declared).
|
|
9032
|
+
*/
|
|
9033
|
+
candidates() {
|
|
9034
|
+
if (this.pending !== null) return {
|
|
9035
|
+
status: "unknown",
|
|
9036
|
+
reason: "the identifier index has not loaded yet"
|
|
9037
|
+
};
|
|
9038
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9039
|
+
const pairs = [];
|
|
9040
|
+
for (const [key, members] of this.byKey) {
|
|
9041
|
+
const parsed = parseKey(key);
|
|
9042
|
+
if (parsed === null || identifierStrength(parsed.key) !== "strong") continue;
|
|
9043
|
+
if (members.size < 2) continue;
|
|
9044
|
+
const sorted = [...members].sort((x, y) => x - y);
|
|
9045
|
+
for (let i = 0; i < sorted.length; i++) for (let j = i + 1; j < sorted.length; j++) {
|
|
9046
|
+
const pair = this.pairOf(sorted[i], sorted[j], seen);
|
|
9047
|
+
if (pair !== null) pairs.push(pair);
|
|
9048
|
+
}
|
|
9049
|
+
}
|
|
9050
|
+
pairs.sort((x, y) => x.a.deviceId - y.a.deviceId || x.b.deviceId - y.b.deviceId);
|
|
9051
|
+
return {
|
|
9052
|
+
status: "answered",
|
|
9053
|
+
pairs,
|
|
9054
|
+
undeclaredDeviceIds: [...this.devices.values()].filter((d) => d.identifiers === null).map((d) => d.deviceId).sort((x, y) => x - y)
|
|
9055
|
+
};
|
|
9056
|
+
}
|
|
9057
|
+
pairOf(idA, idB, seen) {
|
|
9058
|
+
if (idA === void 0 || idB === void 0) return null;
|
|
9059
|
+
const tag = `${idA}/${idB}`;
|
|
9060
|
+
if (seen.has(tag)) return null;
|
|
9061
|
+
seen.add(tag);
|
|
9062
|
+
const a = this.devices.get(idA);
|
|
9063
|
+
const b = this.devices.get(idB);
|
|
9064
|
+
if (a === void 0 || b === void 0 || sameIntegration(a, b)) return null;
|
|
9065
|
+
const bKeys = new Set(keysOf(b.identifiers));
|
|
9066
|
+
const keys = keysOf(a.identifiers).filter((k) => bKeys.has(k)).map(parseKey).filter((k) => k !== null).sort(compareKeys);
|
|
9067
|
+
const confidence = classifyIdentityMatch(keys);
|
|
9068
|
+
return confidence === null ? null : {
|
|
9069
|
+
a: sideOf(a),
|
|
9070
|
+
b: sideOf(b),
|
|
9071
|
+
keys,
|
|
9072
|
+
confidence
|
|
9073
|
+
};
|
|
9074
|
+
}
|
|
9075
|
+
/** True when the write was buffered for replay over a seed still in flight. */
|
|
9076
|
+
buffer(write) {
|
|
9077
|
+
if (this.pending === null) return false;
|
|
9078
|
+
this.pending.push(write);
|
|
9079
|
+
return true;
|
|
9080
|
+
}
|
|
9081
|
+
put(device) {
|
|
9082
|
+
this.drop(device.deviceId);
|
|
9083
|
+
this.devices.set(device.deviceId, device);
|
|
9084
|
+
for (const key of keysOf(device.identifiers)) {
|
|
9085
|
+
const members = this.byKey.get(key) ?? /* @__PURE__ */ new Set();
|
|
9086
|
+
members.add(device.deviceId);
|
|
9087
|
+
this.byKey.set(key, members);
|
|
9088
|
+
}
|
|
9089
|
+
}
|
|
9090
|
+
drop(deviceId) {
|
|
9091
|
+
const existing = this.devices.get(deviceId);
|
|
9092
|
+
if (existing === void 0) return;
|
|
9093
|
+
this.devices.delete(deviceId);
|
|
9094
|
+
for (const key of keysOf(existing.identifiers)) {
|
|
9095
|
+
const members = this.byKey.get(key);
|
|
9096
|
+
if (members === void 0) continue;
|
|
9097
|
+
members.delete(deviceId);
|
|
9098
|
+
if (members.size === 0) this.byKey.delete(key);
|
|
9099
|
+
}
|
|
9100
|
+
}
|
|
9101
|
+
};
|
|
9102
|
+
//#endregion
|
|
8895
9103
|
//#region src/builtins/device-manager/linked-devices-manual-backfill.ts
|
|
8896
9104
|
var LINKED_MANUAL_BACKFILL_MARKER_KEY = "_linkedDevicesManualBackfillVersion";
|
|
8897
9105
|
function planManualBackfill(params) {
|
|
@@ -10645,6 +10853,7 @@ function encodeDeviceRowPatch(patch) {
|
|
|
10645
10853
|
var DeviceRowStore = class {
|
|
10646
10854
|
backend;
|
|
10647
10855
|
logger;
|
|
10856
|
+
observer;
|
|
10648
10857
|
declared = null;
|
|
10649
10858
|
/** Call-site attribution for fleet reads. Armed only by
|
|
10650
10859
|
* `CAMSTACK_FLEET_READ_CENSUS_MS`; see `fleet-read-census.ts`. */
|
|
@@ -10659,9 +10868,10 @@ var DeviceRowStore = class {
|
|
|
10659
10868
|
get censusArmed() {
|
|
10660
10869
|
return this.census.armed;
|
|
10661
10870
|
}
|
|
10662
|
-
constructor(backend, logger, census) {
|
|
10871
|
+
constructor(backend, logger, census, observer) {
|
|
10663
10872
|
this.backend = backend;
|
|
10664
10873
|
this.logger = logger;
|
|
10874
|
+
this.observer = observer;
|
|
10665
10875
|
this.census = census ?? new FleetReadCensus(process.env["CAMSTACK_FLEET_READ_CENSUS_MS"], Date.now());
|
|
10666
10876
|
if (this.census.armed) {
|
|
10667
10877
|
const startedAt = Date.now();
|
|
@@ -10936,6 +11146,7 @@ var DeviceRowStore = class {
|
|
|
10936
11146
|
key: String(meta.id),
|
|
10937
11147
|
value: encodeDeviceRow(meta, extra)
|
|
10938
11148
|
});
|
|
11149
|
+
this.observer?.rowWritten(meta);
|
|
10939
11150
|
}
|
|
10940
11151
|
/**
|
|
10941
11152
|
* Write the named columns of an EXISTING row and nothing else.
|
|
@@ -10957,10 +11168,14 @@ var DeviceRowStore = class {
|
|
|
10957
11168
|
filter: { where: { id: String(deviceId) } },
|
|
10958
11169
|
data: columns
|
|
10959
11170
|
});
|
|
10960
|
-
if (updated === 0)
|
|
10961
|
-
|
|
10962
|
-
|
|
10963
|
-
|
|
11171
|
+
if (updated === 0) {
|
|
11172
|
+
this.logger.warn("device row patch matched no row — the device was removed under it", {
|
|
11173
|
+
tags: { deviceId },
|
|
11174
|
+
meta: { columns: Object.keys(columns) }
|
|
11175
|
+
});
|
|
11176
|
+
return;
|
|
11177
|
+
}
|
|
11178
|
+
this.observer?.rowPatched(deviceId, patch);
|
|
10964
11179
|
}
|
|
10965
11180
|
/**
|
|
10966
11181
|
* Insert-or-update the registration columns. See {@link DeviceRegistrationRow}
|
|
@@ -10986,6 +11201,7 @@ var DeviceRowStore = class {
|
|
|
10986
11201
|
exportFingerprint: row.exportFingerprint
|
|
10987
11202
|
}
|
|
10988
11203
|
});
|
|
11204
|
+
this.observer?.registrationWritten(row);
|
|
10989
11205
|
}
|
|
10990
11206
|
/** Drop the device's row. Idempotent. */
|
|
10991
11207
|
/**
|
|
@@ -11085,6 +11301,7 @@ var DeviceRowStore = class {
|
|
|
11085
11301
|
collection: DEVICE_ROWS_COLLECTION,
|
|
11086
11302
|
key: String(deviceId)
|
|
11087
11303
|
});
|
|
11304
|
+
this.observer?.rowRemoved(deviceId);
|
|
11088
11305
|
}
|
|
11089
11306
|
/**
|
|
11090
11307
|
* The retirement door for the three blobs this collection replaced.
|
|
@@ -14021,7 +14238,8 @@ var DeviceManagerAddon = class extends BaseAddon {
|
|
|
14021
14238
|
};
|
|
14022
14239
|
const settingsStoreApi = this.ctx.api?.settingsStore;
|
|
14023
14240
|
if (!settingsStoreApi) throw new Error("[device-manager] settings-store API not available — refusing to serve a fleet it cannot persist");
|
|
14024
|
-
const
|
|
14241
|
+
const identityIndex = new DeviceIdentityIndex();
|
|
14242
|
+
const deviceRows = new DeviceRowStore(deviceRowBackendOf(settingsStoreApi), this.ctx.logger.child("rows"), void 0, identityIndex);
|
|
14025
14243
|
await deviceRows.declare();
|
|
14026
14244
|
this.deviceRows = deviceRows;
|
|
14027
14245
|
const records = this.ctx.records;
|
|
@@ -14084,6 +14302,7 @@ var DeviceManagerAddon = class extends BaseAddon {
|
|
|
14084
14302
|
const idToAddonId = metaStore.idToAddonId;
|
|
14085
14303
|
const bootRows = await deviceRows.listAll();
|
|
14086
14304
|
for (const row of bootRows) idToAddonId.set(row.meta.id, row.meta.addonId);
|
|
14305
|
+
identityIndex.seed(bootRows);
|
|
14087
14306
|
const stampIntegrationId$1 = (deviceId, integrationId) => stampIntegrationId(metaStore, this.ctx, deviceId, integrationId);
|
|
14088
14307
|
const templates = this.makeTemplateActions();
|
|
14089
14308
|
const pctx = {
|
|
@@ -14169,6 +14388,7 @@ var DeviceManagerAddon = class extends BaseAddon {
|
|
|
14169
14388
|
setRole: (input) => setRole(pctx, input),
|
|
14170
14389
|
setDisplay: (input) => setDisplay(pctx, input),
|
|
14171
14390
|
setIdentifiers: (input) => setIdentifiers(pctx, input),
|
|
14391
|
+
listIdentityCandidates: async () => identityIndex.candidates(),
|
|
14172
14392
|
getRoleDisplayDefaults: (input) => getRoleDisplayDefaults(pctx, input),
|
|
14173
14393
|
setRoleDisplayDefaults: (input) => setRoleDisplayDefaults(pctx, input),
|
|
14174
14394
|
applyInitialMeta: (input) => applyInitialMeta(pctx, input),
|