@camstack/addon-export-alexa 1.2.182 → 1.2.183
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/export-alexa.addon.js +331 -55
- package/dist/export-alexa.addon.mjs +331 -55
- package/package.json +2 -2
|
@@ -6016,7 +6016,7 @@ var ZodIssueCode = {
|
|
|
6016
6016
|
var ZodFirstPartyTypeKind;
|
|
6017
6017
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
6018
6018
|
//#endregion
|
|
6019
|
-
//#region ../types/dist/sleep-
|
|
6019
|
+
//#region ../types/dist/sleep-BaWhXZFm.mjs
|
|
6020
6020
|
/**
|
|
6021
6021
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
6022
6022
|
* window to float samples (D455).
|
|
@@ -7028,7 +7028,7 @@ async function writeMembers(ctx, children, incoming, stored, pathOf) {
|
|
|
7028
7028
|
for (const [member, node] of children) applyMember(out, member, await writeNode(ctx, node, incoming[member], stored[member], pathOf(member)), stored);
|
|
7029
7029
|
return out;
|
|
7030
7030
|
}
|
|
7031
|
-
function rowId$
|
|
7031
|
+
function rowId$2(row, idKey) {
|
|
7032
7032
|
const raw = row[idKey];
|
|
7033
7033
|
if (typeof raw === "string" && raw.length > 0) return raw;
|
|
7034
7034
|
if (typeof raw === "number" && Number.isFinite(raw)) return String(raw);
|
|
@@ -7045,7 +7045,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
7045
7045
|
}
|
|
7046
7046
|
const storedById = /* @__PURE__ */ new Map();
|
|
7047
7047
|
for (const row of storedRows) {
|
|
7048
|
-
const id = rowId$
|
|
7048
|
+
const id = rowId$2(row, node.idKey);
|
|
7049
7049
|
if (id !== null) storedById.set(id, row);
|
|
7050
7050
|
}
|
|
7051
7051
|
const kept = /* @__PURE__ */ new Set();
|
|
@@ -7055,13 +7055,13 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
7055
7055
|
rows.push(row);
|
|
7056
7056
|
continue;
|
|
7057
7057
|
}
|
|
7058
|
-
const id = rowId$
|
|
7058
|
+
const id = rowId$2(row, node.idKey) ?? ctx.mintId();
|
|
7059
7059
|
kept.add(id);
|
|
7060
7060
|
const withId = {
|
|
7061
7061
|
...row,
|
|
7062
7062
|
[node.idKey]: row[node.idKey] ?? id
|
|
7063
7063
|
};
|
|
7064
|
-
if (rowId$
|
|
7064
|
+
if (rowId$2(withId, node.idKey) === null) withId[node.idKey] = id;
|
|
7065
7065
|
const storedRow = storedById.get(id) ?? {};
|
|
7066
7066
|
rows.push(await writeMembers(ctx, node.item, withId, storedRow, (member) => arrayItemFieldPath(fieldPath, id, member)));
|
|
7067
7067
|
}
|
|
@@ -8859,6 +8859,10 @@ var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
|
8859
8859
|
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
8860
8860
|
* (`auth.accessToken`, `headers[].value`).
|
|
8861
8861
|
*
|
|
8862
|
+
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
8863
|
+
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
8864
|
+
* key releases exactly that key's secret.
|
|
8865
|
+
*
|
|
8862
8866
|
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
8863
8867
|
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
8864
8868
|
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
@@ -8871,11 +8875,13 @@ function parseSecretPath(path) {
|
|
|
8871
8875
|
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
8872
8876
|
return path.split(".").map((raw) => {
|
|
8873
8877
|
const each = raw.endsWith("[]");
|
|
8874
|
-
const
|
|
8878
|
+
const map = raw.endsWith("{}");
|
|
8879
|
+
const key = each || map ? raw.slice(0, -2) : raw;
|
|
8875
8880
|
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
8876
8881
|
return {
|
|
8877
8882
|
key,
|
|
8878
|
-
each
|
|
8883
|
+
each,
|
|
8884
|
+
map
|
|
8879
8885
|
};
|
|
8880
8886
|
});
|
|
8881
8887
|
}
|
|
@@ -8927,6 +8933,22 @@ function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arra
|
|
|
8927
8933
|
[segment.key]: mapped
|
|
8928
8934
|
};
|
|
8929
8935
|
}
|
|
8936
|
+
if (segment.map) {
|
|
8937
|
+
if (!isRecord$4(child)) return node;
|
|
8938
|
+
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
8939
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
8940
|
+
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
8941
|
+
return [mapKey, visit({
|
|
8942
|
+
declared,
|
|
8943
|
+
concrete,
|
|
8944
|
+
value
|
|
8945
|
+
})];
|
|
8946
|
+
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
8947
|
+
return {
|
|
8948
|
+
...node,
|
|
8949
|
+
[segment.key]: Object.fromEntries(kept)
|
|
8950
|
+
};
|
|
8951
|
+
}
|
|
8930
8952
|
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
8931
8953
|
if (last) {
|
|
8932
8954
|
const replacement = visit({
|
|
@@ -9068,7 +9090,8 @@ function isZodSecret(schema) {
|
|
|
9068
9090
|
}
|
|
9069
9091
|
/**
|
|
9070
9092
|
* Every declared secret path in a config schema: dotted keys, `[]` for "each
|
|
9071
|
-
* element of this array" (`connection.password`, `rows[].token`)
|
|
9093
|
+
* element of this array" (`connection.password`, `rows[].token`), `{}` for "each value of this
|
|
9094
|
+
* map" (`applianceSecrets{}`). A declared
|
|
9072
9095
|
* object or array is reported as one path and not descended into — everything
|
|
9073
9096
|
* under it is secret.
|
|
9074
9097
|
*/
|
|
@@ -9079,6 +9102,7 @@ function collectZodSecretPaths(schema, prefix = "") {
|
|
|
9079
9102
|
const def = defOf(layer);
|
|
9080
9103
|
if (def.type === "object" && def.shape) for (const [key, child] of Object.entries(def.shape)) paths.push(...collectZodSecretPaths(child, prefix ? `${prefix}.${key}` : key));
|
|
9081
9104
|
else if (def.type === "array" && def.element) paths.push(...collectZodSecretPaths(def.element, `${prefix}[]`));
|
|
9105
|
+
else if (def.type === "record" && def.valueType) paths.push(...collectZodSecretPaths(def.valueType, `${prefix}{}`));
|
|
9082
9106
|
else if (def.type === "union" && def.options) for (const option of def.options) paths.push(...collectZodSecretPaths(option, prefix));
|
|
9083
9107
|
else if (def.type === "intersection") {
|
|
9084
9108
|
if (def.left) paths.push(...collectZodSecretPaths(def.left, prefix));
|
|
@@ -13397,11 +13421,49 @@ function buildCapturingReply(envelope) {
|
|
|
13397
13421
|
};
|
|
13398
13422
|
return wrapper;
|
|
13399
13423
|
}
|
|
13424
|
+
/**
|
|
13425
|
+
* `RecordIntegrationInstances` - the `integration-instances` provider over ONE
|
|
13426
|
+
* entry kind, so an addon that holds a connection serves it in ~30 lines.
|
|
13427
|
+
*
|
|
13428
|
+
* Every instance is one record of the addon's own kind, keyed by the
|
|
13429
|
+
* `integrations` registry id. The records door does the secret work: a field the
|
|
13430
|
+
* kind marks `.meta({ secret: true })` is a keychain marker bound to the row, so
|
|
13431
|
+
* deleting the row deletes the secret, and one row's value is never another's.
|
|
13432
|
+
*
|
|
13433
|
+
* Patch rules for a secret (`updateInstance`): omitted, `''`, the redaction
|
|
13434
|
+
* token or the view the form was given KEEP the stored secret;
|
|
13435
|
+
* `{ $secretClear: true }` clears it; any other string replaces it.
|
|
13436
|
+
*/
|
|
13400
13437
|
/** The most instances one addon lists (an integrations page, not a table). */
|
|
13401
13438
|
var INSTANCES_LIST_MAX = 1e3;
|
|
13402
13439
|
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
13403
13440
|
function topLevelSecretKeys(paths) {
|
|
13404
|
-
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[")));
|
|
13441
|
+
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
13442
|
+
}
|
|
13443
|
+
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
13444
|
+
function secretMapKeys(paths) {
|
|
13445
|
+
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
13446
|
+
}
|
|
13447
|
+
/**
|
|
13448
|
+
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
13449
|
+
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
13450
|
+
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
13451
|
+
*/
|
|
13452
|
+
function secretMapPatch(value) {
|
|
13453
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
13454
|
+
const out = {};
|
|
13455
|
+
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
13456
|
+
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
13457
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
13458
|
+
}
|
|
13459
|
+
/** Does the kind's body schema carry an `enabled` field? */
|
|
13460
|
+
function declaresEnabled(kind) {
|
|
13461
|
+
const json = toJSONSchema(kind.schema, {
|
|
13462
|
+
unrepresentable: "any",
|
|
13463
|
+
io: "input"
|
|
13464
|
+
});
|
|
13465
|
+
const properties = Reflect.get(json, "properties");
|
|
13466
|
+
return typeof properties === "object" && properties !== null && "enabled" in properties;
|
|
13405
13467
|
}
|
|
13406
13468
|
var RecordIntegrationInstances = class {
|
|
13407
13469
|
records;
|
|
@@ -13409,14 +13471,20 @@ var RecordIntegrationInstances = class {
|
|
|
13409
13471
|
hooks;
|
|
13410
13472
|
handle;
|
|
13411
13473
|
secretKeys;
|
|
13474
|
+
secretMaps;
|
|
13412
13475
|
nameField;
|
|
13476
|
+
/** The `integrations` registry owns the on/off switch (`role: devices`); the body has none. */
|
|
13477
|
+
registryOwnsEnabled;
|
|
13413
13478
|
constructor(records, kind, hooks) {
|
|
13414
13479
|
this.records = records;
|
|
13415
13480
|
this.kind = kind;
|
|
13416
13481
|
this.hooks = hooks;
|
|
13417
13482
|
this.handle = records.kind(kind);
|
|
13418
13483
|
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
13484
|
+
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
13419
13485
|
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
13486
|
+
this.registryOwnsEnabled = hooks.description.role === "devices";
|
|
13487
|
+
if (this.registryOwnsEnabled && declaresEnabled(kind)) throw new Error(`kind "${kind.name}": the integrations registry owns the on/off switch of a role "devices" addon, so the body must not declare "enabled"`);
|
|
13420
13488
|
}
|
|
13421
13489
|
/**
|
|
13422
13490
|
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
@@ -13467,7 +13535,7 @@ var RecordIntegrationInstances = class {
|
|
|
13467
13535
|
id: record.id,
|
|
13468
13536
|
name: typeof rawName === "string" ? rawName : record.id,
|
|
13469
13537
|
configured: this.hooks.configured(record.data),
|
|
13470
|
-
enabled: record.data.enabled !== false,
|
|
13538
|
+
...this.registryOwnsEnabled ? {} : { enabled: record.data.enabled !== false },
|
|
13471
13539
|
formValues: shown,
|
|
13472
13540
|
...kind !== void 0 ? { kind } : {},
|
|
13473
13541
|
...health?.status !== void 0 ? { status: health.status } : {},
|
|
@@ -13497,32 +13565,36 @@ var RecordIntegrationInstances = class {
|
|
|
13497
13565
|
id: minted,
|
|
13498
13566
|
data: this.hooks.initialBody(name, kind)
|
|
13499
13567
|
}, { ifRev: 0 });
|
|
13500
|
-
await this.hooks.onChanged?.(minted);
|
|
13568
|
+
await this.hooks.onChanged?.(minted, "created");
|
|
13501
13569
|
return { id: minted };
|
|
13502
13570
|
};
|
|
13503
13571
|
updateInstance = async ({ id, name, values }) => {
|
|
13504
13572
|
const patch = {};
|
|
13505
13573
|
for (const [key, value] of Object.entries(values)) {
|
|
13506
13574
|
if (value === void 0) continue;
|
|
13507
|
-
if (
|
|
13575
|
+
if (this.secretMaps.has(key)) {
|
|
13576
|
+
const entries = secretMapPatch(value);
|
|
13577
|
+
if (entries !== null) patch[key] = entries;
|
|
13578
|
+
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
13508
13579
|
else if (isSecretClear(value)) patch[key] = null;
|
|
13509
13580
|
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
13510
13581
|
}
|
|
13511
13582
|
if (name !== void 0) patch[this.nameField] = name;
|
|
13512
13583
|
await this.handle.patch(id, patch);
|
|
13513
|
-
await this.hooks.onChanged?.(id);
|
|
13584
|
+
await this.hooks.onChanged?.(id, "updated");
|
|
13514
13585
|
return { ok: true };
|
|
13515
13586
|
};
|
|
13516
13587
|
/** The switch lives in the record body; the addon is told so it applies it (D996). */
|
|
13517
13588
|
setInstanceEnabled = async ({ id, enabled }) => {
|
|
13589
|
+
if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
|
|
13518
13590
|
await this.handle.patch(id, { enabled });
|
|
13519
|
-
await this.hooks.onChanged?.(id);
|
|
13591
|
+
await this.hooks.onChanged?.(id, "enabled");
|
|
13520
13592
|
return { ok: true };
|
|
13521
13593
|
};
|
|
13522
13594
|
/** The row and its keychain refs go together (the records door). */
|
|
13523
13595
|
deleteInstance = async ({ id }) => {
|
|
13524
13596
|
await this.handle.delete(id);
|
|
13525
|
-
await this.hooks.onChanged?.(id);
|
|
13597
|
+
await this.hooks.onChanged?.(id, "deleted");
|
|
13526
13598
|
return { ok: true };
|
|
13527
13599
|
};
|
|
13528
13600
|
testInstance = async (input) => {
|
|
@@ -54451,6 +54523,21 @@ var IntegrationInstanceKindSchema = object({
|
|
|
54451
54523
|
disconnectPath: string().min(1).optional()
|
|
54452
54524
|
});
|
|
54453
54525
|
var IntegrationInstanceDescriptionSchema = object({
|
|
54526
|
+
/** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
|
|
54527
|
+
role: _enum([
|
|
54528
|
+
"devices",
|
|
54529
|
+
"services",
|
|
54530
|
+
"both"
|
|
54531
|
+
]),
|
|
54532
|
+
/** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
|
|
54533
|
+
discovery: object({
|
|
54534
|
+
mode: _enum([
|
|
54535
|
+
"none",
|
|
54536
|
+
"lan",
|
|
54537
|
+
"account"
|
|
54538
|
+
]),
|
|
54539
|
+
scopedToInstance: boolean()
|
|
54540
|
+
}).optional(),
|
|
54454
54541
|
/** `single`: at most one instance can exist (Loki). `multiple`: an account each. */
|
|
54455
54542
|
instanceMode: IntegrationInstanceModeSchema,
|
|
54456
54543
|
/** What the instance is, for the UI (`destination`, `relay`, `account`). */
|
|
@@ -54490,10 +54577,11 @@ var IntegrationInstanceSchema = object({
|
|
|
54490
54577
|
/** The addon's own rule (an URL is present, a client id is present...). */
|
|
54491
54578
|
configured: boolean(),
|
|
54492
54579
|
/**
|
|
54493
|
-
* The instance's own on/off switch (D996)
|
|
54494
|
-
*
|
|
54580
|
+
* The instance's own on/off switch (D996), derived from the record body (`enabled !== false`,
|
|
54581
|
+
* so a row written before the field existed is on). Absent when the `integrations` registry
|
|
54582
|
+
* owns the switch (`describe().role` is `devices`): read it from the registry row.
|
|
54495
54583
|
*/
|
|
54496
|
-
enabled: boolean(),
|
|
54584
|
+
enabled: boolean().optional(),
|
|
54497
54585
|
/** The kind of this instance (one of `describe().kinds[].id`), when the provider has kinds. */
|
|
54498
54586
|
kind: string().optional(),
|
|
54499
54587
|
/** Values for the instance form; a secret is a `SecretFieldView`, never text. */
|
|
@@ -101991,7 +102079,7 @@ var ALEXA_ADDON_ID = "export-alexa";
|
|
|
101991
102079
|
* key, id `<addonId>.<key>`, data `{ addonId, key, value }` (never a per-addon scoped table,
|
|
101992
102080
|
* which exists only when something lazily declared it).
|
|
101993
102081
|
*/
|
|
101994
|
-
var ADDON_SETTINGS_TABLE$
|
|
102082
|
+
var ADDON_SETTINGS_TABLE$2 = "addon-settings";
|
|
101995
102083
|
var RETIRED_PUBLIC_URL_KEYS = ["publicHubUrl"];
|
|
101996
102084
|
async function planDropPublicHubUrl(ports) {
|
|
101997
102085
|
const stored = await ports.readStored();
|
|
@@ -102000,7 +102088,7 @@ async function planDropPublicHubUrl(ports) {
|
|
|
102000
102088
|
const rowId = (key) => `${ALEXA_ADDON_ID}.${key}`;
|
|
102001
102089
|
return { edits: [{
|
|
102002
102090
|
op: "deleteKeys",
|
|
102003
|
-
scope: ADDON_SETTINGS_TABLE$
|
|
102091
|
+
scope: ADDON_SETTINGS_TABLE$2,
|
|
102004
102092
|
keys: present.map(rowId),
|
|
102005
102093
|
precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
|
|
102006
102094
|
addonId: ALEXA_ADDON_ID,
|
|
@@ -102085,6 +102173,130 @@ var alexaSkillLinksKind = defineEntryKind("skill-links", {
|
|
|
102085
102173
|
}),
|
|
102086
102174
|
secretArrayKeys: { tokens: "userId" }
|
|
102087
102175
|
});
|
|
102176
|
+
/** The exposure keys that moved into the `skill-exports` record; the migrations name them. */
|
|
102177
|
+
var MOVED_EXPOSURE_KEYS = ["exposed", "exposedActions"];
|
|
102178
|
+
var ExportDeviceSettingsSchema = object({
|
|
102179
|
+
streamPreference: string(),
|
|
102180
|
+
sourceProfile: CamProfileSchema.optional(),
|
|
102181
|
+
allowTranscode: boolean().optional()
|
|
102182
|
+
});
|
|
102183
|
+
var ExposedDeviceEntrySchema = object({
|
|
102184
|
+
deviceId: number(),
|
|
102185
|
+
exposedAt: number(),
|
|
102186
|
+
settings: ExportDeviceSettingsSchema.optional()
|
|
102187
|
+
});
|
|
102188
|
+
var ActionSceneEntrySchema = object({
|
|
102189
|
+
actionId: string(),
|
|
102190
|
+
displayName: string(),
|
|
102191
|
+
addedAt: number()
|
|
102192
|
+
});
|
|
102193
|
+
var SkillExportsBodySchema = object({
|
|
102194
|
+
name: string().min(1),
|
|
102195
|
+
devices: array(ExposedDeviceEntrySchema),
|
|
102196
|
+
actions: array(ActionSceneEntrySchema)
|
|
102197
|
+
});
|
|
102198
|
+
var SKILL_EXPORTS_KIND_NAME = "skill-exports";
|
|
102199
|
+
var SKILL_EXPORTS_NAME = "Alexa exposure";
|
|
102200
|
+
var alexaSkillExportsKind = defineEntryKind(SKILL_EXPORTS_KIND_NAME, {
|
|
102201
|
+
title: "Alexa exposure",
|
|
102202
|
+
nameField: "name",
|
|
102203
|
+
schema: SkillExportsBodySchema
|
|
102204
|
+
});
|
|
102205
|
+
var EMPTY_SKILL_EXPORTS = {
|
|
102206
|
+
name: SKILL_EXPORTS_NAME,
|
|
102207
|
+
devices: [],
|
|
102208
|
+
actions: []
|
|
102209
|
+
};
|
|
102210
|
+
//#endregion
|
|
102211
|
+
//#region src/migrations/exposure-to-record.ts
|
|
102212
|
+
/**
|
|
102213
|
+
* The Alexa exposure lists move into the `skill-exports` record (planning#408 P4). Two
|
|
102214
|
+
* migrations, both `block-owner`: the addon must not serve a membership it cannot trust, and
|
|
102215
|
+
* after them nothing reads the old keys.
|
|
102216
|
+
*
|
|
102217
|
+
* 1. `moveExposureToRecord` (procedure): `exposed` and `exposedActions` become the record under
|
|
102218
|
+
* the instance id. An existing record is never overwritten. A record this pass just wrote is
|
|
102219
|
+
* read BACK and must equal what the settings carried, or the pass throws.
|
|
102220
|
+
* 2. `planDropMovedExposure` (plan): the two keys are deleted only while the record holds every
|
|
102221
|
+
* device and action the settings carried; a record that cannot be read leaves them in place.
|
|
102222
|
+
*/
|
|
102223
|
+
var ADDON_SETTINGS_TABLE$1 = "addon-settings";
|
|
102224
|
+
function devicesOf(value) {
|
|
102225
|
+
if (!Array.isArray(value)) return [];
|
|
102226
|
+
return value.flatMap((entry) => {
|
|
102227
|
+
const parsed = ExposedDeviceEntrySchema.safeParse(entry);
|
|
102228
|
+
return parsed.success ? [parsed.data] : [];
|
|
102229
|
+
});
|
|
102230
|
+
}
|
|
102231
|
+
function actionsOf(value) {
|
|
102232
|
+
if (!Array.isArray(value)) return [];
|
|
102233
|
+
return value.flatMap((entry) => {
|
|
102234
|
+
const parsed = ActionSceneEntrySchema.safeParse(entry);
|
|
102235
|
+
return parsed.success ? [parsed.data] : [];
|
|
102236
|
+
});
|
|
102237
|
+
}
|
|
102238
|
+
/** Key-order-independent JSON, so "identical" does not depend on how a store orders keys. */
|
|
102239
|
+
function canonical$1(value) {
|
|
102240
|
+
if (Array.isArray(value)) return `[${value.map(canonical$1).join(",")}]`;
|
|
102241
|
+
if (typeof value === "object" && value !== null) return `{${Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${canonical$1(v)}`).join(",")}}`;
|
|
102242
|
+
return JSON.stringify(value) ?? "null";
|
|
102243
|
+
}
|
|
102244
|
+
async function moveExposureToRecord(ports) {
|
|
102245
|
+
const stored = await ports.readRawStored();
|
|
102246
|
+
if (!MOVED_EXPOSURE_KEYS.some((key) => key in stored)) return {
|
|
102247
|
+
outcome: "already-done",
|
|
102248
|
+
summary: { moved: false }
|
|
102249
|
+
};
|
|
102250
|
+
const devices = devicesOf(stored["exposed"]);
|
|
102251
|
+
const actions = actionsOf(stored["exposedActions"]);
|
|
102252
|
+
const dropped = (Array.isArray(stored["exposed"]) ? stored["exposed"].length : 0) - devices.length + ((Array.isArray(stored["exposedActions"]) ? stored["exposedActions"].length : 0) - actions.length);
|
|
102253
|
+
if (dropped > 0) ports.warn(`Alexa migration: ${dropped} exposure entr(ies) were not understood and are left out`);
|
|
102254
|
+
const body = {
|
|
102255
|
+
name: SKILL_EXPORTS_NAME,
|
|
102256
|
+
devices,
|
|
102257
|
+
actions
|
|
102258
|
+
};
|
|
102259
|
+
if (await ports.putExports(body) === "exists") return {
|
|
102260
|
+
outcome: "already-done",
|
|
102261
|
+
summary: { moved: false }
|
|
102262
|
+
};
|
|
102263
|
+
const held = await ports.readExports();
|
|
102264
|
+
if (held === null || canonical$1(held.devices) !== canonical$1(devices) || canonical$1(held.actions) !== canonical$1(actions)) throw new Error("the Alexa exposure record does not match the legacy settings; nothing was cleared");
|
|
102265
|
+
return {
|
|
102266
|
+
outcome: "done",
|
|
102267
|
+
summary: {
|
|
102268
|
+
moved: true,
|
|
102269
|
+
devices: devices.length,
|
|
102270
|
+
actions: actions.length
|
|
102271
|
+
}
|
|
102272
|
+
};
|
|
102273
|
+
}
|
|
102274
|
+
var rowId$1 = (key) => `${ALEXA_INSTANCE_ID}.${key}`;
|
|
102275
|
+
async function planDropMovedExposure(ports) {
|
|
102276
|
+
const stored = await ports.readRawStored();
|
|
102277
|
+
const present = MOVED_EXPOSURE_KEYS.filter((key) => key in stored);
|
|
102278
|
+
if (present.length === 0) return { edits: [] };
|
|
102279
|
+
const refuse = (reason) => {
|
|
102280
|
+
ports.warn(`Alexa migration: the legacy exposure keys are kept: ${reason}`);
|
|
102281
|
+
throw new Error(`the legacy Alexa exposure keys are not deleted: ${reason}`);
|
|
102282
|
+
};
|
|
102283
|
+
const held = await ports.readExports();
|
|
102284
|
+
if (held === null) return refuse("no exposure record exists");
|
|
102285
|
+
const heldDevices = new Set(held.devices.map((d) => d.deviceId));
|
|
102286
|
+
for (const device of devicesOf(stored["exposed"])) if (!heldDevices.has(device.deviceId)) return refuse(`the record lacks the device ${device.deviceId}`);
|
|
102287
|
+
const heldActions = new Set(held.actions.map((a) => a.actionId));
|
|
102288
|
+
for (const action of actionsOf(stored["exposedActions"])) if (!heldActions.has(action.actionId)) return refuse(`the record lacks the action ${action.actionId}`);
|
|
102289
|
+
return { edits: [{
|
|
102290
|
+
op: "deleteKeys",
|
|
102291
|
+
scope: ADDON_SETTINGS_TABLE$1,
|
|
102292
|
+
keys: present.map(rowId$1),
|
|
102293
|
+
precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId$1(key), {
|
|
102294
|
+
addonId: ALEXA_INSTANCE_ID,
|
|
102295
|
+
key,
|
|
102296
|
+
value: stored[key]
|
|
102297
|
+
}])))
|
|
102298
|
+
}] };
|
|
102299
|
+
}
|
|
102088
102300
|
//#endregion
|
|
102089
102301
|
//#region src/migrations/settings-to-records.ts
|
|
102090
102302
|
/**
|
|
@@ -102284,7 +102496,9 @@ var DROP_PUBLIC_HUB_URL_ID = "export-alexa/2026-11-02-drop-public-hub-url";
|
|
|
102284
102496
|
var SETTINGS_TO_INTEGRATION_ID = "export-alexa/2026-11-03-settings-to-integration";
|
|
102285
102497
|
var LEDGERS_TO_INTEGRATION_ID = "export-alexa/2026-11-03-ledgers-to-integration";
|
|
102286
102498
|
var DROP_MOVED_SETTINGS_ID = "export-alexa/2026-11-03-drop-moved-settings";
|
|
102287
|
-
var
|
|
102499
|
+
var EXPOSURE_TO_RECORD_ID = "export-alexa/2026-11-04-exposure-to-record";
|
|
102500
|
+
var DROP_MOVED_EXPOSURE_ID = "export-alexa/2026-11-04-drop-moved-exposure";
|
|
102501
|
+
var FIXTURE_MARK = "the endpoint sync state the migration does not know";
|
|
102288
102502
|
/**
|
|
102289
102503
|
* The `export-alexa` catalogue (D987): offered to the engine when the addon initialises. Every
|
|
102290
102504
|
* entry is `tolerate`; until a record exists the addon keeps reading the legacy keys.
|
|
@@ -102353,6 +102567,38 @@ var ADDON_MIGRATIONS = [
|
|
|
102353
102567
|
fixtureMark: FIXTURE_MARK
|
|
102354
102568
|
},
|
|
102355
102569
|
plan: planDropMovedSettings
|
|
102570
|
+
},
|
|
102571
|
+
{
|
|
102572
|
+
meta: {
|
|
102573
|
+
id: EXPOSURE_TO_RECORD_ID,
|
|
102574
|
+
owner: "export-alexa",
|
|
102575
|
+
level: "addon-state",
|
|
102576
|
+
seq: 5,
|
|
102577
|
+
dependsOn: [],
|
|
102578
|
+
store: "settings",
|
|
102579
|
+
scope: "cluster",
|
|
102580
|
+
onFailure: "block-owner",
|
|
102581
|
+
bodyKind: "procedure",
|
|
102582
|
+
description: "Move the exposed devices and actions into the skill-exports record; the record is read back before anything is deleted",
|
|
102583
|
+
fixtureMark: FIXTURE_MARK
|
|
102584
|
+
},
|
|
102585
|
+
procedure: moveExposureToRecord
|
|
102586
|
+
},
|
|
102587
|
+
{
|
|
102588
|
+
meta: {
|
|
102589
|
+
id: DROP_MOVED_EXPOSURE_ID,
|
|
102590
|
+
owner: "export-alexa",
|
|
102591
|
+
level: "addon-state",
|
|
102592
|
+
seq: 6,
|
|
102593
|
+
dependsOn: [EXPOSURE_TO_RECORD_ID],
|
|
102594
|
+
store: "settings",
|
|
102595
|
+
scope: "cluster",
|
|
102596
|
+
onFailure: "block-owner",
|
|
102597
|
+
bodyKind: "plan",
|
|
102598
|
+
description: "Delete the exposed and exposedActions settings keys once the record holds what they carried",
|
|
102599
|
+
fixtureMark: FIXTURE_MARK
|
|
102600
|
+
},
|
|
102601
|
+
plan: planDropMovedExposure
|
|
102356
102602
|
}
|
|
102357
102603
|
];
|
|
102358
102604
|
//#endregion
|
|
@@ -103586,11 +103832,10 @@ var SyncEngine = class {
|
|
|
103586
103832
|
* linkable OAuth client of the hub's core `/oauth2/*` server.
|
|
103587
103833
|
*
|
|
103588
103834
|
* Persistence:
|
|
103589
|
-
*
|
|
103590
|
-
*
|
|
103591
|
-
* `
|
|
103592
|
-
*
|
|
103593
|
-
* of truth.
|
|
103835
|
+
* The skill, its account links and what it exposes are records
|
|
103836
|
+
* (`skills`, `skill-links`, `skill-exports`); the remaining hidden state
|
|
103837
|
+
* lives on `this.config` and writes through `updateGlobalSettings`. There
|
|
103838
|
+
* is NO `<dataDir>/alexa/*.json` sidecar anymore.
|
|
103594
103839
|
*
|
|
103595
103840
|
* Out of scope for this dispatch:
|
|
103596
103841
|
* - AWS Lambda template (CloudFormation + signing image) — the
|
|
@@ -103645,8 +103890,6 @@ var DEFAULT_CONFIG = {
|
|
|
103645
103890
|
lwaClientSecret: "",
|
|
103646
103891
|
advertisedBrokerUrl: "",
|
|
103647
103892
|
region: "NA",
|
|
103648
|
-
exposed: [],
|
|
103649
|
-
exposedActions: [],
|
|
103650
103893
|
linkedAccounts: [],
|
|
103651
103894
|
tokens: [],
|
|
103652
103895
|
exportedEndpoints: {},
|
|
@@ -103744,8 +103987,30 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
103744
103987
|
skillRow = null;
|
|
103745
103988
|
/** The `skill-links` record, once it exists; until then the legacy ledger keys answer. */
|
|
103746
103989
|
linksRow = null;
|
|
103990
|
+
/**
|
|
103991
|
+
* The `skill-exports` record: what the skill exposes (devices Alexa discovers, actions it sees
|
|
103992
|
+
* as scenes). Loaded once at boot after the migrations; this addon is its only writer, so the
|
|
103993
|
+
* in-memory copy is the synchronous read the event path needs. No settings key backs it.
|
|
103994
|
+
*/
|
|
103995
|
+
exportsRow = EMPTY_SKILL_EXPORTS;
|
|
103747
103996
|
/** The keychain refused the link credentials: the ledger is read-only until it answers (D49). */
|
|
103748
103997
|
linksLocked = false;
|
|
103998
|
+
get exposedDevices() {
|
|
103999
|
+
return this.exportsRow.devices;
|
|
104000
|
+
}
|
|
104001
|
+
/** Persist a change of the exposure: the record first, the in-memory copy after it landed. */
|
|
104002
|
+
async writeExports(patch) {
|
|
104003
|
+
const next = {
|
|
104004
|
+
name: this.exportsRow.name,
|
|
104005
|
+
devices: patch.devices ?? this.exportsRow.devices,
|
|
104006
|
+
actions: patch.actions ?? this.exportsRow.actions
|
|
104007
|
+
};
|
|
104008
|
+
await this.exportsHandle().put({
|
|
104009
|
+
id: ALEXA_INSTANCE_ID,
|
|
104010
|
+
data: next
|
|
104011
|
+
});
|
|
104012
|
+
this.exportsRow = next;
|
|
104013
|
+
}
|
|
103749
104014
|
/**
|
|
103750
104015
|
* The legacy ledger keys as lists. A store written by an older build may hold something that
|
|
103751
104016
|
* is not a list there (a clear instruction stored as the value); the page and the gateway read
|
|
@@ -103797,10 +104062,12 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
103797
104062
|
if (records === void 0) throw new Error("export-alexa needs ctx.records — check execution.placement (hub-only)");
|
|
103798
104063
|
await records.declare({
|
|
103799
104064
|
skills: alexaSkillsKind,
|
|
103800
|
-
"skill-links": alexaSkillLinksKind
|
|
104065
|
+
"skill-links": alexaSkillLinksKind,
|
|
104066
|
+
"skill-exports": alexaSkillExportsKind
|
|
103801
104067
|
});
|
|
103802
104068
|
this.instances = new RecordIntegrationInstances(records, alexaSkillsKind, {
|
|
103803
104069
|
description: {
|
|
104070
|
+
role: "services",
|
|
103804
104071
|
instanceMode: "single",
|
|
103805
104072
|
kind: "skills",
|
|
103806
104073
|
canTest: false
|
|
@@ -103818,6 +104085,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
103818
104085
|
});
|
|
103819
104086
|
await this.runMigrations(defineAddonMigrations(ADDON_MIGRATIONS, this.migrationPorts()));
|
|
103820
104087
|
await this.refreshRecords();
|
|
104088
|
+
this.exportsRow = (await this.exportsHandle().get("export-alexa"))?.data ?? EMPTY_SKILL_EXPORTS;
|
|
103821
104089
|
if (!this.config.ingressToken) await this.updateGlobalSettings({ ingressToken: generateIngressToken() });
|
|
103822
104090
|
if (!this.config.snapshotSigningKey) await this.updateGlobalSettings({ snapshotSigningKey: generateIngressToken() });
|
|
103823
104091
|
if (!this.config.visionNamespace) await this.updateGlobalSettings({ visionNamespace: (0, node_crypto.randomUUID)() });
|
|
@@ -103836,7 +104104,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
103836
104104
|
this.visibilityRef = new AccountVisibilityMirror({
|
|
103837
104105
|
gate: this.accessGateRef,
|
|
103838
104106
|
listLinkedUserIds: () => this.view.linkedAccounts.map((a) => a.userId),
|
|
103839
|
-
listExposedDeviceIds: () => this.
|
|
104107
|
+
listExposedDeviceIds: () => this.exposedDevices.map((e) => e.deviceId),
|
|
103840
104108
|
getStored: () => this.config.accountVisibility,
|
|
103841
104109
|
setStored: (next) => this.updateGlobalSettings({ accountVisibility: next }),
|
|
103842
104110
|
logger: this.ctx.logger
|
|
@@ -103846,7 +104114,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
103846
104114
|
logger: this.ctx.logger,
|
|
103847
104115
|
integrationOn: () => this.view.objectDetection,
|
|
103848
104116
|
snapshotsOn: () => this.view.snapshots,
|
|
103849
|
-
isExposed: (deviceId) => this.
|
|
104117
|
+
isExposed: (deviceId) => this.exposedDevices.some((e) => e.deviceId === deviceId),
|
|
103850
104118
|
knownClasses: (deviceId) => this.config.detectionClasses[deviceId]?.classes ?? [],
|
|
103851
104119
|
namespace: () => this.config.visionNamespace,
|
|
103852
104120
|
publicEndpoint: this.publicEndpoint,
|
|
@@ -103864,8 +104132,8 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
103864
104132
|
canPush: () => this.view.tokens.length > 0,
|
|
103865
104133
|
postAddOrUpdate: (userId, endpoints) => this.requireGateway().postReport(userId, (accessToken) => buildAddOrUpdateReportPayload(userId, endpoints, accessToken), `action scenes add/update (${endpoints.length})`),
|
|
103866
104134
|
postDelete: (userId, ids) => this.requireGateway().postReport(userId, (accessToken) => buildDeleteReportPayload(userId, ids, accessToken), `action scenes delete (${ids.length})`),
|
|
103867
|
-
persist: (entries) => this.
|
|
103868
|
-
}, this.
|
|
104135
|
+
persist: (entries) => this.writeExports({ actions: [...entries] })
|
|
104136
|
+
}, this.exportsRow.actions);
|
|
103869
104137
|
const actionScenes = this.actionScenes;
|
|
103870
104138
|
actionScenes.reconcile().catch((err) => {
|
|
103871
104139
|
this.ctx.logger.warn("export-alexa: action scene reconcile at boot failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
@@ -103876,7 +104144,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
103876
104144
|
ownInstance(statusInstanceOf(input));
|
|
103877
104145
|
return {
|
|
103878
104146
|
linkState: this.view.linkedAccounts.length > 0 ? "linked" : "unlinked",
|
|
103879
|
-
exposedDeviceCount: this.
|
|
104147
|
+
exposedDeviceCount: this.exposedDevices.length,
|
|
103880
104148
|
setup: await this.buildSetupBlock()
|
|
103881
104149
|
};
|
|
103882
104150
|
},
|
|
@@ -103892,7 +104160,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
103892
104160
|
},
|
|
103893
104161
|
listExposedDevices: async ({ instanceId }) => {
|
|
103894
104162
|
ownInstance(instanceId);
|
|
103895
|
-
return this.
|
|
104163
|
+
return this.exposedDevices.map((e) => ({ deviceId: String(e.deviceId) }));
|
|
103896
104164
|
},
|
|
103897
104165
|
exposeDevice: async ({ instanceId, deviceId }) => {
|
|
103898
104166
|
ownInstance(instanceId);
|
|
@@ -103906,7 +104174,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
103906
104174
|
listExposedEntities: async ({ instanceId }) => {
|
|
103907
104175
|
ownInstance(instanceId);
|
|
103908
104176
|
await actionScenes.reconcile();
|
|
103909
|
-
return [...this.
|
|
104177
|
+
return [...this.exposedDevices.map((e) => ({ entity: {
|
|
103910
104178
|
kind: "device",
|
|
103911
104179
|
deviceId: String(e.deviceId)
|
|
103912
104180
|
} })), ...actionScenes.list()];
|
|
@@ -103935,18 +104203,18 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
103935
104203
|
discovery: {
|
|
103936
104204
|
ctx: this.ctx,
|
|
103937
104205
|
logger: this.ctx.logger,
|
|
103938
|
-
listExposed: async () => this.
|
|
104206
|
+
listExposed: async () => this.exposedDevices,
|
|
103939
104207
|
buildEndpoints: (deviceId) => this.buildEndpointsForOneDevice(deviceId)
|
|
103940
104208
|
},
|
|
103941
104209
|
cameraStream: {
|
|
103942
104210
|
ctx: this.ctx,
|
|
103943
104211
|
logger: this.ctx.logger,
|
|
103944
|
-
listExposed: () => this.
|
|
104212
|
+
listExposed: () => this.exposedDevices
|
|
103945
104213
|
},
|
|
103946
104214
|
rtcSession: {
|
|
103947
104215
|
ctx: this.ctx,
|
|
103948
104216
|
logger: this.ctx.logger,
|
|
103949
|
-
listExposed: () => this.
|
|
104217
|
+
listExposed: () => this.exposedDevices
|
|
103950
104218
|
},
|
|
103951
104219
|
ptzPreset: {
|
|
103952
104220
|
ctx: this.ctx,
|
|
@@ -104038,13 +104306,13 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
104038
104306
|
this.egressPrewarm = new AlexaEgressPrewarm({
|
|
104039
104307
|
api: this.ctx.api,
|
|
104040
104308
|
logger: this.ctx.logger,
|
|
104041
|
-
listExposed: () => this.
|
|
104309
|
+
listExposed: () => this.exposedDevices,
|
|
104042
104310
|
hasLiveSession: (deviceId) => heldEgressHandles().some((h) => h.deviceId === deviceId)
|
|
104043
104311
|
});
|
|
104044
104312
|
this.lwaGateway = new LwaEventGateway({
|
|
104045
104313
|
ctx: this.ctx,
|
|
104046
104314
|
logger: this.ctx.logger,
|
|
104047
|
-
listExposed: () => this.
|
|
104315
|
+
listExposed: () => this.exposedDevices,
|
|
104048
104316
|
onExposedDoorbellPress: (deviceId) => {
|
|
104049
104317
|
this.egressPrewarm?.onPress(deviceId);
|
|
104050
104318
|
},
|
|
@@ -104063,7 +104331,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
104063
104331
|
this.detectionFeed = new DetectionSensorFeed({
|
|
104064
104332
|
eventBus: this.ctx.eventBus,
|
|
104065
104333
|
enabled: () => this.view.detectionSensors,
|
|
104066
|
-
isExposed: (deviceId) => this.
|
|
104334
|
+
isExposed: (deviceId) => this.exposedDevices.some((e) => e.deviceId === deviceId),
|
|
104067
104335
|
readActiveTracks: async (deviceId) => {
|
|
104068
104336
|
return (await this.ctx.api.pipelineAnalytics.getActiveTracks.query({ deviceId })).map((t) => ({
|
|
104069
104337
|
trackId: t.trackId,
|
|
@@ -104107,7 +104375,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
104107
104375
|
this.stateReconciler.start();
|
|
104108
104376
|
this.syncEngine = new SyncEngine({
|
|
104109
104377
|
logger: this.ctx.logger,
|
|
104110
|
-
listExposed: () => this.
|
|
104378
|
+
listExposed: () => this.exposedDevices,
|
|
104111
104379
|
listLinkedAccounts: () => this.view.linkedAccounts,
|
|
104112
104380
|
hasProactiveCredentials: () => this.view.tokens.length > 0,
|
|
104113
104381
|
buildEndpoints: (deviceId) => this.buildEndpointsForOneDevice(deviceId),
|
|
@@ -104128,7 +104396,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
104128
104396
|
const offRemoved = this.ctx.eventBus.subscribe({ category: EventCategory.DeviceUnregistered }, (event) => {
|
|
104129
104397
|
const id = event.data?.deviceId;
|
|
104130
104398
|
if (typeof id !== "number") return;
|
|
104131
|
-
if (!this.
|
|
104399
|
+
if (!this.exposedDevices.some((e) => e.deviceId === id)) return;
|
|
104132
104400
|
this.unexposeDevice(String(id));
|
|
104133
104401
|
});
|
|
104134
104402
|
this.ctx.addDisposer(async () => offRemoved());
|
|
@@ -104138,7 +104406,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
104138
104406
|
reaper.unref?.();
|
|
104139
104407
|
this.ctx.addDisposer(async () => clearInterval(reaper));
|
|
104140
104408
|
this.ctx.logger.info("export-alexa: initialized", { meta: {
|
|
104141
|
-
exposedCount: this.
|
|
104409
|
+
exposedCount: this.exposedDevices.length,
|
|
104142
104410
|
skillMode: this.view.skillMode,
|
|
104143
104411
|
skillIdSet: this.effectiveSettings().expectedAudience.length > 0,
|
|
104144
104412
|
pushGrants: this.view.tokens.length,
|
|
@@ -104213,13 +104481,13 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
104213
104481
|
if (!await this.ctx.api.deviceManager.getDevice.query({ deviceId }).catch((err) => {
|
|
104214
104482
|
throw new Error(`export-alexa: deviceManager.getDevice failed: ${errMsg$1(err)}`);
|
|
104215
104483
|
})) throw new Error(`export-alexa: device ${deviceId} not found`);
|
|
104216
|
-
const next = this.
|
|
104484
|
+
const next = this.exposedDevices.filter((e) => e.deviceId !== deviceId);
|
|
104217
104485
|
next.push({
|
|
104218
104486
|
deviceId,
|
|
104219
104487
|
exposedAt: Date.now(),
|
|
104220
104488
|
settings: DEFAULT_DEVICE_SETTINGS
|
|
104221
104489
|
});
|
|
104222
|
-
await this.
|
|
104490
|
+
await this.writeExports({ devices: next });
|
|
104223
104491
|
this.ctx.logger.info("export-alexa: exposed device", { meta: { deviceId } });
|
|
104224
104492
|
this.requireSyncEngine().pushDevice(deviceId).then((r) => {
|
|
104225
104493
|
this.ctx.logger.info("export-alexa: synced exposed device", { meta: { ...r } });
|
|
@@ -104234,9 +104502,9 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
104234
104502
|
async unexposeDevice(deviceIdRaw) {
|
|
104235
104503
|
const deviceId = Number.parseInt(deviceIdRaw, 10);
|
|
104236
104504
|
if (!Number.isFinite(deviceId)) return;
|
|
104237
|
-
const next = this.
|
|
104238
|
-
if (next.length === this.
|
|
104239
|
-
await this.
|
|
104505
|
+
const next = this.exposedDevices.filter((e) => e.deviceId !== deviceId);
|
|
104506
|
+
if (next.length === this.exposedDevices.length) return;
|
|
104507
|
+
await this.writeExports({ devices: next });
|
|
104240
104508
|
this.ctx.logger.info("export-alexa: unexposed device", { meta: { deviceId } });
|
|
104241
104509
|
this.requireSyncEngine().removeDevice(deviceId).catch((err) => {
|
|
104242
104510
|
this.ctx.logger.warn("export-alexa: unexpose delete failed", { meta: {
|
|
@@ -104351,7 +104619,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
104351
104619
|
get endpointAccess() {
|
|
104352
104620
|
return {
|
|
104353
104621
|
gate: this.accessGate,
|
|
104354
|
-
isExposed: (deviceId) => this.
|
|
104622
|
+
isExposed: (deviceId) => this.exposedDevices.some((e) => e.deviceId === deviceId)
|
|
104355
104623
|
};
|
|
104356
104624
|
}
|
|
104357
104625
|
/** Narrow the nullable `lwaGateway` for the SyncEngine post closures. It is
|
|
@@ -104381,7 +104649,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
104381
104649
|
const off = this.ctx.eventBus.subscribe({ category: EventCategory.DeviceBindingsChanged }, (event) => {
|
|
104382
104650
|
const deviceId = event.data?.deviceId;
|
|
104383
104651
|
if (typeof deviceId !== "number") return;
|
|
104384
|
-
if (!this.
|
|
104652
|
+
if (!this.exposedDevices.some((e) => e.deviceId === deviceId)) return;
|
|
104385
104653
|
const pending = this.pendingReconcileTimers.get(deviceId);
|
|
104386
104654
|
if (pending) clearTimeout(pending);
|
|
104387
104655
|
const timer = setTimeout(() => {
|
|
@@ -104669,6 +104937,11 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
104669
104937
|
if (records === void 0) throw new Error("records are not available");
|
|
104670
104938
|
return records.kind(alexaSkillLinksKind);
|
|
104671
104939
|
}
|
|
104940
|
+
exportsHandle() {
|
|
104941
|
+
const records = this.ctx.records;
|
|
104942
|
+
if (records === void 0) throw new Error("records are not available");
|
|
104943
|
+
return records.kind(alexaSkillExportsKind);
|
|
104944
|
+
}
|
|
104672
104945
|
/** Re-read both records. A failed read changes nothing: the addon keeps what it has. */
|
|
104673
104946
|
async refreshRecords() {
|
|
104674
104947
|
try {
|
|
@@ -104731,6 +105004,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
104731
105004
|
migrationPorts() {
|
|
104732
105005
|
const skills = this.skillHandle();
|
|
104733
105006
|
const links = this.linksHandle();
|
|
105007
|
+
const exportsHandle = this.exportsHandle();
|
|
104734
105008
|
const putOnce = async (handle, body) => {
|
|
104735
105009
|
if (await handle.get("export-alexa") !== null) return "exists";
|
|
104736
105010
|
try {
|
|
@@ -104760,6 +105034,8 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
104760
105034
|
},
|
|
104761
105035
|
putSkill: (body) => putOnce(skills, body),
|
|
104762
105036
|
putLinks: (body) => putOnce(links, body),
|
|
105037
|
+
putExports: (body) => putOnce(exportsHandle, body),
|
|
105038
|
+
readExports: async () => (await exportsHandle.get("export-alexa"))?.data ?? null,
|
|
104763
105039
|
replaceLinks: async (body) => {
|
|
104764
105040
|
await links.put({
|
|
104765
105041
|
id: ALEXA_INSTANCE_ID,
|
|
@@ -105065,14 +105341,14 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
105065
105341
|
}
|
|
105066
105342
|
}
|
|
105067
105343
|
findEntry(deviceId) {
|
|
105068
|
-
return this.
|
|
105344
|
+
return this.exposedDevices.find((e) => e.deviceId === deviceId) ?? null;
|
|
105069
105345
|
}
|
|
105070
105346
|
async patchEntrySettings(deviceId, settings) {
|
|
105071
|
-
const next = this.
|
|
105347
|
+
const next = this.exposedDevices.map((e) => e.deviceId === deviceId ? {
|
|
105072
105348
|
...e,
|
|
105073
105349
|
settings
|
|
105074
105350
|
} : e);
|
|
105075
|
-
await this.
|
|
105351
|
+
await this.writeExports({ devices: next });
|
|
105076
105352
|
}
|
|
105077
105353
|
};
|
|
105078
105354
|
//#endregion
|