fix(device-plane): unwrap durable discovery receipts

This commit is contained in:
Codex
2026-08-12 18:08:44 +03:00
parent 606872edcc
commit 66e0c62451
2 changed files with 72 additions and 7 deletions
@@ -12,6 +12,8 @@ import {
normalizeCertificateFingerprint,
} from "../../../packages/device-edge-channel-contract/src/index.mjs";
import {
DEVICE_DISCOVERY_VIEW_SCHEMA,
assertSafeProjection,
normalizeAdapterMessage,
normalizeDiscoverySignal,
} from "../../../packages/device-protocol-contract/src/index.mjs";
@@ -298,7 +300,9 @@ export function createDeviceGatewayCoreChannelClient(options = {}) {
async function acceptDiscovery(connection, envelope) {
try {
const signal = normalizeDiscoverySignal(envelope.payload?.signal);
const discovery = await config.observeDiscovery(signal);
const discovery = normalizeDiscoveryReceipt(
await config.observeDiscovery(signal),
);
sendEventResult(connection, envelope, { discovery });
totalEventsAccepted += 1;
} catch (error) {
@@ -468,6 +472,26 @@ export function createDeviceGatewayCoreChannelClient(options = {}) {
}
}
function normalizeDiscoveryReceipt(input) {
if (
!input
|| typeof input !== "object"
|| Array.isArray(input)
|| typeof input.created !== "boolean"
) {
throw new TypeError("device_gateway_core_discovery_receipt_invalid");
}
const discovery = assertSafeProjection(input.value);
if (
discovery.schemaVersion !== DEVICE_DISCOVERY_VIEW_SCHEMA
|| !["quarantine", "claimed"].includes(discovery.lifecycleState)
|| discovery.commandTransport !== "disabled"
) {
throw new TypeError("device_gateway_core_discovery_receipt_invalid");
}
return discovery;
}
function normalizeConfig(options) {
if (typeof options.observeDiscovery !== "function") {
throw new TypeError("device_gateway_core_observe_discovery_invalid");